Duizi and Shunzi

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2883    Accepted Submission(s): 1110

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 calculate max(s).

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 integers ai (1≤ai≤n)

 
Output
For each test case, output the answer in a line.
 
Sample Input
7
1 2 3 4 5 6 7
9
1 1 1 2 2 2 3 3 3
6
2 2 3 3 3 3
6
1 2 3 3 4 5
 
Sample Output
2
4
3
2
Hint

Case 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
 
 
题意:输入一个n,然后输入n张牌,每张牌都不大于n,问可以组成最多的对子数和顺子数,对子是两个相同的牌,顺子是连续的三张牌
思路:从1到n遍历, 如果第 i 张牌能打完对子还有多一张,那么看 i+1 张打完对子是不是可以多,如果多的话只要 i+2 有这张牌就可以打出一个顺子,在计算第 i 张牌的时候记得把对子的数量加进去,在可以组成顺子的时候记得把 第 i+1 和 i +2 凑顺子的那一张牌减掉。
 
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
using namespace std;
#define INF 0x3f3f3f3f
#define eps 1e-10
#define PI acos(-1.0)
#define _e exp(1.0)
#define ll long long
const int maxn=1e6+;
int a[maxn];
int main()
{
int n;
while(~scanf("%d",&n))
{
memset(a,,sizeof(a));
int t;
for(int i=;i<n;i++)
{
scanf("%d",&t);
a[t]++;
}
int ans=;
for(int i=;i<=n;i++)
{
ans+=a[i]/;
if(i<=n- && a[i]% && a[i+]% && a[i+])
{
ans++;
a[i]--;
a[i+]--;
a[i+]--;
}
}
printf("%d\n",ans);
}
}

Duizi and Shunzi HDU - 6188 (贪心)2017 广西ACM/ICPC的更多相关文章

  1. hdu 5016 点分治(2014 ACM/ICPC Asia Regional Xi'an Online)

    Mart Master II Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  2. Duizi and Shunzi HDU

    Duizi and Shunzi Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. 【贪心】【模拟】HDU 5491 The Next (2015 ACM/ICPC Asia Regional Hefei Online)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5491 题目大意: 一个数D(0<=D<231),求比D大的第一个满足:二进制下1个个数在 ...

  4. Hdu OJ 5884-Sort (2016 ACM/ICPC Asia Regional Qingdao Online)(二分+优化哈夫曼)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5884 题目大意:有n个有序的序列,对于第i个序列有ai个元素. 现在有一个程序每次能够归并k个序列, ...

  5. HDU 4749 Parade Show 2013 ACM/ICPC Asia Regional Nanjing Online

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4749 题目大意:给一个原序列N,再给出一个序列M,问从N中一共可以找出多少个长度为m的序列,序列中的数 ...

  6. 【二分】【最长上升子序列】HDU 5489 Removed Interval (2015 ACM/ICPC Asia Regional Hefei Online)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5489 题目大意: 一个N(N<=100000)个数的序列,要从中去掉相邻的L个数(去掉整个区间 ...

  7. HDU 4751 Divide Groups 2013 ACM/ICPC Asia Regional Nanjing Online

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4751 题目大意:判断一堆人能否分成两组,组内人都互相认识. 解题思路:如果两个人不是相互认识,该两人之 ...

  8. HDU 4731 Minimum palindrome 2013 ACM/ICPC 成都网络赛

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4731 题解:规律题,我们可以发现当m大于等于3时,abcabcabc……这个串的回文为1,并且字典数最小 ...

  9. HDU 4734 F(x) 2013 ACM/ICPC 成都网络赛

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4734 数位DP. 用dp[i][j][k] 表示第i位用j时f(x)=k的时候的个数,然后需要预处理下小 ...

随机推荐

  1. 4、kvm相关网卡操作(添加、删除)

    查看虚拟机的网卡信息 virsh domiflist privi-server 添加临时网卡 virsh attach-interface privi-server --type bridge --s ...

  2. TCP/IP三次握手与四次挥手的正确姿势

    0.史上最容易理解的:TCP三次握手,四次挥手 https://cloud.tencent.com/developer/news/257281 A 理解TCP/IP三次握手与四次挥手的正确姿势http ...

  3. 011 Container With Most Water 盛最多水的容器

    给定 n 个非负整数 a1,a2,…,an,每个数代表坐标中的一个点 (i, ai) .画 n 条垂直线,使得垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0).找出其中的两条线,使得它们 ...

  4. (转)Mysql数据库之Binlog日志使用总结Linux下用户组、文件权限详解

    Linux下用户组.文件权限详解 原文:http://blog.csdn.net/sdulibh/article/details/51566772 用户组 在linux中的每个用户必须属于一个组,不能 ...

  5. Storm概念学习系列之storm的功能和三大应用

    不多说,直接上干货! storm的功能 Storm 有许多应用领域:实时分析.在线机器学习.持续计算.分布式 RPC(远过程调用协议,一种通过网络从远程计算机程序上请求服务). ETL(Extract ...

  6. 一步一步配置Spring

    https://blog.csdn.net/tangtong1/article/details/51442757

  7. wamp 下运行Drupal慢的解决方法

    1.Editing your php.ini and make realpath_cache_size=2M, 2.uncomment skip innodb in your my.cnf(my.in ...

  8. prototype 以及 constructor 属性的理解

    1 为什么 xx.constructor.prototype 可以访问到当前对象的原型. 'str'.constructor.prototype      'str'.constructor 指向当前 ...

  9. SQL Server收缩数据库

    USE[master]GOALTER DATABASE CCPG_SFY SET RECOVERY SIMPLE WITH NO_WAITGOALTER DATABASE CCPG_SFY SET R ...

  10. 用命令行的方式将本地项目上传到git

    1.(先进入项目文件夹)通过命令 git init 把这个目录变成git可以管理的仓库 git init 2.把文件添加到版本库中,使用命令 git add .添加到暂存区里面去,不要忘记后面的小数点 ...