Skip to content

Commit ad7a3a3

Browse files
committed
more question
1 parent 0d4ca94 commit ad7a3a3

File tree

3 files changed

+162
-0
lines changed

3 files changed

+162
-0
lines changed

2017/naqualifier/b.cc

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#include <iostream>
2+
#include <queue>
3+
#include <map>
4+
#include <set>
5+
#include <vector>
6+
#include <utility>
7+
#include <algorithm>
8+
9+
#define mp make_pair
10+
#define pb push_back
11+
12+
#define ll long long int
13+
14+
#define MAXN 50005
15+
#define MAXM 150005
16+
#define MAXF 1005
17+
#define INF 9999999999L
18+
19+
using namespace std;
20+
21+
int n, m, f;
22+
int s, t;
23+
24+
// 1: id, 2: cost
25+
vector<pair<int, ll>> adj[MAXN];
26+
vector<pair<int, int>> flights;
27+
28+
// Gets cleared every time
29+
priority_queue<pair<ll, int>> distlist;
30+
ll dists[MAXN];
31+
32+
ll dijkstra() {
33+
// Remember to invert sign here of the distance.
34+
for (int i = 0; i < n; i++)
35+
dists[i] = -1;
36+
distlist.push(mp(0, s));
37+
38+
while (!distlist.empty()) {
39+
int at = -1;
40+
41+
while (!distlist.empty() && dists[distlist.top().second] != -1)
42+
distlist.pop();
43+
44+
if (distlist.empty()) break;
45+
46+
at = distlist.top().second;
47+
dists[at] = distlist.top().first * -1;
48+
distlist.pop();
49+
50+
for (unsigned long i = 0; i < adj[at].size(); i++) {
51+
int att = adj[at][i].first;
52+
ll d = adj[at][i].second;
53+
54+
if (dists[att] == -1)
55+
distlist.push(mp((dists[at] + d) * -1, att));
56+
}
57+
}
58+
59+
if (dists[t] == -1)
60+
return INF;
61+
return dists[t];
62+
}
63+
64+
int main() {
65+
cin >> n >> m >> f >> s >> t;
66+
67+
for (int i = 0; i < m; i++) {
68+
int a, b;
69+
ll v;
70+
cin >> a >> b >> v;
71+
adj[a].pb(mp(b, v));
72+
adj[b].pb(mp(a, v));
73+
}
74+
75+
for (int i = 0; i < f; i++) {
76+
int a, b;
77+
cin >> a >> b;
78+
flights.pb(mp(a, b));
79+
}
80+
81+
// Also try with no flights.
82+
ll bestDist = dijkstra();
83+
for (int i = 0; i < f; i++) {
84+
int p1, p2;
85+
p1 = flights[i].first;
86+
p2 = flights[i].second;
87+
88+
adj[p1].pb(mp(p2, 0));
89+
90+
bestDist = min(bestDist, dijkstra());
91+
92+
adj[p1].erase(adj[p1].end() - 1);
93+
}
94+
95+
cout << bestDist << endl;
96+
return 0;
97+
}

2017/ncpc/g.cc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
struct fuck {
6+
int v, p;
7+
};
8+
9+
fuck fucks[100005];
10+
11+
int main() {
12+
int n, m;
13+
cin >> n >> m;
14+
15+
int mainPos = 1;
16+
17+
for (int i = 0; i < m; i++) {
18+
int x, pp;
19+
cin >> x >> pp;
20+
21+
if (x == 1) {
22+
23+
} else if (x != 1) {
24+
if (fucks[x].v < fucks[1].v &&
25+
fucks[x].v == fucks[1].v &&
26+
fucks[x].p + pp < fucks[1].p) {
27+
}
28+
}
29+
30+
fucks[x].v++;
31+
fucks[x].p+=pp;
32+
33+
}
34+
35+
return 0;
36+
}

2017/waterloo/a.cc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <iostream>
2+
#include <algorithm>
3+
4+
using namespace std;
5+
6+
bool is_triangle(int a, int b, int c) {
7+
int bigger = max(a, max(b, c));
8+
int others = a + b + c - bigger;
9+
return bigger < others;
10+
}
11+
12+
int main() {
13+
int l1, l2, l3, l4, l5;
14+
cin >> l1 >> l2 >> l3 >> l4 >> l5;
15+
16+
int total = 0;
17+
if (is_triangle(l1, l2, l3)) total++;
18+
if (is_triangle(l1, l2, l4)) total++;
19+
if (is_triangle(l1, l2, l5)) total++;
20+
if (is_triangle(l1, l3, l4)) total++;
21+
if (is_triangle(l1, l3, l5)) total++;
22+
if (is_triangle(l1, l4, l5)) total++;
23+
if (is_triangle(l2, l3, l4)) total++;
24+
if (is_triangle(l2, l3, l5)) total++;
25+
if (is_triangle(l2, l4, l5)) total++;
26+
if (is_triangle(l3, l4, l5)) total++;
27+
28+
cout << total << endl;
29+
}

0 commit comments

Comments
 (0)