-
Notifications
You must be signed in to change notification settings - Fork 0
/
uva10141.cpp
111 lines (98 loc) · 2.28 KB
/
uva10141.cpp
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// question #: 10141
// author: SUN, Ka Meng Isaac (skmisaac)
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <set>
#include <list>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000
typedef struct {
string name;
double price;
int r;
double compliance;
int idx;
} rfp;
bool compare(rfp p1, rfp p2) {
if ( p1.compliance > p2.compliance )
return true;
else if ( p1.compliance == p2.compliance )
{
if ( p1.price < p2.price )
return true;
else if ( p1.price > p2.price )
return false;
else
{
if ( p1.idx < p2.idx )
return true;
else
return false;
}
}
else
return false;
}
int main(int argc, char const *argv[])
{
int requirements, proposals;
vector<rfp> company_list;
bool firstCase = true;
//
// Input process
//
int p = 1;
while ( scanf("%d %d", &requirements, &proposals) && requirements && proposals ) {
if (!firstCase)
printf("\n");
company_list.clear();
int n = requirements;
do
{
string junk;
getline(cin, junk);
} while ( n-- );
string name;
for ( int idx = 0; idx < proposals; idx++ ) {
rfp temp_company;
getline(cin, name);
temp_company.name = name;
temp_company.idx = idx;
scanf("%lf %d\n", &temp_company.price, &temp_company.r);
temp_company.compliance = (double)temp_company.r / requirements;
company_list.push_back(temp_company);
for ( int k = 0; k < company_list[idx].r; k++ ) {
string trash;
getline(cin, trash);
}
}
//
// Sorting
//
sort(company_list.begin(), company_list.end(), compare);
// Debugging
// for ( vector<rfp>::iterator it = company_list.begin(); it != company_list.end(); ++it ) {
// printf("Company: %s Price: %lf Compliance: %lf\n", it->name.c_str(), it->price, it->compliance);
// }
//
// Output
printf("RFP #%d\n", p++);
printf("%s\n", company_list[0].name.c_str());
firstCase = false;
}
return 0;
}