codeforces 777B
来源:互联网 发布:c语言优先级排序 编辑:程序博客网 时间:2024/06/07 02:51
题意:有少于两个含有n位数得号码,其中一个是数n1,每一个位固定不变,另一个数n2位之间可以互换,但不能改变其大小。
求
1.使得n2每一个位上的数小于n1中每一个位上的数的数目最少,输出其数目
2.使得n2每一个位上的数大于n1中每一个位上的数的数目最多,输出其数目
思路:两序列升序排,从序列中找
#include<cstdio>#include<algorithm>using namespace std;int a[1001],b[1001];int main(){int n;while(scanf("%d",&n)!=EOF){char s[1001];scanf("%s",s);for(int i=0;i<n;i++)a[i]=s[i]-'0';scanf("%s",s);for(int i=0;i<n;i++)b[i]=s[i]-'0';sort(a,a+n);sort(b,b+n);int ans1=0,ans2=0;for(int i=0,j=0;i<n&&j<n;i++){if(a[j]<=b[i]){ans1++;j++;}}ans1=n-ans1;//找到大于等于的最多数目,用n减去即是最小数目 for(int i=0,j=0;i<n&&j<n;i++){if(b[i]>a[j]){j++;ans2++;}}printf("%d\n%d\n",ans1,ans2);}}
阅读全文
0 0
- codeforces 777B
- 贪心-Codeforces 777B
- codeforces B
- codeforces B
- codeforces B
- codeforces B
- 【codeforces 777B】Game of Credit Cards
- Codeforces 777B-Game of Credit Cards
- codeforces 777b Game of Credit Cards
- Game of Credit Cards (Codeforces-777B)
- CodeForces 626B CodeForces 626B【暴力】
- CodeForces 841B (B) 博弈
- codeforces 134B
- codeforces#98 b
- codeforces 105 div2 B
- Codeforces 166B - Polygons
- codeforces B. Coins
- codeforces----193B Xor
- c程序2
- ELK架构
- c++运算符重载
- [jbb0523整理]压缩感知中的数学知识:NP-hard问题
- 多线程
- codeforces 777B
- jQuery, CSS选择符 属性选择符 自定义选择符1
- SSH pom.xml参考
- 单词数解题报告
- Shell脚本基础17-while循环读取文件内容
- 51Nod 1183
- JAVA Calendar详解
- 如何在IDEA下输入命令行参数
- bzoj 2333: [SCOI2011]棘手的操作 离线+线段树