Bladeren bron

Merge in full round data (use git subtree merge to update)

master
Yorick van Pelt 2 jaren geleden
bovenliggende
commit
addb57d510
7 gewijzigde bestanden met toevoegingen van 142 en 0 verwijderingen
  1. 7
    0
      full/C.py
  2. 7
    0
      full/E.py
  3. 38
    0
      full/F.cpp
  4. 29
    0
      full/F.py
  5. 12
    0
      full/H.py
  6. 42
    0
      full/I.py
  7. 7
    0
      full/J.py

+ 7
- 0
full/C.py Bestand weergeven

@@ -0,0 +1,7 @@
1
+from __future__ import print_function
2
+import sys
3
+x, y  = map(float, sys.stdin.readline().split())
4
+n     = float(sys.stdin.readline())
5
+for l,u,f in ( map(float, line.split()) for line in sys.stdin ):
6
+  y -= (u-l)*(1-f)
7
+print(x / y)

+ 7
- 0
full/E.py Bestand weergeven

@@ -0,0 +1,7 @@
1
+from __future__ import print_function
2
+import sys
3
+n   = int(sys.stdin.readline())
4
+ss  = map(int, sys.stdin.readline().split())
5
+tt  = sorted(enumerate(ss), key = lambda (i,x): -x)
6
+print(" ".join(str(x[0]+1) for x in tt) if tt[0][1] <= sum(ss)-tt[0][1]
7
+      else "impossible")

+ 38
- 0
full/F.cpp Bestand weergeven

@@ -0,0 +1,38 @@
1
+#include <algorithm>
2
+#include <functional>
3
+#include <iostream>
4
+#include <set>
5
+#include <vector>
6
+
7
+using namespace std;
8
+
9
+long f(vector<long>& l)
10
+{
11
+  long m = 0; set<long, greater<long>> s = {0};
12
+  for(auto x : l) {
13
+    // cerr << "x = " << x << endl;
14
+    if (s.count(x) == 0) {
15
+      m = max(m, min(*s.begin(), x));
16
+      s.insert(x);
17
+    } else {
18
+      s.erase(x);
19
+      m = max(m, min(*s.begin(), x));
20
+    }
21
+    // cerr << "m = " << m << endl;
22
+  }
23
+  return m;
24
+}
25
+
26
+int main()
27
+{
28
+  long n; cin >> n; vector<long> l1(n), l2(n);
29
+  for (long i = 0; i < n; ++i) cin >> l1[i];
30
+  for (long i = 0; i < n; ++i) cin >> l2[i];
31
+  set<long> s2(begin(l2), end(l2));
32
+  set<long, greater<long>> s; vector<long> l1_, l2_;
33
+  for (auto x : l1) if (s2.count(x) == 1) s.insert(x);
34
+  for (auto x : l1) if (s.count(x) == 0) l1_.push_back(x);
35
+  for (auto x : l2) if (s.count(x) == 0) l2_.push_back(x);
36
+  long m = *s.begin();
37
+  cout << max(m, max(f(l1_), f(l2_))) << endl;
38
+}

+ 29
- 0
full/F.py Bestand weergeven

@@ -0,0 +1,29 @@
1
+MOVED_TO_CPP
2
+
3
+from __future__ import print_function
4
+import sys
5
+
6
+def f(l):
7
+  m, s, ms = 0, set(), 0
8
+  for x in l:
9
+    if x not in s:
10
+      s.add(x)
11
+      ms = max(x, ms)
12
+    else:
13
+      s.remove(x)
14
+      ms = ...
15
+    if ms > x:
16
+      m = max(m, x)
17
+    else:
18
+      m = max(m, ms)
19
+  return m
20
+
21
+n   = int(sys.stdin.readline())
22
+l1  = map(int, sys.stdin.readline().split())
23
+l2  = map(int, sys.stdin.readline().split())
24
+s2  = set(l2)
25
+s   = [ x for x in l1 if x in s2 ]
26
+l1  = [ x for x in l1 if x not in s ]
27
+l2  = [ x for x in l2 if x not in s ]
28
+m   = max(s)
29
+print(max(m, max(f(l1), f(l2))))

+ 12
- 0
full/H.py Bestand weergeven

@@ -0,0 +1,12 @@
1
+from __future__ import print_function
2
+import sys
3
+def to_int(x):
4
+  bs = []
5
+  for b in x:
6
+    if bs and bs[-1]:
7
+      bs.append(0 if b == "1" else 1)
8
+    else:
9
+      bs.append(1 if b == "1" else 0)
10
+  return int("".join(map(str, bs)), 2)
11
+n, a, b = sys.stdin.readline().split(); n = int(n)
12
+print(to_int(b) - to_int(a) - 1)

+ 42
- 0
full/I.py Bestand weergeven

@@ -0,0 +1,42 @@
1
+from __future__ import print_function
2
+import heapq, sys
3
+
4
+def dijkstra(G, s):
5
+  V, E = G; d = {}; S = set(); q = []
6
+  for u in V: d.setdefault(u, None)
7
+  for u in s:
8
+    d[u] = 0; heapq.heappush(q, (0,u))
9
+  while q:
10
+    n, u = heapq.heappop(q)
11
+    if u in S: continue
12
+    S.add(u)
13
+    for v in E[u]:
14
+      if d[v] is None or d[v] > d[u] + 1:
15
+        d[v] = d[u] + 1; heapq.heappush(q, (d[v],v))
16
+  return d
17
+
18
+def transpose(G):
19
+  V, E = G; ET = {}
20
+  for u in V: ET[u] = []
21
+  for u, vs in E.iteritems():
22
+    for v in vs: ET[v].append(u)
23
+  return V, ET
24
+
25
+n, m, k = map(int, sys.stdin.readline().split())
26
+iron    = [ int(x)-1 for x in sys.stdin.readline().split() ]
27
+coal    = [ int(x)-1 for x in sys.stdin.readline().split() ]
28
+V, E    = range(n), {}
29
+for i, line in enumerate(sys.stdin):
30
+  E[i] = [ int(x)-1 for x in line.split()[1:] ]
31
+G       = V, E
32
+GT      = transpose(G)
33
+ds      = dijkstra(G, [0])
34
+di      = dijkstra(GT, iron)
35
+dc      = dijkstra(GT, coal)
36
+try:
37
+  m = min( ds[i]+di[i]+dc[i] for i in xrange(n)
38
+           if None not in (ds[i],di[i],dc[i]) )
39
+  print(m)
40
+except ValueError as e:
41
+  if "empty" not in e.args[0]: raise
42
+  print("impossible")

+ 7
- 0
full/J.py Bestand weergeven

@@ -0,0 +1,7 @@
1
+from __future__ import print_function
2
+import sys
3
+n, q, s = map(int, float, sys.stdin.readline().split())
4
+s_to_q  = map(int, float, sys.stdin.readline().split())
5
+q_sizes = map(int, float, sys.stdin.readline().split())
6
+
7
+# alleen nog even...

Laden…
Annuleren
Opslaan