UVa1612 Guess

做过的一道题

精度控制很重要

#include<bits/stdc++.h>
using namespace std;
#define maxn 20000
struct player{
    int score[8];
}P[maxn];
int n,ID[maxn];
int main()
{
    int cas=1;
    while(scanf("%d",&n)==1 && n){
        double tmp_f[3];
        int tmp_i[3];
        for(int i=1;i<=n;i++){
            scanf("%lf%lf%lf",&tmp_f[0],&tmp_f[1],&tmp_f[2]);
            for(int j=0;j<3;j++)
                tmp_i[j]=(int)(round(tmp_f[j]*100.0));
            for(int j=0;j<8;j++){
                P[i].score[j]=0;
                for(int k=0;k<3;k++)
                    if(j&(1<<k)) P[i].score[j]+=tmp_i[k];
            }
            sort(P[i].score,P[i].score+8);
        }
        for(int i=1;i<=n;i++)
            scanf("%d",&ID[i]);
        int MAX = P[ID[1]].score[7];
        int pre_ID = ID[1],i;
        for(i=2;i<=n;i++){
            int cur_ID=ID[i];
            bool flag=false;
            for(int j=7;j>=0;j--){
                if(P[cur_ID].score[j]==MAX&&cur_ID>pre_ID){
                    flag=true;
                    pre_ID=cur_ID;
                    break;
                }
                if(P[cur_ID].score[j]<MAX)
                {
                    flag=true;
                    pre_ID=cur_ID;
                    MAX=P[cur_ID].score[j];
                    break;
                }
            }
            if(!flag) break;
        }
        printf("Case %d: ", cas++);
        if(i != n + 1)
            printf("No solution\n");
        else
            printf("%.2lf\n", MAX / 100.0);
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值