UVA1612 Guess(贪心+精度)

description
A competition was just over. It had 3 problems and n players. Each player had an ID number from 1 to n. The final rank was decided by the total score of the 3 problems. The higher the total score was, the higher a player ranked (the smaller the rank number). If two players got the same total score, the one with the smaller ID number got a higher rank. We’ve known for each problem, how much score each player might get if he din’t solve totally wrong (if solved totally wrong, the player got zero in the problem). However, we don’t know whether a player did get score in a problem. For a predicted final rank, you need to judge if the rank is possible.
Input
Input contains several cases. For each case, the first line is an integer n, (n ≤ 16384) to indicate the number of players, followed by n lines, the i-th of which contains three real numbers a, b, c (0 ≤ a, b, c < 1000. a, b and c have 2 decimal places at most.) to respectively indicate the score of each problem Player i might get if he didn’t solve totally wrong. Another line containing n integers follows to indicate the player ID number in the order from rank 1-st to rank n-th.
The last case is followed by a line containing only a zero.
Output
For each case, if the rank is possible, output the highest possible total score for the player with the lowest rank (calculate to 2 decimal places), otherwise output ‘No solution’ (quotes for clarity).

感想(:з」∠)
很直观的一道简单贪心吧。。。
每个人有2^3种分数方案。
就是每个人都尽量选高的分,,但是要满足分数比前一个小,或分数等于前一个人但序号要比前一个人大。
关键问题是,,,问题是!!!
精度qwq
读入的是两位小数,但是在进行浮点数之间的加法时会丢失精度。
1.于是就需要将每个数*100之后再相加,这样可以保护精度。
但是问题来了,这样还是wa。。。
2.需要转成int 最后输出的时候再用浮点数输出,保留两位。可是为什么一定要转成int计算呢???爸爸至今也不明白,,又是一个搁置问题。
3.但是即便是转成int还是要wa。。。相加的时候需要*100.0000000001,而不是*100,然后转成int,这样才能a。
爸爸就更不明白了。。。。搁置问题++。

最后总结,c++的精度问题真是迷幻qwq。

//  Created by ZYD in 2015.
//  Copyright (c) 2015 ZYD. All rights reserved.
//

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <climits>
#include <string>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
const double jd=100.000000001;
#define Size 100000
#define ll long long
#define mk make_pair
#define pb push_back
#define mem(array) memset(array,0,sizeof(array))
// typedef pair<int,int> P;

int main()
{
    freopen("in.txt","r",stdin);
    int tot=0;
    int n,p,f[20000][10],pre;
    double a,b,c,prem;
    while (cin>>n && n)
    {
        tot++;//cout<<n;
        mem(f);
        for(int i=1;i<=n;i++)
        {
            cin>>a>>b>>c;
            // if (tot==1) printf("%.2f %.2f %.2f \n",a,b,c);
            f[i][0]=0;
            f[i][1]=(int)(a*jd);f[i][2]=(int)(b*jd);f[i][3]=(int)(c*jd);
            f[i][4]=(int)(a*jd+b*jd);f[i][5]=(int)(a*jd+c*jd);f[i][6]=(int)(b*jd+c*jd);
            f[i][7]=(int)(a*jd+b*jd+c*jd);
            sort(f[i],f[i]+1+7);
        }
        cin>>p;//cout<<p<<' ';
        pre=f[p][7];prem=p;
        int flag2=0,flag=0;
        for(int i=2;i<=n;i++)
        {
            cin>>p;//cout<<p<<' ';
            if (flag2==1) continue;
            flag=0;
            for(int j=7;j>=0;j--)
            {
                if(f[p][j]<pre||(f[p][j]==pre && p>prem)) 
                {
                    pre=f[p][j];
                    prem=p;
                    flag=1;
                    break;
                }
            }
            if(flag==0) 
            {
                printf("Case %d: No solution\n",tot);
                flag2=1;

            }
        }
        if(flag2==0) printf("Case %d: %.2lf\n",tot,pre/100.00);
    }
    return 0;
}


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值