Duizi and Shunzi

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

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

 
 //2017-08-31
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int N = ;
int arr[N], n;
bool book[N]; int main()
{
//freopen("input1007.txt", "r", stdin);
while(scanf("%d", &n) != EOF){
for(int i = ; i < n; i++)
scanf("%d", &arr[i]);
sort(arr, arr+n);
memset(book, , sizeof(book));
int ans = ;
for(int i = ; i < n; i++){
if(i >= ){
int p1 = -, p2 = -;
for(int j = i-; j >= ; j--){
if(arr[j] == arr[i]- && !book[j]){
p1 = j;
}
if(arr[j] == arr[i]- && !book[j]){
p2 = j;
break;
}
if(arr[j] < arr[i]-)break;
}
if(p1 != - && p2 != -){
ans++;
book[i] = book[p1] = book[p2] = ;
}
}
if(arr[i-] == arr[i] && !book[i-] && !book[i]){
ans++;
book[i-] = book[i] = ;
}
}
printf("%d\n", ans);
} return ;
}

HDU6188的更多相关文章

  1. 【hdu6188】Duizi and Shunzi(贪心)

    2017ACM/ICPC广西邀请赛 重现赛1007 Duizi and Shunzi 题意 有n张牌,问你最多能组成多少对子+顺子?一个牌只能用在一个顺子或者对子中. 题解 本来想写dp的,不会..小 ...

  2. hdu6188 Duizi and Shunzi (贪心或者dp)

    题意 有n张牌,第i张牌上的数字是a[i].我们定义 两张数字是一样的牌 为对子.我们定义 三张数字连续的牌 为顺子.我们想把这n张牌组成尽可能多的顺子和对子.请计算并输出能组成的最多的顺子和对子的数 ...

  3. hdu6188&&百度之星初赛(B) T5

    度度熊的交易计划 Problem Description 度度熊参与了喵哈哈村的商业大会,但是这次商业大会遇到了一个难题: 喵哈哈村以及周围的村庄可以看做是一共由n个片区,m条公路组成的地区. 由于生 ...

  4. CF-1110 (2019/02/08)

    CF-1110 A. Parity 快速幂的思想,考虑最后一位即可 #include <bits/stdc++.h> using namespace std; typedef long l ...

随机推荐

  1. 25_re模块

    一.re模块的核心功能       1.findall —— 查找所有,返回list lst = re.findall("m", "mai le fo len, mai ...

  2. 连接dubbox注册中心的端口默认是20880

    pyg服务工程  都没用到20880 都没用默认,从20881 开始用,第二个服务工程 的则为20882 <dubbo:protocol name="dubbo" port= ...

  3. word2vec的原理(一)

    最近上了公司的新员工基础培训课,又对NLP重新产生的兴趣.NLP的第一步大家知道的就是不停的写正则,那个以前学的还可以就不看了.接着就是我们在把NLP的词料在传入神经网络之前的一个预处理,最经典的就是 ...

  4. 大众点评Cat--架构分析

    转自:http://blog.csdn.net/szwandcj/article/details/51025669 Cat功能强大且多,光日志的报表和图表分析就有十几种,但文档却很少,寥寥无几找到一些 ...

  5. flex定位下overflow失效的问题研究

    概述 这是我在写移动端页面遇到的问题及解决方法,记录下来供以后开发时参考,相信对其他人也有用. 问题 之前写移动端页面,有一个顶条是导航条,需要固定在页面顶部,并且里面的元素需要可以左右滚动. 但是当 ...

  6. linux的Yum软件包管理工具

    Yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及CentOS中的Shell前端软件包管理器.基于RPM包管理,能够从指定的服务器自动下载 ...

  7. dubbo+zookeeper注册服务报错问题:No service registed on zookeeper

    2019-04-04 11:23:40,372 ERROR [tomcat-threads--1] (com.bill99.dolphin.controller.ExceptionController ...

  8. (转)面向对象(深入)|python描述器详解

    原文:https://zhuanlan.zhihu.com/p/32764345 https://www.cnblogs.com/aademeng/articles/7262645.html----- ...

  9. 理解web service 和 SOA

    什么是SOA? SOA的全称为Service Oriented Architecture,即面向服务架构.这是一种架构理念.它的提出是在企业计算领域将耦合的系统划分为松耦合的无状态的服务.服务发布出来 ...

  10. django2笔记:路由path语法

    django2笔记:路由path语法 9月23,Django 发布了2.0a1版本,这是一个 feature freeze 版本,如果没有什么意外的话,2.0正式版不会再增加新的功能了.按照以往的规律 ...