URAL 2011. Long Statement (数论)

2011. Long Statement

Time limit: 0.5 secondMemory limit: 64 MB

Nikita, a schoolboy, is currently taking part in one of programming contests.He is really upset because all the problem statements are so long and unclear. So he took the statement of the first problem and cut itinto pieces in such a way that each piece contained exactly one letter. After that, he threw away all pieces with letter other than“a”, “b” or “c”. Now he has onlyn pieces and wants to compilefrom them his own statement that should be shorter and clearer than the original one.

The new statement should be a single word compiled from alln letters placed in some order. Nikita wondered if he can compile at least six different words of lengthn from the letters. If this is not true,he will be ruined and will start solving other problems.Help Nikita to answer this monumental question!

Input

The first line contains an integer n that is the number of pieces with letters (1 ≤n ≤ 100).The second line describes these pieces as n integers from 1 to 3.1 represents a piece with letter “a”, 2 represents a piece with letter “b”,3 represents a piece with letter “c”.

Output

If Nikita can compile at least six different words of lengthn, output “Yes”. Otherwise output “No”.

Sample

inputoutput

61 2 2 3 3 3Yes

Problem Author: Alexey KungurtsevProblem Source: Ural Regional School Programming Contest 2013

解析:坑爹的计数题。。。开始本以为必须用阶乘搞,最后发现,100!太大,搞不起。不过,我们可以换种思路,找找规律。

分情况讨论满足的情况:

n = 3:必须是1,2,3同时出现才满足。

n = 4:三个数字同时出现或者存在两个数量超过2的数字出现。

n = 5:同n = 4.

n > 5:至少有两个不同的数字出现。

其余的情况均不满足。

AC代码:

#include <bits/stdc++.h>using namespace std;int main(){#ifdef sxkfreopen("in.txt", "r", stdin);#endif // sxkint n, a, b, x;while(~scanf("%d", &n)){a = b = 0;for(int i=0; i<n; i++){scanf("%d", &x);a += (x == 1);//1出现的次数b += (x == 2);//2出现的次数}int flag = 0;if(n == 3 && a == 1 && b == 1) flag = 1;else if((n == 4 || n == 5) && ((a && b && n – a – b) || (a >= 2) + (b >= 2) + (n – a – b >= 2) >= 2))flag = 1;else if(n > 5 && (a > 0) + (b > 0) + (n – a – b > 0) >= 2) flag = 1;puts(flag ? "Yes" : "No");}return 0;}

,切忌贪婪,恨不得一次玩遍所有传说中的好景点,

URAL 2011. Long Statement (数论)

相关文章:

你感兴趣的文章:

标签云: