2017广西邀请赛/hdu
来源:互联网 发布:北京大学大数据专业 编辑:程序博客网 时间:2024/03/29 18:22
Duizi and Shunzi
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 245 Accepted Submission(s): 115
Problem Description
Nike likes playing cards and makes a problem of it.
Now give you n integers,ai(1≤i≤n)
We define two identical numbers (eg:2,2 ) a Duizi,
and three consecutive positive integers (eg:2,3,4 ) a Shunzi.
Now you want to use these integers to form Shunzi and Duizi as many as possible.
Let s be the total number of the Shunzi and the Duizi you formed.
Try to calculatemax(s) .
Each number can be used only once.
Now give you n integers,
We define two identical numbers (eg:
and three consecutive positive integers (eg:
Now you want to use these integers to form Shunzi and Duizi as many as possible.
Let s be the total number of the Shunzi and the Duizi you formed.
Try to calculate
Each number can be used only once.
Input
The input contains several test cases.
For each test case, the first line contains one integer n(1≤n≤106 ).
Then the next line contains n space-separated integersai (1≤ai≤n )
For each test case, the first line contains one integer n(
Then the next line contains n space-separated integers
Output
For each test case, output the answer in a line.
Sample Input
71 2 3 4 5 6 791 1 1 2 2 2 3 3 362 2 3 3 3 3 61 2 3 3 4 5
Sample Output
2432HintCase 1(1,2,3)(4,5,6)Case 2(1,2,3)(1,1)(2,2)(3,3)Case 3(2,2)(3,3)(3,3)Case 4(1,2,3)(3,4,5)
Source
2017ACM/ICPC广西邀请赛-重现赛(感谢广西大学)
Recommend
liuyiding | We have carefully selected several similar problems for you: 6193 6192 6191 6190 6189
对子: (2,2),顺子: (1,2,3)。
贪心思路,优先考虑对子,其次是顺子,详见代码
#include <iostream>#include <algorithm>#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <string.h>#include <map>#include <set>#include <queue>#include <deque>#include <list>#include <bitset>#include <stack>#include <stdlib.h>#define lowbit(x) (x&-x)#define e exp(1.0)#define eps 1e-8//ios::sync_with_stdio(false);// auto start = clock();// cout << (clock() - start) / (double)CLOCKS_PER_SEC<<endl;typedef long long ll;typedef long long LL;using namespace std;typedef unsigned long long ull;const int maxn=1e6+10;int a[maxn];int main(){ ios::sync_with_stdio(false); int n; while(cin>>n) { int x; memset(a,0,sizeof(a)); for(int i=0;i<n;i++) cin>>x,a[x]++; int ans=0; for(int i=1;i<=n;i++) { ans+=(a[i]/2); a[i]%=2; if(i+1<n) { if(a[i]==1 && a[i+1]%2 && a[i+2]) { ans++; a[i]--; a[i+1]--; a[i+2]--; } } } cout<<ans<<endl; } return 0;}
阅读全文
0 0
- 2017广西邀请赛/hdu
- HDU 6186 && 2017广西邀请赛:CS Course
- 【2017广西邀请赛】hdu 6186 CS Course
- HDU 6182 && 2017广西邀请赛:A Math Problem
- HDU 6188 && 2017广西邀请赛:Duizi and Shunzi
- HDU 6185 && 2017广西邀请赛:Covering(矩阵快速幂)
- HDU 6184 && 2017广西邀请赛:Counting Stars(三元环)
- HDU 6183 && 2017广西邀请赛:Color it(线段树)
- hdu 6182A Math Problem/2017ACM/ICPC广西邀请赛
- hdu Covering 2017广西邀请赛 矩阵快速幂
- 【2017广西邀请赛】hdu 6182 A Math Problem
- 【2017广西邀请赛】hdu 6188 Duizi and Shunzi 贪心
- HDU 6184&& 2017广西邀请赛 Counting Stars(三元环计数)
- 【2017广西邀请赛】hdu 6185 Covering 矩阵快速幂
- 【2017广西邀请赛】hdu 6184 Counting Stars 三元环+set
- 广西 2017 邀请赛 CS Course
- 2017年广西邀请赛总结
- 2017ACM/ICPC广西邀请赛
- Python字符串操作
- 桶排序—C—Python
- 银行卡号验证
- 文本
- docker容器内服务随容器启动而自启动
- 2017广西邀请赛/hdu
- 检测文本文件编码方式的策略
- MySQL设置多列为唯一约束,即多列不能同时相同
- 操作系统学习_Linux0.12_引导部分为什么要用两种语法写
- 技术岗网上测评-智力题
- Java 取模 取余
- 支付宝也开始做小程序了 对微信小程序来说喜忧参半
- 接口测试基础-3-接口测试工具介绍
- ubuntu 用git