icpc:problems:luogup1293
problems | |
---|---|
名称 | 班级聚会 |
题目编号 | P1293 |
题目链接 | luogu.com.cn/… |
来源 | Luogu |
算法分类 | 入门_结构体, 入门_循环 |
难易程度 | 入门 |
班级聚会
想法
循环枚举,枚举作为答案的地点。
代码实现
#include <algorithm> #include <iostream> #include <string> using namespace std; struct node { int p, dis; string name; }; node line[150]; int main() { int n = 0; while (true) { n++; cin >> line[n].p >> line[n].dis >> line[n].name; if (line[n].dis == 0) break; } int mi = 2147483647, d = 0; string ans; for (int i = 1; i <= n; i++) { int temp = 0; for (int t = 1; t <= n; t++) { temp += abs(line[i].dis - line[t].dis) * (line[t].p); } if((mi == temp && d > line[i].dis) || (mi > temp)) { mi = temp; ans = line[i].name; d = line[i].dis; } } cout << ans << " " << mi; return 0; }
/app/www/public/data/pages/icpc/problems/luogup1293.txt · 最后更改: 2024/04/20 12:20 由 温婕莺