zzuli-2175: GJJ的日常之再游戏

传送门https://acm.zzuli.edu.cn/zzuliacm/problem.php?id=2175


2175: GJJ的日常之再游戏

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 837  Solved: 176

SubmitStatusWeb Board

Description

GJJ和WJJ又开始了游戏,然而由于WJJ太强了,所以GJJ只好靠计谋取胜,而正因为WJJ太强,所以用过一次的计谋便无效了。
GJJ和WJJ一共玩了N场游戏,如果GJJ想要获胜,必须得赢的场数比Wjj多。
问:GJJ能否获胜?

Input

多实例,到文件尾结束
每个样例第一行一个N(1<=N<=50000),表示GJJ每场使用的计谋的数量;
第二行是N个数x,表示计谋的编号(0<=x<=1000000000)。

Output

对于每组样例,如果GJJ获胜输出"Yes";否则输出"No"。

Sample Input

51 2 3 4 551 2 2 2 1

Sample Output

YesNo

HINT

Source

签到题,排序之后去重之后数组的长度即为GJJ胜利的场数。
注意数据范围不能使用set和map。
可以使用unique去重




#include<cstdio>
#include<algorithm>
using namespace std;
bool cmp(int a,int b)
{
    return a<b;
} 
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        long long a[50050];
        for(int i=1; i<=n; i++)
        {
            scanf("%lld",&a[i]);
        }
        sort(a+1,a+n+1,cmp);
        int sum=0;
        for(int i=1; i<=n; i++)
        {
            if(a[i]==a[i+1])
            sum++;
        }
        if(n%2==0)
        {
            if(sum<n/2)
            printf("Yes\n");
            else
            printf("No\n");
        }
        else
        {
            if(sum<n/2+1)
            printf("Yes\n");
            else
            printf("No\n");
        }
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int a[50005];
int main()
{
    int n;
//    freopen("D://2.in","r",stdin);
//    freopen("D://2.out","w",stdout);
    while(scanf("%d",&n)!=-1)
    {
        for(int i=0;i<n;i++)
            scanf("%d",&a[i]);
        sort(a,a+n);
        int l=unique(a,a+n)-a;
        if(l>n/2)
        {
            puts("Yes");
        }
        else puts("No");
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值