HDU 6188 Duizi and Shunzi 贪心】的更多相关文章

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6188 题意:给了n个数,然后现在问我们最多构成多少个对子和顺子,其中对子是2个相同的牌,顺子是3个连续的牌. 解法:考虑贪心,我们尽量放对子,但是有一种特殊情况就是,我们可以退一个对子出来和周围的相邻点构成顺子. #include <bits/stdc++.h> using namespace std; const int maxn = 1e6+6; int cnt[maxn]; int main…
栈. 将数字排序后,一个一个压入栈.如果栈顶两个元素形成了对子,那么$ans+1$,弹出栈顶两个元素:如果栈顶三个元素形成了顺子,那么$ans+1$,弹出栈顶三个元素. #include<bits/stdc++.h> using namespace std; const int maxn = 1000000 + 10; int n; int a[maxn]; int b[maxn]; int c[maxn]; int main() { while(~scanf("%d",…
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 Problem Description Nike likes playing cards and makes a problem of it. Now give you n integ…
2017ACM/ICPC广西邀请赛 重现赛1007 Duizi and Shunzi 题意 有n张牌,问你最多能组成多少对子+顺子?一个牌只能用在一个顺子或者对子中. 题解 本来想写dp的,不会..小伙伴用dp做的,dp[i][0..1][0..1]表示前i个牌最后两张是否用掉的最大值. 正解贪心就好了.一个牌能作为顺子的最大值,就取这个顺子,然后取对子.要排序去重再考虑. 因为能做顺子,说明前面两张牌剩下了,如果这张牌也能取对子,贡献也是1,而取顺子还可以剩下1张,所以不会更差. 代码 con…
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 Problem Description Nike likes playing cards and makes a problem of it. Now give you n integ…
hdu 4825 Xor Sum(trie+贪心) 刚刚补了前天的CF的D题再做这题感觉轻松了许多.简直一个模子啊...跑树上异或x最大值.贪心地让某位的值与x对应位的值不同即可. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #define CLR(a,b) memset((a),(b),sizeof(…
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, a…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6188 题意 有n个数字,每个数字小于等于n,两个相同的数字价值为1,三个连续的数字价值为1 .问这n个数字的最大价值是多少 思路 用map对这n个数字中每个数字出现的次数进行统计,用ans记录总价值.然后从数字1开始向后考虑,如果数字i出现的次数不小于2,那么ans加上数字i出现的次数除以二(两个相同的数字价值为1),然后让这个次数对2取模,接下来判断数字i还有没有(即:是否为1):如果为1,考虑数…
题意 有n张牌,第i张牌上的数字是a[i].我们定义 两张数字是一样的牌 为对子.我们定义 三张数字连续的牌 为顺子.我们想把这n张牌组成尽可能多的顺子和对子.请计算并输出能组成的最多的顺子和对子的数量. 分析 我是傻逼我是傻逼我是傻逼!重要的事情说三遍!! 这是一道贪心,而且是并不是很复杂的贪心,但是我在场上坚定的认为他是个dp然后连写带调两个小时才过掉它! 结束后我在网上查了一下,果然只有我这么傻逼,但是我还是想把这个奇怪的dp思路写下来··· 我们定义f[i]为前i张牌中对子和顺子最多的数…
Elegant Construction 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5813 Description Being an ACMer requires knowledge in many fields, because problems in this contest may use physics, biology, and even musicology as background. And now in this prob…
Windows 10 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5802 Description Long long ago, there was an old monk living on the top of a mountain. Recently, our old monk found the operating system of his computer was updating to windows 10 automatical…
Reorder the Books Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5500 Description dxy家收藏了一套书,这套书叫<SDOI故事集>,<SDOI故事集>有n(n≤19)n(n\leq 19)n(n≤19)本,每本书有一个编号,从111号到nnn号. dxy把这些书按编号从小到大,从上往下摞成一摞.dxy对这套书极其重视,不允许…
Four Operations Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 22    Accepted Submission(s): 12 Problem Description Little Ruins is a studious boy, recently he learned the four operations!Now h…
题目链接:pid=3697" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=3697 Problem Description     A new Semester is coming and students are troubling for selecting courses. Students select their course on the web course system. There…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5281 贪心题目,但是看看我的博客里边相关贪心的题解实在是少的可怜,这里就写出来供大家一起探讨. 题意还是比较好理解的,这里有一个小小的坑点:枪的数量,和怪物的数量,不一定是相等的,所以我们这里要特殊处理一下. reverse函数:http://blog.sina.com.cn/s/blog_6d79d83a0100wh95.html #include <stdio.h> #include <…
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 inte…
第一题;http://acm.hdu.edu.cn/showproblem.php?pid=1257 贪心与dp傻傻分不清楚,把每一个系统的最小值存起来比较 #include<cstdio> using namespace std; ],b[]; int main() { int n,i,j; while (~scanf("%d",&n)) { ; b[]=-; ;i<n;i++) { scanf("%d",&a[i]); ;j&l…
http://acm.hdu.edu.cn/showproblem.php?pid=5073 就是给你 n 个数,代表n个星球的位置,每一个星球的重量都为 1 开始的时候每一个星球都绕着质心转动,那么质心的位置就是所有的星球的位置之和 / 星球的个数 现在让你移动 k 个星球到任意位置(多个星球可以在同一个位置并且所有的星球在同一直线上) 移动之后那么它们质心的位置就可能发生变化,求 I = sum(di^2) (di表示第i个星球到达质心的距离)最小 根据方差的性质(越密越小)得知贪心策略就是…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 /*Doing Homework again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7903 Accepted Submission(s): 4680 Problem Description Ignatius has just c…
Divide the Sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5783 Description Alice has a sequence A, She wants to split A into as much as possible continuous subsequences, satisfying that for each subsequence, every its prefix sum is not smal…
Keep On Movin 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5744 Description Professor Zhang has kinds of characters and the quantity of the i-th character is ai. Professor Zhang wants to use all the characters build several palindromic strings. He…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem DescriptionIgnatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Eve…
HDU 4957 Poor Mitsui pid=4957" style="">题目链接 思路:利用相邻交换法去贪心就可以.注意容积为0的情况,这是个坑点 代码: #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int N = 45; struct SB { int a, b; } sb[N]; bool cmp(…
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5661 bc(中文):http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=686&pid=1002 题解: 考虑从高位到低位贪心,对于每一位, (1).如果x,y只有唯一的取法,那么只能这么取:否则贪心地必须使答案的这一位等于1. (2).如果x,y都是0,1都能取,则设这是从右向左数第len位,因为x,y能…
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=4864 Task Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 11382    Accepted Submission(s): 2782 Problem Description Today the company has m tasks t…
HDOJ(HDU).1864 最大报销额 题意分析 题目有点问题,原题中说的 单项物品的价值不得超过600元 应该是单类物品的价值不能超过600元. 一开始以为是01背包,后来按贪心写过了. 一张一张发票处理,读入一整张发票的数据.然后检查一下里面是否有不能报销的类别(即除ABC)以外的其他类.然后看一下单类的价钱是否超过600.如都满足题目所说能够报销的要求,则把它存到b数组里面,接着对b数组按照金额降序排序,结合给的经费,先报销大的,再报销小的,遍历一遍即可. 代码总览 #include <…
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1677 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=28195#problem/E Nested Dolls Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1876    Acc…
Balala Power! Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1411    Accepted Submission(s): 239 Problem Description Talented Mr.Tang has n strings consisting of only lower case characters.…
手动博客搬家:本文发表于20170822 21:30:17, 原地址https://blog.csdn.net/suncongbo/article/details/77488127 URL: http://acm.hdu.edu.cn/showproblem.php?pid=2795题目大意:有一个h*w的木板 (h, w<=1e9), 现在有n (n<=2e5)张1*xi的海报要贴在木板上,按1~n的顺序每次贴海报时会选择最上的一排的最左边贴 (海报不能互相覆盖), 求每张海报会被贴在哪一行…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5303 Problem Description There are n apple trees planted along a cyclic road, which is L metres long. Your storehouse is built at position 0 on that cyclic road. The ith tree is planted at position xi,…