acm icpc 北京网络赛 1007

本文提供了一道ACM编程题的解答思路与实现代码。通过分析题目要求,给出了一种有效的算法实现方案,并通过具体代码展示了如何计算特定条件下的数值。适用于对ACM竞赛感兴趣或准备参加此类比赛的读者。

这道题感觉不需要考虑太多,直接写就好了,稍微看一下就知道 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:\n",i);
            if(num==1)
            {
                printf("%d\n",ans[0]);
            }
            else if(ans.size()==num)
            {
                printf("Bad Mushroom\n");
            }
            else
            {
                sort(ans.begin(),ans.end());
                printf("%d",ans[0]);
                for(int j=1;j<ans.size();j++)
                {
                    printf(" %d",ans[j]);
                }
                printf("\n");
            }
        }
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值