acm icpc 北京网络赛 1007

这道题感觉不需要考虑太多,直接写就好了,稍微看一下就知道 s=10000-(200-w)^2 在w=1-200中只可能有100种可能

下面是ac代码:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <vector>

using namespace std;

int cot[10005];
vector <int> ans;

int main()
{
    int t,n,w,s,maxn,num;
    while(scanf("%d",&t)!=EOF)
    {
        for(int i=1;i<=t;i++)
        {
            ans.clear();
            for(int j=1;j<=100;j++)
            {
                s=j*(200-j);
                cot[s]=0;
            }
            maxn=0;
            num=0;
            scanf("%d",&n);
            while(n--)
            {
                scanf("%d",&w);
                s=w*(200-w);
                cot[s]++;
                if(cot[s]==1)
                {
                    num++;
                }
                if(maxn<cot[s])
                    maxn=cot[s];
            }
            for(int j=1;j<=100;j++)
            {
                s=j*(200-j);
                if(cot[s]==maxn)
                {
                    ans.push_back(s);
                }
            }
            printf("Case #%d: ",i);
            if(num==1)
            {
                printf("%d ",ans[0]);
            }
            else if(ans.size()==num)
            {
                printf("Bad Mushroom ");
            }
            else
            {
                sort(ans.begin(),ans.end());
                printf("%d",ans[0]);
                for(int j=1;j<ans.size();j++)
                {
                    printf(" %d",ans[j]);
                }
                printf(" ");
            }
        }
    }
    return 0;
}


原文地址:https://www.cnblogs.com/hqwhqwhq/p/4555895.html