当前位置: 代码迷 >> 综合 >> No Girlfriend(简单题)
  详细解决方案

No Girlfriend(简单题)

热度:78   发布时间:2024-01-13 20:33:05.0

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