No Girlfriend(简单题)

1、http://acm.nbut.edu.cn/Problem/view.xhtml?id=1543

2、题目大意

情人节将至,有n个人分别跟自己喜欢的人约会,给出每个人约会的人编号,如果带走其中一个人,那么喜欢这个人的那些人将会不开心,现在你要带走一个人,使得不开心的人数最多

简单题,不过太心急了,没有注意好边界就提交,导致wrong了两遍才AC

3、题目:

  • [C] No Girlfriend

  • 时间限制: 2000 ms 内存限制: 262144 K       
  • 问题描述
  • You know the day after tomorrow is Valentine's Day, but I have no girlfriend.

    Now, I'll give you a big task, help me take away a person!

    If you take away that person, others who want to appointment with him/her will feel disappointed.

    Your task is to let maximum people feel disappointed.

  • 输入
  • There are multiple test cases, each test case contain a positive number N (1 <= N <= 100).
    Following N lines, for the ith line (1-Based) contain a positive integer P (1 <= P <= N), represent the ith people want to appointment with P.
    Note: Everyone has a distinct number, the ith people's number is i.
  • 输出
  • For each case, output the answer in one line.           
  • 样例输入
  • 3311555222
  • 样例输出
  • 23
  • 提示
  • For the first test case.If you take away 1, then 2 and 3 will feel disappointed.If you take away 2, nobody will feel disappointed.If you take away 3, then 1 will feel disappointed.So the maximum people feel disappointed is 2. 

     

    4、AC代码:

    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    using namespace std;
    int b[105];
    int cmp(int c,int d)
    {
        return c>d;
    }
    int main()
    {
        int n,a;
        while(scanf("%d",&n)!=EOF)
        {
            memset(b,0,sizeof(b));
            for(int i=0;i<n;i++)
            {
                scanf("%d",&a);
                b[a]++;
            }
            sort(b,b+n+1,cmp);
            printf("%d\n",b[0]);
        }
        return 0;
    }
    


     

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值