九度oj 题目1007:奥运排序问题(但无法通过)

题目描述:

按要求,给国家进行排名。

输入:
有多组数据。
第一行给出国家数N,要求排名的国家数M,国家号从0到N-1。
第二行开始的N行给定国家或地区的奥运金牌数,奖牌数,人口数(百万)。
接下来一行给出M个国家号。
输出:
排序有4种方式: 金牌总数 奖牌总数 金牌人口比例 奖牌人口比例 
对每个国家给出最佳排名排名方式 和 最终排名
格式为: 排名:排名方式
如果有相同的最终排名,则输出排名方式最小的那种排名,对于排名方式,金牌总数 < 奖牌总数 < 金牌人口比例 < 奖牌人口比例 
如果有并列排名的情况,即如果出现金牌总数为 100,90,90,80.则排名为1,2,2,4.
每组数据后加一个空行。
样例输入:
4 4
4 8 1
6 6 2
4 8 2
2 12 4
0 1 2 3
4 2
8 10 1
8 11 2
8 12 3
8 13 4
0 3
样例输出:
1:3
1:1
2:1
1:2

1:1
1:1

来源:

2010年浙江大学计算机及软件工程研究生机试真题


用例可以,但通过不了。

留一思路。希望大神能给些建议。


#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
 
struct infor{
    int no;
    int gold;
    int medal;
    int population;
    double goldratio;
    double medalratio;
    infor(int tno,int tgold,int tmedal,int tpopulation){
        no = tno;
        gold = tgold;
        medal = tmedal;
        population = tpopulation;
         
        goldratio = tgold*1.0/population;
        medalratio = medal*1.0/population;
    }
};
int n,m;
vector<infor> pl;
int rankl[5][1024];
 
bool cmp1(const infor a,const infor b){
    return a.gold>b.gold;
}
bool cmp2(infor a,infor b){
    return a.medal>b.medal;
}
bool cmp3(infor a,infor b){
    return a.goldratio>b.goldratio;
}
bool cmp4(infor a,infor b){
    return a.medalratio>b.medalratio;
}
void sortrank1(){
    int nowrank = 0;
    int nowdata = pl.at(0).gold;
    rankl[1][pl.at(0).no] = nowrank;
    for(int i=1;i<n;i++){
        if(pl.at(i-1).gold==pl.at(i).gold){
            rankl[1][pl.at(i).no] = nowrank;
        }
        else{
            rankl[1][pl.at(i).no] = i;
            nowrank = i;
        }
    }
}
void sortrank2(){
    int nowrank = 0;
    int nowdata = pl.at(0).medal;
    rankl[2][pl.at(0).no] = nowrank;
    for(int i=1;i<n;i++){
        if(pl.at(i-1).medal==pl.at(i).medal){
            rankl[2][pl.at(i).no] = nowrank;
        }
        else{
            rankl[2][pl.at(i).no] = i;
            nowrank = i;
        }
    }
}
void sortrank3(){
    int nowrank = 0;
    int nowdata = pl.at(0).goldratio;
    rankl[3][pl.at(0).no] = nowrank;
    for(int i=1;i<n;i++){
        if(pl.at(i-1).goldratio==pl.at(i).goldratio){
            rankl[3][pl.at(i).no] = nowrank;
        }
        else{
            rankl[3][pl.at(i).no] = i;
            nowrank = i;
        }
    }
}
void sortrank4(){
    int nowrank = 0;
    int nowdata = pl.at(0).medalratio;
    rankl[4][pl.at(0).no] = nowrank;
    for(int i=1;i<n;i++){
        if(pl.at(i-1).medalratio==pl.at(i).medalratio){
            rankl[4][pl.at(i).no] = nowrank;
        }
        else{
            rankl[4][pl.at(i).no] = i;
            nowrank = i;
        }
    }
}
 
void sortfinal(){
    for(int i =0;i<n;i++){
        int tmp = n+1;
        int p;
        for(int j =1;j<=4;j++){
             if(tmp>rankl[j][i]){
                tmp = rankl[j][i];
                p = j;
             }
        }
        rankl[0][i] = p;
    }
}

int main(){
    //freopen("input.txt","r",stdin); 
    while(scanf("%d%d",&n,&m)!=EOF){
        if(n==0){
            for(int i =0;i<m;i++){
                printf("0:0\n");
            }
            printf("\n");
            continue;
        }
        pl.clear();
        int tgold,tmedal,tpopulation;
        for(int i=0;i<n;i++){
            scanf("%d%d%d",&tgold,&tmedal,&tpopulation);
            infor tmp(i,tgold,tmedal,tpopulation);
            pl.push_back(tmp);
        }

        sort(pl.begin(),pl.end(),cmp1);
        sortrank1();


        sort(pl.begin(),pl.end(),cmp2);
        sortrank2();
        sort(pl.begin(),pl.end(),cmp3);
        sortrank3();
        sort(pl.begin(),pl.end(),cmp4);
        sortrank4();
        sortfinal();
        for(int i =0;i<m;i++){
            int tm;
            scanf("%d",&tm);
            int pm = rankl[0][tm];
            printf("%d:%d\n",rankl[pm][i]+1,rankl[0][tm]);
        }
        printf("\n");
    }
    return 0;
}
 
/**************************************************************
    Problem: 1007
    User: hankcheung
    Language: C++
    Result: Wrong Answer
****************************************************************/

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值