Skip to content

1055. The World’s Richest (25)超时 #8

@likmin

Description

@likmin

超时了,但好歹我调试了一段时间,可不能扔了。写下以纪念
`
#include
#include<string.h>
#include
using namespace std;
struct node {
char name[9];
int age, net_worth;
}P[100010];
bool cmp(node a, node b) {
return a.age < b.age;
}
bool cmp1(node a, node b) {

if (a.net_worth != b.net_worth)
	return a.net_worth > b.net_worth;
if (a.age != b.age)
	return a.age < b.age;
if (strcmp(a.name, b.name) < 0)
	return true;
return false;

}
int main()
{
int N, K;
scanf("%d %d", &N, &K);
for (int i = 0; i < N; i++) {
scanf("%s %d %d", P[i].name, &P[i].age, &P[i].net_worth);
}
sort(P, P + N, cmp);
for (int i = 1; i <=K; i++) {

	int M, Amin, Amax;
	scanf("%d %d %d", &M, &Amin, &Amax);
	int start = 0,end=N-1;
	while (start<N&&P[start].age < Amin)
		start++;
	while (end>=0&&P[end].age > Amax)
		end--;
	printf("Case #%d:\n", i);
	if (start > end)printf("None");
	else {
		sort(P + start, P + end+1, cmp1);
		M = (M > end - start) ? end - start+1: M;
		for (int j = start; j <start+M; j++) {
			printf("%s %d %d\n", P[j].name, P[j].age, P[j].net_worth);
		}
	}
	sort(P, P + N, cmp);
}
return 0;

}
`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions