浙大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 ...
随机推荐
- android:TextAppearance.Material.Widget.Button.Inverse问题
如果在刚够构建Android Studio项目的时候,运行发现,出现没找到资源的错误!找不到com.android.support/appcompat-v7/23.0.1/res/values-v23 ...
- C语言入门(18)——数组与字符串
用来存放字符量的数组称为字符数组.字符串可以看作一个数组,它的元素是字符型的. 字符数组的定义 形式与前面介绍的数值数组相同.例如: char c[10]; 由于字符型和整型通用,也可以定义为int ...
- OpenStreetMap(OSM) JMap Viewer(Java swing map)
This article from:http://wiki.openstreetmap.org/wiki/JMapViewer JMapViewer is a java component which ...
- Java类和对象初始化
类的生命周期: Java类的初始化: 本阶段负责为类变量赋正确的初始值.(类变量即静态变量) Java编译器把所有的类变量初始化语句和静态初始化器通通收集到<clinit>方法中,该方法只 ...
- MyGui笔记(1)建立第一个工程
记录下学习 MyGui的一些笔记,从建立第一个工程开始. 步骤: 1.右键MYGUI解决方案,添加→新建项目,选择“Win32 项目”,名称为:TestHello.下一步,勾选“空项目”. 2.设置工 ...
- hdu 5590 ZYB's Biology
Problem Description After getting scores ) begins to work with biological questions.Now he give you ...
- UVA 10163 Storage Keepers(dp + 背包)
Problem C.Storage Keepers Background Randy Company has N (1<=N<=100) storages. Company wants ...
- Android上下左右滑动,显示底层布局
转载博客地址:http://www.cnblogs.com/flyme2012/p/4106308.html 闲着没事做了一个小东西.Android的上下左右滑动,显示底层布局.可以做类似于QQ消息列 ...
- POJ 1703 Find them, Catch them (数据结构-并查集)
Find them, Catch them Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 31102 Accepted: ...
- openstack之horizon源码分析之二
一.概述: django基础入手: django新建project:#django-admin startproject mysite 生成如下目录: mysite ├── manage.py └── ...