buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
change_count
int64
0
100
#include <algorithm> #include <cmath> #include <iostream> #include <vector> using namespace std; #define MAX_N 100000 long long q[MAX_N]; long long x[MAX_N]; long long n, z; vector<long long> p; int main() { while (true) { for (int i = 0; i < MAX_N; i++) { q[i] = 0; x[i] = 0; } cin >> n; p.clear(); if (n == 0) { break; } for (int i = 1; i < n; i++) { q[(i * i) % n] = 1; } for (int i = 1; i < n; i++) { if (q[i] == 1) { p.push_back(i); } } for (int i = 0; i < p.size(); i++) { for (int j = i + 1; j < p.size(); j++) { if (i != j) { z = p[i] - p[j]; if (z < 0) { z += n; } if (z > (n - 1) / 2) { z = n - z; } x[z]++; } } } for (int i = 1; i <= (n - 1) / 2; i++) { cout << x[i] * 2 << endl; } } }
#include <algorithm> #include <cmath> #include <iostream> #include <vector> using namespace std; #define MAX_N 100000 long long q[MAX_N]; long long x[MAX_N]; long long n, z; vector<long long> p; int main() { while (true) { for (int i = 0; i < MAX_N; i++) { q[i] = 0; x[i] = 0; } cin >> n; p.clear(); if (n == 0) { break; } for (int i = 1; i < n; i++) { q[(i * i) % n] = 1; } for (int i = 0; i < MAX_N; i++) { if (q[i] == 1) { p.push_back(i); } } for (int i = 0; i < p.size(); i++) { for (int j = i + 1; j < p.size(); j++) { if (i != j) { z = p[i] - p[j]; if (z < 0) { z += n; } if (z > (n - 1) / 2) { z = n - z; } x[z]++; } } } for (int i = 1; i <= (n - 1) / 2; i++) { cout << x[i] * 2 << endl; } } }
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22]]
1
300
4
#include <bits/stdc++.h> using namespace std; int main() { int n; while (cin >> n, n) { int m = (n - 1) / 2; bool sq[10001] = {false}; int a[5001] = {0}; for (int i = 1; i < n; i++) sq[(i * i) % n] = true; for (int i = 1; i < n; i++) { if (!sq[i]) continue; for (int j = 1; j < n; j++) { if (i == j) continue; if (!sq[j]) continue; int d = i - j; if (d < 0) { if (d + n > m) a[n - (d + n)]++; else a[d + n]++; } else { if (d > m) a[n - d]++; else a[d]++; } } } for (int i = 1; i <= m; i++) cout << a[i] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; while (cin >> n, n) { int m = (n - 1) / 2; bool sq[10001] = {false}; int a[5001] = {0}; for (int i = 1; i < n; i++) sq[(i * i) % n] = true; for (int i = 0; i < n; i++) { if (!sq[i]) continue; for (int j = 0; j < n; j++) { if (i == j) continue; if (!sq[j]) continue; int d = i - j; if (d < 0) { if (d + n > m) a[n - (d + n)]++; else a[d + n]++; } else { if (d > m) a[n - d]++; else a[d]++; } } } for (int i = 1; i <= m; i++) cout << a[i] << endl; } return 0; }
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13]]
1
237
4
#include <algorithm> #include <iostream> #include <set> #include <vector> using namespace std; int cnt[5010]; int main() { int n; while (cin >> n && n) { set<int> st; vector<int> v; for (int i = 1; i < n; i++) { st.insert(i * i % n); } set<int>::iterator it = st.begin(); while (it != st.end()) { v.push_back(*it); ++it; } for (int i = 0; i < (n - 1) / 2; i++) cnt[i] = 0; for (int i = 0; i < v.size(); i++) { for (int j = i + 1; j < v.size(); j++) { int x = v[j] - v[i]; x = min(x, n - x); cnt[x] += 2; } } for (int i = 1; i <= (n - 1) / 2; i++) cout << cnt[i] << endl; } return 0; }
#include <algorithm> #include <iostream> #include <set> #include <vector> using namespace std; int cnt[5010]; int main() { int n; while (cin >> n && n) { set<int> st; vector<int> v; for (int i = 1; i < n; i++) { st.insert(i * i % n); } set<int>::iterator it = st.begin(); while (it != st.end()) { v.push_back(*it); ++it; } for (int i = 0; i <= (n - 1) / 2; i++) cnt[i] = 0; for (int i = 0; i < v.size(); i++) { for (int j = i + 1; j < v.size(); j++) { int x = v[j] - v[i]; x = min(x, n - x); cnt[x] += 2; } } for (int i = 1; i <= (n - 1) / 2; i++) cout << cnt[i] << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
1
245
2
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <utility> #include <vector> using namespace std; typedef long long Int; typedef vector<int> vint; typedef pair<int, int> pint; #define mp make_pair template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; } template <class T> void chmin(T &t, T f) { if (t > f) t = f; } template <class T> void chmax(T &t, T f) { if (t < f) t = f; } int in() { int x; scanf("%d", &x); return x; } int a[10010]; int b[10010]; int main() { int n; while (n = in()) { memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); int i, j; for (i = 1; i < n; i++) { a[i * i % n] = 1; } for (i = 1; i < n; i++) { if (a[i] == 0) continue; for (j = i + 1; j < n; j++) { if (a[j] == 0) continue; int k = i - j; if (k < 0) k += n; if (k > (n - 1) / 2) k = n - k; b[k] += 2; } } for (i = 1; i < (n + 1) / 2; i++) cout << b[i] << endl; } return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <utility> #include <vector> using namespace std; typedef long long Int; typedef vector<int> vint; typedef pair<int, int> pint; #define mp make_pair template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; } template <class T> void chmin(T &t, T f) { if (t > f) t = f; } template <class T> void chmax(T &t, T f) { if (t < f) t = f; } int in() { int x; scanf("%d", &x); return x; } int a[10010]; int b[10010]; int main() { int n; while (n = in()) { memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); int i, j; for (i = 1; i < n; i++) { a[i * i % n] = 1; } for (i = 0; i < n; i++) { if (a[i] == 0) continue; for (j = i + 1; j < n; j++) { if (a[j] == 0) continue; int k = i - j; if (k < 0) k += n; if (k > (n - 1) / 2) k = n - k; b[k] += 2; } } for (i = 1; i < (n + 1) / 2; i++) cout << b[i] << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 10, 11, 12, 13], ["+", 0, 52, 8, 9, 0, 7, 10, 11, 12, 13]]
1
394
2
#include <cstdio> #include <set> int i, n, v[9999]; main() { for (; scanf("%d", &n), n;) { std::set<int> t; for (i = 0; i < n;) v[++i] = 0, t.insert(i * i % n); for (auto s = t.begin(), S = s, T = t.end(); s != T; S = ++s) for (; ++S != T; v[i > n / 2 ? n - i : i] += 2) i = *S - *s; for (i = 0; i < n / 2;) printf("%d\n", v[++i]); } }
#include <cstdio> #include <set> int i, n, v[9999]; main() { for (; scanf("%d", &n), n;) { std::set<int> t; for (i = 0; i < n - 1;) v[++i] = 0, t.insert(i * i % n); for (auto s = t.begin(), S = s, T = t.end(); s != T; S = ++s) for (; ++S != T; v[i > n / 2 ? n - i : i] += 2) i = *S - *s; for (i = 0; i < n / 2;) printf("%d\n", v[++i]); } }
[["+", 8, 9, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13]]
1
167
2
#include <algorithm> #include <iostream> #include <vector> #define REP(i, s, n) for (int i = s; i < n; i++) #define rep(i, n) REP(i, 0, n) using namespace std; int main() { int ans[100000000], n; while (cin >> n, n) { vector<int> vec; rep(i, (int)((n - 1) / 2) + 1) ans[i] = 0; REP(i, 1, n) vec.push_back((i * i) % n); sort(vec.begin(), vec.end()); vec.erase(unique(vec.begin(), vec.end()), vec.end()); rep(i, vec.size()) { rep(j, vec.size()) { int diff = vec[i] - vec[j]; if (diff < 0) diff += n; if (diff > (n - 1) / 2) diff = n - diff; if (1 <= diff && diff <= (n - 1) / 2) ans[diff]++; } } REP(i, 1, (int)((n - 1) / 2) + 1) cout << ans[i] << endl; } return 0; }
#include <algorithm> #include <iostream> #include <vector> #define REP(i, s, n) for (int i = s; i < n; i++) #define rep(i, n) REP(i, 0, n) using namespace std; int main() { int ans[1000000], n; while (cin >> n, n) { vector<int> vec; rep(i, (int)((n - 1) / 2) + 1) ans[i] = 0; REP(i, 1, n) vec.push_back((i * i) % n); sort(vec.begin(), vec.end()); vec.erase(unique(vec.begin(), vec.end()), vec.end()); rep(i, vec.size()) { rep(j, vec.size()) { int diff = vec[i] - vec[j]; if (diff < 0) diff += n; if (diff > (n - 1) / 2) diff = n - diff; if (1 <= diff && diff <= (n - 1) / 2) ans[diff]++; } } REP(i, 1, (int)((n - 1) / 2) + 1) cout << ans[i] << endl; } return 0; }
[["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13]]
1
269
2
#include <algorithm> #include <iostream> #include <set> #include <string.h> #include <vector> using namespace std; int number[5000]; void solve() { int n; while (cin >> n, n) { memset(number, 0, sizeof(number)); set<int> Set; for (int i = 1; i < n; ++i) { Set.insert((i * i) % n); } vector<int> num; int size = (n - 1) / 2; set<int>::iterator it = Set.begin(); while (it != Set.end()) { set<int>::iterator it2 = Set.begin(); while (it2 != Set.end()) { int temp = *it2 - *it; if (temp < 0) { temp += n; } if (temp > size) { temp = n - temp; } ++number[temp]; ++it2; } ++it; } for (int i = 1; i < size; ++i) { cout << number[i] << endl; } } } int main() { solve(); return (0); }
#include <algorithm> #include <iostream> #include <set> #include <string.h> #include <vector> using namespace std; int number[5000]; void solve() { int n; while (cin >> n, n) { memset(number, 0, sizeof(number)); set<int> Set; for (int i = 1; i < n; ++i) { Set.insert((i * i) % n); } vector<int> num; int size = (n - 1) / 2; set<int>::iterator it = Set.begin(); while (it != Set.end()) { set<int>::iterator it2 = Set.begin(); while (it2 != Set.end()) { int temp = *it2 - *it; if (temp < 0) { temp += n; } if (temp > size) { temp = n - temp; } ++number[temp]; ++it2; } ++it; } for (int i = 1; i <= size; ++i) { cout << number[i] << endl; } } } int main() { solve(); return (0); }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
1
242
2
#include <stdio.h> int main() { int x[5], y[5], n, ax, ay, bx, by, i, j; scanf("%d", &n); while (n--) { for (i = 0; i < 5; i++) scanf("%d %d", &x[i], &y[i]); int f[2] = {0}; for (i = 0; i < 2; i++) { for (j = 0; j < 3; j++) { ax = x[(j + 1) % 3] - x[j]; ay = y[(j + 1) & 3] - y[j]; bx = x[i + 3] - x[j]; by = y[i + 3] - y[j]; if (ax * by > ay * bx) f[i]++; } f[i] %= 3; } if (f[0] + f[1] == 0 || f[0] * f[1]) printf("NG\n"); else printf("OK\n"); } return 0; }
#include <stdio.h> int main() { int x[5], y[5], n, ax, ay, bx, by, i, j; scanf("%d", &n); while (n--) { for (i = 0; i < 5; i++) scanf("%d %d", &x[i], &y[i]); int f[2] = {0}; for (i = 0; i < 2; i++) { for (j = 0; j < 3; j++) { ax = x[(j + 1) % 3] - x[j]; ay = y[(j + 1) % 3] - y[j]; bx = x[i + 3] - x[j]; by = y[i + 3] - y[j]; if (ax * by > ay * bx) f[i]++; } f[i] %= 3; } if (f[0] + f[1] == 0 || f[0] * f[1]) printf("NG\n"); else printf("OK\n"); } return 0; }
[["-", 0, 11, 12, 16, 31, 69, 71, 16, 17, 67], ["+", 0, 11, 12, 16, 31, 69, 71, 16, 17, 109]]
0
253
2
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <queue> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef pair<int, int> P; typedef long double ld; typedef vector<int> vi; #define pu push #define pb push_back #define mp make_pair #define eps 1e-9 #define INF 2000000000 #define LINF 1000000000000000ll #define sz(x) ((int)(x).size()) #define fi first #define sec second #define SORT(x) sort((x).begin(), (x).end()) #define all(x) (x).begin(), (x).end() #define EQ(a, b) (abs((a) - (b)) < eps) bool isin(int a, int b, int c, int d, int p, int q) { // printf("%d %d %d %d %d %d\n",a,b,c,d,p,q); ld s, t; ld A = a, B = b, C = c, D = d, P = p, Q = q; if (b == 0) { t = Q / D; s = P / A - (C * Q) / (A * D); // cout << s << ' ' << t << endl; if (s > 0 && t > 0 && s + t < 1) return true; else return false; } if (a == 0) { t = P / C; s = Q / B - (D * Q) / (B * C); // cout << s << ' ' << t << endl; if (s > 0 && t > 0 && s + t < 1) return true; else return false; } t = (P * B - A * Q) / (B * C - A * D); s = (P - C * t) / A; // cout << s << ' ' << t << endl; if (s > 0 && t > 0 && s + t < 1) return true; else return false; } int main() { int Q; scanf("%d", &Q); int x1, x2, x3, y1, y2, y3, xk, yk, xs, ys; for (int i = 0; i < Q; i++) { scanf("%d %d %d %d %d %d %d %d %d %d", &x1, &y1, &x2, &y2, &x3, &y3, &xk, &yk, &xs, &ys); int a, b, c, d, p, q, r, s; a = x2 - x1; b = y2 - y1; c = x3 - x1; d = y3 - y1; p = xk - x1; q = yk - y1; r = xs - x1; s = ys - y1; bool orihime = isin(a, b, c, d, p, q); bool kengyu = isin(a, b, c, d, r, s); if (kengyu != orihime) cout << "OK" << endl; else cout << "NO" << endl; } return 0; }
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <queue> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef pair<int, int> P; typedef long double ld; typedef vector<int> vi; #define pu push #define pb push_back #define mp make_pair #define eps 1e-9 #define INF 2000000000 #define LINF 1000000000000000ll #define sz(x) ((int)(x).size()) #define fi first #define sec second #define SORT(x) sort((x).begin(), (x).end()) #define all(x) (x).begin(), (x).end() #define EQ(a, b) (abs((a) - (b)) < eps) bool isin(int a, int b, int c, int d, int p, int q) { // printf("%d %d %d %d %d %d\n",a,b,c,d,p,q); ld s, t; ld A = a, B = b, C = c, D = d, P = p, Q = q; if (b == 0) { t = Q / D; s = P / A - (C * Q) / (A * D); // cout << s << ' ' << t << endl; if (s > 0 && t > 0 && s + t < 1) return true; else return false; } if (a == 0) { t = P / C; s = Q / B - (D * Q) / (B * C); // cout << s << ' ' << t << endl; if (s > 0 && t > 0 && s + t < 1) return true; else return false; } t = (P * B - A * Q) / (B * C - A * D); s = (P - C * t) / A; // cout << s << ' ' << t << endl; if (s > 0 && t > 0 && s + t < 1) return true; else return false; } int main() { int Q; scanf("%d", &Q); int x1, x2, x3, y1, y2, y3, xk, yk, xs, ys; for (int i = 0; i < Q; i++) { scanf("%d %d %d %d %d %d %d %d %d %d", &x1, &y1, &x2, &y2, &x3, &y3, &xk, &yk, &xs, &ys); int a, b, c, d, p, q, r, s; a = x2 - x1; b = y2 - y1; c = x3 - x1; d = y3 - y1; p = xk - x1; q = yk - y1; r = xs - x1; s = ys - y1; bool orihime = isin(a, b, c, d, p, q); bool kengyu = isin(a, b, c, d, r, s); if (kengyu != orihime) cout << "OK" << endl; else cout << "NG" << endl; } return 0; }
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
545
2
#define _USE_MATH_DEFINES #include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define EPS 1e-8 #define INF 1000000 struct Point { double x, y; Point() {} Point(double _x, double _y) { x = _x; y = _y; } Point operator+(const Point p) const { return Point(x + p.x, y + p.y); } Point operator-(const Point p) const { return Point(x - p.x, y - p.y); } Point operator*(const double d) const { return Point(x * d, y * d); } bool operator<(const Point &p) const { if (x == p.x) return y < p.y; return x < p.x; } bool operator==(const Point &p) const { return abs(x - p.x) < EPS && abs(y - p.y) < EPS; } double norm() { return x * x + y * y; } bool input() { if (cin >> x >> y) return true; return false; } }; struct Line { Point a, b; Line() {} Line(Point _a, Point _b) { a = _a; b = _b; } bool input() { if (a.input() && b.input()) return true; return false; } }; struct Circle { Point c; double r; Circle() {} Circle(Point _c, double _r) { c = _c; r = _r; } }; typedef Point Vector; typedef vector<Point> Polygon; typedef Line Segment; double dot(Point p, Point q) { return p.x * q.x + p.y * q.y; } double cross(Point p, Point q) { return p.x * q.y - q.x * p.y; } int ccw(Point a, Point b, Point c) { Vector v1 = b - a; Vector v2 = c - a; if (cross(v1, v2) > EPS) return +1; if (cross(v1, v2) < -EPS) return -1; if (dot(v1, v2) < -EPS) return +2; if (v2.norm() - v1.norm() > EPS) return -2; return 0; } Point project(Segment s, Point p) { Vector v1 = s.b - s.a; Vector v2 = p - s.a; double r = dot(v1, v2) / v1.norm(); return s.a + v1 * r; } Point reflect(Segment s, Point p) { return p + (project(s, p) - p) * 2.0; } bool intersect_ll(Line l, Line m) { return ccw(l.a, l.b, m.a) * ccw(l.a, l.b, m.b) <= 0 && ccw(m.a, m.b, l.a) * ccw(m.a, m.b, l.b) <= 0; } bool crosspoint_ss(Segment s, Segment t, Point &p) { Vector a1, a2, b1, b2; a1 = s.b - s.a; a2 = t.b - t.a; b1 = t.a - s.a; b2 = s.a - t.b; double s1, s2; s1 = cross(a1, b1) / 2; s2 = cross(a1, b2) / 2; if (s1 + s2 < EPS) return false; p = Point(t.a.x + a2.x * s1 / (s1 + s2), t.a.y + a2.y * s1 / (s1 + s2)); return true; } int crosspoint_ll(Line l, Line m, Point &p) { if (intersect_ll(l, m) == false) return 0; if (crosspoint_ss(l, m, p) == true) return 1; return -1; } int crosspoint_cc(Circle c1, Circle c2, Point &p1, Point &p2) { double d, a, t; d = sqrt((c2.c - c1.c).norm()); if (abs(c1.c.x - c2.c.x) < EPS && abs(c1.c.y - c2.c.y) < EPS && abs(c1.r - c2.r) < EPS) return -1; if (d < abs(c1.r - c2.r) || c1.r + c2.r < d) return 0; a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d)); t = atan2(c2.c.y - c1.c.y, c2.c.x - c1.c.x); p1 = Point(c1.c.x + c1.r * cos(t + a), c1.c.y + c1.r * sin(t + a)); p2 = Point(c1.c.x + c1.r * cos(t - a), c1.c.y + c1.r * sin(t - a)); if (abs(p1.x - p2.x) < EPS && abs(p1.y - p2.y) < EPS) return 1; return 2; } int contain_gp(Polygon g, Point p) { Line l = Line(p, Point(INF, p.y)); int cnt = 0, n = g.size(); for (int i = 0; i < n; i++) { Vector a = g[i] - p; Vector b = g[(i + 1) % n] - p; if (ccw(g[i], g[(i + 1) % n], p) == 0) return 1; if (a.y > b.y) swap(a, b); if (a.y <= EPS && EPS < b.y && cross(a, b) > EPS) cnt++; } if ((cnt & 1) == 1) return 2; return 0; } Polygon andrewScan(Polygon s) { if (s.size() <= 2) return s; sort(s.begin(), s.end()); Polygon g; for (int i = 0; i < s.size(); i++) { for (int n = g.size(); n >= 2 && ccw(g[n - 2], g[n - 1], s[i]) != -1; n--) { g.pop_back(); } g.push_back(s[i]); } int upper_n = g.size(); for (int i = s.size() - 2; i >= 0; i--) { for (int n = g.size(); n > upper_n && ccw(g[n - 2], g[n - 1], s[i]) != -1; n--) { g.pop_back(); } g.push_back(s[i]); } reverse(g.begin(), g.end()); g.pop_back(); return g; } int main() { Polygon g(3); Point k, s; int N; cin >> N; for (int ds = 0; ds < N; ds++) { for (int i = 0; i < 3; i++) g[i].input(); k.input(); s.input(); if (contain_gp(g, s) && !contain_gp(g, k)) puts("OK"); else puts("NG"); } return 0; }
#define _USE_MATH_DEFINES #include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define EPS 1e-8 #define INF 1000000 struct Point { double x, y; Point() {} Point(double _x, double _y) { x = _x; y = _y; } Point operator+(const Point p) const { return Point(x + p.x, y + p.y); } Point operator-(const Point p) const { return Point(x - p.x, y - p.y); } Point operator*(const double d) const { return Point(x * d, y * d); } bool operator<(const Point &p) const { if (x == p.x) return y < p.y; return x < p.x; } bool operator==(const Point &p) const { return abs(x - p.x) < EPS && abs(y - p.y) < EPS; } double norm() { return x * x + y * y; } bool input() { if (cin >> x >> y) return true; return false; } }; struct Line { Point a, b; Line() {} Line(Point _a, Point _b) { a = _a; b = _b; } bool input() { if (a.input() && b.input()) return true; return false; } }; struct Circle { Point c; double r; Circle() {} Circle(Point _c, double _r) { c = _c; r = _r; } }; typedef Point Vector; typedef vector<Point> Polygon; typedef Line Segment; double dot(Point p, Point q) { return p.x * q.x + p.y * q.y; } double cross(Point p, Point q) { return p.x * q.y - q.x * p.y; } int ccw(Point a, Point b, Point c) { Vector v1 = b - a; Vector v2 = c - a; if (cross(v1, v2) > EPS) return +1; if (cross(v1, v2) < -EPS) return -1; if (dot(v1, v2) < -EPS) return +2; if (v2.norm() - v1.norm() > EPS) return -2; return 0; } Point project(Segment s, Point p) { Vector v1 = s.b - s.a; Vector v2 = p - s.a; double r = dot(v1, v2) / v1.norm(); return s.a + v1 * r; } Point reflect(Segment s, Point p) { return p + (project(s, p) - p) * 2.0; } bool intersect_ll(Line l, Line m) { return ccw(l.a, l.b, m.a) * ccw(l.a, l.b, m.b) <= 0 && ccw(m.a, m.b, l.a) * ccw(m.a, m.b, l.b) <= 0; } bool crosspoint_ss(Segment s, Segment t, Point &p) { Vector a1, a2, b1, b2; a1 = s.b - s.a; a2 = t.b - t.a; b1 = t.a - s.a; b2 = s.a - t.b; double s1, s2; s1 = cross(a1, b1) / 2; s2 = cross(a1, b2) / 2; if (s1 + s2 < EPS) return false; p = Point(t.a.x + a2.x * s1 / (s1 + s2), t.a.y + a2.y * s1 / (s1 + s2)); return true; } int crosspoint_ll(Line l, Line m, Point &p) { if (intersect_ll(l, m) == false) return 0; if (crosspoint_ss(l, m, p) == true) return 1; return -1; } int crosspoint_cc(Circle c1, Circle c2, Point &p1, Point &p2) { double d, a, t; d = sqrt((c2.c - c1.c).norm()); if (abs(c1.c.x - c2.c.x) < EPS && abs(c1.c.y - c2.c.y) < EPS && abs(c1.r - c2.r) < EPS) return -1; if (d < abs(c1.r - c2.r) || c1.r + c2.r < d) return 0; a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d)); t = atan2(c2.c.y - c1.c.y, c2.c.x - c1.c.x); p1 = Point(c1.c.x + c1.r * cos(t + a), c1.c.y + c1.r * sin(t + a)); p2 = Point(c1.c.x + c1.r * cos(t - a), c1.c.y + c1.r * sin(t - a)); if (abs(p1.x - p2.x) < EPS && abs(p1.y - p2.y) < EPS) return 1; return 2; } int contain_gp(Polygon g, Point p) { Line l = Line(p, Point(INF, p.y)); int cnt = 0, n = g.size(); for (int i = 0; i < n; i++) { Vector a = g[i] - p; Vector b = g[(i + 1) % n] - p; if (ccw(g[i], g[(i + 1) % n], p) == 0) return 1; if (a.y > b.y) swap(a, b); if (a.y <= EPS && EPS < b.y && cross(a, b) > EPS) cnt++; } if ((cnt & 1) == 1) return 2; return 0; } Polygon andrewScan(Polygon s) { if (s.size() <= 2) return s; sort(s.begin(), s.end()); Polygon g; for (int i = 0; i < s.size(); i++) { for (int n = g.size(); n >= 2 && ccw(g[n - 2], g[n - 1], s[i]) != -1; n--) { g.pop_back(); } g.push_back(s[i]); } int upper_n = g.size(); for (int i = s.size() - 2; i >= 0; i--) { for (int n = g.size(); n > upper_n && ccw(g[n - 2], g[n - 1], s[i]) != -1; n--) { g.pop_back(); } g.push_back(s[i]); } reverse(g.begin(), g.end()); g.pop_back(); return g; } int main() { Polygon g(3); Point k, s; int N; cin >> N; for (int ds = 0; ds < N; ds++) { for (int i = 0; i < 3; i++) g[i].input(); k.input(); s.input(); if (contain_gp(g, s) != contain_gp(g, k)) puts("OK"); else puts("NG"); } return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 98], ["-", 0, 57, 15, 339, 51, 16, 12, 91, 17, 111], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 79]]
1
1,680
3
#include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef vector<PII> VPII; typedef istringstream ISS; typedef ostringstream OSS; #define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i) #define FOR(v, c) for (auto &v : c) #define EACH(it, c) for (auto it = c.begin(); it != c.end(); ++it) #define ALL(c) (c).begin(), (c).end() #define DRANGE(c, p) (c).begin(), (c).begin() + p, (c).end() #define PB(n) push_back(n) #define MP(a, b) make_pair((a), (b)) #define EXIST(c, e) ((c).find(e) != (c).end()) #define fst first #define snd second #define DUMP(x) cerr << #x << " = " << (x) << endl #define DEBUG(x) \ cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << (x) << endl #include <complex> typedef complex<double> Point; const double EPS = 1e-8; // ๅ…ฅๅŠ›ใ‚นใƒˆใƒชใƒผใƒ ใ‹ใ‚‰ๅฎŸๆ•ฐไบŒใคใ‚’ใจใฃใฆ Point ใธ istream &operator>>(istream &s, Point &a) { double r, i; s >> r >> i; a = Point(r, i); return s; } // ๅค–็ฉ๏ผˆใ‚ฏใƒญใ‚น็ฉ๏ผ‰ double cross(const Point &a, const Point &b) { return a.real() * b.imag() - a.imag() * b.real(); } // CCW ้–ขๆ•ฐใ€€a -> b -> c ใจ้€ฒใ‚€ใจใใ€ๅๆ™‚่จˆๅ›žใ‚Šใชใ‚‰ 1, ็›ด้€ฒใชใ‚‰ 0, ๆ™‚่จˆๅ›žใ‚Šใชใ‚‰ // -1 include : cross int ccw(const Point &a, const Point &b, const Point &c) { if (cross((b - a), (c - a)) < -EPS) { return -1; } else if (EPS < cross((b - a), (c - a))) { return 1; } else { return 0; } } // ็‚น p ใŒๅคš่ง’ๅฝข qs ใฎๅ†…้ƒจใซใ‚ใ‚‹ใ‹ ( Winding Number Algorithm) :TODO // include : ccw bool point_in_polygon(const Point &p, const vector<Point> &qs) { const int N = qs.size(); int wn = 0; for (int i = 0; i < N; ++i) { const Point &s = qs[i], &t = qs[(i + 1) % N]; if (s.imag() - EPS <= t.imag() && s.imag() - EPS < p.imag() && p.imag() + EPS < t.imag()) // ไธŠๅ‘ใใฎ่พบ { wn += ccw(s, p, t) == -1; } else if (t.imag() - EPS <= s.imag() && t.imag() - EPS < p.imag() && p.imag() + EPS < s.imag()) { wn -= ccw(t, p, s) == -1; } } return wn; }; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; REP(i, 0, n) { vector<Point> tri(3); REP(j, 0, 3) { cin >> tri[i]; } Point s, t; cin >> s >> t; cout << (point_in_polygon(s, tri) ^ point_in_polygon(t, tri) ? "OK" : "NG") << endl; } return 0; }
#include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef vector<PII> VPII; typedef istringstream ISS; typedef ostringstream OSS; #define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i) #define FOR(v, c) for (auto &v : c) #define EACH(it, c) for (auto it = c.begin(); it != c.end(); ++it) #define ALL(c) (c).begin(), (c).end() #define DRANGE(c, p) (c).begin(), (c).begin() + p, (c).end() #define PB(n) push_back(n) #define MP(a, b) make_pair((a), (b)) #define EXIST(c, e) ((c).find(e) != (c).end()) #define fst first #define snd second #define DUMP(x) cerr << #x << " = " << (x) << endl #define DEBUG(x) \ cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << (x) << endl #include <complex> typedef complex<double> Point; const double EPS = 1e-8; // ใƒ†ใƒปใƒ„?ใƒปใƒ†ใƒปใƒ„็’ฐๅดšใ€ใƒ„ใคใ‚ฑใƒ†ใ€ใƒ„ฮดๆš—ใ€ใƒ„ฮดใ‚งใƒ†ใ€ใƒ„ฮดใ‚ทใƒ†ใ€ใƒ„ฮด?ใ€ใƒ„?ๅ‡ใ€ใƒ„ใคๅ˜‰ใƒปใƒ„ใƒงใƒ„ๆทŒใƒฒใƒ„้–‰ใƒผใƒ†ใ€ใƒ„ใ‚ณใƒ„ๅคใ€ใƒ„?ใ€ใƒ†ใ€ใƒ„ใคๆดฅใ€ใƒ„?ใ‚ฃใƒ†ใ€ใƒ„?ใ€ใƒ†ใ€ใƒ„?ใƒฒ // Point ใƒ†ใ€ใƒ„?ใ‚ฏ istream &operator>>(istream &s, Point &a) { double r, i; s >> r >> i; a = Point(r, i); return s; } // ใƒ†ใƒปใƒ„ใ€ใƒ„ๅงชใ‚กใƒ„ใ‚ฅใƒ„ๅ‚ฌใƒƒใƒ„ใ‚ทใƒ„ๆš—ใ€ใƒ„ใคใƒƒใƒ†ใ€ใƒ„ฮดใƒฅใƒ†ใ€ใƒ„ใคใ‚ฑใƒ†ใ‚กใƒ„ใ‚ฅใƒ„ๅ‚ฌใƒƒใƒ„ใ‚ทใƒ„? double cross(const Point &a, const Point &b) { return a.real() * b.imag() - a.imag() * b.real(); } // CCW ใƒ†ใ‚ฅใƒ„้ณดใ€Œใƒ†ใƒฒใƒ„้–‰ใƒผใƒ†ใ€ใƒ„?? -> b -> c // ใƒ†ใ€ใƒ„?ใ‚ฃใƒ†ใ‚ฅใƒ„?ใ‚คใƒ†ใ€ใƒ„ใค?ใ€ใƒ„?ใ‚ฃใƒ†ใ€ใƒ„?ๅ‚ฌใ€ใƒ„??ใƒปใƒ„ๆธ‰ๅ‚ฌใƒฒใƒ„ๅใฅใ‚ฃใƒ„ใ‚ฃใƒ„ๆš—ใƒปใƒ„ๅดขๆฆฒใ€ใƒ„ใค็”˜ใ€ใƒ„?ใ‚งใƒ†ใ€ใƒ„ใค?1, // ใƒ†ใ‚กใƒ„ๅดขใ‚จใƒ†ใ‚ฅใƒ„?ใ‚คใƒ†ใ€ใƒ„?ใ‚งใƒ†ใ€ใƒ„ใค?0, // ใƒ†ใƒฒใƒ„ๅใฅใ‚ฃใƒ„ใ‚ฃใƒ„ๆš—ใƒปใƒ„ๅดขๆฆฒใ€ใƒ„ใค็”˜ใ€ใƒ„?ใ‚งใƒ†ใ€ใƒ„ใค?-1 include : cross int ccw(const Point &a, const Point &b, const Point &c) { if (cross((b - a), (c - a)) < -EPS) { return -1; } else if (EPS < cross((b - a), (c - a))) { return 1; } else { return 0; } } // ใƒ†ใ‚กใƒ„ใคใ‚ฑ p ใƒ†ใ€ใƒ„?ๅคใƒปใƒ„ใ€ใƒ„ๅ ™ใ‚ฃใƒ„ใ‚กใƒ„ๆดฅใƒปใƒ„ใ‚นใƒ„ใ€Œ qs // ใƒ†ใ€ใƒ„?ใƒงใƒ†ใƒปใƒ„??ใ‚ฅใƒ„ฮดใ‚ฃใƒ†ใ€ใƒ„?ใ‚ฉใƒ†ใ€ใƒ„?ใฅใ€ใƒ„ใคๅ‡ใ€ใƒ„??( Winding Number // Algorithm) :TODO include : ccw bool point_in_polygon(const Point &p, const vector<Point> &qs) { const int N = qs.size(); int wn = 0; for (int i = 0; i < N; ++i) { const Point &s = qs[i], &t = qs[(i + 1) % N]; if (s.imag() - EPS <= t.imag() && s.imag() - EPS < p.imag() && p.imag() + EPS < t.imag()) // ใƒ†ใ€ใƒ„ใ‚ฏใƒ„็”˜ใƒปใƒ„้’ๅฆฅใ€ใƒ„?ๅ‚ฌใ€ใƒ„?ใƒงใƒ†ใ‚ฃใƒ„ใ‚ปใƒ„ใ‚ณ { wn += ccw(s, p, t) == -1; } else if (t.imag() - EPS <= s.imag() && t.imag() - EPS < p.imag() && p.imag() + EPS < s.imag()) { wn -= ccw(t, p, s) == -1; } } return wn; }; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; REP(i, 0, n) { vector<Point> tri(3); REP(j, 0, 3) { cin >> tri[j]; } Point s, t; cin >> s >> t; cout << (point_in_polygon(s, tri) ^ point_in_polygon(t, tri) ? "OK" : "NG") << endl; } return 0; }
[["-", 0, 1, 0, 16, 12, 69, 341, 342, 0, 22], ["+", 0, 1, 0, 16, 12, 69, 341, 342, 0, 22]]
1
660
2
def isin(x,y): if S(x1,y1,x2,y2,x,y)+S(x1,y1,x3,y3,x,y)+S(x3,y3,x2,y2,x,y)-S(x1,y1,x2,y2,x3,y3) != 0: return False else: return True def S(x1,y1,x2,y2,x3,y3): return abs(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2)) for roop in range(int(input())): x1,y1,x2,y2,x3,y3,xk,yk,xs,ys = list(map(int,input().split())) print("OK" if isin(xk,yk) != isin(xs,ys) else "NO")
def isin(x,y): if S(x1,y1,x2,y2,x,y)+S(x1,y1,x3,y3,x,y)+S(x3,y3,x2,y2,x,y)-S(x1,y1,x2,y2,x3,y3) != 0: return False else: return True def S(x1,y1,x2,y2,x3,y3): return abs(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2)) for roop in range(int(input())): x1,y1,x2,y2,x3,y3,xk,yk,xs,ys = list(map(int,input().split())) print("OK" if isin(xk,yk) != isin(xs,ys) else "NG")
[["-", 0, 652, 3, 4, 0, 41, 0, 557, 0, 6], ["+", 0, 652, 3, 4, 0, 41, 0, 557, 0, 6]]
5
192
2
from operator import sub,mul def cross(a,b): return a[0]*b[1] - a[1]*b[0] def func(a,b):# return [list(map(sub,aa,bb)) for aa,bb in zip(a,b)] def check(a): return all([x<0 for x in a]) or all([x>0 for x in a]) for _ in range(eval(input())): line = list(map(int,input().split())) tmp = list(zip(line[:6:2],line[1:6:2])) v = func(tmp[1:]+[tmp[0]],tmp) m = func([line[6:8]]*3,tmp) f = func([line[8:]]*3,tmp) if check(list(map(cross,m,v))) != check(list(map(cross,f,v))): print("OK") else: print("NA")
from operator import sub,mul def cross(a,b): return a[0]*b[1] - a[1]*b[0] def func(a,b):# return [list(map(sub,aa,bb)) for aa,bb in zip(a,b)] def check(a): return all([x<0 for x in a]) or all([x>0 for x in a]) for _ in range(eval(input())): line = list(map(int,input().split())) tmp = list(zip(line[:6:2],line[1:6:2])) v = func(tmp[1:]+[tmp[0]],tmp) m = func([line[6:8]]*3,tmp) f = func([line[8:]]*3,tmp) if check(list(map(cross,m,v))) != check(list(map(cross,f,v))): print("OK") else: print("NG")
[["-", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6]]
5
251
2
#include <stdio.h> int n, m; int t[101][101]; int que[2000]; int qa, qb; int calc(int start, int goal) { int i, pos; int visited[101]; int cost[101]; for (i = 0; i < 101; i++) { visited[i] = 0; cost[i] = 0; } qa = 0; qb = 1; que[0] = start; visited[start] = 1; while (qa < qb) { pos = que[qa]; qa++; if (pos == goal) return cost[pos]; for (i = 1; i <= n; i++) { if (t[pos][i] == 0) continue; if (visited[i] == 1) continue; visited[i] = 1; que[qb] = i; qb++; cost[i] = cost[pos] + 1; } } return 9999; } int main() { int i, j; int id, k, l; int s, d, v; int ans; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d %d", &id, &k); for (j = 0; j < k; j++) { scanf("%d", &l); t[id][l] = 1; } } scanf("%d", &m); for (i = 0; i < m; i++) { scanf("%d %d %d", &s, &d, &v); ans = calc(s, d) + 1; if (ans <= v || ans == 10000) printf("%d\n", ans); else printf("NA\n"); } return 0; }
#include <stdio.h> int n, m; int t[101][101]; int que[2000]; int qa, qb; int calc(int start, int goal) { int i, pos; int visited[101]; int cost[101]; for (i = 0; i < 101; i++) { visited[i] = 0; cost[i] = 0; } qa = 0; qb = 1; que[0] = start; visited[start] = 1; while (qa < qb) { pos = que[qa]; qa++; if (pos == goal) return cost[pos]; for (i = 1; i <= n; i++) { if (t[pos][i] == 0) continue; if (visited[i] == 1) continue; visited[i] = 1; que[qb] = i; qb++; cost[i] = cost[pos] + 1; } } return 9999; } int main() { int i, j; int id, k, l; int s, d, v; int ans; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d %d", &id, &k); for (j = 0; j < k; j++) { scanf("%d", &l); t[id][l] = 1; } } scanf("%d", &m); for (i = 0; i < m; i++) { scanf("%d %d %d", &s, &d, &v); ans = calc(s, d) + 1; if (ans <= v && ans != 10000) printf("%d\n", ans); else printf("NA\n"); } return 0; }
[["-", 8, 9, 0, 57, 15, 23, 0, 16, 17, 106], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 17, 98], ["-", 0, 57, 15, 23, 0, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 17, 79]]
0
393
4
#include <stdio.h> int r[100][100], d[100], f[100]; int dijkstra(int s, int g) { int min, p, i, j; for (i = 0; i < 100; i++) { d[i] = 100000; f[i] = 0; } d[s] = 0; while (1) { min = 100000; for (i = 0; i < 100; i++) { if (d[i] < min && f[i] == 0) { min = d[i]; p = i; } } if (min == 100000) break; f[p] = 1; for (j = 0; j < 100; j++) { if (r[p][j] == 1) { if (d[p] + r[p][j] < d[j]) d[j] = r[p][j] + d[p]; } } } return d[p]; } main() { int s, g, n, o, k, t, i, j, a, p, TTL; for (i = 0; i < 100; i++) { for (j = 0; j < 100; j++) { r[i][j] = 0; } } scanf("%d", &n); for (j = 0; j < n; j++) { scanf("%d %d", &o, &k); for (i = 0; i < k; i++) { scanf("%d", &t); r[o - 1][t - 1] = 1; } } scanf("%d", &p); for (j = 0; j < p; j++) { scanf("%d %d %d", &s, &g, &TTL); a = dijkstra(s - 1, g - 1); if (a <= TTL) { printf("%d\n", a); } else printf("NA\n"); } return 0; }
#include <stdio.h> int r[100][100], d[100], f[100]; int dijkstra(int s, int g) { int min, p, i, j; for (i = 0; i < 100; i++) { d[i] = 100000; f[i] = 0; } d[s] = 0; while (1) { min = 100000; for (i = 0; i < 100; i++) { if (d[i] < min && f[i] == 0) { min = d[i]; p = i; } } if (min == 100000) break; f[p] = 1; for (j = 0; j < 100; j++) { if (r[p][j] == 1) { if (d[p] + r[p][j] < d[j]) d[j] = r[p][j] + d[p]; } } } return d[g] + 1; } main() { int s, g, n, o, k, t, i, j, a, p, TTL; for (i = 0; i < 100; i++) { for (j = 0; j < 100; j++) { r[i][j] = 0; } } scanf("%d", &n); for (j = 0; j < n; j++) { scanf("%d %d", &o, &k); for (i = 0; i < k; i++) { scanf("%d", &t); r[o - 1][t - 1] = 1; } } scanf("%d", &p); for (j = 0; j < p; j++) { scanf("%d %d %d", &s, &g, &TTL); a = dijkstra(s - 1, g - 1); if (a <= TTL) { printf("%d\n", a); } else printf("NA\n"); } return 0; }
[["-", 0, 14, 8, 9, 0, 37, 0, 69, 71, 22], ["+", 8, 9, 0, 37, 0, 16, 31, 69, 71, 22], ["+", 0, 14, 8, 9, 0, 37, 0, 16, 17, 72], ["+", 0, 14, 8, 9, 0, 37, 0, 16, 12, 13]]
0
449
4
n, r, k, m[101][101], t[101], p; i, j, s, d, v0, v, f; main() { scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d%d", &r, &k); for (; k--;) { scanf("%d", &d); m[r][d] = 1; } } scanf("%d", &p); for (; p--;) { scanf("%d%d%d", &s, &d, &v0); memset(t, 0, sizeof(t)); t[s] = v = v0; f = 1; while (f && !t[d] && --v) { f = 0; for (i = 1; i <= n; i++) { if (t[i] == v + 1) { for (j = 1; j <= n; j++) { if (m[i][j] && t[j] == 0) t[j] = v, f = 1; } } } } if (t[d]) printf("%d\n", v0 - t[d] + 1); else puts("NA"); } exit(0); }
n, r, k, m[101][101], t[101], p; i, j, s, d, v0, v, f; main() { scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d%d", &r, &k); for (; k--;) { scanf("%d", &d); m[r][d] = 1; } } scanf("%d", &p); for (; p--;) { scanf("%d%d%d", &s, &d, &v0); memset(t, 0, sizeof(t)); t[s] = v = v0; f = 1; while (f && !t[d] && --v > 0) { f = 0; for (i = 1; i <= n; i++) { if (t[i] == v + 1) { for (j = 1; j <= n; j++) { if (m[i][j] && t[j] == 0) t[j] = v, f = 1; } } } } if (t[d]) printf("%d\n", v0 - t[d] + 1); else puts("NA"); } exit(0); }
[["+", 0, 52, 15, 23, 0, 16, 12, 16, 17, 47], ["+", 0, 52, 15, 23, 0, 16, 12, 16, 12, 13]]
0
295
2
#include <algorithm> #include <cctype> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define INF 100000000 typedef long long ll; int d[110][110]; int main(void) { int n; cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { d[i][j] = INF; } d[i][i] = 0; } for (int i = 0; i < n; i++) { int r, k; cin >> r >> k; --r; int t; for (int j = 0; j < k; j++) { cin >> t; d[r][t - 1] = 1; } } for (int k = 0; k < n; k++) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { d[i][j] = min(d[i][j], d[i][k] + d[k][j]); } } } int p; cin >> p; for (int i = 0; i < p; i++) { int s, D, v; cin >> s >> D >> v; if (v >= d[s - 1][D - 1]) { cout << d[s - 1][D - 1] + 1 << endl; } else { cout << "NA" << endl; } } return 0; }
#include <algorithm> #include <cctype> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define INF 100000000 typedef long long ll; int d[110][110]; int main(void) { int n; cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { d[i][j] = INF; } d[i][i] = 0; } for (int i = 0; i < n; i++) { int r, k; cin >> r >> k; --r; int t; for (int j = 0; j < k; j++) { cin >> t; d[r][t - 1] = 1; } } for (int k = 0; k < n; k++) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { d[i][j] = min(d[i][j], d[i][k] + d[k][j]); } } } int p; cin >> p; for (int i = 0; i < p; i++) { int s, D, v; cin >> s >> D >> v; if (v > d[s - 1][D - 1]) { cout << d[s - 1][D - 1] + 1 << endl; } else { cout << "NA" << endl; } } return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47]]
1
353
2
#include <algorithm> #include <iostream> #include <queue> #include <vector> using namespace std; class Node { public: vector<int> e_to; vector<int> e_cost; bool def; int min_cost; Node() { def = false; min_cost = -1; } }; bool operator==(const Node &ot1, const Node &ot2) { return ot1.min_cost == ot2.min_cost; } bool operator!=(const Node &ot1, const Node &ot2) { return !(ot1 == ot2); } bool operator<(const Node &ot1, const Node &ot2) { return ot1.min_cost < ot2.min_cost; } bool operator>(const Node &ot1, const Node &ot2) { return ot1.min_cost > ot2.min_cost; } bool operator<=(const Node &ot1, const Node &ot2) { return !(ot1 > ot2); } bool operator>=(const Node &ot1, const Node &ot2) { return !(ot1 < ot2); } class Dijkstra { priority_queue<Node, vector<Node>, greater<Node>> que; vector<Node> nodes; public: void Init(int node_num) { nodes.resize(node_num); for (int i = 0; i < node_num; ++i) { nodes[i] = Node(); } } void Put(int id, int to, int cost) { nodes[id].e_to.push_back(to); nodes[id].e_cost.push_back(cost); } int Run(int s, int t) { for (vector<Node>::iterator it = nodes.begin(); it != nodes.end(); ++it) { it->min_cost = -1; it->def = false; } nodes[s].min_cost = 0; que.push(nodes[s]); while (!que.empty()) { Node def_node = que.top(); que.pop(); if (def_node.def) continue; def_node.def = true; for (int i = 0; i < def_node.e_to.size(); ++i) { int to = def_node.e_to[i]; int cost = def_node.min_cost + def_node.e_cost[i]; if (nodes[to].min_cost == -1 || cost < nodes[to].min_cost) { nodes[to].min_cost = cost; que.push(nodes[to]); } } } return nodes[t].min_cost; } }; int main() { int n, r, k, t, p, s, d, v; Dijkstra dijk; cin >> n; dijk.Init(n); for (int i = 0; i < n; ++i) { cin >> r >> k; for (int j = 0; j < k; ++j) { cin >> t; dijk.Put(r - 1, t - 1, 1); } } cin >> p; for (int i = 0; i < p; ++i) { cin >> s >> d >> v; int res = dijk.Run(s - 1, d - 1); if (res >= v) { cout << "NA" << endl; } else { cout << res + 1 << endl; } } return 0; }
#include <algorithm> #include <iostream> #include <queue> #include <vector> using namespace std; class Node { public: vector<int> e_to; vector<int> e_cost; bool def; int min_cost; Node() { def = false; min_cost = -1; } }; bool operator==(const Node &ot1, const Node &ot2) { return ot1.min_cost == ot2.min_cost; } bool operator!=(const Node &ot1, const Node &ot2) { return !(ot1 == ot2); } bool operator<(const Node &ot1, const Node &ot2) { return ot1.min_cost < ot2.min_cost; } bool operator>(const Node &ot1, const Node &ot2) { return ot1.min_cost > ot2.min_cost; } bool operator<=(const Node &ot1, const Node &ot2) { return !(ot1 > ot2); } bool operator>=(const Node &ot1, const Node &ot2) { return !(ot1 < ot2); } class Dijkstra { priority_queue<Node, vector<Node>, greater<Node>> que; vector<Node> nodes; public: void Init(int node_num) { nodes.resize(node_num); for (int i = 0; i < node_num; ++i) { nodes[i] = Node(); } } void Put(int id, int to, int cost) { nodes[id].e_to.push_back(to); nodes[id].e_cost.push_back(cost); } int Run(int s, int t) { for (vector<Node>::iterator it = nodes.begin(); it != nodes.end(); ++it) { it->min_cost = -1; it->def = false; } nodes[s].min_cost = 0; que.push(nodes[s]); while (!que.empty()) { Node def_node = que.top(); que.pop(); if (def_node.def) continue; def_node.def = true; for (int i = 0; i < def_node.e_to.size(); ++i) { int to = def_node.e_to[i]; int cost = def_node.min_cost + def_node.e_cost[i]; if (nodes[to].min_cost == -1 || cost < nodes[to].min_cost) { nodes[to].min_cost = cost; que.push(nodes[to]); } } } return nodes[t].min_cost; } }; int main() { int n, r, k, t, p, s, d, v; Dijkstra dijk; cin >> n; dijk.Init(n); for (int i = 0; i < n; ++i) { cin >> r >> k; for (int j = 0; j < k; ++j) { cin >> t; dijk.Put(r - 1, t - 1, 1); } } cin >> p; for (int i = 0; i < p; ++i) { cin >> s >> d >> v; int res = dijk.Run(s - 1, d - 1); if (res >= v || res == -1) { cout << "NA" << endl; } else { cout << res + 1 << endl; } } return 0; }
[["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 106], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
1
678
4
#include <stdio.h> typedef struct { int group; int people_num; int waiting_time; } wqueue_t; int main(void) { int i, j, k, mode; int tennai[17] = {0}; int wqueue_start = 0; int wqueue_end = 0; wqueue_t wqueue[100] = {0}; int waiting_time_list[100] = {0}; int zikan; int query; for (zikan = 0; zikan <= 1000; zikan++) { if (zikan % 5 == 0 && zikan / 5 < 100) { wqueue[wqueue_end].group = zikan / 5; wqueue[wqueue_end].people_num = ((zikan / 5) % 5 == 1) ? 5 : 2; wqueue[wqueue_end].waiting_time = 0; wqueue_end++; } for (i = 0; i < 17; i++) { if (tennai[i] > 0) tennai[i]--; } for (i = wqueue_start, mode = 1; i < wqueue_end; i++) { if (mode) { for (j = wqueue[i].people_num; j < 17; j++) { for (k = j - wqueue[i].people_num; k < j; k++) { if (tennai[k] > 0) break; } if (k >= j) break; } if (j < 17) { for (k = j - wqueue[i].people_num; k < j; k++) { tennai[k] = 17 * (wqueue[i].group % 2) + 3 * (wqueue[i].group % 3) + 19; } wqueue_start = i + 1; waiting_time_list[wqueue[i].group] = wqueue[i].waiting_time; } else { wqueue[i].waiting_time++; mode = 0; } } else { wqueue[i].waiting_time++; } } } while (scanf("%d", &query) == 1) printf("%d\n", waiting_time_list[query]); return 0; }
#include <stdio.h> typedef struct { int group; int people_num; int waiting_time; } wqueue_t; int main(void) { int i, j, k, mode; int tennai[17] = {0}; int wqueue_start = 0; int wqueue_end = 0; wqueue_t wqueue[100] = {0}; int waiting_time_list[100] = {0}; int zikan; int query; for (zikan = 0; zikan <= 1000; zikan++) { if (zikan % 5 == 0 && zikan / 5 < 100) { wqueue[wqueue_end].group = zikan / 5; wqueue[wqueue_end].people_num = ((zikan / 5) % 5 == 1) ? 5 : 2; wqueue[wqueue_end].waiting_time = 0; wqueue_end++; } for (i = 0; i < 17; i++) { if (tennai[i] > 0) tennai[i]--; } for (i = wqueue_start, mode = 1; i < wqueue_end; i++) { if (mode) { for (j = wqueue[i].people_num; j <= 17; j++) { for (k = j - wqueue[i].people_num; k < j; k++) { if (tennai[k] > 0) break; } if (k >= j) break; } if (j <= 17) { for (k = j - wqueue[i].people_num; k < j; k++) { tennai[k] = 17 * (wqueue[i].group % 2) + 3 * (wqueue[i].group % 3) + 19; } wqueue_start = i + 1; waiting_time_list[wqueue[i].group] = wqueue[i].waiting_time; } else { wqueue[i].waiting_time++; mode = 0; } } else { wqueue[i].waiting_time++; } } } while (scanf("%d", &query) == 1) printf("%d\n", waiting_time_list[query]); return 0; }
[["-", 0, 57, 64, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 57, 64, 9, 0, 7, 15, 16, 17, 19], ["-", 64, 9, 0, 57, 15, 23, 0, 16, 17, 18], ["+", 64, 9, 0, 57, 15, 23, 0, 16, 17, 19]]
0
414
4
#include <bits/stdc++.h> using namespace std; struct G { int group, people, now, time; }; int main() { int minutes[100]; int chair[17]; //ใ‚ใƒผใ˜ใ‚…ใ†ใชใชใ›ใใ‚ใฃใŸ๏ผ๏ผ fill_n(chair, 17, 0); queue<G> mati; for (int i = 0; i < 10000; i++) { if (i % 5 == 0 && i / 5 < 100) { // group leave int group = i / 5; mati.push((G){group, group % 5 == 1 ? 5 : 2, i, 17 * (group % 2) + 3 * (group % 3) + 19}); } while (!mati.empty()) { G &g = mati.front(); int count = 0, pos = -1; for (int j = 0; j < 17; j++) { if (!chair[j]) { count++; if (count == g.people) { pos = j - g.people + 1; break; } } else { count = 0; } } if (pos != -1) { minutes[g.group] = i - g.now; for (int j = pos; j < pos + g.people; j++) { chair[j] = g.time; } mati.pop(); } else { break; } } for (int j = 0; j < 16; j++) { if (chair[j] > 0) chair[j]--; } } int n; while (cin >> n) { cout << minutes[n] << endl; } }
#include <bits/stdc++.h> using namespace std; struct G { int group, people, now, time; }; int main() { int minutes[100]; int chair[17]; //ใ‚ใƒผใ˜ใ‚…ใ†ใชใชใ›ใใ‚ใฃใŸ๏ผ๏ผ fill_n(chair, 17, 0); queue<G> mati; for (int i = 0; i < 10000; i++) { if (i % 5 == 0 && i / 5 < 100) { // group leave int group = i / 5; mati.push((G){group, group % 5 == 1 ? 5 : 2, i, 17 * (group % 2) + 3 * (group % 3) + 19}); } while (!mati.empty()) { G &g = mati.front(); int count = 0, pos = -1; for (int j = 0; j < 17; j++) { if (!chair[j]) { count++; if (count == g.people) { pos = j - g.people + 1; break; } } else { count = 0; } } if (pos != -1) { minutes[g.group] = i - g.now; for (int j = pos; j < pos + g.people; j++) { chair[j] = g.time; } mati.pop(); } else { break; } } for (int j = 0; j < 17; j++) { if (chair[j] > 0) chair[j]--; } } int n; while (cin >> n) { cout << minutes[n] << endl; } }
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13]]
1
336
2
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <set> #include <string> #include <utility> #include <vector> #define loop(i, a, b) for (int i = a; i < b; i++) #define rep(i, a) loop(i, 0, a) #define pb push_back #define mp make_pair #define it ::iterator #define all(in) in.begin(), in.end() const double PI = acos(-1); const double ESP = 1e-10; using namespace std; int main() { int ans[100] = {0}; vector<int> seki(17, -1); vector<int> machi; rep(i, 100000) { // cout<<machi.size()<<endl; if (i > 510 && machi.size() == 0) break; if (i < 100 && i % 5 == 0) machi.pb(i / 5); rep(j, 7) if (seki[j] == 1) seki[j] = -1; else if (seki[j] != -1) seki[j]--; while (1) { if (machi.size() == 0) break; int n; if (machi[0] % 5 == 1) n = 5; else n = 2; bool han = false; rep(j, 17 - n + 1) { bool h = true; rep(k, n) if (seki[k + j] != -1) { h = false; break; } if (h) { han = true; ans[machi[0]] = i - machi[0] * 5; rep(k, n) seki[k + j] = 17 * (machi[0] % 2) + 3 * (machi[0] % 3) + 19; machi.erase(machi.begin()); break; } // cout<<i<<endl; } if (han == false) break; } } int in; while (cin >> in) cout << ans[in] << endl; }
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <set> #include <string> #include <utility> #include <vector> #define loop(i, a, b) for (int i = a; i < b; i++) #define rep(i, a) loop(i, 0, a) #define pb push_back #define mp make_pair #define it ::iterator #define all(in) in.begin(), in.end() const double PI = acos(-1); const double ESP = 1e-10; using namespace std; int main() { int ans[100] = {0}; vector<int> seki(17, -1); vector<int> machi; rep(i, 100000) { // cout<<machi.size()<<endl; if (i > 510 && machi.size() == 0) break; if (i < 500 && i % 5 == 0) machi.pb(i / 5); rep(j, 17) { if (seki[j] == 1) seki[j] = -1; else if (seki[j] != -1) seki[j]--; } while (1) { if (machi.size() == 0) break; int n; if (machi[0] % 5 == 1) n = 5; else n = 2; bool han = false; rep(j, 17 - n + 1) { bool h = true; rep(k, n) if (seki[k + j] != -1) { h = false; break; } if (h) { han = true; ans[machi[0]] = i - machi[0] * 5; rep(k, n) seki[k + j] = 17 * (machi[0] % 2) + 3 * (machi[0] % 3) + 19; machi.erase(machi.begin()); break; } // cout<<i<<endl; } if (han == false) break; } // if(i<100)cout<<i; // if(i<100)rep(l,17)printf(" %3d",seki[l]);//cout<<" "<<seki[l]; // if(i<100)cout<<endl; } int in; while (cin >> in) cout << ans[in] << endl; // rep(i,100)printf("%2d %d\n",i,ans[i]); }
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 12, 13], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 12, 13], ["-", 0, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["+", 0, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["+", 0, 14, 8, 9, 0, 9, 0, 9, 0, 45], ["+", 0, 14, 8, 9, 0, 9, 0, 9, 0, 46]]
1
383
6
#include <iostream> #include <queue> using namespace std; const int MAX_SIZE = 100; const int SEATS = 17; int *calc() { queue<int> q; int *a = new int[MAX_SIZE](); int g, n, s[SEATS] = {}; for (int t = 0;; ++t) { for (int i = 0; i < SEATS; ++i) { if (s[i]) s[i]--; } if (t % 5 == 0) q.push(t / 5); while (!q.empty()) { bool c = false; g = q.front(); n = g % 5 == 1 ? 5 : 2; for (int i = 0; i < SEATS - n; ++i) { if (n == 2 && !(s[i] || s[i + 1])) { s[i] = s[i + 1] = 17 * (g % 2) + 3 * (g % 3) + 19; c = true; break; } if (n == 5 && !(s[i] || s[i + 1] || s[i + 2] || s[i + 3] || s[i + 4])) { s[i] = s[i + 1] = s[i + 2] = s[i + 3] = s[i + 4] = 17 * (g % 2) + 3 * (g % 3) + 19; c = true; break; } } if (c) { a[g] = t - g * 5; if (g == MAX_SIZE - 1) return a; q.pop(); } else { break; } } } return a; } int main() { int n; int *a = calc(); while (true) { cin >> n; if (cin.eof()) break; cout << a[n] << endl; } }
#include <iostream> #include <queue> using namespace std; const int MAX_SIZE = 100; const int SEATS = 17; int *calc() { queue<int> q; int *a = new int[MAX_SIZE](); int g, n, s[SEATS] = {}; for (int t = 0;; ++t) { for (int i = 0; i < SEATS; ++i) { if (s[i]) s[i]--; } if (t % 5 == 0) q.push(t / 5); while (!q.empty()) { bool c = false; g = q.front(); n = g % 5 == 1 ? 5 : 2; for (int i = 0; i < SEATS - n + 1; ++i) { if (n == 2 && !(s[i] || s[i + 1])) { s[i] = s[i + 1] = 17 * (g % 2) + 3 * (g % 3) + 19; c = true; break; } if (n == 5 && !(s[i] || s[i + 1] || s[i + 2] || s[i + 3] || s[i + 4])) { s[i] = s[i + 1] = s[i + 2] = s[i + 3] = s[i + 4] = 17 * (g % 2) + 3 * (g % 3) + 19; c = true; break; } } if (c) { a[g] = t - g * 5; if (g == MAX_SIZE - 1) return a; q.pop(); } else { break; } } } return a; } int main() { int n; int *a = calc(); while (true) { cin >> n; if (cin.eof()) break; cout << a[n] << endl; } }
[["+", 8, 9, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13]]
1
419
2
#include <iostream> using namespace std; int x[16], y[100][2], z[100], p[100], s; int main() { for (int i = 0; i < 16; i++) { x[i] = 10000; } for (int i = 0; i < 100; i++) { z[i] = 10000; } for (int i = 0; i < 100; i++) { y[i][0] = i * 5; y[i][1] = 17 * (i % 2) + 3 * (i % 3) + 19; } for (int i = 0; i < 1000; i++) { // Simulation. for (int j = 0; j < 100; j++) { if (z[j] < 100) { z[j]--; } if (z[j] == 0) { for (int k = 0; k < 16; k++) { if (x[k] == j) { x[k] = 10000; } } z[j] = 10000; } } if (i % 5 == 0 && i < 500) { z[i / 5] = 100000; } for (int j = 0; j <= s; j++) { if (z[j] == 100000) { if (j % 5 != 1) { for (int k = 0; k < 15; k++) { if (x[k] + x[k + 1] == 20000) { x[k] = j; x[k + 1] = j; z[j] = y[j][1]; p[j] = i - y[j][0]; s++; goto E; } } } else { for (int k = 0; k < 12; k++) { if (x[k] + x[k + 1] + x[k + 2] + x[k + 3] + x[k + 4] == 50000) { x[k] = j; x[k + 1] = j; x[k + 2] = j; x[k + 3] = j; x[k + 4] = j; z[j] = y[j][1]; p[j] = i - y[j][0]; s++; goto E; } } } E:; } } } int n; while (cin >> n) { cout << p[n] << endl; } return 0; }
#include <iostream> using namespace std; int x[17], y[100][2], z[100], p[100], s; int main() { for (int i = 0; i < 17; i++) { x[i] = 10000; } for (int i = 0; i < 100; i++) { z[i] = 10000; } for (int i = 0; i < 100; i++) { y[i][0] = i * 5; y[i][1] = 17 * (i % 2) + 3 * (i % 3) + 19; } for (int i = 0; i < 1000; i++) { // Simulation. for (int j = 0; j < 100; j++) { if (z[j] < 100) { z[j]--; } if (z[j] == 0) { for (int k = 0; k < 17; k++) { if (x[k] == j) { x[k] = 10000; } } z[j] = 10000; } } if (i % 5 == 0 && i < 500) { z[i / 5] = 100000; } for (int j = 0; j <= s; j++) { if (z[j] == 100000) { if (j % 5 != 1) { for (int k = 0; k < 16; k++) { if (x[k] + x[k + 1] == 20000) { x[k] = j; x[k + 1] = j; z[j] = y[j][1]; p[j] = i - y[j][0]; s++; goto E; } } } else { for (int k = 0; k < 13; k++) { if (x[k] + x[k + 1] + x[k + 2] + x[k + 3] + x[k + 4] == 50000) { x[k] = j; x[k + 1] = j; x[k + 2] = j; x[k + 3] = j; x[k + 4] = j; z[j] = y[j][1]; p[j] = i - y[j][0]; s++; goto E; } } } E:; } } } int n; while (cin >> n) { cout << p[n] << endl; } return 0; }
[["-", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["-", 0, 57, 64, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 57, 64, 9, 0, 7, 15, 16, 12, 13], ["-", 75, 76, 0, 9, 0, 7, 15, 16, 12, 13], ["+", 75, 76, 0, 9, 0, 7, 15, 16, 12, 13]]
1
545
10
#include <cstdio> #include <iostream> using namespace std; struct cus { int a, b, c, d; }; int main() { cus a[100]; for (int i = 0; i < 100; i++) { a[i].a = 5 * i; a[i].b = (i % 5 == 1 ? 5 : 2); a[i].c = 17 * (i % 2) + 3 * (i % 3) + 19; a[i].d = 0; } int t[20] = {}; for (int i = 0; i < 100; i++) { // for(int j=0;j<17;j++)printf("%3d",t[j]); // cout<<endl; int k = max(a[max(0, i - 1)].d, a[i].a); for (;; k++) for (int j = 0; j < 17 - a[i].b; j++) { bool x = true; for (int l = j; l < j + a[i].b; l++) { if (t[l] > k) x = false; } if (x) { for (int l = j; l < j + a[i].b; l++) { t[l] = k + a[i].c; } a[i].c = k - a[i].a; a[i].d = k; goto end; } }; end:; } int n; while (cin >> n) { cout << a[n].c << endl; } }
#include <cstdio> #include <iostream> using namespace std; struct cus { int a, b, c, d; }; int main() { cus a[100]; for (int i = 0; i < 100; i++) { a[i].a = 5 * i; a[i].b = (i % 5 == 1 ? 5 : 2); a[i].c = 17 * (i % 2) + 3 * (i % 3) + 19; a[i].d = 0; } int t[20] = {}; for (int i = 0; i < 100; i++) { // for(int j=0;j<17;j++)printf("%3d",t[j]); // cout<<endl; int k = max(a[max(0, i - 1)].d, a[i].a); for (;; k++) for (int j = 0; j < 17 - a[i].b + 1; j++) { bool x = true; for (int l = j; l < j + a[i].b; l++) { if (t[l] > k) x = false; } if (x) { for (int l = j; l < j + a[i].b; l++) { t[l] = k + a[i].c; } a[i].c = k - a[i].a; a[i].d = k; goto end; } }; end:; } int n; while (cin >> n) { cout << a[n].c << endl; } }
[["+", 0, 7, 8, 7, 15, 16, 12, 16, 17, 72], ["+", 0, 7, 8, 7, 15, 16, 12, 16, 12, 13]]
1
336
2
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) typedef pair<int, int> pii; int main() { int ans[100]; vector<pii> seats; // group_num count seats.push_back(pii(-1, 16)); priority_queue<pii, vector<pii>, greater<pii>> pq; // taisyutu:time, group_num queue<int> que; // mati:group_num int cnt = 0, t = 0; while (cnt < 100) { while (!pq.empty()) { pii now = pq.top(); if (now.first != t) break; pq.pop(); REP(i, seats.size()) if (seats[i].first == now.second) seats[i].first = -1; } REP(i, seats.size() - 1) { if (seats[i].first == seats[i + 1].first) { seats[i].second += seats[i + 1].second; seats.erase(seats.begin() + i + 1); i--; } } if (t % 5 == 0 && t / 5 < 100) que.push(t / 5); while (!que.empty()) { int now = que.front(); int count = now % 5 == 1 ? 5 : 2; bool flag = true; REP(i, seats.size()) { if (seats[i].first == -1 && seats[i].second >= count) { if (seats[i].second - count > 0) seats.insert(seats.begin() + i + 1, pii(-1, seats[i].second - count)); seats[i] = pii(now, count); pq.push(pii(t + 17 * (now % 2) + 3 * (now % 3) + 19, now)); ans[now] = t - now * 5; cnt++; que.pop(); flag = false; break; } } if (flag) break; } t++; } int n; while (cin >> n) cout << ans[n] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) typedef pair<int, int> pii; int main() { int ans[100]; vector<pii> seats; // group_num count seats.push_back(pii(-1, 17)); priority_queue<pii, vector<pii>, greater<pii>> pq; // taisyutu:time, group_num queue<int> que; // mati:group_num int cnt = 0, t = 0; while (cnt < 100) { while (!pq.empty()) { pii now = pq.top(); if (now.first != t) break; pq.pop(); REP(i, seats.size()) if (seats[i].first == now.second) seats[i].first = -1; } REP(i, seats.size() - 1) { if (seats[i].first == seats[i + 1].first) { seats[i].second += seats[i + 1].second; seats.erase(seats.begin() + i + 1); i--; } } if (t % 5 == 0 && t / 5 < 100) que.push(t / 5); while (!que.empty()) { int now = que.front(); int count = now % 5 == 1 ? 5 : 2; bool flag = true; REP(i, seats.size()) { if (seats[i].first == -1 && seats[i].second >= count) { if (seats[i].second - count > 0) seats.insert(seats.begin() + i + 1, pii(-1, seats[i].second - count)); seats[i] = pii(now, count); pq.push(pii(t + 17 * (now % 2) + 3 * (now % 3) + 19, now)); ans[now] = t - now * 5; cnt++; que.pop(); flag = false; break; } } if (flag) break; } t++; } int n; while (cin >> n) cout << ans[n] << endl; return 0; }
[["-", 0, 2, 3, 4, 0, 2, 3, 4, 0, 13], ["+", 0, 2, 3, 4, 0, 2, 3, 4, 0, 13]]
1
479
2
#include "bits/stdc++.h" #include <unordered_map> #include <unordered_set> #pragma warning(disable : 4996) using namespace std; using ld = long double; const ld eps = 1e-9; //// < "d:\d_download\visual studio ///2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual ///studio 2015\projects\programing_contest_c++\debug\b.txt" struct group { int id; int num; int time; }; int cansit(const vector<int> &seats, int num) { for (int i = 0; i < 17 - num; ++i) { bool ok = true; for (int j = i; j < i + num; ++j) { if (seats[j] != -1) { ok = false; } } if (ok) return i; } return -1; } void dosit(vector<int> &seats, int num, int place, int leavetime) { for (int i = place; i < place + num; ++i) { seats[i] = leavetime; } } int main() { int N; while (cin >> N) { queue<group> waiting; vector<int> seats(17, -1); vector<int> anss(100); for (int t = 0; (t <= 1000 || !waiting.empty()); ++t) { for (int i = 0; i < 17; ++i) { if (t == seats[i]) seats[i] = -1; } if (!(t % 5)) { const int id = t / 5; if (id < 100) { const int num = id % 5 == 1 ? 5 : 2; const int time = 17 * (id % 2) + 3 * (id % 3) + 19; waiting.push(group{id, num, time}); } } while (!waiting.empty()) { group atop(waiting.front()); int place = cansit(seats, atop.num); if (place != -1) { dosit(seats, atop.num, place, atop.time + t); anss[atop.id] = t - atop.id * 5; waiting.pop(); } else { break; } } } cout << anss[N] << endl; } return 0; }
#include "bits/stdc++.h" #include <unordered_map> #include <unordered_set> #pragma warning(disable : 4996) using namespace std; using ld = long double; const ld eps = 1e-9; //// < "d:\d_download\visual studio ///2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual ///studio 2015\projects\programing_contest_c++\debug\b.txt" struct group { int id; int num; int time; }; int cansit(const vector<int> &seats, int num) { for (int i = 0; i <= 17 - num; ++i) { bool ok = true; for (int j = i; j < i + num; ++j) { if (seats[j] != -1) { ok = false; } } if (ok) return i; } return -1; } void dosit(vector<int> &seats, int num, int place, int leavetime) { for (int i = place; i < place + num; ++i) { seats[i] = leavetime; } } int main() { int N; while (cin >> N) { queue<group> waiting; vector<int> seats(17, -1); vector<int> anss(100); for (int t = 0; (t <= 1000 || !waiting.empty()); ++t) { for (int i = 0; i < 17; ++i) { if (t == seats[i]) seats[i] = -1; } if (!(t % 5)) { const int id = t / 5; if (id < 100) { const int num = id % 5 == 1 ? 5 : 2; const int time = 17 * (id % 2) + 3 * (id % 3) + 19; waiting.push(group{id, num, time}); } } while (!waiting.empty()) { group atop(waiting.front()); int place = cansit(seats, atop.num); if (place != -1) { dosit(seats, atop.num, place, atop.time + t); anss[atop.id] = t - atop.id * 5; waiting.pop(); } else { break; } } } cout << anss[N] << endl; } return 0; }
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19]]
1
444
2
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define f(a) (a % 5 == 1 ? 5 : 2) using namespace std; typedef pair<int, int> P; //?????????????????????,?????????????????? int c[17]; int cnt[100]; int main() { memset(c, -1, sizeof(c)); priority_queue<P, vector<P>, greater<>> p; queue<int> que; int time = 0; while (1) { if (que.empty() && (time / 5 + 1) * 5 >= 100) break; if (time % 5 == 0 && time / 5 < 100) que.push(time / 5); while (!p.empty() && p.top().first <= time) { replace(c, c + 17, p.top().second, -1); p.pop(); } bool flag = true; while (flag && !que.empty()) { int id = que.front(); flag = false; rep(i, 17 - f(id)) { bool ok = true; rep(j, f(id)) { if (~c[i + j]) ok = false; } if (ok) { rep(j, f(id)) c[i + j] = id; que.pop(); cnt[id] = time - 5 * id; p.push(P(time + 17 * (id % 2) + 3 * (id % 3) + 19, id)); flag = true; break; } } } int Min = INT_MAX; if (!p.empty()) Min = p.top().first; Min = min(Min, (time / 5 + 1) * 5); time = Min; } int n; while (~scanf("%d", &n)) printf("%d\n", cnt[n]); }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define f(a) (a % 5 == 1 ? 5 : 2) using namespace std; typedef pair<int, int> P; int c[17]; int cnt[100]; int main() { memset(c, -1, sizeof(c)); priority_queue<P, vector<P>, greater<>> p; queue<int> que; int time = 0; while (1) { if (que.empty() && time / 5 + 1 >= 100) break; if (time % 5 == 0 && time / 5 < 100) que.push(time / 5); while (!p.empty() && p.top().first <= time) { replace(c, c + 17, p.top().second, -1); p.pop(); } bool flag = true; while (flag && !que.empty()) { int id = que.front(); flag = false; rep(i, 18 - f(id)) { bool ok = true; rep(j, f(id)) { if (~c[i + j]) ok = false; } if (ok) { rep(j, f(id)) c[i + j] = id; que.pop(); cnt[id] = time - 5 * id; p.push(P(time + 17 * (id % 2) + 3 * (id % 3) + 19, id)); flag = true; break; } } } int Min = INT_MAX; if (!p.empty()) Min = p.top().first; Min = min(Min, (time / 5 + 1) * 5); time = Min; } int n; while (~scanf("%d", &n)) printf("%d\n", cnt[n]); }
[["-", 51, 16, 12, 16, 31, 16, 31, 23, 0, 24], ["-", 51, 16, 12, 16, 31, 16, 31, 23, 0, 25], ["-", 15, 339, 51, 16, 12, 16, 31, 16, 17, 48], ["-", 15, 339, 51, 16, 12, 16, 31, 16, 12, 13], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 31, 13], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 31, 13]]
1
409
6
#include <iostream> using namespace std; #define SHEETS 17 #define GROUPS 130 int main() { int ans[GROUPS] = { 0, }; int now; int sheets[SHEETS]; int peoples[GROUPS] = { 0, }; int arrive[GROUPS] = { 0, }; int eating[GROUPS] = { 0, }; for (int i = 0; i < SHEETS; ++i) { sheets[i] = -1; } for (int i = 0; i < GROUPS; ++i) { arrive[i] = i * 5; peoples[i] = i % 5 == 1 ? 5 : 2; eating[i] = 17 * (i % 2) + 3 * (i % 3) + 19; } now = 0; for (int t = 0; t < 800; ++t) { for (int i = 0; i < SHEETS; ++i) { if (sheets[i] >= 0) { --eating[sheets[i]]; if (eating[sheets[i]] == 0) { for (; sheets[i] == sheets[i + 1] && i < SHEETS - 1; ++i) sheets[i] = -1; sheets[i] = -1; } else { for (; sheets[i] == sheets[i + 1] && i < SHEETS - 1; ++i) 0; } } } while (true) { bool bCont = false; for (int i = 0; i < SHEETS; ++i) { if (sheets[i] == -1) { int cont = 0; for (int j = i; j < SHEETS; ++j) { if (sheets[j] == -1) cont++; else break; } if (now < GROUPS && cont >= peoples[now] && t >= arrive[now]) { for (int j = i; j < i + peoples[now]; ++j) sheets[j] = now; /* cout << "NOW: "<<now; cout << " ANS: " << t << "-" << arrive[now] << "=" << ans[now] << '\n'; cout << "t=" << t <<":\t"; for(int i = 0; i < SHEETS; ++i){ cout << sheets[i] << ' '; } cout << endl; */ ans[now] = t - arrive[now]; //<0?0:waiting[now]; ++now; bCont = true; } } } if (!bCont) break; } } /* for(int i = 0; i < GROUPS;++i){ cout << ans[i] << ' '; } */ while (true) { int n; cin >> n; if (cin.eof()) break; cout << ans[n] << endl; } return 0; }
#include <iostream> using namespace std; #define SHEETS 17 #define GROUPS 130 int main() { int ans[GROUPS] = { 0, }; int now; int sheets[SHEETS]; int peoples[GROUPS] = { 0, }; int arrive[GROUPS] = { 0, }; int eating[GROUPS] = { 0, }; for (int i = 0; i < SHEETS; ++i) { sheets[i] = -1; } for (int i = 0; i < GROUPS; ++i) { arrive[i] = i * 5; peoples[i] = i % 5 == 1 ? 5 : 2; eating[i] = 17 * (i % 2) + 3 * (i % 3) + 19; } now = 0; for (int t = 0; t < 800; ++t) { for (int i = 0; i < SHEETS; ++i) { if (sheets[i] >= 0) { --eating[sheets[i]]; if (eating[sheets[i]] == 0) { for (; sheets[i] == sheets[i + 1] && i < SHEETS - 1; ++i) sheets[i] = -1; sheets[i] = -1; /* cout << "t=" << t <<":\t"; for(int i = 0; i < SHEETS; ++i){ cout << sheets[i] << ' '; } cout << endl; */ } else { for (; sheets[i] == sheets[i + 1] && i < SHEETS - 1; ++i) 0; } } } while (true) { bool bCont = false; for (int i = 0; i < SHEETS; ++i) { if (sheets[i] == -1) { int cont = 0; for (int j = i; j < SHEETS; ++j) { if (sheets[j] == -1) cont++; else break; } if (now < GROUPS && cont >= peoples[now] && t >= arrive[now]) { for (int j = i; j < i + peoples[now]; ++j) sheets[j] = now; /* cout << "t=" << t <<":\t"; for(int k = 0; k < SHEETS; ++k){ cout << sheets[k] << ' '; } cout << endl; */ ans[now] = t - arrive[now]; //<0?0:waiting[now]; ++now; bCont = true; break; } } } if (!bCont) break; } } /* for(int i = 0; i < GROUPS;++i){ cout << ans[i] << ' '; } */ while (true) { int n; cin >> n; if (cin.eof()) break; cout << ans[n] << endl; } return 0; }
[["+", 64, 9, 0, 57, 64, 9, 0, 93, 0, 94], ["+", 64, 9, 0, 57, 64, 9, 0, 93, 0, 35]]
1
480
2
#include <iostream> using namespace std; main() { int data[100][2], ans[101]; int seki[17], q = 0; for (int i = 0; i < 100; i++) { if (i % 5 == 1) { data[i][0] = 5; } else { data[i][0] = 2; } data[i][1] = 17 * (i % 2) + 3 * (i % 3) + 19; } for (int i = 0; i < 17; i++) { seki[i] = 0; } for (int i = 0; i < 50; i++) { // printf("!%d! ", i); for (int j = 0; j < 17; j++) { // printf("%2d ", seki[j]); } // printf("\n"); for (int j = 0; j < 17; j++) { if (seki[j] > 0) { seki[j]--; } } while (q <= i / 5) { int tmp = q; if (data[q][0] == 2) { for (int j = 0; j < 16; j++) { if (seki[j] == 0 && seki[j + 1] == 0) { seki[j] = seki[j + 1] = data[q][1]; ans[q] = i - q * 5; q++; break; } } } else { for (int j = 0; j < 13; j++) { if (seki[j] == 0 && seki[j + 1] == 0 && seki[j + 2] == 0 && seki[j + 3] == 0 && seki[j + 4] == 0) { seki[j] = seki[j + 1] = seki[j + 2] = seki[j + 3] = seki[j + 4] = data[q][1]; ans[q] = i - q * 5; q++; break; } } } if (tmp == q) break; } } int n; while (cin >> n) { cout << ans[n] << endl; } return 0; }
#include <iostream> using namespace std; main() { int data[100][2], ans[101]; int seki[17], q = 0; for (int i = 0; i < 100; i++) { if (i % 5 == 1) { data[i][0] = 5; } else { data[i][0] = 2; } data[i][1] = 17 * (i % 2) + 3 * (i % 3) + 19; } for (int i = 0; i < 17; i++) { seki[i] = 0; } for (int i = 0; i < 1000; i++) { // printf("!%d! ", i); for (int j = 0; j < 17; j++) { // printf("%2d ", seki[j]); } // printf("\n"); for (int j = 0; j < 17; j++) { if (seki[j] > 0) { seki[j]--; } } while (q <= i / 5) { int tmp = q; if (data[q][0] == 2) { for (int j = 0; j < 16; j++) { if (seki[j] == 0 && seki[j + 1] == 0) { seki[j] = seki[j + 1] = data[q][1]; ans[q] = i - q * 5; q++; break; } } } else { for (int j = 0; j < 13; j++) { if (seki[j] == 0 && seki[j + 1] == 0 && seki[j + 2] == 0 && seki[j + 3] == 0 && seki[j + 4] == 0) { seki[j] = seki[j + 1] = seki[j + 2] = seki[j + 3] = seki[j + 4] = data[q][1]; ans[q] = i - q * 5; q++; break; } } } if (tmp == q) break; } } int n; while (cin >> n) { cout << ans[n] << endl; } return 0; }
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13]]
1
456
2
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <utility> #include <vector> using namespace std; typedef long long Int; typedef vector<int> vint; typedef pair<int, int> pint; #define mp make_pair template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; } template <class T> void chmin(T &t, T f) { if (t > f) t = f; } template <class T> void chmax(T &t, T f) { if (t < f) t = f; } int in() { int x; scanf("%d", &x); return x; } int seat[17]; int res[200]; int main() { int i; int j; int k = -1; for (i = 0; i < 600; i++) { // cout<<i<<endl; for (j = 0; j < 17; j++) { if (seat[j]) seat[j]--; // cout<<" "<<j<<" "<<seat[j]<<endl; } if (k == -1) { if (i % 5 == 0) { k = i / 5; } } while (1) { int l; if (k == -1) break; if (k % 5 == 1) { for (l = 0; l < 17 - 5; l++) { if (seat[l] + seat[l + 1] + seat[l + 2] + seat[l + 3] + seat[l + 4] == 0) { seat[l] = seat[l + 1] = seat[l + 2] = seat[l + 3] = seat[l + 4] = 17 * (k % 2) + 3 * (k % 3) + 19; res[k] = i - k * 5; k++; if (k > i / 5) k = -1; goto a; } } } else { for (l = 0; l < 17 - 2; l++) { if (seat[l] + seat[l + 1] == 0) { seat[l] = seat[l + 1] = 17 * (k % 2) + 3 * (k % 3) + 19; res[k] = i - k * 5; k++; if (k > i / 5) k = -1; goto a; } } } break; a:; } } int n; while (cin >> n) { cout << res[n] << endl; } return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <utility> #include <vector> using namespace std; typedef long long Int; typedef vector<int> vint; typedef pair<int, int> pint; #define mp make_pair template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; } template <class T> void chmin(T &t, T f) { if (t > f) t = f; } template <class T> void chmax(T &t, T f) { if (t < f) t = f; } int in() { int x; scanf("%d", &x); return x; } int seat[17]; int res[200]; int main() { int i; int j; int k = -1; for (i = 0; i < 600; i++) { // cout<<i<<endl; for (j = 0; j < 17; j++) { if (seat[j]) seat[j]--; // cout<<" "<<j<<" "<<seat[j]<<endl; } if (k == -1) { if (i % 5 == 0) { k = i / 5; } } while (1) { int l; if (k == -1) break; if (k % 5 == 1) { for (l = 0; l <= 17 - 5; l++) { if (seat[l] + seat[l + 1] + seat[l + 2] + seat[l + 3] + seat[l + 4] == 0) { seat[l] = seat[l + 1] = seat[l + 2] = seat[l + 3] = seat[l + 4] = 17 * (k % 2) + 3 * (k % 3) + 19; res[k] = i - k * 5; k++; if (k > i / 5) k = -1; goto a; } } } else { for (l = 0; l <= 17 - 2; l++) { if (seat[l] + seat[l + 1] == 0) { seat[l] = seat[l + 1] = 17 * (k % 2) + 3 * (k % 3) + 19; res[k] = i - k * 5; k++; if (k > i / 5) k = -1; goto a; } } } break; a:; } // cout<<i<<endl; // for(j=0;j<17;j++){ // cout<<" "<<j<<" "<<seat[j]<<endl; //} // cout<<" "<<k<<endl; } int n; // for(n=0;n<200;n++){ // cout<<n<<" "<<res[n]<<endl; //} while (cin >> n) { cout << res[n] << endl; } return 0; } // WA
[["-", 0, 57, 64, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 57, 64, 9, 0, 7, 15, 16, 17, 19], ["-", 75, 76, 0, 9, 0, 7, 15, 16, 17, 18], ["+", 75, 76, 0, 9, 0, 7, 15, 16, 17, 19]]
1
567
4
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <fstream> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; const double EPS = 1e-9; typedef vector<int> vint; typedef pair<int, int> pint; #define rep(i, n) REP(i, 0, n) #define ALL(v) v.begin(), v.end() #define MSG(a) cout << #a << " " << a << endl; #define REP(i, x, n) for (int i = x; i < n; i++) template <class T> T RoundOff(T a) { return int(a + .5 - (a < 0)); } template <class T, class C> void chmax(T &a, C b) { if (a < b) a = b; } template <class T, class C> void chmin(T &a, C b) { if (b < a) a = b; } template <class T, class C> pair<T, C> mp(T a, C b) { return make_pair(a, b); } int Brank(vint v, int num) { rep(i, v.size() - num + 1) { rep(j, num) { if (v[i + j] != -1) break; else if (j + 1 == num) return i; } } return -1; } int main() { for (int n; cin >> n;) { queue<int> que; // id vint store(16, -1); // time int nxt = 0, start; for (int time = 0;; time++) { // ใƒ„่กŒใƒ„็™‚ใ‚ขใƒ„ใฅๅฏๅ˜‰ใคใƒฒใƒ„ใฅใ‚ฅ if (time % 5 == 0) { if (nxt == n) start = time; que.push(nxt++); } // ใƒ„ๅบ—ใƒ„ใคใ‚ฅใƒ„ใฅใ‚กใƒ„ๅ‡บใƒ„ใคใ‚ญ rep(i, 16) store[i] = (store[i] == time ? -1 : store[i]); // ใƒ„ๅบ—ใƒ„ใฅๅฏ็ฆฟใ‚ทใƒ„ใฅใ‚งใƒ„ใฅใ‚ฅ while (!que.empty()) { int id = que.front(); int num = (id % 5 == 1 ? 5 : 2); int index = Brank(store, num); if (index != -1) { if (id == n) { cout << time - start << endl; goto ng; } int span = 17 * (id % 2) + 3 * (id % 3) + 19; REP(i, index, index + num) { store[i] = time + span; } que.pop(); } else { break; } } } ng:; } }
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <fstream> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; const double EPS = 1e-9; typedef vector<int> vint; typedef pair<int, int> pint; #define rep(i, n) REP(i, 0, n) #define ALL(v) v.begin(), v.end() #define MSG(a) cout << #a << " " << a << endl; #define REP(i, x, n) for (int i = x; i < n; i++) template <class T> T RoundOff(T a) { return int(a + .5 - (a < 0)); } template <class T, class C> void chmax(T &a, C b) { if (a < b) a = b; } template <class T, class C> void chmin(T &a, C b) { if (b < a) a = b; } template <class T, class C> pair<T, C> mp(T a, C b) { return make_pair(a, b); } int Brank(vint v, int num) { rep(i, v.size() - num + 1) { rep(j, num) { if (v[i + j] != -1) break; else if (j + 1 == num) return i; } } return -1; } int main() { for (int n; cin >> n;) { queue<int> que; // id vint store(17, -1); // time int nxt = 0, start; for (int time = 0;; time++) { // ใƒ„่กŒใƒ„็™‚ใ‚ขใƒ„ใฅๅฏๅ˜‰ใคใƒฒใƒ„ใฅใ‚ฅ if (time % 5 == 0) { if (nxt == n) start = time; que.push(nxt++); } // ใƒ„ๅบ—ใƒ„ใคใ‚ฅใƒ„ใฅใ‚กใƒ„ๅ‡บใƒ„ใคใ‚ญ rep(i, 17) store[i] = (store[i] == time ? -1 : store[i]); // ใƒ„ๅบ—ใƒ„ใฅๅฏ็ฆฟใ‚ทใƒ„ใฅใ‚งใƒ„ใฅใ‚ฅ while (!que.empty()) { int id = que.front(); int num = (id % 5 == 1 ? 5 : 2); int index = Brank(store, num); if (index != -1) { if (id == n) { cout << time - start << endl; goto ng; } int span = 17 * (id % 2) + 3 * (id % 3) + 19; REP(i, index, index + num) { store[i] = time + span; } que.pop(); } else { break; } } } ng:; } }
[["-", 8, 9, 0, 43, 49, 50, 51, 4, 0, 13], ["+", 8, 9, 0, 43, 49, 50, 51, 4, 0, 13], ["-", 0, 11, 31, 69, 28, 2, 3, 4, 0, 13], ["+", 0, 11, 31, 69, 28, 2, 3, 4, 0, 13]]
1
531
4
// 52 #include <algorithm> #include <iostream> #include <queue> using namespace std; int main() { int a[100]; int cr[17] = {}; queue<int> que; for (int t = 0; t < 600; t++) { if (t % 5 == 0 && t / 5 < 100) { que.push(t / 5); } for (int i = 0; i < 17; i++) { cr[i]--; } int fc = 0; for (int i = 0; i < 17; i++) { if (cr[i] <= 0) { fc++; if (!que.empty()) { int gn = que.front(); int ng = (gn % 5 == 1) ? 5 : 2; if (fc == ng) { for (int j = 0; j < ng; j++) { cr[i - j] = 17 * (gn % 2) + 3 * (gn % 3) + 19; } a[gn] = t - gn * 5; que.pop(); i = 0; fc = 0; } } } else { fc = 0; } } } for (int n; cin >> n;) { cout << a[n] << endl; } return 0; }
// 52 #include <algorithm> #include <iostream> #include <queue> using namespace std; int main() { int a[100]; int cr[17] = {}; queue<int> que; for (int t = 0; t < 600; t++) { if (t % 5 == 0 && t / 5 < 100) { que.push(t / 5); } for (int i = 0; i < 17; i++) { cr[i]--; } int fc = 0; for (int i = 0; i < 17; i++) { if (cr[i] <= 0) { fc++; if (!que.empty()) { int gn = que.front(); int ng = (gn % 5 == 1) ? 5 : 2; if (fc == ng) { for (int j = 0; j < ng; j++) { cr[i - j] = 17 * (gn % 2) + 3 * (gn % 3) + 19; } a[gn] = t - gn * 5; que.pop(); i = -1; fc = 0; } } } else { fc = 0; } } } for (int n; cin >> n;) { cout << a[n] << endl; } return 0; }
[["-", 0, 57, 64, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 13]]
1
276
2
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define ALL(v) (v).begin(), (v).end() #define REV(s) (s).rbegin(), (s).rend() #define MEMSET(v, s) memset(v, s, sizeof(v)) #define MP make_pair #define X first #define Y second using namespace std; typedef long long ll; typedef pair<int, int> P; const int N = 17; int seat[N + 1]; int ans[100]; void sim() { int t = 0; rep(i, 100) { int num = i % 5 == 1 ? 5 : 2; if (t < 5 * i) { rep(j, N) seat[j] -= min(seat[j], 5 * i - t); t = 5 * i; } bool ok = false; while (1) { int cnt = 0; rep(j, num) cnt += !!seat[j]; rep(j, N - num) { if (cnt == 0) { FOR(k, j, j + num) seat[k] = 17 * (i % 2) + 3 * (i % 3) + 19; ans[i] = t - 5 * i; ok = true; break; } if (seat[j + num]) ++cnt; if (seat[j]) --cnt; } if (ok) break; int mint = 1 << 29; rep(j, N) if (seat[j]) mint = min(mint, seat[j]); rep(j, N) if (seat[j]) seat[j] -= mint; t += mint; } // printf("\ntime:%d\nseat:", t); // rep(j, N) printf("%3d", seat[j]); } } int main() { sim(); int n; while (cin >> n) cout << ans[n] << endl; return 0; }
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define ALL(v) (v).begin(), (v).end() #define REV(s) (s).rbegin(), (s).rend() #define MEMSET(v, s) memset(v, s, sizeof(v)) #define MP make_pair #define X first #define Y second using namespace std; typedef long long ll; typedef pair<int, int> P; const int N = 17; int seat[N + 1]; int ans[100]; void sim() { int t = 0; rep(i, 100) { int num = i % 5 == 1 ? 5 : 2; if (t < 5 * i) { rep(j, N) seat[j] -= min(seat[j], 5 * i - t); t = 5 * i; } bool ok = false; while (1) { int cnt = 0; rep(j, num) cnt += !!seat[j]; rep(j, N + 1 - num) { if (cnt == 0) { FOR(k, j, j + num) seat[k] = 17 * (i % 2) + 3 * (i % 3) + 19; ans[i] = t - 5 * i; ok = true; break; } if (seat[j + num]) ++cnt; if (seat[j]) --cnt; } if (ok) break; int mint = 1 << 29; rep(j, N) if (seat[j]) mint = min(mint, seat[j]); rep(j, N) if (seat[j]) seat[j] -= mint; t += mint; } // printf("\ntime:%d\nseat:", t); // rep(j, N) printf("%3d", seat[j]); } } int main() { sim(); int n; while (cin >> n) cout << ans[n] << endl; return 0; }
[["+", 0, 2, 3, 4, 0, 16, 31, 16, 17, 72], ["+", 0, 2, 3, 4, 0, 16, 31, 16, 12, 13]]
1
408
2
import java.util.Scanner; public class Main { /** * @param args */ public static void main(String[] args) { Scanner cin = new Scanner(System.in); while (cin.hasNext()) { int n = cin.nextInt(); n = n % 39; if (n == 0) { System.out.println("3c" + 39); } else { if (n >= 10) System.out.println("3c" + n); else { System.out.println("3c0" + n); } } } } }
import java.util.Scanner; public class Main { /** * @param args */ public static void main(String[] args) { Scanner cin = new Scanner(System.in); while (cin.hasNext()) { int n = cin.nextInt(); n = n % 39; if (n == 0) { System.out.println("3C" + 39); } else { if (n >= 10) System.out.println("3C" + n); else { System.out.println("3C0" + n); } } } } }
[["-", 0, 492, 3, 4, 0, 16, 31, 5, 0, 491], ["+", 0, 492, 3, 4, 0, 16, 31, 5, 0, 491]]
3
120
6
#include <stdio.h> int main(void) { int n; int id; while (scanf("%d", &n) != EOF) { if (n % 39 == 0) { id = 39; } else { id = n % 39; } printf("3C%d\n", id); } return (0); }
#include <stdio.h> int main(void) { int n; int id; while (scanf("%d", &n) != EOF) { if (n % 39 == 0) { id = 39; } else { id = n % 39; } printf("3C%02d\n", id); } return (0); }
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
69
2
a = 39; main(c) { for (; ~scanf("%d", &c) * c; printf("3C%02d\n", c % a ? c % a : a)) ; }
a = 39; main(c) { for (; ~scanf("%d", &c) * a; printf("3C%02d\n", c % a ? c % a : a)) ; }
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 22]]
0
45
2
#include <stdio.h> int main(void) { int n; while (scanf(" %d", &n) != EOF) { printf("3C"); if (n % 39 == 0) printf("39\n"); else if (n % 39 < 10) printf("0%d\n", n % 395); else printf("%d\n", n % 39); } return 0; }
#include <stdio.h> int main(void) { int n; while (scanf(" %d", &n) != EOF) { printf("3C"); if (n % 39 == 0) printf("39\n"); else if (n % 39 < 10) printf("0%d\n", n % 39); else printf("%d\n", n % 39); } return 0; }
[["-", 64, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["+", 64, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
0
88
2
#include <stdio.h> int main() { int n; int r; while (scanf("%d", &n) != EOF) { r = n % 39; if (r == 0) r = 39; printf("3c%02d\n", r); } return 0; }
#include <stdio.h> int main() { int n; int r; while (scanf("%d", &n) != EOF) { r = n % 39; if (r == 0) r = 39; printf("3C%02d\n", r); } return 0; }
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
59
2
#include <stdio.h> int main(void) { int candy; int amari; while (scanf("%d", &candy) != EOF) { amari = candy % 39; if (amari == 0) { printf("3C39"); } else if ((amari >= 1) && (amari <= 9)) { printf("3C0%d", amari); } else { printf("3C%d", amari); } } return (0); }
#include <stdio.h> int main(void) { int candy; int amari; while (scanf("%d", &candy) != EOF) { amari = candy % 39; if (amari == 0) { printf("3C39\n"); } else if ((amari >= 1) && (amari <= 9)) { printf("3C0%d\n", amari); } else { printf("3C%d\n", amari); } } return (0); }
[["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
0
95
3
#include <stdio.h> int main(void) { int n; int ans; while (scanf("%d", &n) != EOF) { ans = n % 39; if (ans == 0) { ans = 39; } printf("3C"); if (ans <= 9 && ans <= 1) { printf("0"); } printf("%d\n", ans); } return (0); }
#include <stdio.h> int main(void) { int n; int ans; while (scanf(" %d", &n) != EOF) { ans = n % 39; if (ans == 0) { ans = 39; } printf("3C"); if (ans <= 9 && ans >= 1) { printf("0"); } printf("%d\n", ans); } return (0); }
[["-", 0, 16, 31, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 16, 31, 2, 3, 4, 0, 5, 0, 6], ["-", 0, 57, 15, 23, 0, 16, 12, 16, 17, 19], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 17, 20]]
0
90
4
#include <stdio.h> int main(void) { int n, a; while (scanf("%d", &n) != EOF) { a = n % 39; if (a == 0) a = 39; printf("3C%d\n", a); } return 0; }
#include <stdio.h> int main(void) { int n, a; while (scanf("%d", &n) != EOF) { a = n % 39; if (a == 0) a = 39; printf("3C%02d\n", a); } return 0; }
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
59
2
#include <stdio.h> int main() { int a, b, c; while (scanf("%d", &a) != EOF) { a = a % 39; if (a == 0) { printf("3C39\n"); } else { printf("3C%d\n", a); } } return 0; }
#include <stdio.h> int main() { int a; while (scanf("%d", &a) != EOF) { a = a % 39; if (a == 0) { printf("3C39\n"); } else { printf("3C%02d\n", a); } } return 0; }
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 0, 21], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
69
6
#include <iostream> using namespace std; int n; int main() { while (cin >> n) { int p = n % 39; if (p == 0) p = 39; cout << "C3"; if (p < 10) cout << "0"; cout << p << endl; } }
#include <iostream> using namespace std; int n; int main() { while (cin >> n) { int p = n % 39; if (p == 0) p = 39; cout << "3C"; if (p < 10) cout << "0"; cout << p << endl; } }
[["-", 8, 9, 0, 1, 0, 16, 12, 5, 0, 6], ["+", 8, 9, 0, 1, 0, 16, 12, 5, 0, 6]]
1
64
2
#include <bits/stdc++.h> // only for GCC using namespace std; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } template <class T> inline T sqr(T x) { return x * x; } typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; typedef unsigned long long ULL; #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort((c).begin(), (c).end()) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) const double EPS = 1e-10; const double PI = acos(-1.0); #define CLR(a) memset((a), 0, sizeof(a)) #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; int dx[8] = {-1, 0, 1, 0, -1, -1, 1, 1}; int dy[8] = {0, -1, 0, 1, -1, 1, -1, 1}; int main() { int n; while (cin >> n) { int ans = n % 39; if (ans == 0) ans = 39; string str = "3C"; str += (ans / 10) + '0'; str += (ans % 10) + '0'; cout << "3C" << str << endl; } }
#include <bits/stdc++.h> // only for GCC using namespace std; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } template <class T> inline T sqr(T x) { return x * x; } typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; typedef unsigned long long ULL; #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort((c).begin(), (c).end()) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) const double EPS = 1e-10; const double PI = acos(-1.0); #define CLR(a) memset((a), 0, sizeof(a)) #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; int dx[8] = {-1, 0, 1, 0, -1, -1, 1, 1}; int dy[8] = {0, -1, 0, 1, -1, 1, -1, 1}; int main() { int n; while (cin >> n) { int ans = n % 39; if (ans == 0) ans = 39; string str = "3C"; str += (ans / 10) + '0'; str += (ans % 10) + '0'; cout << str << endl; } }
[["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 62], ["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["-", 8, 9, 0, 1, 0, 16, 31, 16, 17, 151]]
1
342
4
#include <iostream> using namespace std; int main() { int n, count; while (cin >> n) { count = n % 39; if (count == 0) count = 39; cout << "3C"; (count / 10 == 0) ? cout << "0" << count : cout << count << endl; } return 0; }
#include <iostream> using namespace std; int main() { int n, count; while (cin >> n) { count = n % 39; if (count == 0) count = 39; cout << "3C"; (count / 10 == 0) ? cout << "0" << count : cout << count; cout << endl; } return 0; }
[["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35], ["+", 0, 52, 8, 9, 0, 1, 0, 16, 31, 22]]
1
72
2
#include <cstdio> #include <iostream> using namespace std; int main() { int c; while (cin >> c) { printf("3%%02d\n", ((c % 39) == 0 ? 39 : (c % 39))); } return 0; }
#include <cstdio> #include <iostream> using namespace std; int main() { int c; while (cin >> c) { printf("3C%02d\n", ((c % 39) == 0 ? 39 : (c % 39))); } return 0; }
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
54
2
#include <stdio.h> int main() { int x; while (scanf("%d", &x) != EOF) { x = x % 39; if (x == 0) x = 39; else x = x; if (x <= 9) printf("3C0%d\n", x); printf("3C%d\n", x); } return 0; }
#include <stdio.h> int main() { int x; while (scanf("%d", &x) != EOF) { x = x % 39; if (x == 0) x = 39; else x = x; if (x <= 9) printf("3C0%d\n", x); else printf("3C%d\n", x); } return 0; }
[["+", 0, 52, 8, 9, 0, 57, 75, 76, 0, 95]]
1
77
1
#include <stdio.h> int main(void) { int a; while (scanf("%d", &a) != EOF) { a = a % 39; if (a == 0) { printf("3C39\n"); } else { printf("3C%d\n", a); } } return 0; }
#include <stdio.h> int main(void) { int a; while (scanf("%d", &a) != EOF) { a = a % 39; if (a == 0) { printf("3C39\n"); } else { printf("3C%02d\n", a); } } return 0; }
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
66
2
#include <iostream> using namespace std; int main() { int n; while (cin >> n) { printf("3C%02d", n % 39 == 0 ? 39 : n % 39); } return 0; }
#include <iostream> using namespace std; int main() { int n; while (cin >> n) { printf("3C%02d\n", n % 39 == 0 ? 39 : n % 39); } return 0; }
[["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
1
45
1
#include <iostream> using namespace std; int main() { while (1) { int a; cin >> a; if (cin.fail()) break; cout << "3C"; if (a % 39 == 0) { cout << 39; continue; } cout.width(2); cout.fill('0'); cout << a % 39 << endl; } }
#include <iostream> using namespace std; int main() { while (1) { int a; cin >> a; if (cin.fail()) break; cout << "3C"; if (a % 39 == 0) { cout << 39 << endl; continue; } cout.width(2); cout.fill('0'); cout << a % 39 << endl; } }
[["+", 0, 57, 64, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 57, 64, 9, 0, 1, 0, 16, 12, 22]]
1
81
2
#include <stdio.h> int main(void) { int a; while (scanf("%d", &a) != EOF) { if (a % 39 == 0) printf("3c39\n"); else printf("3C%02d\n", a % 39); } return 0; }
#include <stdio.h> int main(void) { int a; while (scanf("%d", &a) != EOF) { if (a % 39 == 0) printf("3C39\n"); else printf("3C%02d\n", a % 39); } return 0; }
[["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
60
2
#include <cstdio> #include <iostream> #include <math.h> #include <stdio.h> #include <string> using namespace std; int main() { int a, o; while (cin >> a) { o = a % 39; if (o == 0) { cout << "3c39" << endl; } else { cout << "3c"; printf("%02d", o); cout << endl; } } return 0; }
#include <cstdio> #include <iostream> #include <math.h> #include <stdio.h> #include <string> using namespace std; int main() { int a, o; while (cin >> a) { o = a % 39; if (o == 0) { cout << "3C39" << endl; } else { cout << "3C"; printf("%02d", o); cout << endl; } } return 0; }
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["-", 0, 9, 0, 1, 0, 16, 12, 5, 0, 6], ["+", 0, 9, 0, 1, 0, 16, 12, 5, 0, 6]]
1
80
4
#include <iostream> using namespace std; int main() { int n; cin >> n; if (n % 39 == 0) n = 39; else n %= 39; if (n < 10) cout << "3C0" << n << "\n"; else cout << "3C" << n << "\n"; return 0; }
#include <iostream> using namespace std; int main() { int n; while (cin >> n) { if (n % 39 == 0) n = 39; else n %= 39; if (n < 10) cout << "3C0" << n << "\n"; else cout << "3C" << n << "\n"; } return 0; }
[["+", 0, 30, 0, 14, 8, 9, 0, 52, 0, 89], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 24], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
1
70
6
#include <iostream> using namespace std; int main(void) { int n; while (cin >> n) { cout << "3C"; printf("%2d\n", n % 39 ? n % 39 : 39); } return 0; }
#include <iostream> using namespace std; int main(void) { int n; while (cin >> n) { cout << "3C"; printf("%.2d\n", n % 39 ? n % 39 : 39); } return 0; }
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
51
2
#include <iostream> using namespace std; int main(void) { int n, a; cin >> n; a = n % 39; if (a > 0 && a < 10) cout << "3C0" << a << endl; else if (a >= 10) cout << "3C" << a << endl; else if (a == 0) cout << "3C39" << endl; return 0; }
#include <iostream> using namespace std; int main(void) { int n, a; while (cin >> n) { a = n % 39; if (a > 0 && a < 10) cout << "3C0" << a << endl; else if (a >= 10) cout << "3C" << a << endl; else if (a == 0) cout << "3C39" << endl; } return 0; }
[["+", 0, 30, 0, 14, 8, 9, 0, 52, 0, 89], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 24], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
1
83
6
while gets tmp = ($_.to_i) % 39 puts "3c%02d" % (tmp == 0 ? 39 : tmp) end
while gets tmp = ($_.to_i) % 39 puts "3C%02d" % (tmp == 0 ? 39 : tmp) end
[["-", 0, 652, 3, 4, 0, 738, 31, 557, 0, 6], ["+", 0, 652, 3, 4, 0, 738, 31, 557, 0, 6]]
4
26
2
while True: try: a = int(input()) except: break tmp = a - (a // 39) * 39 print("3C{:02d}".format(39 if tmp == 39 else tmp))
while True: try: a = int(input()) except: break tmp = a - (a // 39) * 39 print("3C{:02d}".format(tmp if tmp % 39 else 39))
[["-", 3, 4, 0, 652, 3, 4, 0, 41, 0, 612], ["+", 3, 4, 0, 652, 3, 4, 0, 41, 0, 22], ["-", 0, 652, 3, 4, 0, 41, 0, 666, 667, 60], ["+", 0, 652, 3, 4, 0, 41, 0, 657, 17, 109], ["-", 3, 4, 0, 652, 3, 4, 0, 41, 0, 22], ["+", 3, 4, 0, 652, 3, 4, 0, 41, 0, 612]]
5
44
6
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[][] list = new int[2][4]; while (sc.hasNext()) { String[] eye = sc.nextLine().split(" "); for (int i = 0; i < 2; i++) { if (Double.parseDouble(eye[i]) >= 1.1) list[i][0]++; else if (Double.parseDouble(eye[i]) >= 0.6 && Double.parseDouble(eye[i]) < 1.1) list[i][1]++; else if (Double.parseDouble(eye[i]) >= 0.2 && Double.parseDouble(eye[i]) < 0.6) list[i][2]++; else if (Double.parseDouble(eye[i]) < 0.2) list[i][3]++; } } for (int i = 0; i < 4; i++) System.out.println(list[i][0] + " " + list[i][1]); sc.close(); } }
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[][] list = new int[2][4]; while (sc.hasNext()) { String[] eye = sc.nextLine().split(" "); for (int i = 0; i < 2; i++) { if (Double.parseDouble(eye[i]) >= 1.1) list[i][0]++; else if (Double.parseDouble(eye[i]) >= 0.6 && Double.parseDouble(eye[i]) < 1.1) list[i][1]++; else if (Double.parseDouble(eye[i]) >= 0.2 && Double.parseDouble(eye[i]) < 0.6) list[i][2]++; else if (Double.parseDouble(eye[i]) < 0.2) list[i][3]++; } } for (int i = 0; i < 4; i++) System.out.println(list[0][i] + " " + list[1][i]); sc.close(); } }
[["-", 0, 16, 31, 16, 31, 504, 516, 504, 71, 22], ["+", 0, 16, 31, 16, 31, 504, 516, 504, 71, 499], ["-", 3, 4, 0, 16, 31, 16, 31, 504, 71, 499], ["+", 3, 4, 0, 16, 31, 16, 31, 504, 71, 22], ["-", 3, 4, 0, 16, 12, 504, 516, 504, 71, 22], ["+", 3, 4, 0, 16, 12, 504, 516, 504, 71, 499], ["-", 0, 492, 3, 4, 0, 16, 12, 504, 71, 499], ["+", 0, 492, 3, 4, 0, 16, 12, 504, 71, 22]]
3
260
8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; public class Main { public static void main(String[] args) throws NumberFormatException, IOException { List<Integer> left = new ArrayList<Integer>(); List<Integer> right = new ArrayList<Integer>(); InputStreamReader is = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(is); for (int i = 0; i < 4; i++) { left.add(0); right.add(0); } String str; while ((str = br.readLine()) != null) { String[] sp = str.split(" "); double l = Double.parseDouble(sp[0]); double r = Double.parseDouble(sp[1]); if (1.1 <= l) { left.set(0, left.get(0) + 1); } else if (0.6 <= l && l < 1.1) { left.set(1, left.get(1) + 1); } else if (0.2 <= l && l < 0.6) { left.set(2, left.get(2) + 1); } else { left.set(3, left.get(3) + 1); } if (1.1 <= r) { right.set(0, right.get(0) + 1); } else if (0.6 <= l && l < 1.1) { right.set(1, right.get(1) + 1); } else if (0.2 <= l && l < 0.6) { right.set(2, right.get(2) + 1); } else { right.set(3, right.get(3) + 1); } } for (int i = 0; i < 4; i++) { System.out.println(left.get(i) + " " + right.get(i)); } } }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; public class Main { public static void main(String[] args) throws NumberFormatException, IOException { List<Integer> left = new ArrayList<Integer>(); List<Integer> right = new ArrayList<Integer>(); InputStreamReader is = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(is); for (int i = 0; i < 4; i++) { left.add(0); right.add(0); } String str; while ((str = br.readLine()) != null) { String[] sp = str.split(" "); double l = Double.parseDouble(sp[0]); double r = Double.parseDouble(sp[1]); if (1.1 <= l) { left.set(0, left.get(0) + 1); } else if (0.6 <= l && l < 1.1) { left.set(1, left.get(1) + 1); } else if (0.2 <= l && l < 0.6) { left.set(2, left.get(2) + 1); } else { left.set(3, left.get(3) + 1); } if (1.1 <= r) { right.set(0, right.get(0) + 1); } else if (0.6 <= r && r < 1.1) { right.set(1, right.get(1) + 1); } else if (0.2 <= r && r < 0.6) { right.set(2, right.get(2) + 1); } else { right.set(3, right.get(3) + 1); } } for (int i = 0; i < 4; i++) { System.out.println(left.get(i) + " " + right.get(i)); } } }
[["-", 75, 57, 15, 15, 0, 16, 31, 16, 12, 22], ["+", 75, 57, 15, 15, 0, 16, 31, 16, 12, 22], ["-", 75, 57, 15, 15, 0, 16, 12, 16, 31, 22], ["+", 75, 57, 15, 15, 0, 16, 12, 16, 31, 22]]
3
436
8
import java.util.*; public class Main { public int getIndex(int eye) { if (eye < 0.2) return 3; else if (eye < 0.6) return 2; else if (eye < 1.1) return 1; else return 0; } public static void main(String args[]) { int[] left = new int[4], right = new int[4]; Main m = new Main(); Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int l = sc.nextInt(); int r = sc.nextInt(); left[m.getIndex(l)]++; right[m.getIndex(r)]++; } for (int i = 0; i < 4; i++) System.out.println(left[i] + " " + right[i]); } }
import java.util.*; public class Main { public int getIndex(double eye) { if (eye < 0.2) return 3; else if (eye < 0.6) return 2; else if (eye < 1.1) return 1; else return 0; } public static void main(String args[]) { int[] left = new int[4], right = new int[4]; Main m = new Main(); Scanner sc = new Scanner(System.in); while (sc.hasNext()) { double l = sc.nextDouble(); double r = sc.nextDouble(); left[m.getIndex(l)]++; right[m.getIndex(r)]++; } for (int i = 0; i < 4; i++) System.out.println(left[i] + " " + right[i]); } }
[["-", 0, 195, 54, 495, 0, 496, 39, 506, 0, 507], ["+", 0, 195, 54, 495, 0, 496, 39, 511, 0, 512], ["-", 0, 52, 8, 196, 0, 503, 39, 506, 0, 507], ["+", 0, 52, 8, 196, 0, 503, 39, 511, 0, 512], ["-", 8, 196, 0, 503, 49, 200, 51, 492, 141, 22], ["+", 8, 196, 0, 503, 49, 200, 51, 492, 141, 22]]
3
189
10
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[][] eye = new int[4][2]; while (sc.hasNext()) { for (int i = 0; i < 2; i++) { double p = sc.nextDouble(); if (p < 0.2) eye[3][i]++; else if (p < 6.0) eye[2][i]++; else if (p < 1.1) eye[1][i]++; else eye[0][i]++; } } for (int i = 0; i < 4; i++) { System.out.println(eye[i][0] + " " + eye[i][1]); } } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[][] eye = new int[4][2]; while (sc.hasNext()) { for (int i = 0; i < 2; i++) { double p = sc.nextDouble(); if (p < 0.2) eye[3][i]++; else if (p < 0.6) eye[2][i]++; else if (p < 1.1) eye[1][i]++; else eye[0][i]++; } } for (int i = 0; i < 4; i++) { System.out.println(eye[i][0] + " " + eye[i][1]); } } }
[["-", 0, 57, 75, 57, 15, 15, 0, 16, 12, 515], ["+", 0, 57, 75, 57, 15, 15, 0, 16, 12, 515]]
3
186
2
#include <stdio.h> int main(void) { double l, r; int countla = 0; int countra = 0; int countlb = 0; int countrb = 0; int countlc = 0; int countrc = 0; int countld = 0; int countrd = 0; while (scanf("%lf %lf", &l, &r) != EOF) { if (l >= 1.1) { countla++; } else if (l < 1.1 && l >= 0.6) { countlb++; } else if (l < 0.6 && l >= 0.2) { countlc++; } else if (l < 0.2) { countld++; } if (r >= 1.1) { countra++; } else if (r < 1.1 && r >= 0.6) { countrb++; } else if (r < 0.6 && r >= 0.2) { countrc++; } else if (r < 0.2) { countrd++; } printf("%d %d\n", countla++, countra++); printf("%d %d\n", countlb++, countrb++); printf("%d %d\n", countlc++, countrc++); printf("%d %d\n", countld++, countrd++); } return 0; }
#include <stdio.h> int main(void) { double l, r; int countla = 0; int countra = 0; int countlb = 0; int countrb = 0; int countlc = 0; int countrc = 0; int countld = 0; int countrd = 0; while (scanf("%lf %lf", &l, &r) != EOF) { if (l >= 1.1) { countla++; } else if (l < 1.1 && l >= 0.6) { countlb++; } else if (l < 0.6 && l >= 0.2) { countlc++; } else if (l < 0.2) { countld++; } if (r >= 1.1) { countra++; } else if (r < 1.1 && r >= 0.6) { countrb++; } else if (r < 0.6 && r >= 0.2) { countrc++; } else if (r < 0.2) { countrd++; } } printf("%d %d\n", countla++, countra++); printf("%d %d\n", countlb++, countrb++); printf("%d %d\n", countlc++, countrc++); printf("%d %d\n", countld++, countrd++); return 0; }
[["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46], ["-", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
0
242
2
#include <stdio.h> int main(void) { double left, right; int lefta = 0, righta = 0; int leftb = 0, rightb = 0; int leftc = 0, rightc = 0; int leftd = 0, rightd = 0; while (scanf("%lf %lf", &left, &right) != EOF) { if (left >= 1.1) { lefta++; } else if (left < 1.1 && left >= 0.6) { leftb++; } else if (left < 0.6 && left >= 0.2) { leftc++; } else { leftd++; } if (right >= 1.1) { righta++; } else if (right < 1.1 && right >= 0.6) { rightb++; } else if (right < 0.6 && right >= 0.2) { rightc++; } else { rightd++; } printf("%d %d\n%d %d\n%d %d\n%d %d\n", lefta, righta, leftb, rightb, leftc, rightc, leftd, rightd); } return 0; }
#include <stdio.h> int main(void) { double left, right; int lefta = 0, righta = 0; int leftb = 0, rightb = 0; int leftc = 0, rightc = 0; int leftd = 0, rightd = 0; while (scanf("%lf %lf", &left, &right) != EOF) { if (left >= 1.1) { lefta++; } else if (left < 1.1 && left >= 0.6) { leftb++; } else if (left < 0.6 && left >= 0.2) { leftc++; } else { leftd++; } if (right >= 1.1) { righta++; } else if (right < 1.1 && right >= 0.6) { rightb++; } else if (right < 0.6 && right >= 0.2) { rightc++; } else { rightd++; } } printf("%d %d\n%d %d\n%d %d\n%d %d\n", lefta, righta, leftb, rightb, leftc, rightc, leftd, rightd); return 0; }
[["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46], ["-", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
0
200
2
l[4], r[4], i; main() { float a, b; for (; ~scanf("%f%f", &a, &b);) { l[a < 0.2 ? 3 : a < 0.6 ? 2 : a < 1.1 ? 1 : 0]++; r[b < 0.2 ? 3 : b < 0.6 ? 2 : b < 1.1 ? 1 : 0]++; } for (; i++ < 4;) { printf("%d %d\n", l[i], r[i]); } exit(0); }
l[4], r[4], i; main() { float a, b; for (; ~scanf("%f%f", &a, &b);) { l[a < 0.2 ? 3 : a < 0.6 ? 2 : a < 1.1 ? 1 : 0]++; r[b < 0.2 ? 3 : b < 0.6 ? 2 : b < 1.1 ? 1 : 0]++; } for (; i < 4; i++) { printf("%d %d\n", l[i], r[i]); } exit(0); }
[["-", 0, 9, 0, 7, 15, 16, 31, 27, 17, 29], ["+", 0, 30, 0, 9, 0, 7, 26, 27, 28, 22], ["+", 0, 30, 0, 9, 0, 7, 26, 27, 17, 29]]
0
125
3
#include <stdio.h> int main() { int s[4][2] = {0, 0, 0, 0, 0, 0, 0, 0}, j; double b[2]; while (scanf("%lf %lf", &b[0], &b[1]) != EOF) { for (j = 0; j < 2; j++) { if (b[j] >= 1.1) s[0][j]++; else if (b[j] >= 0.6) s[1][j]++; else if (b[j] >= 0.2) s[2][j]++; else s[3][j]++; } for (j = 0; j < 4; j++) printf("%d %d\n", s[j][0], s[j][1]); } return 0; }
#include <stdio.h> int main() { int s[4][2] = {0, 0, 0, 0, 0, 0, 0, 0}, j; double b[2]; while (scanf("%lf %lf", &b[0], &b[1]) != EOF) { for (j = 0; j < 2; j++) { if (b[j] >= 1.1) s[0][j]++; else if (b[j] >= 0.6) s[1][j]++; else if (b[j] >= 0.2) s[2][j]++; else s[3][j]++; } } for (j = 0; j < 4; j++) printf("%d %d\n", s[j][0], s[j][1]); return 0; }
[["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46], ["-", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
0
189
2
#include <stdio.h> int main(void) { int l[4] = {0}; int r[4] = {0}; double onel, oner; while (scanf("%lf %lf", &onel, oner) == 2) { if (onel < 0.2) l[3]++; else if (onel < 0.6) l[2]++; else if (onel < 1.1) l[1]++; else l[0]++; if (oner < 0.2) r[3]++; else if (oner < 0.6) r[2]++; else if (oner < 1.1) r[1]++; else r[0]++; } printf("%d %d\n", l[0], r[0]); printf("%d %d\n", l[1], r[1]); printf("%d %d\n", l[2], r[2]); printf("%d %d\n", l[3], r[3]); return 0; }
#include <stdio.h> int main(void) { int l[4] = {0}; int r[4] = {0}; double onel, oner; while (scanf("%lf %lf", &onel, &oner) == 2) { if (onel < 0.2) l[3]++; else if (onel < 0.6) l[2]++; else if (onel < 1.1) l[1]++; else l[0]++; if (oner < 0.2) r[3]++; else if (oner < 0.6) r[2]++; else if (oner < 1.1) r[1]++; else r[0]++; } printf("%d %d\n", l[0], r[0]); printf("%d %d\n", l[1], r[1]); printf("%d %d\n", l[2], r[2]); printf("%d %d\n", l[3], r[3]); return 0; }
[["+", 0, 16, 31, 2, 3, 4, 0, 66, 17, 67]]
0
217
1
#include <stdio.h> int main(void) { double eye[40][2]; int num[4][2] = {0}; int i, j; for (i = 0; scanf("%lf %lf", eye[i][0], eye[i][1]) != EOF; i++) for (j = 0; j < 2; j++) if (eye[i][j] >= 1.1) num[0][j]++; else if (eye[i][j] >= 0.6) num[1][j]++; else if (eye[i][j] >= 0.2) num[2][j]++; else num[3][j]++; for (i = 0; i < 4; i++) printf("%d %d\n", num[i][0], num[i][1]); return 0; }
#include <stdio.h> int main(void) { double eye[40][2]; int num[4][2] = {0}; int i, j; for (i = 0; scanf("%lf %lf", &eye[i][0], &eye[i][1]) != EOF; i++) for (j = 0; j < 2; j++) if (eye[i][j] >= 1.1) num[0][j]++; else if (eye[i][j] >= 0.6) num[1][j]++; else if (eye[i][j] >= 0.2) num[2][j]++; else num[3][j]++; for (i = 0; i < 4; i++) printf("%d %d\n", num[i][0], num[i][1]); return 0; }
[["+", 15, 16, 31, 2, 3, 4, 0, 66, 17, 67]]
0
198
2
#include <stdio.h> int main() { int x[8] = {0}, i, j; double a, b; while (scanf("%lf %lf", &a, &b) != EOF) { if (a >= 1.1) { x[0]++; } else if (0.6 <= a) { x[2]++; } else if (0.2 <= a) { x[4]++; } else if (a < 0.2) { x[6]++; } if (b >= 1.1) { x[1]++; } else if (0.6 <= b) { x[3]++; } else if (0.2 <= b) { x[5]++; } else if (b < 0.2) { x[7]++; } for (i = 0; i <= 6; i = i + 2) { printf("%d %d\n", x[i], x[i + 1]); } } return 0; }
#include <stdio.h> int main() { int x[8] = {0}, i, j; double a, b; while (scanf("%lf %lf", &a, &b) != EOF) { if (a >= 1.1) { x[0]++; } else if (0.6 <= a) { x[2]++; } else if (0.2 <= a) { x[4]++; } else if (a < 0.2) { x[6]++; } if (b >= 1.1) { x[1]++; } else if (0.6 <= b) { x[3]++; } else if (0.2 <= b) { x[5]++; } else if (b < 0.2) { x[7]++; } } for (i = 0; i <= 6; i = i + 2) { printf("%d %d\n", x[i], x[i + 1]); } return 0; }
[["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46], ["-", 0, 52, 8, 9, 0, 7, 8, 9, 0, 46]]
0
205
2
#include <stdio.h> int eyejudge(double eyesight); int main(void) { int right[4] = {0}; int left[4] = {0}; double rsig, lsig; int i, j; while (scanf("%lf %lf", &lsig, &rsig) != EOF) { if (eyejudge(lsig) == 0 || eyejudge(rsig) == 0) return (0); left[eyejudge(lsig) - 1]++; right[eyejudge(rsig) - 1]++; } for (i = 0; i < 4; i++) { for (j = 0; j < 2; j++) { printf("%d %d", left[i], right[i]); } putchar('\n'); } return (0); } int eyejudge(double eyesight) { if (eyesight >= 1.1) return (1); else if (eyesight >= 0.6 && eyesight < 1.1) return (2); else if (eyesight >= 0.2 && eyesight < 0.6) return (3); else if (eyesight < 0.2) return (4); else return (0); }
#include <stdio.h> int eyejudge(double eyesight); int main(void) { int right[4] = {0}; int left[4] = {0}; double rsig, lsig; int i, j; while (scanf("%lf %lf", &lsig, &rsig) != EOF) { if (eyejudge(lsig) == 0 || eyejudge(rsig) == 0) return (0); left[eyejudge(lsig) - 1]++; right[eyejudge(rsig) - 1]++; } for (i = 0; i < 4; i++) { for (j = 0; j < 1; j++) { printf("%d %d", left[i], right[i]); } putchar('\n'); } return (0); } int eyejudge(double eyesight) { if (eyesight >= 1.1) return (1); else if (eyesight >= 0.6 && eyesight < 1.1) return (2); else if (eyesight >= 0.2 && eyesight < 0.6) return (3); else if (eyesight < 0.2) return (4); else return (0); }
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13]]
0
236
2
#include <bits/stdc++.h> using namespace std; typedef vector<int> vi; typedef vector<vi> vii; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<vb> vbb; typedef pair<int, int> pii; typedef long long ll; typedef unsigned long long ull; #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define pb push_back #define mp make_pair #define loop(i, a, b) for (int i = (a); i < ull(b); ++i) #define rep(i, n) loop(i, 0, n) const double eps = 1e-10; const double pi = acos(-1.0); const double inf = (int)1e8; int main() { double n, m; vector<pair<int, int>> v(4); while (cin >> n >> m) { if (1.1 <= n) v[0].first++; else if (0.6 <= n && n < 1.1) v[1].first++; else if (0.2 <= n && n < 0.6) v[2].first++; else v[3].first++; if (1.1 <= m) v[0].second++; else if (1.6 <= m && m < 1.1) v[1].second++; else if (0.2 <= m && m < 0.6) v[2].second++; else v[3].second++; } rep(i, 4) { cout << v[i].first << " " << v[i].second << endl; } }
#include <bits/stdc++.h> using namespace std; typedef vector<int> vi; typedef vector<vi> vii; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<vb> vbb; typedef pair<int, int> pii; typedef long long ll; typedef unsigned long long ull; #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define pb push_back #define mp make_pair #define loop(i, a, b) for (int i = (a); i < ull(b); ++i) #define rep(i, n) loop(i, 0, n) const double eps = 1e-10; const double pi = acos(-1.0); const double inf = (int)1e8; int main() { double n, m; vector<pair<int, int>> v(4); while (cin >> n >> m) { if (1.1 <= n) v[0].first++; else if (0.6 <= n && n < 1.1) v[1].first++; else if (0.2 <= n && n < 0.6) v[2].first++; else v[3].first++; if (1.1 <= m) v[0].second++; else if (0.6 <= m && m < 1.1) v[1].second++; else if (0.2 <= m && m < 0.6) v[2].second++; else v[3].second++; } rep(i, 4) { cout << v[i].first << " " << v[i].second << endl; } }
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 31, 13], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 31, 13]]
1
309
2
#include <algorithm> #include <cmath> #include <cstdio> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; int stoi(string x) { stringstream ss; ss << x; int tmp; ss >> tmp; return tmp; } string itos(int x) { stringstream ss; ss << x; return ss.str(); } int main() { int ta[4][2] = {{0}, {0}}; double a, b; while (cin >> a >> b) { if (a >= 1.1) ta[0][0]++; else if (a >= 0.6) ta[1][0]++; else if (a >= 0.2) ta[2][0]++; else ta[3][0]++; if (b >= 1.1) ta[0][0]++; else if (b >= 0.6) ta[1][1]++; else if (b >= 0.2) ta[2][1]++; else ta[3][1]++; } for (int i = 0; i < 4; i++) cout << ta[i][0] << " " << ta[i][1] << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; int stoi(string x) { stringstream ss; ss << x; int tmp; ss >> tmp; return tmp; } string itos(int x) { stringstream ss; ss << x; return ss.str(); } int main() { int ta[4][2] = {{0}, {0}}; double a, b; while (cin >> a >> b) { if (a >= 1.1) ta[0][0]++; else if (a >= 0.6) ta[1][0]++; else if (a >= 0.2) ta[2][0]++; else ta[3][0]++; if (b >= 1.1) ta[0][1]++; else if (b >= 0.6) ta[1][1]++; else if (b >= 0.2) ta[2][1]++; else ta[3][1]++; } for (int i = 0; i < 4; i++) cout << ta[i][0] << " " << ta[i][1] << endl; return 0; }
[["-", 64, 1, 0, 27, 28, 69, 341, 342, 0, 13], ["+", 64, 1, 0, 27, 28, 69, 341, 342, 0, 13]]
1
270
2
#include <iostream> using namespace std; int l[4], r[4]; int main() { double a, b; while (cin >> a >> b) { l[a < 0.2 ? 3 : a < 0.6 ? 2 : a < 1.1 ? 1 : 0]++; r[b < 0.2 ? 3 : b < 0.6 ? 2 : b < 1.1 ? 1 : 0]++; } for (int i = 0; i < 4; i++) { cout << l[i] << ' ' << r[i]; } return 0; }
#include <iostream> using namespace std; int l[4], r[4]; int main() { double a, b; while (cin >> a >> b) { l[a < 0.2 ? 3 : a < 0.6 ? 2 : a < 1.1 ? 1 : 0]++; r[b < 0.2 ? 3 : b < 0.6 ? 2 : b < 1.1 ? 1 : 0]++; } for (int i = 0; i < 4; i++) { cout << l[i] << ' ' << r[i] << endl; } return 0; }
[["+", 0, 7, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 7, 8, 9, 0, 1, 0, 16, 12, 22]]
1
121
2
#include <iostream> using namespace std; int main(void) { double date[41][2]; int num = 0; while (cin >> date[num][0] >> date[num][1]) { num++; } double judge[5] = {0, 0.2, 0.6, 1.1, 100}; int out[4][2] = {0}; for (int i = 0; i < num; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 4; k++) { if (judge[k] <= date[i][j] && date[i][j] < judge[k + 1]) { out[k][j]++; break; } } } } for (int i = 4; i >= 0; i--) { cout << out[i][0] << " " << out[i][1] << endl; } return 0; }
#include <iostream> using namespace std; int main(void) { double date[41][2]; int num = 0; while (cin >> date[num][0] >> date[num][1]) { num++; } double judge[5] = {0, 0.2, 0.6, 1.1, 100}; int out[4][2] = {0}; for (int i = 0; i < num; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 4; k++) { if (judge[k] <= date[i][j] && date[i][j] < judge[k + 1]) { out[k][j]++; break; } } } } for (int i = 3; i >= 0; i--) { cout << out[i][0] << " " << out[i][1] << endl; } return 0; }
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13]]
1
217
2
#include <stdio.h> int main() { int i = 0, lt[4] = {0}, rt[4] = {0}; double left[41], right[41]; while (scanf("%lf", &left[i]) != EOF) { scanf("%lf", &right[i]); if (left[i] >= 1.1) lt[0]++; else if (left[i] >= 0.6) lt[1]++; else if (left[i] >= 0.2) lt[2]++; else lt[3]++; if (right[i] >= 1.1) rt[0]++; else if (right[i] >= 0.6) rt[1]++; else if (right[i] >= 0.2) rt[2]++; else rt[3]++; i++; } for (i = 0; i > 4; i++) { printf("%d %d", lt[i], rt[i]); } return 0; }
#include <stdio.h> int main() { int i = 0, lt[4] = {0}, rt[4] = {0}; double left[41], right[41]; while (scanf("%lf", &left[i]) != EOF) { scanf("%lf", &right[i]); if (left[i] >= 1.1) lt[0]++; else if (left[i] >= 0.6) lt[1]++; else if (left[i] >= 0.2) lt[2]++; else lt[3]++; if (right[i] >= 1.1) rt[0]++; else if (right[i] >= 0.6) rt[1]++; else if (right[i] >= 0.2) rt[2]++; else rt[3]++; i++; } for (i = 0; i < 4; i++) { printf("%d %d\n", lt[i], rt[i]); } return 0; }
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 47], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
1
220
3
#include <iostream> using namespace std; #define A 0 #define B 1 #define C 2 #define D 3 int result[2][4]; int main() { double buf[2]; while (cin >> buf[0] >> buf[1]) { for (int i = 0; i < 2; i++) { if (buf[i] >= 1.1) result[i][A]++; else if (buf[i] >= 0.6) result[i][B]++; else if (buf[i] >= 0.2) result[i][C]++; else result[i][D]++; } } for (int i = 0; i < D; i++) cout << result[0][i] << " " << result[1][i] << endl; return 0; }
#include <iostream> using namespace std; #define A 0 #define B 1 #define C 2 #define D 3 int result[2][4]; int main() { double buf[2]; while (cin >> buf[0] >> buf[1]) { for (int i = 0; i < 2; i++) { if (buf[i] >= 1.1) result[i][A]++; else if (buf[i] >= 0.6) result[i][B]++; else if (buf[i] >= 0.2) result[i][C]++; else result[i][D]++; } } for (int i = 0; i < 4; i++) cout << result[0][i] << " " << result[1][i] << endl; return 0; }
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13]]
1
178
2
#include <stdio.h> int main(void) { double h, m; int cMA, cHA; int cMB, cHB; int cMC, cHC; int cMD, cHD; cMA = 0; cHA = 0; cMB = 0; cHB = 0; cMC = 0; cHC = 0; cMD = 0; cHD = 0; while (scanf("%lf %lf", &h, &m) != EOF) { if (h >= 1.1) { cHA++; } else if (0.6 <= h && h < 0.6) { cHB++; } else if (0.2 <= h && h < 0.6) { cHC++; } else { cHD++; } if (m >= 1.1) { cMA++; } else if (0.6 <= m && m < 1.1) { cMB++; } else if (0.2 <= m && m < 0.6) { cMC++; } else if (0.2 > m) { cMD++; } } printf("%d %d\n%d %d\n%d %d\n%d %d\n", cHA, cMA, cHB, cMB, cHC, cMC, cHD, cMD); return 0; }
#include <stdio.h> int main(void) { double h, m; int cMA, cHA; int cMB, cHB; int cMC, cHC; int cMD, cHD; cMA = 0; cHA = 0; cMB = 0; cHB = 0; cMC = 0; cHC = 0; cMD = 0; cHD = 0; while (scanf("%lf %lf", &h, &m) != EOF) { if (h >= 1.1) { cHA++; } else if (0.6 <= h && h < 1.1) { cHB++; } else if (0.2 <= h && h < 0.6) { cHC++; } else { cHD++; } if (m >= 1.1) { cMA++; } else if (0.6 <= m && m < 1.1) { cMB++; } else if (0.2 <= m && m < 0.6) { cMC++; } else if (0.2 > m) { cMD++; } } printf("%d %d\n%d %d\n%d %d\n%d %d\n", cHA, cMA, cHB, cMB, cHC, cMC, cHD, cMD); return 0; }
[["-", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
1
222
2
#include <cstring> #include <iostream> using namespace std; int getRank(double x) { if (1.1 <= x) return 0; if (0.6 <= x) return 1; if (0.2 <= x) return 2; return 3; } int main() { int resutls[4][2]; double a, b; memset(resutls, 0, sizeof(resutls)); while (cin >> a >> b) { resutls[getRank(a)][0]++; resutls[getRank(a)][1]++; } for (int i = 0; i < 4; i++) { cout << resutls[i][0] << ' ' << resutls[i][1] << endl; } return 0; }
#include <cstring> #include <iostream> using namespace std; int getRank(double x) { if (1.1 <= x) return 0; if (0.6 <= x) return 1; if (0.2 <= x) return 2; return 3; } int main() { int resutls[4][2]; double a, b; memset(resutls, 0, sizeof(resutls)); while (cin >> a >> b) { resutls[getRank(a)][0]++; resutls[getRank(b)][1]++; } for (int i = 0; i < 4; i++) { cout << resutls[i][0] << ' ' << resutls[i][1] << endl; } return 0; }
[["-", 28, 69, 341, 342, 0, 2, 3, 4, 0, 22], ["+", 28, 69, 341, 342, 0, 2, 3, 4, 0, 22]]
1
155
2
#include <iostream> using namespace std; int main() { double r, l; int va[2][4] = {0}; while (cin >> r >> l) { if (r >= 1.1) va[0][0]++; else if (r >= 0.6) va[0][1]++; else if (r >= 0.2) va[0][2]++; else va[0][3]++; if (l >= 1.1) va[1][0]++; else if (l >= 0.6) va[1][1]++; else if (l >= 0.2) va[1][2]++; else va[1][3]++; } for (int i = 0; i < 4; i++) { cout << va[1][i] << " " << va[0][i] << endl; } }
#include <iostream> using namespace std; int main() { double r, l; int va[2][4] = {0}; while (cin >> l >> r) { if (r >= 1.1) va[0][0]++; else if (r >= 0.6) va[0][1]++; else if (r >= 0.2) va[0][2]++; else va[0][3]++; if (l >= 1.1) va[1][0]++; else if (l >= 0.6) va[1][1]++; else if (l >= 0.2) va[1][2]++; else va[1][3]++; } for (int i = 0; i < 4; i++) { cout << va[1][i] << " " << va[0][i] << endl; } }
[["-", 0, 52, 15, 339, 51, 16, 31, 16, 12, 22], ["-", 8, 9, 0, 52, 15, 339, 51, 16, 17, 152], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 152], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 12, 22]]
1
194
4
public class Main { static int N = 10001; public void run(java.io.InputStream in, java.io.PrintStream out) { java.util.Scanner sc = new java.util.Scanner(in); int[] p; int pn, i, n, p1, q1; p = new int[N / 6]; pn = getprime(p); for (;;) { n = sc.nextInt(); if (n == 0) break; p1 = 3; q1 = 5; for (i = 2; p[i] < n && i < pn; i++) if (p[i] - p[i - 1] == 2) { p1 = p[i - 1]; q1 = p[i]; } out.println(p1 + " " + q1); } sc.close(); } public static void main(String[] args) { (new Main()).run(System.in, System.out); } private static int getprime(int[] p) { int i, j, count = 0; boolean[] e; e = new boolean[N]; e[0] = true; e[1] = true; for (i = 2; i < N; i++) if (!e[i]) { p[count++] = i; for (j = i * 2; j < N; j += i) e[j] = true; } return count; } }
public class Main { static int N = 10001; public void run(java.io.InputStream in, java.io.PrintStream out) { java.util.Scanner sc = new java.util.Scanner(in); int[] p; int pn, i, n, p1, q1; p = new int[N / 6]; pn = getprime(p); for (;;) { n = sc.nextInt(); if (n == 0) break; p1 = 3; q1 = 5; for (i = 2; p[i] <= n && i < pn; i++) if (p[i] - p[i - 1] == 2) { p1 = p[i - 1]; q1 = p[i]; } out.println(p1 + " " + q1); } sc.close(); } public static void main(String[] args) { (new Main()).run(System.in, System.out); } private static int getprime(int[] p) { int i, j, count = 0; boolean[] e; e = new boolean[N]; e[0] = true; e[1] = true; for (i = 2; i < N; i++) if (!e[i]) { p[count++] = i; for (j = i * 2; j < N; j += i) e[j] = true; } return count; } }
[["-", 8, 196, 0, 7, 15, 16, 31, 16, 17, 18], ["+", 8, 196, 0, 7, 15, 16, 31, 16, 17, 19]]
3
320
2
import java.util.*; class Main { public static void main(String args[]) { Scanner sc = new Scanner(System.in); Boolean[] prime = new Boolean[10001]; prime[0] = prime[1] = true; for (int i = 2; i < 10001; i++) { if (prime[i] == false) { int j = 2; while (i * j < 10001) { prime[i * j] = true; j++; } } } while (true) { int N = sc.nextInt(); if (N == 0) { return; } while (true) { if (prime[N] == false && prime[N - 2] == false) { System.out.println(N - 2 + " " + N); break; } N--; } } } }
import java.util.*; class Main { public static void main(String args[]) { Scanner sc = new Scanner(System.in); boolean[] prime = new boolean[10001]; prime[0] = prime[1] = true; for (int i = 2; i < 10001; i++) { if (prime[i] == false) { int j = 2; while (i * j < 10001) { prime[i * j] = true; j++; } } } while (true) { int N = sc.nextInt(); if (N == 0) { return; } while (true) { if (prime[N] == false && prime[N - 2] == false) { System.out.println(N - 2 + " " + N); break; } N--; } } } }
[["-", 0, 195, 8, 196, 0, 503, 39, 224, 468, 78], ["+", 0, 195, 8, 196, 0, 503, 39, 224, 468, 523], ["-", 8, 196, 0, 503, 49, 200, 51, 227, 39, 78], ["+", 8, 196, 0, 503, 49, 200, 51, 227, 39, 523]]
3
184
4
import java.util.*; public class Main { public static void main(String[] args) throws java.io.IOException { Scanner scan = new Scanner(System.in); while (scan.hasNext()) { int n = scan.nextInt(); if (n == 0) break; boolean[] prime = new boolean[n + 1]; for (int i = 0; i <= n; i++) prime[i] = true; for (int i = 2; i < n; i++) for (int j = i * 2; j < n; j += i) prime[j] = false; int max = 0; for (int i = 2; i <= n - 2; i++) if (prime[i] && prime[i + 2]) max = i + 2; System.out.println(max - 2 + " " + max); } } }
import java.util.*; public class Main { public static void main(String[] args) throws java.io.IOException { Scanner scan = new Scanner(System.in); while (scan.hasNext()) { int n = scan.nextInt(); if (n == 0) break; boolean[] prime = new boolean[n + 1]; for (int i = 0; i <= n; i++) prime[i] = true; for (int i = 2; i <= n; i++) for (int j = i * 2; j <= n; j += i) prime[j] = false; int max = 0; for (int i = 2; i <= n - 2; i++) if (prime[i] && prime[i + 2]) max = i + 2; System.out.println(max - 2 + " " + max); } } }
[["-", 0, 52, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 8, 196, 0, 7, 8, 7, 15, 16, 17, 18], ["+", 8, 196, 0, 7, 8, 7, 15, 16, 17, 19]]
3
198
4
#include <math.h> #include <stdio.h> int isprime(int n) { int i; if (n <= 1) { return 0; } for (i = 2; i * i <= n; i++) { if (n % i == 0) { return 0; } } return 1; } int main() { int n, i; while (1) { scanf("%d", &n); if (n == 0) { break; } for (i = n; i >= 2; i--) { if (isprime(i) && isprime(i - 2)) { printf("%d %d", i - 2, i); break; } } } return 0; }
#include <math.h> #include <stdio.h> int isprime(int n) { int i; if (n <= 1) { return 0; } for (i = 2; i * i <= n; i++) { if (n % i == 0) { return 0; } } return 1; } int main() { int n, i; while (1) { scanf("%d", &n); if (n == 0) { break; } for (i = n; i >= 2; i--) { if (isprime(i) && isprime(i - 2)) { printf("%d %d\n", i - 2, i); break; } } } return 0; }
[["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
0
145
1
#include <stdio.h> #define M 10001 int main() { char p[M] = {1, 1}; int i, j, n; for (i = 2; i * i < M; i++) { if (p[i]) continue; for (j = i * i; j < M; j += i) p[j] = 1; } while (scanf("%d", &n), n) { while (n--) { if (p[n] + p[n - 2] == 0) break; } printf("%d %d\n", n - 2, n); } return 0; }
#include <stdio.h> #define M 10001 int main() { char p[M] = {1, 1}; int i, j, n; for (i = 2; i * i < M; i++) { if (p[i]) continue; for (j = i * i; j < M; j += i) p[j] = 1; } while (scanf("%d", &n), n++) { while (n--) { if (p[n] + p[n - 2] == 0) break; } printf("%d %d\n", n - 2, n); } return 0; }
[["+", 0, 52, 15, 23, 0, 34, 12, 27, 17, 29]]
0
137
1
#include <stdio.h> int main() { int i, j, p, n; int prime[10000] = {0}; while (scanf("%d", &n), n) { for (i = 2; i < 10000; i++) prime[i] = 1; for (i = 2; i <= n; i++) if (prime[i]) for (j = i + i; j <= n; j += i) prime[j] = 0; for (i = 3; i < n - 2; i += 2) if (prime[i]) if (prime[i + 2]) p = i; printf("%d %d\n", p, p + 2); } return 0; }
#include <stdio.h> int main() { int i, j, p, n; int prime[10001] = {0}; while (scanf("%d", &n), n) { for (i = 2; i < 10000; i++) prime[i] = 1; for (i = 2; i <= n; i++) if (prime[i]) for (j = i + i; j <= n; j += i) prime[j] = 0; for (i = 3; i <= n - 2; i += 2) if (prime[i]) if (prime[i + 2]) p = i; printf("%d %d\n", p, p + 2); } return 0; }
[["-", 8, 9, 0, 43, 49, 50, 49, 80, 81, 13], ["+", 8, 9, 0, 43, 49, 50, 49, 80, 81, 13], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
0
159
4
#include <stdio.h> int isprime(int n) { int i; for (i = 2; i * i < n; i++) { if (n % i == 0) return 0; } return 1; } int main(void) { const int NUM = 10001; int i, n, prime[NUM], p1, q1; for (i = 2; i < NUM; i++) { prime[i] = isprime(i); } while (1) { scanf("%d", &n); if (n == 0) break; for (i = n; i >= 2; i--) { if (prime[i] == 1 && prime[i - 2] == 1) { q1 = i; p1 = i - 2; printf("%d %d\n", p1, q1); break; } } } return 0; }
#include <stdio.h> int isprime(int n) { int i; for (i = 2; i * i <= n; i++) { if (n % i == 0) return 0; } return 1; } int main(void) { const int NUM = 10001; int i, n, prime[NUM], p1, q1; for (i = 2; i < NUM; i++) { prime[i] = isprime(i); } while (1) { scanf("%d", &n); if (n == 0) break; for (i = n; i >= 2; i--) { if (prime[i] == 1 && prime[i - 2] == 1) { q1 = i; p1 = i - 2; printf("%d %d\n", p1, q1); break; } } } return 0; }
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19]]
0
182
2
#include <stdio.h> #include <string.h> int main() { const int MAX_V = 1000; int prime[MAX_V + 1]; int i, k, v, n, p1, q1; for (i = 2; i <= MAX_V; i++) { prime[i] = 1; } for (i = 2; i * i <= MAX_V; i++) { if (prime[i]) { for (k = 2 * i; k <= MAX_V; k += i) { prime[k] = 0; } } } prime[0] = 0; prime[1] = 0; while (1) { scanf("%d", &v); if (v == 0) break; if (prime[v] == 0) { while (1) { v--; if (prime[v] == 1) break; } } p1 = v; q1 = v; for (i = v - 1; i > 0; i--) { if (prime[i] == 1) q1 = i; if (p1 - q1 == 2) { printf("%d %d\n", q1, p1); break; } else { p1 = q1; } } } return 0; }
#include <stdio.h> #include <string.h> int main() { const int MAX_V = 1000000; int prime[MAX_V + 1]; int i, k, v, n, p1, q1; for (i = 2; i <= MAX_V; i++) { prime[i] = 1; } for (i = 2; i * i <= MAX_V; i++) { if (prime[i]) { for (k = 2 * i; k <= MAX_V; k += i) { prime[k] = 0; } } } prime[0] = 0; prime[1] = 0; while (1) { scanf("%d", &v); if (v == 0) break; if (prime[v] == 0) { while (1) { v--; if (prime[v] == 1) break; } } p1 = v; q1 = v; for (i = v - 1; i > 0; i--) { if (prime[i] == 1) q1 = i; if (p1 - q1 == 2) { printf("%d %d\n", q1, p1); break; } else { p1 = q1; } } } return 0; }
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13]]
0
251
2
#include <stdio.h> int isprime(int n) { for (int i = 2; i * i <= n; i++) { if (n % i == 0) return 0; } return 1; } int main() { int n, p1, q1, i; while (1) { scanf("%d", &n); if (n == 0) break; for (i = n; i >= 5; i--) { if (isprime(i) == 1) { if (isprime(i - 2) == 1) { p1 = i; q1 = i - 2; break; } } } printf("%d %d\n", p1, q1); } return 0; }
#include <stdio.h> int isprime(int n) { for (int i = 2; i * i <= n; i++) { if (n % i == 0) return 0; } return 1; } int main() { int n, p1, q1, i; while (1) { scanf("%d", &n); if (n == 0) break; for (i = n; i >= 5; i--) { if (isprime(i) == 1) { if (isprime(i - 2) == 1) { q1 = i; p1 = i - 2; break; } } } printf("%d %d\n", p1, q1); } return 0; }
[["-", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22]]
0
147
4
#include <stdio.h> int isprime(int n) { for (int i = 2; i * i <= n; i++) { if (n % i == 0) return 0; } return 1; } int main() { int number[10000 + 2] = {0}; int n, i, fir, sec; for (i = 2; i < 10000; i++) { number[i] = isprime(i); } while (scanf("%d", &n)) { if (n == 0) break; fir = 0, sec = 0; for (i = n; n > 0; n--) { if (number[i] && number[i - 2]) { fir = i - 2; sec = i; break; } } printf("%d %d\n", fir, sec); } return 0; }
#include <stdio.h> int isprime(int n) { for (int i = 2; i * i <= n; i++) { if (n % i == 0) return 0; } return 1; } int main() { int number[10000 + 2] = {0}; int n, i, fir, sec; for (i = 2; i < 10000; i++) { number[i] = isprime(i); } while (scanf("%d", &n)) { if (n == 0) break; fir = 0, sec = 0; for (i = n; i > 3; i--) { if (number[i] && number[i - 2]) { fir = i - 2; sec = i; break; } } printf("%d %d\n", fir, sec); } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 31, 22], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 31, 22], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13], ["-", 0, 52, 8, 9, 0, 7, 26, 27, 28, 22], ["+", 0, 52, 8, 9, 0, 7, 26, 27, 28, 22]]
0
182
6
#include <math.h> #include <stdio.h> int sos(int); int main() { int i, j, p, q, n; while (1) { scanf("%d", &n); if (n == 0) { break; } for (i = n; i >= 2; i--) { p = sos(i); q = sos(i + 2); if (p != 0 && q != 0) { break; } } printf("%d %d\n", p, q); } return 0; } int sos(int x) { int i; for (i = 2; i <= sqrt(x); i++) { if (x % i == 0) { return 0; } } return x; }
#include <math.h> #include <stdio.h> int sos(int); int main() { int i, j, p, q, n; while (1) { scanf("%d", &n); if (n == 0) { break; } for (i = n - 2; i >= 2; i--) { p = sos(i); q = sos(i + 2); if (p != 0 && q != 0) { break; } } printf("%d %d\n", p, q); } return 0; } int sos(int x) { int i; for (i = 2; i <= sqrt(x); i++) { if (x % i == 0) { return 0; } } return x; }
[["+", 8, 9, 0, 7, 10, 11, 12, 16, 17, 33], ["+", 8, 9, 0, 7, 10, 11, 12, 16, 12, 13]]
0
158
2
#include <stdio.h> #define N 10000 int tbl[N + 1] = {0}; size_t tbln = 0; /** Application main entry point. */ int main(int argc, char *argv[]) { int i, j; for (j = 2; j <= N; ++j) { if (tbl[j]) continue; for (i = j * 2; i <= N; i += j) { tbl[i] = 1; } } for (i = 2; i <= N - 2; ++i) { if (!tbl[i] && !tbl[i + 2]) { tbl[tbln++] = i + 2; } } for (;;) { int n; scanf("%d", &n); if (!(n)) break; for (i = 1; i < tbln && tbl[i] < n; ++i) ; printf("%d %d\n", tbl[i - 1] - 2, tbl[i - 1]); } return (0); }
#include <stdio.h> #define N 10000 int tbl[N + 1] = {0}; size_t tbln = 0; /** Application main entry point. */ int main(int argc, char *argv[]) { int i, j; for (j = 2; j <= N; ++j) { if (tbl[j]) continue; for (i = j * 2; i <= N; i += j) { tbl[i] = 1; } } for (i = 2; i <= N - 2; ++i) { if (!tbl[i] && !tbl[i + 2]) { tbl[tbln++] = i + 2; } } for (;;) { int n; scanf("%d", &n); if (!(n)) break; for (i = 1; i < tbln && tbl[i] <= n; ++i) ; printf("%d %d\n", tbl[i - 1] - 2, tbl[i - 1]); } return (0); }
[["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 18], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 17, 19]]
0
215
2
#include <iostream> using namespace std; bool isp[10000]; main() { isp[0] = isp[1] = 1; for (int i = 2; i <= 100; i++) { if (isp[i]) continue; for (int j = i * i; j <= 10000; j += i) isp[j] = 1; } int n; while (cin >> n, n) { while (!isp[n] && !isp[n - 2]) n--; cout << n - 2 << " " << n << endl; } }
#include <iostream> using namespace std; bool isp[10000]; main() { isp[0] = isp[1] = 1; for (int i = 2; i <= 100; i++) { if (isp[i]) continue; for (int j = i * i; j <= 10000; j += i) isp[j] = 1; } int n; while (cin >> n, n) { while (isp[n] || isp[n - 2]) n--; cout << n - 2 << " " << n << endl; } }
[["-", 0, 52, 15, 339, 51, 16, 31, 91, 17, 111], ["-", 8, 9, 0, 52, 15, 339, 51, 16, 17, 98], ["-", 0, 52, 15, 339, 51, 16, 12, 91, 17, 111], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 106]]
1
124
4
#include <algorithm> #include <iostream> using namespace std; bool p[101000]; void prime() { fill(p, p + 101000, true); p[0] = false; p[1] = false; for (int i = 2; i < 101000; i++) { if (p[i]) { for (int j = 2; i * j < 101000; j++) { p[i * j] = false; } } } } int main() { int n; prime(); while (cin >> n, n) { int ans; for (int i = 0; i < n; i++) { if (p[i] && p[i - 2]) ans = i; } cout << ans - 2 << ' ' << ans << endl; } }
#include <algorithm> #include <iostream> using namespace std; bool p[101000]; void prime() { fill(p, p + 101000, true); p[0] = false; p[1] = false; for (int i = 2; i < 101000; i++) { if (p[i]) { for (int j = 2; i * j < 101000; j++) { p[i * j] = false; } } } } int main() { int n; prime(); while (cin >> n, n) { int ans; for (int i = 0; i <= n; i++) { if (p[i] && p[i - 2]) ans = i; } cout << ans - 2 << ' ' << ans << endl; } }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
1
171
18
#include <bits/stdc++.h> using namespace std; #define MAX_N 12000 int prime[MAX_N]; bool is_prime[MAX_N + 1]; void prime_generate() { int p = 0; for (int i = 0; i <= MAX_N; i++) is_prime[i] = true; is_prime[0] = is_prime[1] = false; for (int i = 2; i <= MAX_N; i++) { if (is_prime[i]) { prime[p++] = i; for (int j = 2 * i; j <= MAX_N; j += i) is_prime[j] = false; } } } void solve(int n) { int p1 = -1, p2 = -1; for (int i = 0; prime[i + 1] <= n; i++) { if (prime[i + 1] - prime[i] == 2) { if (p1 <= prime[i]) { p1 = prime[i]; } if (p2 <= prime[i + 1]) { p2 = prime[i + 1]; } } } cout << p1 << " " << p2 << endl; } int main() { prime_generate(); int n; while (cin >> n) { solve(n); } }
#include <bits/stdc++.h> using namespace std; #define MAX_N 12000 int prime[MAX_N]; bool is_prime[MAX_N + 1]; void prime_generate() { int p = 0; for (int i = 0; i <= MAX_N; i++) is_prime[i] = true; is_prime[0] = is_prime[1] = false; for (int i = 2; i <= MAX_N; i++) { if (is_prime[i]) { prime[p++] = i; for (int j = 2 * i; j <= MAX_N; j += i) is_prime[j] = false; } } } void solve(int n) { int p1 = -1, p2 = -1; for (int i = 0; prime[i + 1] <= n; i++) { if (prime[i + 1] - prime[i] == 2) { if (p1 <= prime[i]) { p1 = prime[i]; } if (p2 <= prime[i + 1]) { p2 = prime[i + 1]; } } } cout << p1 << " " << p2 << endl; } int main() { prime_generate(); int n; while (cin >> n, n) { solve(n); } }
[["+", 8, 9, 0, 52, 15, 339, 51, 34, 0, 21], ["+", 8, 9, 0, 52, 15, 339, 51, 34, 12, 22]]
1
258
2
#include <iostream> #define loop(i, a, b) for (int i = a; i < b; i++) #define rep(i, a) loop(i, 0, a) using namespace std; int main() { int dt[10003]; dt[0] = dt[1] = 0; loop(i, 2, 10003) dt[i] = 1; dt[10001] = dt[10002] = 0; for (int i = 2; i < 100; i++) { if (dt[i] == 1) { for (int j = 2; i * j < 10000; j++) { dt[i * j] = 0; } } } int n; while (1) { cin >> n; if (n == 0) break; int ans = 0; rep(i, n - 2) { if (dt[i] == 1 && dt[i + 2] == 1) { ans = i; } } cout << ans << " " << ans + 2 << endl; } return 0; }
#include <iostream> #define loop(i, a, b) for (int i = a; i < b; i++) #define rep(i, a) loop(i, 0, a) using namespace std; int main() { int dt[10003]; dt[0] = dt[1] = 0; loop(i, 2, 10003) dt[i] = 1; dt[10001] = dt[10002] = 0; for (int i = 2; i < 100; i++) { if (dt[i] == 1) { for (int j = 2; i * j < 10000; j++) { dt[i * j] = 0; } } } int n; while (1) { cin >> n; if (n == 0) break; int ans = 0; rep(i, n - 1) { if (dt[i] == 1 && dt[i + 2] == 1) { ans = i; } } cout << ans << " " << ans + 2 << endl; } return 0; }
[["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
1
207
2
#include <iostream> using namespace std; string prime(int n) { int i, j; string p = "001"; while (p.size() < n) p += "10"; i = 3; while (i * i < n) { for (j = 3 * i; j < n; j += 2 * i) p[j] = '0'; do { i += 2; } while (p[i] - '1'); } return p; } int main() { int n; string p; while (1) { cin >> n; if (!n) break; p = prime(n); while (n) { if (p[n] == '1' && p[n - 2] == '1') { cout << n - 2 << " " << n << endl; break; } n--; } } }
#include <iostream> using namespace std; string prime(int n) { int i, j; string p = "001"; while (p.size() <= n) p += "10"; i = 3; while (i * i <= n) { for (j = 3 * i; j <= n; j += 2 * i) p[j] = '0'; do { i += 2; } while (p[i] - '1'); } return p; } int main() { int n; string p; while (1) { cin >> n; if (!n) break; p = prime(n); while (n) { if (p[n] == '1' && p[n - 2] == '1') { cout << n - 2 << " " << n << endl; break; } n--; } } }
[["-", 8, 9, 0, 52, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 19], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
1
190
6
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define repc(i, s, e) for (int i = (s); i < (e); i++) #define pb(n) push_back((n)) #define mp(n, m) make_pair((n), (m)) #define all(r) r.begin(), r.end() #define fi first #define se second typedef long long ll; typedef vector<int> vi; typedef vector<vi> vii; typedef vector<ll> vl; typedef vector<vl> vll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; int main() { vi v(10010, 1); v[0] = 0; v[1] = 1; for (int i = 2; i < 10010; i++) { if (v[i] == 1) { for (int j = 2; j <= 10010 / i; j++) { v[i * j] = 0; } } } int n; while (cin >> n && n > 0) { int ans = 5; for (int i = n; i > 1; i--) { if (v[i] && v[i - 2]) { ans = i; break; } } cout << ans - 2 << " " << ans << endl; } }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define repc(i, s, e) for (int i = (s); i < (e); i++) #define pb(n) push_back((n)) #define mp(n, m) make_pair((n), (m)) #define all(r) r.begin(), r.end() #define fi first #define se second typedef long long ll; typedef vector<int> vi; typedef vector<vi> vii; typedef vector<ll> vl; typedef vector<vl> vll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; int main() { vi v(100100, 1); v[0] = 0; v[1] = 1; for (int i = 2; i < 100100; i++) { if (v[i] == 1) { for (int j = 2; j <= 100100 / i; j++) { v[i * j] = 0; } } } int n; while (cin >> n && n > 0) { int ans = 5; for (int i = n; i > 1; i--) { if (v[i] && v[i - 2]) { ans = i; break; } } cout << ans - 2 << " " << ans << endl; } }
[["-", 8, 9, 0, 43, 49, 50, 51, 4, 0, 13], ["+", 8, 9, 0, 43, 49, 50, 51, 4, 0, 13], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["-", 64, 9, 0, 7, 15, 16, 12, 16, 31, 13], ["+", 64, 9, 0, 7, 15, 16, 12, 16, 31, 13]]
1
281
6
#include <stdio.h> int isprime(int n) { for (int i = 2; i * i <= n; i++) { if (n % i == 0) return 0; } return 1; } int main() { int n, i, min, max; int number[10000 + 2] = {0}; for (i = 2; i < 10000; i++) { number[i] = isprime(i); } while (scanf("%d", &n)) { if (n == 0) break; max = 0; min = 0; for (i = n; i > 0; i--) { // printf("%d ",i); if (number[i] && number[i - 2]) { min = i; max = i - 2; // printf("%d %d\n",i,i-2); break; } } printf("%d %d\n", min, max); } return 0; }
#include <stdio.h> int isprime(int n) { for (int i = 2; i * i <= n; i++) { if (n % i == 0) return 0; } return 1; } int main() { int n, i, min, max; int number[10000 + 2] = {0}; for (i = 2; i < 10000; i++) { number[i] = isprime(i); } while (scanf("%d", &n)) { if (n == 0) break; max = 0; min = 0; for (i = n; i > 0; i--) { // printf("%d ",i); if (number[i] && number[i - 2]) { min = i - 2; max = i; // printf("%d %d\n",i,i-2); break; } } printf("%d %d\n", min, max); } return 0; }
[["+", 64, 9, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 64, 9, 0, 1, 0, 11, 12, 16, 12, 13], ["-", 64, 9, 0, 1, 0, 11, 12, 16, 17, 33], ["-", 64, 9, 0, 1, 0, 11, 12, 16, 12, 13]]
1
184
34
#include <stdio.h> const int MAX_V = 10000; // 100???????????????????f???????ยข\????ยฐ???ยฌ????? int prime[MAX_V + 1]; int main() { int k, i, max, min, n; // 1????????f???????C0????????f????????????????????ยข for (i = 2; i <= MAX_V; i++) { prime[i] = 1; // 2???????ยฃ????f????????????ยฐ??????ยจ } for (i = 2; i * i <= MAX_V; i++) { if (prime[i]) { for (k = 2 * i; k <= MAX_V; k += i) { prime[k] = 0; // ???f??????2???{???????ยฃ????{?????????f????????????????????ยข } } } while (scanf("%d", &n)) { if (n == 0) break; max = 0; min = 0; for (i = n; i > 0; i++) { if (prime[i] && prime[i - 2]) { max = i; min = max - 2; // printf("%d %d\n",i-2,i); break; } } printf("%d %d\n", min, max); } return 0; }
#include <stdio.h> const int MAX_V = 1000000; // 100???????????????????f???????ยข\????ยฐ???ยฌ????? int prime[MAX_V + 1]; int main() { int k, i, max, min, n; // 1????????f???????C0????????f????????????????????ยข for (i = 2; i <= MAX_V; i++) { prime[i] = 1; // 2???????ยฃ????f????????????ยฐ??????ยจ } for (i = 2; i * i <= MAX_V; i++) { if (prime[i]) { for (k = 2 * i; k <= MAX_V; k += i) { prime[k] = 0; // ???f??????2???{???????ยฃ????{?????????f????????????????????ยข } } } while (scanf("%d", &n)) { if (n == 0) break; max = 0; min = 0; for (i = n; i > 0; i--) { if (prime[i] && prime[i - 2]) { max = i; min = max - 2; // printf("%d %d\n",i-2,i); break; } } printf("%d %d\n", min, max); } return 0; }
[["-", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["-", 0, 52, 8, 9, 0, 7, 26, 27, 17, 29], ["+", 0, 52, 8, 9, 0, 7, 26, 27, 17, 68]]
1
199
4
#include <stdio.h> int main() { const int MAX_V = 10000; int prime[MAX_V + 1]; int i, k, v, ans, dif; for (i = 2; i <= MAX_V; i++) { prime[i] = 1; } for (i = 2; i * i <= MAX_V; i++) { if (prime[i]) { for (k = 2 * i; k <= MAX_V; k += i) { prime[k] = 0; } } } while (scanf("%d", &v) != EOF) { if (v == 0) break; for (k = v; k >= 2; k--) { ans = prime[k]; if (ans == 0) { dif = prime[k - 2]; if (dif == 0) { printf("%d %d\n", k - 2, k); break; } } } } return 0; }
#include <stdio.h> int main() { const int MAX_V = 10000; int prime[MAX_V + 1]; int i, k, v, ans, dif; for (i = 2; i <= MAX_V; i++) { prime[i] = 1; } for (i = 2; i * i <= MAX_V; i++) { if (prime[i]) { for (k = 2 * i; k <= MAX_V; k += i) { prime[k] = 0; } } } while (scanf("%d", &v) != EOF) { if (v == 0) break; for (k = v; k >= 2; k--) { ans = prime[k]; if (ans == 1) { dif = prime[k - 2]; if (dif == 1) { printf("%d %d\n", k - 2, k); break; } } } } return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["-", 64, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 64, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
1
196
4
#include <cmath> #include <iostream> using namespace std; #define MAX_N 3000000 int prime[MAX_N], twin[MAX_N]; void isprime(int c) { prime[2] = 1; for (int i = 3; i < c; i += 2) { for (int j = 3; j <= sqrt(i); j += 2) { if (i % j == 0) { goto E; } } prime[i] = 1; E:; } } void istwin(int d) { for (int i = 5; i < d; i++) { if (prime[i - 2] + prime[i] == 2) { twin[i] = i; } else { twin[i] = twin[i - 1]; } } } int n; int main() { isprime(MAX_N); istwin(MAX_N); while (true) { cin >> n; if (n == 0) { break; } cout << twin[n] - 2 << twin[n] << endl; } }
#include <cmath> #include <iostream> using namespace std; #define MAX_N 3700000 int prime[MAX_N], twin[MAX_N]; void isprime(int c) { prime[2] = 1; for (int i = 3; i < c; i += 2) { for (int j = 3; j <= sqrt(i); j += 2) { if (i % j == 0) { goto E; } } prime[i] = 1; E:; } } void istwin(int d) { for (int i = 5; i < d; i++) { if (prime[i - 2] + prime[i] == 2) { twin[i] = i; } else { twin[i] = twin[i - 1]; } } } int n; int main() { isprime(MAX_N); istwin(MAX_N); while (true) { cin >> n; if (n == 0) { break; } cout << twin[n] - 2 << ' ' << twin[n] << endl; } }
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 0, 1, 0, 16, 31, 16, 31, 16, 17, 151], ["+", 0, 16, 31, 16, 31, 16, 12, 103, 0, 104], ["+", 0, 16, 31, 16, 31, 16, 12, 103, 0, 125]]
1
216
6