URAL 2011. Long Statement (数论)

27 篇文章 0 订阅
23 篇文章 0 订阅

2011. Long Statement

Time limit: 0.5 second
Memory 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 only n 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 all n letters placed in some order. Nikita wondered if he can compile at least six different words of length n 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 length n, output “Yes”. Otherwise output “No”.

Sample

inputoutput
6
1 2 2 3 3 3
Yes
Problem Author: Alexey Kungurtsev
Problem 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 sxk
        freopen("in.txt", "r", stdin);
    #endif // sxk

    int 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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值