zoukankan      html  css  js  c++  java
  • UVA-1612 Guess (贪心)

    题目大意:考试共有三道题,n个人,每个人对每道题的可能得分已知,现在已知考后排名情况,问排名合不合理。

    题目分析:贪心。贪心策略:每处理一个排名,都让他的得分尽量高。

    # include<iostream>
    # include<cstdio>
    # include<cstring>
    # include<algorithm>
    using namespace std;
    
    const double INF=1e10;
    
    double a[16385][3],b[8];
    int rk[16385];
    
    double getMax(int id,double high,double low)
    {
        int cnt=0;
        for(int i=1;i<=3;++i){
            for(int j=0;j+i-1<3;++j){
                double sum=0.0;
                for(int k=j;k<=j+i-1;++k)
                    sum+=a[id][k];
                b[cnt++]=sum;
            }
        }
        b[cnt++]=a[id][0]+a[id][2];
        double res=-1.0;
        for(int i=0;i<cnt;++i)
            if(b[i]>low&&b[i]<high)
                res=max(res,b[i]);
        return res;
    }
    
    double judge(int n)
    {
        double lst;
        for(int i=0;i<n;++i){
            if(i==0){
                lst=a[rk[i]-1][0]+a[rk[i]-1][1]+a[rk[i]-1][2];
                continue;
            }
            if(rk[i]>rk[i-1]){
                lst=getMax(rk[i]-1,lst+0.01,-0.01);
            }else
                lst=getMax(rk[i]-1,lst,-0.01);
            if(lst==-1.0)
                return -1.0;
        }
        return lst;
    }
    
    int main()
    {
        int n,cas=0;
        while(scanf("%d",&n)&&n)
        {
            for(int i=0;i<n;++i){
                for(int j=0;j<3;++j)
                    cin>>a[i][j];
                sort(a[i],a[i]+3);
            }
            for(int i=0;i<n;++i)
                scanf("%d",rk+i);
    
            printf("Case %d: ",++cas);
            double k=judge(n);
            if(k!=-1.0)
                printf("%.2lf
    ",k);
            else
                printf("No solution
    ");
        }
        return 0;
    }
    

      

  • 相关阅读:
    重拾数学--初中--有理数
    Python中的运算符
    PyQt5实现虚拟摇杆
    Python无重复字符的最长子串
    Python两数相加
    Python两数之和
    DBMS,B树和B+树
    浮点数表示
    Lamada表达式
    Java编程思想P159页的错误
  • 原文地址:https://www.cnblogs.com/20143605--pcx/p/4871780.html
Copyright © 2011-2022 走看看