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
|
|---|---|---|---|---|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MKP make_pair
#define fi first
#define se second
typedef pair<int, int> pii;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 205;
constexpr int MAX_W = 10005;
constexpr int INF = 1LL << 60;
/* 基本要素 */
typedef double D; // 座標値の型。doubleかlong doubleを想定
typedef complex<D> P; // Point
typedef pair<P, P> L; // Line
typedef vector<P> VP;
const D EPS = 1e-9; // 許容誤差。問題によって変える
#define X real()
#define Y imag()
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define EQ(n, m) (abs((n) - (m)) < EPS)
// 内積 dot(a,b) = |a||b|cosθ
D dot(P a, P b) { return (conj(a) * b).X; }
// 外積 cross(a,b) = |a||b|sinθ
D cross(P a, P b) { return (conj(a) * b).Y; }
VP crosspointCC(P a, D ar, P b, D br) {
VP ps;
P ab = b - a;
D d = abs(ab);
D crL = (norm(ab) + ar * ar - br * br) / (2 * d);
if (EQ(d, 0) || ar < abs(crL))
return ps;
P abN = ab * P(0, sqrt(ar * ar - crL * crL) / d);
P cp = a + crL / d * ab;
ps.push_back(cp + abN);
if (!EQ(norm(abN), 0))
ps.push_back(cp - abN);
return ps;
}
int n;
vector<P> v;
bool solve() {
v.clear();
cin >> n;
if (!n)
return false;
for (int i = 0; i < n; ++i) {
double x, y;
cin >> x >> y;
v.emplace_back(P(x, y));
}
int res = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
auto crs = crosspointCC(v[i], 1.0, v[j], 1.0);
for (int k = 0; k < crs.size(); ++k) {
int cnt = 0;
for (int l = 0; l < n; ++l) {
double dist = abs(crs[k] - v[l]);
if (dist <= 1.0 + EPS)
cnt++;
}
res = max(res, cnt);
}
}
}
cout << res << endl;
return true;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
while (solve())
;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MKP make_pair
#define fi first
#define se second
typedef pair<int, int> pii;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 205;
constexpr int MAX_W = 10005;
constexpr int INF = 1LL << 60;
/* 基本要素 */
typedef double D; // 座標値の型。doubleかlong doubleを想定
typedef complex<D> P; // Point
typedef pair<P, P> L; // Line
typedef vector<P> VP;
const D EPS = 1e-9; // 許容誤差。問題によって変える
#define X real()
#define Y imag()
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define EQ(n, m) (abs((n) - (m)) < EPS)
// 内積 dot(a,b) = |a||b|cosθ
D dot(P a, P b) { return (conj(a) * b).X; }
// 外積 cross(a,b) = |a||b|sinθ
D cross(P a, P b) { return (conj(a) * b).Y; }
VP crosspointCC(P a, D ar, P b, D br) {
VP ps;
P ab = b - a;
D d = abs(ab);
D crL = (norm(ab) + ar * ar - br * br) / (2 * d);
if (EQ(d, 0) || ar < abs(crL))
return ps;
P abN = ab * P(0, sqrt(ar * ar - crL * crL) / d);
P cp = a + crL / d * ab;
ps.push_back(cp + abN);
if (!EQ(norm(abN), 0))
ps.push_back(cp - abN);
return ps;
}
int n;
vector<P> v;
bool solve() {
v.clear();
cin >> n;
if (!n)
return false;
for (int i = 0; i < n; ++i) {
double x, y;
cin >> x >> y;
v.emplace_back(P(x, y));
}
int res = 1;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
auto crs = crosspointCC(v[i], 1.0, v[j], 1.0);
for (int k = 0; k < crs.size(); ++k) {
int cnt = 0;
for (int l = 0; l < n; ++l) {
double dist = abs(crs[k] - v[l]);
if (dist <= 1.0 + EPS)
cnt++;
}
res = max(res, cnt);
}
}
}
cout << res << endl;
return true;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
while (solve())
;
}
|
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13]]
| 1
| 559
|
#include <bits/stdc++.h>
using namespace std;
#define EPS (1e-4)
typedef complex<double> P;
int main() {
int n;
while (cin >> n, n) {
vector<P> a(n);
for (auto &e : a) {
double x, y;
cin >> x >> y;
e.real(x);
e.imag(y);
}
int m = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (abs(a[j] - a[i]) < 2.0 + EPS) {
P u = (a[j] - a[i]) / 2.0;
P v = P(-u.imag(), u.real()) / abs(u) * sqrt(1.0 - pow(abs(u), 2));
vector<P> o = {a[i] + u + v, a[i] + u - v};
for (auto e : o) {
int t = 2;
for (int k = 0; k < n; k++) {
if (k != i && k != j) {
t += abs(a[k] - e) < 1.0 + EPS;
}
}
m = max(m, t);
}
}
}
}
cout << m << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define EPS (1e-4)
typedef complex<double> P;
int main() {
int n;
while (cin >> n, n) {
vector<P> a(n);
for (auto &e : a) {
double x, y;
cin >> x >> y;
e.real(x);
e.imag(y);
}
int m = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i != j && abs(a[j] - a[i]) < 2.0 + EPS) {
P u = (a[j] - a[i]) / 2.0;
P v = P(-u.imag(), u.real()) / abs(u) * sqrt(1.0 - pow(abs(u), 2));
vector<P> o = {a[i] + u + v, a[i] + u - v};
for (auto e : o) {
int t = 2;
for (int k = 0; k < n; k++) {
if (k != i && k != j) {
t += abs(a[k] - e) < 1.0 + EPS;
}
}
m = max(m, t);
}
}
}
}
cout << m << endl;
}
}
|
[["+", 0, 57, 15, 339, 51, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 79], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 12, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 98]]
| 1
| 292
|
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define rep(i, n) REP(i, 0, n)
typedef long long ll;
typedef pair<int, int> pint;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const double eps = 1e-10;
double add(double a, double b) {
if (abs(a + b) < eps * (abs(a) + abs(b)))
return 0;
return a + b;
}
typedef pair<double, double> P;
P operator+(const P &x, const P &y) {
return {add(x.first, y.first), add(x.second, y.second)};
}
P operator-(const P &x, const P &y) {
return {add(x.first, -y.first), add(x.second, -y.second)};
}
P operator*(const P &x, const double &y) { return {x.first * y, x.second * y}; }
double dot(P x, P y) { return add(x.first * y.first, x.second * y.second); }
double det(P x, P y) { return add(x.first * y.second, -x.second * y.first); }
bool onseg(P p1, P p2, P q) {
return det(p1 - q, p2 - q) == 0 && dot(p1 - q, p2 - q) <= 0;
}
P intersection(P p1, P p2, P q1, P q2) {
return p1 + (p2 - p1) * (det(q2 - q1, q1 - p1) / det(q2 - q1, p2 - p1));
}
bool cross(P p1, P p2, P q1, P q2) {
if (det(p1 - p2, q1 - q2) == 0)
return onseg(p1, p2, q1) || onseg(p1, p2, q2) || onseg(q1, q2, p1) ||
onseg(q1, q2, p2);
P ret = intersection(p1, p2, q1, q2);
return onseg(p1, p2, ret) && onseg(q1, q2, ret);
}
double dist(P p1, P p2, P q) {
if (dot(q - p1, p2 - p1) <= 0)
return sqrt(dot(q - p1, q - p1));
if (dot(q - p2, p1 - p2) <= 0)
return sqrt(dot(q - p2, q - p2));
P d = p1 - p2;
P ret = q + P{d.second, -d.first};
P h = intersection(p1, p2, q, ret);
return sqrt(dot(q - h, q - h));
}
double d(P p, P q) { return sqrt(dot(p - q, p - q)); }
int main() {
int n;
while (cin >> n, n != 0) {
P a[n];
rep(i, n) cin >> a[i].first >> a[i].second;
int ans = 0;
rep(i, n) rep(j, n) {
if (i == j)
continue;
if (d(a[i], a[j]) > 2)
continue;
P v = (a[i] - a[j]) * (1.0 / d(a[i], a[j]));
P h = P{v.second, -v.first};
P c = (a[i] + a[j]) * (1.0 / 2) +
h * sqrt(1.0 - dot(a[i] - a[j], a[i] - a[j]) / 4);
int ret = 2;
rep(k, n) {
if (k == i || k == j)
continue;
if (d(a[k], c) <= 1)
ret++;
}
ans = max(ans, ret);
c = (a[i] + a[j]) * (1.0 / 2) -
h * sqrt(1.0 - dot(a[i] - a[j], a[i] - a[j]) / 4);
ret = 2;
rep(k, n) {
if (k == i || k == j)
continue;
if (d(a[k], c) <= 1)
ret++;
}
ans = max(ans, ret);
}
cout << ans << endl;
}
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define rep(i, n) REP(i, 0, n)
typedef long long ll;
typedef pair<int, int> pint;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const double eps = 1e-10;
double add(double a, double b) {
if (abs(a + b) < eps * (abs(a) + abs(b)))
return 0;
return a + b;
}
typedef pair<double, double> P;
P operator+(const P &x, const P &y) {
return {add(x.first, y.first), add(x.second, y.second)};
}
P operator-(const P &x, const P &y) {
return {add(x.first, -y.first), add(x.second, -y.second)};
}
P operator*(const P &x, const double &y) { return {x.first * y, x.second * y}; }
double dot(P x, P y) { return add(x.first * y.first, x.second * y.second); }
double det(P x, P y) { return add(x.first * y.second, -x.second * y.first); }
bool onseg(P p1, P p2, P q) {
return det(p1 - q, p2 - q) == 0 && dot(p1 - q, p2 - q) <= 0;
}
P intersection(P p1, P p2, P q1, P q2) {
return p1 + (p2 - p1) * (det(q2 - q1, q1 - p1) / det(q2 - q1, p2 - p1));
}
bool cross(P p1, P p2, P q1, P q2) {
if (det(p1 - p2, q1 - q2) == 0)
return onseg(p1, p2, q1) || onseg(p1, p2, q2) || onseg(q1, q2, p1) ||
onseg(q1, q2, p2);
P ret = intersection(p1, p2, q1, q2);
return onseg(p1, p2, ret) && onseg(q1, q2, ret);
}
double dist(P p1, P p2, P q) {
if (dot(q - p1, p2 - p1) <= 0)
return sqrt(dot(q - p1, q - p1));
if (dot(q - p2, p1 - p2) <= 0)
return sqrt(dot(q - p2, q - p2));
P d = p1 - p2;
P ret = q + P{d.second, -d.first};
P h = intersection(p1, p2, q, ret);
return sqrt(dot(q - h, q - h));
}
double d(P p, P q) { return sqrt(dot(p - q, p - q)); }
int main() {
int n;
while (cin >> n, n != 0) {
P a[n];
rep(i, n) cin >> a[i].first >> a[i].second;
int ans = 1;
rep(i, n) rep(j, n) {
if (i == j)
continue;
if (d(a[i], a[j]) > 2)
continue;
P v = (a[i] - a[j]) * (1.0 / d(a[i], a[j]));
P h = P{v.second, -v.first};
P c = (a[i] + a[j]) * (1.0 / 2) +
h * sqrt(1.0 - dot(a[i] - a[j], a[i] - a[j]) / 4);
int ret = 2;
rep(k, n) {
if (k == i || k == j)
continue;
if (d(a[k], c) <= 1)
ret++;
}
ans = max(ans, ret);
c = (a[i] + a[j]) * (1.0 / 2) -
h * sqrt(1.0 - dot(a[i] - a[j], a[i] - a[j]) / 4);
ret = 2;
rep(k, n) {
if (k == i || k == j)
continue;
if (d(a[k], c) <= 1)
ret++;
}
ans = max(ans, ret);
}
cout << ans << endl;
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
| 1
| 1,055
|
#include <complex>
#include <iostream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define EPS 1e-8
using namespace std;
typedef complex<double> P;
int main() {
int n;
double x, y;
while (cin >> n, n) {
P p[n];
rep(i, n) cin >> x >> y, p[i] = P(x, y);
int mx = 0, m1, m2;
rep(i, n) rep(j, i) if (norm(p[i] - p[j]) < 4 + EPS) {
P M = (p[i] + p[j]) / P(2, 0), C1, C2;
double l = sqrt(1 - norm(M - p[i]));
C1 = M + polar(l, arg(p[j] - p[i]) + M_PI / 2);
C2 = M + polar(l, arg(p[j] - p[i]) - M_PI / 2);
m1 = m2 = 0;
rep(k, n) {
if (norm(p[k] - C1) < 1 + EPS)
m1++;
if (norm(p[k] - C2) < 1 + EPS)
m2++;
}
if (m1 > mx)
mx = m1;
if (m2 > mx)
mx = m2;
}
cout << mx << endl;
}
return 0;
}
|
#include <complex>
#include <iostream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define EPS 1e-8
using namespace std;
typedef complex<double> P;
int main() {
int n;
double x, y;
while (cin >> n, n) {
P p[n];
rep(i, n) cin >> x >> y, p[i] = P(x, y);
int mx = 1, m1, m2;
rep(i, n) rep(j, i) if (norm(p[i] - p[j]) < 4 + EPS) {
P M = (p[i] + p[j]) / P(2, 0), C1, C2;
double l = sqrt(1 - norm(M - p[i]));
C1 = M + polar(l, arg(p[j] - p[i]) + M_PI / 2);
C2 = M + polar(l, arg(p[j] - p[i]) - M_PI / 2);
m1 = m2 = 0;
rep(k, n) {
if (norm(p[k] - C1) < 1 + EPS)
m1++;
if (norm(p[k] - C2) < 1 + EPS)
m2++;
}
if (m1 > mx)
mx = m1;
if (m2 > mx)
mx = m2;
}
cout << mx << endl;
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
| 1
| 302
|
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
typedef complex<double> coor;
#define EPS 1e-5
double in_cir(coor o, coor x) { return abs(x - o); }
int search(vector<coor> P) {
int mx = 0;
/*for (int i = 0; i < P.size(); i++) {
printf("%lf, %lf\n", P[i].real(), P[i].imag());
}*/
for (int i = 0; i < P.size(); i++) {
for (int j = i + 1; j < P.size(); j++) {
for (int k = 0; k < 2; k++) {
if (abs(P[i] - P[j]) - 2.0 > -EPS) {
continue;
}
coor d = coor(P[i].imag() - P[j].imag(), -(P[i].real() - P[j].real()));
if (k == 1) {
d = -d;
}
d /= abs(d);
d *= sqrt(1 - norm(P[i] - P[j]) / 4);
// printf("abs(d) = %lf\n", abs(d));
d += (P[i] + P[j]) / 2.0;
// printf("%lf, %lf\n", d.real(), d.imag());
int ctr = 2;
for (int l = 0; l < P.size(); l++) {
// printf("%lf\n", in_cir(d, P[l]));
if (l == i || l == j) {
continue;
}
if (in_cir(d, P[l]) - 1.0 < -EPS) {
ctr++;
}
}
// printf("_%d\n", ctr);
mx = max(ctr, mx);
}
}
}
return mx;
}
int main() {
int N;
while (scanf("%d ", &N) == 1) {
if (N == 0) {
break;
}
vector<coor> P(N);
for (int i = 0; i < N; i++) {
double x, y;
scanf("%lf %lf ", &x, &y);
P[i] = coor(x, y);
}
printf("%d\n", search(P));
}
return 0;
}
|
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
typedef complex<double> coor;
#define EPS 1e-5
double in_cir(coor o, coor x) { return abs(x - o); }
int search(vector<coor> P) {
int mx = 1;
/*for (int i = 0; i < P.size(); i++) {
printf("%lf, %lf\n", P[i].real(), P[i].imag());
}*/
for (int i = 0; i < P.size(); i++) {
for (int j = i + 1; j < P.size(); j++) {
for (int k = 0; k < 2; k++) {
if (abs(P[i] - P[j]) - 2.0 > -EPS) {
continue;
}
coor d = coor(P[i].imag() - P[j].imag(), -(P[i].real() - P[j].real()));
if (k == 1) {
d = -d;
}
d /= abs(d);
d *= sqrt(1 - norm(P[i] - P[j]) / 4);
// printf("abs(d) = %lf\n", abs(d));
d += (P[i] + P[j]) / 2.0;
// printf("%lf, %lf\n", d.real(), d.imag());
int ctr = 2;
for (int l = 0; l < P.size(); l++) {
// printf("%lf\n", in_cir(d, P[l]));
if (l == i || l == j) {
continue;
}
if (in_cir(d, P[l]) - 1.0 < -EPS) {
ctr++;
}
}
// printf("_%d\n", ctr);
mx = max(ctr, mx);
}
}
}
return mx;
}
int main() {
int N;
while (scanf("%d ", &N) == 1) {
if (N == 0) {
break;
}
vector<coor> P(N);
for (int i = 0; i < N; i++) {
double x, y;
scanf("%lf %lf ", &x, &y);
P[i] = coor(x, y);
}
printf("%d\n", search(P));
}
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13]]
| 1
| 428
|
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
typedef complex<double> P;
const double EPS = 1e-8;
int main() {
int n;
while (cin >> n, n) {
vector<P> v;
REP(i, n) {
double x, y;
cin >> x >> y;
v.push_back(P(x, y));
}
int ans = 0;
REP(i, n - 1) {
for (int j = i + 1; j < n; j++) {
P m = (v[i] + v[j]) * P(0.5, 0);
// cout << "m "<< m << endl;
P a = v[i] - v[j];
double dis = abs(a);
if (1 - dis * dis / 4 < 0)
continue;
double d = sqrt(1 - dis * dis / 4);
int hoge[] = {1, -1};
REP(k, 2) {
P un = (a * P(0, hoge[k])) / dis;
P o1 = m + un * d;
// cout << o1 << endl;
int sum = 0;
REP(l, n) {
if (norm(v[l] - o1) < 1 + EPS)
sum++;
}
ans = max(ans, sum);
}
}
}
cout << ans << endl;
}
}
|
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
typedef complex<double> P;
const double EPS = 1e-8;
int main() {
int n;
while (cin >> n, n) {
vector<P> v;
REP(i, n) {
double x, y;
cin >> x >> y;
v.push_back(P(x, y));
}
int ans = 1;
REP(i, n - 1) {
for (int j = i + 1; j < n; j++) {
P m = (v[i] + v[j]) * P(0.5, 0);
// cout << "m "<< m << endl;
P a = v[i] - v[j];
double dis = abs(a);
if (1 - dis * dis / 4 < 0)
continue;
double d = sqrt(1 - dis * dis / 4);
int hoge[] = {1, -1};
REP(k, 2) {
P un = (a * P(0, hoge[k])) / dis;
P o1 = m + un * d;
// cout << o1 << endl;
int sum = 0;
REP(l, n) {
if (norm(v[l] - o1) < 1 + EPS)
sum++;
}
ans = max(ans, sum);
}
}
}
cout << ans << endl;
}
}
|
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
| 1
| 312
|
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
//eÍÍÌë·
// 1 * 10^(-5)
#define EPS (1e-8)
int n;
pair<double, double> p[301];
int main() {
while (1) {
cin >> n;
if (n == 0)
break;
for (int i = 0; i < n; i++) {
cin >> p[i].first >> p[i].second;
}
int maxPoints = 1;
// 2_ð~üãÉÂ~ðè
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
double d = hypot(p[i].first - p[j].first, p[i].second - p[j].second);
if (d > 2.0 + EPS)
continue; //£ê·¬
//_(»ê¼êÌÀW̽Ï)
pair<double, double> m((p[i].first + p[j].first) / 2.0,
(p[i].second + p[j].second) / 2.0);
//PÊ@üxNg
// @üxNgÌX«Íüªp[i]p[j]Æ|¯Ä-1C·Èí¿
// v = (p[j].first - p[i].first, p[j].second - p[i].second)
// ±êÌ·³Ívx^2 + vy^2 = d^2
// æÁÄPÊxNgÉ·éÉÍ
// (vx/d)^2 + (vy/d)^2 = 1
pair<double, double> ve((p[j].first - p[i].first) / d,
(p[j].second - p[i].second) / d);
//_©çSÜÅÌ£
double l = sqrt(1.0 - d * d / 4.0);
//_2©çèÜé~Í2Â
for (int s = -1; s < 2; s += 2) { //
pair<double, double> c(m.first + s * l * ve.first,
m.second - s * l * ve.second);
int count = 2;
for (int k = 0; k < n; k++) {
if (k == i || k == j)
continue; //¯êÌ_ÍÜßÈ¢
if (hypot(c.first - p[k].first, c.second - p[k].second) < 1.0 + EPS)
count++;
}
maxPoints = max(maxPoints, count);
}
}
}
cout << maxPoints << endl;
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
//eÍÍÌë·
// 1 * 10^(-5)
#define EPS (1e-8)
int n;
pair<double, double> p[301];
int main() {
while (1) {
cin >> n;
if (n == 0)
break;
for (int i = 0; i < n; i++) {
cin >> p[i].first >> p[i].second;
}
int maxPoints = 1;
// 2_ð~üãÉÂ~ðè
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
double d = hypot(p[i].first - p[j].first, p[i].second - p[j].second);
if (d > 2.0 + EPS)
continue; //£ê·¬
//_(»ê¼êÌÀW̽Ï)
pair<double, double> m((p[i].first + p[j].first) / 2.0,
(p[i].second + p[j].second) / 2.0);
//PÊ@üxNg
// @üxNgÌX«Íüªp[i]p[j]Æ|¯Ä-1C·Èí¿
// v = (p[j].second - p[i].second, p[j].first - p[i].first)
// ±êÌ·³Ívx^2 + vy^2 = d^2
// æÁÄPÊxNgÉ·éÉÍ
// (vx/d)^2 + (vy/d)^2 = 1
pair<double, double> ve((p[j].second - p[i].second) / d,
(p[j].first - p[i].first) / d);
//_©çSÜÅÌ£
double l = sqrt(1.0 - d * d / 4.0);
//_2©çèÜé~Í2Â
for (int s = -1; s < 2; s += 2) { //
pair<double, double> c(m.first + s * l * ve.first,
m.second - s * l * ve.second);
int count = 2;
for (int k = 0; k < n; k++) {
if (k == i || k == j)
continue; //¯êÌ_ÍÜßÈ¢
if (hypot(c.first - p[k].first, c.second - p[k].second) < 1.0 + EPS)
count++;
}
maxPoints = max(maxPoints, count);
}
}
}
cout << maxPoints << endl;
}
return 0;
}
|
[["-", 0, 16, 31, 23, 0, 16, 31, 118, 119, 120], ["+", 0, 16, 31, 23, 0, 16, 31, 118, 119, 120], ["-", 0, 16, 31, 23, 0, 16, 12, 118, 119, 120], ["+", 0, 16, 31, 23, 0, 16, 12, 118, 119, 120]]
| 1
| 420
|
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int, int> PI;
typedef vector<int> vi;
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define F first
#define S second
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
main() {
int n;
while (cin >> n, n) {
double x[n], y[n];
rep(i, n) cin >> x[i] >> y[i];
int ans = 0;
rep(i, n) {
rep(j, i) {
double sx, sy;
double tx = x[i] - x[j], ty = y[i] - y[j];
double len = sqrt(tx * tx + ty * ty);
if (len > 2)
continue;
len = sqrt(1 - len * len / 4);
double theta = atan2(ty, tx) + M_PI / 2;
int tans = 0;
sx = (x[i] + x[j]) / 2 + cos(theta) * len;
sy = (y[i] + y[j]) / 2 + sin(theta) * len;
rep(k, n) {
tx = sx - x[k];
ty = sy - y[k];
if (tx * tx + ty * ty <= 1 + EPS)
++tans;
}
ans = max(ans, tans);
tans = 0;
sx = (x[i] + x[j]) / 2 - cos(theta) * len;
sy = (y[i] + y[j]) / 2 - sin(theta) * len;
rep(k, n) {
tx = sx - x[k];
ty = sy - y[k];
if (tx * tx + ty * ty <= 1 + EPS)
++tans;
}
ans = max(ans, tans);
}
}
cout << ans << endl;
}
}
|
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int, int> PI;
typedef vector<int> vi;
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define F first
#define S second
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
main() {
int n;
while (cin >> n, n) {
double x[n], y[n];
rep(i, n) cin >> x[i] >> y[i];
int ans = 1;
rep(i, n) {
rep(j, i) {
double sx, sy;
double tx = x[i] - x[j], ty = y[i] - y[j];
double len = sqrt(tx * tx + ty * ty);
if (len > 2)
continue;
len = sqrt(1 - len * len / 4);
double theta = atan2(ty, tx) + M_PI / 2;
int tans = 0;
sx = (x[i] + x[j]) / 2 + cos(theta) * len;
sy = (y[i] + y[j]) / 2 + sin(theta) * len;
rep(k, n) {
tx = sx - x[k];
ty = sy - y[k];
if (tx * tx + ty * ty <= 1 + EPS)
++tans;
}
ans = max(ans, tans);
tans = 0;
sx = (x[i] + x[j]) / 2 - cos(theta) * len;
sy = (y[i] + y[j]) / 2 - sin(theta) * len;
rep(k, n) {
tx = sx - x[k];
ty = sy - y[k];
if (tx * tx + ty * ty <= 1 + EPS)
++tans;
}
ans = max(ans, tans);
}
}
cout << ans << endl;
}
}
|
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
| 1
| 512
|
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
using namespace std;
const double EPS = 1e-8;
typedef complex<double> Point;
int calc(Point p, vector<Point> &ps) {
int ans = 0;
for (int i = 0; i < ps.size(); i++) {
if (abs(ps[i] - p) < 1.0 + EPS) {
ans++;
}
}
return ans;
}
vector<Point> touching_circle(Point a, Point b, double r) {
vector<Point> res;
double d = abs(b - a);
if (d > 2 * r)
return res;
Point mid = 0.5 * (a + b);
Point dir = polar(sqrt(r * r - d * d / 4), arg(b - a) + M_PI / 2);
res.push_back(mid + dir);
res.push_back(mid - dir);
return res;
}
int main() {
int N;
while (cin >> N && N) {
vector<Point> ps(N);
REP(i, N) {
double x, y;
cin >> x >> y;
ps[i] = Point(x, y);
}
int ans = 0;
REP(i, N) REP(j, N) if (abs(ps[i] - ps[j]) > EPS) {
vector<Point> tp = touching_circle(ps[i], ps[j], 1.0);
for (Point c : tp) {
ans = max(ans, calc(c, ps));
}
}
cout << ans << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
using namespace std;
const double EPS = 1e-8;
typedef complex<double> Point;
int calc(Point p, vector<Point> &ps) {
int ans = 0;
for (int i = 0; i < ps.size(); i++) {
if (abs(ps[i] - p) < 1.0 + EPS) {
ans++;
}
}
return ans;
}
vector<Point> touching_circle(Point a, Point b, double r) {
vector<Point> res;
double d = abs(b - a);
if (d > 2 * r)
return res;
Point mid = 0.5 * (a + b);
Point dir = polar(sqrt(r * r - d * d / 4), arg(b - a) + M_PI / 2);
res.push_back(mid + dir);
res.push_back(mid - dir);
return res;
}
int main() {
int N;
while (cin >> N && N) {
vector<Point> ps(N);
REP(i, N) {
double x, y;
cin >> x >> y;
ps[i] = Point(x, y);
}
int ans = 1;
REP(i, N) REP(j, N) if (abs(ps[i] - ps[j]) > EPS) {
vector<Point> tp = touching_circle(ps[i], ps[j], 1.0);
for (Point c : tp) {
ans = max(ans, calc(c, ps));
}
}
cout << ans << endl;
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
| 1
| 347
|
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
using namespace std;
#define X real()
#define Y imag()
typedef double D;
D EPS = 1e-8;
typedef complex<D> P;
struct L {
P a, b;
P vec() { return b - a; }
};
typedef vector<P> Pol;
int sig(D a) { return a < -EPS ? -1 : a > EPS ? 1 : 0; }
D dot(P a, P b) { return a.X * b.X + a.Y * b.Y; }
D cross(P a, P b) { return a.X * b.Y - a.Y * b.X; }
D area(Pol pol) {
int n = pol.size();
D res = 0;
REP(i, n) { res += cross(pol[i], pol[(i + 1) % n]); }
return abs(res) / 2.0;
}
// 2点a, bを通る半径rの円の中心
vector<P> tc2(P a, P b, D r) {
vector<P> res;
D d = abs(b - a);
if (sig(d - 2 * r) > 0)
return res;
P mid = 0.5 * (a + b);
P dir = polar(sqrt(r * r - d * d / 4), arg(b - a) + M_PI / 2);
res.push_back(mid + dir);
res.push_back(mid - dir);
return res;
}
int main() {
int N;
while (cin >> N && N > 0) {
vector<P> ps(N);
REP(i, N) {
D x, y;
cin >> x >> y;
ps[i] = P(x, y);
}
int ans = 0;
REP(i, N) REP(j, N) if (i != j) {
vector<P> cv = tc2(ps[i], ps[j], 1.0);
for (auto c : cv) {
int sum = 0;
REP(k, N) {
if (sig(abs(c - ps[k]) - 1.0) <= 0) {
sum++;
}
}
ans = max(ans, sum);
}
}
cout << ans << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
using namespace std;
#define X real()
#define Y imag()
typedef double D;
D EPS = 1e-8;
typedef complex<D> P;
struct L {
P a, b;
P vec() { return b - a; }
};
typedef vector<P> Pol;
int sig(D a) { return a < -EPS ? -1 : a > EPS ? 1 : 0; }
D dot(P a, P b) { return a.X * b.X + a.Y * b.Y; }
D cross(P a, P b) { return a.X * b.Y - a.Y * b.X; }
D area(Pol pol) {
int n = pol.size();
D res = 0;
REP(i, n) { res += cross(pol[i], pol[(i + 1) % n]); }
return abs(res) / 2.0;
}
// 2点a, bを通る半径rの円の中心
vector<P> tc2(P a, P b, D r) {
vector<P> res;
D d = abs(b - a);
if (sig(d - 2 * r) > 0)
return res;
P mid = 0.5 * (a + b);
P dir = polar(sqrt(r * r - d * d / 4), arg(b - a) + M_PI / 2);
res.push_back(mid + dir);
res.push_back(mid - dir);
return res;
}
int main() {
int N;
while (cin >> N && N > 0) {
vector<P> ps(N);
REP(i, N) {
D x, y;
cin >> x >> y;
ps[i] = P(x, y);
}
int ans = 1;
REP(i, N) REP(j, N) if (i != j) {
vector<P> cv = tc2(ps[i], ps[j], 1.0);
for (auto c : cv) {
int sum = 0;
REP(k, N) {
if (sig(abs(c - ps[k]) - 1.0) <= 0) {
sum++;
}
}
ans = max(ans, sum);
}
}
cout << ans << endl;
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
| 1
| 488
|
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <vector>
using namespace std;
typedef double Num;
typedef complex<Num> Pt2;
struct Circle2 {
Pt2 p;
Num r;
Circle2(Pt2 p, Num r) : p(p), r(r) {}
};
const double eps = 1e-10;
const double pi = 3.14159265358979323846;
Pt2 ortho(Pt2 v) { return v * Pt2(0, 1); }
Pt2 unit(Pt2 v) { return v / abs(v); }
vector<Circle2> make_circle(Pt2 a, Pt2 b, Num r) {
Num d = abs(b - a) / 2.0;
d = sqrt(r * r - d * d); // assert(r*r-d*d >= 0)
Pt2 p = (b + a) / 2.0;
Pt2 v = unit(ortho(b - a)) * d;
vector<Circle2> ret;
ret.push_back(Circle2(p + v, r));
ret.push_back(Circle2(p - v, r));
return ret;
}
bool into_circle(Circle2 p, Pt2 a) {
return abs(a - p.p) * abs(a - p.p) < p.r * p.r + eps;
}
int main() {
int N;
while (cin >> N, N) {
Pt2 ps[300];
for (int i = 0; i < N; i++) {
Num x, y;
cin >> x >> y;
ps[i] = Pt2(x, y);
}
int ans = 0;
for (int i = 0; i < N; i++)
for (int j = i + 1; j < N; j++) {
if (abs(ps[i] - ps[j]) > 2.0)
continue;
vector<Circle2> cs = make_circle(ps[i], ps[j], 1.0);
for (int k = 0; k < 2; k++) {
int cnt = 0;
for (int l = 0; l < N; l++) {
if (into_circle(cs[k], ps[l]))
cnt++;
}
ans = max(ans, cnt);
}
}
cout << ans << endl;
}
}
|
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <vector>
using namespace std;
typedef double Num;
typedef complex<Num> Pt2;
struct Circle2 {
Pt2 p;
Num r;
Circle2(Pt2 p, Num r) : p(p), r(r) {}
};
const double eps = 1e-10;
const double pi = 3.14159265358979323846;
Pt2 ortho(Pt2 v) { return v * Pt2(0, 1); }
Pt2 unit(Pt2 v) { return v / abs(v); }
vector<Circle2> make_circle(Pt2 a, Pt2 b, Num r) {
Num d = abs(b - a) / 2.0;
d = sqrt(r * r - d * d); // assert(r*r-d*d >= 0)
Pt2 p = (b + a) / 2.0;
Pt2 v = unit(ortho(b - a)) * d;
vector<Circle2> ret;
ret.push_back(Circle2(p + v, r));
ret.push_back(Circle2(p - v, r));
return ret;
}
bool into_circle(Circle2 p, Pt2 a) {
return abs(a - p.p) * abs(a - p.p) < p.r * p.r + eps;
}
int main() {
int N;
while (cin >> N, N) {
Pt2 ps[300];
for (int i = 0; i < N; i++) {
Num x, y;
cin >> x >> y;
ps[i] = Pt2(x, y);
}
int ans = 1;
for (int i = 0; i < N; i++)
for (int j = i + 1; j < N; j++) {
if (abs(ps[i] - ps[j]) > 2.0)
continue;
vector<Circle2> cs = make_circle(ps[i], ps[j], 1.0);
for (int k = 0; k < 2; k++) {
int cnt = 0;
for (int l = 0; l < N; l++) {
if (into_circle(cs[k], ps[l]))
cnt++;
}
ans = max(ans, cnt);
}
}
cout << ans << endl;
}
}
|
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
| 1
| 459
|
#include <algorithm>/*{{{*/
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
static const double PI(3.14159265358979323846);
static const double EPS(1e-10);
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef complex<double> P;
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();
}
#define FOR(i, b, e) for (typeof(b) i = (b); assert((i) <= (e)), i != (e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define OPOVER(_op, _type) inline bool operator _op(const _type &t) const
#define arrsz(a) (sizeof(a) / sizeof(a[0]))
#define F first
#define S second
#define MP(a, b) make_pair(a, b)
#define SZ(a) ((ll)a.size())
#define PB(e) push_back(e)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(t, i, c) for (t::iterator i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define BIT(n) (1ULL << (n))
#define BITOF(n, m) ((n) >> (m)&1)
#define RANGE(a, b, c) ((a) <= (b) && (b) <= (c))
#define DEBUG_ON
#ifdef DEBUG_ON
#define dprt(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__)
#define darr(a) \
copy((a), (a) + arrsz(a), ostream_iterator<int>(cerr, " ")); \
cerr << endl
#define darr_range(a, f, t) \
copy((a) + (f), (a) + (t), ostream_iterator<int>(cerr, " ")); \
cerr << endl
#define dvec(v) \
copy(ALL(v), ostream_iterator<int>(cerr, " ")); \
cerr << endl
#define darr2(a, n, m) \
FOR(i, 0, (n)) { darr_range((a)[i], 0, (m)); }
#define dvec2(v) \
FOR(i, 0, SZ(v)) { dvec((v)[i]); }
#define WAIT() \
{ \
string _wait_; \
cerr << "(hit return to continue)" << endl; \
getline(cin, _wait_); \
}
#else
#define dprt(fmt, ...)
#define darr(a)
#define darr_range(a, f, t)
#define dvec(v)
#define darr2(a, n, m)
#define dvec2(v)
#define WAIT()
#endif
/*}}}*/
int N;
vector<P> points;
P middle_point(P a, P b) { return a + (b - a) / 2.0; }
// 点pを中心としてr(radian)回転 p(0,0)で原点を中心として回転
P rotate(P t, P p, double r) {
// double r=radians(angle);
return (t - p) * P(cos(r), sin(r)) + p;
}
// 2円 |x-a|=raと|x-b|=rbの交点計算
bool intersection_c_c(P a, double ra, P b, double rb, P ans[]) {
double di = abs(a - b);
if (di > ra + rb || di < abs(ra - rb))
return false;
double t = (ra * ra - rb * rb + di * di) / (di + di);
double rd = acos(t / ra);
P dv = (b - a) / abs(b - a);
P g1 = rotate(dv, P(0, 0), rd);
P g2 = rotate(dv, P(0, 0), -rd);
ans[0] = a + g1 * ra;
ans[1] = a + g2 * ra;
return true;
}
int main(int argc, char const *argv[]) {
while (cin >> N, N) {
int ans = 0;
points.clear();
REP(i, N) {
double x, y;
cin >> x >> y;
points.PB(P(x, y));
}
REP(i, N) {
FOR(j, i + 1, N) {
P p1 = points[i], p2 = points[j];
dprt("(%lf, %lf) and (%lf, %lf)\n", p1.real(), p1.imag(), p2.real(),
p2.imag());
P centers[2];
if (intersection_c_c(p1, 1, p2, 1, centers)) {
REP(k, 2) {
dprt(" center: (%lf, %lf)\n", centers[k].real(), centers[k].imag());
int cnt = 0;
REP(l, N) {
if (abs(centers[k] - points[l]) < 1.0 + EPS) {
++cnt;
}
}
ans = max(ans, cnt);
}
}
}
}
cout << ans << endl;
}
return 0;
}
|
#include <algorithm>/*{{{*/
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
static const double PI(3.14159265358979323846);
static const double EPS(1e-10);
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef complex<double> P;
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();
}
#define FOR(i, b, e) for (typeof(b) i = (b); assert((i) <= (e)), i != (e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define OPOVER(_op, _type) inline bool operator _op(const _type &t) const
#define arrsz(a) (sizeof(a) / sizeof(a[0]))
#define F first
#define S second
#define MP(a, b) make_pair(a, b)
#define SZ(a) ((ll)a.size())
#define PB(e) push_back(e)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(t, i, c) for (t::iterator i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define BIT(n) (1ULL << (n))
#define BITOF(n, m) ((n) >> (m)&1)
#define RANGE(a, b, c) ((a) <= (b) && (b) <= (c))
#define DEBUG_ON_
#ifdef DEBUG_ON
#define dprt(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__)
#define darr(a) \
copy((a), (a) + arrsz(a), ostream_iterator<int>(cerr, " ")); \
cerr << endl
#define darr_range(a, f, t) \
copy((a) + (f), (a) + (t), ostream_iterator<int>(cerr, " ")); \
cerr << endl
#define dvec(v) \
copy(ALL(v), ostream_iterator<int>(cerr, " ")); \
cerr << endl
#define darr2(a, n, m) \
FOR(i, 0, (n)) { darr_range((a)[i], 0, (m)); }
#define dvec2(v) \
FOR(i, 0, SZ(v)) { dvec((v)[i]); }
#define WAIT() \
{ \
string _wait_; \
cerr << "(hit return to continue)" << endl; \
getline(cin, _wait_); \
}
#else
#define dprt(fmt, ...)
#define darr(a)
#define darr_range(a, f, t)
#define dvec(v)
#define darr2(a, n, m)
#define dvec2(v)
#define WAIT()
#endif
/*}}}*/
int N;
vector<P> points;
P middle_point(P a, P b) { return a + (b - a) / 2.0; }
// 点pを中心としてr(radian)回転 p(0,0)で原点を中心として回転
P rotate(P t, P p, double r) {
// double r=radians(angle);
return (t - p) * P(cos(r), sin(r)) + p;
}
// 2円 |x-a|=raと|x-b|=rbの交点計算
bool intersection_c_c(P a, double ra, P b, double rb, P ans[]) {
double di = abs(a - b);
if (di > ra + rb || di < abs(ra - rb))
return false;
double t = (ra * ra - rb * rb + di * di) / (di + di);
double rd = acos(t / ra);
P dv = (b - a) / abs(b - a);
P g1 = rotate(dv, P(0, 0), rd);
P g2 = rotate(dv, P(0, 0), -rd);
ans[0] = a + g1 * ra;
ans[1] = a + g2 * ra;
return true;
}
int main(int argc, char const *argv[]) {
while (cin >> N, N) {
int ans = 1;
points.clear();
REP(i, N) {
double x, y;
cin >> x >> y;
points.PB(P(x, y));
}
REP(i, N) {
FOR(j, i + 1, N) {
P p1 = points[i], p2 = points[j];
dprt("(%lf, %lf) and (%lf, %lf)\n", p1.real(), p1.imag(), p2.real(),
p2.imag());
P centers[2];
if (intersection_c_c(p1, 1, p2, 1, centers)) {
REP(k, 2) {
dprt(" center: (%lf, %lf)\n", centers[k].real(), centers[k].imag());
int cnt = 0;
REP(l, N) {
if (abs(centers[k] - points[l]) < 1.0 + EPS) {
++cnt;
}
}
ans = max(ans, cnt);
}
}
}
}
cout << ans << endl;
}
return 0;
}
|
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 141, 22], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 141, 22], ["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
| 1
| 872
|
#include <cmath>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
typedef pair<double, double> pos;
const double r = 1;
const double eps = 0.0001;
int count(vector<pos> ps, double x, double y, int ban1, int ban2) {
int c = 0; // 2;
for (int i = 0; i < ps.size(); i++) {
if ( // i!=ban1&&i!=ban2&&
pow(ps[i].first - x, 2) + pow(ps[i].second - y, 2) <=
pow(1.0 + eps, 2)) {
c++;
}
}
return c;
}
bool range(pos p1, pos p2, double r) {
return pow(p1.first - p2.first, 2) + pow(p1.second - p2.second, 2) <= r * r;
}
double len(pos p) { return sqrt(pow(p.first, 2) + pow(p.second, 2)); }
double len2(pos p) { return (pow(p.first, 2) + pow(p.second, 2)); }
vector<pos> point2(pos p1, pos p2) {
pos m = make_pair((p1.first + p2.first) / 2, (p1.second + p2.second) / 2);
pos vec = make_pair(p1.first - p2.first, p1.second - p2.second);
pos q = m; // make_pair(p2.first+vec.first/2,p2.second+vec.second/2);
double l = sqrt(1 - pow(len(vec) / 2.0, 2));
double ll = len(vec);
pos vec2 = make_pair(-vec.second, vec.first);
vec2.first = vec2.first / ll * l;
vec2.second = vec2.second / ll * l;
vector<pos> ret;
ret.push_back(make_pair(q.first + vec2.first, q.second + vec2.second));
ret.push_back(make_pair(q.first - vec2.first, q.second - vec2.second));
return ret;
}
int solve(vector<pos> ps) {
int mx = 0;
for (int i = 0; i < ps.size() - 1; i++)
for (int k = i + 1; k < ps.size(); k++) {
if (range(ps[i], ps[k], 2)) {
// cerr << "*****" << i << " " << k << endl;
vector<pos> vp = point2(ps[i], ps[k]);
mx = max(mx, count(ps, vp[0].first, vp[0].second, i, k));
mx = max(mx, count(ps, vp[1].first, vp[1].second, i, k));
}
}
return mx;
}
int main() {
// cerr << point2(make_pair(0,0),make_pair(1,1))[1].first << endl;
while (true) {
int n;
vector<pos> v;
cin >> n;
if (n == 0)
return 0;
for (int i = 0; i < n; i++) {
double x, y;
cin >> x >> y;
v.push_back(make_pair(x, y));
}
cout << solve(v) << endl;
}
}
|
#include <cmath>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
typedef pair<double, double> pos;
const double r = 1;
const double eps = 0.0000000001;
int count(vector<pos> ps, double x, double y, int ban1, int ban2) {
int c = 0; // 2;
for (int i = 0; i < ps.size(); i++) {
if ( // i!=ban1&&i!=ban2&&
pow(ps[i].first - x, 2) + pow(ps[i].second - y, 2) <=
pow(1.0 + eps, 2)) {
c++;
}
}
return c;
}
bool range(pos p1, pos p2, double r) {
return pow(p1.first - p2.first, 2) + pow(p1.second - p2.second, 2) <= r * r;
}
double len(pos p) { return sqrt(pow(p.first, 2) + pow(p.second, 2)); }
double len2(pos p) { return (pow(p.first, 2) + pow(p.second, 2)); }
vector<pos> point2(pos p1, pos p2) {
pos m = make_pair((p1.first + p2.first) / 2, (p1.second + p2.second) / 2);
pos vec = make_pair(p1.first - p2.first, p1.second - p2.second);
pos q = m; // make_pair(p2.first+vec.first/2,p2.second+vec.second/2);
double l = sqrt(1 - pow(len(vec) / 2.0, 2));
double ll = len(vec);
pos vec2 = make_pair(-vec.second, vec.first);
vec2.first = vec2.first / ll * l;
vec2.second = vec2.second / ll * l;
vector<pos> ret;
ret.push_back(make_pair(q.first + vec2.first, q.second + vec2.second));
ret.push_back(make_pair(q.first - vec2.first, q.second - vec2.second));
return ret;
}
int solve(vector<pos> ps) {
int mx = 1;
for (int i = 0; i < ps.size() - 1; i++)
for (int k = i + 1; k < ps.size(); k++) {
if (range(ps[i], ps[k], 2)) {
// cerr << "*****" << i << " " << k << endl;
vector<pos> vp = point2(ps[i], ps[k]);
mx = max(mx, count(ps, vp[0].first, vp[0].second, i, k));
mx = max(mx, count(ps, vp[1].first, vp[1].second, i, k));
}
}
return mx;
}
int main() {
// cerr << point2(make_pair(0,0),make_pair(1,1))[1].first << endl;
while (true) {
int n;
vector<pos> v;
cin >> n;
if (n == 0)
return 0;
for (int i = 0; i < n; i++) {
double x, y;
cin >> x >> y;
v.push_back(make_pair(x, y));
}
cout << solve(v) << endl;
}
}
|
[["-", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13]]
| 1
| 673
|
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define EPS 1e-10
#define PI 3.141592653589793238
// sqrtは重い
using namespace std;
typedef pair<double, double> P;
void display(complex<double> a, complex<double> b) {
cout << "(" << a.real() << "," << a.imag() << ")"
<< " "
<< "(" << b.real() << "," << b.imag() << ")" << endl;
}
int main() {
int n, ans;
double xin, yin, X;
complex<double> m;
while (cin >> n && n) {
ans = 0;
complex<double> point[n];
for (int i = 0; i < n; i++) {
cin >> xin >> yin;
point[i] = complex<double>(xin, yin);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j)
continue;
complex<double> Rr = point[i] - point[j];
if (abs(Rr) <= 2.0 + EPS) {
complex<double> UKPC, U, P1, P2;
UKPC = (point[i] + point[j]) * 0.5;
double T = sqrt(1 - norm(point[i] - point[j]) * 0.25);
UKPC = (point[i] + point[j]) * 0.5;
/* unit vector(単位べく利ゅ) */ /* T倍に拡大 90度回転 */
P1 = UKPC + (point[i] - point[j]) / abs(point[i] - point[j]) *
polar(T, PI / 2.0);
P2 = UKPC + (point[i] - point[j]) / abs(point[i] - point[j]) *
polar(T, -PI / 2.0);
// cout << "P1 = " << P1 << ", P2 = " << P2 << endl;
int cnt = 0;
complex<double> CalcP;
double Calc;
for (int k = 0; k < n; k++) {
Calc = abs(P1 - point[k]);
if (Calc < 1.0 + EPS) {
cnt++;
}
}
ans = max(ans, cnt);
cnt = 0;
for (int k = 0; k < n; k++) {
Calc = abs(P2 - point[k]);
if (fabs(Calc) < 1.0 + EPS) {
cnt++;
}
}
ans = max(ans, cnt);
}
}
}
cout << ans << endl;
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define EPS 1e-10
#define PI 3.141592653589793238
// sqrt重い
using namespace std;
typedef pair<double, double> P;
void display(complex<double> a, complex<double> b) {
cout << "(" << a.real() << "," << a.imag() << ")"
<< " "
<< "(" << b.real() << "," << b.imag() << ")" << endl;
}
int main() {
int n, ans;
double xin, yin, X;
complex<double> m;
while (cin >> n && n) {
ans = 1;
complex<double> point[n];
for (int i = 0; i < n; i++) {
cin >> xin >> yin;
point[i] = complex<double>(xin, yin);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j)
continue;
complex<double> Rr = point[i] - point[j];
if (abs(Rr) <= 2 + EPS) {
complex<double> UKPC, U, P1, P2;
UKPC = (point[i] + point[j]) * 0.5;
double T = sqrt(1 - norm(point[i] - point[j]) * 0.25);
UKPC = (point[i] + point[j]) * 0.5;
P1 = UKPC + (point[i] - point[j]) / abs(point[i] - point[j]) *
polar(T, PI / 2.0);
P2 = UKPC + (point[i] - point[j]) / abs(point[i] - point[j]) *
polar(T, -PI / 2.0);
// cout << "P1 = " << P1 << ", P2 = " << P2 << endl;
int cnt = 0;
complex<double> CalcP;
double Calc;
for (int k = 0; k < n; k++) {
Calc = abs(P1 - point[k]);
if (Calc < 1.0 + EPS) {
cnt++;
}
}
ans = max(ans, cnt);
cnt = 0;
for (int k = 0; k < n; k++) {
Calc = abs(P2 - point[k]);
if (fabs(Calc) < 1.0 + EPS) {
cnt++;
}
}
ans = max(ans, cnt);
}
}
}
cout << ans << endl;
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 31, 13], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 31, 13]]
| 1
| 549
|
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <vector>
using namespace std;
const double EPS = 1e-9;
bool tolerant_eq(double a, double b) { return abs(a - b) < EPS; }
struct Point {
double x, y;
explicit Point(const double &x = 0.0, const double &y = 0.0) : x(x), y(y) {}
static Point invalid() {
double qnan = numeric_limits<double>::quiet_NaN();
return Point(qnan, qnan);
}
bool is_valid() const { return !(isnan(x) || isnan(y)); }
Point operator+(const Point &p) const { return Point(x + p.x, y + p.y); }
Point &operator+=(const Point &p) { return *this = *this + p; }
Point operator-(const Point &p) const { return Point(x - p.x, y - p.y); }
Point &operator-=(const Point &p) { return *this = *this - p; }
Point operator*(double s) const { return Point(x * s, y * s); }
Point &operator*=(double s) { return *this = *this * s; }
Point operator/(double s) const { return Point(x / s, y / s); }
Point &operator/=(double s) { return *this = *this / s; }
bool operator==(const Point &p) const { return x == p.x && y == p.y; }
bool operator!=(const Point &p) const { return x != p.x || y != p.y; }
bool operator<(const Point &p) const {
return (x == p.x) ? (y < p.y) : (x < p.x);
}
};
Point operator*(double s, const Point &p) { return p * s; }
bool tolerant_eq(const Point &a, const Point &b) {
return tolerant_eq(a.x, b.x) && tolerant_eq(a.y, b.y);
}
double abs(const Point &p) { return sqrt(p.x * p.x + p.y * p.y); }
Point unit(const Point &p) { return p / abs(p); }
Point ortho(const Point &p) { return Point(-p.y, p.x); }
double cross(const Point &a, const Point &b) { return a.x * b.y - a.y * b.x; }
double dot(const Point &a, const Point &b) { return a.x * b.x + a.y * b.y; }
int ccw(const Point &a, const Point &b, const Point &c) {
Point d = b - a, e = c - a;
if (cross(d, e) > 0.0) {
return 1;
}
if (cross(d, e) < 0.0) {
return -1;
}
if (dot(d, e) < 0.0) {
return 2;
}
if (abs(d) < abs(e)) {
return -2;
}
return 0;
}
struct Circle {
Point c;
double r;
explicit Circle(const Point &c = Point(), double r = 0.0) : c(c), r(r) {}
static Circle invalid() {
double qnan = numeric_limits<double>::quiet_NaN();
return Circle(Point::invalid(), qnan);
}
bool is_valid() const { return c.is_valid() && !isnan(r); }
bool operator<(const Circle &i) const {
return (r == i.r) ? (c < i.c) : (r < i.r);
}
};
bool intersect(const Circle &a, const Circle &b) {
return abs(a.c - b.c) <= a.r + b.r;
}
vector<Point> crosspoint(const Circle &a, const Circle &b) {
if (!intersect(a, b)) {
return vector<Point>();
}
double l = abs(b.c - a.c), s = (l + a.r + b.r) / 2.0;
double S = sqrt(s * (s - l) * (s - a.r) * (s - b.r));
double d = (S * 2) / l, t = sqrt(a.r * a.r - d * d);
Point v = t * unit(b.c - a.c);
Point w = d * unit(ortho(v));
Point x = a.c + v + w, y = a.c + v - w;
if (tolerant_eq(x, y)) {
return vector<Point>(1, x);
}
vector<Point> ans(2);
ans[0] = x;
ans[1] = y;
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cout << setiosflags(ios::fixed) << setprecision(10);
while (true) {
int N;
cin >> N;
if (N == 0) {
break;
}
vector<Point> points(N);
for (int i = 0; i < N; ++i) {
cin >> points[i].x >> points[i].y;
}
int answer = 0;
for (int i = 0; i < N; ++i) {
Circle ci(points[i], 1.0);
for (int j = i + 1; j < N; ++j) {
Circle cj(points[j], 1.0);
if (!intersect(ci, cj)) {
continue;
}
vector<Point> cp = crosspoint(ci, cj);
for (int k = 0; k < cp.size(); ++k) {
Point c = cp[k];
int count = 0;
for (int l = 0; l < N; ++l) {
if (abs(c - points[l]) <= 1.0 + EPS) {
++count;
}
}
answer = max(answer, count);
}
}
}
cout << answer << endl;
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <vector>
using namespace std;
const double EPS = 1e-9;
bool tolerant_eq(double a, double b) { return abs(a - b) < EPS; }
struct Point {
double x, y;
explicit Point(const double &x = 0.0, const double &y = 0.0) : x(x), y(y) {}
static Point invalid() {
double qnan = numeric_limits<double>::quiet_NaN();
return Point(qnan, qnan);
}
bool is_valid() const { return !(isnan(x) || isnan(y)); }
Point operator+(const Point &p) const { return Point(x + p.x, y + p.y); }
Point &operator+=(const Point &p) { return *this = *this + p; }
Point operator-(const Point &p) const { return Point(x - p.x, y - p.y); }
Point &operator-=(const Point &p) { return *this = *this - p; }
Point operator*(double s) const { return Point(x * s, y * s); }
Point &operator*=(double s) { return *this = *this * s; }
Point operator/(double s) const { return Point(x / s, y / s); }
Point &operator/=(double s) { return *this = *this / s; }
bool operator==(const Point &p) const { return x == p.x && y == p.y; }
bool operator!=(const Point &p) const { return x != p.x || y != p.y; }
bool operator<(const Point &p) const {
return (x == p.x) ? (y < p.y) : (x < p.x);
}
};
Point operator*(double s, const Point &p) { return p * s; }
bool tolerant_eq(const Point &a, const Point &b) {
return tolerant_eq(a.x, b.x) && tolerant_eq(a.y, b.y);
}
double abs(const Point &p) { return sqrt(p.x * p.x + p.y * p.y); }
Point unit(const Point &p) { return p / abs(p); }
Point ortho(const Point &p) { return Point(-p.y, p.x); }
double cross(const Point &a, const Point &b) { return a.x * b.y - a.y * b.x; }
double dot(const Point &a, const Point &b) { return a.x * b.x + a.y * b.y; }
int ccw(const Point &a, const Point &b, const Point &c) {
Point d = b - a, e = c - a;
if (cross(d, e) > 0.0) {
return 1;
}
if (cross(d, e) < 0.0) {
return -1;
}
if (dot(d, e) < 0.0) {
return 2;
}
if (abs(d) < abs(e)) {
return -2;
}
return 0;
}
struct Circle {
Point c;
double r;
explicit Circle(const Point &c = Point(), double r = 0.0) : c(c), r(r) {}
static Circle invalid() {
double qnan = numeric_limits<double>::quiet_NaN();
return Circle(Point::invalid(), qnan);
}
bool is_valid() const { return c.is_valid() && !isnan(r); }
bool operator<(const Circle &i) const {
return (r == i.r) ? (c < i.c) : (r < i.r);
}
};
bool intersect(const Circle &a, const Circle &b) {
return abs(a.c - b.c) <= a.r + b.r;
}
vector<Point> crosspoint(const Circle &a, const Circle &b) {
if (!intersect(a, b)) {
return vector<Point>();
}
double l = abs(b.c - a.c), s = (l + a.r + b.r) / 2.0;
double S = sqrt(s * (s - l) * (s - a.r) * (s - b.r));
double d = (S * 2) / l, t = sqrt(a.r * a.r - d * d);
Point v = t * unit(b.c - a.c);
Point w = d * unit(ortho(v));
Point x = a.c + v + w, y = a.c + v - w;
if (tolerant_eq(x, y)) {
return vector<Point>(1, x);
}
vector<Point> ans(2);
ans[0] = x;
ans[1] = y;
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cout << setiosflags(ios::fixed) << setprecision(10);
while (true) {
int N;
cin >> N;
if (N == 0) {
break;
}
vector<Point> points(N);
for (int i = 0; i < N; ++i) {
cin >> points[i].x >> points[i].y;
}
int answer = 1;
for (int i = 0; i < N; ++i) {
Circle ci(points[i], 1.0);
for (int j = i + 1; j < N; ++j) {
Circle cj(points[j], 1.0);
if (!intersect(ci, cj)) {
continue;
}
vector<Point> cp = crosspoint(ci, cj);
for (int k = 0; k < cp.size(); ++k) {
Point c = cp[k];
int count = 0;
for (int l = 0; l < N; ++l) {
if (abs(c - points[l]) <= 1.0 + EPS) {
++count;
}
}
answer = max(answer, count);
}
}
}
cout << answer << endl;
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
| 1
| 1,344
|
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// conversion
//------------------------------------------
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();
}
// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef vector<LL> VLL;
// container util
//------------------------------------------
#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 MT(a, b, c) MP(a, MP(b, c))
// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
double x[300], y[300];
int n;
int count(double x0, double y0, int p, int q) {
int ret = 2;
REP(i, n) {
if (i == p || i == q)
continue;
double dx = x0 - x[i];
double dy = y0 - y[i];
if (pow(dx, 2.0) + pow(dy, 2.0) < 1.0)
ret++;
}
return ret;
}
int main() {
while (1) {
int ret = 1;
cin >> n;
if (n == 0)
break;
REP(i, n) scanf("%f %f", &x[i], &y[i]);
REP(i, n) {
FOR(j, i + 1, n) {
double dx = x[j] - x[i];
double dy = y[j] - y[i];
double d = sqrt(pow(dx, 2.0) + pow(dy, 2.0));
if (d < 2.0) {
double mx = (x[j] + x[i]) * 0.5;
double my = (y[j] + y[i]) * 0.5;
{
double x1 = mx - dy / d * sqrt(1.0 - d * d / 4.0);
double y1 = my + dx / d * sqrt(1.0 - d * d / 4.0);
ret = max(ret, count(x1, y1, i, j));
}
{
double x1 = mx + dy / d * sqrt(1.0 - d * d / 4.0);
double y1 = my - dx / d * sqrt(1.0 - d * d / 4.0);
ret = max(ret, count(x1, y1, i, j));
}
}
}
}
cout << ret << endl;
}
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// conversion
//------------------------------------------
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();
}
// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef vector<LL> VLL;
// container util
//------------------------------------------
#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 MT(a, b, c) MP(a, MP(b, c))
// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
double x[300], y[300];
int n;
int count(double x0, double y0, int p, int q) {
int ret = 2;
REP(i, n) {
if (i == p || i == q)
continue;
double dx = x0 - x[i];
double dy = y0 - y[i];
if (pow(dx, 2.0) + pow(dy, 2.0) < 1.0)
ret++;
}
return ret;
}
int main() {
while (1) {
int ret = 1;
cin >> n;
if (n == 0)
break;
REP(i, n) scanf("%lf %lf", &x[i], &y[i]);
REP(i, n) {
FOR(j, i + 1, n) {
double dx = x[j] - x[i];
double dy = y[j] - y[i];
double d = sqrt(pow(dx, 2.0) + pow(dy, 2.0));
if (d < 2.0) {
double mx = (x[j] + x[i]) * 0.5;
double my = (y[j] + y[i]) * 0.5;
{
double x1 = mx - dy / d * sqrt(1.0 - d * d / 4.0);
double y1 = my + dx / d * sqrt(1.0 - d * d / 4.0);
ret = max(ret, count(x1, y1, i, j));
}
{
double x1 = mx + dy / d * sqrt(1.0 - d * d / 4.0);
double y1 = my - dx / d * sqrt(1.0 - d * d / 4.0);
ret = max(ret, count(x1, y1, i, j));
}
}
}
}
cout << ret << endl;
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 1
| 634
|
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) REP(i, 0, n)
typedef complex<double> P;
#define EPS (1e-10)
#define EQ(a, b) (abs((a) - (b)) < EPS)
#define EQV(a, b) (EQ((a).real(), (b).real) && EQ((a).imag(), (b).imag()))
P unit_vector(P a) { return a / abs(a); }
P normal_vector1(P a) { return a * P(0, 1); }
P normal_vector2(P a) { return a * P(0, -1); }
double distance_p_p(P a, P b) { return abs(a - b); }
int N;
int main() {
while (cin >> N) {
vector<P> ps;
rep(i, N) {
double x, y;
cin >> x >> y;
ps.push_back(P(x, y));
}
int ans = 0;
rep(i, N) {
REP(j, i + 1, N) {
P p, q;
p = ps[i];
q = ps[j];
double d = distance_p_p(p, q);
if (d > 2)
continue;
P pq_c = (q - p) / 2.0;
P a = unit_vector(normal_vector1(q - p));
P b = unit_vector(normal_vector2(q - p));
P c1 = (p + pq_c) + a * (sqrt(1.0 - d * d / 4.0));
P c2 = (p + pq_c) + b * (sqrt(1.0 - d * d / 4.0));
int buf1, buf2;
buf1 = buf2 = 2;
rep(k, N) {
if (k == i || k == j)
continue;
if (distance_p_p(ps[k], c1) <= 1)
buf1++;
if (distance_p_p(ps[k], c2) <= 1)
buf2++;
}
ans = max(ans, max(buf1, buf2));
}
}
cout << ans << endl;
}
return 0;
}
|
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) REP(i, 0, n)
typedef complex<double> P;
#define EPS (1e-10)
#define EQ(a, b) (abs((a) - (b)) < EPS)
#define EQV(a, b) (EQ((a).real(), (b).real) && EQ((a).imag(), (b).imag()))
P unit_vector(P a) { return a / abs(a); }
P normal_vector1(P a) { return a * P(0, 1); }
P normal_vector2(P a) { return a * P(0, -1); }
double distance_p_p(P a, P b) { return abs(a - b); }
int N;
int main() {
while (cin >> N, N) {
vector<P> ps;
rep(i, N) {
double x, y;
cin >> x >> y;
ps.push_back(P(x, y));
}
int ans = 1;
rep(i, N) {
REP(j, i + 1, N) {
P p, q;
p = ps[i];
q = ps[j];
double d = distance_p_p(p, q);
if (d > 2)
continue;
P pq_c = (q - p) / 2.0;
P a = unit_vector(normal_vector1(q - p));
P b = unit_vector(normal_vector2(q - p));
P c1 = (p + pq_c) + a * (sqrt(1.0 - d * d / 4.0));
P c2 = (p + pq_c) + b * (sqrt(1.0 - d * d / 4.0));
int buf1, buf2;
buf1 = buf2 = 2;
rep(k, N) {
if (k == i || k == j)
continue;
if (distance_p_p(ps[k], c1) <= 1)
buf1++;
if (distance_p_p(ps[k], c2) <= 1)
buf2++;
}
ans = max(ans, max(buf1, buf2));
}
}
cout << ans << endl;
}
return 0;
}
|
[["+", 8, 9, 0, 52, 15, 339, 51, 34, 0, 21], ["+", 8, 9, 0, 52, 15, 339, 51, 34, 12, 22], ["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
| 1
| 421
|
#include <algorithm>
#include <complex>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (int)(n); ++i)
#define X real()
#define Y imag()
typedef complex<double> Pt;
const double EPS = 1e-9;
int main() {
int n;
while (cin >> n, n) {
double x, y;
vector<Pt> p;
rep(i, n) {
cin >> x >> y;
p.push_back(Pt(x, y));
}
int ans = 1;
rep(i, n) rep2(j, i + 1, n) {
double d = abs(p[i] - p[j]);
if (d > 2.0)
continue;
Pt m = (p[i] + p[j]) / 2.0;
Pt v = Pt(p[i].Y - p[j].Y, p[j].X - p[i].X);
v /= abs(v);
v *= sqrt(1.0 - d / 2.0);
int t1 = 0, t2 = 0;
Pt c1 = m + v, c2 = m - v;
rep(k, n) {
if (abs(p[k] - c1) < 1.0 + EPS)
++t1;
if (abs(p[k] - c2) < 1.0 + EPS)
++t2;
}
ans = max(max(t1, t2), ans);
}
cout << ans << endl;
}
}
|
#include <algorithm>
#include <complex>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (int)(n); ++i)
#define X real()
#define Y imag()
typedef complex<double> Pt;
const double EPS = 1e-9;
int main() {
int n;
while (cin >> n, n) {
double x, y;
vector<Pt> p;
rep(i, n) {
cin >> x >> y;
p.push_back(Pt(x, y));
}
int ans = 1;
rep(i, n) rep2(j, i + 1, n) {
double d = abs(p[i] - p[j]);
if (d > 2.0)
continue;
Pt m = (p[i] + p[j]) / 2.0;
Pt v = Pt(p[i].Y - p[j].Y, p[j].X - p[i].X);
v /= abs(v);
v *= sqrt(1.0 - d * d / 4.0);
int t1 = 0, t2 = 0;
Pt c1 = m + v, c2 = m - v;
rep(k, n) {
if (abs(p[k] - c1) < 1.0 + EPS)
++t1;
if (abs(p[k] - c2) < 1.0 + EPS)
++t2;
}
ans = max(max(t1, t2), ans);
}
cout << ans << endl;
}
}
|
[["+", 3, 4, 0, 16, 12, 16, 31, 16, 17, 48], ["+", 3, 4, 0, 16, 12, 16, 31, 16, 12, 22], ["-", 12, 2, 3, 4, 0, 16, 12, 16, 12, 13], ["+", 12, 2, 3, 4, 0, 16, 12, 16, 12, 13]]
| 1
| 311
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iostream>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int main() {
int n;
const double eps = 1e-8;
while (true) {
cin >> n;
if (n == 0)
return 0;
int ans = 0;
vector<double> x(n), y(n);
for (int i = 0; i < n; i++)
cin >> x[i] >> y[i];
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
const double d = hypot(x[i] - x[j], y[i] - y[j]);
if (d > 2.0 - eps)
continue;
const double mx = (x[i] + x[j]) / 2.0;
const double my = (y[i] + y[j]) / 2.0;
const double dvx = (x[i] - x[j]) / d;
const double dvy = (y[i] - y[j]) / d;
const double cx1 = mx + dvy * sqrt(1.0 - d * d / 4.0);
const double cy1 = my - dvx * sqrt(1.0 - d * d / 4.0);
const double cx2 = mx - dvy * sqrt(1.0 - d * d / 4.0);
const double cy2 = my + dvx * sqrt(1.0 - d * d / 4.0);
int res = 2;
for (int k = 0; k < n; k++) {
if (k == i || k == j)
continue;
// if(hypot(x[k]-cx1,y[k]-cy1)<1.0+eps)
//res++;
if ((x[k] - cx1) * (x[k] - cx1) + (y[k] - cy1) * (y[k] - cy1) <
1.0 + eps)
res++;
}
ans = max(ans, res);
res = 2;
for (int k = 0; k < n; k++) {
if (k == i || k == j)
continue;
// if(hypot(x[k]-cx2,y[k]-cy2)<1.0+eps)
//res++;
if ((x[k] - cx2) * (x[k] - cx2) + (y[k] - cy2) * (y[k] - cy2) <
1.0 + eps)
res++;
}
ans = max(ans, res);
}
}
cout << ans << endl;
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iostream>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int main() {
int n;
const double eps = 1e-8;
while (true) {
cin >> n;
if (n == 0)
return 0;
int ans = 1;
vector<double> x(n), y(n);
for (int i = 0; i < n; i++)
cin >> x[i] >> y[i];
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
const double d = hypot(x[i] - x[j], y[i] - y[j]);
if (d > 2.0 + eps)
continue;
const double mx = (x[i] + x[j]) / 2.0;
const double my = (y[i] + y[j]) / 2.0;
const double dvx = (x[i] - x[j]) / d;
const double dvy = (y[i] - y[j]) / d;
const double cx1 = mx + dvy * sqrt(1.0 - d * d / 4.0);
const double cy1 = my - dvx * sqrt(1.0 - d * d / 4.0);
const double cx2 = mx - dvy * sqrt(1.0 - d * d / 4.0);
const double cy2 = my + dvx * sqrt(1.0 - d * d / 4.0);
int res = 2;
for (int k = 0; k < n; k++) {
if (k == i || k == j)
continue;
// if(hypot(x[k]-cx1,y[k]-cy1)<1.0+eps)
//res++;
if ((x[k] - cx1) * (x[k] - cx1) + (y[k] - cy1) * (y[k] - cy1) <
1.0 + eps)
res++;
}
ans = max(ans, res);
res = 2;
for (int k = 0; k < n; k++) {
if (k == i || k == j)
continue;
// if(hypot(x[k]-cx2,y[k]-cy2)<1.0+eps)
//res++;
if ((x[k] - cx2) * (x[k] - cx2) + (y[k] - cy2) * (y[k] - cy2) <
1.0 + eps)
res++;
}
ans = max(ans, res);
}
}
cout << ans << endl;
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 33], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 72]]
| 1
| 510
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iostream>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int main() {
int n;
const double eps = 1e-8;
while (true) {
cin >> n;
if (n == 0)
return 0;
int ans = 0;
vector<double> x(n), y(n);
for (int i = 0; i < n; i++)
cin >> x[i] >> y[i];
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
const double d = hypot(x[i] - x[j], y[i] - y[j]);
if (d > 2.0 - eps)
continue;
const double mx = (x[i] + x[j]) / 2.0;
const double my = (y[i] + y[j]) / 2.0;
const double dvx = (x[i] - x[j]) / d;
const double dvy = (y[i] - y[j]) / d;
const double cx1 = mx + dvy * sqrt(1.0 - d * d / 4.0);
const double cy1 = my - dvx * sqrt(1.0 - d * d / 4.0);
const double cx2 = mx - dvy * sqrt(1.0 - d * d / 4.0);
const double cy2 = my + dvx * sqrt(1.0 - d * d / 4.0);
int res = 2;
for (int k = 0; k < n; k++) {
if (k == i || k == j)
continue;
// if(hypot(x[k]-cx1,y[k]-cy1)<1.0+eps)
//res++;
if ((x[k] - cx1) * (x[k] - cx1) + (y[k] - cy1) * (y[k] - cy1) <
1.0 + eps)
res++;
}
ans = max(ans, res);
res = 2;
for (int k = 0; k < n; k++) {
if (k == i || k == j)
continue;
// if(hypot(x[k]-cx2,y[k]-cy2)<1.0+eps)
//res++;
if ((x[k] - cx2) * (x[k] - cx2) + (y[k] - cy2) * (y[k] - cy2) <
1.0 + eps)
res++;
}
ans = max(ans, res);
}
}
cout << ans << endl;
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iostream>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int main() {
int n;
const double eps = 1e-8;
while (true) {
cin >> n;
if (n == 0)
return 0;
//必ず1つは囲める
int ans = 1;
vector<double> x(n), y(n);
for (int i = 0; i < n; i++)
cin >> x[i] >> y[i];
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
const double d = hypot(x[i] - x[j], y[i] - y[j]);
if (d > 2.0 - eps)
continue;
//中点
const double mx = (x[i] + x[j]) / 2.0;
const double my = (y[i] + y[j]) / 2.0;
//方向ベクトル
const double dvx = (x[i] - x[j]) / d;
const double dvy = (y[i] - y[j]) / d;
//(x[i],y[i]),(x[j],y[j])が円周上にある半径1の円の中心1
const double cx1 = mx + dvy * sqrt(1.0 - d * d / 4.0);
const double cy1 = my - dvx * sqrt(1.0 - d * d / 4.0);
//(x[i],y[i]),(x[j],y[j])が円周上にある半径1の円の中心2
const double cx2 = mx - dvy * sqrt(1.0 - d * d / 4.0);
const double cy2 = my + dvx * sqrt(1.0 - d * d / 4.0);
// 2点は円周上にあるので確定(誤差死回避)
int res = 2;
for (int k = 0; k < n; k++) {
if (k == i || k == j)
continue;
if ((x[k] - cx1) * (x[k] - cx1) + (y[k] - cy1) * (y[k] - cy1) <
1.0 + eps)
res++;
}
ans = max(ans, res);
res = 2;
for (int k = 0; k < n; k++) {
if (k == i || k == j)
continue;
if ((x[k] - cx2) * (x[k] - cx2) + (y[k] - cy2) * (y[k] - cy2) <
1.0 + eps)
res++;
}
ans = max(ans, res);
}
}
cout << ans << endl;
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
| 1
| 510
|
// AOJ 1133: Water Tank
// 2018.2.20 bal4u
#include <stdio.h>
#include <string.h>
int n;
int b[12];
int h[12];
double x[12], ans[12];
//#define getchar_unlocked() getchar()
int in() {
int n = 0;
int c = getchar_unlocked();
do
n = (n << 3) + (n << 1) + (c & 0xf), c = getchar_unlocked();
while (c >= '0');
return n;
}
double calc(int pos, int l, int r, double y) {
int i, m, k;
double dy;
if (r - l > 1) {
for (m = i = l + 1; i < r; i++)
if (h[m] < h[i])
m = i;
if (pos < m) {
y = calc(pos, l, m, y);
y = calc(pos, m, r, y);
} else {
y = calc(pos, m, r, y);
y = calc(pos, l, m, y);
}
}
k = h[l];
if (k > h[r])
k = h[r];
dy = (k - ans[l]) * (b[r] - b[l]);
if (dy < 0)
dy = 0;
if (dy > y)
dy = y;
y -= dy;
for (i = l; i < r; i++)
ans[i] += dy / (b[r] - b[l]);
return y;
}
int bsch(int x) {
int m, l = 0, r = n;
while (l < r) {
m = (l + r) >> 1;
if (b[m] <= x)
l = m + 1;
else
r = m;
}
return l;
}
int main() {
int cno, i, m, l, f, a, p, t;
cno = in();
while (cno--) {
n = in();
b[0] = 0, h[0] = 50, b[n + 1] = 100, h[n + 1] = 50;
for (i = 1; i <= n; i++)
b[i] = in(), h[i] = in();
memset(x, 0, sizeof(x));
m = in();
while (m--) {
f = in(), a = in();
x[t = bsch(f) - 1] += a / 30.0;
}
l = in();
while (l--) {
p = in(), t = in();
memset(ans, 0, sizeof(ans));
for (i = 0; i <= n; i++)
calc(i, 0, n + 1, x[i] * t);
printf("%lf\n", ans[bsch(p) - 1]);
}
}
return 0;
}
|
// AOJ 1133: Water Tank
// 2018.2.20 bal4u
#include <stdio.h>
#include <string.h>
int n;
int b[12];
int h[12];
double x[12], ans[12];
//#define getchar_unlocked() getchar()
int in() {
int n = 0;
int c = getchar_unlocked();
do
n = (n << 3) + (n << 1) + (c & 0xf), c = getchar_unlocked();
while (c >= '0');
return n;
}
double calc(int pos, int l, int r, double y) {
int i, m, k;
double dy;
if (r - l > 1) {
for (m = i = l + 1; i < r; i++)
if (h[m] < h[i])
m = i;
if (pos < m) {
y = calc(pos, l, m, y);
y = calc(pos, m, r, y);
} else {
y = calc(pos, m, r, y);
y = calc(pos, l, m, y);
}
}
k = h[l];
if (k > h[r])
k = h[r];
dy = (k - ans[l]) * (b[r] - b[l]);
if (dy < 0)
dy = 0;
if (dy > y)
dy = y;
y -= dy;
for (i = l; i < r; i++)
ans[i] += dy / (b[r] - b[l]);
return y;
}
int bsch(int x) {
int m, l = 0, r = n + 1;
while (l < r) {
m = (l + r) >> 1;
if (b[m] <= x)
l = m + 1;
else
r = m;
}
return l;
}
int main() {
int cno, i, m, l, f, a, p, t;
cno = in();
while (cno--) {
n = in();
b[0] = 0, h[0] = 50, b[n + 1] = 100, h[n + 1] = 50;
for (i = 1; i <= n; i++)
b[i] = in(), h[i] = in();
memset(x, 0, sizeof(x));
m = in();
while (m--) {
f = in(), a = in();
x[t = bsch(f) - 1] += a / 30.0;
}
l = in();
while (l--) {
p = in(), t = in();
memset(ans, 0, sizeof(ans));
for (i = 0; i <= n; i++)
calc(i, 0, n + 1, x[i] * t);
printf("%lf\n", ans[t = bsch(p) - 1]);
}
}
return 0;
}
|
[["+", 8, 9, 0, 43, 49, 50, 51, 16, 17, 72], ["+", 8, 9, 0, 43, 49, 50, 51, 16, 12, 13], ["+", 0, 2, 3, 4, 0, 69, 71, 11, 31, 22], ["+", 0, 2, 3, 4, 0, 69, 71, 11, 17, 32]]
| 0
| 635
|
#ifndef _WIN32
#include <iostream>
#endif
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define FOR(i, bg, ed) for (int i = (bg); i < (ed); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
typedef vector<string> VS;
VS wrap(VS v, char c) {
int R = v.size(), C = v[0].size();
VS ret(R + 2, string(C + 2, c));
REP(i, R) REP(j, C) ret[i + 1][j + 1] = v[i][j];
return ret;
}
const int dr[] = {0, 0, 1, -1};
const int dc[] = {1, -1, 0, 0};
typedef long long LL;
typedef vector<LL> V;
typedef vector<V> VV;
double pos[20];
double h[20];
double in[20];
double w[20];
void f(int x, double &v, int l, int r) {
if (r - l >= 2) {
int mid = l + 1;
FOR(i, l + 1, r - 1) if (h[mid] < h[i]) mid = i;
if (x < mid) {
f(x, v, l, mid);
f(x, v, mid, r);
} else {
f(x, v, mid, r);
f(x, v, l, mid);
}
}
double hh = min(h[l], h[r]);
if (in[l] >= hh)
return;
double vv = min((hh - in[l]) * (pos[r] - pos[l]), v);
v -= vv;
vv /= (pos[r] - pos[l]);
FOR(i, l, r) in[i] += vv;
}
int main() {
cout << fixed;
cout << setprecision(10);
int D;
cin >> D;
while (D--) {
int N;
cin >> N;
pos[0] = 0;
pos[N + 1] = 100;
h[0] = 50;
h[N + 1] = 50;
REP(i, N) cin >> pos[i + 1] >> h[i + 1];
REP(i, N + 1) w[i] = 0;
int M;
cin >> M;
REP(i, M) {
int p;
double z;
cin >> p >> z;
z /= 30;
int id = upper_bound(pos, pos + N + 2, p) - pos - 1;
w[id] += z;
}
cin >> M;
while (M--) {
int p, t;
cin >> p >> t;
REP(i, N + 1) in[i] = 0;
REP(i, N + 1) {
double v = w[i] * t;
f(i, v, 0, N + 1);
}
int id = upper_bound(pos, pos + N + 2, p) - pos - 1;
cout << in[id] << endl;
}
}
}
|
#ifndef _WIN32
#include <iostream>
#endif
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define FOR(i, bg, ed) for (int i = (bg); i < (ed); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
typedef vector<string> VS;
VS wrap(VS v, char c) {
int R = v.size(), C = v[0].size();
VS ret(R + 2, string(C + 2, c));
REP(i, R) REP(j, C) ret[i + 1][j + 1] = v[i][j];
return ret;
}
const int dr[] = {0, 0, 1, -1};
const int dc[] = {1, -1, 0, 0};
typedef long long LL;
typedef vector<LL> V;
typedef vector<V> VV;
int pos[20];
double h[20];
double in[20];
double w[20];
void f(int x, double &v, int l, int r) {
if (r - l >= 2) {
int mid = l + 1;
FOR(i, l + 1, r) if (h[mid] < h[i]) mid = i;
if (x < mid) {
f(x, v, l, mid);
f(x, v, mid, r);
} else {
f(x, v, mid, r);
f(x, v, l, mid);
}
}
double hh = min(h[l], h[r]);
if (in[l] >= hh)
return;
double vv = min((hh - in[l]) * (pos[r] - pos[l]), v);
v -= vv;
vv /= (pos[r] - pos[l]);
FOR(i, l, r) in[i] += vv;
}
int main() {
cout << fixed;
cout << setprecision(10);
int D;
cin >> D;
while (D--) {
int N;
cin >> N;
pos[0] = 0;
pos[N + 1] = 100;
h[0] = 50;
h[N + 1] = 50;
REP(i, N) cin >> pos[i + 1] >> h[i + 1];
REP(i, N + 1) w[i] = 0;
int M;
cin >> M;
REP(i, M) {
int p;
double z;
cin >> p >> z;
z /= 30;
int id = upper_bound(pos, pos + N + 2, p) - pos - 1;
w[id] += z;
}
cin >> M;
while (M--) {
int p, t;
cin >> p >> t;
REP(i, N + 1) in[i] = 0;
REP(i, N + 1) {
double v = w[i] * t;
f(i, v, 0, N + 1);
}
int id = upper_bound(pos, pos + N + 2, p) - pos - 1;
cout << in[id] << endl;
}
}
}
|
[["-", 36, 36, 36, 36, 0, 30, 0, 43, 39, 40], ["+", 36, 36, 36, 36, 0, 30, 0, 43, 39, 40], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 17, 33], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
| 1
| 689
|
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define reps(i, f, n) for (int i = f; i < int(n); i++)
#define rep(i, n) reps(i, 0, n)
const int H = 50;
const int D = 30;
const int W = 100;
const double EPS = 0.00000001;
class Tank {
public:
int w, h;
int flow;
double sum;
bool used;
Tank(int w, int h) : w(w), h(h) {
flow = 0;
sum = 0;
used = false;
}
double getheight() {
double size = w * D;
return sum / size;
}
};
class Event {
public:
int kind;
double time;
int pos;
int cnum;
int tank;
Event(int kind, double time, int pos, int cnum, int tank)
: kind(kind), time(time), pos(pos), cnum(cnum), tank(tank) {}
bool operator<(const Event a) const { return time < a.time; }
};
typedef pair<int, int> pii;
int n, m, r;
vector<Tank> tank;
vector<pii> check;
double checkans[100];
int getpos(int w) {
int ret = 0;
int sum = 0;
rep(i, tank.size()) {
if (sum >= w)
break;
ret = i;
sum += tank[i].w;
}
return ret;
}
void print() {
printf("Tank\n");
rep(i, tank.size()) {
double size = tank[i].w * D;
double height = tank[i].sum / size;
printf("w=%d h=%d flow=%d sum=%lf used=%d height=%lf\n", tank[i].w,
tank[i].h, tank[i].flow, tank[i].sum, tank[i].used, height);
}
puts("");
}
void printevent(vector<Event> &event) {
printf("Event\n");
rep(i, event.size()) {
if (event[i].kind)
printf("tank ");
else
printf("watch ");
printf("time=%lf pos=%d tank=%d\n", event[i].time, event[i].pos,
event[i].tank);
}
puts("");
}
void addcheck(double time, vector<Event> &event) {
rep(i, check.size()) {
if (checkans[i] + EPS >= 0)
continue;
event.push_back(Event(0, check[i].second - time, check[i].first, i, -1));
}
}
int leftwall(int pos) {
if (pos == 0)
return H;
return tank[pos - 1].h;
}
int rightwall(int pos) { return tank[pos].h; }
void addtank(vector<Event> &event) {
if (tank.size() == 1 && tank[0].getheight() + EPS > H)
return;
rep(i, tank.size()) {
if (tank[i].used)
continue;
if (tank[i].flow == 0)
continue;
int under = tank[i].w * D;
int left = leftwall(i);
int right = rightwall(i);
int mini = min(left, right);
int size = under * mini;
double rest = size - tank[i].sum;
double time = rest / tank[i].flow;
event.push_back(Event(1, time, -1, -1, i));
}
}
void flowtank(double time) {
rep(i, tank.size()) {
tank[i].sum += tank[i].flow * time;
tank[i].sum = min((double)H * D * tank[i].w, tank[i].sum);
}
}
void margetank() {
rep(i, tank.size()) {
int right = rightwall(i);
int left = leftwall(i);
double height = tank[i].sum / (tank[i].w * D);
if (right == left) {
} else if (right < left) {
if (height + EPS > right) {
double opheight = tank[i + 1].sum / (tank[i + 1].w * D);
if (opheight + EPS > right) {
tank[i].h = tank[i + 1].h;
tank[i].w += tank[i + 1].w;
tank[i].flow += tank[i + 1].flow;
tank[i].sum += tank[i + 1].sum;
tank.erase(tank.begin() + i + 1);
i = 0;
} else {
tank[i + 1].flow += tank[i].flow;
tank[i].flow = 0;
}
}
} else {
if (height + EPS > left) {
double opheight = tank[i - 1].sum / (tank[i - 1].w * D);
if (opheight + EPS > left) {
tank[i].h = tank[i - 1].h;
tank[i].w += tank[i - 1].w;
tank[i].flow += tank[i - 1].flow;
tank[i].sum += tank[i - 1].sum;
tank.erase(tank.begin() + i - 1);
i = 0;
} else {
tank[i - 1].flow += tank[i].flow;
tank[i].flow = 0;
}
}
}
}
}
void solve() {
cin >> n;
rep(i, 100) checkans[i] = -1;
int befb = 0;
tank.clear();
rep(i, n) {
int b, h;
cin >> b >> h;
tank.push_back(Tank(b - befb, h));
befb = b;
}
tank.push_back(Tank(W - befb, H));
cin >> m;
rep(i, m) {
int f, a;
cin >> f >> a;
tank[getpos(f)].flow += a;
}
check.clear();
cin >> r;
rep(i, r) {
int p, t;
cin >> p >> t;
check.push_back(pii(p, t));
}
// print();
double time = 0;
rep(pp, 20) {
vector<Event> event;
addcheck(time, event);
addtank(event);
if (event.size() == 0)
break;
sort(event.begin(), event.end());
// printf("i=%d time=%lf\n",pp,time);
// printevent(event);
flowtank(event[0].time);
time += event[0].time;
margetank();
// print();
if (event[0].kind == false) {
int pos = getpos(event[0].pos);
double under = tank[pos].w * D;
// printf("!!!!!!!!!!!!!!!!!!!! %lf\n", tank[pos].sum/under);
checkans[event[0].cnum] = tank[pos].sum / under;
}
// break;
}
rep(i, check.size()) { printf("%.9lf\n", checkans[i]); }
}
int main() {
int d;
cin >> d;
rep(i, d) { solve(); }
}
/*
1
5
15 40
35 20
50 45
70 30
80 10
2
60 4
75 1
3
60 6000
75 6000
85 6000
*/
|
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define reps(i, f, n) for (int i = f; i < int(n); i++)
#define rep(i, n) reps(i, 0, n)
const int H = 50;
const int D = 30;
const int W = 100;
const double EPS = 0.00000001;
class Tank {
public:
int w, h;
int flow;
double sum;
bool used;
Tank(int w, int h) : w(w), h(h) {
flow = 0;
sum = 0;
used = false;
}
double getheight() {
double size = w * D;
return sum / size;
}
};
class Event {
public:
int kind;
double time;
int pos;
int cnum;
int tank;
Event(int kind, double time, int pos, int cnum, int tank)
: kind(kind), time(time), pos(pos), cnum(cnum), tank(tank) {}
bool operator<(const Event a) const { return time < a.time; }
};
typedef pair<int, int> pii;
int n, m, r;
vector<Tank> tank;
vector<pii> check;
double checkans[100];
int getpos(int w) {
int ret = 0;
int sum = 0;
rep(i, tank.size()) {
if (sum >= w)
break;
ret = i;
sum += tank[i].w;
}
return ret;
}
void print() {
printf("Tank\n");
rep(i, tank.size()) {
double size = tank[i].w * D;
double height = tank[i].sum / size;
printf("w=%d h=%d flow=%d sum=%lf used=%d height=%lf\n", tank[i].w,
tank[i].h, tank[i].flow, tank[i].sum, tank[i].used, height);
}
puts("");
}
void printevent(vector<Event> &event) {
printf("Event\n");
rep(i, event.size()) {
if (event[i].kind)
printf("tank ");
else
printf("watch ");
printf("time=%lf pos=%d tank=%d\n", event[i].time, event[i].pos,
event[i].tank);
}
puts("");
}
void addcheck(double time, vector<Event> &event) {
rep(i, check.size()) {
if (checkans[i] + EPS >= 0)
continue;
event.push_back(Event(0, check[i].second - time, check[i].first, i, -1));
}
}
int leftwall(int pos) {
if (pos == 0)
return H;
return tank[pos - 1].h;
}
int rightwall(int pos) { return tank[pos].h; }
void addtank(vector<Event> &event) {
if (tank.size() == 1 && tank[0].getheight() + EPS > H)
return;
rep(i, tank.size()) {
if (tank[i].used)
continue;
if (tank[i].flow == 0)
continue;
int under = tank[i].w * D;
int left = leftwall(i);
int right = rightwall(i);
int mini = min(left, right);
int size = under * mini;
double rest = size - tank[i].sum;
double time = rest / tank[i].flow;
event.push_back(Event(1, time, -1, -1, i));
}
}
void flowtank(double time) {
rep(i, tank.size()) {
tank[i].sum += tank[i].flow * time;
tank[i].sum = min((double)H * D * tank[i].w, tank[i].sum);
}
}
void margetank() {
rep(i, tank.size()) {
int right = rightwall(i);
int left = leftwall(i);
double height = tank[i].sum / (tank[i].w * D);
if (right == left) {
} else if (right < left) {
if (height + EPS > right) {
double opheight = tank[i + 1].sum / (tank[i + 1].w * D);
if (opheight + EPS > right) {
tank[i].h = tank[i + 1].h;
tank[i].w += tank[i + 1].w;
tank[i].flow += tank[i + 1].flow;
tank[i].sum += tank[i + 1].sum;
tank.erase(tank.begin() + i + 1);
i = 0;
} else {
tank[i + 1].flow += tank[i].flow;
tank[i].flow = 0;
}
}
} else {
if (height + EPS > left) {
double opheight = tank[i - 1].sum / (tank[i - 1].w * D);
if (opheight + EPS > left) {
tank[i].h = tank[i - 1].h;
tank[i].w += tank[i - 1].w;
tank[i].flow += tank[i - 1].flow;
tank[i].sum += tank[i - 1].sum;
tank.erase(tank.begin() + i - 1);
i = 0;
} else {
tank[i - 1].flow += tank[i].flow;
tank[i].flow = 0;
}
}
}
}
}
void solve() {
cin >> n;
rep(i, 100) checkans[i] = -1;
int befb = 0;
tank.clear();
rep(i, n) {
int b, h;
cin >> b >> h;
tank.push_back(Tank(b - befb, h));
befb = b;
}
tank.push_back(Tank(W - befb, H));
cin >> m;
rep(i, m) {
int f, a;
cin >> f >> a;
tank[getpos(f)].flow += a;
}
check.clear();
cin >> r;
rep(i, r) {
int p, t;
cin >> p >> t;
check.push_back(pii(p, t));
}
// print();
double time = 0;
while (1) {
vector<Event> event;
addcheck(time, event);
addtank(event);
if (event.size() == 0)
break;
sort(event.begin(), event.end());
// printf("i=%d time=%lf\n",pp,time);
// printevent(event);
flowtank(event[0].time);
time += event[0].time;
margetank();
// print();
if (event[0].kind == false) {
int pos = getpos(event[0].pos);
double under = tank[pos].w * D;
// printf("!!!!!!!!!!!!!!!!!!!! %lf\n", tank[pos].sum/under);
checkans[event[0].cnum] = tank[pos].sum / under;
}
// break;
}
rep(i, check.size()) { printf("%.14lf\n", checkans[i]); }
}
int main() {
int d;
cin >> d;
rep(i, d) { solve(); }
}
/*
1
5
15 40
35 20
50 45
70 30
80 10
2
60 4
75 1
3
60 6000
75 6000
85 6000
*/
|
[["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 52, 0, 89], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 21], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 51, 13], ["-", 0, 1, 0, 2, 3, 4, 0, 25, 0, 35], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 1
| 1,587
|
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge {
int u, v;
ll w;
};
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
int main() {
for (;;) {
int N, M;
cin >> N >> M;
if (N == 0)
break;
int r;
cin >> r;
vector<int> t(r), n(r), m(r), s(r);
for (int i = 0; i < r; i++)
cin >> t[i] >> n[i] >> m[i] >> s[i];
int q;
cin >> q;
while (q--) {
int ts, te, _m;
cin >> ts >> te >> _m;
int x = 0, start, end, ans = 0;
for (int i = 0; i < r; i++) {
if (m[i] != _m)
continue;
if (s[i]) {
if (x == 0)
start = t[i];
x++;
} else {
x--;
if (x == 0) {
end = t[i];
ans += min(te, end) - max(ts, start);
}
}
}
cout << ans << endl;
}
}
}
|
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge {
int u, v;
ll w;
};
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
int main() {
for (;;) {
int N, M;
cin >> N >> M;
if (N == 0)
break;
int r;
cin >> r;
vector<int> t(r), n(r), m(r), s(r);
for (int i = 0; i < r; i++)
cin >> t[i] >> n[i] >> m[i] >> s[i];
int q;
cin >> q;
while (q--) {
int ts, te, _m;
cin >> ts >> te >> _m;
int x = 0, start, end, ans = 0;
for (int i = 0; i < r; i++) {
if (m[i] != _m)
continue;
if (s[i]) {
if (x == 0)
start = t[i];
x++;
} else {
x--;
if (x == 0) {
end = t[i];
ans += max(0, min(te, end) - max(ts, start));
}
}
}
cout << ans << endl;
}
}
}
|
[["+", 64, 9, 0, 1, 0, 11, 12, 2, 63, 22], ["+", 0, 1, 0, 11, 12, 2, 3, 4, 0, 24], ["+", 0, 1, 0, 11, 12, 2, 3, 4, 0, 13], ["+", 0, 1, 0, 11, 12, 2, 3, 4, 0, 21], ["+", 3, 4, 0, 16, 12, 2, 3, 4, 0, 25]]
| 1
| 358
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
while (true) {
int N, M;
cin >> N >> M;
if (N == 0)
break;
int r;
cin >> r;
vector<int> t(r), n(r), m(r), s(r);
for (int i = 0; i < r; i++) {
cin >> t[i] >> n[i] >> m[i] >> s[i];
}
int q;
cin >> q;
vector<int> ts(q), te(q), qm(q);
for (int i = 0; i < q; i++) {
cin >> ts[i] >> te[i] >> qm[i];
}
for (int i = 0; i < q; i++) {
int sum = 0;
int start = 0;
int PCnum = 0;
for (int j = 0; j < r; j++) {
if (m[j] == qm[i]) {
if (s[j] == 1) {
PCnum++;
if (PCnum == 1)
start = t[j];
} else {
PCnum--;
if (PCnum == 0)
sum += min(t[j], te[i]) - max(ts[i], start);
}
}
}
cout << sum << endl;
}
}
}
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
while (true) {
int N, M;
cin >> N >> M;
if (N == 0)
break;
int r;
cin >> r;
vector<int> t(r), n(r), m(r), s(r);
for (int i = 0; i < r; i++) {
cin >> t[i] >> n[i] >> m[i] >> s[i];
}
int q;
cin >> q;
vector<int> ts(q), te(q), qm(q);
for (int i = 0; i < q; i++) {
cin >> ts[i] >> te[i] >> qm[i];
}
for (int i = 0; i < q; i++) {
int sum = 0;
int start = 0;
int PCnum = 0;
for (int j = 0; j < r; j++) {
if (m[j] == qm[i]) {
if (s[j] == 1) {
PCnum++;
if (PCnum == 1)
start = t[j];
} else {
PCnum--;
if (PCnum == 0)
sum += max(0, min(t[j], te[i]) - max(ts[i], start));
}
}
}
cout << sum << endl;
}
}
}
|
[["+", 0, 57, 64, 1, 0, 11, 12, 2, 63, 22], ["+", 64, 1, 0, 11, 12, 2, 3, 4, 0, 24], ["+", 64, 1, 0, 11, 12, 2, 3, 4, 0, 13], ["+", 64, 1, 0, 11, 12, 2, 3, 4, 0, 21], ["+", 3, 4, 0, 16, 12, 2, 3, 4, 0, 25]]
| 1
| 300
|
#include <iostream>
using namespace std;
int main() {
int N, M;
int r;
while (cin >> N >> M) {
if (N == 0 && M == 0)
break;
cin >> r;
int *t = new int[r];
int *n = new int[r];
int *m = new int[r];
int *s = new int[r];
for (int i = 0; i < r; i++) {
cin >> t[i] >> n[i] >> m[i] >> s[i];
}
int q;
cin >> q;
for (int i = 0; i < q; i++) {
int start, end, studentNum;
cin >> start >> end >> studentNum;
int pcNum = 0;
int pcStart = 0;
int sum = 0;
for (int j = 0; j < r; j++) {
if (studentNum == m[j]) {
if (s[j] == 1) {
if (pcNum == 0) {
if (t[j] <= start) {
pcStart = start;
} else if (t[j] >= end) {
pcStart = end;
} else {
pcStart = t[j];
}
}
pcNum++;
} else {
if (pcNum == 1) {
if (t[j] <= start) {
sum += t[j] - start;
} else if (t[j] >= end) {
sum += end - pcStart;
} else {
sum += t[j] - pcStart;
}
}
pcNum--;
}
}
}
cout << sum << endl;
}
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int N, M;
int r;
while (cin >> N >> M) {
if (N == 0 && M == 0)
break;
cin >> r;
int *t = new int[r];
int *n = new int[r];
int *m = new int[r];
int *s = new int[r];
for (int i = 0; i < r; i++) {
cin >> t[i] >> n[i] >> m[i] >> s[i];
}
int q;
cin >> q;
for (int i = 0; i < q; i++) {
int start, end, studentNum;
cin >> start >> end >> studentNum;
int pcNum = 0;
int pcStart = 0;
int sum = 0;
for (int j = 0; j < r; j++) {
if (studentNum == m[j]) {
if (s[j] == 1) {
if (pcNum == 0) {
if (t[j] <= start) {
pcStart = start;
} else if (t[j] >= end) {
pcStart = end;
} else {
pcStart = t[j];
}
}
pcNum++;
} else {
if (pcNum == 1) {
if (t[j] <= start) {
sum += 0;
} else if (t[j] >= end) {
sum += end - pcStart;
} else {
sum += t[j] - pcStart;
}
}
pcNum--;
}
}
}
cout << sum << endl;
}
}
return 0;
}
|
[["-", 0, 1, 0, 11, 12, 16, 31, 69, 28, 22], ["-", 0, 11, 12, 16, 31, 69, 341, 342, 0, 70], ["-", 0, 11, 12, 16, 31, 69, 341, 342, 0, 22], ["-", 0, 11, 12, 16, 31, 69, 341, 342, 0, 73], ["-", 64, 9, 0, 1, 0, 11, 12, 16, 17, 33], ["-", 64, 9, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 13]]
| 1
| 340
|
#include <iostream>
#include <set>
#include <vector>
using namespace std;
int main() {
while (true) {
int N, M, r, q, t, n, m, s, ts, te, mm;
vector<pair<int, pair<int, int>>> lg[10001];
cin >> N >> M;
if (!(N || M))
break;
cin >> r;
for (int i = 0; i < r; ++i) {
cin >> t >> n >> mm >> s;
lg[mm].push_back(make_pair(t, make_pair(n, s)));
}
cin >> q;
for (int i = 0; i < q; ++i) {
set<int> pc;
int cnt = 0;
int start = 0;
cin >> ts >> te >> m;
for (int j = 0; j < lg[m].size(); ++j) {
if (lg[m][j].second.second == 1) {
pc.insert(lg[m][j].second.first);
} else {
pc.erase(lg[m][j].second.first);
}
if (lg[m][j].first < ts) {
if (!pc.empty()) {
start = ts;
} else {
start = 0;
}
} else if (ts <= lg[m][j].first && lg[m][j].first <= te) {
if (!pc.empty() && start == 0) {
start = lg[m][j].first;
} else if (pc.empty() && start != 0) {
cnt += lg[m][j].first - start;
start = 0;
}
} else if (lg[m][j].first > te) {
if (start != 0)
cnt += te - start;
}
}
cout << cnt << endl;
}
}
}
|
#include <iostream>
#include <set>
#include <vector>
using namespace std;
int main() {
while (true) {
int N, M, r, q, t, n, m, s, ts, te, mm;
vector<pair<int, pair<int, int>>> lg[10001];
cin >> N >> M;
if (!(N || M))
break;
cin >> r;
for (int i = 0; i < r; ++i) {
cin >> t >> n >> mm >> s;
lg[mm].push_back(make_pair(t, make_pair(n, s)));
}
cin >> q;
for (int i = 0; i < q; ++i) {
set<int> pc;
int cnt = 0;
int start = 0;
cin >> ts >> te >> m;
for (int j = 0; j < lg[m].size(); ++j) {
if (lg[m][j].second.second == 1) {
pc.insert(lg[m][j].second.first);
} else {
pc.erase(lg[m][j].second.first);
}
if (lg[m][j].first < ts) {
if (!pc.empty()) {
start = ts;
} else {
start = 0;
}
} else if (ts <= lg[m][j].first && lg[m][j].first <= te) {
if (!pc.empty() && start == 0) {
start = lg[m][j].first;
} else if (pc.empty() && start != 0) {
cnt += lg[m][j].first - start;
start = 0;
}
} else if (lg[m][j].first > te) {
if (start != 0)
cnt += te - start;
break;
}
}
cout << cnt << endl;
}
}
}
|
[["+", 75, 76, 0, 57, 64, 9, 0, 93, 0, 94], ["+", 75, 76, 0, 57, 64, 9, 0, 93, 0, 35]]
| 1
| 415
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for (int i = 0; i < (n); i++)
#define All(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;
int state[10001][10261];
int pc[10001];
main() {
int N, M;
while (cin >> N >> M, !(N == 0 && M == 0)) {
int r, q;
fill_n(*state, 10001 * 10261, 0);
cin >> r;
Rep(i, r) {
int t, n, m, s;
cin >> t >> n >> m >> s;
if (s)
pc[n] = t;
else {
for (int j = pc[n]; j < t; j++) {
state[m][j] = 1;
}
}
}
cin >> q;
Rep(i, q) {
int ts, te, m;
cin >> ts >> te >> m;
int sum = 0;
for (int j = ts; j < te; j++)
sum += state[m][j];
cout << sum << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for (int i = 0; i < (n); i++)
#define All(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;
bool state[10001][1261];
int pc[10001];
main() {
int N, M;
while (cin >> N >> M, !(N == 0 && M == 0)) {
int r, q;
fill_n(*state, 10001 * 1261, false);
cin >> r;
Rep(i, r) {
int t, n, m, s;
cin >> t >> n >> m >> s;
if (s)
pc[n] = t;
else {
for (int j = pc[n]; j < t; j++) {
state[m][j] = 1;
}
}
}
cin >> q;
Rep(i, q) {
int ts, te, m;
cin >> ts >> te >> m;
int sum = 0;
for (int j = ts; j < te; j++)
sum += state[m][j];
cout << sum << endl;
}
}
}
|
[["-", 36, 36, 36, 36, 0, 30, 0, 43, 39, 40], ["+", 36, 36, 36, 36, 0, 30, 0, 43, 39, 40], ["-", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 147]]
| 1
| 261
|
#include <algorithm>
#include <iostream>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
int main() {
while (true) {
int n;
int m;
cin >> n >> m;
if (n == 0 && m == 0) {
break;
}
unordered_map<int, int> wip;
using Range = tuple<int, int, int>;
vector<Range> v;
int r;
cin >> r;
for (int i = 0; i < r; ++i) {
int t;
int n_;
int m_;
int s;
cin >> t >> n_ >> m_ >> s;
if (s == 1) {
wip[n_] = t;
} else {
v.push_back(make_tuple(m_, wip[n_], t));
wip.erase(n_);
}
}
int q;
cin >> q;
for (int i = 0; i < q; ++i) {
int t_s;
int t_e;
int m_;
cin >> t_s >> t_e >> m_;
auto merge = [](const Range &a, const Range &b) {
int am, as, ae;
int bm, bs, be;
tie(am, as, ae) = a;
tie(bm, bs, be) = b;
int max_ = max(as, bs);
int min_ = min(ae, be);
if (max_ <= min_) {
make_pair(true, make_tuple(am, min(as, bs), max(ae, be)));
}
return make_pair(false, Range{});
};
vector<Range> cv;
copy_if(begin(v), end(v), back_inserter(cv),
[m_](const Range &a) { return get<0>(a) == m_; });
vector<Range> curr = cv;
vector<Range> prev = cv;
while (true) {
prev = curr;
curr = {};
bool merged{false};
for (int j = 0; j < static_cast<int>(prev.size()) - 1; ++j) {
auto a = merge(prev[j], prev[j + 1]);
if (a.first) {
curr.push_back(a.second);
curr.insert(end(curr), begin(prev) + j + 2, end(prev));
merged = true;
break;
}
curr.push_back(prev[j]);
}
if (!merged) {
break;
}
}
// ??????????????????????????£???????????§?¨???????????????????prev?????¨??????????´?????????????????????§??????
// curr????????????????´??????\??£??????????????????prev?????¨??????
cv = prev;
cv.erase(unique(begin(cv), end(cv)), end(cv));
int c{0};
for (auto &&j : cv) {
int beg = max(t_s, get<1>(j));
int en = min(t_e, get<2>(j));
if (en - beg > 0) {
c += en - beg;
}
}
cout << c << endl;
}
}
}
|
#include <algorithm>
#include <iostream>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
int main() {
while (true) {
int n;
int m;
cin >> n >> m;
if (n == 0 && m == 0) {
break;
}
unordered_map<int, int> wip;
using Range = tuple<int, int, int>;
vector<Range> v;
int r;
cin >> r;
for (int i = 0; i < r; ++i) {
int t;
int n_;
int m_;
int s;
cin >> t >> n_ >> m_ >> s;
if (s == 1) {
wip[n_] = t;
} else {
v.push_back(make_tuple(m_, wip[n_], t));
wip.erase(n_);
}
}
int q;
cin >> q;
for (int i = 0; i < q; ++i) {
int t_s;
int t_e;
int m_;
cin >> t_s >> t_e >> m_;
auto merge = [](const Range &a, const Range &b) {
int am, as, ae;
int bm, bs, be;
tie(am, as, ae) = a;
tie(bm, bs, be) = b;
int max_ = max(as, bs);
int min_ = min(ae, be);
if (max_ <= min_) {
return make_pair(true, make_tuple(am, min(as, bs), max(ae, be)));
}
return make_pair(false, Range{});
};
vector<Range> cv;
copy_if(begin(v), end(v), back_inserter(cv),
[m_](const Range &a) { return get<0>(a) == m_; });
vector<Range> curr = cv;
vector<Range> prev = cv;
while (true) {
prev = curr;
curr = {};
bool merged{false};
for (int j = 0; j < static_cast<int>(prev.size()) - 1; ++j) {
auto a = merge(prev[j], prev[j + 1]);
if (a.first) {
curr.push_back(a.second);
curr.insert(end(curr), begin(prev) + j + 2, end(prev));
merged = true;
break;
}
curr.push_back(prev[j]);
}
if (!merged) {
break;
}
}
// ??????????????????????????£???????????§?¨???????????????????prev?????¨??????????´?????????????????????§??????
// curr????????????????´??????\??£??????????????????prev?????¨??????
cv = prev;
cv.erase(unique(begin(cv), end(cv)), end(cv));
int c{0};
for (auto &&j : cv) {
int beg = max(t_s, get<1>(j));
int en = min(t_e, get<2>(j));
if (en - beg > 0) {
c += en - beg;
}
}
cout << c << endl;
}
}
}
|
[["+", 8, 9, 0, 57, 64, 9, 0, 37, 0, 38]]
| 1
| 619
|
#include <iostream>
#include <vector>
using namespace std;
class student {
public:
int st[51], ed[51];
int num, cnt;
student() {
num = 0;
cnt = 0;
}
};
int main() {
int N; // 学生数
int M; // PC数
while (cin >> N >> M, N || M) {
int r; // 利用記録数
int q; // 質問数
vector<student> std(N);
// 登録
cin >> r;
for (int i = 0; i < r; i++) {
int t, n, m, s; // s(1: ログイン, 0: ログアウト), 時刻tにPCnで学生mが
cin >> t >> n >> m >> s;
if (s == 1) { // ログイン
if (std[m].cnt == 0) { // まだログインしていない
std[m].st[std[m].num] = t;
}
std[m].cnt++;
} else { // ログアウト
if (std[m].cnt == 1)
std[m].ed[std[m].num++] = t;
std[m].cnt--;
}
}
// 質問
cin >> q;
for (int i = 0; i < q; i++) {
int ts, te, m;
int ans = 0;
cin >> ts >> te >> m;
for (int j = 0; j < std[m].num; j++) {
if (std[m].ed[j] <= ts)
continue;
if (std[m].st[j] >= te)
break;
if (std[m].st[j] <= ts && std[m].ed[j] >= te) {
ans += te - ts;
break;
}
if (std[m].st[j] <= ts && std[m].ed[j] < te)
ans += std[m].ed[j] - ts;
else if (std[m].st[j] >= ts && std[m].ed[j] >= te) {
ans += te - std[m].st[j];
break;
} else if (std[m].st[j] >= ts && std[m].ed[j] < te)
ans += std[m].ed[j] - std[m].st[j];
}
cout << ans << endl;
}
}
return 0;
}
|
#include <iostream>
#include <vector>
using namespace std;
class student {
public:
int st[50], ed[50];
int num, cnt;
student() {
num = 0;
cnt = 0;
}
};
int main() {
int N; // PC数
int M; // 学生数
while (cin >> N >> M, N || M) {
int r; // 利用記録数
int q; // 質問数
vector<student> std(M + 1);
// 登録
cin >> r;
for (int i = 0; i < r; i++) {
int t, n, m, s; // s(1: ログイン, 0: ログアウト), 時刻tにPCnで学生mが
cin >> t >> n >> m >> s;
if (s == 1) { // ログイン
if (std[m].cnt == 0) { // まだログインしていない
std[m].st[std[m].num] = t;
}
std[m].cnt++;
} else { // ログアウト
if (std[m].cnt == 1)
std[m].ed[std[m].num++] = t;
std[m].cnt--;
}
}
// 質問
cin >> q;
for (int i = 0; i < q; i++) {
int ts, te, m;
int ans = 0;
cin >> ts >> te >> m;
for (int j = 0; j < std[m].num; j++) {
if (std[m].ed[j] <= ts)
continue;
if (std[m].st[j] >= te)
break;
if (std[m].st[j] <= ts && std[m].ed[j] >= te) {
ans += te - ts;
break;
}
if (std[m].st[j] <= ts && std[m].ed[j] < te)
ans += std[m].ed[j] - ts;
else if (std[m].st[j] >= ts && std[m].ed[j] >= te) {
ans += te - std[m].st[j];
break;
} else if (std[m].st[j] >= ts && std[m].ed[j] < te)
ans += std[m].ed[j] - std[m].st[j];
}
cout << ans << endl;
}
}
return 0;
}
|
[["-", 0, 353, 8, 123, 0, 124, 49, 80, 81, 13], ["+", 0, 353, 8, 123, 0, 124, 49, 80, 81, 13], ["-", 0, 43, 49, 53, 54, 55, 0, 56, 39, 78], ["+", 0, 43, 49, 50, 51, 4, 0, 16, 31, 22], ["+", 0, 43, 49, 50, 51, 4, 0, 16, 17, 72], ["+", 0, 43, 49, 50, 51, 4, 0, 16, 12, 13]]
| 1
| 492
|
#include <iostream>
#include <vector>
using namespace std;
const int MaxN = 1001;
const int MaxM = 10001;
int N, M;
int main() {
int count[MaxM];
while (cin >> N >> M && !(N == 0 && M == 0)) {
vector<vector<pair<int, int>>> logg(MaxM);
int r;
cin >> r;
int t, n, m, s;
for (int i = 0; i < MaxM; i++) { // 初期化
count[i] = 0;
}
for (int i = 0; i < r; i++) {
cin >> t >> n >> m >> s;
if (s == 1) { // login
count[m]++;
if (count[m] == 1) {
logg[m].push_back(make_pair(t, t));
}
} else { // logout
count[m]--;
if (count[m] == 0) {
logg[m].back().second = t;
}
}
}
int q;
cin >> q;
for (int i = 0; i < q; i++) {
int ts, te, m, ans = 0;
cin >> ts >> te >> m;
int ans1, ans2; // 4debug ans1は誤りらしい
for (int j = 0; j < logg[m].size(); j++) {
if (logg[m][j].first < te) {
ans1 = min(te, logg[m][j].second) - max(ts, logg[m][j].first);
} else {
ans1 = 0;
}
ans2 = max(0, min(te, logg[m][j].second) - max(ts, logg[m][j].first));
/*
if(ans1!=ans2) {
cout<<"Q: "<<ts<<" "<<te<<endl;
cout<<"why: "<<min(te, logg[m][j].second)-max(ts,
logg[m][j].first)<<endl; cout<<"val: "<<logg[m][j].first<<"
"<<logg[m][j].second<<endl; cout<<"ans: "<<ans1<<" "<<ans2<<endl;
}
*/
ans += ans1;
}
cout << ans << endl;
}
}
}
|
#include <iostream>
#include <vector>
using namespace std;
const int MaxN = 1001;
const int MaxM = 10001;
int N, M;
int main() {
int count[MaxM];
while (cin >> N >> M && !(N == 0 && M == 0)) {
vector<vector<pair<int, int>>> logg(MaxM);
int r;
cin >> r;
int t, n, m, s;
for (int i = 0; i < MaxM; i++) { // 初期化
count[i] = 0;
}
for (int i = 0; i < r; i++) {
cin >> t >> n >> m >> s;
if (s == 1) { // login
count[m]++;
if (count[m] == 1) {
logg[m].push_back(make_pair(t, t));
}
} else { // logout
count[m]--;
if (count[m] == 0) {
logg[m].back().second = t;
}
}
}
int q;
cin >> q;
for (int i = 0; i < q; i++) {
int ts, te, m, ans = 0;
cin >> ts >> te >> m;
int ans1, ans2; // 4debug ans1は誤りらしい
for (int j = 0; j < logg[m].size(); j++) {
if (logg[m][j].first < te) {
ans1 = min(te, logg[m][j].second) - max(ts, logg[m][j].first);
} else {
ans1 = 0;
}
ans2 = max(0, min(te, logg[m][j].second) - max(ts, logg[m][j].first));
/*
if(ans1!=ans2) {
cout<<"Q: "<<ts<<" "<<te<<endl;
cout<<"why: "<<min(te, logg[m][j].second)-max(ts,
logg[m][j].first)<<endl; cout<<"val: "<<logg[m][j].first<<"
"<<logg[m][j].second<<endl; cout<<"ans: "<<ans1<<" "<<ans2<<endl;
}
*/
ans += ans2;
}
cout << ans << endl;
}
}
}
|
[["-", 0, 7, 8, 9, 0, 1, 0, 11, 12, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 12, 22]]
| 1
| 390
|
#! /usr/bin/python
# -*- coding: utf-8 -*-
from bisect import *
while True:
(N, M) = list(map(int, input().split()))
if N == 0: break
r = int(input())
used = [0]*(N+1)
imos = [[0]*1301 for i in range(M+1)]
for i in range(r):
(t, n, m, s) = list(map(int, input().split()))
if s == 1 and used[n] == 0:
used[n] = m
imos[m][t] = 1
if s == 0 and used[n] == m:
used[n] = 0
imos[m][t] -= 1
#if imos[m][t] > 0:
# imos[m][t] -= 1
#else:
# imos[m][t] = -1
q = int(input())
for i in range(q):
cnt += 1
(qs, qe, user) = list(map(int, input().split()))
tmp = 0
ans = 0
for j in range(540, 1261):
#if imos[user][j] == 1:
# tmp += 1
if tmp > 0 and j > qs and j <= qe:
ans += 1
tmp += imos[user][j]
#if imos[user][j] == -1:
# tmp -= 1
print(ans)
|
#! /usr/bin/python
# -*- coding: utf-8 -*-
from bisect import *
while True:
(N, M) = list(map(int, input().split()))
if N == 0: break
r = int(input())
used = [0]*(N+1)
imos = [[0]*1301 for i in range(M+1)]
for i in range(r):
(t, n, m, s) = list(map(int, input().split()))
if s == 1 and used[n] == 0:
used[n] = m
imos[m][t] += 1
if s == 0 and used[n] == m:
used[n] = 0
imos[m][t] -= 1
#if imos[m][t] > 0:
# imos[m][t] -= 1
#else:
# imos[m][t] = -1
q = int(input())
for i in range(q):
(qs, qe, user) = list(map(int, input().split()))
tmp = 0
ans = 0
for j in range(540, 1261):
#if imos[user][j] == 1:
# tmp += 1
if tmp > 0 and j > qs and j <= qe:
ans += 1
tmp += imos[user][j]
#if imos[user][j] == -1:
# tmp -= 1
print(ans)
|
[["-", 0, 57, 64, 196, 0, 1, 0, 662, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 677, 17, 107], ["-", 0, 7, 8, 196, 0, 1, 0, 677, 31, 22], ["-", 0, 7, 8, 196, 0, 1, 0, 677, 17, 107], ["-", 0, 7, 8, 196, 0, 1, 0, 677, 12, 612]]
| 5
| 255
|
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int n, m, i, j;
int tarou[101];
int hanako[101];
int tarou_sum = 0, hanako_sum = 0;
int sa;
int min_tarou = 999, min_hanako = 999;
int min = 999;
int hen = 0;
while (1) {
scanf("%d %d", &m, &n);
if (m == 0)
break;
min_tarou = 999;
min_hanako = 999;
tarou_sum = 0;
hanako_sum = 0;
min = 999;
for (i = 0; i < m; i++) {
scanf("%d", &tarou[i]);
tarou_sum += tarou[i];
}
for (i = 0; i < n; i++) {
scanf("%d", &hanako[i]);
hanako_sum += hanako[i];
}
if (!(abs(tarou_sum - hanako_sum) % 2)) {
sa = abs(tarou_sum - hanako_sum) / 2;
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
if (abs(tarou[i] - hanako[j]) == sa && (tarou[i] + hanako[j]) < min) {
min_tarou = tarou[i];
min_hanako = hanako[j];
min = tarou[i] + hanako[j];
}
}
}
}
if (min_tarou == 999) {
printf("-1\n");
} else {
printf("%d %d\n", min_tarou, min_hanako);
}
}
return 0;
}
|
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int n, m, i, j;
int tarou[101];
int hanako[101];
int tarou_sum = 0, hanako_sum = 0;
int sa;
int min_tarou = 999, min_hanako = 999;
int min = 999;
int hen = 0;
while (1) {
scanf("%d %d", &m, &n);
if (m == 0)
break;
min_tarou = 999;
min_hanako = 999;
tarou_sum = 0;
hanako_sum = 0;
min = 999;
for (i = 0; i < m; i++) {
scanf("%d", &tarou[i]);
tarou_sum += tarou[i];
}
for (i = 0; i < n; i++) {
scanf("%d", &hanako[i]);
hanako_sum += hanako[i];
}
if (!(abs(tarou_sum - hanako_sum) % 2)) {
sa = (tarou_sum - hanako_sum) / 2;
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
if ((tarou[i] - hanako[j]) == sa && (tarou[i] + hanako[j]) < min) {
min_tarou = tarou[i];
min_hanako = hanako[j];
min = tarou[i] + hanako[j];
}
}
}
}
if (min_tarou == 999) {
printf("-1\n");
} else {
printf("%d %d\n", min_tarou, min_hanako);
}
}
return 0;
}
|
[["-", 0, 1, 0, 11, 12, 16, 31, 2, 63, 22], ["-", 15, 23, 0, 16, 31, 16, 31, 2, 63, 22]]
| 0
| 330
|
#include <stdio.h>
int main(void) {
int taro[100] = {0}, hanako[100] = {0};
int i, j, n, m, min, tarotrade, hanakotrade;
int taroall, hanakoall;
scanf("%d%d", &n, &m);
while (m + n) {
taroall = 0;
hanakoall = 0;
min = 201;
for (i = 0; i < n; i++) {
scanf("%d", &taro[i]);
// printf("%d",taro[i]);
taroall += taro[i];
}
for (i = 0; i < m; i++) {
scanf("%d", &hanako[i]);
// printf("%d",hanako[i]);
hanakoall += hanako[i];
}
// printf("%d",taroall);
// printf("%d",hanakoall);
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if ((taroall - taro[i] + hanako[j]) ==
(hanakoall - hanako[j] + taro[i])) {
// printf("%d",taro[i] + hanako[j]);
if (min > taro[i] + hanako[j]) {
tarotrade = taro[i];
hanakotrade = hanako[j];
min = taro[i] + hanako[j];
// puts("1");
}
}
}
}
if (min == 101) {
puts("-1");
} else {
printf("%d %d\n", tarotrade, hanakotrade);
}
scanf("%d%d", &n, &m);
}
return (0);
}
|
#include <stdio.h>
int main(void) {
int taro[100] = {0}, hanako[100] = {0};
int i, j, n, m, min, tarotrade, hanakotrade;
int taroall, hanakoall;
scanf("%d%d", &n, &m);
while (m + n) {
taroall = 0;
hanakoall = 0;
min = 201;
for (i = 0; i < n; i++) {
scanf("%d", &taro[i]);
// printf("%d",taro[i]);
taroall += taro[i];
}
for (i = 0; i < m; i++) {
scanf("%d", &hanako[i]);
// printf("%d",hanako[i]);
hanakoall += hanako[i];
}
// printf("%d",taroall);
// printf("%d",hanakoall);
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if ((taroall - taro[i] + hanako[j]) ==
(hanakoall - hanako[j] + taro[i])) {
// printf("%d",taro[i] + hanako[j]);
if (min > taro[i] + hanako[j]) {
tarotrade = taro[i];
hanakotrade = hanako[j];
min = taro[i] + hanako[j];
// puts("1");
}
}
}
}
if (min == 201) {
puts("-1");
} else {
printf("%d %d\n", tarotrade, hanakotrade);
}
scanf("%d%d", &n, &m);
}
return (0);
}
|
[["-", 8, 9, 0, 57, 15, 23, 0, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 12, 13]]
| 0
| 309
|
#include <stdio.h>
void sorting(int x[], int first, int end) {
int t;
int i = first;
int j = end;
int p = (first + end) / 2;
int pivot = x[p];
while (1) {
while (x[i] < pivot)
i++;
while (x[j] > pivot)
j--;
if (i >= j)
break;
t = x[i];
x[i] = x[j];
x[j] = t;
i++;
j--;
}
if (first < i - 1)
sorting(x, first, i - 1);
if (j + 1 < end)
sorting(x, j + 1, end);
}
int exchange(int flag, int n[], int m[], int n_num, int m_num, int dif) {
int i = 0, j;
if (dif % 2 == 1)
goto notfound;
while (i < m_num) {
for (j = 0; j < n_num; j++) {
if (n[j] == m[i] + dif / 2)
goto found;
if (n[j] > m[i])
break;
}
i++;
}
notfound:
printf("-1\n");
return 0;
found:
if (flag == 0)
printf("%d %d\n", n[j], m[i]);
else
printf("%d %d\n", m[i], n[j]);
return 0;
}
int main() {
int n[100] = {0};
int m[100] = {0};
int n_sum, m_sum;
int n_num, m_num, i;
int dif;
scanf("%d %d", &n_num, &m_num);
while (n_num != 0) {
n_sum = 0;
m_sum = 0;
for (i = 0; i < n_num; i++) {
scanf("%d", &n[i]);
n_sum += n[i];
}
for (i = 0; i < m_num; i++) {
scanf("%d", &m[i]);
m_sum += m[i];
}
sorting(n, 0, n_num - 1);
sorting(m, 0, m_num - 1);
if (n_sum >= m_sum) {
dif = n_sum - m_sum;
exchange(0, n, m, n_num, m_num, dif);
} else {
dif = m_sum - n_sum;
exchange(1, m, n, m_num, n_num, dif);
}
scanf("%d %d", &n_num, &m_num);
}
return 0;
}
|
#include <stdio.h>
void sorting(int x[], int first, int end) {
int t;
int i = first;
int j = end;
int p = (first + end) / 2;
int pivot = x[p];
while (1) {
while (x[i] < pivot)
i++;
while (x[j] > pivot)
j--;
if (i >= j)
break;
t = x[i];
x[i] = x[j];
x[j] = t;
i++;
j--;
}
if (first < i - 1)
sorting(x, first, i - 1);
if (j + 1 < end)
sorting(x, j + 1, end);
}
int exchange(int flag, int n[], int m[], int n_num, int m_num, int dif) {
int i = 0, j;
if (dif % 2 == 1)
goto notfound;
while (i < m_num) {
for (j = 0; j < n_num; j++) {
/*printf("dif:%d n:%d m:%d\n",dif/2, j, i);*/
if (n[j] == m[i] + dif / 2)
goto found;
if (n[j] > m[i] + dif / 2)
break;
}
i++;
}
notfound:
printf("-1\n");
return 0;
found:
if (flag == 0)
printf("%d %d\n", n[j], m[i]);
else
printf("%d %d\n", m[i], n[j]);
return 0;
}
int main() {
int n[100] = {0};
int m[100] = {0};
int n_sum, m_sum;
int n_num, m_num, i;
int dif;
scanf("%d %d", &n_num, &m_num);
while (n_num != 0) {
n_sum = 0;
m_sum = 0;
for (i = 0; i < n_num; i++) {
scanf("%d", &n[i]);
n_sum += n[i];
}
for (i = 0; i < m_num; i++) {
scanf("%d", &m[i]);
m_sum += m[i];
}
/**printf("%d %d\n",n_sum, m_sum);*/
sorting(n, 0, n_num - 1);
/*for(i=0; i< n_num; i++){
printf("%d ",n[i]);
}
printf("\n");*/
sorting(m, 0, m_num - 1);
/*for(i=0; i<m_num; i++){
printf("%d ",m[i]);
}
printf("\n");*/
if (n_sum >= m_sum) {
dif = n_sum - m_sum;
exchange(0, n, m, n_num, m_num, dif);
} else {
dif = m_sum - n_sum;
exchange(1, m, n, m_num, n_num, dif);
}
scanf("%d %d", &n_num, &m_num);
}
return 0;
}
|
[["+", 0, 57, 15, 23, 0, 16, 12, 16, 17, 72], ["+", 15, 23, 0, 16, 12, 16, 12, 16, 31, 22], ["+", 15, 23, 0, 16, 12, 16, 12, 16, 17, 85], ["+", 15, 23, 0, 16, 12, 16, 12, 16, 12, 13]]
| 0
| 552
|
#include <bits/stdc++.h>
#define cinf(n, x) \
for (int i = 0; i < (n); i++) \
cin >> x[i];
typedef long long int ll;
using namespace std;
int main() {
int n, m;
while (1) {
cin >> n >> m;
vector<int> a(n), b(m);
if (n == 0 && m == 0)
break;
cinf(n, a);
cinf(m, b);
int suma = 0;
int sumb = 0;
for (int i = 0; i < n; ++i)
suma += a[i];
for (int i = 0; i < m; i++)
sumb += b[i];
int ansa = 150;
int ansb = 150;
if (suma > sumb) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (suma - sumb == (a[i] - b[j]) * 2 && b[j] + a[i] < ansa + ansb)
ansa = a[i];
ansb = b[j];
}
}
} else if (suma == sumb) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[i] == b[j] && ansa > a[i]) {
ansa = a[i];
ansb = b[j];
}
}
}
} else {
for (int j = 0; j < m; j++) {
for (int i = 0; i < n; i++) {
if (sumb - suma == (b[j] - a[i]) * 2 && b[j] + a[i] < ansa + ansb) {
ansa = a[i];
ansb = b[j];
}
}
}
}
if (ansa == 150)
cout << -1 << endl;
else
cout << ansa << " " << ansb << endl;
}
}
|
#include <bits/stdc++.h>
#define cinf(n, x) \
for (int i = 0; i < (n); i++) \
cin >> x[i];
typedef long long int ll;
using namespace std;
int main() {
int n, m;
while (1) {
cin >> n >> m;
vector<int> a(n), b(m);
if (n == 0 && m == 0)
break;
cinf(n, a);
cinf(m, b);
int suma = 0;
int sumb = 0;
for (int i = 0; i < n; ++i)
suma += a[i];
for (int i = 0; i < m; i++)
sumb += b[i];
int ansa = 150;
int ansb = 150;
if (suma > sumb) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (suma - sumb == (a[i] - b[j]) * 2 && b[j] + a[i] < ansa + ansb) {
ansa = a[i];
ansb = b[j];
}
}
}
} else if (suma == sumb) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[i] == b[j] && ansa > a[i]) {
ansa = a[i];
ansb = b[j];
}
}
}
} else {
for (int j = 0; j < m; j++) {
for (int i = 0; i < n; i++) {
if (sumb - suma == (b[j] - a[i]) * 2 && b[j] + a[i] < ansa + ansb) {
ansa = a[i];
ansb = b[j];
}
}
}
}
if (ansa == 150)
cout << -1 << endl;
else
cout << ansa << " " << ansb << endl;
}
}
|
[["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 45], ["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 46]]
| 1
| 420
|
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define INF 1000000000
#define EPS 1e-9
using namespace std;
typedef list<int> L;
typedef pair<int, int> P;
typedef vector<int> V;
typedef queue<int> Q;
typedef stack<int> S;
typedef map<string, int> M;
int sum(V v, int num) {
int res = 0;
for (int i = 0; i < v.size(); i++)
res += v[i];
return res - num;
}
int main() {
int N, M;
while (cin >> N >> M, (N && M)) {
V n, m;
for (int i = 0; i < N; i++) {
int tmp;
cin >> tmp;
n.push_back(tmp);
}
for (int i = 0; i < M; i++) {
int tmp;
cin >> tmp;
m.push_back(tmp);
}
P res = P(1000, 1000);
for (int i = 0; i < n.size(); i++) {
for (int j = 0; j < m.size(); j++) {
if (sum(m, m[i] - n[j]) - sum(n, n[j] - m[i]) == 0)
if (res.first + res.second > n[j] + m[i])
res = P(n[j], m[i]);
}
}
if (res.first == 1000)
cout << -1 << endl;
else
cout << res.first << " " << res.second << endl;
}
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define INF 1000000000
#define EPS 1e-9
using namespace std;
typedef list<int> L;
typedef pair<int, int> P;
typedef vector<int> V;
typedef queue<int> Q;
typedef stack<int> S;
typedef map<string, int> M;
int sum(V v, int num) {
int res = 0;
for (int i = 0; i < v.size(); i++)
res += v[i];
return res - num;
}
int main() {
int N, M;
while (cin >> N >> M, (N && M)) {
V n, m;
for (int i = 0; i < N; i++) {
int tmp;
cin >> tmp;
n.push_back(tmp);
}
for (int i = 0; i < M; i++) {
int tmp;
cin >> tmp;
m.push_back(tmp);
}
P res = P(1000, 1000);
for (int i = 0; i < m.size(); i++) {
for (int j = 0; j < n.size(); j++) {
if (sum(m, m[i] - n[j]) - sum(n, n[j] - m[i]) == 0)
if (res.first + res.second > n[j] + m[i])
res = P(n[j], m[i]);
}
}
if (res.first == 1000)
cout << -1 << endl;
else
cout << res.first << " " << res.second << endl;
}
return 0;
}
|
[["-", 0, 7, 15, 16, 12, 2, 63, 118, 28, 22], ["+", 0, 7, 15, 16, 12, 2, 63, 118, 28, 22]]
| 1
| 371
|
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
int i, j, k;
int n, m;
int sa, sb; // a,bの合計
int a[100], b[100];
int ans[3];
while (1) {
scanf("%d %d", &n, &m);
if ((n == 0) && (m == 0))
break;
//初期化
sa = 0;
sb = 0;
ans[0] = 0;
ans[1] = 0;
ans[2] = 201;
for (i = 0; i < 100; i++) {
a[i] = 0;
b[i] = 0;
}
//入力
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
sa += a[i];
}
for (i = 0; i < m; i++) {
scanf("%d", &b[i]);
sb += b[i];
}
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if ((sa - sb) == 2 * (a[i] - b[j])) {
if (ans[2] > (a[i] + b[j]))
ans[0] = a[i];
ans[1] = b[j];
ans[2] = (a[i] + b[j]);
}
}
}
if (ans[2] == 201) {
printf("-1\n");
} else {
printf("%d %d\n", a[0], a[1]);
}
}
//ここからテンプレ
return 0;
}
|
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
int i, j, k;
int n, m;
int sa, sb; // a,bの合計
int a[100], b[100];
int ans[3];
while (1) {
scanf("%d %d", &n, &m);
if ((n == 0) && (m == 0))
break;
//初期化
sa = 0;
sb = 0;
ans[0] = 0;
ans[1] = 0;
ans[2] = 201;
for (i = 0; i < 100; i++) {
a[i] = 0;
b[i] = 0;
}
//入力
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
sa += a[i];
}
for (i = 0; i < m; i++) {
scanf("%d", &b[i]);
sb += b[i];
}
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if ((sa - sb) == 2 * (a[i] - b[j])) {
if (ans[2] > (a[i] + b[j])) {
ans[0] = a[i];
ans[1] = b[j];
ans[2] = (a[i] + b[j]);
}
}
}
}
if (ans[2] == 201) {
printf("-1\n");
} else {
printf("%d %d\n", ans[0], ans[1]);
}
}
return 0;
}
|
[["+", 0, 57, 64, 9, 0, 57, 64, 9, 0, 45], ["+", 0, 52, 8, 9, 0, 7, 8, 9, 0, 46], ["-", 0, 1, 0, 2, 3, 4, 0, 69, 28, 22], ["+", 0, 1, 0, 2, 3, 4, 0, 69, 28, 22]]
| 1
| 370
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
int s[100], t[100], sumS, sumT;
int N, M;
bool Exists(int target) {
int *p = lower_bound(t, t + M, target);
if (p >= t + M)
return false;
if (*p == target)
return true;
return false;
}
signed main() {
while (cin >> N >> M, N || M) {
sumS = 0;
sumT = 0;
for (int i = 0; i < N; i++) {
cin >> s[i];
sumS += s[i];
}
for (int i = 0; i < M; i++) {
cin >> t[i];
sumT += t[i];
}
sort(t, t + M);
int ans1 = LLONG_MAX / 2, ans2 = LLONG_MAX / 2;
for (int i = 0; i < N; i++) {
int target = sumT - sumS + 2 * s[i];
if (target & 1 || !Exists(target / 2))
continue;
if (ans1 + ans2 > s[i] + target) {
ans1 = s[i];
ans2 = target;
}
}
if (ans1 == LLONG_MAX / 2)
puts("-1");
else
printf("%lld %lld\n", ans1, ans2);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
int s[100], t[100], sumS, sumT;
int N, M;
bool Exists(int target) {
int *p = lower_bound(t, t + M, target);
if (p >= t + M)
return false;
if (*p == target)
return true;
return false;
}
signed main() {
while (cin >> N >> M, N || M) {
sumS = 0;
sumT = 0;
for (int i = 0; i < N; i++) {
cin >> s[i];
sumS += s[i];
}
for (int i = 0; i < M; i++) {
cin >> t[i];
sumT += t[i];
}
sort(t, t + M);
int ans1 = LLONG_MAX / 2, ans2 = LLONG_MAX / 2;
for (int i = 0; i < N; i++) {
int target = sumT - sumS + 2 * s[i];
if (target & 1 || !Exists(target / 2))
continue;
target /= 2;
if (ans1 + ans2 > s[i] + target) {
ans1 = s[i];
ans2 = target;
}
}
if (ans1 == LLONG_MAX / 2)
puts("-1");
else
printf("%lld %lld\n", ans1, ans2);
}
return 0;
}
|
[["+", 0, 7, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 17, 90], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 7, 8, 9, 0, 1, 0, 35]]
| 1
| 289
|
#include <bits/stdc++.h>
using namespace std;
int main() {
while (1) {
int n, m, flower[100], tarou[100], cnt = 0, fsum = 0, tsum = 0, tchange,
fchange;
int ff, tt;
int fma = 99999, tma = 99999;
cin >> n >> m;
if (n == 0 && m == 0)
break;
for (int i = 0; i < n; i++) {
cin >> tarou[i];
tsum += tarou[i];
}
for (int i = 0; i < m; i++) {
cin >> flower[i];
fsum += flower[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
tt = tsum - tarou[j] + flower[i];
ff = fsum - flower[i] + tarou[j];
// cout << tt << " " << ff << endl;
if (tt == ff) {
cnt = 1;
tchange = tarou[j];
fchange = flower[i];
if (tma + fma > tchange + fchange) {
// cout << 1111111;
tma = tarou[j];
fma = flower[i];
}
}
}
}
if (cnt == 1)
cout << tma << " " << fma << endl;
else
cout << -1 << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
while (1) {
int n, m, flower[100], tarou[100], cnt = 0, fsum = 0, tsum = 0, tchange,
fchange;
int ff, tt;
int fma = 99999, tma = 99999;
cin >> n >> m;
if (n == 0 && m == 0)
break;
for (int i = 0; i < n; i++) {
cin >> tarou[i];
tsum += tarou[i];
}
for (int i = 0; i < m; i++) {
cin >> flower[i];
fsum += flower[i];
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
tt = tsum - tarou[j] + flower[i];
ff = fsum - flower[i] + tarou[j];
// cout << tt << " " << ff << endl;
if (tt == ff) {
cnt = 1;
tchange = tarou[j];
fchange = flower[i];
if (tma + fma > tchange + fchange) {
// cout << 1111111;
tma = tarou[j];
fma = flower[i];
}
}
}
}
if (cnt == 1)
cout << tma << " " << fma << endl;
else
cout << -1 << endl;
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22], ["-", 0, 7, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 12, 22]]
| 1
| 283
|
#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() {
int n, m;
int a[110], b[110];
while (cin >> n >> m) {
int asum = 0, bsum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
asum += a[i];
}
for (int i = 0; i < m; i++) {
cin >> b[i];
bsum += b[i];
}
pair<int, int> ans;
int diff = 10000;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (asum - a[i] + b[j] == bsum - b[j] + a[i] && a[i] + b[j] < diff) {
diff = a[i] + b[j];
ans.first = a[i];
ans.second = b[j];
}
}
}
if (diff == 10000)
cout << -1 << endl;
else
cout << ans.first << " " << ans.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() {
int n, m;
int a[110], b[110];
while (cin >> n >> m, n + m) {
int asum = 0, bsum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
asum += a[i];
}
for (int i = 0; i < m; i++) {
cin >> b[i];
bsum += b[i];
}
pair<int, int> ans;
int diff = 10000;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (asum - a[i] + b[j] == bsum - b[j] + a[i] && a[i] + b[j] < diff) {
diff = a[i] + b[j];
ans.first = a[i];
ans.second = b[j];
}
}
}
if (diff == 10000)
cout << -1 << endl;
else
cout << ans.first << " " << ans.second << endl;
}
}
|
[["+", 8, 9, 0, 52, 15, 339, 51, 34, 0, 21], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 31, 22], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 17, 72], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 12, 22]]
| 1
| 366
|
#include <stdio.h>
#include <stdlib.h>
int main() {
int N, M;
while (1) {
scanf("%d %d", &N, &M);
if (N == 0 && M == 0)
break;
int n[102] = {}, m[102] = {};
int ns = 0, ms = 0;
for (int i = 0; i < N; i++) {
scanf("%d", &n[i]);
ns += n[i];
}
for (int i = 0; i < M; i++) {
scanf("%d", &m[i]);
ms += m[i];
}
for (int i = 0; i < N; i++)
for (int j = N - 1; j > i; j--)
if (n[j] < n[j - 1]) {
int t = n[j];
n[j] = n[j - 1];
n[j - 1] = t;
}
for (int i = 0; i < M; i++)
for (int j = M - 1; j > i; j--)
if (m[j] < m[j - 1]) {
int t = m[j];
m[j] = m[j - 1];
m[j - 1] = t;
}
int d = ms - ns;
// if(d<0)d*=-1;
int x = n[N - 1], y = m[M - 1];
bool f = false;
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++)
if (ms + n[i] - m[j] == ns + m[j] - n[i] && x + y > n[i] + m[j]) {
x = n[i];
y = m[j];
f = true;
}
// if(f==true)break;
}
if (f == true)
printf("%d %d\n", x, y);
else
printf("-1\n");
}
return 0;
}
|
#include <stdio.h>
#include <stdlib.h>
int main() {
int N, M;
while (1) {
scanf("%d %d", &N, &M);
if (N == 0 && M == 0)
break;
int n[102] = {}, m[102] = {};
int ns = 0, ms = 0;
for (int i = 0; i < N; i++) {
scanf("%d", &n[i]);
ns += n[i];
}
for (int i = 0; i < M; i++) {
scanf("%d", &m[i]);
ms += m[i];
}
for (int i = 0; i < N; i++)
for (int j = N - 1; j > i; j--)
if (n[j] < n[j - 1]) {
int t = n[j];
n[j] = n[j - 1];
n[j - 1] = t;
}
for (int i = 0; i < M; i++)
for (int j = M - 1; j > i; j--)
if (m[j] < m[j - 1]) {
int t = m[j];
m[j] = m[j - 1];
m[j - 1] = t;
}
int d = ms - ns;
// if(d<0)d*=-1;
int x = n[N - 1], y = m[M - 1];
bool f = false;
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++)
if (ms + n[i] - m[j] == ns + m[j] - n[i] && x + y >= n[i] + m[j]) {
x = n[i];
y = m[j];
f = true;
}
// if(f==true)break;
}
if (f == true)
printf("%d %d\n", x, y);
else
printf("-1\n");
}
return 0;
}
|
[["-", 8, 57, 15, 339, 51, 16, 12, 16, 17, 47], ["+", 8, 57, 15, 339, 51, 16, 12, 16, 17, 20]]
| 1
| 447
|
#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 1 << 20;
int main() {
int i, j, n, m, diff, anstaro, anshanako, taro[101], hanako[101];
while (1) {
cin >> n >> m;
if (n == 0 && m == 0)
break;
anstaro = MAX;
anshanako = MAX;
diff = 0;
for (i = 0; i < n; i++) {
cin >> taro[i];
diff += taro[i];
}
for (j = 0; j < m; j++) {
cin >> hanako[j];
diff -= hanako[j];
}
// cout << " " << diff << endl;
if (diff % 2 == 1)
cout << -1 << endl;
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if ((taro[i] - hanako[j]) * 2 == diff) {
if (taro[i] + hanako[j] < anstaro + anshanako) {
anstaro = taro[i];
anshanako = hanako[j];
}
}
}
}
if (anstaro != MAX && anshanako != MAX) {
cout << anstaro << " " << anshanako << endl;
} else {
cout << -1 << endl;
}
}
return 0;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 1 << 20;
int main() {
int i, j, n, m, diff, anstaro, anshanako, taro[101], hanako[101];
while (1) {
cin >> n >> m;
if (n == 0 && m == 0)
break;
anstaro = MAX;
anshanako = MAX;
diff = 0;
for (i = 0; i < n; i++) {
cin >> taro[i];
diff += taro[i];
}
for (j = 0; j < m; j++) {
cin >> hanako[j];
diff -= hanako[j];
}
// cout << " " << diff << endl;
if (diff % 2 == 1) {
cout << -1 << endl;
continue;
}
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if ((taro[i] - hanako[j]) * 2 == diff) {
if (taro[i] + hanako[j] < anstaro + anshanako) {
anstaro = taro[i];
anshanako = hanako[j];
}
}
}
}
if (anstaro != MAX && anshanako != MAX) {
cout << anstaro << " " << anshanako << endl;
} else {
cout << -1 << endl;
}
}
return 0;
}
|
[["+", 0, 52, 8, 9, 0, 57, 64, 9, 0, 45], ["+", 8, 9, 0, 57, 64, 9, 0, 1, 0, 35], ["+", 8, 9, 0, 57, 64, 9, 0, 116, 0, 117], ["+", 0, 52, 8, 9, 0, 57, 64, 9, 0, 46]]
| 1
| 275
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
typedef pair<int, int> P;
int main() {
int n, m;
while (cin >> n >> m && n) {
int sum = 0;
vector<int> p(n), q(n);
rep(i, n) {
cin >> p[i];
sum += p[i];
}
rep(i, m) {
cin >> q[i];
sum -= q[i];
}
int ap = INF, aq = INF;
for (int pn : p)
for (int qn : q)
if (2 * (pn - qn) == sum && pn + qn < ap + aq) {
ap = pn;
aq = qn;
}
if (ap == INF) {
puts("-1");
} else {
cout << ap << ' ' << aq << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
typedef pair<int, int> P;
int main() {
int n, m;
while (cin >> n >> m && n) {
int sum = 0;
vector<int> p(n), q(m);
rep(i, n) {
cin >> p[i];
sum += p[i];
}
rep(i, m) {
cin >> q[i];
sum -= q[i];
}
int ap = INF, aq = INF;
for (int pn : p)
for (int qn : q)
if (2 * (pn - qn) == sum && pn + qn < ap + aq) {
ap = pn;
aq = qn;
}
if (ap == INF) {
puts("-1");
} else {
cout << ap << ' ' << aq << endl;
}
}
return 0;
}
|
[["-", 0, 43, 49, 53, 54, 55, 0, 56, 39, 78], ["+", 0, 43, 49, 53, 54, 55, 0, 56, 39, 78]]
| 1
| 217
|
#include <iostream>
using namespace std;
int main() {
int a, b;
int taro[100], hanako[100], tsum, hsum;
while (cin >> a >> b) {
if (a == 0 && b == 0)
break;
tsum = hsum = 0;
for (int i = 0; i < a; i++) {
cin >> taro[i];
tsum += taro[i];
}
for (int i = 0; i < b; i++) {
cin >> hanako[i];
hsum += hanako[i];
}
int min = 201, x, y;
for (int i = 0; i < a; i++) {
for (int j = 0; j < b; j++) {
int newt = tsum - taro[i] + hanako[j],
newh = hsum - hanako[j] + taro[i];
if (newt == newh && (taro[i] + hanako[j]) < min) {
min = taro[i] + hanako[j];
x = taro[i];
y = hanako[j];
}
}
}
if (min == 201)
cout << -1 << endl;
else
cout << x << " " << y << endl;
return 0;
}
}
|
#include <iostream>
using namespace std;
int main() {
int a, b;
int taro[100], hanako[100], tsum, hsum;
while (cin >> a >> b) {
if (a == 0 && b == 0)
break;
tsum = hsum = 0;
for (int i = 0; i < a; i++) {
cin >> taro[i];
tsum += taro[i];
}
for (int i = 0; i < b; i++) {
cin >> hanako[i];
hsum += hanako[i];
}
int min = 201, x, y;
for (int i = 0; i < a; i++) {
for (int j = 0; j < b; j++) {
int newt = tsum - taro[i] + hanako[j],
newh = hsum - hanako[j] + taro[i];
if (newt == newh && (taro[i] + hanako[j]) < min) {
min = taro[i] + hanako[j];
x = taro[i];
y = hanako[j];
}
}
}
if (min == 201)
cout << -1 << endl;
else
cout << x << " " << y << endl;
}
}
|
[["-", 8, 9, 0, 52, 8, 9, 0, 37, 0, 38], ["-", 8, 9, 0, 52, 8, 9, 0, 37, 0, 13], ["-", 8, 9, 0, 52, 8, 9, 0, 37, 0, 35]]
| 1
| 266
|
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
using namespace std;
vector<int> taro;
vector<int> hana;
int n, m, a;
int tarowa = 0, hanawa = 0;
int nextInt() {
int a;
cin >> a;
return a;
}
int solve() {
int exi, exj;
int min = 1000;
REP(i, n) {
REP(j, m) {
if (tarowa - taro[j] + hana[i] == hanawa - hana[i] + taro[j]) {
if (taro[j] + hana[i] < min) {
min = taro[j] + hana[i];
exi = i;
exj = j;
}
}
}
}
if (min != 1000)
cout << taro[exj] << " " << hana[exi] << endl;
else
cout << -1 << endl;
return 0;
}
int main() {
while (true) {
cin >> n >> m;
if (!n && !m)
break;
taro.resize(n);
hana.resize(m);
REP(i, n) {
a = nextInt();
taro[i] = a;
tarowa += a;
}
REP(i, m) {
a = nextInt();
hana[i] = a;
hanawa += a;
}
solve();
tarowa = 0;
hanawa = 0;
taro.clear();
hana.clear();
}
return 0;
}
|
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
using namespace std;
vector<int> taro;
vector<int> hana;
int n, m, a;
int tarowa = 0, hanawa = 0;
int nextInt() {
int a;
cin >> a;
return a;
}
int solve() {
int exi, exj;
int min = 100000;
REP(i, m) {
REP(j, n) {
if (tarowa - taro[j] + hana[i] == hanawa - hana[i] + taro[j]) {
if (taro[j] + hana[i] < min) {
min = taro[j] + hana[i];
exi = i;
exj = j;
}
}
}
}
if (min != 100000)
cout << taro[exj] << " " << hana[exi] << endl;
else
cout << -1 << endl;
return 0;
}
int main() {
while (true) {
cin >> n >> m;
if (!n && !m)
break;
taro.resize(n);
hana.resize(m);
REP(i, n) {
a = nextInt();
taro[i] = a;
tarowa += a;
}
REP(i, m) {
a = nextInt();
hana[i] = a;
hanawa += a;
}
solve();
tarowa = 0;
hanawa = 0;
taro.clear();
hana.clear();
}
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["-", 0, 14, 49, 53, 54, 55, 0, 56, 39, 78], ["+", 0, 14, 49, 53, 54, 55, 0, 56, 39, 78], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
| 1
| 377
|
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define REP(i, a, b) for (int i = a; i < b; ++i)
#define rep(i, n) REP(i, 0, n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define ALL(a) (a).begin(), (a).end()
#define ifnot(a) if (not a)
#define dump(x) cerr << #x << " = " << (x) << endl
using namespace std;
void reader(int &a) { scanf("%d", &a); }
void reader(double &a) { scanf("%lf", &a); }
void reader(char a[]) { scanf("%s", a); }
void reader(char &a) { scanf(" %c", &a); }
void reader(ll &a) { scanf("%lld", &a); }
void reader(ull &a) { scanf("%llu", &a); }
// void reader(string& a){cin >> a;};
template <class T, class U> void reader(T &t, U &u) {
reader(t);
reader(u);
}
template <class T, class U, class V> void reader(T &t, U &u, V &v) {
reader(t);
reader(u);
reader(v);
}
void writer(const int a, char c) {
printf("%d", a);
putchar(c);
}
void writer(const ll a, char c) {
printf("%lld", a);
putchar(c);
}
void writer(const ull a, char c) {
printf("%llu", a);
putchar(c);
}
void writer(const double a, char c) {
printf("%.20lf", a);
putchar(c);
}
void writer(const char a[]) { printf("%s", a); };
void writer(const char a[], char c) {
printf("%s", a);
putchar(c);
};
void writer(const char a, char c) {
putchar(a);
putchar(c);
};
template <class T> void writerLn(T t) { writer(t, '\n'); }
template <class T, class U> void writerLn(T t, U u) {
writer(t, ' ');
writer(u, '\n');
}
template <class T, class U, class V> void writerLn(T t, U u, V v) {
writer(t, ' ');
writer(u, ' ');
writer(v, '\n');
}
template <class T> void writerArr(T x[], int n) {
int i;
if (!n) {
putchar('\n');
return;
}
rep(i, n - 1) writer(x[i], ' ');
writer(x[n - 1], '\n');
}
template <class T> void writerVec(vector<T> x) {
int n = x.size();
int i;
if (!n) {
putchar('\n');
return;
}
rep(i, n - 1) writer(x[i], ' ');
writer(x[n - 1], '\n');
}
vector<string> split(const string &str, char sep) {
vector<string> v;
stringstream ss(str);
string buffer;
while (getline(ss, buffer, sep)) {
v.push_back(buffer);
}
return v;
}
// #define int ll
bool test = 1;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define MAX 300000
//.....................
ull mod = (int)1e9 + 7;
signed main(void) {
while (1) {
int n, m;
cin >> n >> m;
if (n == 0 && m == 0)
break;
int a[100];
int asum = 0;
rep(i, n) {
reader(a[i]);
asum += a[i];
}
set<int> b;
int bsum = 0;
rep(i, m) {
int buf;
reader(buf);
bsum += buf;
b.insert(buf);
}
int a1 = 10000;
int b1 = 10000;
int target = bsum - asum;
if (abs(target) % 2 == 0) {
int d = abs(target) / 2;
if (target < 0)
target *= -1;
rep(i, n) {
auto target_b = b.find(d + a[i]);
if (target_b != b.end()) {
if (a[i] + *target_b < a1 + b1) {
a1 = a[i];
b1 = *target_b;
}
}
}
}
if (a1 > 1000)
puts("-1");
else
writerLn(a1, b1);
}
return 0;
}
|
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define REP(i, a, b) for (int i = a; i < b; ++i)
#define rep(i, n) REP(i, 0, n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define ALL(a) (a).begin(), (a).end()
#define ifnot(a) if (not a)
#define dump(x) cerr << #x << " = " << (x) << endl
using namespace std;
void reader(int &a) { scanf("%d", &a); }
void reader(double &a) { scanf("%lf", &a); }
void reader(char a[]) { scanf("%s", a); }
void reader(char &a) { scanf(" %c", &a); }
void reader(ll &a) { scanf("%lld", &a); }
void reader(ull &a) { scanf("%llu", &a); }
// void reader(string& a){cin >> a;};
template <class T, class U> void reader(T &t, U &u) {
reader(t);
reader(u);
}
template <class T, class U, class V> void reader(T &t, U &u, V &v) {
reader(t);
reader(u);
reader(v);
}
void writer(const int a, char c) {
printf("%d", a);
putchar(c);
}
void writer(const ll a, char c) {
printf("%lld", a);
putchar(c);
}
void writer(const ull a, char c) {
printf("%llu", a);
putchar(c);
}
void writer(const double a, char c) {
printf("%.20lf", a);
putchar(c);
}
void writer(const char a[]) { printf("%s", a); };
void writer(const char a[], char c) {
printf("%s", a);
putchar(c);
};
void writer(const char a, char c) {
putchar(a);
putchar(c);
};
template <class T> void writerLn(T t) { writer(t, '\n'); }
template <class T, class U> void writerLn(T t, U u) {
writer(t, ' ');
writer(u, '\n');
}
template <class T, class U, class V> void writerLn(T t, U u, V v) {
writer(t, ' ');
writer(u, ' ');
writer(v, '\n');
}
template <class T> void writerArr(T x[], int n) {
int i;
if (!n) {
putchar('\n');
return;
}
rep(i, n - 1) writer(x[i], ' ');
writer(x[n - 1], '\n');
}
template <class T> void writerVec(vector<T> x) {
int n = x.size();
int i;
if (!n) {
putchar('\n');
return;
}
rep(i, n - 1) writer(x[i], ' ');
writer(x[n - 1], '\n');
}
vector<string> split(const string &str, char sep) {
vector<string> v;
stringstream ss(str);
string buffer;
while (getline(ss, buffer, sep)) {
v.push_back(buffer);
}
return v;
}
// #define int ll
bool test = 1;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define MAX 300000
//.....................
ull mod = (int)1e9 + 7;
signed main(void) {
while (1) {
int n, m;
cin >> n >> m;
if (n == 0 && m == 0)
break;
int a[100];
int asum = 0;
rep(i, n) {
reader(a[i]);
asum += a[i];
}
set<int> b;
int bsum = 0;
rep(i, m) {
int buf;
reader(buf);
bsum += buf;
b.insert(buf);
}
int a1 = 10000;
int b1 = 10000;
int target = bsum - asum;
if (abs(target) % 2 == 0) {
int d = abs(target) / 2;
if (target < 0)
d *= -1;
rep(i, n) {
auto target_b = b.find(d + a[i]);
if (target_b != b.end()) {
if (a[i] + *target_b < a1 + b1) {
a1 = a[i];
b1 = *target_b;
}
}
}
}
if (a1 > 1000)
puts("-1");
else
writerLn(a1, b1);
}
return 0;
}
|
[["-", 64, 9, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 64, 9, 0, 57, 64, 1, 0, 11, 31, 22]]
| 1
| 1,036
|
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = (n)-1; i >= 0; i--)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define REPS(i, f, n) for (int i = (f)-1; i >= (n); i--)
int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, 1, -1, 0};
void slove(int n, int m) {
vint vtaro(n);
vint vhana(n);
int sumtaro = 0, sumhana = 0;
rep(i, n) {
int tmp;
scanf("%d", &tmp);
sumtaro += tmp;
vtaro[i] = tmp;
}
sort(all(vtaro));
rep(i, m) {
int tmp;
scanf("%d", &tmp);
sumhana += tmp;
vhana[i] = tmp;
}
sort(all(vhana));
double sa = sumtaro - sumhana; //????¨??????????
rep(i, n) {
rep(j, m) {
if (vtaro[i] - vhana[j] == (sa / 2)) {
// printf("summm %d %d sa %f hahaaaa %d\n", sumtaro, sumhana, sa,
// vtaro[i] - vhana[j]);
printf("%d %d\n", vtaro[i], vhana[j]);
return;
}
}
}
printf("-1\n");
return;
}
int main(void) {
int n, m;
rep(i, 1000) {
cin >> n >> m;
if (n == 0)
break;
slove(n, m);
}
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = (n)-1; i >= 0; i--)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define REPS(i, f, n) for (int i = (f)-1; i >= (n); i--)
int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, 1, -1, 0};
void slove(int n, int m) {
vint vtaro(n);
vint vhana(m);
int sumtaro = 0, sumhana = 0;
rep(i, n) {
int tmp;
scanf("%d", &tmp);
sumtaro += tmp;
vtaro[i] = tmp;
}
sort(all(vtaro));
rep(i, m) {
int tmp;
scanf("%d", &tmp);
sumhana += tmp;
vhana[i] = tmp;
}
sort(all(vhana));
double sa = sumtaro - sumhana; //????¨??????????
rep(i, n) {
rep(j, m) {
if (vtaro[i] - vhana[j] == (sa / 2)) {
printf("%d %d\n", vtaro[i], vhana[j]);
return;
}
}
}
printf("-1\n");
return;
}
int main(void) {
int n, m;
rep(i, 1000) {
cin >> n >> m;
if (n == 0)
break;
slove(n, m);
}
return 0;
}
|
[["-", 0, 43, 49, 53, 54, 55, 0, 56, 39, 78], ["+", 0, 43, 49, 53, 54, 55, 0, 56, 39, 78]]
| 1
| 376
|
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(itr, data) \
for (__typeof((data).begin()) itr = (data).begin(); itr != (data).end(); \
++itr)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second
typedef unsigned long long UInt64;
typedef long long Int64;
const int INF = 100000000;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
using namespace std;
typedef pair<int, int> P;
int n, m;
int sum(vector<int> vec) {
int res = 0;
rep(i, vec.size()) res += vec[i];
return res;
}
void solve() {
P ans = mp(INF, INF);
vector<int> taro, hanako;
rep(i, n) {
int a;
cin >> a;
taro.pb(a);
}
rep(i, m) {
int a;
cin >> a;
hanako.pb(a);
}
rep(i, n) rep(j, m) {
swap(taro[i], hanako[j]);
if (sum(taro) == sum(hanako)) {
if (ans.fr + ans.sc > taro[i] + hanako[j]) {
ans = mp(taro[i], hanako[j]);
}
}
swap(taro[i], hanako[j]);
}
if (ans.fr == INF && ans.sc == INF)
cout << "-1" << endl;
else
cout << ans.fr << " " << ans.sc << endl;
return;
}
int main() {
while (cin >> n >> m) {
if (!(n + m))
return 0;
solve();
}
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(itr, data) \
for (__typeof((data).begin()) itr = (data).begin(); itr != (data).end(); \
++itr)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second
typedef unsigned long long UInt64;
typedef long long Int64;
const int INF = 100000000;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
using namespace std;
typedef pair<int, int> P;
int n, m;
int sum(vector<int> vec) {
int res = 0;
rep(i, vec.size()) res += vec[i];
return res;
}
void solve() {
P ans = mp(INF, INF);
vector<int> taro, hanako;
rep(i, n) {
int a;
cin >> a;
taro.pb(a);
}
rep(i, m) {
int a;
cin >> a;
hanako.pb(a);
}
rep(i, n) rep(j, m) {
swap(taro[i], hanako[j]);
if (sum(taro) == sum(hanako)) {
if (ans.fr + ans.sc > taro[i] + hanako[j]) {
ans = mp(taro[i], hanako[j]);
}
}
swap(taro[i], hanako[j]);
}
if (ans.fr == INF && ans.sc == INF)
cout << "-1" << endl;
else
cout << ans.sc << " " << ans.fr << endl;
return;
}
int main() {
while (cin >> n >> m) {
if (!(n + m))
return 0;
solve();
}
return 0;
}
|
[["-", 31, 16, 31, 16, 31, 16, 12, 118, 119, 120], ["+", 31, 16, 31, 16, 31, 16, 12, 118, 119, 120], ["-", 0, 1, 0, 16, 31, 16, 12, 118, 119, 120], ["+", 0, 1, 0, 16, 31, 16, 12, 118, 119, 120]]
| 1
| 418
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
int main(void) {
int n, m;
int a[101], b[101];
bool flag;
while (cin >> n >> m && n) {
rep(i, n) scanf("%d", &a[i]);
rep(i, m) scanf("%d", &b[i]);
int suma = 0, sumb = 0;
rep(i, n) suma += a[i];
rep(i, m) sumb += b[i];
flag = false;
int ans_a = INT_MAX / 2, ans_b = INT_MAX / 2;
rep(i, n) {
rep(j, n) {
if (suma - sumb == 2 * (a[i] - b[j])) {
if (ans_a + ans_b > a[i] + b[j]) {
ans_a = a[i];
ans_b = b[j];
flag = true;
}
}
}
}
if (flag)
cout << ans_a << " " << ans_b << endl;
else
cout << -1 << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
int main(void) {
int n, m;
int a[101], b[101];
bool flag;
while (cin >> n >> m && n) {
rep(i, n) scanf("%d", &a[i]);
rep(i, m) scanf("%d", &b[i]);
int suma = 0, sumb = 0;
rep(i, n) suma += a[i];
rep(i, m) sumb += b[i];
flag = false;
int ans_a = INT_MAX / 2, ans_b = INT_MAX / 2;
rep(i, n) {
rep(j, m) {
if (suma - sumb == 2 * (a[i] - b[j])) {
if (ans_a + ans_b > a[i] + b[j]) {
ans_a = a[i];
ans_b = b[j];
flag = true;
}
}
}
}
if (flag)
cout << ans_a << " " << ans_b << endl;
else
cout << -1 << endl;
}
}
|
[["-", 0, 14, 49, 53, 54, 55, 0, 56, 39, 78], ["+", 0, 14, 49, 53, 54, 55, 0, 56, 39, 78]]
| 1
| 244
|
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main() {
int a, b;
while (cin >> a >> b, a | b) {
map<int, vector<int>> l;
vector<vector<int>> s;
vector<int> c(a);
vector<int> d(b);
int x, y;
x = y = 0;
for (int e = 0; e < a; e++) {
cin >> c[e];
x += c[e];
}
for (int f = 0; f < b; f++) {
cin >> d[f];
y += d[f];
}
x = (x - y) / 2;
for (int g = 0; g < a; g++) {
for (int h = 0; h < b; h++) {
if (c[g] - d[h] == x) {
vector<int> i(2);
i[0] = c[g];
i[1] = d[h];
s.push_back(i);
}
}
}
if (s.size() == 0)
cout << -1 << endl;
else {
for (auto j : s) {
l[j[0] + j[1]];
l[j[0] + j[1]] = j;
}
auto q = l.begin();
cout << q->second[0] << " " << q->second[1] << endl;
}
}
}
|
#include <iostream>
#include <map>
#include <string>
#include <vector>
#define int double
using namespace std;
signed main() {
signed a, b;
while (cin >> a >> b, a | b) {
map<int, vector<int>> l;
vector<vector<int>> s;
vector<int> c(a);
vector<int> d(b);
int x, y;
x = y = 0;
for (int e = 0; e < a; e++) {
cin >> c[e];
x += c[e];
}
for (int f = 0; f < b; f++) {
cin >> d[f];
y += d[f];
}
x = (x - y) / 2;
for (int g = 0; g < a; g++) {
for (int h = 0; h < b; h++) {
if (c[g] - d[h] == x) {
vector<int> i(2);
i[0] = c[g];
i[1] = d[h];
s.push_back(i);
}
}
}
if (s.size() == 0)
cout << -1 << endl;
else {
for (auto j : s) {
l[j[0] + j[1]];
l[j[0] + j[1]] = j;
}
auto q = l.begin();
cout << q->second[0] << " " << q->second[1] << endl;
}
}
}
|
[["+", 36, 36, 36, 36, 0, 30, 0, 58, 0, 148], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 141, 22], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["-", 36, 36, 36, 36, 0, 30, 0, 14, 39, 40], ["+", 36, 36, 0, 30, 0, 14, 39, 86, 0, 156], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 156]]
| 1
| 327
|
#include <iostream>
using namespace std;
int sum(int *, int);
int main(void) {
int n, m, sub, flag, cnum1, cnum2, i, j, sum1, sum2;
cin >> n >> m;
int a[101], b[101];
while ((n == 0 && m == 0) != 1) {
//
for (i = 0; i < n; i++) {
cin >> a[i];
}
for (j = 0; j < m; j++) {
cin >> b[j];
}
sub = sum(a, n) - sum(b, m);
//
flag = 0;
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if ((a[i] - b[j]) * 2 == sub) {
if (flag == 0) {
cnum1 = a[i];
cnum2 = b[j];
flag++;
} else {
if (a[i] + b[j] < cnum1 + cnum2) {
cnum1 = a[i];
cnum2 = b[j];
}
}
}
}
}
if (flag == 0) {
cout << "-1\n" << endl;
} else {
cout << cnum1 << " " << cnum2 << endl;
}
cin >> n >> m;
}
return 0;
}
int sum(int *p, int n) {
int s = 0, i;
for (i = 0; i < n; i++)
s += p[i];
return s;
}
|
#include <iostream>
using namespace std;
int sum(int *, int);
int main(void) {
int n, m, sub, flag, cnum1, cnum2, i, j, sum1, sum2;
cin >> n >> m;
int a[101], b[101];
while ((n == 0 && m == 0) != 1) {
//
for (i = 0; i < n; i++) {
cin >> a[i];
}
for (j = 0; j < m; j++) {
cin >> b[j];
}
sub = sum(a, n) - sum(b, m);
//
flag = 0;
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if ((a[i] - b[j]) * 2 == sub) {
if (flag == 0) {
cnum1 = a[i];
cnum2 = b[j];
flag++;
} else {
if (a[i] + b[j] < cnum1 + cnum2) {
cnum1 = a[i];
cnum2 = b[j];
}
}
}
}
}
if (flag == 0) {
cout << "-1" << endl;
} else {
cout << cnum1 << " " << cnum2 << endl;
}
cin >> n >> m;
}
return 0;
}
int sum(int *p, int n) {
int s = 0, i;
for (i = 0; i < n; i++)
s += p[i];
return s;
}
|
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 44]]
| 1
| 335
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int sn[100], sm[100];
int i, j, n, m, cn = 0, cm = 0;
cin >> n >> m;
while (n != 0 && m != 0) {
cn = 0;
cm = 0;
for (i = 0; i < n; i++) {
cin >> sn[i];
cn += sn[i];
}
for (j = 0; j < m; j++) {
cin >> sm[j];
cm += sm[j];
}
sort(&sn[0], &sn[n]);
sort(&sm[0], &sm[m]);
i = 0;
j = 0;
// printf("%d %d\n",cm,cn);
while (i < n && j < m) {
// printf("%d %d %d %d %d
// %d\n",i,j,sn[i],sm[j],cm-sm[j]+sn[i],cn+sm[j]-sn[i]);
if (cm + sn[i] - sm[j] < cn + sm[j] - sn[i]) {
i++;
} else if (cm + sn[i] - sm[j] > cn + sm[j] - sn[i]) {
j++;
} else if (cm + sn[i] - sm[j] == cn + sm[j] - sn[i]) {
cout << sn[i] << sm[j] << endl;
break;
}
}
if (!(i < n && j < m))
cout << "-1" << endl;
cin >> n >> m;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int sn[100], sm[100];
int i, j, n, m, cn = 0, cm = 0;
cin >> n >> m;
while (n != 0 && m != 0) {
cn = 0;
cm = 0;
for (i = 0; i < n; i++) {
cin >> sn[i];
cn += sn[i];
}
for (j = 0; j < m; j++) {
cin >> sm[j];
cm += sm[j];
}
sort(&sn[0], &sn[n]);
sort(&sm[0], &sm[m]);
i = 0;
j = 0;
// printf("%d %d\n",cm,cn);
while (i < n && j < m) {
// printf("%d %d %d %d %d
// %d\n",i,j,sn[i],sm[j],cm-sm[j]+sn[i],cn+sm[j]-sn[i]);
if (cm + sn[i] - sm[j] < cn + sm[j] - sn[i]) {
i++;
} else if (cm + sn[i] - sm[j] > cn + sm[j] - sn[i]) {
j++;
} else if (cm + sn[i] - sm[j] == cn + sm[j] - sn[i]) {
cout << sn[i] << " " << sm[j] << endl;
break;
}
}
if (!(i < n && j < m))
cout << "-1" << endl;
cin >> n >> m;
}
return 0;
}
|
[["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 62], ["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 64, 9, 0, 1, 0, 16, 31, 16, 17, 151]]
| 1
| 317
|
#include <iostream>
using namespace std;
int main() {
while (1) {
int n, m;
cin >> n >> m;
if (m == 0)
break;
int t[n], h[n];
for (int i = 0; i < n; i++)
cin >> t[i];
for (int i = 0; i < m; i++)
cin >> h[i];
int sumt = 0, sumh = 0;
for (int i = 0; i < n; i++)
sumt += t[i];
for (int i = 0; i < m; i++)
sumh += h[i];
int x, y, min = 1000;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (sumt - t[i] + h[j] == sumh + t[i] - h[j]) {
if (t[i] + h[j] < min) {
min = t[i] + h[j];
x = t[i];
y = h[j];
}
}
}
}
if (min == 1000)
cout << -1 << endl;
else
cout << x << ' ' << y << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
while (1) {
int n, m;
cin >> n >> m;
if (m == 0)
break;
int t[n], h[m];
for (int i = 0; i < n; i++)
cin >> t[i];
for (int i = 0; i < m; i++)
cin >> h[i];
int sumt = 0, sumh = 0;
for (int i = 0; i < n; i++)
sumt += t[i];
for (int i = 0; i < m; i++)
sumh += h[i];
int x, y, min = 1000;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (sumt - t[i] + h[j] == sumh + t[i] - h[j]) {
if (t[i] + h[j] < min) {
min = t[i] + h[j];
x = t[i];
y = h[j];
}
}
}
}
if (min == 1000)
cout << -1 << endl;
else
cout << x << ' ' << y << endl;
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 43, 49, 80, 81, 22], ["+", 0, 52, 8, 9, 0, 43, 49, 80, 81, 22]]
| 1
| 280
|
#include <stdio.h>
int main() {
int n, m, suma = 0, sumb = 0, x, sa[100], sb[100], i, j, blank, a;
while (1) {
scanf("%d %d", &n, &m);
if (n == 0 && m == 0)
break;
suma = 0;
sumb = 0;
for (i = 0; i < n; i++) {
scanf("%d", &sa[i]);
suma += sa[i];
}
for (j = 0; j < m; j++) {
scanf("%d", &sb[j]);
sumb += sb[j];
}
x = suma - sumb;
if (x % 2 == 1 || x * -1 % 2 == 1) {
printf("-1\n");
continue;
}
x /= 2;
for (i = 0; i < n - 1; i++) {
for (j = 0; j < n - 1; j++) {
if (sa[j] > sa[j + 1]) {
blank = sa[j];
sa[j] = sa[j + 1];
sa[j + 1] = blank;
}
}
}
for (i = 0; i < n - 1; i++) {
for (j = 0; j < n - 1; j++) {
if (sb[j] > sb[j + 1]) {
blank = sb[j];
sb[j] = sb[j + 1];
sb[j + 1] = blank;
}
}
}
// for(i = 0; i < n; i++) printf("%d\n",sa[i]);
// for(i = 0; i < m; i++) printf("%d\n",sb[i]);
// printf("\n");
// printf("%d %d %d\n",x,suma,sumb);
a = 0;
if (x <= 0) {
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if (sa[i] - sb[j] == x) {
printf("%d %d\n", sa[i], sb[j]);
a = 1;
break;
}
}
if (a == 1)
break;
}
} else {
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if (sa[i] - sb[j] == x) {
printf("%d %d\n", sa[i], sb[j]);
a = 1;
break;
}
}
if (a == 1)
break;
}
}
if (a == 0)
printf("-1\n");
}
return 0;
}
|
#include <stdio.h>
int main() {
int n, m, suma = 0, sumb = 0, x, sa[100], sb[100], i, j, blank, a, sumx;
while (1) {
scanf("%d %d", &n, &m);
if (n == 0 && m == 0)
break;
suma = 0;
sumb = 0;
for (i = 0; i < n; i++) {
scanf("%d", &sa[i]);
suma += sa[i];
}
for (j = 0; j < m; j++) {
scanf("%d", &sb[j]);
sumb += sb[j];
}
x = suma - sumb;
if (x % 2 == 1 || x * -1 % 2 == 1) {
printf("-1\n");
continue;
}
x /= 2;
for (i = 0; i < n - 1; i++) {
for (j = 0; j < n - 1; j++) {
if (sa[j] > sa[j + 1]) {
blank = sa[j];
sa[j] = sa[j + 1];
sa[j + 1] = blank;
}
}
}
for (i = 0; i < m - 1; i++) {
for (j = 0; j < m - 1; j++) {
if (sb[j] > sb[j + 1]) {
blank = sb[j];
sb[j] = sb[j + 1];
sb[j + 1] = blank;
}
}
}
// for(i = 0; i < n; i++) printf("%d\n",sa[i]);
// for(i = 0; i < m; i++) printf("%d\n",sb[i]);
// printf("\n");
// printf("%d %d %d\n",x,suma,sumb);
a = 0;
if (x <= 0) {
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if (sa[i] - sb[j] == x) {
printf("%d %d\n", sa[i], sb[j]);
a = 1;
break;
}
}
if (a == 1)
break;
}
} else {
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if (sa[i] - sb[j] == x) {
printf("%d %d\n", sa[i], sb[j]);
a = 1;
break;
}
}
if (a == 1)
break;
}
}
if (a == 0)
printf("-1\n");
}
return 0;
}
|
[["+", 0, 30, 0, 14, 8, 9, 0, 43, 0, 21], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 31, 22], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 31, 22]]
| 1
| 536
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, temp, tempa, c, i;
while (1) {
cin >> n >> m;
if (n == m && n == 0)
break;
int a[n], b[m], suma = 0, sumb = 0, d = 0;
for (i = 0; i < n; i++) {
cin >> a[i];
suma += a[i];
}
for (i = 0; i < m; i++) {
cin >> b[i];
sumb += b[i];
}
for (i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (a[i] > a[j]) {
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
for (i = 0; i < m - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (b[i] > b[j]) {
temp = b[i];
b[i] = b[j];
b[j] = temp;
}
}
}
if (suma > sumb) {
c = suma - sumb;
if (c % 2 == 1) {
cout << -1 << endl;
} else {
c = c / 2;
for (i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (c == a[i] - b[j]) {
cout << a[i] << ' ' << b[j] << endl;
d = 1;
break;
}
}
if (d == 1) {
break;
}
}
if (i == n) {
cout << -1 << endl;
}
}
} else {
c = sumb - suma;
if (c % 2 == 1) {
cout << -1 << endl;
} else {
c = c / 2;
for (i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (c == b[i] - a[j]) {
cout << a[j] << ' ' << b[i] << endl;
d = 1;
break;
}
}
if (d == 1) {
break;
}
}
if (i == m) {
cout << -1 << endl;
}
}
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, temp, tempa, c, i;
while (1) {
cin >> n >> m;
if (n == m && n == 0)
break;
int a[n], b[m], suma = 0, sumb = 0, d = 0;
for (i = 0; i < n; i++) {
cin >> a[i];
suma += a[i];
}
for (i = 0; i < m; i++) {
cin >> b[i];
sumb += b[i];
}
for (i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (a[i] > a[j]) {
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
for (i = 0; i < m - 1; i++) {
for (int j = i + 1; j < m; j++) {
if (b[i] > b[j]) {
temp = b[i];
b[i] = b[j];
b[j] = temp;
}
}
}
if (suma > sumb) {
c = suma - sumb;
if (c % 2 == 1) {
cout << -1 << endl;
} else {
c = c / 2;
for (i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (c == a[i] - b[j]) {
cout << a[i] << ' ' << b[j] << endl;
d = 1;
break;
}
}
if (d == 1) {
break;
}
}
if (i == n) {
cout << -1 << endl;
}
}
} else {
c = sumb - suma;
if (c % 2 == 1) {
cout << -1 << endl;
} else {
c = c / 2;
for (i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (c == b[i] - a[j]) {
cout << a[j] << ' ' << b[i] << endl;
d = 1;
break;
}
}
if (d == 1) {
break;
}
}
if (i == m) {
cout << -1 << endl;
}
}
}
}
}
|
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 12, 22]]
| 1
| 539
|
#include "iostream"
using namespace std;
int main() {
while (1) {
int n, m, t[100], h[100], sumt = 0, sumh = 0, mint = 101, minh = 101;
cin >> n >> m;
if (n == 0 && m == 0)
break;
for (int i = 0; i < n; i++) {
cin >> t[i];
sumt += t[i];
}
for (int i = 0; i < m; i++) {
cin >> h[i];
sumh += h[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; i++) {
if (sumt - t[i] + h[j] == sumh - h[j] + t[i]) {
if (h[j] + t[i] < mint + minh) {
mint = t[i];
minh = h[j];
}
}
}
}
if (mint == 101 && minh == 101)
cout << "-1" << endl;
else
cout << mint << " " << minh << endl;
}
return 0;
}
|
#include "iostream"
using namespace std;
int main() {
while (1) {
int n, m, t[100], h[100], sumt = 0, sumh = 0, mint = 101, minh = 101;
cin >> n >> m;
if (n == 0 && m == 0)
break;
for (int i = 0; i < n; i++) {
cin >> t[i];
sumt += t[i];
}
for (int i = 0; i < m; i++) {
cin >> h[i];
sumh += h[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (sumt - t[i] + h[j] == sumh - h[j] + t[i]) {
if (h[j] + t[i] < mint + minh) {
mint = t[i];
minh = h[j];
}
}
}
}
if (mint == 101 && minh == 101)
cout << "-1" << endl;
else
cout << mint << " " << minh << endl;
}
return 0;
}
|
[["-", 0, 7, 8, 9, 0, 7, 26, 27, 28, 22], ["+", 0, 7, 8, 9, 0, 7, 26, 27, 28, 22]]
| 1
| 255
|
#include <bits/stdc++.h>
#define FOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000 // 2000000000
#define LLINF 1000000000000000000 // 9000000000000000000
#define PI 3.14159265358979
using namespace std;
typedef long long int ll;
typedef pair<long long int, long long int> P;
int main(void) {
while (1) {
bool flag = true;
int n, m;
int post = -1;
int posh = -1;
int mini = INF;
int sa = 0;
int tasu = 0;
int hasu = 0;
int taro[101] = {};
int hana[101] = {};
cin >> n >> m;
if (n == 0 && m == 0) {
break;
}
FOR(i, 1, n) {
cin >> taro[i];
tasu += taro[i];
}
FOR(i, 1, m) {
cin >> hana[i];
hasu += hana[i];
}
sa = tasu - hasu;
if (sa % 2 == 1 || sa % 2 == -1) {
flag = false;
}
FOR(i, 1, n) {
FOR(t, 1, m) {
if (sa / 2 == taro[i] - hana[t]) {
if (mini > taro[i] + hana[t]) {
mini = taro[i] + hana[t];
post = i;
posh = t;
}
}
}
}
if (post == -1) {
flag = false;
}
if (flag) {
cout << taro[post] << " " << hana[posh] << endl;
} else {
cout << -1 << endl;
}
cout << endl;
}
}
|
#include <bits/stdc++.h>
#define FOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000 // 2000000000
#define LLINF 1000000000000000000 // 9000000000000000000
#define PI 3.14159265358979
using namespace std;
typedef long long int ll;
typedef pair<long long int, long long int> P;
int main(void) {
while (1) {
bool flag = true;
int n, m;
int post = -1;
int posh = -1;
int mini = INF;
int sa = 0;
int tasu = 0;
int hasu = 0;
int taro[101] = {};
int hana[101] = {};
cin >> n >> m;
if (n == 0 && m == 0) {
break;
}
FOR(i, 1, n) {
cin >> taro[i];
tasu += taro[i];
}
FOR(i, 1, m) {
cin >> hana[i];
hasu += hana[i];
}
sa = tasu - hasu;
if (sa % 2 == 1 || sa % 2 == -1) {
flag = false;
}
FOR(i, 1, n) {
FOR(t, 1, m) {
if (sa / 2 == taro[i] - hana[t]) {
if (mini > taro[i] + hana[t]) {
mini = taro[i] + hana[t];
post = i;
posh = t;
}
}
}
}
if (post == -1) {
flag = false;
}
if (flag) {
cout << taro[post] << " " << hana[posh] << endl;
} else {
cout << -1 << endl;
}
}
}
|
[["-", 0, 52, 8, 9, 0, 1, 0, 16, 31, 22], ["-", 0, 52, 8, 9, 0, 1, 0, 16, 17, 151], ["-", 0, 52, 8, 9, 0, 1, 0, 16, 12, 22], ["-", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 1
| 349
|
#include <bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int, int>
#define PLL pair<ll, ll>
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define RFOR(i, m, n) for (int i = m; i >= n; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define all(a) a.begin(), a.end()
const int vx[4] = {0, 1, 0, -1};
const int vy[4] = {1, 0, -1, 0};
#define PI 3.14159265
void f(int n, int m) {
int a[100], b[100];
int suma = 0, sumb = 0;
rep(i, n) {
cin >> a[i];
suma += a[i];
}
rep(i, m) {
cin >> b[i];
sumb += b[i];
}
sort(a, a + n);
sort(b, b + n);
rep(i, n) {
rep(j, m) {
if (suma - a[i] + b[j] == sumb - b[j] + a[i]) {
cout << a[i] << ' ' << b[j] << endl;
return;
}
}
}
cout << -1 << endl;
}
int main() {
while (1) {
int n, m;
cin >> n >> m;
if (n == 0)
break;
f(n, m);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int, int>
#define PLL pair<ll, ll>
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define RFOR(i, m, n) for (int i = m; i >= n; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define all(a) a.begin(), a.end()
const int vx[4] = {0, 1, 0, -1};
const int vy[4] = {1, 0, -1, 0};
#define PI 3.14159265
void f(int n, int m) {
int a[100], b[100];
int suma = 0, sumb = 0;
rep(i, n) {
cin >> a[i];
suma += a[i];
}
rep(i, m) {
cin >> b[i];
sumb += b[i];
}
sort(a, a + n);
sort(b, b + m);
rep(i, n) {
rep(j, m) {
if (suma - a[i] + b[j] == sumb - b[j] + a[i]) {
cout << a[i] << ' ' << b[j] << endl;
return;
}
}
}
cout << -1 << endl;
}
int main() {
while (1) {
int n, m;
cin >> n >> m;
if (n == 0)
break;
f(n, m);
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 22], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 22]]
| 1
| 307
|
#include <cstdio>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main() {
while (1) {
int n, m, tarou_ch = 0, hanako_ch = 0, min = 201;
scanf("%d%d", &n, &m);
if (n == 0 && m == 0)
break;
int input;
vector<int> tarou, hanako;
for (int i = 0; i < n; i++) {
scanf("%d", &input);
tarou.push_back(input);
}
for (int i = 0; i < m; i++) {
scanf("%d", &input);
hanako.push_back(input);
}
vector<int>::iterator v1 = tarou.begin(), v2 = hanako.begin();
int tarou_sum = accumulate(tarou.begin(), tarou.end(), 0);
int hanako_sum = accumulate(hanako.begin(), hanako.end(), 0);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
// // printf("test:%d %d\n", tarou_sum-*v1+*v2, hanako_sum+*v1-*v2);
// printf("test:%d %d\n", *v1, *v2);
if ((tarou_sum - *v1 + *v2) == (hanako_sum + *v1 - *v2)) {
if (*v1 + *v2 < min) {
min = *v1 + *v2;
tarou_ch = *v1;
hanako_ch = *v2;
}
}
v2++;
}
v1++;
v2 = hanako.begin();
}
if (min == 201) {
printf("-1");
} else
printf("%d %d\n", tarou_ch, hanako_ch);
}
}
|
#include <cstdio>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main() {
while (1) {
int n, m, tarou_ch = 0, hanako_ch = 0, min = 201;
scanf("%d%d", &n, &m);
if (n == 0 && m == 0)
break;
int input;
vector<int> tarou, hanako;
for (int i = 0; i < n; i++) {
scanf("%d", &input);
tarou.push_back(input);
}
for (int i = 0; i < m; i++) {
scanf("%d", &input);
hanako.push_back(input);
}
vector<int>::iterator v1 = tarou.begin(), v2 = hanako.begin();
int tarou_sum = accumulate(tarou.begin(), tarou.end(), 0);
int hanako_sum = accumulate(hanako.begin(), hanako.end(), 0);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
// // printf("test:%d %d\n", tarou_sum-*v1+*v2, hanako_sum+*v1-*v2);
// printf("test:%d %d\n", *v1, *v2);
if ((tarou_sum - *v1 + *v2) == (hanako_sum + *v1 - *v2)) {
if (*v1 + *v2 < min) {
min = *v1 + *v2;
tarou_ch = *v1;
hanako_ch = *v2;
}
}
v2++;
}
v1++;
v2 = hanako.begin();
}
if (min == 201) {
printf("-1\n");
} else
printf("%d %d\n", tarou_ch, hanako_ch);
}
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 1
| 335
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(T) T.begin(), T.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
const int INF = 1 << 24;
int main(void) {
int N, M;
int Ntotal, Mtotal;
int n[100], m[100];
int min;
while (true) {
Ntotal = 0;
Mtotal = 0;
min = INF;
cin >> N >> M;
if (N == M && N == 0)
break;
rep(i, N) {
cin >> n[i];
Ntotal += n[i];
}
rep(i, M) {
cin >> m[i];
Mtotal += m[i];
}
if (Mtotal == Ntotal) {
rep(i, N) {
rep(j, M) {
if (n[i] == m[j] && min > n[i])
min = n[i];
}
}
if (min == INF)
cout << -1 << endl;
else
cout << min << ' ' << min << endl;
} else {
int tem1 = INF, tem2 = INF;
min = abs(Ntotal - Mtotal);
rep(i, N) {
rep(j, M) {
if (abs(n[i] - m[j]) * 2 == min && tem1 + tem2 > n[i] + m[j]) {
tem1 = n[i];
tem2 = m[j];
}
}
}
if (tem1 == tem2)
cout << -1 << endl;
else
cout << tem1 << ' ' << tem2 << endl;
}
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(T) T.begin(), T.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
const int INF = 1 << 24;
int main(void) {
int N, M;
int Ntotal, Mtotal;
int n[100], m[100];
int min;
while (true) {
Ntotal = 0;
Mtotal = 0;
min = INF;
cin >> N >> M;
if (N == M && N == 0)
break;
rep(i, N) {
cin >> n[i];
Ntotal += n[i];
}
rep(i, M) {
cin >> m[i];
Mtotal += m[i];
}
if (Mtotal == Ntotal) {
rep(i, N) {
rep(j, M) {
if (n[i] == m[j] && min > n[i])
min = n[i];
}
}
if (min == INF)
cout << -1 << endl;
else
cout << min << ' ' << min << endl;
} else {
int tem1 = INF, tem2 = INF;
min = Ntotal - Mtotal;
rep(i, N) {
rep(j, M) {
if ((n[i] - m[j]) * 2 == min && tem1 + tem2 > n[i] + m[j]) {
tem1 = n[i];
tem2 = m[j];
}
}
}
if (tem1 == tem2)
cout << -1 << endl;
else
cout << tem1 << ' ' << tem2 << endl;
}
}
return 0;
}
|
[["-", 0, 9, 0, 1, 0, 11, 12, 2, 63, 22], ["-", 0, 1, 0, 11, 12, 2, 3, 4, 0, 24], ["-", 0, 1, 0, 11, 12, 2, 3, 4, 0, 25], ["-", 51, 16, 31, 16, 31, 16, 31, 2, 63, 22]]
| 1
| 392
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define reps(i, f, n) for (int i = f; i < int(n); i++)
#define rep(i, n) reps(i, 0, n)
int main() {
while (1) {
int a, b;
int t[111];
int h[111];
cin >> a >> b;
if (a == 0 && b == 0)
break;
rep(i, a) cin >> t[i];
rep(i, b) cin >> h[i];
int inf = 1111111111;
int mini = inf;
int ans1, ans2;
rep(i, a) {
rep(j, b) {
swap(t[i], h[j]);
int sumt = 0;
int sumh = 0;
rep(k, a) sumt += t[k];
rep(k, b) sumh += h[k];
if (sumt == sumh) {
int r = t[i] + h[j];
if (r < mini) {
ans1 = t[i];
ans2 = h[j];
mini = r;
;
}
}
swap(t[i], h[j]);
}
}
if (mini == inf)
puts("-1");
else
printf("%d %d\n", ans1, ans2);
}
}
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define reps(i, f, n) for (int i = f; i < int(n); i++)
#define rep(i, n) reps(i, 0, n)
int main() {
while (1) {
int a, b;
int t[111];
int h[111];
cin >> a >> b;
if (a == 0 && b == 0)
break;
rep(i, a) cin >> t[i];
rep(i, b) cin >> h[i];
int inf = 1111111111;
int mini = inf;
int ans1, ans2;
rep(i, a) {
rep(j, b) {
swap(t[i], h[j]);
int sumt = 0;
int sumh = 0;
rep(k, a) sumt += t[k];
rep(k, b) sumh += h[k];
if (sumt == sumh) {
int r = t[i] + h[j];
if (r < mini) {
ans1 = t[i];
ans2 = h[j];
mini = r;
;
}
}
swap(t[i], h[j]);
}
}
if (mini == inf)
puts("-1");
else
printf("%d %d\n", ans2, ans1);
}
}
|
[["-", 75, 76, 0, 1, 0, 2, 3, 4, 0, 22], ["-", 75, 76, 0, 1, 0, 2, 3, 4, 0, 21], ["+", 75, 76, 0, 1, 0, 2, 3, 4, 0, 21], ["+", 75, 76, 0, 1, 0, 2, 3, 4, 0, 22]]
| 1
| 276
|
import java.util.Arrays;
import java.util.Scanner;
public class Main {
Scanner in = new Scanner(System.in);
int n, w, d;
int[] W = new int[102];
int[] D = new int[102];
int[] area = new int[102];
final int INF = 100001;
public void run() {
while (true) {
n = in.nextInt();
w = in.nextInt();
d = in.nextInt();
if ((n | w | d) == 0)
break;
Arrays.fill(W, INF);
Arrays.fill(D, INF);
Arrays.fill(area, INF);
W[0] = w;
D[0] = d;
area[0] = w * d;
int w1, w2, d1, d2;
for (int i = 0; i < n; i++) {
/*
for (int j = 0; j < area.length; j++) {
if (area[j] == INF) break;
System.out.print(area[j] + " ");
}
System.out.println();
for (int j = 0; j < area.length; j++) {
if (area[j] == INF) break;
System.out.print(W[j] + " ");
}
System.out.println();
for (int j = 0; j < area.length; j++) {
if (area[j] == INF) break;
System.out.print(D[j] + " ");
}
System.out.println();
*/
int next = in.nextInt() - 1;
int nw = W[next];
int nd = D[next];
for (int j = next; j < i; j++) {
area[j] = area[j + 1];
D[j] = D[j + 1];
W[j] = W[j + 1];
}
int pos = in.nextInt();
for (; pos > (nw + nd) * 2; pos -= (nw + nd) * 2)
;
if (pos < nw) {
d1 = d2 = nd;
w1 = pos;
w2 = nw - pos;
} else if (pos < nw + nd) {
pos -= nw;
w1 = w2 = nw;
d1 = pos;
d2 = nd - pos;
} else if (pos < nw * 2 + nd) {
pos -= (nd + nw);
d1 = d2 = nd;
w1 = pos;
w2 = nw - pos;
} else {
pos -= (nd + nw * 2);
w1 = w2 = nw;
d1 = pos;
d2 = nd - pos;
}
if (w1 * d1 > w2 * d2) {
int temp = w1;
w1 = w2;
w2 = temp;
temp = d1;
d1 = d2;
d2 = temp;
}
W[i] = w1;
W[i + 1] = w2;
D[i] = d1;
D[i + 1] = d2;
area[i] = w1 * d1;
area[i + 1] = w2 * d2;
}
Arrays.sort(area);
System.out.println(area[0]);
for (int i = 1; i < area.length; i++) {
if (area[i] == INF)
break;
System.out.print(" " + area[i]);
}
System.out.println();
}
}
public static void main(String args[]) { new Main().run(); }
}
|
import java.util.Arrays;
import java.util.Scanner;
public class Main {
Scanner in = new Scanner(System.in);
int n, w, d;
int[] W = new int[102];
int[] D = new int[102];
int[] area = new int[102];
final int INF = 100001;
public void run() {
while (true) {
n = in.nextInt();
w = in.nextInt();
d = in.nextInt();
if ((n | w | d) == 0)
break;
Arrays.fill(W, INF);
Arrays.fill(D, INF);
Arrays.fill(area, INF);
W[0] = w;
D[0] = d;
area[0] = w * d;
int w1, w2, d1, d2;
for (int i = 0; i < n; i++) {
/*
for (int j = 0; j < area.length; j++) {
if (area[j] == INF) break;
System.out.print(area[j] + " ");
}
System.out.println();
for (int j = 0; j < area.length; j++) {
if (area[j] == INF) break;
System.out.print(W[j] + " ");
}
System.out.println();
for (int j = 0; j < area.length; j++) {
if (area[j] == INF) break;
System.out.print(D[j] + " ");
}
System.out.println();
*/
int next = in.nextInt() - 1;
int nw = W[next];
int nd = D[next];
for (int j = next; j < i; j++) {
area[j] = area[j + 1];
D[j] = D[j + 1];
W[j] = W[j + 1];
}
int pos = in.nextInt();
for (; pos > (nw + nd) * 2; pos -= (nw + nd) * 2)
;
if (pos < nw) {
d1 = d2 = nd;
w1 = pos;
w2 = nw - pos;
} else if (pos < nw + nd) {
pos -= nw;
w1 = w2 = nw;
d1 = pos;
d2 = nd - pos;
} else if (pos < nw * 2 + nd) {
pos -= (nd + nw);
d1 = d2 = nd;
w1 = pos;
w2 = nw - pos;
} else {
pos -= (nd + nw * 2);
w1 = w2 = nw;
d1 = pos;
d2 = nd - pos;
}
if (w1 * d1 > w2 * d2) {
int temp = w1;
w1 = w2;
w2 = temp;
temp = d1;
d1 = d2;
d2 = temp;
}
W[i] = w1;
W[i + 1] = w2;
D[i] = d1;
D[i + 1] = d2;
area[i] = w1 * d1;
area[i + 1] = w2 * d2;
}
Arrays.sort(area);
System.out.print(area[0]);
for (int i = 1; i < area.length; i++) {
if (area[i] == INF)
break;
System.out.print(" " + area[i]);
}
System.out.println();
}
}
public static void main(String args[]) { new Main().run(); }
}
|
[["-", 0, 52, 8, 196, 0, 1, 0, 492, 141, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 492, 141, 22]]
| 3
| 618
|
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define RSORT(c) sort((c).rbegin(), (c).rend())
#define CLR(a) memset((a), 0, sizeof(a))
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
struct Cake {
int w, h;
bool operator<(const Cake &c) const { return w * h < c.w * c.h; }
};
int main() {
int n, w, h;
while (cin >> n >> w >> h, n | w | h) {
vector<Cake> cake;
cake.push_back({w, h});
REP(i, n) {
int p, s;
cin >> p >> s;
p--;
Cake c = cake[p];
cake.erase(cake.begin() + p);
int N = s % (c.w + c.h);
int cutpoint, other;
// LOG("CUT %d %d\n",c.w, c.h);
if (N > w) { //よこ
cutpoint = N - c.w;
other = c.h - cutpoint;
Cake c1 = {c.w, cutpoint};
Cake c2 = {c.w, other};
// LOG("W 1:%d %d ,,, 1:%d %d\n",c1.w, c1.h,
//c2.w,c2.h);
if (c1 < c2) {
cake.push_back(c1);
cake.push_back(c2);
} else {
cake.push_back(c2);
cake.push_back(c1);
}
} else {
cutpoint = N;
other = c.w - cutpoint;
Cake c1 = {cutpoint, c.h};
Cake c2 = {other, c.h};
// LOG("H 1:%d %d ,,, 1:%d %d\n",c1.w, c1.h,
//c2.w,c2.h);
if (c1 < c2) {
cake.push_back(c1);
cake.push_back(c2);
} else {
cake.push_back(c2);
cake.push_back(c1);
}
}
}
SORT(cake);
cout << cake[0].w * cake[0].h;
FOR(i, 1, cake.size()) { cout << " " << cake[i].w * cake[i].h; }
cout << endl;
}
}
|
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define RSORT(c) sort((c).rbegin(), (c).rend())
#define CLR(a) memset((a), 0, sizeof(a))
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
struct Cake {
int w, h;
bool operator<(const Cake &c) const { return w * h < c.w * c.h; }
};
int main() {
int n, w, h;
while (cin >> n >> w >> h, n | w | h) {
vector<Cake> cake;
cake.push_back({w, h});
REP(i, n) {
int p, s;
cin >> p >> s;
p--;
Cake c = cake[p];
cake.erase(cake.begin() + p);
int N = s % (c.w + c.h);
int cutpoint, other;
// LOG("CUT %d %d\n",c.w, c.h);
if (N > c.w) { //よこ
cutpoint = N - c.w;
other = c.h - cutpoint;
Cake c1 = {c.w, cutpoint};
Cake c2 = {c.w, other};
// LOG("W 1:%d %d ,,, 1:%d %d\n",c1.w, c1.h,
//c2.w,c2.h);
if (c1 < c2) {
cake.push_back(c1);
cake.push_back(c2);
} else {
cake.push_back(c2);
cake.push_back(c1);
}
} else {
cutpoint = N;
other = c.w - cutpoint;
Cake c1 = {cutpoint, c.h};
Cake c2 = {other, c.h};
// LOG("H 1:%d %d ,,, 1:%d %d\n",c1.w, c1.h,
//c2.w,c2.h);
if (c1 < c2) {
cake.push_back(c1);
cake.push_back(c2);
} else {
cake.push_back(c2);
cake.push_back(c1);
}
}
}
SORT(cake);
cout << cake[0].w * cake[0].h;
FOR(i, 1, cake.size()) { cout << " " << cake[i].w * cake[i].h; }
cout << endl;
}
}
|
[["+", 0, 57, 15, 339, 51, 16, 12, 118, 28, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 118, 17, 131]]
| 1
| 579
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define MAX_N 5000
#define INF 10000000
int cake[MAX_N][5]; // num,x1,y1,x2,y2//
int N, H, W, P, S;
int X1, Y1, X2, Y2, pos;
int W1, H1, C1, C2, C3, C4, A, SIS, SIS1, mens, enshu;
vector<int> cake2;
void MEMSET() {
for (int i = 0; i < MAX_N; i++) {
for (int j = 0; j < 5; j++) {
cake[i][j] = 0;
}
}
N = 0;
H = 0;
W = 0;
P = 0;
S = 0;
pos = 0;
W1 = 0;
H1 = 0;
C1 = 0;
C2 = 0;
C3 = 0;
C4 = 0;
A = 0;
SIS = 0;
SIS1 = 0;
mens = 0;
enshu = 0;
cake2.clear();
}
void CAKE() {
// one.
if (S <= C1) {
C4 = (S) + X1;
A = 0;
if (W1 < (C4 - X1) * 2) {
A += 1;
}
for (int j = 0; j < 2; j++) {
if (j == 0) {
cake[pos][0] = INF + A;
cake[pos][1] = X1;
cake[pos][2] = Y1;
cake[pos][3] = C4;
cake[pos][4] = Y2;
}
if (j == 1) {
cake[SIS1][0] = INF + A;
cake[SIS1][1] = C4;
cake[SIS1][2] = Y1;
cake[SIS1][3] = X2;
cake[SIS1][4] = Y2;
}
A += 1;
if (A >= 2) {
A = 0;
}
}
}
// two.
else if (S <= C2) {
C4 = (S - C1) + Y1;
A = 0;
if (H1 < (C4 - Y1) * 2) {
A += 1;
}
for (int j = 0; j < 2; j++) {
if (j == 0) {
cake[pos][0] = INF + A;
cake[pos][1] = X1;
cake[pos][2] = Y1;
cake[pos][3] = X2;
cake[pos][4] = C4;
}
if (j == 1) {
cake[SIS1][0] = INF + A;
cake[SIS1][1] = X1;
cake[SIS1][2] = C4;
cake[SIS1][3] = X2;
cake[SIS1][4] = Y2;
}
A += 1;
if (A >= 2) {
A = 0;
}
}
}
// three.
else if (S <= C3) {
C4 = X2 - (S - C2);
A = 0;
if (W1 < (C4 - X1) * 2) {
A += 1;
}
for (int j = 0; j < 2; j++) {
if (j == 0) {
cake[pos][0] = INF + A;
cake[pos][1] = X1;
cake[pos][2] = Y1;
cake[pos][3] = C4;
cake[pos][4] = Y2;
}
if (j == 1) {
cake[SIS1][0] = INF + A;
cake[SIS1][1] = C4;
cake[SIS1][2] = Y1;
cake[SIS1][3] = X2;
cake[SIS1][4] = Y2;
}
A += 1;
if (A >= 2) {
A = 0;
}
}
}
// four.
else if (S > C3) {
C4 = Y2 - (S - C3);
A = 0;
if (H1 < (C4 - Y1) * 2) {
A += 1;
}
for (int j = 0; j < 2; j++) {
if (j == 0) {
cake[pos][0] = INF + A;
cake[pos][1] = X1;
cake[pos][2] = Y1;
cake[pos][3] = X2;
cake[pos][4] = C4;
}
if (j == 1) {
cake[SIS1][0] = INF + A;
cake[SIS1][1] = X1;
cake[SIS1][2] = C4;
cake[SIS1][3] = X2;
cake[SIS1][4] = Y2;
}
A += 1;
if (A >= 2) {
A = 0;
}
}
}
}
int main() {
while (true) {
MEMSET();
cin >> N >> W >> H;
if (N == 0 && W == 0 && H == 0) {
break;
}
cake[0][0] = 1;
cake[0][1] = 0;
cake[0][2] = 0;
cake[0][3] = W;
cake[0][4] = H;
for (int i = 0; i < N; i++) {
cin >> P >> S;
for (int j = 0; j <= i; j++) {
if (cake[j][0] == P) {
X1 = cake[j][1];
Y1 = cake[j][2];
X2 = cake[j][3];
Y2 = cake[j][4];
pos = j;
}
}
W1 = (X2 - X1);
H1 = (Y2 - Y1);
C1 = W1;
C2 = C1 + H1;
C3 = C2 + W1;
C4 = 0;
A = 0;
enshu = C2 * 2;
SIS1 = i + 1;
SIS = SIS1 - pos;
S %= enshu;
CAKE();
for (int j = 0; j <= i; j++) {
if (j != pos && cake[j][0] >= P) {
cake[j][0] -= 1;
}
}
if (cake[pos][0] == INF) {
cake[pos][0] = i + 1;
} else {
cake[pos][0] = i + 2;
}
if (cake[SIS1][0] == INF) {
cake[SIS1][0] = i + 1;
} else {
cake[SIS1][0] = i + 2;
}
}
for (int i = 0; i < N + 1; i++) {
W1 = (cake[i][3] - cake[i][1]);
H1 = (cake[i][4] - cake[i][2]);
mens = W1 * H1;
cake2.push_back(mens);
}
sort(cake2.begin(), cake2.end());
for (int i = 0; i < cake2.size(); i++) {
if (i >= 1) {
cout << ' ';
}
cout << cake2[i];
}
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define MAX_N 5000
#define INF 10000000
int cake[MAX_N][5]; // num,x1,y1,x2,y2//
int N, H, W, P, S;
int X1, Y1, X2, Y2, pos;
int W1, H1, C1, C2, C3, C4, A, SIS, SIS1, mens, enshu;
vector<int> cake2;
void MEMSET() {
for (int i = 0; i < MAX_N; i++) {
for (int j = 0; j < 5; j++) {
cake[i][j] = 0;
}
}
N = 0;
H = 0;
W = 0;
P = 0;
S = 0;
pos = 0;
W1 = 0;
H1 = 0;
C1 = 0;
C2 = 0;
C3 = 0;
C4 = 0;
A = 0;
SIS = 0;
SIS1 = 0;
mens = 0;
enshu = 0;
cake2.clear();
}
void CAKE() {
// one.
if (S <= C1) {
C4 = (S) + X1;
A = 0;
if (W1 < (C4 - X1) * 2) {
A += 1;
}
for (int j = 0; j < 2; j++) {
if (j == 0) {
cake[pos][0] = INF + A;
cake[pos][1] = X1;
cake[pos][2] = Y1;
cake[pos][3] = C4;
cake[pos][4] = Y2;
}
if (j == 1) {
cake[SIS1][0] = INF + A;
cake[SIS1][1] = C4;
cake[SIS1][2] = Y1;
cake[SIS1][3] = X2;
cake[SIS1][4] = Y2;
}
A += 1;
if (A >= 2) {
A = 0;
}
}
}
// two.
else if (S <= C2) {
C4 = (S - C1) + Y1;
A = 0;
if (H1 < (C4 - Y1) * 2) {
A += 1;
}
for (int j = 0; j < 2; j++) {
if (j == 0) {
cake[pos][0] = INF + A;
cake[pos][1] = X1;
cake[pos][2] = Y1;
cake[pos][3] = X2;
cake[pos][4] = C4;
}
if (j == 1) {
cake[SIS1][0] = INF + A;
cake[SIS1][1] = X1;
cake[SIS1][2] = C4;
cake[SIS1][3] = X2;
cake[SIS1][4] = Y2;
}
A += 1;
if (A >= 2) {
A = 0;
}
}
}
// three.
else if (S <= C3) {
C4 = X2 - (S - C2);
A = 0;
if (W1 < (C4 - X1) * 2) {
A += 1;
}
for (int j = 0; j < 2; j++) {
if (j == 0) {
cake[pos][0] = INF + A;
cake[pos][1] = X1;
cake[pos][2] = Y1;
cake[pos][3] = C4;
cake[pos][4] = Y2;
}
if (j == 1) {
cake[SIS1][0] = INF + A;
cake[SIS1][1] = C4;
cake[SIS1][2] = Y1;
cake[SIS1][3] = X2;
cake[SIS1][4] = Y2;
}
A += 1;
if (A >= 2) {
A = 0;
}
}
}
// four.
else if (S > C3) {
C4 = Y2 - (S - C3);
A = 0;
if (H1 < (C4 - Y1) * 2) {
A += 1;
}
for (int j = 0; j < 2; j++) {
if (j == 0) {
cake[pos][0] = INF + A;
cake[pos][1] = X1;
cake[pos][2] = Y1;
cake[pos][3] = X2;
cake[pos][4] = C4;
}
if (j == 1) {
cake[SIS1][0] = INF + A;
cake[SIS1][1] = X1;
cake[SIS1][2] = C4;
cake[SIS1][3] = X2;
cake[SIS1][4] = Y2;
}
A += 1;
if (A >= 2) {
A = 0;
}
}
}
}
int main() {
while (true) {
MEMSET();
cin >> N >> W >> H;
if (N == 0 && W == 0 && H == 0) {
break;
}
cake[0][0] = 1;
cake[0][1] = 0;
cake[0][2] = 0;
cake[0][3] = W;
cake[0][4] = H;
for (int i = 0; i < N; i++) {
cin >> P >> S;
for (int j = 0; j <= i; j++) {
if (cake[j][0] == P) {
X1 = cake[j][1];
Y1 = cake[j][2];
X2 = cake[j][3];
Y2 = cake[j][4];
pos = j;
}
}
W1 = (X2 - X1);
H1 = (Y2 - Y1);
C1 = W1;
C2 = C1 + H1;
C3 = C2 + W1;
C4 = 0;
A = 0;
enshu = C2 * 2;
SIS1 = i + 1;
SIS = SIS1 - pos;
S %= enshu;
CAKE();
for (int j = 0; j <= i; j++) {
if (j != pos && cake[j][0] >= P) {
cake[j][0] -= 1;
}
}
if (cake[pos][0] == INF) {
cake[pos][0] = i + 1;
} else {
cake[pos][0] = i + 2;
}
if (cake[SIS1][0] == INF) {
cake[SIS1][0] = i + 1;
} else {
cake[SIS1][0] = i + 2;
}
}
for (int i = 0; i < N + 1; i++) {
W1 = (cake[i][3] - cake[i][1]);
H1 = (cake[i][4] - cake[i][2]);
mens = W1 * H1;
cake2.push_back(mens);
}
sort(cake2.begin(), cake2.end());
for (int i = 0; i < cake2.size(); i++) {
if (i >= 1) {
cout << ' ';
}
cout << cake2[i];
}
cout << endl;
}
return 0;
}
|
[["+", 0, 52, 8, 9, 0, 1, 0, 16, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 52, 8, 9, 0, 1, 0, 16, 12, 22], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 1
| 1,488
|
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define repr(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define rep(i, n) repl(i, 0, n)
#define each(itr, v) for (auto itr : v)
#define pb(s) push_back(s)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x " = " << x << endl
#define print(x) cout << x << endl
#define maxch(x, y) x = max(x, y)
#define minch(x, y) x = min(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt(x) bitset<32>(x).count()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;
#define INF INT_MAX / 3
#define MAX_N 1000000001
struct Cake {
int s;
int tate, yoko;
};
bool operator<(const Cake &a, const Cake &b) { return a.s < b.s; }
void cut(vector<Cake> &v, int i, int l) {
Cake piece = v[i];
v.erase(v.begin() + i);
bool t = true;
while (true) {
if (piece.yoko < l) {
l -= piece.yoko;
} else {
t = false;
break;
}
if (piece.tate < l) {
l -= piece.tate;
} else {
t = true;
break;
}
}
Cake a, b;
if (t) {
a = Cake{(piece.tate - l) * piece.yoko, piece.tate - l, piece.yoko};
b = Cake{l * piece.yoko, l, piece.yoko};
} else {
a = Cake{piece.tate * (piece.yoko - l), piece.tate, piece.yoko - l};
b = Cake{piece.tate * l, piece.tate, l};
}
if (b < a)
swap(a, b);
v.pb(a);
v.pb(b);
}
int n, w, d;
int main() {
cin.sync_with_stdio(false);
while (cin >> n >> w >> d, w) {
vector<Cake> v;
Cake tmp = Cake{w * d, d, w};
v.pb(tmp);
rep(i, n) {
int p, l;
cin >> p >> l;
cut(v, p - 1, l);
}
sort(all(v));
rep(i, v.size() - 1) printf("%d ", v[i].s);
print(v[v.size() - 1].s);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define repr(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define rep(i, n) repl(i, 0, n)
#define each(itr, v) for (auto itr : v)
#define pb(s) push_back(s)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x " = " << x << endl
#define print(x) cout << x << endl
#define maxch(x, y) x = max(x, y)
#define minch(x, y) x = min(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt(x) bitset<32>(x).count()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;
#define INF INT_MAX / 3
#define MAX_N 1000000001
struct Cake {
int s;
int tate, yoko;
};
bool operator<(const Cake &a, const Cake &b) { return a.s < b.s; }
void cut(vector<Cake> &v, int i, int l) {
Cake piece = v[i];
v.erase(v.begin() + i);
bool t = true;
while (true) {
if (piece.yoko < l) {
l -= piece.yoko;
} else {
t = false;
break;
}
if (piece.tate < l) {
l -= piece.tate;
} else {
t = true;
break;
}
}
Cake a, b;
if (t) {
a = Cake{(piece.tate - l) * piece.yoko, piece.tate - l, piece.yoko};
b = Cake{l * piece.yoko, l, piece.yoko};
} else {
a = Cake{piece.tate * (piece.yoko - l), piece.tate, piece.yoko - l};
b = Cake{piece.tate * l, piece.tate, l};
}
if (b < a)
swap(a, b);
v.pb(a);
v.pb(b);
}
int n, w, d;
int main() {
cin.sync_with_stdio(false);
while (cin >> n >> w >> d, w) {
vector<Cake> v;
Cake tmp = Cake{w * d, d, w};
v.pb(tmp);
rep(i, n) {
int p, l;
cin >> p >> l;
cut(v, p - 1, l);
}
sort(all(v));
rep(i, v.size() - 1) printf("%d ", v[i].s);
printf("%d\n", v[v.size() - 1].s);
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 62], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 21]]
| 1
| 587
|
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
bool larger(pair<int, int> &a, pair<int, int> &b) {
return a.first * a.second < b.first * b.second;
}
int main() {
while (1) {
int n, w, d;
cin >> n >> w >> d;
if (w == 0)
break;
vector<pair<int, int>> cakes;
cakes.push_back(make_pair(w, d));
for (int i = 0; i < n; i++) {
int p, s;
cin >> p >> s;
p--;
int x = cakes[p].first, y = cakes[p].second;
cakes.erase(cakes.begin() + p);
s %= x + y;
if (s < x) {
if (s <= x / 2) {
cakes.push_back(make_pair(s, y));
cakes.push_back(make_pair(x - s, y));
} else {
cakes.push_back(make_pair(x - s, y));
cakes.push_back(make_pair(s, d));
}
} else {
s -= x;
if (s <= y / 2) {
cakes.push_back(make_pair(x, s));
cakes.push_back(make_pair(x, y - s));
} else {
cakes.push_back(make_pair(x, y - s));
cakes.push_back(make_pair(x, s));
}
}
}
sort(cakes.begin(), cakes.end(), larger);
for (int i = 0; i < n; i++) {
cout << cakes[i].first * cakes[i].second << " ";
}
cout << cakes[n].first * cakes[n].second << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
bool larger(pair<int, int> &a, pair<int, int> &b) {
return a.first * a.second < b.first * b.second;
}
int main() {
while (1) {
int n, w, d;
cin >> n >> w >> d;
if (w == 0)
break;
vector<pair<int, int>> cakes;
cakes.push_back(make_pair(w, d));
for (int i = 0; i < n; i++) {
int p, s;
cin >> p >> s;
p--;
int x = cakes[p].first, y = cakes[p].second;
cakes.erase(cakes.begin() + p);
s %= x + y;
if (s < x) {
if (s <= x / 2) {
cakes.push_back(make_pair(s, y));
cakes.push_back(make_pair(x - s, y));
} else {
cakes.push_back(make_pair(x - s, y));
cakes.push_back(make_pair(s, y));
}
} else {
s -= x;
if (s <= y / 2) {
cakes.push_back(make_pair(x, s));
cakes.push_back(make_pair(x, y - s));
} else {
cakes.push_back(make_pair(x, y - s));
cakes.push_back(make_pair(x, s));
}
}
}
sort(cakes.begin(), cakes.end(), larger);
for (int i = 0; i < n; i++) {
cout << cakes[i].first * cakes[i].second << " ";
}
cout << cakes[n].first * cakes[n].second << endl;
}
return 0;
}
|
[["-", 0, 2, 3, 4, 0, 2, 3, 4, 0, 22], ["+", 0, 2, 3, 4, 0, 2, 3, 4, 0, 22]]
| 1
| 397
|
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
struct cake {
int w, d, p;
cake(int w_, int d_, int p_) {
w = w_;
d = d_;
p = p_;
}
cake() {
w = 0;
d = 0;
p = 0;
}
};
typedef pair<cake, cake> P;
// c := 切ろうとしているケーキ, s := 切る位置
P cut(cake c, int s) {
int w1, w2, d1, d2;
s %= c.w + c.d;
if (s < c.w) {
w1 = s;
w2 = c.w - s;
d1 = d2 = c.d;
} else {
s -= c.w;
d1 = s;
d2 = c.d - s;
w1 = w2 = c.w;
}
if (w1 * d1 > w2 * d2) {
swap(w1, w2);
swap(d1, d2);
}
// firstが小さいケーキ, secondが大きいケーキ
cake c1(w1, d1, 0);
cake c2(w2, d2, 0);
P result(c1, c2);
return result;
}
int main() {
int n, w, d;
while (cin >> n >> w >> d, n || w || d) {
vector<cake> now;
vector<cake> next;
next.push_back(cake(w, d, 1));
for (int i = 1; i <= n; i++) {
int p, s;
now = next;
next.clear();
cin >> p >> s;
for (int j = 0; j < now.size(); j++) {
if (now[j].p == p) {
P p_cake = cut(now[j], s);
// 小さいケーキ
p_cake.first.p = i;
next.push_back(p_cake.first);
// 大きいケーキ
p_cake.second.p = i + 1;
next.push_back(p_cake.second);
break;
} else {
if (now[j].p > p)
now[j].p--;
next.push_back(now[j]);
}
}
}
vector<int> ans;
for (int i = 0; i < next.size(); i++) {
ans.push_back(next[i].w * next[i].d);
}
sort(ans.begin(), ans.end());
for (int i = 0; i < ans.size(); i++) {
cout << ans[i];
if (i == ans.size() - 1)
cout << endl;
else
cout << " ";
}
}
}
|
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
struct cake {
int w, d, p;
cake(int w_, int d_, int p_) {
w = w_;
d = d_;
p = p_;
}
cake() {
w = 0;
d = 0;
p = 0;
}
};
typedef pair<cake, cake> P;
// c := 切ろうとしているケーキ, s := 切る位置
P cut(cake c, int s) {
int w1, w2, d1, d2;
s %= c.w + c.d;
if (s < c.w) {
w1 = s;
w2 = c.w - s;
d1 = d2 = c.d;
} else {
s -= c.w;
d1 = s;
d2 = c.d - s;
w1 = w2 = c.w;
}
if (w1 * d1 > w2 * d2) {
swap(w1, w2);
swap(d1, d2);
}
// firstが小さいケーキ, secondが大きいケーキ
cake c1(w1, d1, 0);
cake c2(w2, d2, 0);
P result(c1, c2);
return result;
}
int main() {
int n, w, d;
while (cin >> n >> w >> d, n || w || d) {
vector<cake> now;
vector<cake> next;
next.push_back(cake(w, d, 1));
for (int i = 1; i <= n; i++) {
int p, s;
now = next;
next.clear();
cin >> p >> s;
for (int j = 0; j < now.size(); j++) {
if (now[j].p == p) {
P p_cake = cut(now[j], s);
// 小さいケーキ
p_cake.first.p = i;
next.push_back(p_cake.first);
// 大きいケーキ
p_cake.second.p = i + 1;
next.push_back(p_cake.second);
} else {
if (now[j].p > p)
now[j].p--;
next.push_back(now[j]);
}
}
}
vector<int> ans;
for (int i = 0; i < next.size(); i++) {
ans.push_back(next[i].w * next[i].d);
}
sort(ans.begin(), ans.end());
for (int i = 0; i < ans.size(); i++) {
cout << ans[i];
if (i == ans.size() - 1)
cout << endl;
else
cout << " ";
}
}
}
|
[["-", 8, 9, 0, 57, 64, 9, 0, 93, 0, 94], ["-", 8, 9, 0, 57, 64, 9, 0, 93, 0, 35]]
| 1
| 545
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
using namespace std;
#define dump(n) cerr << "# " << #n << "=" << (n) << endl
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define peri(i, a, b) for (int i = int(b); i-- > int(a);)
#define rep(i, n) repi(i, 0, n)
#define per(i, n) peri(i, 0, n)
#define iter(c) __typeof__((c).begin())
#define foreach(i, c) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define all(c) (c).begin(), (c).end()
#define mp make_pair
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pii;
struct Rect {
int x, y, w, h;
Rect() {}
Rect(int x, int y, int w, int h) : x(x), y(y), w(w), h(h) {}
};
int main() {
for (int n, w, h; cin >> n >> w >> h, n | w | h;) {
list<Rect> rs;
rs.push_back(Rect(0, 0, w, h));
rep(i, n) {
int p, s;
cin >> p >> s;
iter(rs) it = rs.begin();
advance(it, p - 1);
int len = (it->w + it->h) * 2;
Rect r1, r2;
if ((s %= len) < it->w) {
r1 = Rect(it->x, it->y, s, it->h);
r2 = Rect(it->x + s, it->y, it->w - s, it->h);
} else if ((s -= it->w) < it->h) {
r1 = Rect(it->x, it->y, it->w, s);
r2 = Rect(it->x, it->y + s, it->w, it->h - s);
} else if ((s -= it->h) < it->w) {
r1 = Rect(it->x, it->y, it->h - s, it->h);
r2 = Rect(it->x + it->w - s, it->y, s, it->h);
} else if ((s -= it->w) < it->h) {
r1 = Rect(it->x, it->y, it->w, it->h - s);
r2 = Rect(it->x, it->y + it->h - s, it->w, s);
}
if (r1.w * r1.h > r2.w * r2.h)
swap(r1, r2);
rs.push_back(r1);
rs.push_back(r2);
rs.erase(it);
}
vi as;
foreach (i, rs)
as.push_back(i->w * i->h);
sort(all(as));
rep(i, as.size()) printf("%d%c", as[i], i == as.size() - 1 ? '\n' : ' ');
}
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
using namespace std;
#define dump(n) cerr << "# " << #n << "=" << (n) << endl
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define peri(i, a, b) for (int i = int(b); i-- > int(a);)
#define rep(i, n) repi(i, 0, n)
#define per(i, n) peri(i, 0, n)
#define iter(c) __typeof__((c).begin())
#define foreach(i, c) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define all(c) (c).begin(), (c).end()
#define mp make_pair
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pii;
struct Rect {
int x, y, w, h;
Rect() {}
Rect(int x, int y, int w, int h) : x(x), y(y), w(w), h(h) {}
};
int main() {
for (int n, w, h; cin >> n >> w >> h, n | w | h;) {
list<Rect> rs;
rs.push_back(Rect(0, 0, w, h));
rep(i, n) {
int p, s;
cin >> p >> s;
iter(rs) it = rs.begin();
advance(it, p - 1);
int len = (it->w + it->h) * 2;
Rect r1, r2;
if ((s %= len) < it->w) {
r1 = Rect(it->x, it->y, s, it->h);
r2 = Rect(it->x + s, it->y, it->w - s, it->h);
} else if ((s -= it->w) < it->h) {
r1 = Rect(it->x, it->y, it->w, s);
r2 = Rect(it->x, it->y + s, it->w, it->h - s);
} else if ((s -= it->h) < it->w) {
r1 = Rect(it->x, it->y, it->w - s, it->h);
r2 = Rect(it->x + it->w - s, it->y, s, it->h);
} else if ((s -= it->w) < it->h) {
r1 = Rect(it->x, it->y, it->w, it->h - s);
r2 = Rect(it->x, it->y + it->h - s, it->w, s);
}
if (r1.w * r1.h > r2.w * r2.h)
swap(r1, r2);
rs.push_back(r1);
rs.push_back(r2);
rs.erase(it);
}
vi as;
foreach (i, rs)
as.push_back(i->w * i->h);
sort(all(as));
rep(i, as.size()) printf("%d%c", as[i], i == as.size() - 1 ? '\n' : ' ');
}
return 0;
}
|
[["-", 12, 2, 3, 4, 0, 16, 31, 118, 119, 120], ["+", 12, 2, 3, 4, 0, 16, 31, 118, 119, 120]]
| 1
| 710
|
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#define REP(i, a, b) for (i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
class Tpair {
public:
int first, second;
Tpair(int x, int y) {
first = x;
second = y;
}
bool operator<(const Tpair &a) const {
return (first) * (second) < (a.first) * (a.second);
}
};
typedef Tpair P;
int main() {
int i, j, k, l, m, n;
int w, d, s, p;
while (cin >> n >> w >> d) {
vector<P> cakes;
cakes.clear();
if (n == 0 && w == 0 && d == 0)
break;
cakes.push_back(P(w, d));
rep(i, n) {
cin >> p >> s;
int ww = cakes[p - 1].first, dd = cakes[p - 1].second;
cakes.erase(cakes.begin() + p - 1);
s = s % (2 * ww + 2 * dd);
vector<P> subcakes;
subcakes.clear();
if (s < ww) {
subcakes.push_back(P(s, dd));
subcakes.push_back(P(ww - s, dd));
} else if (s < ww + dd) {
s = s - ww;
subcakes.push_back(P(ww, s));
subcakes.push_back(P(ww, dd - s));
} else if (s < 2 * ww + dd) {
s -= ww + dd;
subcakes.push_back(P(s, dd));
subcakes.push_back(P(ww - s, dd));
} else {
s -= 2 * ww + dd;
subcakes.push_back(P(ww, s));
subcakes.push_back(P(ww, dd - s));
}
sort(subcakes.begin(), subcakes.end());
cakes.push_back(subcakes[1]);
cakes.push_back(subcakes[0]);
}
sort(cakes.begin(), cakes.end());
rep(i, cakes.size() - 1) cout << cakes[i].first * cakes[i].second << " ";
cout << cakes[i].first * cakes[i].second << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#define REP(i, a, b) for (i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
class Tpair {
public:
int first, second;
Tpair(int x, int y) {
first = x;
second = y;
}
bool operator<(const Tpair &a) const {
return (first) * (second) < (a.first) * (a.second);
}
};
typedef Tpair P;
int main() {
int i, j, k, l, m, n;
int w, d, s, p;
while (cin >> n >> w >> d) {
vector<P> cakes;
cakes.clear();
if (n == 0 && w == 0 && d == 0)
break;
cakes.push_back(P(w, d));
rep(i, n) {
cin >> p >> s;
int ww = cakes[p - 1].first, dd = cakes[p - 1].second;
cakes.erase(cakes.begin() + p - 1);
s = s % (2 * ww + 2 * dd);
vector<P> subcakes;
subcakes.clear();
if (s < ww) {
subcakes.push_back(P(s, dd));
subcakes.push_back(P(ww - s, dd));
} else if (s < ww + dd) {
s = s - ww;
subcakes.push_back(P(ww, s));
subcakes.push_back(P(ww, dd - s));
} else if (s < 2 * ww + dd) {
s -= ww + dd;
subcakes.push_back(P(s, dd));
subcakes.push_back(P(ww - s, dd));
} else {
s -= 2 * ww + dd;
subcakes.push_back(P(ww, s));
subcakes.push_back(P(ww, dd - s));
}
sort(subcakes.begin(), subcakes.end());
cakes.push_back(subcakes[0]);
cakes.push_back(subcakes[1]);
}
sort(cakes.begin(), cakes.end());
rep(i, cakes.size() - 1) cout << cakes[i].first * cakes[i].second << " ";
cout << cakes[i].first * cakes[i].second << endl;
}
return 0;
}
|
[["-", 0, 2, 3, 4, 0, 69, 341, 342, 0, 13], ["+", 0, 2, 3, 4, 0, 69, 341, 342, 0, 13]]
| 1
| 519
|
#
# 1149: Cut the Cakes
#
loop do
n, w, h = gets.split.map(&:to_i)
break if (n | w | h) == 0
cakes = [[w, h]]
n.times do
pi, si = gets.split.map(&:to_i)
pi -= 1
wi, hi = cakes[pi]
cakes.delete_at(pi)
si %= wi + hi
if si < wi
wi0 = si
wi1 = wi - wi0
if wi0 < wi1
cakes += [[wi0, hi], [wi1, hi]]
else
cakes += [[wi1, hi], [wi0, hi]]
end
else
hi0 = hi - (wi - si)
hi1 = hi -hi0
if hi0 < hi1
cakes += [[wi, hi0], [wi, hi1]]
else
cakes += [[wi, hi1], [wi, hi0]]
end
end
end
puts cakes.map{|wi, hi| wi * hi}.sort.join(' ')
end
|
#
# 1149: Cut the Cakes
#
loop do
n, w, h = gets.split.map(&:to_i)
break if (n | w | h) == 0
cakes = [[w, h]]
n.times do
pi, si = gets.split.map(&:to_i)
pi -= 1
wi, hi = cakes[pi]
cakes.delete_at(pi)
si %= wi + hi
if si < wi
wi0 = si
wi1 = wi - wi0
if wi0 < wi1
cakes += [[wi0, hi], [wi1, hi]]
else
cakes += [[wi1, hi], [wi0, hi]]
end
else
hi0 = hi - (si - wi)
hi1 = hi - hi0
if hi0 < hi1
cakes += [[wi, hi0], [wi, hi1]]
else
cakes += [[wi, hi1], [wi, hi0]]
end
end
end
puts cakes.map{|wi, hi| wi * hi}.sort.join(' ')
end
|
[["-", 0, 662, 12, 738, 12, 739, 0, 738, 31, 22], ["-", 0, 662, 12, 738, 12, 739, 0, 738, 17, 33], ["+", 0, 662, 12, 738, 12, 739, 0, 738, 17, 33], ["+", 0, 662, 12, 738, 12, 739, 0, 738, 12, 22]]
| 4
| 204
|
/*
AizuOnline A1145
Title The Genome Database of All Space Life
*/
#include <stdio.h>
#include <string.h>
// Global data section
char s[101];
int idx;
int node_ptr;
struct NODE {
int car;
int cdr;
char *genum;
int glen; // mojiretu no nagasa
int blen; // tenkai go no nagasa never .GE. 1000000
int coef; // keisuu < 5keta
} Gnode[100];
//
int is_under_5digits(char *g) {
int i;
for (i = 0; i < 5; i++)
if (!isdigit(g[i]))
return (i);
return (5);
}
int get_close_paren(char *g) {
char *p;
int depth;
#ifdef DEBUG2
printf("gcp=%s\n", g);
#endif
depth = 0;
for (p = g; *p; p++) {
if (*p == '(')
depth++;
if (*p == ')')
depth--;
if (depth == 0) {
#ifdef DEBUG2
printf("gcpA=%d\n", p - g);
#endif
return (p - g);
}
}
return (-1);
}
int get_1st(char *g, int l) {
int ret;
int i;
if (isupper(g[0])) {
for (i = 0; i < l; i++)
if (!isupper(g[i + 1]))
return (i + 1);
return (l);
}
if (ret = is_under_5digits(g)) {
#if DEBUG2
printf("NL=%d\n", ret);
#endif
if (isalpha(g[ret]))
return (ret + 1);
if (g[ret] == '(')
return (ret + 1 + get_close_paren(g + ret));
}
}
int is_single(char *g, int l) {
if (l == 1)
return (isupper(g[0]));
else
return (isupper(g[0]) && is_single(g + 1, l - 1));
}
int all_upper(char *g, int len) {
int i;
for (i = 0; i < len; i++)
if (!isupper(g[i]))
return (0);
return (-1);
}
int get_times(char *g, char len) {
int i, c;
// printf("T:%s %d\n",g,len);
c = 0;
for (i = 0; i < len; i++) {
c *= 10;
c += (g[i] - '0');
}
return (c);
}
int get_len_recursive(int ndp) {
int ret, ret1, ret2;
if (Gnode[ndp].cdr == -1) {
if (Gnode[ndp].car == -1) {
if (Gnode[ndp].coef != 1)
ret = Gnode[ndp].coef;
else
ret = Gnode[ndp].glen;
// printf("Le:%d\n",ret);
Gnode[ndp].blen = ret;
return (ret);
} else {
ret = get_len_recursive(Gnode[ndp].car);
if (ret != -1) {
ret *= Gnode[ndp].coef;
if (ret > 1000000)
ret = -1;
}
Gnode[ndp].blen = ret;
return (ret);
}
} else {
ret1 = get_len_recursive(Gnode[ndp].car);
ret2 = get_len_recursive(Gnode[ndp].cdr);
if (ret1 == -1 || ret2 == -1)
ret = -1;
else {
ret = ret1 + ret2;
if (ret > 1000000)
ret = -1;
}
Gnode[ndp].blen = ret;
return (ret);
}
}
void print_all_node() {
int i;
printf("SEQ:COEF:LEN:CAR:CDR:STRING\n");
for (i = 0; i <= node_ptr; i++) {
print_1_node(i);
printf("\n");
}
}
print_1_node(int i) {
int j;
printf("%d:", i);
printf("[%d]", Gnode[i].coef);
printf("(%d)", Gnode[i].blen);
if (Gnode[i].car > 0)
printf("%d:", Gnode[i].car);
else
printf("*:");
if (Gnode[i].cdr > 0)
printf("%d:", Gnode[i].cdr);
else
printf("*:");
for (j = 0; j < Gnode[i].glen; j++) {
printf("%c", Gnode[i].genum[j]);
}
}
void set_node(int n, char *g, int len) {
int ret;
// printf("G:%d %s %d\n",n,g,len);
Gnode[n].car = -1;
Gnode[n].cdr = -1;
Gnode[n].genum = g;
Gnode[n].glen = len;
}
int get_new_node() {
node_ptr++;
Gnode[node_ptr].car = -1;
Gnode[node_ptr].cdr = -1;
Gnode[node_ptr].genum = NULL;
Gnode[node_ptr].glen = 0;
Gnode[node_ptr].blen = 0;
Gnode[node_ptr].coef = 1;
return (node_ptr);
}
int init_node() {
int i;
for (i = 0; i < 100; i++) {
Gnode[i].car = -1;
Gnode[i].cdr = -1;
Gnode[i].genum = NULL;
Gnode[i].glen = 0;
Gnode[i].blen = 0;
Gnode[i].coef = 1;
}
}
void set_nodes_recursive(int ndp, char *g, int gl) {
int l1, carp, cdrp, ret;
// printf("g %s gl %d\n",g,gl);
set_node(ndp, g, gl);
l1 = get_1st(g, gl);
if (l1 < gl) {
carp = Gnode[ndp].car = get_new_node();
cdrp = Gnode[ndp].cdr = get_new_node();
set_nodes_recursive(carp, g, l1);
set_nodes_recursive(cdrp, &g[l1], gl - l1);
} else if (ret = is_under_5digits(g)) {
Gnode[ndp].coef = get_times(g, ret);
if (g[ret] == '(') {
carp = Gnode[ndp].car = get_new_node();
Gnode[ndp].cdr = -1;
// printf("tims %d\n",get_times(g,ret));
set_nodes_recursive(carp, g + ret + 1, gl - ret - 2);
} else {
Gnode[ndp].car = -1;
Gnode[ndp].genum += ret;
Gnode[ndp].glen -= ret;
}
}
}
void set_all_node() { set_nodes_recursive(0, s, strlen(s)); }
void get_len_all() { get_len_recursive(0); }
char get_bunsi(int ndp, int id) {
struct NODE *np;
int car_len;
np = &Gnode[ndp];
#ifdef DEBUG1
print_1_node(ndp);
printf("\t:I=%d\n", id);
#endif
if (np->car > 0)
car_len = Gnode[np->car].blen;
else
car_len = 0;
if (np->blen == -1) {
if (np->cdr == -1) {
if (car_len == -1)
return (get_bunsi(np->car, id % car_len));
else
return (get_bunsi(np->car, id));
} else {
if (car_len > id || car_len == -1)
return (get_bunsi(np->car, id));
else
return (get_bunsi(np->cdr, id - car_len));
}
} else {
if (np->blen <= id)
return ('0');
if (np->cdr == -1) {
if (np->car == -1) {
if (np->coef > 1) // number*terminal
{
return (np->genum[0]);
} else // terminal...
return (np->genum[id]);
} else
return (get_bunsi(np->car, id % car_len));
}
if (car_len > id)
return (get_bunsi(np->car, id));
else
return (get_bunsi(np->cdr, id - car_len));
}
}
main() {
while (EOF != scanf("%s %d", s, &idx) &&
!(s[0] == '0' && s[1] == '\0' && idx == 0)) {
init_node();
node_ptr = 0;
set_all_node();
get_len_all();
#ifdef DEBUG1
print_all_node();
printf("--trace inf------------\n");
#endif
printf("%c\n", get_bunsi(0, idx));
}
return (0);
}
|
/*
AizuOnline A1145
Title The Genome Database of All Space Life
*/
#include <stdio.h>
#include <string.h>
// Global data section
char s[101];
int idx;
int node_ptr;
struct NODE {
int car;
int cdr;
char *genum;
int glen; // mojiretu no nagasa
int blen; // tenkai go no nagasa never .GE. 1000000
int coef; // keisuu < 5keta
} Gnode[100];
//
int is_under_5digits(char *g) {
int i;
for (i = 0; i < 5; i++)
if (!isdigit(g[i]))
return (i);
return (5);
}
int get_close_paren(char *g) {
char *p;
int depth;
#ifdef DEBUG2
printf("gcp=%s\n", g);
#endif
depth = 0;
for (p = g; *p; p++) {
if (*p == '(')
depth++;
if (*p == ')')
depth--;
if (depth == 0) {
#ifdef DEBUG2
printf("gcpA=%d\n", p - g);
#endif
return (p - g);
}
}
return (-1);
}
int get_1st(char *g, int l) {
int ret;
int i;
if (isupper(g[0])) {
for (i = 0; i < l; i++)
if (!isupper(g[i + 1]))
return (i + 1);
return (l);
}
if (ret = is_under_5digits(g)) {
#if DEBUG2
printf("NL=%d\n", ret);
#endif
if (isalpha(g[ret]))
return (ret + 1);
if (g[ret] == '(')
return (ret + 1 + get_close_paren(g + ret));
}
}
int is_single(char *g, int l) {
if (l == 1)
return (isupper(g[0]));
else
return (isupper(g[0]) && is_single(g + 1, l - 1));
}
int all_upper(char *g, int len) {
int i;
for (i = 0; i < len; i++)
if (!isupper(g[i]))
return (0);
return (-1);
}
int get_times(char *g, char len) {
int i, c;
// printf("T:%s %d\n",g,len);
c = 0;
for (i = 0; i < len; i++) {
c *= 10;
c += (g[i] - '0');
}
return (c);
}
int get_len_recursive(int ndp) {
int ret, ret1, ret2;
if (Gnode[ndp].cdr == -1) {
if (Gnode[ndp].car == -1) {
if (Gnode[ndp].coef != 1)
ret = Gnode[ndp].coef;
else
ret = Gnode[ndp].glen;
// printf("Le:%d\n",ret);
Gnode[ndp].blen = ret;
return (ret);
} else {
ret = get_len_recursive(Gnode[ndp].car);
if (ret != -1) {
ret *= Gnode[ndp].coef;
if (ret > 1000000)
ret = -1;
}
Gnode[ndp].blen = ret;
return (ret);
}
} else {
ret1 = get_len_recursive(Gnode[ndp].car);
ret2 = get_len_recursive(Gnode[ndp].cdr);
if (ret1 == -1 || ret2 == -1)
ret = -1;
else {
ret = ret1 + ret2;
if (ret > 1000000)
ret = -1;
}
Gnode[ndp].blen = ret;
return (ret);
}
}
void print_all_node() {
int i;
printf("SEQ:COEF:LEN:CAR:CDR:STRING\n");
for (i = 0; i <= node_ptr; i++) {
print_1_node(i);
printf("\n");
}
}
print_1_node(int i) {
int j;
printf("%d:", i);
printf("[%d]", Gnode[i].coef);
printf("(%d)", Gnode[i].blen);
if (Gnode[i].car > 0)
printf("%d:", Gnode[i].car);
else
printf("*:");
if (Gnode[i].cdr > 0)
printf("%d:", Gnode[i].cdr);
else
printf("*:");
for (j = 0; j < Gnode[i].glen; j++) {
printf("%c", Gnode[i].genum[j]);
}
}
void set_node(int n, char *g, int len) {
int ret;
// printf("G:%d %s %d\n",n,g,len);
Gnode[n].car = -1;
Gnode[n].cdr = -1;
Gnode[n].genum = g;
Gnode[n].glen = len;
}
int get_new_node() {
node_ptr++;
Gnode[node_ptr].car = -1;
Gnode[node_ptr].cdr = -1;
Gnode[node_ptr].genum = NULL;
Gnode[node_ptr].glen = 0;
Gnode[node_ptr].blen = 0;
Gnode[node_ptr].coef = 1;
return (node_ptr);
}
int init_node() {
int i;
for (i = 0; i < 100; i++) {
Gnode[i].car = -1;
Gnode[i].cdr = -1;
Gnode[i].genum = NULL;
Gnode[i].glen = 0;
Gnode[i].blen = 0;
Gnode[i].coef = 1;
}
}
void set_nodes_recursive(int ndp, char *g, int gl) {
int l1, carp, cdrp, ret;
// printf("g %s gl %d\n",g,gl);
set_node(ndp, g, gl);
l1 = get_1st(g, gl);
if (l1 < gl) {
carp = Gnode[ndp].car = get_new_node();
cdrp = Gnode[ndp].cdr = get_new_node();
set_nodes_recursive(carp, g, l1);
set_nodes_recursive(cdrp, &g[l1], gl - l1);
} else if (ret = is_under_5digits(g)) {
Gnode[ndp].coef = get_times(g, ret);
if (g[ret] == '(') {
carp = Gnode[ndp].car = get_new_node();
Gnode[ndp].cdr = -1;
// printf("tims %d\n",get_times(g,ret));
set_nodes_recursive(carp, g + ret + 1, gl - ret - 2);
} else {
Gnode[ndp].car = -1;
Gnode[ndp].genum += ret;
Gnode[ndp].glen -= ret;
}
}
}
void set_all_node() { set_nodes_recursive(0, s, strlen(s)); }
void get_len_all() { get_len_recursive(0); }
char get_bunsi(int ndp, int id) {
struct NODE *np;
int car_len;
np = &Gnode[ndp];
#ifdef DEBUG1
print_1_node(ndp);
printf("\t:I=%d\n", id);
#endif
if (np->car > 0)
car_len = Gnode[np->car].blen;
else
car_len = 0;
if (np->blen == -1) {
if (np->cdr == -1) {
if (car_len != -1)
return (get_bunsi(np->car, id % car_len));
else
return (get_bunsi(np->car, id));
} else {
if (car_len > id || car_len == -1)
return (get_bunsi(np->car, id));
else
return (get_bunsi(np->cdr, id - car_len));
}
} else {
if (np->blen <= id)
return ('0');
if (np->cdr == -1) {
if (np->car == -1) {
if (np->coef > 1) // number*terminal
{
return (np->genum[0]);
} else // terminal...
return (np->genum[id]);
} else
return (get_bunsi(np->car, id % car_len));
}
if (car_len > id)
return (get_bunsi(np->car, id));
else
return (get_bunsi(np->cdr, id - car_len));
}
}
main() {
while (EOF != scanf("%s %d", s, &idx) &&
!(s[0] == '0' && s[1] == '\0' && idx == 0)) {
init_node();
node_ptr = 0;
set_all_node();
get_len_all();
#ifdef DEBUG1
print_all_node();
printf("--trace inf------------\n");
#endif
printf("%c\n", get_bunsi(0, idx));
}
return (0);
}
|
[["-", 64, 9, 0, 57, 15, 23, 0, 16, 17, 60], ["+", 64, 9, 0, 57, 15, 23, 0, 16, 17, 79]]
| 0
| 1,730
|
#include <bits/stdc++.h>
#define int long long
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) _range(i, 0, n)
#define _range(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _overload(__VA_ARGS__, _range, _rep, )(__VA_ARGS__)
#define _rrep(i, n) _rrange(i, n, 0)
#define _rrange(i, a, b) for (int i = (int)(a)-1; i >= (int)(b); --i)
#define rrep(...) _overload(__VA_ARGS__, _rrange, _rrep, )(__VA_ARGS__)
#define _all(arg) begin(arg), end(arg)
#define uniq(arg) sort(_all(arg)), (arg).erase(unique(_all(arg)), end(arg))
#define getidx(ary, key) lower_bound(_all(ary), key) - begin(ary)
#define clr(a, b) memset((a), (b), sizeof(a))
#define bit(n) (1LL << (n))
// #define DEBUG
#ifdef DEBUG
#define dump(...) fprintf(stderr, __VA_ARGS__)
#else
#define dump(...)
#endif
template <class T> bool chmax(T &a, const T &b) {
return (a < b) ? (a = b, 1) : 0;
}
template <class T> bool chmin(T &a, const T &b) {
return (b < a) ? (a = b, 1) : 0;
}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf = 1LL << 62;
const ll mod = 1000000007LL;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll extgcd(ll a, ll b, ll &x, ll &y) {
x = 1, y = 0;
ll g = a;
if (b != 0)
g = extgcd(b, a % b, y, x), y -= a / b * x;
return g;
}
ll ADD(const ll &a, const ll &b, const ll &mod) { return (a + b) % mod; }
ll SUB(const ll &a, const ll &b, const ll &mod) { return (a - b + mod) % mod; }
ll MUL(const ll &a, const ll &b, const ll &mod) { return (1LL * a * b) % mod; }
ll DIV(const ll &a, const ll &b, const ll &mod) {
ll x, y;
extgcd(b, mod, x, y);
return MUL(a, (x + mod) % mod, mod);
}
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1, 6);
uniform_real_distribution<double> score(0.0, 10.0);
string in;
int n, idx;
int parse(int sum) {
// cerr << ">>>> " << sum << ", " << in.substr(idx) << endl;
char cur = in[idx];
if (isdigit(cur)) {
int mul = 0;
while (isdigit(in[idx])) {
mul = 10 * mul + (int)(in[idx] - '0');
idx++;
}
if (isupper(in[idx])) {
if (sum + mul >= n) {
throw in[idx];
}
idx++;
return mul * 1;
}
idx++; // read '('
int head = idx;
int len = 0;
while (in[idx] != ')') {
len += parse(sum + len);
}
idx++;
if (sum + mul * len >= n) {
n = (n - sum) % len;
if (n == 0)
n = len;
idx = head;
len = 0;
while (in[idx] != ')') {
len += parse(sum + len);
}
}
return mul * len;
} else if (isupper(cur)) {
int len = 0;
while (isupper(in[idx])) {
len++;
if (sum + len == n) {
throw in[idx];
}
idx++;
}
return len;
}
}
signed main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
for (; cin >> in >> n, in != "0";) {
n++;
in = "1(" + in + ")";
idx = 0;
char res = '0';
try {
parse(0);
} catch (char c) {
res = c;
}
cout << res << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
#define int long long
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) _range(i, 0, n)
#define _range(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _overload(__VA_ARGS__, _range, _rep, )(__VA_ARGS__)
#define _rrep(i, n) _rrange(i, n, 0)
#define _rrange(i, a, b) for (int i = (int)(a)-1; i >= (int)(b); --i)
#define rrep(...) _overload(__VA_ARGS__, _rrange, _rrep, )(__VA_ARGS__)
#define _all(arg) begin(arg), end(arg)
#define uniq(arg) sort(_all(arg)), (arg).erase(unique(_all(arg)), end(arg))
#define getidx(ary, key) lower_bound(_all(ary), key) - begin(ary)
#define clr(a, b) memset((a), (b), sizeof(a))
#define bit(n) (1LL << (n))
// #define DEBUG
#ifdef DEBUG
#define dump(...) fprintf(stderr, __VA_ARGS__)
#else
#define dump(...)
#endif
template <class T> bool chmax(T &a, const T &b) {
return (a < b) ? (a = b, 1) : 0;
}
template <class T> bool chmin(T &a, const T &b) {
return (b < a) ? (a = b, 1) : 0;
}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf = 1LL << 62;
const ll mod = 1000000007LL;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll extgcd(ll a, ll b, ll &x, ll &y) {
x = 1, y = 0;
ll g = a;
if (b != 0)
g = extgcd(b, a % b, y, x), y -= a / b * x;
return g;
}
ll ADD(const ll &a, const ll &b, const ll &mod) { return (a + b) % mod; }
ll SUB(const ll &a, const ll &b, const ll &mod) { return (a - b + mod) % mod; }
ll MUL(const ll &a, const ll &b, const ll &mod) { return (1LL * a * b) % mod; }
ll DIV(const ll &a, const ll &b, const ll &mod) {
ll x, y;
extgcd(b, mod, x, y);
return MUL(a, (x + mod) % mod, mod);
}
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1, 6);
uniform_real_distribution<double> score(0.0, 10.0);
string in;
int n, idx;
int parse(int sum) {
// cerr << ">>>> " << sum << ", " << in.substr(idx) << endl;
char cur = in[idx];
if (isdigit(cur)) {
int mul = 0;
while (isdigit(in[idx])) {
mul = 10 * mul + (int)(in[idx] - '0');
idx++;
}
if (isupper(in[idx])) {
if (sum + mul >= n) {
throw in[idx];
}
idx++;
return mul * 1;
}
idx++; // read '('
int head = idx;
int len = 0;
while (in[idx] != ')') {
len += parse(sum + len);
}
idx++; // read ')'
if (sum + mul * len >= n) {
n = (n - sum) % len;
if (n == 0)
n = len;
idx = head;
len = 0;
while (in[idx] != ')') {
len += parse(len);
}
}
return mul * len;
} else if (isupper(cur)) {
int len = 0;
while (isupper(in[idx])) {
len++;
if (sum + len == n) {
throw in[idx];
}
idx++;
}
return len;
}
}
signed main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
for (; cin >> in >> n, in != "0";) {
n++;
in = "1(" + in + ")";
idx = 0;
char res = '0';
try {
parse(0);
} catch (char c) {
res = c;
}
cout << res << endl;
}
return 0;
}
|
[["-", 0, 11, 12, 2, 3, 4, 0, 16, 31, 22], ["-", 0, 11, 12, 2, 3, 4, 0, 16, 17, 72]]
| 1
| 879
|
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, char>;
string S;
int n, it;
int num() {
int res = 0;
while (it < n && isdigit(S[it])) {
res = res * 10 + S[it] - '0';
it++;
}
return res;
}
P parser(int t) {
P res(0, '0');
while (it < n && S[it] != ')') {
if (isdigit(S[it])) {
int nm = num();
if (S[it] == '(') {
it++;
int tmp = it;
auto p = parser(t);
if (p.second != '0') {
res.second = p.second;
break;
} else if (t < p.first * nm) {
it = tmp;
t %= p.first;
res.second = parser(t).second;
}
t -= p.first * nm;
res.first += p.first * nm;
assert(S[it++] == ')');
} else {
if (t < nm) {
res.second = S[it];
}
t -= nm;
res.first += nm;
it++;
}
} else {
if (t == 0) {
res.second = S[it];
}
t--;
res.first++;
it++;
}
if (t < 0) {
break;
}
}
return res;
}
int main() {
int i;
while (cin >> S >> i, S != "0" || i != 0) {
n = S.size();
it = 0;
cout << parser(i).second << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, char>;
string S;
int n, it;
int num() {
int res = 0;
while (it < n && isdigit(S[it])) {
res = res * 10 + S[it] - '0';
it++;
}
return res;
}
P parser(int t) {
P res(0, '0');
while (it < n && S[it] != ')') {
if (isdigit(S[it])) {
int nm = num();
if (S[it] == '(') {
it++;
int tmp = it;
auto p = parser(t);
if (p.second != '0') {
res.second = p.second;
break;
} else if (t < p.first * nm) {
it = tmp;
t %= p.first;
res.second = parser(t).second;
break;
}
t -= p.first * nm;
res.first += p.first * nm;
assert(S[it++] == ')');
} else {
if (t < nm) {
res.second = S[it];
}
t -= nm;
res.first += nm;
it++;
}
} else {
if (t == 0) {
res.second = S[it];
}
t--;
res.first++;
it++;
}
if (t < 0) {
break;
}
}
return res;
}
int main() {
int i;
while (cin >> S >> i, S != "0" || i != 0) {
n = S.size();
it = 0;
cout << parser(i).second << endl;
}
return 0;
}
|
[["+", 75, 76, 0, 57, 64, 9, 0, 93, 0, 94], ["+", 75, 76, 0, 57, 64, 9, 0, 93, 0, 35]]
| 1
| 374
|
#include <iostream>
#include <string>
using namespace std;
string s;
int n;
void calc(string &p, int k) {
// cout << p << " " << k << endl;
if (k >= s.size())
return;
if (p.size() > n)
return;
if (s[k] == ')')
return;
if (s[k] <= 'Z' && s[k] >= 'A') {
p.push_back(s[k]);
calc(p, k + 1);
return;
}
string x;
int z = k;
bool flag = 0;
for (int i = k;; i++) {
if (s[i] == '(') {
z = i;
flag = 1;
break;
}
if (s[i] <= 'Z' && s[i] >= 'A') {
z = i - 1;
break;
}
x.push_back(s[i]);
}
int d = 0;
if (s[z] == '(')
d++;
int r;
for (int i = z + 1;; i++) {
if (s[i] == '(') {
d++;
}
if (s[i] == ')') {
d--;
}
if (d == 0) {
r = i;
break;
}
}
if (flag) {
int y = stoi(x);
for (int j = 0; j < y; j++) {
if (p.size() > n)
return;
calc(p, z + 1);
}
if (p.size() > n)
return;
if (p.size() < n) {
calc(p, r + 1);
}
} else {
int y = stoi(x);
for (int i = 0; i < y; i++) {
p.push_back(s[r]);
}
if (p.size() < n) {
calc(p, r + 1);
}
}
return;
}
int main() {
while (cin >> s >> n && s != "0") {
string p;
calc(p, 0);
if (p.size() <= n) {
cout << 0 << endl;
} else {
cout << p[n] << endl;
}
}
return 0;
}
|
#include <iostream>
#include <string>
using namespace std;
string s;
int n;
void calc(string &p, int k) {
// cout << p << " " << k << endl;
if (k >= s.size())
return;
if (p.size() > n)
return;
if (s[k] == ')')
return;
if (s[k] <= 'Z' && s[k] >= 'A') {
p.push_back(s[k]);
calc(p, k + 1);
return;
}
string x;
int z = k;
bool flag = 0;
for (int i = k;; i++) {
if (s[i] == '(') {
z = i;
flag = 1;
break;
}
if (s[i] <= 'Z' && s[i] >= 'A') {
z = i - 1;
break;
}
x.push_back(s[i]);
}
int d = 0;
if (s[z] == '(')
d++;
int r;
for (int i = z + 1;; i++) {
if (s[i] == '(') {
d++;
}
if (s[i] == ')') {
d--;
}
if (d == 0) {
r = i;
break;
}
}
if (flag) {
int y = stoi(x);
for (int j = 0; j < y; j++) {
if (p.size() > n)
return;
calc(p, z + 1);
}
if (p.size() > n)
return;
if (p.size() <= n) {
calc(p, r + 1);
}
} else {
int y = stoi(x);
for (int i = 0; i < y; i++) {
p.push_back(s[r]);
}
if (p.size() <= n) {
calc(p, r + 1);
}
}
return;
}
int main() {
while (cin >> s >> n && s != "0") {
string p;
calc(p, 0);
if (p.size() <= n) {
cout << 0 << endl;
} else {
cout << p[n] << endl;
}
}
return 0;
}
|
[["-", 64, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 64, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["-", 0, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 0, 9, 0, 57, 15, 339, 51, 16, 17, 19]]
| 1
| 488
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// common
typedef int i32;
typedef long long i64, ll;
typedef long double ld;
#define BR "\n"
#define ALL(c) (c).begin(), (c).end()
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, l, r) for (int i = (int)l; i < (int)(r); ++i)
#define EACH(it, o) for (auto it = (o).begin(); it != (o).end(); ++it)
#define IN(l, v, r) ((l) <= (v) && (v) < (r))
// config
//#define NDEBUG
//#define INF 1<<30
//#define EPS 1e-8
// const ll MOD =100000007;
// debug
#ifdef NDEBUG
#define DUMP(x)
#define DUMPLN(x)
#define DEBUG(x)
#define DEBUGLN(x)
#define LINE()
#define LINELN()
#define CHECK(exp, act)
#define STOP(e)
#else
#define DUMP(x) cerr << #x << " = " << (x)
#define DUMPLN(x) DUMP(x) << endl
#define DEBUG(x) DUMP(x) << LINE() << " " << __FILE__
#define DEBUGLN(x) DEBUG(x) << endl
#define LINE() cerr << " (L" << __LINE__ << ")"
#define LINELN() LINE() << endl
#define CHECK(exp, act) \
if (exp != act) { \
DUMPLN(exp); \
DEBUGLN(act); \
}
#define STOP(e) \
CHECK(e, true); \
if (!(e)) \
exit(1);
#endif
template <class T> inline string toString(const vector<T> &x) {
stringstream ss;
REP(i, x.size()) {
if (i != 0)
ss << " ";
ss << x[i];
}
return ss.str();
}
template <class T> inline string toString(const vector<vector<T>> &map) {
stringstream ss;
REP(i, map.size()) {
if (i != 0)
ss << BR;
ss << toString(map[i]);
}
return ss.str();
}
template <class K, class V> string toString(map<K, V> &x) {
string res;
stringstream ss;
for (auto &p : x)
ss << p.first << ":" << p.second << " ";
return ss.str();
}
string BITtoString(int bit) {
stringstream ss;
while (bit != 0) {
ss << (bit % 2);
bit /= 2;
}
string res = ss.str();
reverse(ALL(res));
return res;
}
template <typename T, typename V> inline T pmod(T v, V MOD) {
return (v % MOD + MOD) % MOD;
}
#define nextInt(n) scanf("%d", &n)
#define defInt(n) \
int n; \
nextInt(n)
#define nextLong(n) scanf("%lld", &n)
#define defLong(n) \
ll n; \
nextLong(n)
#define nextDouble(n) scanf("%lf", &n)
string str;
bool over;
string ans;
int p;
namespace SyntaxAnalysis {
typedef string::const_iterator Cursor;
// l.erase(remove(l.begin(), l.end(), ' '),
//l.end());//空白除去
class ParseError {};
string expression(Cursor &);
int number(Cursor &);
string seq(Cursor &);
// <四則演算の式> ::= <乗算除算の式> (+ or -) <乗算除算の式> (+ or -) ...
string expression(Cursor &c) {
string res = "";
if (over)
return res;
int v = 1;
while (c != str.end() && *c != ')') {
if (*c == '(') {
c++; // (
string data = expression(c);
REP(i, v) {
res += data;
if (p < (int)res.size() - 1) {
over = true;
ans = res[p];
return res;
}
}
c++; // )
v = 1;
} else if (isdigit(*c)) {
v = number(c);
} else { //文字
string data(1, *c);
c++;
REP(i, v) {
res += data;
if (p < (int)res.size() - 1) {
over = true;
ans = res[p];
return res;
}
}
v = 1;
}
}
return res;
}
// <数> ::= (0|1|2|3|4|5|6|7|8|9)+
int number(Cursor &c) {
stringstream ss;
while (isdigit(*c)) {
ss << *c;
c++;
}
int ret;
ss >> ret;
return ret;
}
// <文字>
string seq(Cursor &c) {
stringstream ss;
while (isupper(*c)) {
ss << *c;
c++;
}
return ss.str();
}
} // namespace SyntaxAnalysis
using namespace SyntaxAnalysis;
class Main {
public:
int N;
void run() {
// ifstream cin("D2");
// ofstream cout( "D2.out" );
while (true) {
over = false;
ans = "";
cin >> str;
if (str == "0")
break;
cin >> p;
Cursor c = str.begin();
expression(c);
if (!over)
cout << 0 << endl;
else
cout << ans << endl;
}
}
};
int main() {
cout << fixed << setprecision(15);
ios::sync_with_stdio(false);
Main().run();
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// common
typedef int i32;
typedef long long i64, ll;
typedef long double ld;
#define BR "\n"
#define ALL(c) (c).begin(), (c).end()
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, l, r) for (int i = (int)l; i < (int)(r); ++i)
#define EACH(it, o) for (auto it = (o).begin(); it != (o).end(); ++it)
#define IN(l, v, r) ((l) <= (v) && (v) < (r))
// config
//#define NDEBUG
//#define INF 1<<30
//#define EPS 1e-8
// const ll MOD =100000007;
// debug
#ifdef NDEBUG
#define DUMP(x)
#define DUMPLN(x)
#define DEBUG(x)
#define DEBUGLN(x)
#define LINE()
#define LINELN()
#define CHECK(exp, act)
#define STOP(e)
#else
#define DUMP(x) cerr << #x << " = " << (x)
#define DUMPLN(x) DUMP(x) << endl
#define DEBUG(x) DUMP(x) << LINE() << " " << __FILE__
#define DEBUGLN(x) DEBUG(x) << endl
#define LINE() cerr << " (L" << __LINE__ << ")"
#define LINELN() LINE() << endl
#define CHECK(exp, act) \
if (exp != act) { \
DUMPLN(exp); \
DEBUGLN(act); \
}
#define STOP(e) \
CHECK(e, true); \
if (!(e)) \
exit(1);
#endif
template <class T> inline string toString(const vector<T> &x) {
stringstream ss;
REP(i, x.size()) {
if (i != 0)
ss << " ";
ss << x[i];
}
return ss.str();
}
template <class T> inline string toString(const vector<vector<T>> &map) {
stringstream ss;
REP(i, map.size()) {
if (i != 0)
ss << BR;
ss << toString(map[i]);
}
return ss.str();
}
template <class K, class V> string toString(map<K, V> &x) {
string res;
stringstream ss;
for (auto &p : x)
ss << p.first << ":" << p.second << " ";
return ss.str();
}
string BITtoString(int bit) {
stringstream ss;
while (bit != 0) {
ss << (bit % 2);
bit /= 2;
}
string res = ss.str();
reverse(ALL(res));
return res;
}
template <typename T, typename V> inline T pmod(T v, V MOD) {
return (v % MOD + MOD) % MOD;
}
#define nextInt(n) scanf("%d", &n)
#define defInt(n) \
int n; \
nextInt(n)
#define nextLong(n) scanf("%lld", &n)
#define defLong(n) \
ll n; \
nextLong(n)
#define nextDouble(n) scanf("%lf", &n)
string str;
bool over;
string ans;
int p;
namespace SyntaxAnalysis {
typedef string::const_iterator Cursor;
// l.erase(remove(l.begin(), l.end(), ' '),
//l.end());//空白除去
class ParseError {};
string expression(Cursor &);
int number(Cursor &);
string seq(Cursor &);
// <四則演算の式> ::= <乗算除算の式> (+ or -) <乗算除算の式> (+ or -) ...
string expression(Cursor &c) {
string res = "";
if (over)
return res;
int v = 1;
while (c != str.end() && *c != ')') {
if (*c == '(') {
c++; // (
string data = expression(c);
REP(i, v) {
res += data;
if (p <= (int)res.size() - 1) {
over = true;
ans = res[p];
return res;
}
}
c++; // )
v = 1;
} else if (isdigit(*c)) {
v = number(c);
} else { //文字
string data(1, *c);
c++;
REP(i, v) {
res += data;
if (p <= (int)res.size() - 1) {
over = true;
ans = res[p];
return res;
}
}
v = 1;
}
}
return res;
}
// <数> ::= (0|1|2|3|4|5|6|7|8|9)+
int number(Cursor &c) {
stringstream ss;
while (isdigit(*c)) {
ss << *c;
c++;
}
int ret;
ss >> ret;
return ret;
}
// <文字>
string seq(Cursor &c) {
stringstream ss;
while (isupper(*c)) {
ss << *c;
c++;
}
return ss.str();
}
} // namespace SyntaxAnalysis
using namespace SyntaxAnalysis;
class Main {
public:
int N;
void run() {
// ifstream cin("D2");
// ofstream cout( "D2.out" );
while (true) {
over = false;
ans = "";
cin >> str;
if (str == "0")
break;
cin >> p;
Cursor c = str.begin();
expression(c);
if (!over)
cout << 0 << endl;
else
cout << ans << endl;
}
}
};
int main() {
cout << fixed << setprecision(15);
ios::sync_with_stdio(false);
Main().run();
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19]]
| 1
| 960
|
#!/usr/bin/ruby
def dfs(s,_l,_r)
r=''
i=_l
n=nil
while i<_r
if ('0'..'9').include?(s[i])
if !n
n=s[i].to_i
else
n=n*10+s[i].to_i
end
i+=1
elsif s[i]=='('
n=1 if !n
cnt=1
j=i+1
while cnt>0
if s[j]=='('
cnt+=1
elsif s[j]==')'
cnt-=1
end
j+=1
end
_r=dfs(s,i+1,j-1)
n.times{
r+=_r
return r if r.size>$n
}
n=nil
i=j
else
n=1 if !n
r+=s[i]*n
n=nil
i+=1
end
end
r
end
i=0
loop{
s,_=gets.split
break if s=='0'
$n=_.to_i
r=dfs(s,0,s.size)
puts r.size>$n ? r[$n] : '0'
}
|
#!/usr/bin/ruby
def dfs(s,_l,_r)
r=''
i=_l
n=nil
while i<_r
if ('0'..'9').include?(s[i])
if !n
n=s[i].to_i
else
n=n*10+s[i].to_i
end
i+=1
elsif s[i]=='('
n=1 if !n
cnt=1
j=i+1
while cnt>0
if s[j]=='('
cnt+=1
elsif s[j]==')'
cnt-=1
end
j+=1
end
r0=dfs(s,i+1,j-1)
n.times{
r+=r0
return r if r.size>$n
}
n=nil
i=j
else
n=1 if !n
r+=s[i]*n
n=nil
i+=1
end
end
r
end
i=0
loop{
s,_=gets.split
break if s=='0'
$n=_.to_i
r=dfs(s,0,s.size)
puts r.size>$n ? r[$n] : '0'
}
|
[["-", 0, 121, 75, 759, 64, 749, 0, 662, 31, 22], ["+", 0, 121, 75, 759, 64, 749, 0, 662, 31, 22], ["-", 0, 652, 196, 196, 8, 734, 0, 755, 12, 22], ["+", 0, 652, 196, 196, 8, 734, 0, 755, 12, 22]]
| 4
| 239
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String args[]) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
while (true) {
int parson = Integer.parseInt(br.readLine());
if (parson == 0)
break;
int point[] = new int[parson];
int max = 0;
int min = 0;
int maxI = 0;
int minI = 0;
for (int i = 0; i < parson; i++) {
point[i] = Integer.parseInt(br.readLine());
max = Math.max(max, point[i]);
min = Math.min(min, point[i]);
if (max == point[i])
maxI = i;
if (min == point[i]) {
minI = i;
}
}
int result = 0;
for (int i = 0; i < parson; i++) {
if (i != maxI && i != minI) {
result += point[i];
}
}
System.out.println(result / (parson - 2));
}
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String args[]) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
while (true) {
int parson = Integer.parseInt(br.readLine());
if (parson == 0)
break;
int point[] = new int[parson];
int max = 0;
int min = 1000;
int maxI = 0;
int minI = 0;
for (int i = 0; i < parson; i++) {
point[i] = Integer.parseInt(br.readLine());
max = Math.max(max, point[i]);
min = Math.min(min, point[i]);
if (max == point[i])
maxI = i;
if (min == point[i]) {
minI = i;
}
}
int result = 0;
for (int i = 0; i < parson; i++) {
if (i != maxI && i != minI) {
result += point[i];
}
}
System.out.println(result / (parson - 2));
// System.out.println(max + " " + min);
}
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
|
[["-", 0, 52, 8, 196, 0, 503, 49, 200, 51, 499], ["+", 0, 52, 8, 196, 0, 503, 49, 200, 51, 499]]
| 3
| 277
|
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader reader =
new BufferedReader(new InputStreamReader(System.in));
String s = reader.readLine();
int n = Integer.parseInt(s);
if (n == 0) {
System.exit(0);
}
int[] tensuu = new int[n];
for (int i = 0; i < n; i++) {
tensuu[i] = Integer.parseInt(reader.readLine());
}
Arrays.sort(tensuu);
int sum = 0;
for (int j = 1; j < n - 1; j++) {
sum += tensuu[j];
}
int ans = sum / (n - 2);
System.out.println(ans);
}
}
|
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader reader =
new BufferedReader(new InputStreamReader(System.in));
while (true) {
String s = reader.readLine();
int n = Integer.parseInt(s);
if (n == 0) {
System.exit(0);
}
int[] tensuu = new int[n];
for (int i = 0; i < n; i++) {
tensuu[i] = Integer.parseInt(reader.readLine());
}
Arrays.sort(tensuu);
int sum = 0;
for (int j = 1; j < n - 1; j++) {
sum += tensuu[j];
}
int ans = sum / (n - 2);
System.out.println(ans);
}
}
}
|
[["+", 8, 498, 0, 195, 8, 196, 0, 52, 0, 89], ["+", 0, 195, 8, 196, 0, 52, 15, 15, 0, 24], ["+", 0, 195, 8, 196, 0, 52, 15, 15, 0, 146], ["+", 0, 195, 8, 196, 0, 52, 15, 15, 0, 25], ["+", 0, 195, 8, 196, 0, 52, 8, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 52, 8, 196, 0, 46]]
| 3
| 182
|
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
while (n != 0) {
int i = 0;
int[] a = new int[n];
for (i = 0; i <= n - 1; i++) {
int j = s.nextInt();
a[i] = j;
}
int max = 0;
int min = 1000;
int sum = 0;
for (i = n - 1; i >= 0; i--) {
if (a[i] > max) {
max = a[i];
} else if (a[i] < min) {
min = a[i];
}
sum += a[i];
}
sum -= max;
sum -= min;
int point = sum / (n - 2);
System.out.println(point);
n = s.nextInt();
}
}
}
|
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
while (n != 0) {
int i = 0;
int[] a = new int[n];
for (i = 0; i <= n - 1; i++) {
int j = s.nextInt();
a[i] = j;
}
int max = 0;
int min = 1000;
int sum = 0;
for (i = n - 1; i >= 0; i--) {
if (a[i] > max) {
max = a[i];
}
if (a[i] < min) {
min = a[i];
}
sum += a[i];
}
sum -= max;
sum -= min;
int point = sum / (n - 2);
System.out.println(point);
n = s.nextInt();
}
}
}
|
[["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95]]
| 3
| 213
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true) {
int n = sc.nextInt();
if (n == 0)
break;
int sum = 0, maxi = 0, mini = 1000;
for (int i = 0; i < n; i++) {
int a = sc.nextInt();
sum += a;
maxi = Math.max(maxi, a);
mini = Math.max(mini, a);
}
System.out.println((sum - maxi - mini) / (n - 2));
}
return;
}
}
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true) {
int n = sc.nextInt();
if (n == 0)
break;
int sum = 0, maxi = 0, mini = 1000;
for (int i = 0; i < n; i++) {
int a = sc.nextInt();
sum += a;
maxi = Math.max(maxi, a);
mini = Math.min(mini, a);
}
System.out.println((sum - maxi - mini) / (n - 2));
}
return;
}
}
|
[["-", 8, 196, 0, 1, 0, 11, 12, 492, 141, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 492, 141, 22]]
| 3
| 145
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true) {
int n = sc.nextInt();
if (n == 0)
break;
int[] point = new int[n];
int sum = 0, max = 0, min = 1000;
for (int i = 0; i < n; i++) {
point[i] = sc.nextInt();
sum += point[i];
if (point[i] > max)
max = point[i];
if (point[i] < min)
min = point[i];
}
sum = sum - max - min;
System.out.println(sum);
}
}
}
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true) {
int n = sc.nextInt();
if (n == 0)
break;
int[] point = new int[n];
int sum = 0, max = 0, min = 1000;
for (int i = 0; i < n; i++) {
point[i] = sc.nextInt();
sum += point[i];
if (point[i] > max)
max = point[i];
if (point[i] < min)
min = point[i];
}
sum = sum - max - min;
System.out.println(sum / (n - 2));
}
}
}
|
[["+", 0, 1, 0, 492, 3, 4, 0, 16, 17, 85], ["+", 0, 492, 3, 4, 0, 16, 12, 23, 0, 24], ["+", 3, 4, 0, 16, 12, 23, 0, 16, 31, 22], ["+", 3, 4, 0, 16, 12, 23, 0, 16, 17, 33], ["+", 3, 4, 0, 16, 12, 23, 0, 16, 12, 499], ["+", 0, 492, 3, 4, 0, 16, 12, 23, 0, 25]]
| 3
| 165
|
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int s = 0;
int i = 0;
int n = 0;
int w = 0;
while (w == 0) {
s = sc.nextInt();
if (s == 0) {
break;
}
int a[] = new int[s];
for (i = 0; i < s; i++) {
a[i] = sc.nextInt();
}
Arrays.sort(a);
for (i = 1; i < s - 1; i++) {
n = n + a[i];
}
n = n / s;
System.out.println(n);
s = 0;
i = 0;
n = 0;
w = 0;
}
}
}
|
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int s = 0;
int i = 0;
int n = 0;
int w = 0;
while (w == 0) {
s = sc.nextInt();
if (s == 0) {
break;
}
int[] a = new int[s];
for (i = 0; i < s; i++) {
a[i] = sc.nextInt();
}
Arrays.sort(a);
for (i = 1; i < s - 1; i++) {
n = n + a[i];
}
n = n / (s - 2);
System.out.println(n);
s = 0;
i = 0;
n = 0;
w = 0;
}
}
}
|
[["-", 0, 52, 8, 196, 0, 503, 49, 200, 141, 22], ["+", 0, 52, 8, 196, 0, 503, 49, 200, 141, 22], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 12, 499], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25]]
| 3
| 189
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int n = sc.nextInt();
if (n == 0) {
break;
}
int max = 0;
int min = 1000;
int ten = 0;
for (int i = 0; i < n; i++) {
int s = sc.nextInt();
ten += s;
if (s > max) {
max = s;
} else if (s < min) {
min = s;
}
}
ten = (ten - max - min) / (n - 2);
System.out.println(ten);
}
sc.close();
}
}
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int n = sc.nextInt();
if (n == 0) {
break;
}
int max = 0;
int min = 1000;
int ten = 0;
for (int i = 0; i < n; i++) {
int s = sc.nextInt();
ten += s;
if (s > max) {
max = s;
}
if (s < min) {
min = s;
}
}
ten = (ten - max - min) / (n - 2);
System.out.println(ten);
}
sc.close();
}
}
|
[["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95]]
| 3
| 164
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int judge[], i, n, max, min, ave;
Scanner sc = new Scanner(System.in);
while (true) {
n = sc.nextInt();
if (n == 0)
break;
judge = new int[n];
ave = 0;
max = -1;
min = 101;
for (i = 0; i < n; i++) {
judge[i] = sc.nextInt();
if (judge[i] > max)
max = judge[i];
if (judge[i] < min)
min = judge[i];
ave += judge[i];
}
ave -= (max + min);
ave /= i - 2;
System.out.println(ave);
}
}
}
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int judge[], i, n, max, min, ave;
Scanner sc = new Scanner(System.in);
while (true) {
n = sc.nextInt();
if (n == 0)
break;
judge = new int[n];
ave = 0;
max = -1;
min = 1001;
for (i = 0; i < n; i++) {
judge[i] = sc.nextInt();
if (judge[i] > max)
max = judge[i];
if (judge[i] < min)
min = judge[i];
ave += judge[i];
}
ave -= (max + min);
ave /= i - 2;
System.out.println(ave);
}
}
}
|
[["-", 0, 52, 8, 196, 0, 1, 0, 11, 12, 499], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 12, 499]]
| 3
| 181
|
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String arg[]) {
Scanner in = new Scanner(System.in);
for (;;) {
int n = in.nextInt();
if (n == 0)
return;
boolean a[] = new boolean[300001];
Arrays.fill(a, true);
for (int i = 2; i <= 300000; i++) {
if (!a[i])
continue;
if (i % 7 == 1 || i % 7 == 6)
for (int j = i + i; j <= 300000; j += i)
a[j] = false;
}
for (int i = 0; i <= 300000; i++) {
if (i % 7 != 1 && i % 7 != 6)
a[i] = false;
}
System.out.print(n + ":");
for (int i = 2; i <= n; i++) {
if (a[i])
if (n % i == 0)
System.out.print(" " + i);
}
System.out.println();
}
}
}
|
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String arg[]) {
Scanner in = new Scanner(System.in);
for (;;) {
int n = in.nextInt();
if (n == 1)
return;
boolean a[] = new boolean[300001];
Arrays.fill(a, true);
for (int i = 2; i <= 300000; i++) {
if (!a[i])
continue;
if (i % 7 == 1 || i % 7 == 6)
for (int j = i + i; j <= 300000; j += i)
a[j] = false;
}
for (int i = 0; i <= 300000; i++) {
if (i % 7 != 1 && i % 7 != 6)
a[i] = false;
}
System.out.print(n + ":");
for (int i = 2; i <= n; i++) {
if (a[i])
if (n % i == 0)
System.out.print(" " + i);
}
System.out.println();
}
}
}
|
[["-", 8, 196, 0, 57, 15, 15, 0, 16, 12, 499], ["+", 8, 196, 0, 57, 15, 15, 0, 16, 12, 499]]
| 3
| 252
|
import java.util.Scanner;
public class Main {
static final int N = 300000;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int answer;
int[] table = new int[N + 1];
for (int i = 0; i < N; i++)
table[i] = 0;
for (int i = 6; i <= N; i += 7) {
table[i] = 1;
table[i + 2] = 1;
}
for (int i = 6; i <= N; i++)
if (table[i] == 1)
for (int j = i * 2; j <= N; j += i)
table[j] = 0;
while (true) {
int n = sc.nextInt();
if (n == 1)
break;
System.out.print(n + ":");
for (int i = 6; i < N / 6; i++)
if (table[i] == 1 && n % i == 0)
System.out.print(" " + i);
System.out.println("");
}
sc.close();
}
}
|
import java.util.Scanner;
public class Main {
static final int N = 300000;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int answer;
int[] table = new int[N + 1];
for (int i = 0; i < N; i++)
table[i] = 0;
for (int i = 6; i <= N; i += 7) {
table[i] = 1;
table[i + 2] = 1;
}
for (int i = 6; i <= N; i++)
if (table[i] == 1)
for (int j = i * 2; j <= N; j += i)
table[j] = 0;
while (true) {
int n = sc.nextInt();
if (n == 1)
break;
System.out.print(n + ":");
for (int i = 6; i < N; i++)
if (table[i] == 1 && n % i == 0)
System.out.print(" " + i);
System.out.println("");
}
sc.close();
}
}
|
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 85], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 499]]
| 3
| 255
|
#include <math.h>
#include <stdio.h>
#define MAX 300000
int main() {
int i, j;
int n;
int board[MAX + 1];
for (i = 0; i < MAX; i++) {
board[i] = (i % 7 == 1 || i % 7 == 6);
}
board[1] = 0;
j = 6;
while (j < MAX) {
for (i = 2 * j; i < MAX; i++)
board[i] = 0;
j++;
while (!board[j]) {
if (j == MAX - 1)
break;
j++;
}
if (j == MAX - 1)
j++;
}
while (scanf("%d", &n), n != 1) {
printf("%d:", n);
for (i = 0; i < n; i++) {
if (board[i]) {
if (n % i == 0)
printf(" %d", i);
}
}
puts("");
}
return 0;
}
|
#include <stdio.h>
#include <math.h>
#define MAX 300000
int main() {
int i, j;
int n;
int board[MAX + 1];
for (i = 0; i < MAX; i++) {
board[i] = (i % 7 == 1 || i % 7 == 6);
}
board[1] = 0;
j = 6;
while (j < MAX) {
for (i = 2 * j; i < MAX; i += j)
board[i] = 0;
j++;
while (!board[j]) {
if (j == MAX - 1)
break;
j++;
}
if (j == MAX - 1)
j++;
}
while (scanf("%d", &n), n != 1) {
printf("%d:", n);
for (i = 0; i <= n; i++) {
if (board[i]) {
if (n % i == 0)
printf(" %d", i);
}
}
puts("");
}
return 0;
}
|
[["-", 36, 36, 36, 36, 0, 30, 0, 135, 136, 137], ["-", 36, 36, 36, 36, 0, 30, 0, 135, 0, 138], ["+", 36, 36, 36, 36, 0, 30, 0, 135, 0, 138], ["+", 36, 36, 36, 36, 0, 30, 0, 135, 136, 137], ["-", 0, 52, 8, 9, 0, 7, 26, 27, 17, 29], ["+", 0, 52, 8, 9, 0, 7, 26, 11, 17, 107], ["+", 0, 52, 8, 9, 0, 7, 26, 11, 12, 22], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
| 0
| 218
|
#include <math.h>
#include <stdio.h>
int main(void) {
int tg, i, j, n, l[300001] = {0}, c = 0;
for (i = 2; i < 300001; i++) {
if (i % 7 == 1 | i % 7 == 6) {
l[c] = i;
c++;
}
}
for (i = 0; i < (int)(sqrt(c)); i++) {
if (!l[i]) {
continue;
}
for (j = i + 1; j < c; j++) {
if (!(l[j] % l[i])) {
l[j] = 0;
}
}
}
while (1) {
scanf("%d", &tg);
if (tg == 1) {
break;
}
printf("%d: ", tg);
for (i = 0; i < c; i++) {
if (l[i] && !(tg % l[i])) {
printf("%d ", l[i]);
}
}
printf("\b\n");
}
return 0;
}
|
#include <math.h>
#include <stdio.h>
int main(void) {
int tg, i, j, n, l[300001] = {0}, c = 0;
for (i = 2; i < 300001; i++) {
if (i % 7 == 1 | i % 7 == 6) {
l[c] = i;
c++;
}
}
for (i = 0; i < (int)(sqrt(c)); i++) {
if (!l[i]) {
continue;
}
for (j = i + 1; j < c; j++) {
if (!(l[j] % l[i])) {
l[j] = 0;
}
}
}
while (1) {
scanf("%d", &tg);
if (tg == 1) {
break;
}
printf("%d:", tg);
for (i = 0; i < c; i++) {
if (l[i] && !(tg % l[i])) {
printf(" %d", l[i]);
}
}
printf("\n");
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 242
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const int MAXN = 300000;
vector<int> msprimes;
bool isprime[MAXN + 1];
void seive() {
for (int i = 0; i <= MAXN; i++)
isprime[i] = true;
isprime[0] = isprime[1] = false;
for (int i = 2; i <= MAXN; i++) {
if (i % 7 != 1 && i % 7 != 6)
continue;
if (isprime[i]) {
msprimes.push_back(i);
for (int j = 2 * i; j <= MAXN; j += i)
isprime[j] = false;
}
}
}
void solve(int x) {
printf("%d:", x);
for (int p : msprimes) {
if (p > x)
break;
if (x % p == 0) {
printf(" %d", p);
x /= p;
}
}
printf("\n");
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
// get Monday-Saturday Primes
seive();
// for(int p: msprimes) cout << p << endl;
while (1) {
int x;
cin >> x;
if (x == 1)
break;
solve(x);
}
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const int MAXN = 300000;
vector<int> msprimes;
bool isprime[MAXN + 1];
void seive() {
for (int i = 0; i <= MAXN; i++)
isprime[i] = true;
isprime[0] = isprime[1] = false;
for (int i = 2; i <= MAXN; i++) {
if (i % 7 != 1 && i % 7 != 6)
continue;
if (isprime[i]) {
msprimes.push_back(i);
for (int j = 2 * i; j <= MAXN; j += i)
isprime[j] = false;
}
}
}
void solve(int x) {
printf("%d:", x);
for (int p : msprimes) {
if (p > x)
break;
if (x % p == 0) {
printf(" %d", p);
}
}
printf("\n");
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
// get Monday-Saturday Primes
seive();
// for(int p: msprimes) cout << p << endl;
while (1) {
int x;
cin >> x;
if (x == 1)
break;
solve(x);
}
}
|
[["-", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22], ["-", 0, 57, 64, 9, 0, 1, 0, 11, 17, 90], ["-", 0, 57, 64, 9, 0, 1, 0, 11, 12, 22], ["-", 8, 9, 0, 57, 64, 9, 0, 1, 0, 35]]
| 1
| 264
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define rep(i, b) for (int i = 0; i < b; i++)
using namespace std;
bool smp[300001];
int main() {
rep(i, 300001) { //月曜土曜数の判定
if ((i % 7 == 1) || (i % 7 == 6))
smp[i] = true;
else
smp[i] = false;
}
smp[1] = false;
rep(i, 300001) {
if (smp[i]) {
for (int j = i * 2; j < 300001; j += i) {
smp[j] = false;
}
}
}
int n = 0;
while (cin >> n, n != 1) {
cout << n << ':';
rep(i, n + 1) {
if (smp[i] && n % i == 0)
cout << i << ' ';
}
cout << endl;
}
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define rep(i, b) for (int i = 0; i < b; i++)
using namespace std;
bool smp[300001];
int main() {
rep(i, 300001) { //月曜土曜数の判定
if ((i % 7 == 1) || (i % 7 == 6))
smp[i] = true;
else
smp[i] = false;
}
smp[1] = false;
rep(i, 300001) {
if (smp[i]) {
for (int j = i * 2; j < 300001; j += i) {
smp[j] = false;
}
}
}
int n = 0;
while (cin >> n, n != 1) {
cout << n << ':';
rep(i, n + 1) {
if (smp[i] && n % i == 0)
cout << ' ' << i;
}
cout << endl;
}
}
|
[["-", 0, 57, 64, 1, 0, 16, 31, 16, 12, 22], ["-", 0, 9, 0, 57, 64, 1, 0, 16, 17, 151], ["+", 0, 9, 0, 57, 64, 1, 0, 16, 17, 151], ["+", 0, 9, 0, 57, 64, 1, 0, 16, 12, 22]]
| 1
| 205
|
#include <bits/stdc++.h>
using namespace std;
const int N_MAX = 300010;
vector<int> primes;
void sieve() {
vector<bool> is_prime(N_MAX, true);
int cnt = 1;
while (true) {
for (int i = -1; i <= 2; i += 2) {
int x = cnt * 7 + i;
if (is_prime[x]) {
for (int j = 2 * x; j < N_MAX; j += x)
is_prime[j] = false;
primes.push_back(x);
}
}
if (cnt * 7 > N_MAX)
break;
cnt++;
}
}
int N;
void solve() {
cout << N << ":";
for (auto v : primes)
if (N % v == 0)
cout << " " << v;
cout << endl;
}
int main() {
while (cin >> N, N != 1)
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N_MAX = 300010;
vector<int> primes;
void sieve() {
vector<bool> is_prime(N_MAX, true);
int cnt = 1;
while (true) {
for (int i = -1; i <= 2; i += 2) {
int x = cnt * 7 + i;
if (is_prime[x]) {
for (int j = 2 * x; j < N_MAX; j += x)
is_prime[j] = false;
primes.push_back(x);
}
}
if (cnt * 7 > N_MAX)
break;
cnt++;
}
}
int N;
void solve() {
cout << N << ":";
for (auto v : primes)
if (N % v == 0)
cout << " " << v;
cout << endl;
}
int main() {
sieve();
while (cin >> N, N != 1)
solve();
return 0;
}
|
[["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["+", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35]]
| 1
| 192
|
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define ALL(g) (g).begin(), (g).end()
#define REP(i, x, n) for (int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define F(i, j, k) fill(i[0], i[0] + j * j, k)
#define P(p) cout << (p) << endl;
#define EXIST(s, e) ((s).find(e) != (s).end())
#define INF 1 << 25
#define pb push_back
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef long long ll;
#define MAX_N 300000
int main() {
bool isMonFri[MAX_N + 1];
REP(i, 6, MAX_N + 1) {
if (i % 7 == 1 || i % 7 == 6)
isMonFri[i] = true;
}
vi v;
REP(i, 6, MAX_N + 1) {
if (isMonFri[i]) {
v.pb(i);
for (int j = i + i; j < MAX_N + 1; j += i) {
isMonFri[j] = false;
}
}
}
int n;
while (cin >> n) {
cout << n << ":";
rep(i, v.size()) {
if (n % v[i] == 0)
cout << " " << v[i];
}
cout << endl;
}
return 0;
}
|
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define ALL(g) (g).begin(), (g).end()
#define REP(i, x, n) for (int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define F(i, j, k) fill(i[0], i[0] + j * j, k)
#define P(p) cout << (p) << endl;
#define EXIST(s, e) ((s).find(e) != (s).end())
#define INF 1 << 25
#define pb push_back
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef long long ll;
#define MAX_N 300000
int main() {
bool isMonFri[MAX_N + 1];
REP(i, 6, MAX_N + 1) {
if (i % 7 == 1 || i % 7 == 6)
isMonFri[i] = true;
}
vi v;
REP(i, 6, MAX_N + 1) {
if (isMonFri[i]) {
v.pb(i);
for (int j = i + i; j < MAX_N + 1; j += i) {
isMonFri[j] = false;
}
}
}
int n;
while (cin >> n, n != 1) {
cout << n << ":";
rep(i, v.size()) {
if (n % v[i] == 0)
cout << " " << v[i];
}
cout << endl;
}
return 0;
}
|
[["+", 8, 9, 0, 52, 15, 339, 51, 34, 0, 21], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 31, 22], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 17, 79], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 12, 13]]
| 1
| 315
|
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
using namespace std;
bool G[300000] = {};
int main() {
for (int i = 8; i <= 300000; i += 7) {
G[i] = true;
for (int j = 6; j * j <= i; j += 7) {
if (i % (j) == 0 || i % (j + 2) == 0) {
G[i] = false;
break;
}
}
}
for (int i = 6; i <= 300000; i += 7) {
G[i] = true;
for (int j = 6; j * j <= i; j += 7) {
if (i % (j) == 0 || i % (j + 2) == 0) {
G[i] = false;
break;
}
}
}
int N;
while (1) {
cin >> N;
if (N == 1)
break;
cout << N << ":";
for (int i = 7; i <= 300000; i += 7) {
if (G[i - 1] == true) {
if (N % (i - 1) == 0)
cout << " " << i - 1;
}
if (G[i + 1] == true) {
if (N % (i + 1) == 0)
cout << " " << i + 1;
}
}
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
using namespace std;
bool G[300000] = {};
int main() {
for (int i = 8; i <= 300000; i += 7) {
G[i] = true;
for (int j = 6; j * j <= i; j += 7) {
if (i % (j) == 0 || i % (j + 2) == 0) {
G[i] = false;
break;
}
}
}
for (int i = 6; i <= 300000; i += 7) {
G[i] = true;
for (int j = 6; j * j <= i; j += 7) {
if (i % (j) == 0 || i % (j + 2) == 0) {
G[i] = false;
break;
}
}
}
int N;
while (1) {
cin >> N;
if (N == 1)
break;
cout << N << ":";
for (int i = 7; i <= 300000; i += 7) {
if (G[i - 1] == true) {
if (N % (i - 1) == 0)
cout << " " << i - 1;
}
if (G[i + 1] == true) {
if (N % (i + 1) == 0)
cout << " " << i + 1;
}
}
cout << endl;
}
return 0;
}
|
[["+", 0, 52, 8, 9, 0, 1, 0, 16, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 52, 8, 9, 0, 1, 0, 16, 12, 22], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 1
| 296
|
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
#define FOR(i, init, n) for (int i = init; i < n; i++)
#define REP(i, n) FOR(i, 0, n)
#define MON 1
#define SAT 6
int isPrime(int cand) {
// int i, limit;
int limit = sqrt(cand);
// limit = (int)sqrt((double)cand);
int i = limit;
if (cand < 2) {
return (0);
}
while (i > 1) {
if (cand % i == 0) {
break;
}
i--;
}
// for (; i > 1; i--){
// //for (i = limit; i > 1; i--){
// if (cand % i == 0){
// break;
// }
//}
if (i == 1) {
return (1);
} else {
return (0);
}
// else{
// return(0);
//}
}
int isMonSatPrime(int cand) {
if (cand % 7 != 1 && cand % 7 != 6) {
return (0);
}
if (cand < 2) {
return (0);
}
int i = 6;
int next = MON;
while (i > 1) {
if (cand % i == 0) {
break;
}
i += next == SAT ? 5 : 2;
next = next == SAT ? MON : SAT;
// if (next == SAT){
// i += 5;
// next = MON;
//}
// else if (next == MON){
// i += 2;
// next = SAT;
//}
}
return i == cand ? 1 : 0;
// if (i == (cand)){
// return(1);
//}
// else{
// //puts("?????????????´???°??§??????????????????");
// return(0);
//}
}
int main() {
// FILE* fin = freopen("input.txt", "r", stdin);
// FILE* fout = freopen("output.txt", "w", stdout);
while (1) {
int num;
scanf("%d", &num);
if (num == 1) {
break;
}
printf("%d:", num);
// int i = 6;
int next = MON;
for (int i = 0; i <= num;
i += next == SAT ? 5 : 2, next = next == SAT ? MON : SAT) {
if (num % i == 0) {
if (isMonSatPrime(i) == 1) {
printf(" %d", i);
}
}
}
// while (i <= num){
// if (num%i == 0){
// if (isMonSatPrime(i) == 1){
// printf(" %d", i);
// }
// }
// i += next == SAT ? 2 : 5;
// next = next == SAT ? MON : SAT;
// //if (next == SAT){
// // i += 5;
// // next = MON;
// //}
// //else if (next == MON){
// // i += 2;
// // next = SAT;
// //}
//}
puts("");
}
return 0;
}
|
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
#define FOR(i, init, n) for (int i = init; i < n; i++)
#define REP(i, n) FOR(i, 0, n)
#define MON 1
#define SAT 6
int isPrime(int cand) {
// int i, limit;
int limit = sqrt(cand);
// limit = (int)sqrt((double)cand);
int i = limit;
if (cand < 2) {
return (0);
}
while (i > 1) {
if (cand % i == 0) {
break;
}
i--;
}
// for (; i > 1; i--){
// //for (i = limit; i > 1; i--){
// if (cand % i == 0){
// break;
// }
//}
if (i == 1) {
return (1);
} else {
return (0);
}
// else{
// return(0);
//}
}
int isMonSatPrime(int cand) {
if (cand % 7 != 1 && cand % 7 != 6) {
return (0);
}
if (cand < 2) {
return (0);
}
int i = 6;
int next = MON;
while (i > 1) {
if (cand % i == 0) {
break;
}
i += next == SAT ? 5 : 2;
next = next == SAT ? MON : SAT;
// if (next == SAT){
// i += 5;
// next = MON;
//}
// else if (next == MON){
// i += 2;
// next = SAT;
//}
}
return i == cand ? 1 : 0;
// if (i == (cand)){
// return(1);
//}
// else{
// //puts("?????????????´???°??§??????????????????");
// return(0);
//}
}
int main() {
// FILE* fin = freopen("input.txt", "r", stdin);
// FILE* fout = freopen("output.txt", "w", stdout);
while (1) {
int num;
scanf("%d", &num);
if (num == 1) {
break;
}
printf("%d:", num);
// int i = 6;
int next = MON;
for (int i = 6; i <= num;
i += next == SAT ? 5 : 2, next = next == SAT ? MON : SAT) {
if (num % i == 0) {
if (isMonSatPrime(i) == 1) {
printf(" %d", i);
}
}
}
// while (i <= num){
// if (num%i == 0){
// if (isMonSatPrime(i) == 1){
// printf(" %d", i);
// }
// }
// i += next == SAT ? 2 : 5;
// next = next == SAT ? MON : SAT;
// //if (next == SAT){
// // i += 5;
// // next = MON;
// //}
// //else if (next == MON){
// // i += 2;
// // next = SAT;
// //}
//}
puts("");
}
return 0;
}
|
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13]]
| 1
| 380
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define INF 1000000000
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long int ll;
vector<ll> P(300001, 0);
void era() {
for (int i = 6; i < 300001; i++) {
if (P[i] == 0)
continue;
int j = i;
while (j < 300001) {
j += i;
if (j >= 300001)
break;
P[j] = 0;
}
}
}
int main() {
P[1] = 1;
int i = 1;
while (true) {
int p, q;
p = i * 7 - 1;
q = i * 7 + 1;
i++;
if (p < 300001) {
P[p] = p;
} else {
break;
}
if (q < 300001) {
P[q] = q;
} else {
break;
}
}
era();
for (;;) {
ll num;
cin >> num;
if (num == 1)
break;
cout << num << ":";
for (int i = 0; i <= num; i++) {
if (P[i] != 0 and num % i == 0) {
cout << " " << i;
}
}
cout << endl;
}
}
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define INF 1000000000
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long int ll;
vector<ll> P(300001, 0);
void era() {
for (int i = 6; i < 300001; i++) {
if (P[i] == 0)
continue;
int j = i;
while (j < 300001) {
j += i;
if (j >= 300001)
break;
P[j] = 0;
}
}
}
int main() {
P[1] = 1;
int i = 1;
while (true) {
int p, q;
p = i * 7 - 1;
q = i * 7 + 1;
i++;
if (p < 300001) {
P[p] = p;
} else {
break;
}
if (q < 300001) {
P[q] = q;
} else {
break;
}
}
era();
for (;;) {
ll num;
cin >> num;
if (num == 1)
break;
cout << num << ":";
for (int i = 2; i <= num; i++) {
if (P[i] != 0 and num % i == 0) {
cout << " " << i;
}
}
cout << endl;
}
}
|
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13]]
| 1
| 292
|
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, x, y) for (int(i) = (x); (i) < (y); (i)++)
int main() {
while (true) {
vector<int> temp;
rep(i, 0, 300001) { temp.push_back(i); }
int n;
cin >> n;
if (n == 1) {
break;
}
cout << n << ":";
rep(i, 6, 300001) {
if (temp[i] % 7 == 1 || temp[i] % 7 == 6) {
if (temp[i] != 0) {
if (n % temp[i] == 0) {
cout << " " << temp[i];
}
for (int j = i + i; j <= n; j += i) {
temp[j] = 0;
}
}
}
}
}
return 0;
}
|
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, x, y) for (int(i) = (x); (i) < (y); (i)++)
int main() {
while (true) {
vector<int> temp;
rep(i, 0, 300001) { temp.push_back(i); }
int n;
cin >> n;
if (n == 1) {
break;
}
cout << n << ":";
rep(i, 6, 300001) {
if (temp[i] % 7 == 1 || temp[i] % 7 == 6) {
if (temp[i] != 0) {
if (n % temp[i] == 0) {
cout << " " << temp[i];
}
for (int j = i + i; j <= n; j += i) {
temp[j] = 0;
}
}
}
}
cout << endl;
}
return 0;
}
|
[["+", 0, 52, 8, 9, 0, 1, 0, 16, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 52, 8, 9, 0, 1, 0, 16, 12, 22], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 1
| 176
|
// #define USE_CPP11
// #define USE_PRINTF
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#ifdef USE_CPP11
#include <functional>
#include <unordered_map>
#include <unordered_set>
#endif
#define PRINT(obj) cout << obj << endl
#define REP(i, n) for (int(i) = 0; (i) < (n); i++)
#define SPACE " "
typedef long long ll;
const int INF = 1e9 + 10;
using namespace std;
namespace Scanner {
#ifdef USE_PRINTF
int nextInt() {
int d;
scanf("%d", &d);
return d;
}
float nextFloat() {
float f;
scanf("%f", &f);
return f;
}
double nextDouble() {
double f;
scanf("%lf", &f);
return f;
}
string nextString() {
string s;
scanf("%s", &s);
return s;
}
ll nextll() {
ll l;
scanf("%ll", &l);
return l;
}
#else
int nextInt() {
int d;
cin >> d;
return d;
}
float nextFloat() {
float f;
cin >> f;
return f;
}
double nextDouble() {
double f;
cin >> f;
return f;
}
string nextString() {
string s;
cin >> s;
return s;
}
ll nextll() {
ll l;
cin >> l;
return l;
}
#endif
string getLine() {
string input;
getline(cin, input);
return input;
}
}; // namespace Scanner
namespace myLibrary {
vector<string> split(const string &str, char delim) {
vector<string> ret;
size_t current = 0, found;
while ((found = str.find_first_of(delim, current)) != string::npos) {
ret.push_back(string(str, current, found - current));
current = found + 1;
}
ret.push_back(string(str, current, str.size() - current));
return ret;
}
#ifdef USE_CPP11
///
/// higher-order functional
/// This is something like map in haskell, python, etc.
/// Sample usage:
/// vector<int> a = {1, 2, 3, 4, 5};
/// vector<int> b = myLibrary::_Map<int, int>(a, [](int n){
/// return n * n;
/// });
/// Result:
/// b = 1, 4, 9, 16, 25
///
template <typename T_IN, typename T_OUT, class Functor>
vector<T_OUT> _Map(vector<T_IN> src, Functor func) {
vector<T_OUT> ret;
for (int i = 0; i < src.size(); i++) {
ret.push_back(func(src[i]));
}
return ret;
}
#endif
}; // namespace myLibrary
struct Point {
public:
int y, x;
Point(int y, int x) : y(y), x(x) {}
Point() {}
};
/// BEGIN //////////////////////////////////////////////////////////
int main() {
while (true) {
int n = Scanner::nextInt();
if (n == 1) {
break;
}
cout << n << ":";
for (int i = n; i <= n; i++) {
if (i % 7 != 1 && i % 7 != 6) {
continue;
}
if (n % i == 0) {
bool flag = true;
for (int j = 6; j < i; j++) {
if (j % 7 != 1 && j % 7 != 6) {
continue;
}
if (i % j == 0) {
flag = false;
break;
}
}
if (flag) {
cout << SPACE << i;
}
}
}
cout << endl;
}
return 0;
}
/// END //////////////////////////////////////////////////////////
|
// #define USE_CPP11
// #define USE_PRINTF
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#ifdef USE_CPP11
#include <functional>
#include <unordered_map>
#include <unordered_set>
#endif
#define PRINT(obj) cout << obj << endl
#define REP(i, n) for (int(i) = 0; (i) < (n); i++)
#define SPACE " "
typedef long long ll;
const int INF = 1e9 + 10;
using namespace std;
namespace Scanner {
#ifdef USE_PRINTF
int nextInt() {
int d;
scanf("%d", &d);
return d;
}
float nextFloat() {
float f;
scanf("%f", &f);
return f;
}
double nextDouble() {
double f;
scanf("%lf", &f);
return f;
}
string nextString() {
string s;
scanf("%s", &s);
return s;
}
ll nextll() {
ll l;
scanf("%ll", &l);
return l;
}
#else
int nextInt() {
int d;
cin >> d;
return d;
}
float nextFloat() {
float f;
cin >> f;
return f;
}
double nextDouble() {
double f;
cin >> f;
return f;
}
string nextString() {
string s;
cin >> s;
return s;
}
ll nextll() {
ll l;
cin >> l;
return l;
}
#endif
string getLine() {
string input;
getline(cin, input);
return input;
}
}; // namespace Scanner
namespace myLibrary {
vector<string> split(const string &str, char delim) {
vector<string> ret;
size_t current = 0, found;
while ((found = str.find_first_of(delim, current)) != string::npos) {
ret.push_back(string(str, current, found - current));
current = found + 1;
}
ret.push_back(string(str, current, str.size() - current));
return ret;
}
#ifdef USE_CPP11
///
/// higher-order functional
/// This is something like map in haskell, python, etc.
/// Sample usage:
/// vector<int> a = {1, 2, 3, 4, 5};
/// vector<int> b = myLibrary::_Map<int, int>(a, [](int n){
/// return n * n;
/// });
/// Result:
/// b = 1, 4, 9, 16, 25
///
template <typename T_IN, typename T_OUT, class Functor>
vector<T_OUT> _Map(vector<T_IN> src, Functor func) {
vector<T_OUT> ret;
for (int i = 0; i < src.size(); i++) {
ret.push_back(func(src[i]));
}
return ret;
}
#endif
}; // namespace myLibrary
struct Point {
public:
int y, x;
Point(int y, int x) : y(y), x(x) {}
Point() {}
};
/// BEGIN //////////////////////////////////////////////////////////
int main() {
while (true) {
int n = Scanner::nextInt();
if (n == 1) {
break;
}
cout << n << ":";
for (int i = 6; i <= n; i++) {
if (i % 7 != 1 && i % 7 != 6) {
continue;
}
if (n % i == 0) {
bool flag = true;
for (int j = 6; j < i; j++) {
if (j % 7 != 1 && j % 7 != 6) {
continue;
}
if (i % j == 0) {
flag = false;
break;
}
}
if (flag) {
cout << SPACE << i;
}
}
}
cout << endl;
}
return 0;
}
/// END //////////////////////////////////////////////////////////
|
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 22], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13]]
| 1
| 687
|
#include <cmath>
#include <iostream>
using namespace std;
const int MAX = 300200;
int p[MAX];
int q[MAX];
int l = 0;
void prime() {
int n = 0;
for (int i = 6; i < MAX; i++) {
bool flag = 1;
if (i % 7 == 1 || i % 7 == 6) {
q[n] = i;
for (int j = 0; q[j] < sqrt(i); j++) {
if (i % q[j] == 0) {
flag = 0;
break;
}
}
if (flag == 1)
p[l++] = q[n++];
}
}
}
int main() {
int num;
prime();
while (1) {
cin >> num;
if (num == 1)
break;
cout << num << ":";
for (int i = 0; p[i] <= num; i++) {
if (num % p[i] == 0)
cout << " " << p[i];
}
cout << endl;
}
return 0;
}
|
#include <cmath>
#include <iostream>
using namespace std;
const int MAX = 300200;
int p[MAX];
int q[MAX];
int l = 0;
void prime() {
int n = 0;
for (int i = 6; i < MAX; i++) {
bool flag = 1;
if (i % 7 == 1 || i % 7 == 6) {
q[n] = i;
for (int j = 0; q[j] < i; j++) {
if (i % q[j] == 0) {
flag = 0;
break;
}
}
if (flag == 1)
p[l++] = q[n++];
}
}
}
int main() {
int num;
prime();
while (1) {
cin >> num;
if (num == 1)
break;
cout << num << ":";
for (int i = 0; p[i] <= num; i++) {
if (num % p[i] == 0)
cout << " " << p[i];
}
cout << endl;
}
return 0;
}
|
[["-", 64, 9, 0, 7, 15, 16, 12, 2, 63, 22], ["-", 0, 7, 15, 16, 12, 2, 3, 4, 0, 24], ["-", 0, 7, 15, 16, 12, 2, 3, 4, 0, 25]]
| 1
| 232
|
#include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define vi vector<int>
#define vvi vector<vector<int>>
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
template <class T, class S> void cmin(T &a, const S &b) {
if (a > b)
a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
if (a < b)
a = b;
}
#define MAX (300000 + 10)
using namespace std;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
int main() {
vector<int> v;
for (int i = 0; 7 * i + 6 < MAX; i++) {
if (!i) {
v.push_back(6);
continue;
}
v.push_back(7 * i + 1);
v.push_back(7 * i + 6);
}
vector<int> p;
p.push_back(6);
vector<bool> flag(MAX, true);
for (int i = 0; i < v.size(); i++) {
if (!flag[v[i]])
continue;
for (int j = 0; v[j] * v[i] < MAX; j++)
flag[v[i] * v[j]] = false;
}
int n;
while (cin >> n, n != 1) {
vector<int> ans;
int range = (int)(upper_bound(all(v), n) - v.begin());
for (int i = range; i >= 0; i--) {
if (v[i] > n)
continue;
if (!(n % v[i]))
if (flag[v[i]])
ans.push_back(v[i]);
}
reverse(all(ans));
cout << n << ":";
rep(i, ans.size()) if (i) cout << " " << ans[i];
else cout << ans[i];
cout << endl;
}
}
|
#include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define vi vector<int>
#define vvi vector<vector<int>>
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
template <class T, class S> void cmin(T &a, const S &b) {
if (a > b)
a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
if (a < b)
a = b;
}
#define MAX (300000 + 10)
using namespace std;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
int main() {
vector<int> v;
for (int i = 0; 7 * i + 6 < MAX; i++) {
if (!i) {
v.push_back(6);
continue;
}
v.push_back(7 * i + 1);
v.push_back(7 * i + 6);
}
vector<int> p;
p.push_back(6);
vector<bool> flag(MAX, true);
for (int i = 0; i < v.size(); i++) {
if (!flag[v[i]])
continue;
for (int j = 0; v[j] * v[i] < MAX; j++)
flag[v[i] * v[j]] = false;
}
int n;
while (cin >> n, n != 1) {
vector<int> ans;
int range = (int)(upper_bound(all(v), n) - v.begin());
for (int i = range; i >= 0; i--) {
if (v[i] > n)
continue;
if (!(n % v[i]))
if (flag[v[i]])
ans.push_back(v[i]);
}
reverse(all(ans));
cout << n << ": ";
rep(i, ans.size()) if (i) cout << " " << ans[i];
else cout << ans[i];
cout << endl;
}
}
|
[["-", 8, 9, 0, 1, 0, 16, 12, 5, 0, 6], ["+", 8, 9, 0, 1, 0, 16, 12, 5, 0, 6]]
| 1
| 519
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.