HDU 6188 Duizi and Shunzi

7人阅读 评论(0) 收藏 举报
分类:

Duizi and Shunzi

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


Problem Description
Nike likes playing cards and makes a problem of it.

Now give you n integers, ai(1in)

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(1n106).
Then the next line contains n space-separated integers ai (1ain)
 

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)
 

Source
 

Recommend
liuyiding   |   We have carefully selected several similar problems for you:  6275 6274 6273 6272 6271 
           

           

                这道题用贪心来做就好~~
#include<iostream>
#include<cstdio>
using namespace std;
int sum[1000005];
int main()
{
	int n;
	int maxn=0;
	while (cin >> n)
	{
		memset(sum, 0, sizeof(sum));
		for (int s = 0; s < n; s++)
		{
			int w;
			scanf("%d", &w);
			if (w > maxn)
			{
				maxn = w;
			}
			sum[w]++;
		}
		int ans = 0;
		for (int s = 1; s <= maxn; s++)
		{
			int te = sum[s] / 2;
	//		cout << te << endl;
			ans += te;
			sum[s] %= 2;
			if (sum[s]==1&&sum[s + 1] % 2 == 1 && sum[s + 2] > 0)
			{
				ans++;
		//		cout << s << endl;
				sum[s]--;
				sum[s + 1]--;
				sum[s + 2]--;
			}
		}
		cout << ans << endl;
	}
	return 0;
}



查看评论

HDU-6188:Duizi and Shunzi

HDU-6188:Duizi and Shunzi Nike likes playing cards and makes a problem of it. Now give you n intege...
  • Mitsuha_
  • Mitsuha_
  • 2017-09-02 18:35:38
  • 318

【贪心】hdu - 6188 Duizi and Shunzi

Problem Description 输入一个n,接下来有n个数,让你求出能组成最多的对子或者顺子的和。 对子: (2,2),顺子: (1,2,3)。 题目链接:http://acm.hd...
  • bbbbswbq
  • bbbbswbq
  • 2017-09-01 09:03:51
  • 465

HDU 6188 Duizi and Shunzi 贪心

题目:http://acm.hdu.edu.cn/showproblem.php?pid=6188题意:给出n个数字,两个相同的数字可以组成对子,三个连续的数字可以组成顺子,问能组成对子和顺子的总数最...
  • discreeter
  • discreeter
  • 2017-08-31 20:03:23
  • 515

Duizi and Shunzi HDU - 6188

Nike likes playing cards and makes a problem of it.  Now give you n integers, ai(1≤i≤n)ai(1≤i≤n) ...
  • CS33sun
  • CS33sun
  • 2017-10-24 20:21:18
  • 76

2017广西邀请赛 G Duizi and Shunzi(贪心)

题目链接:Duizi and Shunzi 题意:问给出一组数,求max(对子数+顺子数)。约定,每个数只能用一次,对子长度为2,顺子长度为3。如22是一对对子,123是一对顺子。 思路:很容易想...
  • qq_33843429
  • qq_33843429
  • 2017-09-13 11:27:01
  • 87

HDU 6188 Duizi and Shunzi(贪心+细节)

题目地址 题意:给你一堆牌,有两种组合方式,问最多能组合成多少个对子和顺子(同牌面的2张可以组成一个对子,连续牌面数字的3张可以组成一个顺子) 思路:这题是贪心写的,我昨天虽然想到了这种方法,但是...
  • xjh_shin
  • xjh_shin
  • 2017-09-01 17:12:28
  • 406

HDU 6188 Duizi and Shunzi(贪心)

Nike likes playing cards and makes a problem of it. Now give you n integers, ai(1≤i≤n)ai(1≤i≤n) ...
  • qq_37497322
  • qq_37497322
  • 2017-09-05 14:56:29
  • 268

hdu 6188 Duizi and Shunzi(贪心)

Duizi and Shunzi Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others...
  • Timeclimber
  • Timeclimber
  • 2018-01-28 19:42:03
  • 67

2017广西邀请赛 Duizi and Shunzi(贪心+DP)

题意:给你n个数,问你最多能组成多少顺子和对子 题解:和bzoj上的一道题类似,不过bzoj上对子是3张牌,所以无脑先选对子即可,然而这道题对子是 两张牌,因此之前的贪心还是有些问题的,比如: 1...
  • haut_ykc
  • haut_ykc
  • 2017-08-31 17:16:09
  • 409

HDU 6188 - Duizi and Shunzi ( 贪心 )

题意 给出n张牌, 每张牌编号为ai, 有两种组成方式, 一种叫”对子”, 也就是两张牌牌面相同, 另一种叫”顺子”, 也就是三张牌牌面连续, 每张牌最多只能用一次, 求最多能组成多少组 思路 ...
  • JinxiSui
  • JinxiSui
  • 2018-04-15 18:58:30
  • 9
    个人资料
    持之以恒
    等级:
    访问量: 3610
    积分: 705
    排名: 7万+
    文章分类
    文章存档