浙大PAT 7-06 题解
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <queue>
#include <stack>
#define N 400
#define ll int
using namespace std;
struct node{
ll gold,all,pre,num;
double pa,pg;
ll r1,r2,r3,r4;
}p[N];
bool cmp1(node a,node b){return a.gold>b.gold;}
bool cmp2(node a,node b){return a.all>b.all;}
bool cmp3(node a,node b){return a.pa>b.pa;}
bool cmp5(node a,node b){return a.pg>b.pg;}
bool cmp4(node a,node b){return a.num<b.num;}
int main(){
ll n,m,i,j;
while(~scanf("%d%d",&n,&m)){
for(i=0;i<n;i++){
scanf("%d %d %d",&p[i].gold,&p[i].all,&p[i].pre);
p[i].num=i;
if(p[i].pre==0){p[i].pg=p[i].pa=1000;continue;}
if(p[i].all)
p[i].pa=(double)p[i].all/(double)p[i].pre;
else p[i].pg=0;
if(p[i].gold)
p[i].pg=(double)p[i].gold/(double)p[i].pre;
else p[i].pg=0;
}
sort(p,p+n,cmp1);
ll rank=0,ranktemp=0;
for(i=0;i<n;i++)
if(i!=0 && p[i].gold==p[i-1].gold)
p[i].r1=rank,ranktemp++;
else
{
rank+=ranktemp+1;
ranktemp=0;
p[i].r1=rank;
}
sort(p,p+n,cmp2);
rank=0,ranktemp=0;
for(i=0;i<n;i++)
if(i!=0 && p[i].all==p[i-1].all)
p[i].r2=rank,ranktemp++;
else
{
rank+=ranktemp+1;
ranktemp=0;
p[i].r2=rank;
}
sort(p,p+n,cmp5);
rank=0,ranktemp=0;
for(i=0;i<n;i++)
if(i!=0 && p[i].pg==p[i-1].pg)
p[i].r4=rank,ranktemp++;
else
{
rank+=ranktemp+1;
ranktemp=0;
p[i].r4=rank;
}
sort(p,p+n,cmp3);
rank=0,ranktemp=0;
for(i=0;i<n;i++)
if(i!=0 && p[i].pa==p[i-1].pa)
p[i].r3=rank,ranktemp++;
else
{
rank+=ranktemp+1;
ranktemp=0;
p[i].r3=rank;
}
sort(p,p+n,cmp4);
while(m--){
scanf("%d",&i);
ll a=N,b;
if(p[i].r1<a){a=p[i].r1;b=1;}
if(p[i].r2<a){a=p[i].r2;b=2;}
if(p[i].r4<a){a=p[i].r4;b=3;}
if(p[i].r3<a){a=p[i].r3;b=4;}
printf("%d:%d",a,b);
if(m)printf(" ");
else printf("\n");
}
}
return 0;
}
/*
4 4
51 100 1000
36 110 300
6 14 32
5 18 40
0 1 2 3
7 2
51 100 1000
36 110 300
6 14 32
5 18 40
23 73 142
19 47 61
16 41 82
4 6
6 6
15 45 50
45 90 500
50 100 1000
30 80 75
50 100 500
40 90 100
2 4 1 5 3 0
4 4
2 3 1
1 3 1
2 5 1
0 4 1
1 3 2 0
*/
浙大PAT 7-06 题解的更多相关文章
- 浙大pat 1035题解
1035. Password (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To prepare f ...
- 浙大pat 1025题解
1025. PAT Ranking (25) 时间限制 200 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...
- 浙大pat 1011题解
With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excite ...
- 浙大pat 1012题解
1012. The Best Rank (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To eval ...
- 浙大 pat 1003 题解
1003. Emergency (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...
- 浙大 pat 1038 题解
1038. Recover the Smallest Number (30) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...
- 浙大 pat 1047题解
1047. Student List for Course (25) 时间限制 400 ms 内存限制 64000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Y ...
- 浙大pat 1054 题解
1054. The Dominant Color (20) 时间限制 100 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard Behind the scen ...
- 浙大pat 1059 题解
1059. Prime Factors (25) 时间限制 50 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 HE, Qinming Given ...
随机推荐
- gulp api
gulp api 简介 gulp是前端开发过程中对代码进行构建的工具,是自动化项目的构建利器:它不仅能对网站资源进行优化,而且在开发过程中很多重复的任务能够使用正确的工具自动完成 gulp是基于Nod ...
- JavaMail回复
JavaMail邮件回复 http://blog.csdn.net/o_darling/article/details/17558049 http://blog.csdn.net/xiyang_199 ...
- 将Linux下编译的warning警告信息输出到文件中[整理笔记]
Linux中,脚本语言环境中,即你用make xxx即其他一些普通linux命令,比如ls,find等,不同的数字,代表不同的含义: 数字 含义 标准叫法0 标准输入 stdin = standar ...
- java 数字前自动补零实现
/** * 里数字转字符串前面自动补0的实现. * */ public class TestStringFormat { public static void main(String[] args) ...
- 拓扑图弹力布局呈现Flickr图片搜索结果:智能创新
十年前有值得分享的图片我都存在Flickr上,可惜yahoo收购了Flickr之后堕落好多年,最近yahoo在梅姐带领下Flickr团队终于恢复了生机,个人免费存储空间扩充到了1T,界面用户体验也有 ...
- ubuntu gnome vnc
1,安装登陆管理器 --apt-get install gdm (还可以为kdm/xdm) lightdm,display manager
- [Linux] 修改主机名(hostname)
在Linux命令行下输入hostname,查看当前主机名,如果想修改它,直接在hostname后面加上新主机名即可(注:以下操作都需要root用户执行),如: # hostname newhostna ...
- Introducing Regular Expressions 学习笔记
Introducing Regular Expressions 读书笔记 工具: regexbuddy:http://download.csdn.net/tag/regexbuddy%E7%A0%B4 ...
- VS2015 开发人员命令提示,如何实现记事本编程
开始,选择VS2015 开发人员命令提示,打开 找到.c文件的位置,复制位置 在VS2015 开发人员命令提示, 输入cd 位置 回车 然后输入cl 文件名 回车 这样进行编译
- AngularJS 实战讲义笔记
第一部分 快速上手 1.1 感受AngularJs四大核心特性(MVC, 模块化,指令系统,双向数据绑定)1.2 搭建自动化的前端开发,调试,测试环境 代码编辑工具 (sublime) 断点调试工具 ...