coderforce 489B B. BerSU Ball
来源:互联网 发布:战争程序员白濑 动漫 编辑:程序博客网 时间:2024/06/05 07:03
题意:每两个跳舞的人可以配对,并且他们两个的绝对值只差小于等于1。求最多匹配多少对
解:排个序,配对就完了
#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>using namespace std;const int maxm=1e3+10;int a[maxm];int b[maxm];int main(){ int n; while(scanf("%d",&n)!=EOF) { for(int i=0;i<n;i++) { scanf("%d",&a[i]); } int m; scanf("%d",&m); for(int i=0;i<m;i++) { scanf("%d",&b[i]); } sort(a,a+n); sort(b,b+m); int cnt=0; for(int i=0,j=0;i<n&&j<m;) { if(abs(a[i]-b[j])<=1) { i++; j++; cnt++; } else if(a[i]>b[j]) { j++; } else { i++; } } printf("%d\n",cnt); } return 0;}
0 0
- coderforce 489B B. BerSU Ball
- CodeForces 489B BerSU Ball
- Codeforces 489B BerSU Ball
- B. BerSU Ball
- 【寒江雪】B. BerSU Ball
- CF 277.5 B. BerSU Ball
- codeforces—— 489B —— BerSU Ball
- Codeforces Round #277.5 (Div. 2)B——BerSU Ball
- Codeforces #277.5 (Div. 2) B. BerSU Ball(DP:LCS)
- Codeforces Round #277.5 (Div. 2)---B. BerSU Ball (贪心)
- Codeforces Round #277.5 (Div. 2):B BerSU Ball
- Codeforces Round #277.5(Div. 2) B. BerSU Ball【二分匹配】
- BerSU Ball
- coderforce 1B-Spreadsheet
- coderforce 560 B
- coderforce 591B Rebranding
- coderforce 569B Inventory
- coderforce --B. Sereja and Suffixes
- POJ 1681 (高斯消元)
- 【openjudge】集合问题
- 百度地图自定义图层----BMapTileCutterJava切图工具网络版
- hdu4864 贪心+平衡二叉搜索树(map)
- 机器学习Python环境安装
- coderforce 489B B. BerSU Ball
- lightoj 1043 - Triangle Partitioning
- 关于socket tcp/ip的理解
- ajax
- Excel Sheet Column Title
- STM32库函数(3):库文件stm32f10x_flash.c内的函数
- nyoj A+B Problem IV【实数a+b】大数
- 相电压、线电压、相电流、线电流
- 自定义滑动选取价格