zoukankan      html  css  js  c++  java
  • 【习题 8-8 UVA

    【链接】 我是链接,点我呀:)
    【题意】

    在这里输入题意

    【题解】

    double千万不要用==判断相等。。。 而且两个保留2位有效数字的数字x,y 判断它们相等应该这样。 int temp1 = round(x*100.0),temp2 = round(y*100.0); temp1==temp2的话,才成立 不能直接*100 会出现精度误差。

    然后就是把每个人的所有可能成绩都算出来(8种);
    然后从大到小排序。
    一开始每个人都得最高分。
    set中以分数和id为关键字进行排序。
    然后对于读入的第i个分数a[i]。
    如果set的头元素不为a[i];
    那么就让头元素的得分更低一点;
    即从第i高的得分变成第i+1高的得分。
    直到不能更低为止。(无解

    【代码】

    /*
      	1.Shoud it use long long ?
      	2.Have you ever test several sample(at least therr) yourself?
      	3.Can you promise that the solution is right? At least,the main ideal
      	4.use the puts("") or putchar() or printf and such things?
      	5.init the used array or any value?
      	6.use error MAX_VALUE?
      	7.use scanf instead of cin/cout?
      	8.whatch out the detail input require
    */
    /*
        一定在这里写完思路再敲代码!!!
    */
    #include <bits/stdc++.h>
    #define index fuck_index
    using namespace std;
    
    const int N = 2e4;
    
    int n,index[N];
    vector<double> v[N];
    double vv[3];
    
    
    struct abc{
        int ind;
    
        abc(int x):ind(x){}
    
        friend bool operator < (abc a,abc b){
            int temp1 = round(v[a.ind][index[a.ind]]*100.0);
            int temp2 = round(v[b.ind][index[b.ind]]*100.0);
            if (temp1!=temp2)
                return temp1>temp2;
            else
                return a.ind<b.ind;
        }
    };
    
    set <abc> myset;
    
    bool ok(){
        int pre;
        for (int i = 1;i <= n;i++){
            int x;cin >> x;
            if (i==n){
                cout <<fixed<<setprecision(2)<<v[x][index[x]] << endl;
                return true;
            }
            while ( (*myset.begin()).ind!=x){
    
                int temp = (*myset.begin()).ind;
                myset.erase(myset.begin());
                if (index[temp]==((int)v[temp].size()-1)) {
                    for (int j = i+1;j <= n;j++) cin >> x;
                    return false;
                }
                index[temp]++;
                myset.insert(abc(temp));
            }
    
            myset.erase(myset.begin());
        }
    
        return true;
    }
    
    int main(){
    	#ifdef LOCAL_DEFINE
    	    freopen("rush_in.txt", "r", stdin);
    	#endif
    	ios::sync_with_stdio(0),cin.tie(0);
    	int kase = 0;
    	while (cin>>n && n){
            myset.clear();
            for (int i = 1;i <= n;i++){
                v[i].clear();
                for (int j = 0;j < 3;j++) cin >> vv[j];
                for (int j = 0;j < 3;j++) v[i].push_back(vv[j]);
                for (int j = 0;j < 3;j++)
                    for (int k = j+1;k < 3;k++)
                        v[i].push_back(vv[j]+vv[k]);
                v[i].push_back(vv[0]+vv[1]+vv[2]);
                v[i].push_back(0);
                sort(v[i].begin(),v[i].end());
                reverse(v[i].begin(),v[i].end());
                index[i] = 0;
            }
    
            for (int i = 1;i <= n;i++) myset.insert(abc(i));
            cout<<"Case "<<++kase<<": ";
            if (!ok()) cout <<"No solution"<<endl;
    
    	}
    
    	return 0;
    }
    
    
  • 相关阅读:
    学习 JS 内容知识点与个人感悟【2】
    学习两天hml的感悟
    编程一星期感悟(上)
    java基础及练习题
    java基础程序代码及Scanner和Random
    java中Random和Scanner及其循环语句
    java语言及数据类型
    SQL含义+单行函数
    DTL+数据字典+序列、索引、视图
    sql plus及SQL语句
  • 原文地址:https://www.cnblogs.com/AWCXV/p/8254026.html
Copyright © 2011-2022 走看看