Duizi and Shunzi HDU
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
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.
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)
Case 1(1,2,3)(4,5,6)

#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+5;
int a[maxn];
int main()
{
int n;
while(~scanf("%d",&n))
{
memset(a,0,sizeof(a));
int t;
for(int i=0;i<n;i++)
{
scanf("%d",&t);
a[t]++;
}
int ans=0;
for(int i=1;i<=n;i++)
{
ans+=a[i]/2;
if(i<=n-2 && a[i]%2 && a[i+1]%2 && a[i+2])
{
ans++;
a[i]--;
a[i+1]--;
a[i+2]--;
}
}
printf("%d\n",ans);
}
}

Duizi and Shunzi HDU的更多相关文章
- Duizi and Shunzi HDU - 6188 (贪心)2017 广西ACM/ICPC
Duizi and Shunzi Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 【hdu6188】Duizi and Shunzi(贪心)
2017ACM/ICPC广西邀请赛 重现赛1007 Duizi and Shunzi 题意 有n张牌,问你最多能组成多少对子+顺子?一个牌只能用在一个顺子或者对子中. 题解 本来想写dp的,不会..小 ...
- 2017ACM/ICPC广西邀请赛 1007 Duizi and Shunzi
Duizi and Shunzi Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 6188:Duizi and Shunzi(贪心)(广西邀请赛)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6188 题意 有n个数字,每个数字小于等于n,两个相同的数字价值为1,三个连续的数字价值为1 .问这n个 ...
- HDU 6188 Duizi and Shunzi 贪心
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6188 题意:给了n个数,然后现在问我们最多构成多少个对子和顺子,其中对子是2个相同的牌,顺子是3个连续 ...
- HDU 6188 Duizi and Shunzi
栈. 将数字排序后,一个一个压入栈.如果栈顶两个元素形成了对子,那么$ans+1$,弹出栈顶两个元素:如果栈顶三个元素形成了顺子,那么$ans+1$,弹出栈顶三个元素. #include<bit ...
- 2017ACM/ICPC广西邀请赛-重现赛 1007.Duizi and Shunzi
Problem Description Nike likes playing cards and makes a problem of it. Now give you n integers, ai( ...
- hdu6188 Duizi and Shunzi (贪心或者dp)
题意 有n张牌,第i张牌上的数字是a[i].我们定义 两张数字是一样的牌 为对子.我们定义 三张数字连续的牌 为顺子.我们想把这n张牌组成尽可能多的顺子和对子.请计算并输出能组成的最多的顺子和对子的数 ...
- 2017ACM/ICPC广西邀请赛 Duizi and Shunzi
题意:就是一个集合分开,有两种区分 对子:两个相同数字,顺子:连续三个不同数字,问最多分多少个 解法:贪心,如果当前数字不构成顺子就取对子 /2,如果可以取顺子,那么先取顺子再取对子 #include ...
随机推荐
- ctf-ping命令执行绕过
题目连接:http://ctf.klmyssn.com/challenges#Ping 命令执行绕过,试了试过滤了一些:一些命令 但是反引号可以执行命令 通过拼接,可以拼接出来:ls 命令 127.0 ...
- Mybatis核心知识点
一.初识Mybatis框架 mybatis是一个持久层的框架,是apache下的顶级项目. mybatis托管到goolecode下,再后来托管到github下(https://github.com/ ...
- unittest框架下的HTMLTestRunner报告模块使用及优化
引言 在做接口自动化测试的时候,使用python单元测试框架unittest下HTMLTestRunner报告模板,可以很好的展示我们测试结果的数据. 官方的标准版模板地址:http://tungwa ...
- c++踩坑大法好 typedef和模板
1,typedef字面意思,自定义一种数据类型 语法:typedef 类型名称 类型标识符; 基本用法: 1) 为基本数据类型定义新的类型名. 2) 为自定义数据类型(结构体.公用体和枚举类型)定义简 ...
- JUC-ThreadPool线程池
一.为什么用线程池 例子:10年前单核CPU电脑,假的多线程,像马戏团小丑玩多个球,CPU需要来回切换. 现在是多核电脑,多个线程各自跑在独立的CPU上,不用切换效率高. 线程池的优势: 线程池做的工 ...
- 杭电oj_1713——相遇周期(java实现)
question:相遇周期 思路: 首先将两个分数化为最简形式(也就是分子分母同时除以最大公约数) 然后题意是要求两个分数的最小公倍数 借助以下两个公式,就可以求出结果 1.最小公倍数*最大公约数 = ...
- 【PAT甲级】1115 Counting Nodes in a BST (30分)(二叉查找树)
题意: 输入一个正整数N(<=1000),接着输入N个整数([-1000,1000]),依次插入一棵初始为空的二叉排序树.输出最底层和最底层上一层的结点个数之和,例如x+y=x+y. AAAAA ...
- 修改oracle数据库用户名和密码
第一步:连接数据库 使用ssh工具以root身份连接服务器, 然后切换到oracle用户:su - oracle(回车) 使用sqlplus连接数据库:sqlplus /nolog(回车) 以管理员身 ...
- Myeclipse异常
打不开文件 问题描述:Myeclipse然打开什么东西都报错了:Could not open the editor: Invalid thread access 解决方法:1.cmd 2.cd 进入你 ...
- pygame 浅解
import pygame from first_pygame.plane_spirit import * # 调用重载的精灵类 # 初始化 pygame.init() # 初始化所有所需游戏模块 s ...