麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

1055. The World's Richest (25)

2019-11-14 09:12:28
字體:
來源:轉載
供稿:網友

1055. The World's Richest (25)

時間限制 400 ms內存限制 128000 kB代碼長度限制 16000 B判題程序 Standard 作者 CHEN, Yue

Forbes magazine publishes every year its list of billionaires based on the annual ranking of the world's wealthiest people. Now you are supposed to simulate this job, but concentrate only on the people in a certain range of ages. That is, given the net worths of N people, you must find the M richest people in a given range of their ages.

Input Specification:

Each input file contains one test case. For each case, the first line contains 2 positive integers: N (<=105) - the total number of people, and K (<=103) - the number of queries. Then N lines follow, each contains the name (string of no more than 8 characters without space), age (integer in (0, 200]), and the net worth (integer in [-106, 106]) of a person. Finally there are K lines of queries, each contains three positive integers: M (<= 100) - the maximum number of outputs, and [Amin, Amax] which are the range of ages. All the numbers in a line are separated by a space.

Output Specification:

For each query, first PRint in a line "Case #X:" where X is the query number starting from 1. Then output the M richest people with their ages in the range [Amin, Amax]. Each person's information occupies a line, in the format

Name Age Net_Worth

The outputs must be in non-increasing order of the net worths. In case there are equal worths, it must be in non-decreasing order of the ages. If both worths and ages are the same, then the output must be in non-decreasing alphabetical order of the names. It is guaranteed that there is no two persons share all the same of the three pieces of information. In case no one is found, output "None".

Sample Input:

12 4Zoe_Bill 35 2333Bob_Volk 24 5888Anny_Cin 95 999999Williams 30 -22Cindy 76 76000Alice 18 88888Joe_Mike 32 3222Michael 5 300000Rosemary 40 5888Dobby 24 5888Billy 24 5888Nobody 5 04 15 454 30 354 5 951 45 50

Sample Output:

Case #1:Alice 18 88888Billy 24 5888Bob_Volk 24 5888Dobby 24 5888Case #2:Joe_Mike 32 3222Zoe_Bill 35 2333Williams 30 -22Case #3:Anny_Cin 95 999999Michael 5 300000Alice 18 88888Cindy 76 76000Case #4:None

#include<iostream>#include<string>#include<vector>#include<algorithm>#include<string.h>using namespace std;struct person{		char name[10];		int age;		int worth;};bool compare1(const person &a,const person &b){	return a.age<b.age;}bool compare2(const person &a,const person &b){	if(a.worth!=b.worth)	return a.worth>b.worth;	else if(a.age!=b.age)	return a.age<b.age;	if(strcmp(b.name,a.name)>0)	return true;	return false;}vector<person> v;vector<person> a;void qury(int b,int min,int max,int N){	int i;	v.clear();/*	int start=0,end=a.size()-1;	while(start<end-1){		if(a[(start+end)/2].age>min){			end=(start+end)/2;		}		else if(a[(start+end)/2].age<min){			start=(start+end)/2;		}		else{			start=(start+end)/2;			end=start;		}	}	if(start-3<0)	start=0;	else	start=start-3;*/	for(i=0;i<N;i++){		/*if(a[i].age>max)		break;*/		if(a[i].age>=min&&a[i].age<=max)		v.push_back(a[i]);		if(v.size()>=b)		break;	}	if(v.size()==0){	printf("None/n");	return ;	}	//sort(v.begin(),v.end(),compare2);	if(b>=v.size())	for(i=0;i<v.size();i++){	printf("%s %d %d/n",v[i].name,v[i].age,v[i].worth);	}	else	for(i=0;i<b;i++){	printf("%s %d %d/n",v[i].name,v[i].age,v[i].worth);	}}int main(){	int N,M,i,temp1,temp2,temp3;	person tt;	cin>>N>>M; 	for(i=0;i<N;i++){		scanf("%s %d %d",&tt.name,&tt.age,&tt.worth);		a.push_back(tt);	}	sort(a.begin(),a.end(),compare2);	for(i=0;i<M;i++){		scanf("%d %d %d",&temp1,&temp2,&temp3);		printf("Case #%d:/n",i+1);		qury(temp1,temp2,temp3,N);	}} 感想:這道題關鍵點是運行時間,測試點2和3表示數據量最大和查詢數據量最大,具體要求:1. 先按輸出要求用sort函數排序后,再取數據,這里當數據量到達了要求的量的時候要停止遍歷,這樣可以降低時間2. 不要用string類,不要用cout,用char* 和printf3. 使用vector也可以加快速度4. 注掉的部分是我之前的想法(先按時間排序,再用二分查找法找到要查找的子字符串的起始位置,然后再對字符串排序,結果會略超時)
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 精品中文字幕久久久久四十五十骆 | 精品久久久久久久久久久久包黑料 | a级毛片免费观看在线播放 日本aaa一级片 | 欧美亚洲国产成人 | 日韩精品一区二区三区中文 | 国产毛片在线看 | 久久久成人一区二区免费影院 | 欧美一级电影网 | 性 毛片| 久久午夜神器 | 欧美电影在线观看 | 免费a视频在线观看 | 国语自产免费精品视频在 | 亚洲成人福利网站 | 精品国产一区二区三区久久久 | 97风流梦电影| aa级黄色片| 黄色毛片一级视频 | 国产精品久久久久久久亚洲按摩 | 一级黄色毛片a | 成人午夜视频网站 | 91久久另类重口变态 | 中文字幕在线观看网址 | 粉嫩粉嫩一区二区三区在线播放 | 久久国产精品久久久久久久久久 | 91在线精品亚洲一区二区 | 美国av在线免费观看 | 欧美视频网 | 国产乱淫av片免费观看 | 午色影院 | 在线观看中文字幕av | 欧美性受ⅹ╳╳╳黑人a性爽 | 精品在线观看一区 | 日本中文高清 | 欧美久久一区二区 | 日韩一级免费毛片 | 九一成人 | 九九热视频在线免费观看 | 蜜桃91麻豆 | 99ri在线 | 黄色电影免费提供 |