Description
Bobo has
Input
The input consists of several test cases and is terminated by end-of-file.
The first line of each test case contains an integer
The
Output
For each test case, print
Constraint
- The sum of
does not exceed .
Sample Input
2
1 1 1
1 1 2
2
1 1 2
1 1 1
3
1 3 1
2 2 1
3 1 1
Sample Output
2 1
1 2
1 2 3
题解
题目大意
给你
分析
题给关系中的不等式只涉及
struct Node {
long long a, b, c;
int id;
}
同时,在比较三元组关系时,因为本题数据卡精度较严,因此不能用double,而应交叉相乘再比较,同时在这过程中约去一些相同的项(避免爆long long)。
代码
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 1010;
typedef long long ll;
struct Node {
ll a, b, c;
int id;
bool operator < (const Node& x) const {
ll q1 = c * (x.a + x.b);
ll q2 = x.c * (a + b);
if(q2 == q1) return id < x.id;
else return q2 < q1;
}
} t[MAXN];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n = 0;
while(cin >> n) {
for(int i = 1; i <= n; i++) {
cin >> t[i].a >> t[i].b >> t[i].c;
t[i].id = i;
}
sort(t + 1, t + n + 1);
for(int i = 1; i <= n; i++)
if(i != n) cout << t[i].id << " ";
else cout << t[i].id << endl;
}
return 0;
}