45105
56 94
38 17
45 46
94 65
42 77
4 31
71 51
49 31
82 9
11 62
33 30
50 19
52 61
32 8
<308494 bytes omitted>
用户输出
1349072953962
系统信息
Exited with return code 0
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#21000 | #1022. jwp的排队难题 | Accepted | 100 | 50 ms | 1808 K | C++ 11 / 1024 B | zichengsaber | 2019-09-16 22:57:18 |
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long ll;
//面向对象学习
class Person {
public:
ll a, b;
Person(ll i, ll j) : a(i), b(j) {}
Person() {}
friend bool operator<(const Person &A, const Person &B) { return (B.a * A.b < A.a * B.b); }
};
const int maxn = 1e5 + 5;
Person person[maxn];
/* 解决思想:
贪心的思想:题目的特点
1.总共等待的时间是一定的
2.贪心的直觉是先排ai/bi大的即单位等待时间内暴躁值更大的在前面
3.通过JM的介绍可以用相邻交换法证明其正确性
*/
int main() {
int n, a, b;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%lld%lld", &person[i].a, &person[i].b);
}
// sort
sort(person + 1, person + 1 + n);
//
ll minSum = 0, time = 0;
for (int i = 1; i <= n; i++) {
time += person[i].b;
minSum += person[i].a * time;
}
//
printf("%lld\n", minSum);
return 0;
}
45105
56 94
38 17
45 46
94 65
42 77
4 31
71 51
49 31
82 9
11 62
33 30
50 19
52 61
32 8
<308494 bytes omitted>
用户输出
1349072953962
系统信息
Exited with return code 0
6667
81 6
83 71
57 69
97 27
5 84
20 77
28 77
77 57
97 49
40 18
78 39
41 69
14 11
99 1
<45515 bytes omitted>
用户输出
29669490408
系统信息
Exited with return code 0
55457
60 47
63 7
81 14
91 88
2 83
4 35
80 77
55 46
97 57
65 10
56 14
15 43
88 3
19 62
<379227 bytes omitted>
用户输出
2046293880925
系统信息
Exited with return code 0
54839
31 85
77 24
87 83
9 18
35 74
88 40
59 14
47 63
50 31
17 40
1 23
71 10
43 69
24 1
<374961 bytes omitted>
用户输出
1999020249779
系统信息
Exited with return code 0