Duizi and Shunzi

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

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)

 
 
题解:使用数组保存了每一个数字出现的次数
然后成1开始  循环到n    1ms的时间就可以了
dp记录的是前面循序的长度dp=0,1,2      ans记录的是答案     当你到了第i的数的时候   分以下情况
 
1》如果数据中没有i,也就是b[i]=0;那么把dp置0就好了
2》如果数据中有   然后dp=2了   那么不管有多少个i    我拿去一个i和前面的i-1,i-2放一起,形成一对  是最优的   (这你要明白)
3》如果数据中有   然后dp=0,1     要是i的数目是奇数   那就多出来的那个i   就和i-1放一起   dp++    不然的话  dp=0  ans+=b[i]/2;
 
 
 
 #include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cstring>
#include <math.h>
using namespace std;
int b[];
//int qyh[10010],hyh[10010];
int main()
{
int a,n;
while(~scanf("%d",&n))
{
for(int i=; i<; ++i)
{
b[i]=;
}
for(int i=; i<n; ++i)
{
scanf("%d",&a);
b[a]++;
}
int dp=;
int ans=;
for(int i=; i<=n; ++i)
{
if(b[i]==)
{
dp=;
continue;
}
if(dp==)
{
ans+=;
ans+=(b[i]-)/;
dp=(b[i]-)%;
}
else if(dp==)
{
if(b[i]%==)
{
dp++;
ans+=b[i]/;
}
else
{
dp=;
ans+=b[i]/;
}
}
else if(dp==)
{
if(b[i]%==)
{
dp++;
ans+=b[i]/;
}
else
{
dp=;
ans+=b[i]/;
}
}
}
printf("%d\n",ans);
}
return ;
}

2017ACM/ICPC广西邀请赛 1007 Duizi and Shunzi的更多相关文章

  1. 2017ACM/ICPC广西邀请赛-重现赛

    HDU 6188 Duizi and Shunzi 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6188 思路: 签到题,以前写的. 实现代码: #inc ...

  2. 2017ACM/ICPC广西邀请赛

    A.A Math Problem #include <bits/stdc++.h> using namespace std; typedef long long ll; inline ll ...

  3. 2017ACM/ICPC广西邀请赛-重现赛(感谢广西大学)

    上一场CF打到心态爆炸,这几天也没啥想干的 A Math Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/3 ...

  4. 2017ACM/ICPC广西邀请赛-重现赛 1007.Duizi and Shunzi

    Problem Description Nike likes playing cards and makes a problem of it. Now give you n integers, ai( ...

  5. 2017ACM/ICPC广西邀请赛 Duizi and Shunzi

    题意:就是一个集合分开,有两种区分 对子:两个相同数字,顺子:连续三个不同数字,问最多分多少个 解法:贪心,如果当前数字不构成顺子就取对子 /2,如果可以取顺子,那么先取顺子再取对子 #include ...

  6. 2017ACM/ICPC广西邀请赛-重现赛 1010.Query on A Tree

    Problem Description Monkey A lives on a tree, he always plays on this tree. One day, monkey A learne ...

  7. 2017ACM/ICPC广西邀请赛-重现赛 1004.Covering

    Problem Description Bob's school has a big playground, boys and girls always play games here after s ...

  8. HDU 6191 2017ACM/ICPC广西邀请赛 J Query on A Tree 可持久化01字典树+dfs序

    题意 给一颗\(n\)个节点的带点权的树,以\(1\)为根节点,\(q\)次询问,每次询问给出2个数\(u\),\(x\),求\(u\)的子树中的点上的值与\(x\)异或的值最大为多少 分析 先dfs ...

  9. 2017ACM/ICPC广西邀请赛-重现赛 1001 A Math Problem

    2017-08-31 16:48:00 writer:pprp 这个题比较容易,我用的是快速幂 写了一次就过了 题目如下: A Math Problem Time Limit: 2000/1000 M ...

随机推荐

  1. Python开发笔记:网络数据抓取

    网络数据获取(爬取)分为两部分: 1.抓取(抓取网页) · urlib内建模块,特别是urlib.request · Requests第三方库(中小型网络爬虫的开发) · Scrapy框架(大型网络爬 ...

  2. input 时间字段默认值

    背景: 时间字段展示默认值,开始时间为当天 0点,结束时间为当天晚上12点 代码: <input style="Width: 180px;float:left ;" type ...

  3. 7、Python变量流程基础(变量、赋值、格式化、运算符、流程控制、range()函数)

    一.执行Python程序的两种方式 1.交互式 在终端内输入“python3”,然后输入python代码 2.命令行式 在终端内输入“python3 文本文件路径” 二.变量 1.变量的组成 Pyth ...

  4. Dubbo源码分析:Filter

    类图 Filter链 在ProtocolFilterWrapper对象中完成Filter完成组建. 实现代码

  5. hibernate之多对多关系

    hibernate的多对多hibernate可以直接映射多对多关联关系(看作两个一对多) 下面我们拿三张表来做实例 t_book_hb t_book_category_hb(桥接表) t_catego ...

  6. IIS 站点配置文件

    IIS 站点配置文件  C:/Windows/System32/inetsrv/config/applicationHost.config 配置文件示例: <system.application ...

  7. 第03组 团队git现场编程实战

    1.组员职责分工 张逸杰:复制监督整个编程任务的进程以及协助组员编程 黄智锋.刘汪洋:负责UI设计 苏凯婷.鲍冰如:爬取数据并负责测评出福州最受欢迎的商圈 陈荣杰.杨锦镔:爬取数据并负责测评出福州人均 ...

  8. c++ 题解

    43题 #include <random> #include <iostream> int main() { ][] = { {,,,}, {,,,}, {,,,}}; ; n ...

  9. c博客作业—分支,结构顺序

    1展现PTA总分 1 2 2本章学习类容总结 1常量和变量 常量:在运行中其值不变的量被称为常量,常量的类型通常是由书写格式决定,包括整型常量,实数型变量等等. 变量: 在运行中其值可变的量被称为变量 ...

  10. Centos 7 更换为 阿里云 yum 源

    地址: https://opsx.alibaba.com/ 操作步骤: 1.备份 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentO ...