1055 The World Richest

编程入门 行业动态 更新时间:2024-10-18 14:15:55

1055 The <a href=https://www.elefans.com/category/jswz/34/1769196.html style=World Richest"/>

1055 The World Richest

1055 The World's Richest

  • 解题代码
  • 测试结果
  • 问题整理

解题代码

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct person {char name[9];int age;int worth;
}p[100000], p1[100000];
typedef struct person per;
struct que {int cnt;int min, max;
}q[1000];
bool cmp(per a, per b) {if (a.worth != b.worth) return a.worth > b.worth;if (a.age != b.age) return a.age < b.age;return strcmp(a.name, b.name) < 0;
}
int Age[201] = { 0 };
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].worth);for (int i = 0; i < K; i++)scanf("%d %d %d", &q[i]t, &q[i].min, &q[i].max);sort(p, p + N, cmp);int pp = 0;for (int i = 0; i < N; i++) {if (Age[p[i].age] < 100) {Age[p[i].age]++;p1[pp++] = p[i];}}for (int i = 0; i < K; i++) {if (i) printf("\n");printf("Case #%d:", i + 1);int len = q[i]t, l, j;for ( j = 0, l = 0; j < pp && l < len; j++) {if (p1[j].age >= q[i].min && p1[j].age <= q[i].max) {printf("\n%s %d %d", p1[j].name, p1[j].age, p1[j].worth);l++;}}if (!l) printf("\nNone");}return 0;
}

测试结果

问题整理

1.排序算法。
2.该题通过题意分析,预处理后极大缩短了运行时间,避免了超时。
3.注意有两个条件判断的for循环。

更多推荐

1055 The World Richest

本文发布于:2024-02-07 02:47:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1752568.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:World   Richest

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!