Codeforces Round #277.5 (Div. 2)-B
来源:互联网 发布:未再网络上注册怎么办 编辑:程序博客网 时间:2024/06/05 15:19
一看就是贪心,想了个策略,先排序再尽可能用两个较小的凑成一对,
代码:
#include<iostream>#include<cstdio>#include<cmath>#include<map>#include<cstring>#include<algorithm>#define rep(i,a,b) for(int i=(a);i<(b);i++)#define rev(i,a,b) for(int i=(a);i>=(b);i--)#define clr(a,x) memset(a,x,sizeof a)typedef long long LL;using namespace std;const int mod=1e9 +7;const int maxn=3005;const int maxm=4005;int da[maxn],db[maxn],u[maxn],v[maxn];int dis(int a,int b){ return a>b?a-b:b-a;}int main(){ int n,m; while(~scanf("%d",&n)) { for(int i=0;i<n;i++) scanf("%d",&da[i]); scanf("%d",&m); for(int i=0;i<m;i++) scanf("%d",&db[i]); sort(da,da+n); sort(db,db+m); int cur=0,cnt=0; for(int i=0;cur<m&&i<n;) { while(cur<m&&da[i]-db[cur]>1) cur++; while(i<n&&db[cur]-da[i]>1) i++; if(dis(db[cur],da[i])<=1)cnt++,cur++,i++; } printf("%d\n",cnt); } return 0;}
0 0
- Codeforces Round #277.5 (Div. 2)-B
- Codeforces Round #277.5 (Div. 2) B
- Codeforces Round #277.5 (Div. 2)B——BerSU Ball
- Codeforces Round #277.5 (Div. 2)---B. BerSU Ball (贪心)
- Codeforces Round #277.5 (Div. 2) A B C D
- Codeforces Round #277.5 (Div. 2):B BerSU Ball
- Codeforces Round #277.5(Div. 2) B. BerSU Ball【二分匹配】
- Codeforces Round #131 (Div. 2) A B
- Codeforces Round #134 (Div. 2)B. Airport
- Codeforces Round #170 (Div. 2) problem B
- Codeforces Round #173 (Div. 2) Problem B
- Codeforces Round #181 (Div. 2) B. Coach
- Codeforces Round #185 (Div. 2)--A,B
- Codeforces Round #171 (Div. 2) B
- Codeforces Round #169 (Div. 2) B题
- Codeforces Round #188 (Div. 2) B题
- Codeforces Round #192 (Div. 2) B
- Codeforces Round #203 (Div. 2) B. Resort
- android ListView 一些重要属性详解
- C# 实现设置系统环境变量设置
- git 命令
- 深入解析Apache Mina源码(4)——Mina编解码以及对粘包和断包的处理
- 青岛泽雨你到底怎么了???人去楼空了,难道真的要倒闭了吗?
- Codeforces Round #277.5 (Div. 2)-B
- 初级会计实务试题要怎么复习
- cannot handle exception type PackageManager.NameNotFoundException thrown by implicit super construct
- android权限大全
- svn 冲突解决
- 省市级联--jquery调取json数据
- Linux字符串操作大全
- 警告: 程序集绑定日志记录被关闭。
- Android开发教程:shape和selector的结合使用