随笔 - 5, 文章 - 0, 评论 - 0, 引用 - 0
数据加载中……

1007 奥运排序问题

http://ac.jobdu.com/problem.php?pid=1007
这道题目有个隐蔽的地方,就是要求排序的m个国家号并不一定按序给出,因此输出的时候必须按照给定的顺序输出。
我之前就是因为用的sort排序自动有低到高输出导致WA
下面的代码已AC,我是新手,欢迎交流。
 1
 #include <iostream>
 2 #include <vector>
 3 #include <cstdio>
 4 using namespace std;
 5 
 6 struct Nation
 7 {
 8     int gold,medal;
 9     double pop,gpp,mpp;
10 };
11 
12 int main()
13 {
14     freopen("in.txt","r",stdin);
15     int n,m,rk,md;
16     int i,*sel;
17     Nation nt;
18     vector<Nation> nvec,svec;
19     while(scanf("%d%d", &n,&m)!=EOF)
20     {
21         nvec.clear();
22         for(i=0; i<n; ++i)
23         {
24             scanf("%d%d%lf", &(nt.gold),&(nt.medal),&(nt.pop));
25             nt.gpp = (double)nt.gold/nt.pop;
26             nt.mpp = (double)nt.medal/nt.pop;
27             nvec.push_back(nt);
28         }
29         sel =(int *)malloc(sizeof(int)*m);
30         svec.clear();
31         for(i=0; i<m; ++i)
32         {
33             scanf("%d", &sel[i]);
34             svec.push_back(nvec.at(sel[i]));
35         }
36         for(size_t ix =0; ix <svec.size(); ++ix)
37         {
38             int rank[4]={1,1,1,1};
39             
40             for(i=0; i<m; ++i)
41             {
42                 if(nvec[sel[i]].gold > svec[ix].gold)
43                     ++rank[0];
44             }
45             for(i=0; i<m; ++i)
46             {
47                 if(nvec[sel[i]].medal > svec[ix].medal)
48                     ++rank[1];
49             }
50             for(i=0; i<m; ++i)
51             {
52                 if(nvec[sel[i]].gpp > svec[ix].gpp)
53                     ++rank[2];
54             }
55             for(i=0; i<m; ++i)
56             {
57                 if(nvec[sel[i]].mpp > svec[ix].mpp)
58                     ++rank[3];
59             }
60             if(rank[0]>rank[1])
61             {
62                 rk=rank[1];
63                 md=2;
64             }
65             else
66             {
67                 rk=rank[0];
68                 md=1;
69             }
70             if(rk > rank[2])
71             {
72                 rk=rank[2];
73                 md=3;
74             }
75             if(rk > rank[3])
76             {
77                 rk=rank[3];
78                 md=4;
79             }
80             printf("%d:%d\n", rk, md);
81         }
82         printf("\n");
83     }
84     return 0;
85 }

posted on 2013-01-24 14:09 gamer67 阅读(416) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理