CF #651B. Beautiful Paintings
来源:互联网 发布:谭咏麟你知我知被禁 编辑:程序博客网 时间:2024/05/16 15:31
题意:n个数,现在以任意的顺序排列,使a[i]+1>a[i],这样的对数最多。
分析:
方法一:先排序。对每一个数,向后扫描比它大的那个数,
方法二 :如果n个数都不相同,则必有n-1对符合要求,一旦有最大重复数字个数为m,则有n-1-m对。符合要求。
/*method ——1*//*#include<bits/stdc++.h>using namespace std;int a[1005],vis[1005];int main(){ int n; while(~scanf("%d",&n)) { for(int i=0;i<n;i++) scanf("%d",a+i); sort(a,a+n); memset(vis,0,sizeof(vis)); int flag,num=0; for(int i=0;i<n;i++) { flag=a[i]; for(int j=i+1;j<n;j++) if(a[j]>flag&&(!vis[j])) { num++; vis[j]=1; break; } } printf("%d\n",num); } return 0;}
/*method --2*/#include<bits/stdc++.h>using namespace std;int a[1002],xx=0;int main(){ int n,x; cin>>n; for(int i=0;i<n;i++) cin>>x,xx=max(xx,a[x]++); printf("%d\n",n-xx-1); return 0;}
0 0
- CF #651B. Beautiful Paintings
- cf#345-B - Beautiful Paintings-暴力
- codeforces--651B Beautiful Paintings
- codeforces 651B Beautiful Paintings
- CodeForces 651B Beautiful Paintings
- codeforces 651B Beautiful Paintings
- CodeForces 651B Beautiful Paintings
- 【CodeForces】651B - Beautiful Paintings
- 【CodeForces】[651B]Beautiful Paintings
- CodeForces 651B Beautiful Paintings
- CodeForces 651B Beautiful Paintings
- Codeforces 651B Beautiful Paintings
- cf 345-B - Beautiful Paintings 暴力什么的太水了
- codeforces 651B Beautiful Paintings (想法)
- codeforces 651B Beautiful Paintings【优先队列】
- Codeforces 651B Beautiful Paintings【思维】
- codeforces 651B Beautiful Paintings(贪心)
- Codeforces 651B Beautiful Paintings【贪心】
- HDU 2.1.7 整数对
- 第二周项目-小试循环
- HDU 2.1.8 The area
- iOS开发bundle对象使用详解
- 如何让处于文档流中间的tab标签页滚动到顶部时固定
- CF #651B. Beautiful Paintings
- 使用Eclipse插件DB viewer进行MySQL数据库操作
- HDU 1.3.3 排名
- 水牛VPN,
- UML类图几种关系的总结
- Pku oj 1064 Cable master(二分搜索)
- HDU 1.3.4 百步穿杨
- 针对Android Service不能隐式启动的问题
- LEETCODE 160