2017ACM/ICPC广西邀请赛 1007 Duizi and Shunzi
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
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.
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
)
line.
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
4
3
2
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)
#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的更多相关文章
- 2017ACM/ICPC广西邀请赛-重现赛
HDU 6188 Duizi and Shunzi 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6188 思路: 签到题,以前写的. 实现代码: #inc ...
- 2017ACM/ICPC广西邀请赛
A.A Math Problem #include <bits/stdc++.h> using namespace std; typedef long long ll; inline ll ...
- 2017ACM/ICPC广西邀请赛-重现赛(感谢广西大学)
上一场CF打到心态爆炸,这几天也没啥想干的 A Math Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/3 ...
- 2017ACM/ICPC广西邀请赛-重现赛 1007.Duizi and Shunzi
Problem Description Nike likes playing cards and makes a problem of it. Now give you n integers, ai( ...
- 2017ACM/ICPC广西邀请赛 Duizi and Shunzi
题意:就是一个集合分开,有两种区分 对子:两个相同数字,顺子:连续三个不同数字,问最多分多少个 解法:贪心,如果当前数字不构成顺子就取对子 /2,如果可以取顺子,那么先取顺子再取对子 #include ...
- 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 ...
- 2017ACM/ICPC广西邀请赛-重现赛 1004.Covering
Problem Description Bob's school has a big playground, boys and girls always play games here after s ...
- HDU 6191 2017ACM/ICPC广西邀请赛 J Query on A Tree 可持久化01字典树+dfs序
题意 给一颗\(n\)个节点的带点权的树,以\(1\)为根节点,\(q\)次询问,每次询问给出2个数\(u\),\(x\),求\(u\)的子树中的点上的值与\(x\)异或的值最大为多少 分析 先dfs ...
- 2017ACM/ICPC广西邀请赛-重现赛 1001 A Math Problem
2017-08-31 16:48:00 writer:pprp 这个题比较容易,我用的是快速幂 写了一次就过了 题目如下: A Math Problem Time Limit: 2000/1000 M ...
随机推荐
- getProperty获取属性值
- 英语听力,如何成为更好的交谈着https://www.bilibili.com/video/av4279405?from=search&seid=5889429711390689339
and how many of you know at least one person that you because you just do not want to talk to them.y ...
- learning java FileOutputStream
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStrea ...
- 在Modelsim波形窗口复制信号
可以通过张贴复制变量名在Modelsim波形窗口复制信号.
- outlook 修改视图
- java操作数据库,以页面显示学生信息为例
该部分内容实现的功能主要是:从数据库中查询数据并展示到页面,在页面中新增数据信息,在页面中修改数据信息,在页面中删除数据信息. =================stuList.jsp======== ...
- 集合类 collection接口 LinkedList
LinkedList 是另外一种重要的数据结构形式, 底层是使用了双向链表数据结构, 特点: 查询速度慢,增删快. 继承关系如下: 可以发现,LinkedList同时实现了Quene和Deque接口. ...
- Tomcat的并发能力
关注 一.一些限制 Windows 每个进程中的线程数不允许超过 2000 Linux 每个进程中的线程数不允许超过 1000 在 Java 中每开启一个线程需要耗用 1MB 的 JVM 内存空间 ...
- Nginx搭建简单文件下载服务器
在C:\pleiades\nginx-1.16.1下新建一个目录files,然后放入若干文件,接下来修改nginx.conf,增加粗体字如下: #user nobody; worker_process ...
- checkbox与label内的文字垂直居中的解决方案
<label style="float:left;margin-top:5px;margin-left:10px;cursor:pointer"><input t ...