Duizi and Shunzi HDU - 6188 (贪心)2017 广西A…
2018-09-10 00:58:17来源:博客园 阅读 ()
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)
#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); } }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- C++ rand函数 2020-06-10
- Android P HIDL demo代码编写 (原创) 2020-05-07
- C++ STL框架 2020-03-29
- AtCoder Grand Contest 043--A - Range Flip Find Route 2020-03-22
- 在Android平台使用SNPE应链接libc++库 2020-03-17
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash