当前位置:网站首页>Educational Codeforces Round 89 (Rated for Div. 2)ABC题解
Educational Codeforces Round 89 (Rated for Div. 2)ABC题解
2022-07-20 14:18:00 【Think-killer】
A. Shovels and Swords
判断各种情况即可。
#include <iostream>
#include<algorithm>
using namespace std;
int t,a,b;
int main()
{
scanf("%d",&t);
while(t--){
scanf("%d%d",&a,&b);
int ans=0,ax;
if(a==0||b==0||(a==1&&b==1)) cout<<"0\n";
else{
ans=max(a,b);
ax=min(a,b);
if(2*ax<=ans) cout<<ax<<endl;
else cout<<(ans+ax)/3<<endl;
}
}
return 0;
}
B. Shuffle
题解:要想知道交换后可以得到的ak=1的可能,只需要知道X是否在l与r之间,如果在则可以使用l,r之间的任意索引数。
#include <iostream>
#include<algorithm>
using namespace std;
int t,n,x,m,l,r;
int main()
{
scanf("%d",&t);
while(t--){
cin>>n>>x>>m;
int a=x,b=x;
while(m--){
cin>>l>>r;
if(r<a||b<l) continue;//判断是否在x可取值的范围
else a=min(l,a),b=max(r,b);//更新索引数取值范围
}
cout<<b-a+1<<endl;//输出所有索引数个数
}
return 0;
}
C. Palindromic Paths
题意:使得每条(1,1)到(n,m)的路径上的数字都对称,即倒数第i步与正数第i步相等,求最小改变的数字个数。
题解:横纵坐标相加之和相同的点即为第i步可以到达的所有点
#include <iostream>
#include<algorithm>
#include<cstring>
int a[70],b[70]
int main()
{
int t;
cin>>t;
while(t--){
int n,m;
cin>>n>>m;
int x;
memset(a,0,sizeof a);
memset(b,0,sizeof b);
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cin>>x;
if(x) a[i+j]++;//计算第n步可以到达的点的1的个数
else b[i+j]++;//计算第n步可以到达的点的0的个数
}
}
int ans=0;
for(int i=0,j=n+m-2;i<j;i++,j--)
ans+=min(a[i]+a[j],b[i]+b[j]);//求所有最小改变数之和
cout<<ans<<endl;
}
}
边栏推荐
- Explain the tax arrears with deduction: there is no tax arrears, and we will continue to operate in compliance as usual
- ウクアジ / Xiaohei
- 百度工程师眼中的云原生可观测性追踪技术
- Observability improves the quality of software engineering, and observation cloud attends the 2022 qecon global software quality & effectiveness conference
- 敏实集团IPO被终止:曾拟募资65亿 秦荣华曾遭法院处罚
- Unity Image控件和RawImage
- 【Unity基础知识】基础游戏单位GameObject中常用的属性和API
- 暑假打工 2 个月,让我明白了 Keepalived 高可用的三种路由方案
- Draw a callout box according to Yolo TXT label data
- Unity3D不同脚本函数或参数之间调用
猜你喜欢
VB.NET插件开发案例
Unity Slider滑动条开发
斯坦福、Meta AI新研究:实现AGI之路,数据剪枝比我们想象得更重要
上海文旅局局长:安全是文旅业的生命线,正抢抓元宇宙新赛道
C language: file operation: sequential reading and writing, random reading and writing
ICML2022奖项公布:15篇杰出论文,复旦、厦大、上交大研究入选
ICML 2022 | 解决CNN固有缺陷, CCNN凭借单一架构,实现多项SOTA
Judge whether view slides in or out of the visible area of the screen
harbor安装
Scala advanced (VIII): collection content summary (Part 2)
随机推荐
Efcore table relationship, one-to-one, use case
Bubble sort and selection sort
Fraud detection using CSP
硬核Fiddler抓包工具大型攻略(二)Fiddler进阶篇
依赖注入
游戏合作伙伴专题:BreederDAO 与 MonkeyLeague 的合作拉开序幕
今日睡眠质量记录73分
Unity Slider滑动条开发
今日来介绍关于淘宝相似商品搜索的API接口
MySQL · 性能优化· CloudDBA SQL优化建议之统计信息获取
VB.NET插件开发案例
【性能优化】MySQL常用慢查询分析工具
中国石墨上市:市值近12亿港元 实现鹤岗民营企业上市零突破
二叉树刷题(五)
New research of Stanford and meta AI: Data pruning is more important than we think on the road to AgI
[server data recovery] a data recovery case in which the storage raid6 array was paralyzed due to power failure
2022第十五届南京国际工业自动化及工业机器人展览会
【Unity基础知识】基础游戏单位GameObject中常用的属性和API
2022 the 14th Nanjing International Smart site exhibition | smart site exhibition
Is the higher the yield of financial products, the better?