-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathP10026.cpp
More file actions
89 lines (79 loc) · 1.6 KB
/
P10026.cpp
File metadata and controls
89 lines (79 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <iomanip>
#include <algorithm>
struct Real;
typedef std::pair<Real,Real> Point;
typedef std::pair<Point,Point> Line;
typedef long long ll;
#define XX first
#define YY second
#define p1 first
#define p2 second
ll gcd(ll a, ll b) {
ll c;
while(a != 0) {
c = a;
a = b%a;
b = c;
}
return b;
}
int sign(ll l) {
if(l < 0)
return -1;
return 1;
}
struct Real {
ll nom, denom;
Real() : nom(0), denom(0) {}
Real(ll i) : nom(i), denom(1) {}
Real(ll nom, ll denom) : nom(sign(denom)*nom), denom(std::abs(denom)) {}
Real(const std::string &rep) {
nom = 0;
denom = 1;
char c;
unsigned int i = 0;
while(((c = rep[i]) != '.') && i < rep.size()) {
nom = 10*nom + (c-'0');
++i;
}
++i;
while(i < rep.size()) {
nom = 10*nom + (rep[i]-'0');
denom*=10;
++i;
}
}
bool operator<(const Real &b) const {
return nom*b.denom < b.nom*denom;
}
};
typedef std::pair<Real,int> TT;
/*
If all times were 1: Order by fine decreasing.
If all fines were 1: Order by time increasing
*/
int main() {
int cases, N;
TT a[1000];
std::cin >> cases;
for(int cas = 0; cas < cases; ++cas) {
if(cas != 0)
std::cout << std::endl;
std::cin >> N;
for(int i = 0; i < N; ++i) {
std::cin >> a[i].first.nom >> a[i].first.denom; // tt.TIME >> tt.FINE;
a[i].second = i;
}
std::sort(a, a+N);
for(int i = 0; i < N; ++i) {
if(i != 0)
std::cout << " ";
std::cout << (a[i].second+1);
}
std::cout << std::endl;
}
return 0;
}