buggy_code
stringlengths 11
625k
| fixed_code
stringlengths 17
625k
| bug_type
stringlengths 2
4.45k
| language
int64 0
8
| token_count
int64 5
200k
| change_count
int64 0
100
|
|---|---|---|---|---|---|
#include <iostream>
using namespace std;
struct Sweets {
int i, p, q, r;
};
int main() {
int n;
Sweets s[1000];
while (1) {
cin >> n;
if (n == 0)
break;
for (int i = 0; i < n; i++) {
cin >> s[i].i >> s[i].p >> s[i].q >> s[i].r;
}
int P, Q, R, C;
cin >> P >> Q >> R >> C;
int sum = 0;
for (int i = 0; i < n; i++) {
if (s[i].p <= P && s[i].q <= Q && s[i].r <= R &&
(s[i].p + s[i].q + s[i].r) <= C) {
cout << s[i].i << endl;
sum++;
}
}
if (sum == 0)
cout << "NA" << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
struct Sweets {
int i, p, q, r;
};
int main() {
int n;
Sweets s[1000];
while (1) {
cin >> n;
if (n == 0)
break;
for (int i = 0; i < n; i++) {
cin >> s[i].i >> s[i].p >> s[i].q >> s[i].r;
}
int P, Q, R, C;
cin >> P >> Q >> R >> C;
int sum = 0;
for (int i = 0; i < n; i++) {
if (s[i].p <= P && s[i].q <= Q && s[i].r <= R &&
(s[i].p * 4 + s[i].q * 9 + s[i].r * 4) <= C) {
cout << s[i].i << endl;
sum++;
}
}
if (sum == 0)
cout << "NA" << endl;
}
return 0;
}
|
[["+", 31, 23, 0, 16, 31, 16, 31, 16, 17, 48], ["+", 31, 23, 0, 16, 31, 16, 31, 16, 12, 13], ["+", 31, 23, 0, 16, 31, 16, 12, 16, 17, 48], ["+", 31, 23, 0, 16, 31, 16, 12, 16, 12, 13], ["+", 12, 16, 31, 23, 0, 16, 12, 16, 17, 48], ["+", 12, 16, 31, 23, 0, 16, 12, 16, 12, 13]]
| 1
| 226
| 6
|
#include <iostream>
using namespace std;
int main() {
int n;
while (true) {
int i[1000], p[1000], q[1000], r[1000];
cin >> n;
if (n == 0)
break;
for (int j = 0; j < n; j++) {
cin >> i[j] >> p[j] >> q[j] >> r[j];
}
int P, Q, R, C;
int sp = 0, sq = 0, sr = 0;
int cal[1000];
int count = 0;
cin >> P >> Q >> R >> C;
for (int j = 0; j < n; j++) {
sp = p[j] * 4;
sq = q[j] * 9;
sr = r[j] * 4;
cal[j] = sp + sq + sr;
// cout << sp << ' ' << sq << ' ' << sr << ' ' << cal[j] << endl;
if (P > p[j] && Q > q[j] && R > r[j] && C > cal[j]) {
count++;
cout << i[j] << endl;
}
}
if (count == 0)
cout << "NA" << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int n;
while (true) {
int i[1000], p[1000], q[1000], r[1000];
cin >> n;
if (n == 0)
break;
for (int j = 0; j < n; j++) {
cin >> i[j] >> p[j] >> q[j] >> r[j];
}
int P, Q, R, C;
int sp = 0, sq = 0, sr = 0;
int cal[1000];
int count = 0;
cin >> P >> Q >> R >> C;
for (int j = 0; j < n; j++) {
sp = p[j] * 4;
sq = q[j] * 9;
sr = r[j] * 4;
cal[j] = sp + sq + sr;
if (P >= p[j] && Q >= q[j] && R >= r[j] && C >= cal[j]) {
count++;
cout << i[j] << endl;
}
}
if (count == 0)
cout << "NA" << endl;
}
return 0;
}
|
[["-", 51, 16, 31, 16, 31, 16, 31, 16, 17, 47], ["+", 51, 16, 31, 16, 31, 16, 31, 16, 17, 20], ["-", 51, 16, 31, 16, 31, 16, 12, 16, 17, 47], ["+", 51, 16, 31, 16, 31, 16, 12, 16, 17, 20], ["-", 15, 339, 51, 16, 31, 16, 12, 16, 17, 47], ["+", 15, 339, 51, 16, 31, 16, 12, 16, 17, 20], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 47], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 20]]
| 1
| 251
| 8
|
#include <cstdio>
using namespace std;
int main() {
int n;
while (scanf("%d", &n), n) {
int a[1024], b[1024], c[1024], d[1024], cal[1024];
for (int i = 0; i < n; i++) {
scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
cal[i] = (4 * b[i]) + (7 * c[i]) + (4 * d[i]);
}
int P, Q, R, C;
scanf("%d%d%d%d", &P, &Q, &R, &C);
bool f = false;
for (int i = 0; i < n; i++) {
if (b[i] <= P && c[i] <= Q && d[i] <= R && cal[i] <= C) {
printf("%d\n", a[i]);
f = true;
}
}
if (f == false)
printf("NA\n");
}
return 0;
}
|
#include <cstdio>
using namespace std;
int main() {
int n;
while (scanf("%d", &n), n) {
int a[1024], b[1024], c[1024], d[1024], cal[1024];
for (int i = 0; i < n; i++) {
scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
cal[i] = (4 * b[i]) + (9 * c[i]) + (4 * d[i]);
}
int P, Q, R, C;
scanf("%d%d%d%d", &P, &Q, &R, &C);
bool f = false;
for (int i = 0; i < n; i++) {
if (b[i] <= P && c[i] <= Q && d[i] <= R && cal[i] <= C) {
printf("%d\n", a[i]);
f = true;
}
}
if (f == false)
printf("NA\n");
}
return 0;
}
|
[["-", 12, 16, 31, 16, 12, 23, 0, 16, 31, 13], ["+", 12, 16, 31, 16, 12, 23, 0, 16, 31, 13]]
| 1
| 251
| 2
|
#include <iostream>
#include <vector>
using namespace std;
int main() {
for (;;) {
int n;
cin >> n;
if (n == 0)
break;
vector<vector<int>> v(n, vector<int>(4));
for (int i = 0; i < n; i++) {
cin >> v[i][0] >> v[i][1] >> v[i][2] >> v[i][3];
}
int P, Q, R, C;
cin >> P >> Q >> R >> C;
bool bfind = false;
for (int i = 0; i < n; i++) {
if (v[i][1] > P)
continue;
if (v[i][2] > Q)
continue;
if (v[i][3] > R)
continue;
if ((v[i][1] + v[i][3]) * 4 + v[i][2] * 7 > C)
continue;
cout << v[i][0] << endl;
bfind = true;
}
if (!bfind)
cout << "NA" << endl;
}
return 0;
}
|
#include <iostream>
#include <vector>
using namespace std;
int main() {
for (;;) {
int n;
cin >> n;
if (n == 0)
break;
vector<vector<int>> v(n, vector<int>(4));
for (int i = 0; i < n; i++) {
cin >> v[i][0] >> v[i][1] >> v[i][2] >> v[i][3];
}
int P, Q, R, C;
cin >> P >> Q >> R >> C;
bool bfind = false;
for (int i = 0; i < n; i++) {
if (v[i][1] > P)
continue;
if (v[i][2] > Q)
continue;
if (v[i][3] > R)
continue;
if ((v[i][1] + v[i][3]) * 4 + v[i][2] * 9 > C)
continue;
cout << v[i][0] << endl;
bfind = true;
}
if (!bfind)
cout << "NA" << endl;
}
return 0;
}
|
[["-", 15, 339, 51, 16, 31, 16, 12, 16, 12, 13], ["+", 15, 339, 51, 16, 31, 16, 12, 16, 12, 13]]
| 1
| 256
| 2
|
#include <iostream>
using namespace std;
int main() {
int P, Q, R, C;
int n, h;
while (cin >> n) {
if (n == 0)
break;
h = 0;
int i[n], p[n], q[n], r[n];
for (int j = 0; j < n; j++)
cin >> i[j] >> p[j] >> q[j] >> r[j];
cin >> P >> Q >> R >> C;
for (int j = 0; j < n; j++) {
if (p[j] > P)
continue;
if (q[j] > Q)
continue;
if (r[j] > R)
continue;
if (4 * p[j] + 9 * q[j] + 4 * r[j] > C)
continue;
else {
cout << i[j] << endl;
h = 1;
}
}
if (h == 1)
cout << "NA" << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int P, Q, R, C;
int n, h;
while (cin >> n) {
if (n == 0)
break;
h = 0;
int i[n], p[n], q[n], r[n];
for (int j = 0; j < n; j++)
cin >> i[j] >> p[j] >> q[j] >> r[j];
cin >> P >> Q >> R >> C;
for (int j = 0; j < n; j++) {
if (p[j] > P)
continue;
if (q[j] > Q)
continue;
if (r[j] > R)
continue;
if (4 * p[j] + 9 * q[j] + 4 * r[j] > C)
continue;
else {
cout << i[j] << endl;
h = 1;
}
}
if (h == 0)
cout << "NA" << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
| 1
| 222
| 2
|
#include <bits/stdc++.h>
using namespace std;
#define MAX 1000
int main() {
int N, Num[MAX], P[MAX], Q[MAX], R[MAX], Cal[MAX];
while (cin >> N, N) {
int p, q, r, c;
for (int i = 0; i < N; i++) {
cin >> Num[i] >> P[i] >> Q[i] >> R[i];
Cal[i] = P[i] * 4 + Q[i] * 9 + R[i] * 4;
}
vector<int> ans;
cin >> p >> q >> r >> c;
for (int i = 0; i < N; i++) {
if (P[i] <= p && Q[i] <= q && R[i] <= r && Cal[i] <= c) {
ans.push_back(Num[i]);
break;
}
}
int size = ans.size();
if (size) {
for (int i = 0; i < size; i++) {
cout << ans[i] << endl;
}
} else {
cout << "NA" << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define MAX 1000
int main() {
int N, Num[MAX], P[MAX], Q[MAX], R[MAX], Cal[MAX];
while (cin >> N, N) {
int p, q, r, c;
for (int i = 0; i < N; i++) {
cin >> Num[i] >> P[i] >> Q[i] >> R[i];
Cal[i] = P[i] * 4 + Q[i] * 9 + R[i] * 4;
}
vector<int> ans;
cin >> p >> q >> r >> c;
for (int i = 0; i < N; i++) {
if (P[i] <= p && Q[i] <= q && R[i] <= r && Cal[i] <= c) {
ans.push_back(Num[i]);
}
}
int size = ans.size();
if (size) {
for (int i = 0; i < size; i++) {
cout << ans[i] << endl;
}
} else {
cout << "NA" << endl;
}
}
return 0;
}
|
[["-", 8, 9, 0, 57, 64, 9, 0, 93, 0, 94], ["-", 8, 9, 0, 57, 64, 9, 0, 93, 0, 35]]
| 1
| 256
| 2
|
while 1:
N = int(input())
if N == 0:break
cals = [ list(map(int,input().split())) for i in range(N)]
P,Q,R,C = list(map(int,input().split()))
res = [ x for x in cals if x[1]<=P and x[2]<=Q and x[3]<=R and 4*x[1] + 9*x[2] + 4*x[3]]
if len(res) == 0:print('NA')
else:
for i in res:
print(i[0])
|
while 1:
N = int(input())
if N == 0:break
cals = [ list(map(int,input().split())) for i in range(N)]
P,Q,R,C = list(map(int,input().split()))
res = [ x for x in cals if x[1]<=P and x[2]<=Q and x[3]<=R and 4*x[1] + 9*x[2] + 4*x[3] <= C]
if len(res) == 0:print('NA')
else:
for i in res:
print(i[0])
|
[["+", 12, 658, 0, 678, 0, 679, 12, 666, 667, 19], ["+", 12, 658, 0, 678, 0, 679, 12, 666, 0, 22]]
| 5
| 145
| 2
|
while True:
n = int(input())
if n == 0:
break
s = []
for i in range(n):
s.append([int(i) for i in input().split()])
p, q, r, c = [int(i) for i in input().split()]
possible = []
for i in range(n):
if (s[i][1] <= p) & (s[i][2] <= q) & (s[i][3] <= r) & ((4 * (s[i][1] + s[i][3]) + 9 * s[i][2]) <= c):
possible.append(i + 1)
if possible == []:
print('NA')
else:
for i in possible:
print(i)
|
while True:
n = int(input())
if n == 0:
break
s = []
for i in range(n):
s.append([int(i) for i in input().split()])
p, q, r, c = [int(i) for i in input().split()]
possible = []
for i in range(n):
if (s[i][1] <= p) & (s[i][2] <= q) & (s[i][3] <= r) & ((4 * (s[i][1] + s[i][3]) + 9 * s[i][2]) <= c):
possible.append(s[i][0])
if possible == []:
print('NA')
else:
for i in possible:
print(i)
|
[["+", 0, 652, 3, 4, 0, 206, 51, 206, 51, 22], ["+", 0, 652, 3, 4, 0, 206, 51, 206, 0, 70], ["-", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["-", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612], ["+", 0, 652, 3, 4, 0, 206, 51, 206, 0, 73], ["+", 0, 1, 0, 652, 3, 4, 0, 206, 0, 70], ["+", 0, 1, 0, 652, 3, 4, 0, 206, 206, 612], ["+", 0, 1, 0, 652, 3, 4, 0, 206, 0, 73]]
| 5
| 190
| 8
|
#include <math.h>
#include <stdio.h>
int main(void) {
int n, y, i, b, t, maxb;
double sum, r, max;
for (; max = 0, scanf("%d", &n), n;) {
scanf("%d", &y);
for (i = 0; i < n; i++) {
scanf("%d %lf %d", &b, &r, &t);
switch (t) {
case 1:
sum = (1 + y * r / 100);
break;
case 2:
sum = pow((double)(1 + r / 100), y);
break;
}
if (max < sum) {
max = sum;
maxb = i;
}
}
printf("%d\n", maxb + 1);
}
return 0;
}
|
#include <math.h>
#include <stdio.h>
int main(void) {
int n, y, i, b, t, maxb;
double sum, r, max;
for (; max = 0, scanf("%d", &n), n;) {
scanf("%d", &y);
for (i = 0; i < n; i++) {
scanf("%d %lf %d", &b, &r, &t);
switch (t) {
case 1:
sum = (1 + y * r / 100);
break;
case 2:
sum = pow((double)(1 + r / 100), y);
break;
}
if (max < sum) {
max = sum;
maxb = b;
}
}
printf("%d\n", maxb);
}
return 0;
}
|
[["-", 0, 57, 64, 9, 0, 1, 0, 11, 12, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 22], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 17, 72], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
| 0
| 171
| 4
|
#include <stdio.h>
int main() {
int n, y, i, j, b, r, t, num;
double ans, max;
while (1) {
max = 0.0;
scanf("%d", &n);
if (n == 0)
break;
scanf("%d", &y);
for (i = 0; i < n; i++) {
scanf("%d%d%d", &b, &r, &t);
if (t == 1) {
ans = (1 + y * (double)r / 100);
}
else {
for (j = 0; j < y; j++) {
ans *= (1 + (double)r / 100);
}
}
if (max < ans) {
num = b;
max = ans;
}
}
printf("%d\n", num);
}
return 0;
}
|
#include <stdio.h>
int main() {
int n, y, i, j, b, r, t, num;
double ans, max;
while (1) {
max = 0.0;
scanf("%d", &n);
if (n == 0)
break;
scanf("%d", &y);
for (i = 0; i < n; i++) {
scanf("%d%d%d", &b, &r, &t);
if (t == 1) {
ans = (1 + y * (double)r / 100);
}
else {
ans = 1.0;
for (j = 0; j < y; j++) {
ans *= (1 + (double)r / 100);
}
}
if (max < ans) {
num = b;
max = ans;
}
}
printf("%d\n", num);
}
return 0;
}
|
[["+", 75, 76, 0, 9, 0, 1, 0, 11, 31, 22], ["+", 75, 76, 0, 9, 0, 1, 0, 11, 17, 32], ["+", 75, 76, 0, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 57, 75, 76, 0, 9, 0, 1, 0, 35]]
| 0
| 182
| 4
|
#include <math.h>
#include <stdio.h>
double calcuate(int y, int t, int r) {
if (t == 1) {
return 1.0 * (1.0 + y * (double)r / 100);
} else {
return 1.0 * pow(1.0 + (double)r / 100, y);
}
}
int main(void) {
int n, y, b, r, t;
int i;
double max, now;
int maxno;
while (1) {
scanf("%d", &n);
if (n == 0)
break;
scanf("%d", &y);
max = maxno = 0;
for (i = 0; i < n; i++) {
scanf("%d%d%d", &b, &r, &t);
now = calcuate(y, t, r);
if (now > max) {
max = now;
maxno = b;
}
}
printf("%d\n", &maxno);
}
return 0;
}
|
#include <math.h>
#include <stdio.h>
double calcuate(int y, int t, int r) {
if (t == 1) {
return 1.0 * (1.0 + y * (double)r / 100);
} else {
return 1.0 * pow(1.0 + (double)r / 100, y);
}
}
int main(void) {
int n, y, b, r, t;
int i;
double max, now;
int maxno;
while (1) {
scanf("%d", &n);
if (n == 0)
break;
scanf("%d", &y);
max = maxno = 0;
for (i = 0; i < n; i++) {
scanf("%d%d%d", &b, &r, &t);
now = calcuate(y, t, r);
if (now > max) {
max = now;
maxno = b;
}
}
printf("%d\n", maxno);
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 66, 17, 67]]
| 0
| 203
| 1
|
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
#define loop(i, a, b) for (int i = (a); i < int(b); i++)
#define rep(i, b) loop(i, 0, b)
int main() {
int n;
while (cin >> n) {
int y;
cin >> y;
double mr = 0;
int maxb = -1;
rep(i, n) {
double b, r, t;
cin >> b >> r >> t;
double rate = 1;
if (t == 0)
rate = (1 + y * r / 100);
else {
rep(j, y) rate *= (1 + r / 100);
}
if (rate > mr) {
mr = rate;
maxb = b;
}
}
cout << maxb << endl;
}
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
#define loop(i, a, b) for (int i = (a); i < int(b); i++)
#define rep(i, b) loop(i, 0, b)
int main() {
int n;
while (cin >> n && n) {
int y;
cin >> y;
double mr = 0;
int maxb = -1;
rep(i, n) {
double b, r, t;
cin >> b >> r >> t;
double rate = 1;
if (t == 1)
rate = (1 + y * r / 100);
else {
rep(j, y) rate *= (1 + r / 100);
}
if (rate > mr) {
mr = rate;
maxb = b;
}
}
cout << maxb << endl;
}
}
|
[["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 98], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 12, 22], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
| 1
| 149
| 4
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double EPS = 1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main() {
int n;
while (cin >> n, n) {
int y;
cin >> y;
double ma = -1;
int out;
rep(i, n) {
int a, b, c;
cin >> a >> b >> c;
double tmp;
if (c == 1)
tmp = 1 + y * b / 100.0;
else
tmp = pow(a + b / 100.0, y);
if (ma < tmp) {
ma = tmp;
out = a;
}
}
cout << out << endl;
}
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double EPS = 1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main() {
int n;
while (cin >> n, n) {
int y;
cin >> y;
double ma = -1;
int out;
rep(i, n) {
int a, b, c;
cin >> a >> b >> c;
double tmp;
if (c == 1)
tmp = 1 + y * b / 100.0;
else
tmp = pow(1 + b / 100.0, y);
if (ma < tmp) {
ma = tmp;
out = a;
}
}
cout << out << endl;
}
}
|
[["-", 0, 11, 12, 2, 3, 4, 0, 16, 31, 22], ["+", 0, 11, 12, 2, 3, 4, 0, 16, 31, 13]]
| 1
| 195
| 2
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, maxi, n, y, b, r, t;
while (cin >> n, n) {
cin >> y;
double maxm = 0;
for (i = 0; i < n; ++i) {
cin >> b >> r >> t;
double m = (t == 1) ? (double)(1.0 + (double)y * (double)r / 100)
: (double)(pow((1 + (double)r / 100), y));
if (maxm < m) {
maxm = m;
maxi = i;
}
}
cout << maxi + 1 << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, maxi, n, y, b, r, t;
while (cin >> n, n) {
cin >> y;
double maxm = 0;
for (i = 0; i < n; ++i) {
cin >> b >> r >> t;
double m = (t == 1) ? (double)(1.0 + (double)y * (double)r / 100)
: (double)(pow((1 + (double)r / 100), y));
if (maxm < m) {
maxm = m;
maxi = b;
}
}
cout << maxi << endl;
}
return 0;
}
|
[["-", 0, 57, 64, 9, 0, 1, 0, 11, 12, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 22], ["-", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["-", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
| 1
| 145
| 4
|
#include <cmath>
#include <cstdio>
int n, y, b, r, t;
int main() {
while (~scanf("%d", &n)) {
if (!n)
break;
int p = 0;
double d = 0, e;
scanf("%d", &y);
for (int i = 0; i < n; i++) {
scanf("%d%d%d", &b, &r, &t);
if (t == 1)
e = y * r * 0.01;
else
e = pow(1 + r * 0.01, y);
if (d < e)
d = e, p = b;
}
printf("%d\n", p);
}
return 0;
}
|
#include <cmath>
#include <cstdio>
int n, y, b, r, t;
int main() {
while (~scanf("%d", &n)) {
if (!n)
break;
int p = 0;
double d = 0, e;
scanf("%d", &y);
for (int i = 0; i < n; i++) {
scanf("%d%d%d", &b, &r, &t);
if (t == 1)
e = 1 + y * r * 0.01;
else
e = pow(1 + r * 0.01, y);
if (d < e)
d = e, p = b;
}
printf("%d\n", p);
}
return 0;
}
|
[["+", 0, 57, 64, 1, 0, 11, 12, 16, 31, 13], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 17, 72]]
| 1
| 152
| 2
|
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define fi first
#define se second
template <typename A, typename B> inline bool chmax(A &a, B b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename A, typename B> inline bool chmin(A &a, B b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1ll << 29;
const ll MOD = 1000000007;
const double EPS = 1e-9;
int main() {
int n;
while (cin >> n, n) {
int y;
cin >> y;
double ma = -1;
int manum = -1;
REP(i, n) {
double b, r, t;
scanf("%lf %lf %lf", &b, &r, &t);
double now;
if (t == 1) {
now = 1 + y * (r / 100);
} else {
now = 1 + pow(1 + r / 100, y);
}
if (chmax(ma, now))
manum = b;
}
cout << manum << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define fi first
#define se second
template <typename A, typename B> inline bool chmax(A &a, B b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename A, typename B> inline bool chmin(A &a, B b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1ll << 29;
const ll MOD = 1000000007;
const double EPS = 1e-9;
int main() {
int n;
while (cin >> n, n) {
int y;
cin >> y;
double ma = -1;
int manum = -1;
REP(i, n) {
double b, r, t;
scanf("%lf %lf %lf", &b, &r, &t);
double now;
if (t == 1) {
now = 1 + y * (r / 100);
} else {
now = pow(1 + r / 100, y);
}
if (chmax(ma, now))
manum = b;
}
cout << manum << endl;
}
return 0;
}
|
[["-", 0, 9, 0, 1, 0, 11, 12, 16, 31, 13], ["-", 0, 9, 0, 1, 0, 11, 12, 16, 17, 72]]
| 1
| 296
| 2
|
#include <cmath>
#include <iostream>
using namespace std;
int main() {
int n, y;
while (cin >> n) {
cin >> y;
int b, r, t, res;
double mx = 0;
for (int i = 0; i < n; ++i) {
cin >> b >> r >> t;
if (t == 1) {
double interest = 100.0 * (1 + y * r / 100.0);
if (mx < interest) {
mx = interest;
res = b;
}
} else {
double interest = 100.0 * pow(1 + r / 100.0, y);
if (mx < interest) {
mx = interest;
res = b;
}
}
}
cout << res << endl;
}
return 0;
}
|
#include <cmath>
#include <iostream>
using namespace std;
int main() {
int n, y;
while (cin >> n, n) {
cin >> y;
int b, r, t, res;
double mx = 0;
for (int i = 0; i < n; ++i) {
cin >> b >> r >> t;
if (t == 1) {
double interest = 100.0 * (1 + y * r / 100.0);
if (mx < interest) {
mx = interest;
res = b;
}
} else {
double interest = 100.0 * pow(1 + r / 100.0, y);
if (mx < interest) {
mx = interest;
res = b;
}
}
}
cout << res << endl;
}
return 0;
}
|
[["+", 8, 9, 0, 52, 15, 339, 51, 34, 0, 21], ["+", 8, 9, 0, 52, 15, 339, 51, 34, 12, 22]]
| 1
| 152
| 2
|
#include <iostream>
using namespace std;
double f(double k, int p) {
if (p == 0)
return 1;
else
return k * f(k, p - 1);
}
int main() {
int n;
while (cin >> n) {
int y;
cin >> y;
double maxv = 0;
int maxn;
for (int i = 1; i <= n; i++) {
int b, t;
double r;
cin >> b >> r >> t;
double v;
if (t == 1)
v = 1 + y * r / 100;
else
v = f(1 + r / 100, y);
if (v > maxv) {
maxv = v;
maxn = b;
}
}
cout << maxn << endl;
}
}
|
#include <iostream>
using namespace std;
double f(double k, int p) {
if (p == 0)
return 1;
else
return k * f(k, p - 1);
}
int main() {
int n;
while (cin >> n, n) {
int y;
cin >> y;
double maxv = 0;
int maxn;
for (int i = 1; i <= n; i++) {
int b, t;
double r;
cin >> b >> r >> t;
double v;
if (t == 1)
v = 1 + y * r / 100;
else
v = f(1 + r / 100, y);
if (v > maxv) {
maxv = v;
maxn = b;
}
}
cout << maxn << endl;
}
}
|
[["+", 8, 9, 0, 52, 15, 339, 51, 34, 0, 21], ["+", 8, 9, 0, 52, 15, 339, 51, 34, 12, 22]]
| 1
| 158
| 2
|
#include <cmath>
#include <cstdio>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main() {
for (int n; scanf("%d", &n), n;) {
int y, ans;
scanf("%d", &y);
double p_ans = -1;
rep(i, n) {
int b, r, t;
scanf("%d%d%d", &b, &r, &t);
double p;
if (t == 1) { // tanri
p = 1 + y * r / 100.0;
} else { // fukuri
p = pow(1 + r / 100.0, y);
}
if (p_ans < p)
p_ans = p, ans = i + 1;
}
printf("%d\n", ans);
}
return 0;
}
|
#include <cmath>
#include <cstdio>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main() {
for (int n; scanf("%d", &n), n;) {
int y, ans;
scanf("%d", &y);
double p_ans = -1;
rep(i, n) {
int b, r, t;
scanf("%d%d%d", &b, &r, &t);
double p;
if (t == 1) { // tanri
p = 1 + y * r / 100.0;
} else { // fukuri
p = pow(1 + r / 100.0, y);
}
if (p_ans < p)
p_ans = p, ans = b;
}
printf("%d\n", ans);
}
return 0;
}
|
[["-", 64, 1, 0, 34, 12, 11, 12, 16, 31, 22], ["-", 64, 1, 0, 34, 12, 11, 12, 16, 17, 72], ["-", 64, 1, 0, 34, 12, 11, 12, 16, 12, 13], ["+", 0, 57, 64, 1, 0, 34, 12, 11, 12, 22]]
| 1
| 161
| 4
|
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <utility>
int main() {
int n, y, r, t;
std::pair<double, int> b[50];
while (scanf("%d", &n), n) {
scanf("%d", &y);
for (int i = 0; i < n; ++i) {
scanf("%d%d%d", &b[i].second, &r, &t);
if (r - 2)
b[i].first = 1 + t / 100.0 * y;
else
b[i].first = pow(1 + t / 100.0, (double)y);
}
std::sort(b, b + n);
printf("%d\n", b[n - 1].second);
}
return 0;
}
|
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <utility>
int main() {
int n, y, r, t;
std::pair<double, int> b[50];
while (scanf("%d", &n), n) {
scanf("%d", &y);
for (int i = 0; i < n; ++i) {
scanf("%d%d%d", &b[i].second, &r, &t);
if (t - 2)
b[i].first = 1 + r / 100.0 * y;
else
b[i].first = pow(1 + r / 100.0, (double)y);
}
std::sort(b, b + n);
printf("%d\n", b[n - 1].second);
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["-", 0, 11, 12, 16, 12, 16, 31, 16, 31, 22], ["+", 0, 11, 12, 16, 12, 16, 31, 16, 31, 22], ["-", 12, 2, 3, 4, 0, 16, 12, 16, 31, 22], ["+", 12, 2, 3, 4, 0, 16, 12, 16, 31, 22]]
| 1
| 173
| 6
|
#include <cmath>
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
int main() {
while (true) {
int n, y, res;
double mx = 0;
cin >> n;
if (n == 0)
break;
cin >> y;
while (n--) {
int b, r, t;
cin >> b >> r >> t;
double k;
if (t == 1)
k = 1 + (double)k / 100 * y;
else
k = pow(1 + (double)k / 100, y);
if (k > mx) {
mx = k;
res = b;
}
}
cout << res << endl;
}
return 0;
}
|
#include <cmath>
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
int main() {
while (true) {
int n, y, res;
double mx = 0;
cin >> n;
if (n == 0)
break;
cin >> y;
while (n--) {
int b, r, t;
cin >> b >> r >> t;
double k;
if (t == 1)
k = 1 + (double)r / 100 * y;
else
k = pow(1 + (double)r / 100, y);
if (k > mx) {
mx = k;
res = b;
}
}
cout << res << endl;
}
return 0;
}
|
[["-", 12, 16, 12, 16, 31, 16, 31, 74, 51, 22], ["+", 12, 16, 12, 16, 31, 16, 31, 74, 51, 22], ["-", 3, 4, 0, 16, 12, 16, 31, 74, 51, 22], ["+", 3, 4, 0, 16, 12, 16, 31, 74, 51, 22]]
| 1
| 142
| 4
|
#include <cmath>
#include <iostream>
using namespace std;
int main() {
int n, y, b, r, t;
int ans_num;
double ans_value;
double v;
while (1) {
ans_value = ans_num = -1;
cin >> n;
if (!n)
break;
cin >> y;
for (int i = 0; i < n; i++) {
cin >> b >> r >> t;
if (t == 1)
v = 1.0 * (1.0 + y * (r / 100.0));
else
v = 1.0 * pow(1.0 + r / 100.0, y);
if (v > ans_value) {
ans_value = v;
ans_num = i + 1;
}
}
cout << ans_num << endl;
}
}
|
#include <cmath>
#include <iostream>
using namespace std;
int main() {
int n, y, b, r, t;
int ans_num;
double ans_value;
double v;
while (1) {
ans_value = ans_num = -1;
cin >> n;
if (!n)
break;
cin >> y;
for (int i = 0; i < n; i++) {
cin >> b >> r >> t;
if (t == 1)
v = 1.0 * (1.0 + y * (r / 100.0));
else
v = 1.0 * pow(1.0 + r / 100.0, y);
if (v > ans_value) {
ans_value = v;
ans_num = b;
}
}
cout << ans_num << endl;
}
}
|
[["-", 64, 9, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 64, 9, 0, 1, 0, 11, 12, 16, 17, 72], ["-", 64, 9, 0, 1, 0, 11, 12, 16, 12, 13], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 22]]
| 1
| 147
| 4
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <strstream>
#include <vector>
using namespace std;
int main() {
int n;
while (cin >> n && n) {
multimap<double, int, greater<double>> rieki;
int y;
cin >> y;
for (int i = 0; i < n; i++) {
int b, r, t;
cin >> b >> r >> t;
double v;
if (t == 1) {
v = 1.0 * (1.0 + y * (r / 100.0));
rieki.insert(make_pair(v, i + 1));
}
else {
v = 1.0 * pow(1.0 + r / 100.0, y);
rieki.insert(make_pair(v, i + 1));
}
}
multimap<double, int, greater<double>>::iterator it = rieki.begin();
cout << (*it).second << endl;
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <strstream>
#include <vector>
using namespace std;
int main() {
int n;
while (cin >> n && n) {
multimap<double, int, greater<double>> rieki;
int y;
cin >> y;
for (int i = 0; i < n; i++) {
int b, r, t;
cin >> b >> r >> t;
double v;
if (t == 1) {
v = 1.0 * (1.0 + y * (r / 100.0));
rieki.insert(make_pair(v, b));
}
else {
v = 1.0 * pow(1.0 + r / 100.0, y);
rieki.insert(make_pair(v, b));
}
}
multimap<double, int, greater<double>>::iterator it = rieki.begin();
cout << (*it).second << endl;
}
return 0;
}
|
[["-", 3, 4, 0, 2, 3, 4, 0, 16, 31, 22], ["-", 3, 4, 0, 2, 3, 4, 0, 16, 17, 72], ["-", 3, 4, 0, 2, 3, 4, 0, 16, 12, 13], ["+", 0, 2, 3, 4, 0, 2, 3, 4, 0, 22]]
| 1
| 202
| 8
|
#include <iostream>
using namespace std;
int main() {
long n, d;
while (cin >> n, n) {
while (n >= 13) {
d = 0;
if (n % 2 == 1) {
for (int i = 3; i * i < n; i += 2) {
if (d == 1)
break;
if (i * i < n - 8) {
if ((n - 8) % i == 0)
d = 1;
}
if (i * i < n - 6) {
if ((n - 6) % i == 0)
d = 1;
}
if (i * i < n - 2) {
if ((n - 2) % i == 0)
d = 1;
}
if (n % i == 0)
d = 1;
}
n -= 2;
}
else {
n--;
continue;
}
if (!d) {
cout << n + 2 << endl;
break;
}
}
}
}
|
#include <iostream>
using namespace std;
int main() {
long n, d;
while (cin >> n, n) {
while (n >= 13) {
d = 0;
if (n % 2 == 1) {
for (int i = 3; i * i <= n; i += 2) {
if (d == 1)
break;
if (i * i <= n - 8) {
if ((n - 8) % i == 0)
d = 1;
}
if (i * i <= n - 6) {
if ((n - 6) % i == 0)
d = 1;
}
if (i * i <= n - 2) {
if ((n - 2) % i == 0)
d = 1;
}
if (n % i == 0)
d = 1;
}
n -= 2;
}
else {
n--;
continue;
}
if (!d) {
cout << n + 2 << endl;
break;
}
}
}
}
|
[["-", 0, 57, 64, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 57, 64, 9, 0, 7, 15, 16, 17, 19], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19]]
| 1
| 201
| 8
|
#include <iostream>
using namespace std;
bool p[10000000];
void erato() {
fill(p, p + 10000000, true);
p[0] = p[1] = false;
for (int i = 0; i < 10000000; i++) {
if (!p[i])
continue;
for (int j = i + i; j < 10000000; j += i) {
p[j] = false;
}
}
}
int main() {
erato();
int n;
while (cin >> n, n) {
for (int i = n;; i--) {
if (p[i] && p[i - 2] && p[i - 6] && p[i - 8]) {
cout << n << endl;
break;
}
}
}
}
|
#include <iostream>
using namespace std;
bool p[10000000];
void erato() {
fill(p, p + 10000000, true);
p[0] = p[1] = false;
for (int i = 0; i < 10000000; i++) {
if (!p[i])
continue;
for (int j = i + i; j < 10000000; j += i) {
p[j] = false;
}
}
}
int main() {
erato();
int n;
while (cin >> n, n) {
for (int i = n;; i--) {
if (p[i] && p[i - 2] && p[i - 6] && p[i - 8]) {
cout << i << endl;
break;
}
}
}
}
|
[["-", 64, 9, 0, 1, 0, 16, 31, 16, 12, 22], ["+", 64, 9, 0, 1, 0, 16, 31, 16, 12, 22]]
| 1
| 167
| 2
|
#include <iostream>
#include <map>
#include <queue>
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
class state {
public:
int tx;
int ty;
int kx;
int ky;
bool operator<(const state &s) const {
if (ty != s.ty)
return ty < s.ty;
if (tx != s.tx)
return tx < s.tx;
if (ky != s.ky)
return ky < s.ky;
if (kx != s.kx)
return kx < s.kx;
return false;
}
};
int main() {
while (true) {
int W, H;
cin >> W >> H;
if (W == 0 && H == 0)
break;
bool d[52][52];
for (int i = 0; i < H + 2; i++) {
for (int j = 0; j < W + 2; j++) {
d[i][j] = 1;
}
}
state num;
cin >> num.tx >> num.ty >> num.kx >> num.ky;
for (int i = 1; i < H + 1; i++) {
for (int j = 1; j < W + 1; j++) {
cin >> d[j][i];
}
}
queue<state> q;
q.push(num);
map<state, int> m;
m[num] = 0;
while (true) {
num = q.front();
q.pop();
if (m[num] >= 100) {
cout << "NA" << endl;
break;
}
if (num.tx == num.kx && num.ty == num.ky) {
cout << m[num] << endl;
break;
}
for (int i = 0; i < 4; i++) {
state copy = num;
if (d[copy.ty + dy[i]][copy.tx + dx[i]] == 0) {
copy.ty += dy[i];
copy.tx += dx[i];
}
if (d[copy.ky - dy[i]][copy.kx - dx[i]] == 0) {
copy.ky -= dy[i];
copy.kx -= dx[i];
}
if (m.find(copy) == m.end()) {
q.push(copy);
m[copy] = m[num] + 1;
}
}
if (q.empty()) {
cout << "NA" << endl;
break;
}
}
m.clear();
while (!q.empty()) {
q.pop();
}
}
return 0;
}
|
#include <iostream>
#include <map>
#include <queue>
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
class state {
public:
int tx;
int ty;
int kx;
int ky;
bool operator<(const state &s) const {
if (ty != s.ty)
return ty < s.ty;
if (tx != s.tx)
return tx < s.tx;
if (ky != s.ky)
return ky < s.ky;
if (kx != s.kx)
return kx < s.kx;
return false;
}
};
int main() {
while (true) {
int W, H;
cin >> W >> H;
if (W == 0 && H == 0)
break;
int d[52][52];
for (int i = 0; i < H + 2; i++) {
for (int j = 0; j < W + 2; j++) {
d[i][j] = 1;
}
}
state num;
cin >> num.tx >> num.ty >> num.kx >> num.ky;
for (int i = 1; i < H + 1; i++) {
for (int j = 1; j < W + 1; j++) {
cin >> d[i][j];
}
}
queue<state> q;
q.push(num);
map<state, int> m;
m[num] = 0;
while (true) {
num = q.front();
q.pop();
if (m[num] >= 100) {
cout << "NA" << endl;
break;
}
if (num.tx == num.kx && num.ty == num.ky) {
cout << m[num] << endl;
break;
}
for (int i = 0; i < 4; i++) {
state copy = num;
if (d[copy.ty + dy[i]][copy.tx + dx[i]] == 0) {
copy.ty += dy[i];
copy.tx += dx[i];
}
if (d[copy.ky - dy[i]][copy.kx - dx[i]] == 0) {
copy.ky -= dy[i];
copy.kx -= dx[i];
}
if (m.find(copy) == m.end()) {
q.push(copy);
m[copy] = m[num] + 1;
}
}
if (q.empty()) {
cout << "NA" << endl;
break;
}
}
m.clear();
while (!q.empty()) {
q.pop();
}
}
return 0;
}
|
[["-", 8, 9, 0, 52, 8, 9, 0, 43, 39, 40], ["+", 8, 9, 0, 52, 8, 9, 0, 43, 39, 40], ["-", 0, 16, 12, 69, 28, 69, 341, 342, 0, 22], ["+", 0, 16, 12, 69, 28, 69, 341, 342, 0, 22], ["-", 0, 1, 0, 16, 12, 69, 341, 342, 0, 22], ["+", 0, 1, 0, 16, 12, 69, 341, 342, 0, 22]]
| 1
| 588
| 6
|
#include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
struct State {
pair<int, int> t, k;
int turn;
};
int dy[] = {0, 1, 0, -1};
int dx[] = {1, 0, -1, 0};
int w, h;
int field[52][52];
bool visited[52][52][52][52];
int main() {
while (cin >> w >> h, w | h) {
memset(visited, false, sizeof(visited));
queue<State> q;
State a, b;
a.turn = 0;
cin >> a.t.second >> a.t.first;
cin >> a.k.second >> a.k.first;
for (int i = 0; i < 52; i++) {
for (int j = 0; j < 52; j++)
field[i][j] = 1;
}
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++)
cin >> field[i][j];
}
int ans = -1;
q.push(a);
visited[a.t.first][a.t.second][a.k.first][a.k.second] = true;
while (!q.empty()) {
a = q.front();
q.pop();
if (a.t.first == a.k.first && a.t.second == a.k.second) {
ans = a.turn;
break;
}
if (100 <= a.turn + abs(a.t.first - a.k.first) / 2 +
abs(a.t.second - a.k.second) / 2) {
break;
}
for (int i = 0; i < 4; i++) {
b = a;
b.t.first += dy[i];
b.t.second += dx[i];
b.k.first -= dy[i];
b.k.second -= dx[i];
if (field[b.t.first][b.t.second])
b.t = a.t;
if (field[b.k.first][b.k.second])
b.k = a.k;
b.turn = a.turn + 1;
if (!visited[b.t.first][b.t.second][b.k.first][b.k.second]) {
visited[b.t.first][b.t.second][b.k.first][b.k.second] = true;
q.push(b);
}
}
}
while (!q.empty())
q.pop();
if (ans == -1)
cout << "NA" << endl;
else
cout << ans << endl;
}
return 0;
}
|
#include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
struct State {
pair<int, int> t, k;
int turn;
};
int dy[] = {0, 1, 0, -1};
int dx[] = {1, 0, -1, 0};
int w, h;
int field[52][52];
bool visited[52][52][52][52];
int main() {
while (cin >> w >> h, w | h) {
memset(visited, false, sizeof(visited));
queue<State> q;
State a, b;
a.turn = 0;
cin >> a.t.second >> a.t.first;
cin >> a.k.second >> a.k.first;
for (int i = 0; i < 52; i++) {
for (int j = 0; j < 52; j++)
field[i][j] = 1;
}
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++)
cin >> field[i][j];
}
int ans = -1;
q.push(a);
visited[a.t.first][a.t.second][a.k.first][a.k.second] = true;
while (!q.empty()) {
a = q.front();
q.pop();
if (a.t.first == a.k.first && a.t.second == a.k.second) {
ans = a.turn;
break;
}
if (100 <= a.turn + abs(a.t.first - a.k.first) / 2 +
abs(a.t.second - a.k.second) / 2) {
break;
}
for (int i = 0; i < 4; i++) {
b = a;
b.t.first += dy[i];
b.t.second += dx[i];
b.k.first -= dy[i];
b.k.second -= dx[i];
if (field[b.t.first][b.t.second])
b.t = a.t;
if (field[b.k.first][b.k.second])
b.k = a.k;
b.turn = a.turn + 1;
if (!visited[b.t.first][b.t.second][b.k.first][b.k.second]) {
visited[b.t.first][b.t.second][b.k.first][b.k.second] = true;
q.push(b);
}
}
}
while (!q.empty())
q.pop();
if (ans == -1)
cout << "NA" << endl;
else
cout << ans << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19]]
| 1
| 636
| 8
|
#include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1 << 30
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct Data {
int tx, ty, kx, ky, cost;
Data(int tx, int ty, int kx, int ky, int cost)
: tx(tx), ty(ty), kx(kx), ky(ky), cost(cost) {}
};
int main() {
int x, y;
while (cin >> x >> y) {
if (x == 0 && y == 0)
break;
int tx, ty, kx, ky;
cin >> tx >> ty >> kx >> ky;
tx--;
ty--;
kx--;
ky--;
int field[55][55];
memset(field, 0, sizeof(field));
rep(i, y) rep(j, x) cin >> field[i][j];
bool used[52][52][52][52];
rep(i, 52) rep(j, 52) rep(k, 52) rep(l, 52) used[i][j][k][l] = false;
used[tx][ty][kx][ky] = true;
queue<Data> que;
que.push(Data(tx, ty, kx, ky, 0));
bool flag = false;
int ans;
while (que.size()) {
Data data = que.front();
que.pop();
if (data.cost >= 100)
break;
if (data.tx == data.kx && data.ty == data.ky) {
flag = true;
ans = data.cost;
break;
}
rep(i, 4) {
int ntx = data.tx + dx[i];
int nty = data.ty + dy[i];
int nkx = data.kx + dx[(i + 2) % 4];
int nky = data.ky + dy[(i + 2) % 4];
Data nd(data.tx, data.ty, data.kx, data.ky, data.cost + 1);
if (0 <= ntx && ntx < x && 0 <= nty && nty < y &&
field[ntx][nty] == 0) {
nd.tx = ntx;
nd.ty = nty;
}
if (0 <= nkx && nkx < x && 0 <= nky && nky < y &&
field[nkx][nty] == 0) {
nd.kx = nkx;
nd.ky = nky;
}
if (!used[nd.tx][nd.ty][nd.kx][nd.ky]) {
used[nd.tx][nd.ty][nd.kx][nd.ky] = true;
que.push(nd);
}
}
}
if (flag)
cout << ans << endl;
else
cout << "NA" << endl;
}
}
|
#include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1 << 30
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct Data {
int tx, ty, kx, ky, cost;
Data(int tx, int ty, int kx, int ky, int cost)
: tx(tx), ty(ty), kx(kx), ky(ky), cost(cost) {}
};
int main() {
int x, y;
while (cin >> x >> y) {
if (x == 0 && y == 0)
break;
int tx, ty, kx, ky;
cin >> tx >> ty >> kx >> ky;
tx--;
ty--;
kx--;
ky--;
int field[55][55];
memset(field, 0, sizeof(field));
rep(i, y) rep(j, x) cin >> field[i][j];
bool used[52][52][52][52];
rep(i, 52) rep(j, 52) rep(k, 52) rep(l, 52) used[i][j][k][l] = false;
used[tx][ty][kx][ky] = true;
queue<Data> que;
que.push(Data(tx, ty, kx, ky, 0));
bool flag = false;
int ans;
while (que.size()) {
Data data = que.front();
que.pop();
if (data.cost >= 100)
break;
if (data.tx == data.kx && data.ty == data.ky) {
flag = true;
ans = data.cost;
break;
}
rep(i, 4) {
int ntx = data.tx + dx[i];
int nty = data.ty + dy[i];
int nkx = data.kx + dx[(i + 2) % 4];
int nky = data.ky + dy[(i + 2) % 4];
Data nd(data.tx, data.ty, data.kx, data.ky, data.cost + 1);
if (0 <= ntx && ntx < x && 0 <= nty && nty < y &&
field[nty][ntx] == 0) {
nd.tx = ntx;
nd.ty = nty;
}
if (0 <= nkx && nkx < x && 0 <= nky && nky < y &&
field[nky][nkx] == 0) {
nd.kx = nkx;
nd.ky = nky;
}
if (!used[nd.tx][nd.ty][nd.kx][nd.ky]) {
used[nd.tx][nd.ty][nd.kx][nd.ky] = true;
que.push(nd);
}
}
}
if (flag)
cout << ans << endl;
else
cout << "NA" << endl;
}
}
|
[["-", 12, 16, 31, 69, 28, 69, 341, 342, 0, 22], ["+", 12, 16, 31, 69, 28, 69, 341, 342, 0, 22], ["-", 51, 16, 12, 16, 31, 69, 341, 342, 0, 22], ["+", 51, 16, 12, 16, 31, 69, 341, 342, 0, 22]]
| 1
| 667
| 8
|
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#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;
#define rep(i, n) for (int i = 0; i < n; i++)
#define mp make_pair
int dx[] = {0, -1, 0, 1};
int dy[] = {-1, 0, 1, 0};
bool v[50][50][50][50];
int f[50][50];
int x, y;
int tx, ty, kx, ky;
main() {
while (cin >> x >> y, x) {
cin >> tx >> ty >> kx >> ky;
--tx;
--ty;
--kx;
--ky;
rep(i, x) rep(j, y) cin >> f[i][j];
memset(v, 0, sizeof(v));
v[tx][ty][kx][ky] = 1;
queue<pair<pair<pi, pi>, int>> Q;
Q.push(mp(mp(mp(tx, ty), mp(kx, ky)), 0));
while (!Q.empty()) {
tx = Q.front().first.first.first;
ty = Q.front().first.first.second;
kx = Q.front().first.second.first;
ky = Q.front().first.second.second;
int time = Q.front().second;
Q.pop();
rep(d, 4) {
int ntx = tx + dx[d], nty = ty + dy[d];
int nkx = kx - dx[d], nky = ky - dy[d];
if (ntx < 0 || ntx >= x || nty < 0 || nty >= y || f[ntx][nty])
ntx = tx, nty = ty;
if (nkx < 0 || nkx >= x || nky < 0 || nky >= y || f[nkx][nky])
nkx = kx, nky = ky;
if (v[ntx][nty][nkx][nky] || time >= 99)
continue;
if (ntx == nkx && nty == nky) {
cout << time + 1 << endl;
goto END;
}
Q.push(mp(mp(mp(ntx, nty), mp(nkx, nky)), time + 1));
v[ntx][nty][nkx][nky] = 1;
}
}
puts("NA");
END:;
}
}
|
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#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;
#define rep(i, n) for (int i = 0; i < n; i++)
#define mp make_pair
int dx[] = {0, -1, 0, 1};
int dy[] = {-1, 0, 1, 0};
bool v[50][50][50][50];
int f[50][50];
int x, y;
int tx, ty, kx, ky;
main() {
while (cin >> x >> y, x) {
cin >> tx >> ty >> kx >> ky;
--tx;
--ty;
--kx;
--ky;
rep(i, y) rep(j, x) cin >> f[j][i];
memset(v, 0, sizeof(v));
v[tx][ty][kx][ky] = 1;
queue<pair<pair<pi, pi>, int>> Q;
Q.push(mp(mp(mp(tx, ty), mp(kx, ky)), 0));
while (!Q.empty()) {
tx = Q.front().first.first.first;
ty = Q.front().first.first.second;
kx = Q.front().first.second.first;
ky = Q.front().first.second.second;
int time = Q.front().second;
Q.pop();
rep(d, 4) {
int ntx = tx + dx[d], nty = ty + dy[d];
int nkx = kx - dx[d], nky = ky - dy[d];
if (ntx < 0 || ntx >= x || nty < 0 || nty >= y || f[ntx][nty])
ntx = tx, nty = ty;
if (nkx < 0 || nkx >= x || nky < 0 || nky >= y || f[nkx][nky])
nkx = kx, nky = ky;
if (v[ntx][nty][nkx][nky] || time >= 99)
continue;
if (ntx == nkx && nty == nky) {
cout << time + 1 << endl;
goto END;
}
Q.push(mp(mp(mp(ntx, nty), mp(nkx, nky)), time + 1));
v[ntx][nty][nkx][nky] = 1;
}
}
puts("NA");
END:;
}
}
|
[["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22], ["-", 0, 16, 12, 69, 28, 69, 341, 342, 0, 22], ["+", 0, 16, 12, 69, 28, 69, 341, 342, 0, 22], ["-", 0, 1, 0, 16, 12, 69, 341, 342, 0, 22], ["+", 0, 1, 0, 16, 12, 69, 341, 342, 0, 22]]
| 1
| 575
| 8
|
#include <iostream>
#include <queue>
struct D {
int t, u, k, l, c;
};
main() {
for (int X, Y, t, u, k, l, d[50][50], a[4] = {1, 0, -1, 0};
std::cin >> X >> Y >> t >> u >> k >> l, X;
~k ? printf("%d\n", k) : puts("NA")) {
std::queue<D> q;
D p = {t - 1, u - 1, k - 1, l - 1, 0}, r;
q.push(p);
for (u = 0; u < Y; u++)
for (t = 0; t < X; t++)
std::cin >> d[t][u];
int v[50][50][50][50] = {0};
for (k = -1; q.size();) {
p = q.front();
q.pop();
if (p.t == p.k && p.u == p.l) {
k = p.c;
break;
}
v[p.t][p.u][p.k][p.l] = 1;
for (t = 4; t-- > 0;) {
r = p;
r.t += a[t];
r.u += a[(t + 3) % 4];
r.k += a[(t + 2) % 4];
r.l += a[(t + 1) % 4];
r.c++;
if (r.t < 0 | X <= r.t | r.u < 0 | Y <= r.u | d[r.t][r.u]) {
r.t = p.t;
r.u = p.u;
}
if (r.k < 0 | X <= r.k | r.l < 0 | Y <= r.l | d[r.k][r.l]) {
r.k = p.k;
r.l = p.l;
}
if (!v[r.t][r.u][r.k][r.l])
q.push(r);
v[r.t][r.u][r.k][r.l] = 1;
}
}
}
}
|
#include <iostream>
#include <queue>
struct D {
int t, u, k, l, c;
};
main() {
for (int X, Y, t, u, k, l, d[50][50], a[4] = {1, 0, -1, 0};
std::cin >> X >> Y >> t >> u >> k >> l, X;
~k ? printf("%d\n", k) : puts("NA")) {
std::queue<D> q;
D p = {t - 1, u - 1, k - 1, l - 1, 0}, r;
q.push(p);
for (u = 0; u < Y; u++)
for (t = 0; t < X; t++)
std::cin >> d[t][u];
bool v[50][50][50][50] = {0};
for (k = -1; q.size();) {
p = q.front();
q.pop();
if (p.t == p.k && p.u == p.l) {
k = p.c;
break;
}
v[p.t][p.u][p.k][p.l] = 1;
for (t = 4; t-- > 0;) {
r = p;
r.t += a[t];
r.u += a[(t + 3) % 4];
r.k += a[(t + 2) % 4];
r.l += a[(t + 1) % 4];
r.c++;
if (r.t < 0 | X <= r.t | r.u < 0 | Y <= r.u | d[r.t][r.u]) {
r.t = p.t;
r.u = p.u;
}
if (r.k < 0 | X <= r.k | r.l < 0 | Y <= r.l | d[r.k][r.l]) {
r.k = p.k;
r.l = p.l;
}
if (!v[r.t][r.u][r.k][r.l])
q.push(r);
v[r.t][r.u][r.k][r.l] = 1;
}
}
}
}
|
[["-", 8, 9, 0, 7, 8, 9, 0, 43, 39, 40], ["+", 8, 9, 0, 7, 8, 9, 0, 43, 39, 40]]
| 1
| 526
| 2
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#define limX(a) (min(max(1, a), X))
#define limY(a) (min(max(1, a), Y))
using namespace std;
typedef struct d {
int tx, ty, kx, ky, time;
} D;
int G[55][55], X, Y, R, tx, ty, kx, ky,
mx[4] = {0, -1, 0, 1}, my[4] = {-1, 0, 1, 0}, F[51][51][51][51];
struct Order {
bool operator()(D const &a, D const &b) const { return a.time > b.time; }
};
int main() {
D tmp, tmp2;
for (; scanf("%d%d", &X, &Y), X;) {
memset(F, 0, sizeof(F));
priority_queue<D, vector<D>, Order> Q;
R = -1;
tmp.time = 0;
scanf("%d%d%d%d", &tmp.tx, &tmp.ty, &tmp.kx, &tmp.ky);
for (int i = 1; i <= Y; i++)
for (int j = 1; j <= X; j++)
scanf("%d", &G[i][j]);
Q.push(tmp);
for (; !Q.empty();) {
tmp = tmp2 = Q.top();
Q.pop();
if (tmp.time >= 100)
break;
if (tmp.kx == tmp.tx && tmp.ky == tmp.ty) {
R = tmp.time;
break;
}
for (int i = 0; i < 4; tmp = tmp2, i++) {
tmp.kx = limX(tmp.kx + mx[i]);
tmp.ky = limY(tmp.ky + my[i]);
if (G[tmp.ky][tmp.ky])
tmp.kx = tmp2.kx, tmp.ky = tmp2.ky;
tmp.tx = limX(tmp.tx - mx[i]);
tmp.ty = limY(tmp.ty - my[i]);
if (G[tmp.ty][tmp.ty])
tmp.tx = tmp2.tx, tmp.ty = tmp2.ty;
tmp.time++;
if (!F[tmp.kx][tmp.ky][tmp.tx][tmp.ty]) {
F[tmp.kx][tmp.ky][tmp.tx][tmp.ty] = 1;
Q.push(tmp);
}
}
}
if (R == -1)
puts("NA");
else
printf("%d\n", R);
}
}
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#define limX(a) (min(max(1, a), X))
#define limY(a) (min(max(1, a), Y))
using namespace std;
typedef struct d {
int tx, ty, kx, ky, time;
} D;
int G[55][55], X, Y, R, tx, ty, kx, ky,
mx[4] = {0, -1, 0, 1}, my[4] = {-1, 0, 1, 0}, F[51][51][51][51];
struct Order {
bool operator()(D const &a, D const &b) const { return a.time > b.time; }
};
int main() {
D tmp, tmp2;
for (; scanf("%d%d", &X, &Y), X;) {
memset(F, 0, sizeof(F));
priority_queue<D, vector<D>, Order> Q;
R = -1;
tmp.time = 0;
scanf("%d%d%d%d", &tmp.tx, &tmp.ty, &tmp.kx, &tmp.ky);
for (int i = 1; i <= Y; i++)
for (int j = 1; j <= X; j++)
scanf("%d", &G[i][j]);
Q.push(tmp);
for (; !Q.empty();) {
tmp = tmp2 = Q.top();
Q.pop();
if (tmp.time >= 100)
break;
if (tmp.kx == tmp.tx && tmp.ky == tmp.ty) {
R = tmp.time;
break;
}
for (int i = 0; i < 4; tmp = tmp2, i++) {
tmp.kx = limX(tmp.kx + mx[i]);
tmp.ky = limY(tmp.ky + my[i]);
if (G[tmp.ky][tmp.kx])
tmp.kx = tmp2.kx, tmp.ky = tmp2.ky;
tmp.tx = limX(tmp.tx - mx[i]);
tmp.ty = limY(tmp.ty - my[i]);
if (G[tmp.ty][tmp.tx])
tmp.tx = tmp2.tx, tmp.ty = tmp2.ty;
tmp.time++;
if (!F[tmp.kx][tmp.ky][tmp.tx][tmp.ty]) {
F[tmp.kx][tmp.ky][tmp.tx][tmp.ty] = 1;
Q.push(tmp);
}
}
}
if (R == -1)
puts("NA");
else
printf("%d\n", R);
}
}
|
[["-", 15, 339, 51, 69, 341, 342, 0, 118, 119, 120], ["+", 15, 339, 51, 69, 341, 342, 0, 118, 119, 120]]
| 1
| 585
| 4
|
import java.util.Scanner;
// Quaternion Multiplication
public class Main {
void run() {
Scanner sc = new Scanner(System.in);
for (;;) {
int n = sc.nextInt();
if (n == 0)
break;
for (int i = 0; i < n; i++) {
int x1 = sc.nextInt(), y1 = sc.nextInt(), z1 = sc.nextInt(),
w1 = sc.nextInt();
int x2 = sc.nextInt(), y2 = sc.nextInt(), z2 = sc.nextInt(),
w2 = sc.nextInt();
int x = x1 * x2 - y1 * y2 - z1 * z2 - w1 * w2;
int y = x1 * y2 + y1 * x2 + z1 * w2 - w1 * z2;
int z = z1 * z2 - y1 * w2 + z1 * y2 + w1 * y2;
int w = x1 * w2 + y1 * z2 - z1 * y2 + w1 * x2;
System.out.println(x + " " + y + " " + z + " " + w);
}
}
}
public static void main(String[] args) { new Main().run(); }
}
|
import java.util.Scanner;
// Quaternion Multiplication
public class Main {
void run() {
Scanner sc = new Scanner(System.in);
for (;;) {
int n = sc.nextInt();
if (n == 0)
break;
for (int i = 0; i < n; i++) {
int x1 = sc.nextInt(), y1 = sc.nextInt(), z1 = sc.nextInt(),
w1 = sc.nextInt();
int x2 = sc.nextInt(), y2 = sc.nextInt(), z2 = sc.nextInt(),
w2 = sc.nextInt();
int x = x1 * x2 - y1 * y2 - z1 * z2 - w1 * w2;
int y = x1 * y2 + y1 * x2 + z1 * w2 - w1 * z2;
int z = x1 * z2 - y1 * w2 + z1 * x2 + w1 * y2;
int w = x1 * w2 + y1 * z2 - z1 * y2 + w1 * x2;
System.out.println(x + " " + y + " " + z + " " + w);
}
}
}
public static void main(String[] args) { new Main().run(); }
}
|
[["-", 51, 16, 31, 16, 31, 16, 31, 16, 31, 22], ["+", 51, 16, 31, 16, 31, 16, 31, 16, 31, 22], ["-", 49, 200, 51, 16, 31, 16, 12, 16, 12, 22], ["+", 49, 200, 51, 16, 31, 16, 12, 16, 12, 22]]
| 3
| 260
| 4
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
while (true) {
int n = sc.nextInt();
if (n == 0)
break;
while (n != 0) {
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int d = sc.nextInt();
int e = sc.nextInt();
int f = sc.nextInt();
int g = sc.nextInt();
int h = sc.nextInt();
int x = a * e - b * f - c * h - d * h;
int y = a * f + b * e * c * h - d * g;
int z = a * g - b * h + e * c + d * f;
int w = a * h + b * g - c * f + d * e;
System.out.println(x + " " + y + " " + z + " " + w);
n--;
}
}
}
}
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
while (true) {
int n = sc.nextInt();
if (n == 0)
break;
while (n != 0) {
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int d = sc.nextInt();
int e = sc.nextInt();
int f = sc.nextInt();
int g = sc.nextInt();
int h = sc.nextInt();
int x = a * e - b * f - c * g - d * h;
int y = a * f + b * e + c * h - d * g;
int z = a * g - b * h + e * c + d * f;
int w = a * h + b * g - c * f + d * e;
System.out.println(x + " " + y + " " + z + " " + w);
n--;
}
}
}
}
|
[["-", 49, 200, 51, 16, 31, 16, 12, 16, 12, 22], ["+", 49, 200, 51, 16, 31, 16, 12, 16, 12, 22], ["-", 51, 16, 31, 16, 12, 16, 31, 16, 17, 48], ["+", 0, 503, 49, 200, 51, 16, 31, 16, 17, 72]]
| 3
| 246
| 4
|
#include <iostream>
using namespace std;
int main() {
int n, a, b, c, d, e, f, g, h, x, y, z, w;
while (cin >> n, n)
while (n--)
cin >> a >> b >> c >> d >> e >> f >> g >> h;
cout << a * e - b * f - c * g - d * h << " " << a * f + b * e + c * h - d * g
<< " " << a * g - b * h + c * e + d * f << " "
<< a * h + b * g - c * f + d * e << endl;
}
|
#include <iostream>
using namespace std;
int main() {
int n, a, b, c, d, e, f, g, h, x, y, z, w;
while (cin >> n, n)
while (n--) {
cin >> a >> b >> c >> d >> e >> f >> g >> h;
cout << a * e - b * f - c * g - d * h << " "
<< a * f + b * e + c * h - d * g << " "
<< a * g - b * h + c * e + d * f << " "
<< a * h + b * g - c * f + d * e << endl;
}
}
|
[["+", 8, 9, 0, 52, 8, 52, 8, 9, 0, 45], ["+", 8, 9, 0, 52, 8, 52, 8, 9, 0, 46]]
| 1
| 150
| 2
|
#include <iostream>
using namespace std;
#define N 4
#define X 0
#define Y 1
#define Z 2
#define W 3
int main() {
while (true) {
int n;
cin >> n;
if (!n) {
break;
}
for (int i = 0; i < n; i++) {
int val1[N], val2[N];
for (int j = 0; j < N; j++) {
cin >> val1[j];
}
for (int j = 0; j < N; j++) {
cin >> val2[j];
}
int ans[N];
ans[X] = val1[X] * val2[X] - val1[Y] * val2[Y] - val1[Z] * val2[Z] -
val1[W] * val2[W];
ans[Y] = val1[X] * val2[Y] + val1[Y] * val2[X] + val1[Z] * val2[W] -
val1[W] * val2[Z];
ans[Z] = val1[X] * val2[Z] - val1[Y] * val2[W] + val1[Z] * val2[X] +
val1[W] * val2[Y];
ans[W] = val1[X] * val2[W] + val1[Y] * val2[Z] - val1[Z] * val2[Y] +
val1[W] * val2[X];
cout << ans[X] << ' ' << ans[Y] << ' ' << ans[Z] << ' ' << ans[W];
}
}
return 0;
}
|
#include <iostream>
using namespace std;
#define N 4
#define X 0
#define Y 1
#define Z 2
#define W 3
int main() {
while (true) {
int n;
cin >> n;
if (!n) {
break;
}
for (int i = 0; i < n; i++) {
int val1[N], val2[N];
for (int j = 0; j < N; j++) {
cin >> val1[j];
}
for (int j = 0; j < N; j++) {
cin >> val2[j];
}
int ans[N];
ans[X] = val1[X] * val2[X] - val1[Y] * val2[Y] - val1[Z] * val2[Z] -
val1[W] * val2[W];
ans[Y] = val1[X] * val2[Y] + val1[Y] * val2[X] + val1[Z] * val2[W] -
val1[W] * val2[Z];
ans[Z] = val1[X] * val2[Z] - val1[Y] * val2[W] + val1[Z] * val2[X] +
val1[W] * val2[Y];
ans[W] = val1[X] * val2[W] + val1[Y] * val2[Z] - val1[Z] * val2[Y] +
val1[W] * val2[X];
cout << ans[X] << ' ' << ans[Y] << ' ' << ans[Z] << ' ' << ans[W] << '\n';
}
}
return 0;
}
|
[["+", 0, 7, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 8, 9, 0, 1, 0, 16, 12, 103, 0, 104], ["+", 8, 9, 0, 1, 0, 16, 12, 103, 0, 44]]
| 1
| 345
| 10
|
#include <cstdio>
using namespace std;
int main() {
int n, fi, se, th, fo, x1, x2, y1, y2, z1, z2, w1, w2;
while (true) {
scanf("%d", &n);
if (n == 0)
break;
for (int i = 0; i < n; i++) {
scanf("%d%d%d%d%d%d%d%d", &x1, &y1, &z1, &w1, &x2, &y2, &z2, &w2);
fi = x1 * x2 + (-1) * (y1 * y2) + (-1) * (z1 * z2) + (-1) * (w1 * w2);
se = x1 * y2 + y1 * x2 + z1 * w2 + (-1) * w1 * z2;
th = x1 * z2 + (-1) * (y1 * w2) + z1 * x2 + w1 * y2;
fo = x1 * w2 + y1 * z2 + (-1) * (z1 * y2) + w1 * x2;
printf("%d %d %d %d", fi, se, th, fo);
}
}
return 0;
}
|
#include <cstdio>
using namespace std;
int main() {
int n, fi, se, th, fo, x1, x2, y1, y2, z1, z2, w1, w2;
while (true) {
scanf("%d", &n);
if (n == 0)
break;
for (int i = 0; i < n; i++) {
scanf("%d%d%d%d%d%d%d%d", &x1, &y1, &z1, &w1, &x2, &y2, &z2, &w2);
fi = x1 * x2 + (-1) * (y1 * y2) + (-1) * (z1 * z2) + (-1) * (w1 * w2);
se = x1 * y2 + y1 * x2 + z1 * w2 + (-1) * w1 * z2;
th = x1 * z2 + (-1) * (y1 * w2) + z1 * x2 + w1 * y2;
fo = x1 * w2 + y1 * z2 + (-1) * (z1 * y2) + w1 * x2;
printf("%d %d %d %d\n", fi, se, th, fo);
}
}
return 0;
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 1
| 234
| 1
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double EPS = 1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main() {
int n;
while (cin >> n, n) {
rep(i, n) {
int a, b, c, d, e, f, g, h;
cin >> a >> b >> c >> d >> e >> f >> g >> h;
int x = a * e - b * f - c * g - d * h;
int y = a * f + b * e + c * h - d * f;
int z = a * g - b * h + c * e + d * g;
int q = a * h + b * g - c * f + d * e;
cout << x << " " << y << " " << z << " " << q << endl;
}
}
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double EPS = 1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main() {
int n;
while (cin >> n, n) {
rep(i, n) {
int a, b, c, d, e, f, g, h;
cin >> a >> b >> c >> d >> e >> f >> g >> h;
int x = a * e - b * f - c * g - d * h;
int y = a * f + b * e + c * h - d * g;
int z = a * g - b * h + c * e + d * f;
int q = a * h + b * g - c * f + d * e;
cout << x << " " << y << " " << z << " " << q << endl;
}
}
}
|
[["-", 0, 43, 49, 50, 51, 16, 12, 16, 12, 22], ["+", 0, 43, 49, 50, 51, 16, 12, 16, 12, 22]]
| 1
| 245
| 4
|
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
//#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
signed main() {
int n;
while (cin >> n) {
if (n == 0)
break;
rep(i, 0, n) {
int x1, y1, z1, w1, x2, y2, z2, w2;
cin >> x1 >> y1 >> z1 >> w1 >> x2 >> y2 >> z2 >> w2;
int x, y, z, w;
x = x1 * x2 - y1 * y2 - z1 * z2 - w1 * w2;
y = x1 * y2 + y1 * z2 + z1 * w2 - w1 * z2;
z = x1 * z2 - y1 * w2 + z1 * x2 + w1 * y2;
w = x1 * w2 + y1 * z2 - z1 * y2 + w1 * x2;
cout << x << " " << y << " " << z << " " << w << endl;
}
}
}
|
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
signed main() {
int n;
while (cin >> n) {
if (n == 0)
break;
rep(i, 0, n) {
int x1, y1, z1, w1, x2, y2, z2, w2;
cin >> x1 >> y1 >> z1 >> w1 >> x2 >> y2 >> z2 >> w2;
int x, y, z, w;
x = x1 * x2 - y1 * y2 - z1 * z2 - w1 * w2;
y = x1 * y2 + y1 * x2 + z1 * w2 - w1 * z2;
z = x1 * z2 - y1 * w2 + z1 * x2 + w1 * y2;
w = x1 * w2 + y1 * z2 - z1 * y2 + w1 * x2;
cout << x << " " << y << " " << z << " " << w << endl;
}
}
}
|
[["+", 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, 58, 0, 148], ["-", 12, 16, 31, 16, 31, 16, 12, 16, 12, 22], ["+", 12, 16, 31, 16, 31, 16, 12, 16, 12, 22]]
| 1
| 244
| 5
|
#ifdef __GNU_C__
#include <bits/stdc++.h>
#else
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <memory.h>
#include <sstream>
#include <string>
#include <vector>
#endif // __GNU_C__
using namespace std;
#define REP(i, max) for (int i = 0, iMax = max; i < iMax; i++)
#define RREP(i, min, max) for (int i = min, iMax = max; i < iMax; i++)
#define EREP(i, min, max) for (int i = min, iMax = max; i <= iMax; i++)
#define REV(i, max) for (int i = max - 1; i >= 0; i--)
#define RREV(i, min, max) for (int i = max, iMin = min; i > iMin; i--)
#define EREV(i, min, max) for (int i = max - 1, iMin = min; i >= iMin; i--)
typedef unsigned long long u64;
struct Quaternion {
int q[4];
void Print() { ::scanf("%d %d %d %d\n", q[0], q[1], q[2], q[3]); }
Quaternion operator*(Quaternion &o) {
/* static int eddingtonEpsilon[][][] =
{
{{0, 0, 0}, {0, 0, 1}, {-1, 0, 0} },
{{0, 0, -1}, {0, 0, 0}, {1, 0, 0} },
{{0, 1, 0}, {-1, 0, 0}, {0, 0, 0} },
};
*/
return Quaternion(
q[0] * o.q[0] - q[1] * o.q[1] - q[2] * o.q[2] - q[3] * o.q[3],
q[2] * o.q[3] - q[3] * o.q[2] + q[0] * o.q[1] + q[1] * o.q[0],
q[3] * o.q[1] - q[1] * o.q[3] + q[0] * o.q[2] + q[2] * o.q[0],
q[1] * o.q[2] - q[2] * o.q[1] + q[0] * o.q[3] + q[3] * o.q[0]);
}
Quaternion() {}
Quaternion(int ct, int x, int y, int z) {
q[0] = ct, q[1] = x, q[2] = y, q[3] = z;
}
};
int main(int args, char *psArgs[]) {
int numQuaternions;
vector<Quaternion> quaternions;
while (::scanf("%d", &numQuaternions), numQuaternions) {
while (numQuaternions--) {
Quaternion a, b;
::scanf("%d %d %d %d", &a.q[0], &a.q[1], &a.q[2], &a.q[3]);
::scanf("%d %d %d %d", &b.q[0], &b.q[1], &b.q[2], &b.q[3]);
(a * b).Print();
}
}
}
|
#ifdef __GNU_C__
#include <bits/stdc++.h>
#else
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <memory.h>
#include <sstream>
#include <string>
#include <vector>
#endif // __GNU_C__
using namespace std;
#define REP(i, max) for (int i = 0, iMax = max; i < iMax; i++)
#define RREP(i, min, max) for (int i = min, iMax = max; i < iMax; i++)
#define EREP(i, min, max) for (int i = min, iMax = max; i <= iMax; i++)
#define REV(i, max) for (int i = max - 1; i >= 0; i--)
#define RREV(i, min, max) for (int i = max, iMin = min; i > iMin; i--)
#define EREV(i, min, max) for (int i = max - 1, iMin = min; i >= iMin; i--)
typedef unsigned long long u64;
struct Quaternion {
int q[4];
void Print() { ::printf("%d %d %d %d\n", q[0], q[1], q[2], q[3]); }
Quaternion operator*(Quaternion &o) {
/* static int eddingtonEpsilon[][][] =
{
{{0, 0, 0}, {0, 0, 1}, {-1, 0, 0} },
{{0, 0, -1}, {0, 0, 0}, {1, 0, 0} },
{{0, 1, 0}, {-1, 0, 0}, {0, 0, 0} },
};
*/
return Quaternion(
q[0] * o.q[0] - q[1] * o.q[1] - q[2] * o.q[2] - q[3] * o.q[3],
q[2] * o.q[3] - q[3] * o.q[2] + q[0] * o.q[1] + q[1] * o.q[0],
q[3] * o.q[1] - q[1] * o.q[3] + q[0] * o.q[2] + q[2] * o.q[0],
q[1] * o.q[2] - q[2] * o.q[1] + q[0] * o.q[3] + q[3] * o.q[0]);
}
Quaternion() {}
Quaternion(int ct, int x, int y, int z) {
q[0] = ct, q[1] = x, q[2] = y, q[3] = z;
}
};
int main(int args, char *psArgs[]) {
int numQuaternions;
vector<Quaternion> quaternions;
while (::scanf("%d", &numQuaternions), numQuaternions) {
while (numQuaternions--) {
Quaternion a, b;
::scanf("%d %d %d %d", &a.q[0], &a.q[1], &a.q[2], &a.q[3]);
::scanf("%d %d %d %d", &b.q[0], &b.q[1], &b.q[2], &b.q[3]);
(a * b).Print();
}
}
}
|
[["-", 8, 9, 0, 1, 0, 2, 63, 343, 141, 22], ["+", 8, 9, 0, 1, 0, 2, 63, 343, 141, 22]]
| 1
| 533
| 2
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
while (cin >> n, n) {
for (int i = 0; i < n; i++) {
int x1, y1, z1, w1, x2, y2, z2, w2, x3, y3, z3, w3;
cin >> x1 >> y1 >> z1 >> w1 >> x2 >> y2 >> z2 >> w2;
x3 = x1 * x2 - y1 * y2 - z1 * z2 - w1 * w2;
y3 = x1 * y2 + y1 * x2 + z1 * w2 - w1 * z2;
z3 = x1 * z2 - y1 * w2 + z1 * x2 + w1 * y2;
w3 = x1 * w2 + y1 * z2 - z1 * y2 + w1 * x2;
cout << x3 << " " << y3 << " " << z3 << " " << w3;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
while (cin >> n, n) {
for (int i = 0; i < n; i++) {
int x1, y1, z1, w1, x2, y2, z2, w2, x3, y3, z3, w3;
cin >> x1 >> y1 >> z1 >> w1 >> x2 >> y2 >> z2 >> w2;
x3 = x1 * x2 - y1 * y2 - z1 * z2 - w1 * w2;
y3 = x1 * y2 + y1 * x2 + z1 * w2 - w1 * z2;
z3 = x1 * z2 - y1 * w2 + z1 * x2 + w1 * y2;
w3 = x1 * w2 + y1 * z2 - z1 * y2 + w1 * x2;
cout << x3 << " " << y3 << " " << z3 << " " << w3 << endl;
}
}
return 0;
}
|
[["+", 0, 7, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 7, 8, 9, 0, 1, 0, 16, 12, 22]]
| 1
| 181
| 2
|
#include <iostream>
#include <vector>
using namespace std;
struct four {
int a, b, c, d;
four(int _a, int _b, int _c, int _d) : a(_a), b(_b), c(_c), d(_d) {}
four() { a = b = c = d = 0; }
};
four operator+(const four &x, const four &y) {
return four(x.a + y.a, x.b + y.b, x.c + y.c, x.d + y.d);
}
four operator*(const four &x, const four &y) {
four ret;
ret.a = x.a * y.a - x.b * y.b - x.c * y.c - x.d * y.d;
ret.b = x.a * y.b + x.b * y.c + x.c * y.d - x.d * y.a;
ret.c = x.a * y.c - x.b * y.d + x.c * y.a + x.d * y.b;
ret.d = x.a * y.d + x.b * y.a - x.c * y.b + x.d * y.c;
return ret;
}
int main() {
int n;
while (cin >> n, n) {
for (int i = 0; i < n; ++i) {
four f[2];
for (int j = 0; j < 2; ++j) {
int a, b, c, d;
cin >> a >> b >> c >> d;
f[j] = four(a, b, c, d);
}
four ans = f[0] * f[1];
cout << ans.a << " " << ans.b << " " << ans.c << " " << ans.d << endl;
}
}
}
|
#include <iostream>
#include <vector>
using namespace std;
struct four {
int a, b, c, d;
four(int _a, int _b, int _c, int _d) : a(_a), b(_b), c(_c), d(_d) {}
four() { a = b = c = d = 0; }
};
four operator+(const four &x, const four &y) {
return four(x.a + y.a, x.b + y.b, x.c + y.c, x.d + y.d);
}
four operator*(const four &x, const four &y) {
four ret;
ret.a = x.a * y.a - x.b * y.b - x.c * y.c - x.d * y.d;
ret.b = x.a * y.b + x.b * y.a + x.c * y.d - x.d * y.c;
ret.c = x.a * y.c - x.b * y.d + x.c * y.a + x.d * y.b;
ret.d = x.a * y.d + x.b * y.c - x.c * y.b + x.d * y.a;
return ret;
}
int main() {
int n;
while (cin >> n, n) {
for (int i = 0; i < n; ++i) {
four f[2];
for (int j = 0; j < 2; ++j) {
int a, b, c, d;
cin >> a >> b >> c >> d;
f[j] = four(a, b, c, d);
}
four ans = f[0] * f[1];
cout << ans.a << " " << ans.b << " " << ans.c << " " << ans.d << endl;
}
}
}
|
[["-", 31, 16, 31, 16, 12, 16, 12, 118, 119, 120], ["+", 31, 16, 31, 16, 12, 16, 12, 118, 119, 120], ["-", 0, 11, 12, 16, 12, 16, 12, 118, 119, 120], ["+", 0, 11, 12, 16, 12, 16, 12, 118, 119, 120]]
| 1
| 428
| 8
|
#include <algorithm>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main() {
int n;
while (scanf("%d", &n), n) {
for (int i = 0; i < n; i++) {
int form1[4], form2[4]; /*0:x,1:y,2:z,w:3*/
for (int i = 0; i < 4; i++)
scanf("%d", &form1[i]);
for (int i = 0; i < 4; i++)
scanf("%d", &form2[i]);
int ans[4] = {0};
int mid[5][5] = {{0}};
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
mid[i][j] = abs(form1[i] * form2[j]);
}
}
ans[0] = mid[0][0] - mid[1][1] - mid[2][2] - mid[3][3];
ans[1] = mid[0][1] + mid[1][0] + mid[2][3] - mid[3][2];
ans[2] = mid[0][2] + mid[2][0] - mid[1][3] + mid[3][1];
ans[3] = mid[0][3] + mid[1][2] - mid[2][1] + mid[3][0];
for (int i = 0; i < 3; i++)
printf("%d ", ans[i]);
printf("%d\n", ans[3]);
}
}
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main() {
int n;
while (scanf("%d", &n), n) {
for (int i = 0; i < n; i++) {
int form1[4], form2[4]; /*0:x,1:y,2:z,w:3*/
for (int i = 0; i < 4; i++)
scanf("%d", &form1[i]);
for (int i = 0; i < 4; i++)
scanf("%d", &form2[i]);
int ans[4] = {0};
int mid[5][5] = {{0}};
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
mid[i][j] = form1[i] * form2[j];
}
}
ans[0] = mid[0][0] - mid[1][1] - mid[2][2] - mid[3][3];
ans[1] = mid[0][1] + mid[1][0] + mid[2][3] - mid[3][2];
ans[2] = mid[0][2] + mid[2][0] - mid[1][3] + mid[3][1];
ans[3] = mid[0][3] + mid[1][2] - mid[2][1] + mid[3][0];
for (int i = 0; i < 3; i++)
printf("%d ", ans[i]);
printf("%d\n", ans[3]);
}
}
return 0;
}
|
[["-", 8, 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]]
| 1
| 385
| 3
|
#include <iostream>
using namespace std;
int main() {
int n;
while (cin >> n, n) {
while (n--) {
int a[4], b[4], c[4];
for (int i = 0; i < 4; i++) {
cin >> a[i];
c[i] = 0;
}
for (int i = 0; i < 4; i++)
cin >> b[i];
c[0] = a[0] * b[0] - a[1] * b[1] - a[2] * b[2] - a[3] * b[3];
c[1] = a[0] * b[1] + a[1] * b[0] + a[2] * b[3] - a[3] * b[2];
c[2] = a[0] * b[2] - a[1] * b[3] + a[2] * b[0] + a[3] * b[1];
c[3] = a[0] * b[3] + a[1] * b[2] + a[2] * b[1] + a[3] * b[0];
for (int i = 0; i < 3; i++)
cout << c[i] << " ";
cout << c[3] << endl;
}
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int n;
while (cin >> n, n) {
while (n--) {
int a[4], b[4], c[4];
for (int i = 0; i < 4; i++) {
cin >> a[i];
c[i] = 0;
}
for (int i = 0; i < 4; i++)
cin >> b[i];
c[0] = a[0] * b[0] - a[1] * b[1] - a[2] * b[2] - a[3] * b[3];
c[1] = a[0] * b[1] + a[1] * b[0] + a[2] * b[3] - a[3] * b[2];
c[2] = a[0] * b[2] - a[1] * b[3] + a[2] * b[0] + a[3] * b[1];
c[3] = a[0] * b[3] + a[1] * b[2] - a[2] * b[1] + a[3] * b[0];
for (int i = 0; i < 3; i++)
cout << c[i] << " ";
cout << c[3] << endl;
}
}
return 0;
}
|
[["-", 0, 1, 0, 11, 12, 16, 31, 16, 17, 72], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 17, 33]]
| 1
| 316
| 2
|
#include <iostream>
using namespace std;
int main() {
int a[4], b[4];
int n;
while (1) {
cin >> n;
if (!n)
break;
while (!n) {
for (int i = 0; i < 4; i++)
cin >> a[i];
for (int i = 0; i < 4; i++)
cin >> b[i];
cout << a[0] * b[0] - a[1] * b[1] - a[2] * b[2] - a[3] * b[3] << " "
<< a[0] * b[1] + a[1] * b[0] + a[2] * b[3] - a[3] * b[2] << " "
<< a[0] * b[2] - a[1] * b[3] + a[2] * b[0] + a[3] * b[1] << " "
<< a[0] * b[3] + a[1] * b[2] - a[2] * b[1] + a[3] * b[0] << endl;
n--;
}
}
}
|
#include <iostream>
using namespace std;
int main() {
int a[4], b[4];
int n;
while (1) {
cin >> n;
if (!n)
break;
while (n) {
for (int i = 0; i < 4; i++)
cin >> a[i];
for (int i = 0; i < 4; i++)
cin >> b[i];
cout << a[0] * b[0] - a[1] * b[1] - a[2] * b[2] - a[3] * b[3] << " "
<< a[0] * b[1] + a[1] * b[0] + a[2] * b[3] - a[3] * b[2] << " "
<< a[0] * b[2] - a[1] * b[3] + a[2] * b[0] + a[3] * b[1] << " "
<< a[0] * b[3] + a[1] * b[2] - a[2] * b[1] + a[3] * b[0] << endl;
n--;
}
}
}
|
[["-", 8, 9, 0, 52, 15, 339, 51, 91, 17, 111]]
| 1
| 271
| 1
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, j) for (int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for (int i = (int)(j); i < (int)(k); ++i)
#define P pair<int, int>
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
const int N = 1000;
int X[2], Y[2], Z[2], W[2];
int x, y, z, w;
void calc() {
x = X[0] * X[1] + (Y[0] * Y[1] * -1) + (Z[0] * Z[1] * -1) +
(W[0] * W[1] * -1);
y = X[0] * Y[1] + Y[0] * X[1] + Z[0] * W[1] + (W[0] * Z[1] * -1);
z = X[0] * Z[1] + (Y[0] * W[1] * -1) + Z[0] * X[1] + W[0] * Y[1];
w = X[0] * W[1] + Y[0] * X[1] + (Z[0] * Y[1] * -1) + W[0] * Z[1];
}
int main() {
int T;
while (cin >> T && T != 0) {
REP(t, T) {
cin >> X[0] >> Y[0] >> Z[0] >> W[0];
cin >> X[1] >> Y[1] >> Z[1] >> W[1];
calc();
printf("%d %d %d %d\n", x, y, z, w);
}
}
return 0;
}
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, j) for (int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for (int i = (int)(j); i < (int)(k); ++i)
#define P pair<int, int>
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
const int N = 1000;
int X[2], Y[2], Z[2], W[2];
int x, y, z, w;
void calc() {
x = X[0] * X[1] + (Y[0] * Y[1] * -1) + (Z[0] * Z[1] * -1) +
(W[0] * W[1] * -1);
y = X[0] * Y[1] + Y[0] * X[1] + Z[0] * W[1] + (W[0] * Z[1] * -1);
z = X[0] * Z[1] + (Y[0] * W[1] * -1) + Z[0] * X[1] + W[0] * Y[1];
w = X[0] * W[1] + Y[0] * Z[1] + (Z[0] * Y[1] * -1) + W[0] * X[1];
}
int main() {
int T;
while (cin >> T && T != 0) {
REP(t, T) {
cin >> X[0] >> Y[0] >> Z[0] >> W[0];
cin >> X[1] >> Y[1] >> Z[1] >> W[1];
calc();
printf("%d %d %d %d\n", x, y, z, w);
}
}
return 0;
}
|
[["-", 31, 16, 31, 16, 12, 16, 12, 69, 28, 22], ["+", 31, 16, 31, 16, 12, 16, 12, 69, 28, 22], ["-", 0, 11, 12, 16, 12, 16, 12, 69, 28, 22], ["+", 0, 11, 12, 16, 12, 16, 12, 69, 28, 22]]
| 1
| 405
| 4
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char s[10000][1025], tmp[10000000], x[1025], *p, q;
int c[10000] = {0}, n, i, j, f, r;
int main() {
for (; scanf("%d\n", &n), n;) {
memset(c, 0, sizeof(c));
memset(s, 0, sizeof(tmp));
for (; n--; sprintf(tmp, "%s %s ", tmp, x))
gets(x);
q = getchar();
for (p = strtok(tmp, " "); p; p = strtok(NULL, " ")) {
sscanf(p, "%s", x);
if (x[0] == q) {
for (i = f = 0; s[i][0] && strcmp(s[i], x) <= 0; i++)
if (strcmp(s[i], x) == 0)
c[i]++, f = 1;
if (!f) {
memmove(s + i + 1, s + i, (10000 - i - 1) * sizeof(x));
strcpy(s[i], x);
memmove(c + i + 1, c + i, (10000 - i - 1) * sizeof(0));
c[i] = 1;
}
}
}
for (j = 5; j--;) {
for (i = 0, r = -1; s[i][0] && s[i][0] <= q; i++)
if (s[i][0] == q && (r == -1 || c[i] > c[r]))
r = i;
if (r == -1 || !c[r]) {
printf("%s", j == 4 ? "NA" : "");
break;
}
printf("%s%s", j == 4 ? "" : " ", s[r]);
c[r] = 0;
}
puts("");
}
return 0;
}
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char s[10000][1025], tmp[20000000], x[1025], *p, q;
int c[10000] = {0}, n, i, j, f, r;
int main() {
for (; scanf("%d\n", &n), n;) {
memset(c, 0, sizeof(c));
memset(tmp, 0, sizeof(tmp));
for (; n--; sprintf(tmp, "%s %s ", tmp, x))
gets(x);
q = getchar();
for (p = strtok(tmp, " "); p; p = strtok(NULL, " ")) {
sscanf(p, "%s", x);
if (x[0] == q) {
for (i = f = 0; s[i][0] && strcmp(s[i], x) <= 0; i++)
if (strcmp(s[i], x) == 0)
c[i]++, f = 1;
if (!f) {
memmove(s + i + 1, s + i, (10000 - i - 1) * sizeof(x));
strcpy(s[i], x);
memmove(c + i + 1, c + i, (10000 - i - 1) * sizeof(0));
c[i] = 1;
}
}
}
for (j = 5; j--;) {
for (i = 0, r = -1; s[i][0] && s[i][0] <= q; i++)
if (s[i][0] == q && (r == -1 || c[i] > c[r]))
r = i;
if (r == -1 || !c[r]) {
printf("%s", j == 4 ? "NA" : "");
break;
}
printf("%s%s", j == 4 ? "" : " ", s[r]);
c[r] = 0;
}
puts("");
}
return 0;
}
|
[["-", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22]]
| 0
| 458
| 4
|
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#define _A_ true
using namespace std;
typedef pair<int, string> P;
int main() {
int n;
// map<string,int> dic;
P dic[10000];
string s[10000];
int index = 0;
string si;
char han;
map<string, int> Map;
map<string, bool> used;
/*
P p[3];
p[0] = P(2,"ba");
p[1] = P(2,"a");
p[2] = P(1,"c");
sort(p,p+3);
for(int i=0;i<3;i++){
cout << p[i].first << " " << p[i].second << endl;
}
*/
while (_A_) {
cin >> n;
if (n == 0)
break;
index = 0;
int Nc = 0;
for (int i = 0; i < 10000; i++) {
dic[i].first = -1;
}
Map.clear();
int temp = 0, word_sum = 0;
char c;
for (int i = 0; i < 10000; i++)
s[i].clear();
while (temp < n) {
cin >> s[word_sum++];
scanf("%c", &c);
if (c == '\n')
temp++;
// cout << "c = " << c;
// cout << "temp =" << temp << endl;
}
cin >> han;
for (int i = 0; i < word_sum; i++) {
if (s[i][0] == han) {
Map[s[i]]++;
}
}
int index2 = 0;
for (int i = 0; i < word_sum; i++) {
if (s[i][0] == han && !used[s[i]]) {
dic[index2] = P(Map[s[i]], s[i]);
index2++;
Nc++;
used[s[i]] = true;
}
}
sort(dic, dic + index2, greater<P>());
int index3 = 0;
int flag = dic[0].first;
int ccounter = 0;
map<int, string> Nari;
int point = 0;
set<string> Answer;
int Count = 0;
// for(int i=0;i<index2;i++){
// cout << dic[i].first << " " << dic[i].second << endl;
//}
// cout << "------------" << endl;
if (index2 == 0) {
cout << "NA";
} else {
for (int i = 0; i <= index2; i++) {
if (flag != dic[i].first) {
// cout << "flag = " << flag << " " << point <<" "<< i << endl;
for (int j = point; j < i; j++) {
Answer.insert(dic[j].second);
}
if (point == i) {
Answer.insert(dic[point].second);
}
set<string>::iterator it = Answer.begin();
while (it != Answer.end()) {
cout << *it;
it++;
Count++;
if (Count < 5 && Nc != Count) {
cout << " ";
} else {
break;
}
}
Answer.clear();
point = i;
flag = dic[i].first;
}
}
}
cout << endl;
}
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#define _A_ true
using namespace std;
typedef pair<int, string> P;
int main() {
int n;
// map<string,int> dic;
P dic[10000];
string s[10000];
int index = 0;
string si;
char han;
map<string, int> Map;
map<string, bool> used;
/*
P p[3];
p[0] = P(2,"ba");
p[1] = P(2,"a");
p[2] = P(1,"c");
sort(p,p+3);
for(int i=0;i<3;i++){
cout << p[i].first << " " << p[i].second << endl;
}
*/
while (_A_) {
cin >> n;
if (n == 0)
break;
index = 0;
int Nc = 0;
for (int i = 0; i < 10000; i++) {
dic[i].first = -1;
}
Map.clear();
used.clear();
int temp = 0, word_sum = 0;
char c;
for (int i = 0; i < 10000; i++)
s[i].clear();
while (temp < n) {
cin >> s[word_sum++];
scanf("%c", &c);
if (c == '\n')
temp++;
// cout << "c = " << c;
// cout << "temp =" << temp << endl;
}
cin >> han;
for (int i = 0; i < word_sum; i++) {
if (s[i][0] == han) {
Map[s[i]]++;
}
}
int index2 = 0;
for (int i = 0; i < word_sum; i++) {
if (s[i][0] == han && !used[s[i]]) {
dic[index2] = P(Map[s[i]], s[i]);
index2++;
Nc++;
used[s[i]] = true;
}
}
sort(dic, dic + index2, greater<P>());
int index3 = 0;
int flag = dic[0].first;
int ccounter = 0;
map<int, string> Nari;
int point = 0;
set<string> Answer;
int Count = 0;
// for(int i=0;i<index2;i++){
// cout << dic[i].first << " " << dic[i].second << endl;
//}
// cout << "------------" << endl;
if (index2 == 0) {
cout << "NA";
} else {
for (int i = 0; i <= index2; i++) {
if (flag != dic[i].first) {
// cout << "flag = " << flag << " " << point <<" "<< i << endl;
for (int j = point; j < i; j++) {
Answer.insert(dic[j].second);
}
if (point == i) {
Answer.insert(dic[point].second);
}
set<string>::iterator it = Answer.begin();
while (it != Answer.end()) {
cout << *it;
it++;
Count++;
if (Count < 5 && Nc != Count) {
cout << " ";
} else {
break;
}
}
Answer.clear();
point = i;
flag = dic[i].first;
}
}
}
cout << endl;
}
return 0;
}
|
[["+", 8, 9, 0, 1, 0, 2, 63, 118, 28, 22], ["+", 8, 9, 0, 1, 0, 2, 63, 118, 17, 131], ["+", 8, 9, 0, 1, 0, 2, 63, 118, 119, 120], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 1
| 581
| 6
|
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#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>
using namespace std;
#if __GNUC__
#include <tr1/unordered_map>
#include <tr1/unordered_set>
using namespace tr1;
#else
#include <unordered_map>
#include <unordered_set>
#endif
#ifdef __GNUC__
template <class T> int popcount(T n);
template <> int popcount(unsigned int n) { return __builtin_popcount(n); }
template <> int popcount(int n) { return __builtin_popcount(n); }
template <> int popcount(unsigned long long n) {
return __builtin_popcountll(n);
}
template <> int popcount(long long n) { return __builtin_popcountll(n); }
#else
#define __typeof__ decltype
template <class T> int popcount(T n) {
return n ? 1 + popcount(n & (n - 1)) : 0;
}
#endif
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define foreach(it, c) \
for (__typeof__((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define rforeach(it, c) \
for (__typeof__((c).rbegin()) it = (c).rbegin(); it != (c).rend(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CL(arr, val) memset(arr, val, sizeof(arr))
#define COPY(dest, src) memcpy(dest, src, sizeof(src))
template <class T> void max_swap(T &a, const T &b) { a = max(a, b); }
template <class T> void min_swap(T &a, const T &b) { a = min(a, b); }
typedef long long ll;
typedef pair<int, int> pint;
template <class T, class U> ostream &operator<<(ostream &os, pair<T, U> &p) {
os << "( " << p.first << ", " << p.second << " )";
return os;
}
template <class T> string to_s(const T &a) {
ostringstream os;
os << a;
return os.str();
}
const int mod = 1000000007;
const double PI = acos(-1.0);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
bool valid_pos(int x, int y, int w, int h) {
return 0 <= x && x < w && 0 <= y && y < h;
}
template <class T>
void print(T a, int n, int br = 1, const string &deli = ", ") {
cout << "{ ";
for (int i = 0; i < n; ++i) {
cout << a[i];
if (i + 1 != n)
cout << deli;
}
cout << " }";
while (br--)
cout << endl;
}
template <class T>
void print(const vector<T> &v, int br = 1, const string &deli = ", ") {
print(v, v.size(), br, deli);
}
template <class T> void print2d(T a, int w, int h, int width = -1, int br = 1) {
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
if (width != -1)
cout.width(width);
cout << a[i][j] << ' ';
}
cout << endl;
}
while (br--)
cout << endl;
}
template <class T> void input(T &a, int n) {
for (int i = 0; i < n; ++i)
cin >> a[i];
}
template <class T, class U> void input(T &a, U &b, int n) {
for (int i = 0; i < n; ++i)
cin >> a[i] >> b[i];
}
vector<string> split(string str, const string &deli_chars) {
for (int i = 0; i < str.size(); ++i)
if (deli_chars.find(str[i]) != string::npos)
str[i] = ' ';
stringstream ss(str);
vector<string> res;
for (string s; ss >> s;)
res.push_back(s);
return res;
}
typedef pair<string, int> P;
bool cmp(const P &a, const P &b) {
if (a.second != b.second)
return a.second > b.second;
else
return a.first < b.first;
}
int main() {
ios::sync_with_stdio(false);
int n;
string line;
while (cin >> n, n) {
getline(cin, line);
map<string, int> c;
while (n--) {
getline(cin, line);
vector<string> spl = split(line, " ");
foreach (it, spl)
++c[*it];
}
getline(cin, line);
vector<P> v;
foreach (it, c)
if (it->first[0] == line[0])
v.push_back(*it);
if (v.empty())
cout << "NA" << endl;
else {
sort(all(v));
cout << v[0].first;
for (int i = 1; i < min<int>(5, v.size()); ++i)
cout << " " << v[i].first;
cout << endl;
}
}
}
|
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#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>
using namespace std;
#if __GNUC__
#include <tr1/unordered_map>
#include <tr1/unordered_set>
using namespace tr1;
#else
#include <unordered_map>
#include <unordered_set>
#endif
#ifdef __GNUC__
template <class T> int popcount(T n);
template <> int popcount(unsigned int n) { return __builtin_popcount(n); }
template <> int popcount(int n) { return __builtin_popcount(n); }
template <> int popcount(unsigned long long n) {
return __builtin_popcountll(n);
}
template <> int popcount(long long n) { return __builtin_popcountll(n); }
#else
#define __typeof__ decltype
template <class T> int popcount(T n) {
return n ? 1 + popcount(n & (n - 1)) : 0;
}
#endif
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define foreach(it, c) \
for (__typeof__((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define rforeach(it, c) \
for (__typeof__((c).rbegin()) it = (c).rbegin(); it != (c).rend(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CL(arr, val) memset(arr, val, sizeof(arr))
#define COPY(dest, src) memcpy(dest, src, sizeof(src))
template <class T> void max_swap(T &a, const T &b) { a = max(a, b); }
template <class T> void min_swap(T &a, const T &b) { a = min(a, b); }
typedef long long ll;
typedef pair<int, int> pint;
template <class T, class U> ostream &operator<<(ostream &os, pair<T, U> &p) {
os << "( " << p.first << ", " << p.second << " )";
return os;
}
template <class T> string to_s(const T &a) {
ostringstream os;
os << a;
return os.str();
}
const int mod = 1000000007;
const double PI = acos(-1.0);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
bool valid_pos(int x, int y, int w, int h) {
return 0 <= x && x < w && 0 <= y && y < h;
}
template <class T>
void print(T a, int n, int br = 1, const string &deli = ", ") {
cout << "{ ";
for (int i = 0; i < n; ++i) {
cout << a[i];
if (i + 1 != n)
cout << deli;
}
cout << " }";
while (br--)
cout << endl;
}
template <class T>
void print(const vector<T> &v, int br = 1, const string &deli = ", ") {
print(v, v.size(), br, deli);
}
template <class T> void print2d(T a, int w, int h, int width = -1, int br = 1) {
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
if (width != -1)
cout.width(width);
cout << a[i][j] << ' ';
}
cout << endl;
}
while (br--)
cout << endl;
}
template <class T> void input(T &a, int n) {
for (int i = 0; i < n; ++i)
cin >> a[i];
}
template <class T, class U> void input(T &a, U &b, int n) {
for (int i = 0; i < n; ++i)
cin >> a[i] >> b[i];
}
vector<string> split(string str, const string &deli_chars) {
for (int i = 0; i < str.size(); ++i)
if (deli_chars.find(str[i]) != string::npos)
str[i] = ' ';
stringstream ss(str);
vector<string> res;
for (string s; ss >> s;)
res.push_back(s);
return res;
}
typedef pair<string, int> P;
bool cmp(const P &a, const P &b) {
if (a.second != b.second)
return a.second > b.second;
else
return a.first < b.first;
}
int main() {
ios::sync_with_stdio(false);
int n;
string line;
while (cin >> n, n) {
getline(cin, line);
map<string, int> c;
while (n--) {
getline(cin, line);
vector<string> spl = split(line, " ");
foreach (it, spl)
++c[*it];
}
getline(cin, line);
vector<P> v;
foreach (it, c)
if (it->first[0] == line[0])
v.push_back(*it);
if (v.empty())
cout << "NA" << endl;
else {
sort(all(v), cmp);
cout << v[0].first;
for (int i = 1; i < min<int>(5, v.size()); ++i)
cout << " " << v[i].first;
cout << endl;
}
}
}
|
[["+", 0, 9, 0, 1, 0, 2, 3, 4, 0, 21], ["+", 0, 9, 0, 1, 0, 2, 3, 4, 0, 22]]
| 1
| 1,151
| 2
|
#include <algorithm>
#include <climits>
#include <cstring>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
bool larger(pair<int, string> d1, pair<int, string> d2) {
return (d1.first > d2.first);
}
int main() {
while (1) {
int n;
cin >> n;
if (n == 0)
break;
cin.ignore(INT_MAX, '\n');
vector<string> dic;
for (int i = 0; i < n; i++) {
char line[1024];
cin.getline(line, sizeof(line));
dic.push_back(string(strtok(line, " ")));
char *buf;
while (buf = strtok(NULL, " ")) {
dic.push_back(string(buf));
}
}
sort(dic.begin(), dic.end());
char ch;
cin >> ch;
int begin = 0;
while (begin < dic.size() && dic[begin][0] != ch)
begin++;
if (begin == dic.size())
cout << "NA" << endl;
int end = begin;
while (end < dic.size() && dic[end][0] == ch)
end++;
vector<pair<int, string>> res;
for (int i = begin; i < end; i++) {
int idx = 0;
bool hit = false;
for (; idx < res.size(); idx++) {
if (res[idx].second == dic[i]) {
hit = true;
break;
}
}
if (hit)
res[idx].first++;
else {
pair<int, string> data(0, dic[i]);
res.push_back(data);
}
}
sort(res.begin(), res.end(), larger);
int len = res.size();
if (len > 5)
len = 5;
for (int i = 0; i < len; i++) {
cout << res[i].second;
if (i < len - 1)
cout << ' ';
}
cout << endl;
}
return 0;
}
|
#include <algorithm>
#include <climits>
#include <cstring>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
bool larger(pair<int, string> d1, pair<int, string> d2) {
return (d1.first > d2.first);
}
int main() {
while (1) {
int n;
cin >> n;
if (n == 0)
break;
cin.ignore(INT_MAX, '\n');
vector<string> dic;
for (int i = 0; i < n; i++) {
char line[1024];
cin.getline(line, sizeof(line));
dic.push_back(string(strtok(line, " ")));
char *buf;
while (buf = strtok(NULL, " ")) {
dic.push_back(string(buf));
}
}
sort(dic.begin(), dic.end());
char ch;
cin >> ch;
int begin = 0;
while (begin < dic.size() && dic[begin][0] != ch)
begin++;
if (begin == dic.size())
cout << "NA";
int end = begin;
while (end < dic.size() && dic[end][0] == ch)
end++;
vector<pair<int, string>> res;
for (int i = begin; i < end; i++) {
int idx = 0;
bool hit = false;
for (; idx < res.size(); idx++) {
if (res[idx].second == dic[i]) {
hit = true;
break;
}
}
if (hit)
res[idx].first++;
else {
pair<int, string> data(0, dic[i]);
res.push_back(data);
}
}
sort(res.begin(), res.end(), larger);
int len = res.size();
if (len > 5)
len = 5;
for (int i = 0; i < len; i++) {
cout << res[i].second;
if (i < len - 1)
cout << ' ';
}
cout << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 57, 64, 1, 0, 16, 17, 151], ["-", 8, 9, 0, 57, 64, 1, 0, 16, 12, 22]]
| 1
| 465
| 2
|
#include <algorithm>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define each(i, c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define dbg(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
const int inf = (int)1e9;
const double EPS = 1e-9, INF = 1e12;
int main() {
int n;
while (cin >> n, n) {
cin.ignore();
string in;
map<string, int> cnt;
rep(i, n) {
getline(cin, in);
stringstream ss(in);
while (ss >> in)
cnt[in]++;
}
char c;
int mx = 0;
vector<pair<int, string>> ans;
cin >> c;
each(i, cnt) {
if (i->first[0] == c)
ans.pb(mp(-i->second, i->first));
}
sort(all(ans));
bool f = 1;
rep(i, min(5, (int)ans.size())) {
if (!f)
cout << " ";
f = 0;
cout << ans[i].second;
}
if (!ans.size())
cout << "NA" << endl;
cout << endl;
}
return 0;
}
|
#include <algorithm>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define each(i, c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define dbg(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
const int inf = (int)1e9;
const double EPS = 1e-9, INF = 1e12;
int main() {
int n;
while (cin >> n, n) {
cin.ignore();
string in;
map<string, int> cnt;
rep(i, n) {
getline(cin, in);
stringstream ss(in);
while (ss >> in)
cnt[in]++;
}
char c;
int mx = 0;
vector<pair<int, string>> ans;
cin >> c;
each(i, cnt) {
if (i->first[0] == c)
ans.pb(mp(-i->second, i->first));
}
sort(all(ans));
bool f = 1;
rep(i, min(5, (int)ans.size())) {
if (!f)
cout << " ";
f = 0;
cout << ans[i].second;
}
if (!ans.size())
cout << "NA";
cout << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 57, 64, 1, 0, 16, 17, 151], ["-", 8, 9, 0, 57, 64, 1, 0, 16, 12, 22]]
| 1
| 312
| 2
|
#include <algorithm>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
bool cmp(pair<string, int> x, pair<string, int> y) {
return x.second != y.second ? x.second > y.second : x.first < y.first;
}
int main() {
for (int N; cin >> N, N;) {
map<char, map<string, int>> dict;
cin.ignore();
for (int i = 0; i < N; i++) {
string s;
getline(cin, s);
istringstream iss(s);
for (string t; iss >> t; dict[t[0]][t]++)
;
}
char c;
cin >> c;
vector<pair<string, int>> res(dict[c].begin(), dict[c].end());
sort(res.begin(), res.end());
if (res.empty()) {
cout << "NA" << endl;
} else {
for (int i = 0, end = min<int>(res.size(), 5); i < end; i++) {
cout << res[i].first << " \n"[i == end - 1];
}
}
}
}
|
#include <algorithm>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
bool cmp(pair<string, int> x, pair<string, int> y) {
return x.second != y.second ? x.second > y.second : x.first < y.first;
}
int main() {
for (int N; cin >> N, N;) {
map<char, map<string, int>> dict;
cin.ignore();
for (int i = 0; i < N; i++) {
string s;
getline(cin, s);
istringstream iss(s);
for (string t; iss >> t; dict[t[0]][t]++)
;
}
char c;
cin >> c;
vector<pair<string, int>> res(dict[c].begin(), dict[c].end());
sort(res.begin(), res.end(), cmp);
if (res.empty()) {
cout << "NA" << endl;
} else {
for (int i = 0, end = min<int>(res.size(), 5); i < end; i++) {
cout << res[i].first << " \n"[i == end - 1];
}
}
}
}
|
[["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 21], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22]]
| 1
| 281
| 2
|
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
class Word {
public:
string name;
int cnt, pos;
Word(string name, int cnt, int pos) : name(name), cnt(cnt), pos(pos) {
cnt = 0;
pos = 0;
}
bool operator<(const Word &w) const {
if (cnt == w.cnt)
return pos > w.pos;
return cnt > w.cnt;
}
};
main() {
int n;
string line, word;
char ch;
while (1) {
cin >> n;
if (n == 0)
break;
getline(cin, line);
vector<string> tmp;
map<string, int> post, cntt;
set<string> buffer;
vector<Word> W;
for (int i = 0; i < n; i++) {
getline(cin, line);
stringstream sin(line);
while (sin >> word) {
tmp.push_back(word);
}
}
cin >> ch;
for (int i = 0; i < tmp.size(); i++) {
if (tmp[i][0] == ch) {
buffer.insert(tmp[i]);
post[tmp[i]] = i;
cntt[tmp[i]]++;
}
}
for (set<string>::iterator it = buffer.begin(); it != buffer.end(); it++) {
W.push_back(Word(*it, cntt[*it], post[*it]));
}
sort(W.begin(), W.end());
getline(cin, line);
if (W.size() == 0) {
cout << "NA" << endl;
} else {
for (int i = 0; i < min(5, (int)W.size()); i++) {
if (i)
cout << " ";
cout << W[i].name;
}
cout << endl;
}
}
}
|
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
class Word {
public:
string name;
int cnt, pos;
Word(string name, int cnt, int pos) : name(name), cnt(cnt), pos(pos) {
cnt = 0;
pos = 0;
}
bool operator<(const Word &w) const {
// if ( cnt == w.cnt ) return pos > w.pos;
// return cnt > w.cnt;
if (cnt == w.cnt)
return name < w.name;
return cnt > w.cnt;
}
};
main() {
int n;
string line, word;
char ch;
while (1) {
cin >> n;
if (n == 0)
break;
getline(cin, line);
vector<string> tmp;
map<string, int> post, cntt;
set<string> buffer;
vector<Word> W;
for (int i = 0; i < n; i++) {
getline(cin, line);
stringstream sin(line);
while (sin >> word) {
tmp.push_back(word);
}
}
cin >> ch;
for (int i = 0; i < tmp.size(); i++) {
if (tmp[i][0] == ch) {
buffer.insert(tmp[i]);
post[tmp[i]] = i;
cntt[tmp[i]]++;
}
}
for (set<string>::iterator it = buffer.begin(); it != buffer.end(); it++) {
W.push_back(Word(*it, cntt[*it], post[*it]));
}
sort(W.begin(), W.end());
getline(cin, line);
if (W.size() == 0) {
cout << "NA" << endl;
} else {
for (int i = 0; i < min(5, (int)W.size()); i++) {
if (i)
cout << " ";
cout << W[i].name;
}
cout << endl;
}
}
}
|
[["-", 8, 9, 0, 57, 64, 37, 0, 16, 31, 22], ["-", 8, 9, 0, 57, 64, 37, 0, 16, 17, 47], ["+", 8, 9, 0, 57, 64, 37, 0, 16, 31, 22], ["+", 8, 9, 0, 57, 64, 37, 0, 16, 17, 18], ["-", 0, 57, 64, 37, 0, 16, 12, 118, 119, 120], ["+", 0, 57, 64, 37, 0, 16, 12, 118, 119, 120]]
| 1
| 431
| 6
|
#include <iostream>
int main() {
int sum = 0, i;
for (int j = 0; j <= 10; j++) {
std::cin >> i;
sum = sum + i;
}
std::cout << sum << std::endl;
}
|
#include <iostream>
int main() {
int sum = 0, i;
for (int j = 0; j < 10; j++) {
std::cin >> i;
sum = sum + i;
}
std::cout << sum << std::endl;
}
|
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18]]
| 1
| 53
| 2
|
#include <iostream>
using namespace std;
int s, sum;
int main() {
for (int i = 0; i < 10; i++) {
cin >> s;
sum += s;
}
cout << s << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int s, sum;
int main() {
for (int i = 0; i < 10; i++) {
cin >> s;
sum += s;
}
cout << sum << endl;
return 0;
}
|
[["-", 8, 9, 0, 1, 0, 16, 31, 16, 12, 22], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 12, 22]]
| 1
| 50
| 2
|
#include <iostream>
using namespace std;
int main() {
int sum = 0;
for (int i = 0; i < 10; i++) {
int s;
cin >> s;
sum += s;
cout << sum << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int sum = 0;
for (int i = 0; i < 10; i++) {
int s;
cin >> s;
sum += s;
}
cout << sum << endl;
return 0;
}
|
[["+", 0, 14, 8, 9, 0, 7, 8, 9, 0, 46], ["-", 0, 14, 8, 9, 0, 7, 8, 9, 0, 46]]
| 1
| 53
| 2
|
#include <iostream>
using namespace std;
int main() {
int point = 0;
int x;
for (int i = 0; i < 10; i++) {
cin >> x;
point += x;
}
cout << x << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int point = 0;
int x;
for (int i = 0; i < 10; i++) {
cin >> x;
point += x;
}
cout << point << endl;
return 0;
}
|
[["-", 8, 9, 0, 1, 0, 16, 31, 16, 12, 22], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 12, 22]]
| 1
| 53
| 2
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s = 0, a;
for (int i = 0; i < 10; i++) {
cin >> s;
s += a;
}
cout << s << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s = 0, a;
for (int i = 0; i < 10; i++) {
cin >> a;
s += a;
}
cout << s << endl;
}
|
[["-", 0, 7, 8, 9, 0, 1, 0, 16, 12, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 16, 12, 22]]
| 1
| 49
| 2
|
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, string> P;
static const double EPS = 1e-8;
int main() {
int sum = 0;
for (int i = 0; i < 10; i++) {
int tmp;
printf("%d", &tmp);
sum += tmp;
}
printf("%d\n", sum);
}
|
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, string> P;
static const double EPS = 1e-8;
int main() {
int sum = 0;
for (int i = 0; i < 10; i++) {
int tmp;
scanf("%d", &tmp);
sum += tmp;
}
printf("%d\n", sum);
}
|
[["-", 0, 7, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 2, 63, 22]]
| 1
| 114
| 2
|
p $<.split.map(&:to_i).inject(:+)
|
p $<.map(&:to_i).inject(:+)
|
[["-", 3, 4, 0, 652, 486, 652, 486, 652, 735, 22], ["-", 0, 652, 3, 4, 0, 652, 486, 652, 17, 131]]
| 4
| 15
| 2
|
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
int main() {
vector<pair<int, int>> yabashi;
int n, m, a, b, weight;
bool bl;
while (1) {
bl = true;
weight = 0;
cin >> n;
if (n == 0)
break;
for (int i = 0; i < n; i++) {
cin >> m >> a >> b;
yabashi.push_back(make_pair(a, m));
yabashi.push_back(make_pair(b, (-m)));
}
stable_sort(yabashi.begin(), yabashi.end());
for (int i = 0; i < n * 2; i++) {
weight += yabashi[i].second;
if (weight > 150) {
bl = false;
break;
}
}
if (bl == true)
cout << "OK" << endl;
else
cout << "NG" << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
int main() {
vector<pair<int, int>> yabashi;
int n, m, a, b, weight;
bool bl;
while (1) {
bl = true;
weight = 0;
yabashi.clear();
cin >> n;
if (n == 0)
break;
for (int i = 0; i < n; i++) {
cin >> m >> a >> b;
yabashi.push_back(make_pair(a, m));
yabashi.push_back(make_pair(b, (-m)));
}
stable_sort(yabashi.begin(), yabashi.end());
for (int i = 0; i < n * 2; i++) {
weight += yabashi[i].second;
if (weight > 150) {
bl = false;
break;
}
}
if (bl == true)
cout << "OK" << endl;
else
cout << "NG" << endl;
}
return 0;
}
|
[["+", 8, 9, 0, 1, 0, 2, 63, 118, 28, 22], ["+", 8, 9, 0, 1, 0, 2, 63, 118, 17, 131], ["+", 8, 9, 0, 1, 0, 2, 63, 118, 119, 120], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 1
| 202
| 6
|
loop do
n = gets.to_i
break if n==0
hash = Hash.new(0)
max =0
n.times do
m,a,b = gets.split.map(&:to_i)
hash[a] += m
hash[b] += -m
max = [max,b].max
end
flag = true
sum=0
0.upto(max) do |t|
sum+=hash[t]
if sum>150
flag = false
break
end
end
puts flag ? "OK" : "NG"
end
|
loop do
n = gets.to_i
break if n==0
hash = Hash.new(0)
max =0
n.times do
m,a,b = gets.split.map(&:to_i)
hash[a] += m
hash[b] += -m
max = [max,b].max
end
flag = true
sum=0
hash.keys.sort.each do |t|
sum+=hash[t]
if sum>150
flag = false
break
end
end
puts flag ? "OK" : "NG"
end
|
[["-", 0, 652, 196, 737, 8, 736, 0, 652, 486, 612], ["+", 8, 736, 0, 652, 486, 652, 486, 652, 486, 22], ["-", 0, 652, 196, 737, 8, 736, 0, 652, 735, 22], ["-", 196, 737, 8, 736, 0, 652, 3, 4, 0, 24], ["-", 196, 737, 8, 736, 0, 652, 3, 4, 0, 22], ["-", 196, 737, 8, 736, 0, 652, 3, 4, 0, 25], ["+", 8, 736, 0, 652, 486, 652, 486, 652, 735, 22], ["+", 196, 737, 8, 736, 0, 652, 486, 652, 17, 131], ["+", 196, 737, 8, 736, 0, 652, 486, 652, 735, 22], ["+", 0, 652, 196, 737, 8, 736, 0, 652, 17, 131], ["+", 0, 652, 196, 737, 8, 736, 0, 652, 735, 22]]
| 4
| 108
| 11
|
while True:
n = eval(input())
if n == 0: break
datas = [list(map(int,input().split())) for i in range(n)]
maxw = 0
for d1 in datas:
w = sum([d2[0] for d2 in datas if d2[1]<=d1[1]<d2[2]])
maxw = max(w,mxw)
print("OK" if maxw <= 150 else "NG")
|
while True:
n = eval(input())
if n == 0: break
datas = [list(map(int,input().split())) for i in range(n)]
maxw = 0
for d1 in datas:
w = sum([d2[0] for d2 in datas if d2[1]<=d1[1]<d2[2]])
maxw = max(w,maxw)
print("OK" if maxw <= 150 else "NG")
|
[["-", 0, 1, 0, 662, 12, 652, 3, 4, 0, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 22]]
| 5
| 103
| 2
|
import java.util.Scanner;
class Main {
double[][] dp;
int[] v;
int[][] event;
int x, y, z;
public static void main(String args[]) {
Main app = new Main();
Scanner scan = new Scanner(System.in);
while (true) {
app.x = scan.nextInt();
app.y = scan.nextInt();
app.z = scan.nextInt();
if (app.x == 0 && app.y == 0 && app.z == 0) {
break;
}
app.v = new int[app.x];
for (int i = 0; i < app.x; i++) {
app.v[i] = scan.nextInt();
}
app.event = new int[app.y + 1][2];
for (int i = 0; i < app.z; i++) {
int tmp = scan.nextInt();
app.event[tmp][0] = scan.nextInt();
app.event[tmp][1] = scan.nextInt();
}
app.dp = new double[app.y + 1][5001];
System.out.println(app.LifeGame());
}
}
public int LifeGame() {
dp[0][0] = 1;
for (int i = 0; i < y + 1; i++) {
for (int j = 0; j < 5001; j++) {
if (dp[i][j] > 0) {
for (int k = 0; k < x; k++) {
if (i != y) {
int num = i + v[k];
if (num > y) {
num = y;
}
int money = j;
switch (event[num][0]) {
case 1:
num += event[num][1];
if (num > y) {
num = y;
}
break;
case 2:
money = j + event[num][1];
break;
case 3:
money = j - event[num][1];
if (money < 0) {
money = 0;
}
break;
}
dp[num][money] += dp[i][j] / x;
}
}
}
}
}
int exp = 0;
for (int i = 0; i < 5001; i++) {
exp += dp[y][i] * i;
}
return exp;
}
}
|
import java.util.Scanner;
class Main {
double[][] dp;
int[] v;
int[][] event;
int x, y, z;
public static void main(String args[]) {
Main app = new Main();
Scanner scan = new Scanner(System.in);
while (true) {
app.x = scan.nextInt();
app.y = scan.nextInt();
app.z = scan.nextInt();
if (app.x == 0 && app.y == 0 && app.z == 0) {
break;
}
app.v = new int[app.x];
for (int i = 0; i < app.x; i++) {
app.v[i] = scan.nextInt();
}
app.event = new int[app.y + 1][2];
for (int i = 0; i < app.z; i++) {
int tmp = scan.nextInt();
app.event[tmp][0] = scan.nextInt();
app.event[tmp][1] = scan.nextInt();
}
app.dp = new double[app.y + 1][5001];
System.out.println(app.LifeGame());
}
}
public int LifeGame() {
dp[0][0] = 1;
for (int i = 0; i < y + 1; i++) {
for (int j = 0; j < 5001; j++) {
if (dp[i][j] > 0) {
for (int k = 0; k < x; k++) {
if (i != y) {
int num = i + v[k];
if (num > y) {
num = y;
}
int money = j;
switch (event[num][0]) {
case 1:
num += event[num][1];
if (num > y) {
num = y;
}
break;
case 2:
money = j + event[num][1];
break;
case 3:
money = j - event[num][1];
if (money < 0) {
money = 0;
}
break;
}
dp[num][money] += dp[i][j] / x;
}
}
}
}
}
double exp = 0;
for (int i = 0; i < 5001; i++) {
exp += dp[y][i] * i;
}
return (int)exp;
}
}
|
[["-", 0, 195, 8, 196, 0, 503, 39, 506, 0, 507], ["+", 0, 195, 8, 196, 0, 503, 39, 511, 0, 512], ["+", 0, 195, 8, 196, 0, 37, 0, 74, 0, 24], ["+", 8, 196, 0, 37, 0, 74, 39, 506, 0, 507], ["+", 0, 195, 8, 196, 0, 37, 0, 74, 0, 25]]
| 3
| 532
| 5
|
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
new Main().run();
}
private void run() throws IOException {
Scanner scanner = new Scanner(System.in);
while (true) {
int x = scanner.nextInt();
int n = scanner.nextInt();
int e = scanner.nextInt();
if ((x | n | e) == 0)
break;
int[] v = new int[x];
for (int i = 0; i < x; i++) {
v[i] = scanner.nextInt();
}
int[][] ev = new int[n + 1][2];
while (e-- > 0) {
int p = scanner.nextInt();
int k = scanner.nextInt();
int val = scanner.nextInt();
ev[p][0] = k;
ev[p][1] = val;
}
Map<Integer, List<Double>> map = new HashMap<Integer, List<Double>>();
List<Double> list = new ArrayList<Double>();
for (int i = 0; i <= n; i++) {
list.add(0d);
}
list.set(0, 1.0);
map.put(0, list);
for (int i = 0; i < n; i++) {
Map<Integer, List<Double>> tmpMap =
new HashMap<Integer, List<Double>>();
tmpMap.putAll(map);
for (Entry<Integer, List<Double>> entry : map.entrySet()) {
int j = entry.getKey();
if (entry.getValue().get(i) == 0)
continue;
for (int k = 0; k < x; k++) {
int np = Math.min(n, i + v[k]);
int nm = j;
if (ev[np][0] == 1)
np = Math.min(n, np + ev[np][1]);
else if (ev[np][0] == 2)
nm += ev[np][1];
else if (ev[np][0] == 3)
nm = Math.max(0, nm - ev[np][1]);
List<Double> tmp;
if (!map.containsKey(nm)) {
tmp = new ArrayList<Double>();
for (int l = 0; l <= n; l++) {
tmp.add(0d);
}
} else {
tmp = tmpMap.get(nm);
}
double t = tmp.get(np);
tmp.set(np, t + entry.getValue().get(i) / x);
tmpMap.put(nm, tmp);
}
}
map = tmpMap;
}
double ans = 0;
for (Entry<Integer, List<Double>> enty : map.entrySet()) {
ans += enty.getKey() * enty.getValue().get(n);
}
System.out.println((int)ans);
}
}
}
|
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
new Main().run();
}
private void run() throws IOException {
Scanner scanner = new Scanner(System.in);
while (true) {
int x = scanner.nextInt();
int n = scanner.nextInt();
int e = scanner.nextInt();
if ((x | n | e) == 0)
break;
int[] v = new int[x];
for (int i = 0; i < x; i++) {
v[i] = scanner.nextInt();
}
int[][] ev = new int[n + 1][2];
while (e-- > 0) {
int p = scanner.nextInt();
int k = scanner.nextInt();
int val = scanner.nextInt();
ev[p][0] = k;
ev[p][1] = val;
}
Map<Integer, List<Double>> map = new HashMap<Integer, List<Double>>();
List<Double> list = new ArrayList<Double>();
for (int i = 0; i <= n; i++) {
list.add(0d);
}
list.set(0, 1.0);
map.put(0, list);
for (int i = 0; i < n; i++) {
Map<Integer, List<Double>> tmpMap =
new HashMap<Integer, List<Double>>();
tmpMap.putAll(map);
for (Entry<Integer, List<Double>> entry : map.entrySet()) {
int j = entry.getKey();
if (entry.getValue().get(i) == 0)
continue;
for (int k = 0; k < x; k++) {
int np = Math.min(n, i + v[k]);
int nm = j;
if (ev[np][0] == 1)
np = Math.min(n, np + ev[np][1]);
else if (ev[np][0] == 2)
nm += ev[np][1];
else if (ev[np][0] == 3)
nm = Math.max(0, nm - ev[np][1]);
List<Double> tmp;
if (!tmpMap.containsKey(nm)) {
tmp = new ArrayList<Double>();
for (int l = 0; l <= n; l++) {
tmp.add(0d);
}
} else {
tmp = tmpMap.get(nm);
}
double t = tmp.get(np);
tmp.set(np, t + entry.getValue().get(i) / x);
tmpMap.put(nm, tmp);
}
}
map = tmpMap;
}
double ans = 0;
for (Entry<Integer, List<Double>> enty : map.entrySet()) {
ans += enty.getKey() * enty.getValue().get(n);
}
System.out.println((int)ans);
}
}
}
|
[["-", 0, 57, 15, 15, 0, 91, 439, 492, 500, 22], ["+", 0, 57, 15, 15, 0, 91, 439, 492, 500, 22]]
| 3
| 720
| 2
|
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
public class Main {
public static void main(String[] args) { new Main().run(); }
private void run() {
Scanner scanner = new Scanner(System.in);
while (true) {
int x = scanner.nextInt();
int y = scanner.nextInt();
int z = scanner.nextInt();
if ((x | y | z) == 0)
break;
int[] v = new int[x];
for (int i = 0; i < x; i++) {
v[i] = scanner.nextInt();
}
int[][] ev = new int[y + 1][2];
for (int i = 0; i < z; i++) {
int b = scanner.nextInt();
ev[b][0] = scanner.nextInt();
ev[b][1] = scanner.nextInt();
}
Map<Integer, double[]> memo = new HashMap<Integer, double[]>();
double[] a = new double[y + 1];
a[0] = 1.0;
memo.put(0, a);
for (int i = 0; i < y; i++) {
Map<Integer, double[]> tmpMap = new HashMap<Integer, double[]>();
tmpMap.putAll(memo);
for (Iterator<Entry<Integer, double[]>> iterator =
memo.entrySet().iterator();
iterator.hasNext();) {
Entry<Integer, double[]> entry = iterator.next();
if (entry.getValue()[i] == 0)
continue;
for (int j = 0; j < x; j++) {
int key = entry.getKey();
double[] val = entry.getValue();
int nm = Math.min(y, i + v[j]);
if (ev[nm][0] == 1)
nm = Math.min(y, nm + ev[nm][1]);
else if (ev[nm][0] == 2)
key += ev[nm][1];
else if (ev[nm][0] == 3)
key = Math.max(0, key - ev[nm][1]);
if (!tmpMap.containsKey(key)) {
double[] d = new double[y + 1];
d[nm] = val[i] / x;
tmpMap.put(key, d);
} else {
double[] d = memo.get(key);
d[nm] += val[i] / x;
}
}
}
memo = tmpMap;
}
double ans = 0;
for (Entry<Integer, double[]> entry : memo.entrySet()) {
ans += entry.getKey() * entry.getValue()[y];
}
System.out.println((int)ans);
}
}
}
|
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
public class Main {
public static void main(String[] args) { new Main().run(); }
private void run() {
Scanner scanner = new Scanner(System.in);
while (true) {
int x = scanner.nextInt();
int y = scanner.nextInt();
int z = scanner.nextInt();
if ((x | y | z) == 0)
break;
int[] v = new int[x];
for (int i = 0; i < x; i++) {
v[i] = scanner.nextInt();
}
int[][] ev = new int[y + 1][2];
for (int i = 0; i < z; i++) {
int b = scanner.nextInt();
ev[b][0] = scanner.nextInt();
ev[b][1] = scanner.nextInt();
}
Map<Integer, double[]> memo = new HashMap<Integer, double[]>();
double[] a = new double[y + 1];
a[0] = 1.0;
memo.put(0, a);
for (int i = 0; i < y; i++) {
Map<Integer, double[]> tmpMap = new HashMap<Integer, double[]>();
tmpMap.putAll(memo);
for (Iterator<Entry<Integer, double[]>> iterator =
memo.entrySet().iterator();
iterator.hasNext();) {
Entry<Integer, double[]> entry = iterator.next();
if (entry.getValue()[i] == 0)
continue;
for (int j = 0; j < x; j++) {
int key = entry.getKey();
double[] val = entry.getValue();
int nm = Math.min(y, i + v[j]);
if (ev[nm][0] == 1)
nm = Math.min(y, nm + ev[nm][1]);
else if (ev[nm][0] == 2)
key += ev[nm][1];
else if (ev[nm][0] == 3)
key = Math.max(0, key - ev[nm][1]);
if (!tmpMap.containsKey(key)) {
double[] d = new double[y + 1];
d[nm] = val[i] / x;
tmpMap.put(key, d);
} else {
double[] d = tmpMap.get(key);
d[nm] += val[i] / x;
}
}
}
memo = tmpMap;
}
double ans = 0;
for (Entry<Integer, double[]> entry : memo.entrySet()) {
ans += entry.getKey() * entry.getValue()[y];
}
System.out.println((int)ans);
}
}
}
|
[["-", 75, 196, 0, 503, 49, 200, 51, 492, 500, 22], ["+", 75, 196, 0, 503, 49, 200, 51, 492, 500, 22]]
| 3
| 668
| 2
|
#include <bits/stdc++.h>
using namespace std;
int X, Y, Z;
vector<int> V;
vector<int> pl, gt;
vector<vector<double>> dp;
double calc(int v, int m) {
if (v == Y)
return (double)m;
if (dp[v][m] > -1.)
return dp[v][m];
double sum = 0;
for (int i = 0; i < V.size(); i++) {
int tv = min(Y, v + V[i]);
int tm = max(0, m + gt[v]);
tv = min(Y, tv + pl[tv]);
sum += calc(tv, tm);
}
return dp[v][m] = sum / V.size();
}
int main() {
while (scanf("%d %d %d", &X, &Y, &Z), X) {
V.resize(X);
pl = vector<int>(Y + 1, 0);
gt = vector<int>(Y + 1, 0);
dp = vector<vector<double>>(Y + 1, vector<double>(6000, -1.));
for (int i = 0; i < X; i++) {
scanf("%d", &V[i]);
}
for (int i = 0; i < Z; i++) {
int N, E, A;
scanf("%d %d %d", &N, &E, &A);
if (E == 1)
pl[N] = A;
if (E == 2)
gt[N] = A;
if (E == 3)
gt[N] = -A;
}
printf("%d\n", (int)calc(0, 0));
}
}
|
#include <bits/stdc++.h>
using namespace std;
int X, Y, Z;
vector<int> V;
vector<int> pl, gt;
vector<vector<double>> dp;
double calc(int v, int m) {
if (v == Y)
return (double)m;
if (dp[v][m] > -1.)
return dp[v][m];
double sum = 0;
for (int i = 0; i < V.size(); i++) {
int tv = min(Y, v + V[i]);
int tm = max(0, m + gt[tv]);
tv = min(Y, tv + pl[tv]);
sum += calc(tv, tm);
}
return dp[v][m] = sum / V.size();
}
int main() {
while (scanf("%d %d %d", &X, &Y, &Z), X) {
V.resize(X);
pl = vector<int>(Y + 1, 0);
gt = vector<int>(Y + 1, 0);
dp = vector<vector<double>>(Y + 1, vector<double>(6000, -1.));
for (int i = 0; i < X; i++) {
scanf("%d", &V[i]);
}
for (int i = 0; i < Z; i++) {
int N, E, A;
scanf("%d %d %d", &N, &E, &A);
if (E == 1)
pl[N] = A;
if (E == 2)
gt[N] = A;
if (E == 3)
gt[N] = -A;
}
printf("%d\n", (int)calc(0, 0));
}
}
|
[["-", 3, 4, 0, 16, 12, 69, 341, 342, 0, 22], ["+", 3, 4, 0, 16, 12, 69, 341, 342, 0, 22]]
| 1
| 389
| 2
|
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <stdio.h>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;
enum Event {
None,
Move_On,
Get,
Lose,
};
struct Info {
void init() {
value = 0;
event = None;
}
Event event;
int value;
};
int main() {
int X, Y, Z, V[4], N, E, A, next_masu;
Event event[4] = {None, Move_On, Get, Lose};
double dp[51][5001];
double ans;
Info info[51];
while (true) {
scanf("%d %d %d", &X, &Y, &Z);
if (X == 0 && Y == 0 && Z == 0)
break;
for (int i = 0; i <= Y; i++)
info[i].init();
for (int i = 0; i < X; i++) {
scanf("%d", &V[i]);
}
for (int i = 0; i < Z; i++) {
scanf("%d %d %d", &N, &E, &A);
info[N].event = event[E];
info[N].value = A;
}
for (int i = 0; i <= Y; i++) {
for (int k = 0; k <= 5000; k++)
dp[i][k] = 0.0;
}
dp[0][0] = 1.0;
for (int masu = 0; masu <= Y - 1; masu++) {
for (int score = 0; score <= 5000; score++) {
if (dp[masu][score] == 0.0)
continue;
for (int dice = 0; dice < X; dice++) {
if (masu + V[dice] > Y) {
next_masu = Y;
} else {
next_masu = masu + V[dice];
}
if (info[next_masu].event == None) {
dp[next_masu][score] += dp[masu][score] / (double)(X);
} else if (info[next_masu].event == Move_On) {
if (next_masu + info[next_masu].value > Y) {
next_masu = Y;
} else {
next_masu = next_masu + info[next_masu].value;
}
dp[next_masu][score] += dp[masu][score] / (double)(X);
} else if (info[next_masu].event == Get) {
dp[next_masu][score + info[next_masu].value] +=
dp[masu][score] / (double)(X);
} else { // info[next_masu].event == Lose
if (score < info[next_masu].value) {
dp[next_masu][0] += dp[masu][score] * (double)(X);
} else {
dp[next_masu][score - info[next_masu].value] +=
dp[masu][score] / (double)(X);
}
}
}
}
}
ans = 0;
for (int i = 0; i <= 5000; i++) {
ans += (double)i * dp[Y][i];
}
printf("%.0f\n", floor(ans));
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <stdio.h>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;
enum Event {
None,
Move_On,
Get,
Lose,
};
struct Info {
void init() {
value = 0;
event = None;
}
Event event;
int value;
};
int main() {
int X, Y, Z, V[4], N, E, A, next_masu;
Event event[4] = {None, Move_On, Get, Lose};
double dp[51][5001];
double ans;
Info info[51];
while (true) {
scanf("%d %d %d", &X, &Y, &Z);
if (X == 0 && Y == 0 && Z == 0)
break;
for (int i = 0; i <= Y; i++)
info[i].init();
for (int i = 0; i < X; i++) {
scanf("%d", &V[i]);
}
for (int i = 0; i < Z; i++) {
scanf("%d %d %d", &N, &E, &A);
info[N].event = event[E];
info[N].value = A;
}
for (int i = 0; i <= Y; i++) {
for (int k = 0; k <= 5000; k++)
dp[i][k] = 0.0;
}
dp[0][0] = 1.0;
for (int masu = 0; masu <= Y - 1; masu++) {
for (int score = 0; score <= 5000; score++) {
if (dp[masu][score] == 0.0)
continue;
for (int dice = 0; dice < X; dice++) {
if (masu + V[dice] > Y) {
next_masu = Y;
} else {
next_masu = masu + V[dice];
}
if (info[next_masu].event == None) {
dp[next_masu][score] += dp[masu][score] / (double)(X);
} else if (info[next_masu].event == Move_On) {
if (next_masu + info[next_masu].value > Y) {
next_masu = Y;
} else {
next_masu = next_masu + info[next_masu].value;
}
dp[next_masu][score] += dp[masu][score] / (double)(X);
} else if (info[next_masu].event == Get) {
dp[next_masu][score + info[next_masu].value] +=
dp[masu][score] / (double)(X);
} else { // info[next_masu].event == Lose
if (score < info[next_masu].value) {
dp[next_masu][0] += dp[masu][score] / (double)(X);
} else {
dp[next_masu][score - info[next_masu].value] +=
dp[masu][score] / (double)(X);
}
}
}
}
}
ans = 0;
for (int i = 0; i <= 5000; i++) {
ans += (double)i * dp[Y][i];
}
printf("%.0f\n", floor(ans));
}
return 0;
}
|
[["-", 64, 9, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 64, 9, 0, 1, 0, 11, 12, 16, 17, 85]]
| 1
| 689
| 2
|
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
struct E {
int e, a;
E() {}
E(int e, int a) : e(e), a(a) {}
};
int x, y, z;
int v[55];
E e[55];
// int dp[55][5555];
double dp[55][5555];
// int solve(int n,int m){
double solve(int n, int m) {
if (n >= y)
return m;
if (dp[n][m] >= 0)
return dp[n][m];
int ret = 0;
for (int i = 0; i < x; i++) {
int nn = n + v[i];
int nm = m;
switch (e[nn].e) {
case 1:
nn += e[nn].a;
break;
case 2:
nm += e[nn].a;
break;
case 3:
nm -= e[nn].a;
}
nm = max(nm, 0);
ret += solve(nn, nm);
}
return dp[n][m] = ret / x;
}
int main(void) {
while (1) {
scanf("%d%d%d", &x, &y, &z);
if (!x)
break;
for (int i = 0; i <= y; i++)
e[i] = E(0, 0);
// memset(dp,-1,sizeof(dp));
for (int i = 0; i < 55; i++) {
for (int j = 0; j < 5555; j++) {
dp[i][j] = -1;
}
}
for (int i = 0; i < x; i++) {
scanf("%d", v + i);
}
for (int i = 0; i < z; i++) {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
e[a] = E(b, c);
}
printf("%d\n", (int)solve(0, 0));
}
}
|
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
struct E {
int e, a;
E() {}
E(int e, int a) : e(e), a(a) {}
};
int x, y, z;
int v[55];
E e[66];
// int dp[55][5555];
double dp[55][5555];
// int solve(int n,int m){
double solve(int n, int m) {
if (n >= y)
return m;
if (dp[n][m] >= 0)
return dp[n][m];
double ret = 0;
for (int i = 0; i < x; i++) {
int nn = n + v[i];
int nm = m;
switch (e[nn].e) {
case 1:
nn += e[nn].a;
break;
case 2:
nm += e[nn].a;
break;
case 3:
nm -= e[nn].a;
}
nm = max(nm, 0);
ret += solve(nn, nm);
}
return dp[n][m] = ret / x;
}
int main(void) {
while (1) {
scanf("%d%d%d", &x, &y, &z);
if (!x)
break;
for (int i = 0; i <= 66; i++)
e[i] = E(0, 0);
// memset(dp,-1,sizeof(dp));
for (int i = 0; i < 55; i++) {
for (int j = 0; j < 5555; j++) {
dp[i][j] = -1;
}
}
for (int i = 0; i < x; i++) {
scanf("%d", v + i);
}
for (int i = 0; i < z; i++) {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
e[a] = E(b, c);
}
printf("%d\n", (int)solve(0, 0));
}
}
|
[["-", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13]]
| 1
| 435
| 6
|
def solve(x,y,maxm):
for i in range(y):
for j in range(maxm+1):
if dp[i][j]==0:continue
for k in range(int(x)):
if event[min(y,i+v[k])][0]==0:
dp[min(y,i+v[k])][j]+=dp[i][j]/x
elif event[i+v[k]][0]==1:
skip=event[i+v[k]][1]
dp[min(y,i+skip)][j]+=dp[i][j]/x
elif event[i+v[k]][0]==2:
m=event[i+v[k]][1]
dp[i+v[k]][j+m]+=dp[i][j]/x
else:
m=event[i+v[k]][1]
dp[i+v[k]][max(0,j-m)]+=dp[i][j]/x
return dp
while True:
x,y,z=list(map(int,input().split()))
if x==0 and y==0 and z==0:break
v=list(map(int,input().split()))
event=[[0]*2 for _ in range(y+1)]
maxm=0
for i in range(z):
n,e,a=list(map(int,input().split()))
event[n][0]=e
event[n][1]=a
if e==2:
maxm+=a
dp=[[0]*(5005) for _ in range(y+1)]
dp[0][0]=1
x=float(x)
dp=solve(x,y,maxm)
ans=0.0
for i in range(maxm+1):
ans+=dp[y][i]*i
print((int(ans)))
|
def solve(x,y,maxm):
for i in range(y):
for j in range(maxm+1):
if dp[i][j]==0:continue
for k in range(int(x)):
if event[min(y,i+v[k])][0]==0:
dp[min(y,i+v[k])][j]+=dp[i][j]/x
elif event[i+v[k]][0]==1:
skip=event[i+v[k]][1]
dp[min(y,i+v[k]+skip)][j]+=dp[i][j]/x
elif event[i+v[k]][0]==2:
m=event[i+v[k]][1]
dp[i+v[k]][j+m]+=dp[i][j]/x
else:
m=event[i+v[k]][1]
dp[i+v[k]][max(0,j-m)]+=dp[i][j]/x
return dp
while True:
x,y,z=list(map(int,input().split()))
if x==0 and y==0 and z==0:break
v=list(map(int,input().split()))
event=[[0]*2 for _ in range(y+1)]
maxm=0
for i in range(z):
n,e,a=list(map(int,input().split()))
event[n][0]=e
event[n][1]=a
if e==2:
maxm+=a
dp=[[0]*(5005) for _ in range(y+1)]
dp[0][0]=1
x=float(x)
dp=solve(x,y,maxm)
ans=0.0
for i in range(maxm+1):
ans+=dp[y][i]*i
print((int(ans)))
|
[["+", 3, 4, 0, 657, 31, 657, 12, 206, 51, 22], ["+", 3, 4, 0, 657, 31, 657, 12, 206, 0, 70], ["+", 3, 4, 0, 657, 31, 657, 12, 206, 206, 22], ["+", 3, 4, 0, 657, 31, 657, 12, 206, 0, 73], ["+", 51, 206, 206, 652, 3, 4, 0, 657, 17, 72]]
| 5
| 463
| 5
|
#include <algorithm>
#include <queue>
#include <stdio.h>
using namespace std;
int dp[12][12][12][12][52];
int v[12][12][12][12][52];
int t[12][12];
struct wolf {
int cost;
int row;
int col;
int L;
int R;
int v;
wolf() {}
wolf(int a, int b, int c, int d, int e, int f) {
cost = a;
row = b;
col = c;
L = d;
R = e;
v = f;
}
};
inline bool operator<(const wolf &a, const wolf &b) {
if (a.cost != b.cost)
return a.cost > b.cost;
return false;
}
int main() {
int a, b;
while (scanf("%d%d", &b, &a), a) {
int c, d, e;
scanf("%d%d%d", &c, &d, &e);
for (int i = 0; i < a; i++)
for (int j = 0; j < b; j++)
scanf("%d", &t[i][j]);
for (int i = 0; i < a; i++)
for (int j = 0; j < b; j++)
for (int k = 0; k < b; k++)
for (int l = 0; l < b; l++)
for (int m = 0; m <= d; m++)
dp[i][j][k][l][m] = 999999999;
for (int i = 0; i < a; i++)
for (int j = 0; j < b; j++)
for (int k = 0; k < b; k++)
for (int l = 0; l < b; l++)
for (int m = 0; m <= d; m++)
v[i][j][k][l][m] = 0;
priority_queue<wolf> Q;
if (e <= 1) {
printf("NA\n");
continue;
}
for (int i = 0; i < b; i++) {
if (t[0][i] > 0) {
dp[0][i][i][i][min(d, e - 1 + t[0][i])] = 0;
Q.push(wolf(0, 0, i, i, i, min(d, e - 1 + t[0][i])));
} else {
dp[0][i][i][i][e - 1] = -t[0][i];
Q.push(wolf(-t[0][i], 0, i, i, i, e - 1));
}
}
while (Q.size()) {
wolf at = Q.top();
Q.pop();
if (v[at.row][at.col][at.L][at.R][at.v])
continue;
v[at.row][at.col][at.L][at.R][at.v] = 1;
if (at.v == 1)
continue;
if (at.col) {
if (at.col == at.L) {
if (t[at.row][at.col - 1] > 0) {
int tov = min(d, at.v - 1 + t[at.row][at.col - 1]);
if (!v[at.row][at.col - 1][at.col - 1][at.R][tov] &&
dp[at.row][at.col - 1][at.col - 1][at.R][tov] > at.cost) {
dp[at.row][at.col - 1][at.col - 1][at.R][tov] = at.cost;
Q.push(wolf(at.cost, at.row, at.col - 1, at.col - 1, at.R, tov));
}
} else {
if (!v[at.row][at.col - 1][at.col - 1][at.R][at.v - 1] &&
dp[at.row][at.col - 1][at.col - 1][at.R][at.v - 1] >
at.cost - t[at.row][at.col - 1]) {
dp[at.row][at.col - 1][at.col - 1][at.R][at.v - 1] =
at.cost - t[at.row][at.col - 1];
Q.push(wolf(at.cost - t[at.row][at.col - 1], at.row, at.col - 1,
at.col - 1, at.R, at.v));
}
}
} else {
if (!v[at.row][at.col - 1][at.L][at.R][at.v - 1] &&
dp[at.row][at.col - 1][at.L][at.R][at.v - 1] > at.cost) {
dp[at.row][at.col - 1][at.L][at.R][at.v - 1] = at.cost;
Q.push(wolf(at.cost, at.row, at.col - 1, at.L, at.R, at.v - 1));
}
}
}
if (at.col < b - 1) {
if (at.col == at.R) {
if (t[at.row][at.col + 1] > 0) {
int tov = min(d, at.v - 1 + t[at.row][at.col + 1]);
if (!v[at.row][at.col + 1][at.L][at.col + 1][tov] &&
dp[at.row][at.col + 1][at.L][at.col + 1][tov] > at.cost) {
dp[at.row][at.col + 1][at.L][at.col + 1][tov] = at.cost;
Q.push(wolf(at.cost, at.row, at.col + 1, at.L, at.col + 1, tov));
}
} else {
if (!v[at.row][at.col + 1][at.L][at.col + 1][at.v - 1] &&
dp[at.row][at.col + 1][at.L][at.col + 1][at.v - 1] >
at.cost - t[at.row][at.col + 1]) {
dp[at.row][at.col + 1][at.L][at.col + 1][at.v - 1] =
at.cost - t[at.row][at.col + 1];
Q.push(wolf(at.cost - t[at.row][at.col + 1], at.row, at.col + 1,
at.L, at.col + 1, at.v - 1));
}
}
} else {
if (!v[at.row][at.col + 1][at.L][at.R][at.v - 1] &&
dp[at.row][at.col + 1][at.L][at.R][at.v - 1] > at.cost) {
dp[at.row][at.col + 1][at.L][at.R][at.v - 1] = at.cost;
Q.push(wolf(at.cost, at.row, at.col + 1, at.L, at.R, at.v - 1));
}
}
}
if (at.row < a - 1) {
if (t[at.row + 1][at.col] > 0) {
int tov = min(d, at.v - 1 + t[at.row + 1][at.col]);
if (!v[at.row + 1][at.col][at.col][at.col][tov] &&
dp[at.row + 1][at.col][at.col][at.col][tov] > at.cost) {
dp[at.row + 1][at.col][at.col][at.col][tov] = at.cost;
Q.push(wolf(at.cost, at.row + 1, at.col, at.col, at.col, tov));
}
} else {
if (!v[at.row + 1][at.col][at.col][at.col][at.v - 1] &&
dp[at.row + 1][at.col][at.col][at.col][at.v - 1] >
at.cost - t[at.row + 1][at.col]) {
dp[at.row + 1][at.col][at.col][at.col][at.v - 1] =
at.cost - t[at.row + 1][at.col];
Q.push(wolf(at.cost - t[at.row + 1][at.col], at.row + 1, at.col,
at.col, at.col, at.v - 1));
}
}
}
}
int ret = 999999999;
for (int i = 0; i < b; i++) {
for (int j = 0; j < b; j++)
for (int k = 0; k < b; k++)
for (int l = 1; l <= d; l++)
ret = min(ret, dp[a - 1][i][j][k][l]);
}
if (ret > c) {
printf("NA\n");
} else
printf("%d\n", ret);
}
}
|
#include <algorithm>
#include <queue>
#include <stdio.h>
using namespace std;
int dp[12][12][12][12][52];
int v[12][12][12][12][52];
int t[12][12];
struct wolf {
int cost;
int row;
int col;
int L;
int R;
int v;
wolf() {}
wolf(int a, int b, int c, int d, int e, int f) {
cost = a;
row = b;
col = c;
L = d;
R = e;
v = f;
}
};
inline bool operator<(const wolf &a, const wolf &b) {
if (a.cost != b.cost)
return a.cost > b.cost;
return false;
}
int main() {
int a, b;
while (scanf("%d%d", &b, &a), a) {
int c, d, e;
scanf("%d%d%d", &c, &d, &e);
for (int i = 0; i < a; i++)
for (int j = 0; j < b; j++)
scanf("%d", &t[i][j]);
for (int i = 0; i < a; i++)
for (int j = 0; j < b; j++)
for (int k = 0; k < b; k++)
for (int l = 0; l < b; l++)
for (int m = 0; m <= d; m++)
dp[i][j][k][l][m] = 999999999;
for (int i = 0; i < a; i++)
for (int j = 0; j < b; j++)
for (int k = 0; k < b; k++)
for (int l = 0; l < b; l++)
for (int m = 0; m <= d; m++)
v[i][j][k][l][m] = 0;
priority_queue<wolf> Q;
if (e <= 1) {
printf("NA\n");
continue;
}
for (int i = 0; i < b; i++) {
if (t[0][i] > 0) {
dp[0][i][i][i][min(d, e - 1 + t[0][i])] = 0;
Q.push(wolf(0, 0, i, i, i, min(d, e - 1 + t[0][i])));
} else {
dp[0][i][i][i][e - 1] = -t[0][i];
Q.push(wolf(-t[0][i], 0, i, i, i, e - 1));
}
}
while (Q.size()) {
wolf at = Q.top();
Q.pop();
if (v[at.row][at.col][at.L][at.R][at.v])
continue;
v[at.row][at.col][at.L][at.R][at.v] = 1;
if (at.v == 1)
continue;
if (at.col) {
if (at.col == at.L) {
if (t[at.row][at.col - 1] > 0) {
int tov = min(d, at.v - 1 + t[at.row][at.col - 1]);
if (!v[at.row][at.col - 1][at.col - 1][at.R][tov] &&
dp[at.row][at.col - 1][at.col - 1][at.R][tov] > at.cost) {
dp[at.row][at.col - 1][at.col - 1][at.R][tov] = at.cost;
Q.push(wolf(at.cost, at.row, at.col - 1, at.col - 1, at.R, tov));
}
} else {
if (!v[at.row][at.col - 1][at.col - 1][at.R][at.v - 1] &&
dp[at.row][at.col - 1][at.col - 1][at.R][at.v - 1] >
at.cost - t[at.row][at.col - 1]) {
dp[at.row][at.col - 1][at.col - 1][at.R][at.v - 1] =
at.cost - t[at.row][at.col - 1];
Q.push(wolf(at.cost - t[at.row][at.col - 1], at.row, at.col - 1,
at.col - 1, at.R, at.v - 1));
}
}
} else {
if (!v[at.row][at.col - 1][at.L][at.R][at.v - 1] &&
dp[at.row][at.col - 1][at.L][at.R][at.v - 1] > at.cost) {
dp[at.row][at.col - 1][at.L][at.R][at.v - 1] = at.cost;
Q.push(wolf(at.cost, at.row, at.col - 1, at.L, at.R, at.v - 1));
}
}
}
if (at.col < b - 1) {
if (at.col == at.R) {
if (t[at.row][at.col + 1] > 0) {
int tov = min(d, at.v - 1 + t[at.row][at.col + 1]);
if (!v[at.row][at.col + 1][at.L][at.col + 1][tov] &&
dp[at.row][at.col + 1][at.L][at.col + 1][tov] > at.cost) {
dp[at.row][at.col + 1][at.L][at.col + 1][tov] = at.cost;
Q.push(wolf(at.cost, at.row, at.col + 1, at.L, at.col + 1, tov));
}
} else {
if (!v[at.row][at.col + 1][at.L][at.col + 1][at.v - 1] &&
dp[at.row][at.col + 1][at.L][at.col + 1][at.v - 1] >
at.cost - t[at.row][at.col + 1]) {
dp[at.row][at.col + 1][at.L][at.col + 1][at.v - 1] =
at.cost - t[at.row][at.col + 1];
Q.push(wolf(at.cost - t[at.row][at.col + 1], at.row, at.col + 1,
at.L, at.col + 1, at.v - 1));
}
}
} else {
if (!v[at.row][at.col + 1][at.L][at.R][at.v - 1] &&
dp[at.row][at.col + 1][at.L][at.R][at.v - 1] > at.cost) {
dp[at.row][at.col + 1][at.L][at.R][at.v - 1] = at.cost;
Q.push(wolf(at.cost, at.row, at.col + 1, at.L, at.R, at.v - 1));
}
}
}
if (at.row < a - 1) {
if (t[at.row + 1][at.col] > 0) {
int tov = min(d, at.v - 1 + t[at.row + 1][at.col]);
if (!v[at.row + 1][at.col][at.col][at.col][tov] &&
dp[at.row + 1][at.col][at.col][at.col][tov] > at.cost) {
dp[at.row + 1][at.col][at.col][at.col][tov] = at.cost;
Q.push(wolf(at.cost, at.row + 1, at.col, at.col, at.col, tov));
}
} else {
if (!v[at.row + 1][at.col][at.col][at.col][at.v - 1] &&
dp[at.row + 1][at.col][at.col][at.col][at.v - 1] >
at.cost - t[at.row + 1][at.col]) {
dp[at.row + 1][at.col][at.col][at.col][at.v - 1] =
at.cost - t[at.row + 1][at.col];
Q.push(wolf(at.cost - t[at.row + 1][at.col], at.row + 1, at.col,
at.col, at.col, at.v - 1));
}
}
}
}
int ret = 999999999;
for (int i = 0; i < b; i++) {
for (int j = 0; j < b; j++)
for (int k = 0; k < b; k++)
for (int l = 1; l <= d; l++)
ret = min(ret, dp[a - 1][i][j][k][l]);
}
if (ret > c) {
printf("NA\n");
} else
printf("%d\n", ret);
}
}
|
[["+", 3, 4, 0, 2, 3, 4, 0, 16, 17, 33], ["+", 3, 4, 0, 2, 3, 4, 0, 16, 12, 13]]
| 1
| 2,296
| 2
|
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var str = input.trim();
if (str = "1 0 0")
console.log("Close");
if (str = "0 1 0")
console.log("Close");
if (str = "1 1 0")
console.log("Open");
if (str = "0 0 1")
console.log("Open");
if (str = "0 0 0")
console.log("Close");
|
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var str = input.trim();
if (str == "1 0 0")
console.log("Close");
if (str == "0 1 0")
console.log("Close");
if (str == "1 1 0")
console.log("Open");
if (str == "0 0 1")
console.log("Open");
if (str == "0 0 0")
console.log("Close");
|
[["-", 0, 493, 0, 57, 15, 23, 0, 11, 0, 32], ["+", 0, 493, 0, 57, 15, 23, 0, 16, 17, 60]]
| 2
| 115
| 10
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int b1 = scan.nextInt();
int b2 = scan.nextInt();
int b3 = scan.nextInt();
if (b1 == 1 && b2 == 0 && b3 == 0 || b1 == 0 && b2 == 1 && b3 == 0 ||
b1 == 0 && b2 == 0 && b3 == 0) {
System.out.println("Close");
} else {
if (b1 == 1 && b2 == 1 && b2 == 0 || b1 == 0 && b2 == 0 && b3 == 1) {
System.out.println("Open");
}
}
}
}
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int b1 = scan.nextInt();
int b2 = scan.nextInt();
int b3 = scan.nextInt();
if (b1 == 1 && b2 == 0 && b3 == 0 || b1 == 0 && b2 == 1 && b3 == 0 ||
b1 == 0 && b2 == 0 && b3 == 0) {
System.out.println("Close");
} else {
if (b1 == 1 && b2 == 1 && b3 == 0 || b1 == 0 && b2 == 0 && b3 == 1) {
System.out.println("Open");
}
}
}
}
|
[["-", 15, 15, 0, 16, 31, 16, 12, 16, 31, 22], ["+", 15, 15, 0, 16, 31, 16, 12, 16, 31, 22]]
| 3
| 155
| 2
|
#include <stdio.h>
int main(void) {
int b[3] = {0};
int x = 0, i;
for (i = 0; i < 3; i++) {
scanf("%d", b[i]);
}
x = 2 * 2 * b[0] + 2 * b[1] + b[2];
switch (x) {
case 6:
case 1:
printf("Open\n");
break;
default:
printf("Close\n");
break;
}
return (0);
}
|
#include <stdio.h>
int main(void) {
int b[3] = {0};
int x = 0, i;
for (i = 0; i < 3; i++) {
scanf("%d", &b[i]);
}
x = 2 * 2 * b[0] + 2 * b[1] + b[2];
switch (x) {
case 6:
case 1:
printf("Open\n");
break;
default:
printf("Close\n");
break;
}
return (0);
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 66, 17, 67]]
| 0
| 115
| 1
|
#include <stdio.h>
int main(void) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if ((a + b == 2) || (c = 1)) {
printf("Open\n");
} else {
printf("Close");
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if ((a + b == 2) || (c == 1)) {
printf("Open\n");
} else {
printf("Close\n");
}
return 0;
}
|
[["-", 15, 23, 0, 16, 12, 23, 0, 11, 17, 32], ["+", 15, 23, 0, 16, 12, 23, 0, 16, 17, 60], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 71
| 3
|
#include <stdio.h>
int main() {
int a, b, c;
scanf("%d %d %d", a, b, c);
if (c == 1)
printf("Open\n");
else if (a == 1 && b == 1)
printf("Open\n");
else
printf("Close\n");
return 0;
}
|
#include <stdio.h>
int main() {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if (c == 1)
printf("Open\n");
else if (a == 1 && b == 1)
printf("Open\n");
else
printf("Close\n");
return 0;
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 66, 17, 67]]
| 0
| 73
| 3
|
#include <stdio.h>
int main(void) {
int b1, b2, b3;
scanf("%d %d %d", &b1, &b2, &b3);
if ((b1 == 1 && b2 == 0 && b3 == 0) || (b1 == 0 && b2 == 1 && b3 == 0) ||
(b1 == 0 && b2 == 0 && b3 == 0)) {
printf("close\n");
}
else if ((b1 == 1 && b2 == 1 && b3 == 0) || (b1 == 0 && b2 == 0 && b3 == 1)) {
printf("open\n");
}
return (0);
}
|
#include <stdio.h>
int main(void) {
int b1, b2, b3;
scanf("%d %d %d", &b1, &b2, &b3);
if ((b1 == 1 && b2 == 0 && b3 == 0) || (b1 == 0 && b2 == 1 && b3 == 0) ||
(b1 == 0 && b2 == 0 && b3 == 0)) {
printf("Close\n");
}
else if ((b1 == 1 && b2 == 1 && b3 == 0) || (b1 == 0 && b2 == 0 && b3 == 1)) {
printf("Open\n");
}
return (0);
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 0
| 132
| 4
|
#include <stdio.h>
int main(void) {
int b1;
int b2;
int b3;
scanf("%d %d %d", &b1, &b2, &b3);
if ((b1 = 1) && (b2 = 1) || (b3 = 1)) {
printf("Open\n");
} else {
printf("Close\n");
}
return (0);
}
|
#include <stdio.h>
int main(void) {
int b1;
int b2;
int b3;
scanf("%d %d %d", &b1, &b2, &b3);
if ((b1 == 1) && (b2 == 1) || (b3 == 1)) {
printf("Open\n");
} else {
printf("Close\n");
}
return (0);
}
|
[["-", 0, 16, 31, 16, 31, 23, 0, 11, 17, 32], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 17, 60], ["-", 0, 16, 31, 16, 12, 23, 0, 11, 17, 32], ["+", 0, 16, 31, 16, 12, 23, 0, 16, 17, 60], ["-", 15, 23, 0, 16, 12, 23, 0, 11, 17, 32], ["+", 15, 23, 0, 16, 12, 23, 0, 16, 17, 60]]
| 0
| 80
| 6
|
#include <stdio.h>
int main(void) {
int b1, b2, b3;
scanf("%d %d %d", &b1, &b2, &b3);
if (b1 == 1) {
if (b2 == 1)
puts("Open");
else
puts("Close");
}
else {
if (b2 == 1 || b3 == 1)
puts("Open");
else
puts("Close");
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int b1, b2, b3;
scanf("%d %d %d", &b1, &b2, &b3);
if (b1 == 1) {
if (b2 == 1)
puts("Open");
else
puts("Close");
}
else {
if (b3 == 1)
puts("Open");
else
puts("Close");
}
return 0;
}
|
[["-", 0, 57, 15, 23, 0, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 23, 0, 16, 31, 16, 17, 60], ["-", 0, 57, 15, 23, 0, 16, 31, 16, 12, 13], ["-", 0, 9, 0, 57, 15, 23, 0, 16, 17, 106]]
| 0
| 92
| 4
|
#include <stdio.h>
int main(void) {
int b1, b2, b3;
scanf("%d %d %d", &b1, &b2, &b3);
if (b1 == 1 == b2 || b3 == 1)
printf("Open\n");
else
printf("Close\n");
return 0;
}
|
#include <stdio.h>
int main(void) {
int b1, b2, b3;
scanf("%d %d %d", &b1, &b2, &b3);
if (b1 == 1 && 1 == b2 || b3 == 1)
printf("Open\n");
else
printf("Close\n");
return 0;
}
|
[["+", 0, 57, 15, 23, 0, 16, 31, 16, 17, 98], ["+", 15, 23, 0, 16, 31, 16, 12, 16, 31, 13]]
| 0
| 64
| 2
|
#include <stdio.h>
int main(void) {
int b1, b2, b3;
scanf("%d %d %d", b1, b2, b3);
if ((b1 == 1 && b2 == 1) || b3 == 1) {
printf("Open\n");
} else {
printf("Close\n");
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int b1, b2, b3;
scanf("%d %d %d", &b1, &b2, &b3);
if ((b1 == 1 && b2 == 1) || b3 == 1) {
printf("Open\n");
} else {
printf("Close\n");
}
return 0;
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 66, 17, 67]]
| 0
| 69
| 3
|
#include <stdio.h>
int main() {
int a, b, c;
scanf("%d%d%d", a, b, c);
if (a == 1 && b == 1 && c == 0 || c == 1) {
printf("Open\n");
} else
printf("Close\n");
return 0;
}
|
#include <stdio.h>
int main() {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
if (a == 1 && b == 1 && c == 0 || c == 1) {
printf("Open\n");
} else
printf("Close\n");
return 0;
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 66, 17, 67]]
| 0
| 68
| 3
|
#include <stdio.h>
int main(void) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if (a == 1 && b == 0 && c == 0) {
printf("Close\n");
}
if (a == 0 && b == 1 && c == 0) {
printf("Close\n");
}
if (a == a && b == 1 && c == 0) {
printf("Open\n");
}
if (a == 0 && b == 0 && c == 1) {
printf("Open\n");
}
if (a == 0 && b == 0 && c == 0) {
printf("Close\n");
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if (a == 1 && b == 0 && c == 0) {
printf("Close\n");
} else if (a == 0 && b == 1 && c == 0) {
printf("Close\n");
} else if (a == a && b == 1 && c == 0) {
printf("Open\n");
} else if (a == 0 && b == 0 && c == 1) {
printf("Open\n");
} else if (a == 0 && b == 0 && c == 0) {
printf("Close\n");
}
return 0;
}
|
[["+", 0, 14, 8, 9, 0, 57, 75, 76, 0, 95], ["+", 0, 57, 75, 76, 0, 57, 75, 76, 0, 95]]
| 0
| 155
| 4
|
#include <stdio.h>
int main(void) {
int s1, s2, s3;
scanf("%d %d %d", &s1, &s2, &s3);
if (s1 == 1 && s2 == 1 && s3 == 0) {
printf("Open\n");
}
if (s1 == 0 && s2 == 0 && s3 == 1) {
printf("Open\n");
}
else {
printf("Close\n");
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int s1, s2, s3;
scanf("%d %d %d", &s1, &s2, &s3);
if (s1 == 1 && s2 == 1 && s3 == 0) {
printf("Open\n");
}
else if (s1 == 0 && s2 == 0 && s3 == 1) {
printf("Open\n");
}
else {
printf("Close\n");
}
return 0;
}
|
[["+", 0, 14, 8, 9, 0, 57, 75, 76, 0, 95]]
| 0
| 94
| 1
|
#include <stdio.h>
int main(void) {
int b1, b2, b3;
scanf("%d %d %d", b1, b2, b3);
if (b1 == 1 && b2 == 0 && b3 == 0 || b1 == 0 && b2 == 1 && b3 == 0 ||
b1 == 0 && b2 == 0 && b3 == 0)
printf("Close\n");
else
printf("Open\n");
return 0;
}
|
#include <stdio.h>
int main(void) {
int b1, b2, b3;
scanf("%d %d %d", &b1, &b2, &b3);
if (b1 == 1 && b2 == 0 && b3 == 0 || b1 == 0 && b2 == 1 && b3 == 0 ||
b1 == 0 && b2 == 0 && b3 == 0)
printf("Close\n");
else
printf("Open\n");
return 0;
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 66, 17, 67]]
| 0
| 87
| 3
|
#include <stdio.h>
int main(void) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if ((a == 1 && b == 0 && c == 0) || (a == 0 && b == 1 && c == 0) ||
(a == b == c == 0)) {
printf("Close\n");
} else {
printf("Open\n");
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if ((a == 1 && b == 0 && c == 0) || (a == 0 && b == 1 && c == 0) ||
(a == 0 && b == 0 && c == 0)) {
printf("Close\n");
} else {
printf("Open\n");
}
return 0;
}
|
[["+", 12, 23, 0, 16, 31, 16, 31, 16, 12, 13], ["+", 0, 16, 12, 23, 0, 16, 31, 16, 17, 98], ["+", 12, 23, 0, 16, 31, 16, 12, 16, 12, 13], ["+", 15, 23, 0, 16, 12, 23, 0, 16, 17, 98]]
| 0
| 96
| 4
|
main(a, b, c) {
scanf("%d%d%d", &a, &b, &c);
div(puts(a ? b : c ? "Open" : "Close"));
}
|
main(a, b, c) {
scanf("%d%d%d", &a, &b, &c);
div(puts(a * b + c ? "Open" : "Close"));
}
|
[["-", 3, 4, 0, 2, 3, 4, 0, 41, 0, 101], ["+", 3, 4, 0, 41, 15, 16, 31, 16, 17, 48], ["-", 3, 4, 0, 2, 3, 4, 0, 41, 0, 102], ["+", 0, 2, 3, 4, 0, 41, 15, 16, 17, 72]]
| 0
| 47
| 4
|
main(a) {
gets(&a);
div(puts(15 & a & 15 & a >> 16 | 15 & *&a + 1 ? "Open" : "Close"));
}
|
main(a) {
gets(&a);
div(puts(15 & a & a >> 16 | 15 & (&a)[1] ? "Open" : "Close"));
}
|
[["-", 0, 41, 15, 16, 31, 16, 31, 16, 12, 13], ["-", 3, 4, 0, 41, 15, 16, 31, 16, 17, 67], ["-", 15, 16, 12, 16, 12, 16, 31, 66, 17, 48], ["+", 15, 16, 12, 16, 12, 69, 28, 23, 0, 24], ["-", 0, 41, 15, 16, 12, 16, 12, 16, 17, 72], ["+", 15, 16, 12, 16, 12, 69, 28, 23, 0, 25], ["+", 0, 41, 15, 16, 12, 16, 12, 69, 0, 70], ["+", 0, 41, 15, 16, 12, 16, 12, 69, 0, 73]]
| 0
| 44
| 8
|
a[];
main() {
gets(a);
div(puts(*a & *a >> 16 | a[1] % 2 ? "Open" : "Close"));
}
|
a[];
main() {
gets(a);
div(puts(15 & *a & *a >> 16 | 15 & a[1] ? "Open" : "Close"));
}
|
[["+", 0, 41, 15, 16, 31, 16, 31, 16, 31, 13], ["+", 0, 41, 15, 16, 31, 16, 31, 16, 17, 67], ["+", 3, 4, 0, 41, 15, 16, 12, 16, 31, 13], ["+", 3, 4, 0, 41, 15, 16, 12, 16, 17, 67], ["-", 3, 4, 0, 41, 15, 16, 12, 16, 17, 109], ["-", 3, 4, 0, 41, 15, 16, 12, 16, 12, 13]]
| 0
| 45
| 2
|
a[];
main() {
gets(a);
div(puts(*a & *a >> 16 | a[1] % 2 ? "Open" : "Close"));
}
|
a[];
main() {
gets(a);
div(puts(15 & *a & *a >> 16 | a[1] % 2 ? "Open" : "Close"));
}
|
[["+", 0, 41, 15, 16, 31, 16, 31, 16, 31, 13], ["+", 0, 41, 15, 16, 31, 16, 31, 16, 17, 67]]
| 0
| 45
| 2
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)), UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a + mod - b) % mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i, m, n) for (int i = m; i < n; i++)
#define drep(i, n, m) for (int i = n; i >= m; i--)
#define rep(i, n) repi(i, 0, n)
#define rrep(i, n) repi(i, 1, n + 1)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9 + 7;
const int INF = 1e18 + 7;
signed main() {
int a, b, c, ans = 0;
scanf("%lld%lld%lld", &a, &b, &c);
if (a == 1 and b == 1 and c == 1)
ans = 1;
if (a == 0 and b == 0 and c == 1)
ans = 1;
printf("%s\n", ans ? "Open" : "Close");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)), UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a + mod - b) % mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i, m, n) for (int i = m; i < n; i++)
#define drep(i, n, m) for (int i = n; i >= m; i--)
#define rep(i, n) repi(i, 0, n)
#define rrep(i, n) repi(i, 1, n + 1)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9 + 7;
const int INF = 1e18 + 7;
signed main() {
int a, b, c, ans = 0;
scanf("%lld%lld%lld", &a, &b, &c);
if (a == 1 and b == 1 and c == 0)
ans = 1;
if (a == 0 and b == 0 and c == 1)
ans = 1;
printf("%s\n", ans ? "Open" : "Close");
return 0;
}
|
[["-", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
| 1
| 276
| 2
|
#include <stdio.h>
int main() {
int x, y, z;
scanf("%d %d %d", &x, &y, &z);
if ((x == 1 && y == 1) || z == 1) {
printf("open\n");
} else {
printf("close\n");
}
return 0;
}
|
#include <stdio.h>
int main() {
int x, y, z;
scanf("%d %d %d", &x, &y, &z);
if ((x == 1 && y == 1) || z == 1) {
printf("Open\n");
} else {
printf("Close\n");
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 1
| 71
| 4
|
#include <iostream>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if ((a == 1 && b == 1 && c == 0) || (a == 0 && b == 0 && c == 1))
cout << "open" << endl;
else
cout << "close" << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if ((a == 1 && b == 1 && c == 0) || (a == 0 && b == 0 && c == 1))
cout << "Open" << endl;
else
cout << "Close" << endl;
return 0;
}
|
[["-", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 77
| 4
|
#include <iostream>
using namespace std;
int main() {
int b1, b2, b3;
cin >> b1 >> b2 >> b3;
if (b1 == 1 && b2 == 0 && b3 == 0) {
cout << "Close" << endl;
} else if (b1 == 0 && b2 == 1 && b3 == 0) {
cout << "Colse" << endl;
} else if (b1 == 1 && b2 == 1 && b3 == 0) {
cout << "Open" << endl;
} else if (b1 == 0 && b2 == 0 && b3 == 1) {
cout << "Open" << endl;
} else if (b1 == 0 && b2 == 0 && b3 == 0) {
cout << "Close" << endl;
}
}
|
#include <iostream>
using namespace std;
int main() {
int b1, b2, b3;
cin >> b1 >> b2 >> b3;
if (b1 == 1 && b2 == 0 && b3 == 0) {
cout << "Close" << endl;
} else if (b1 == 0 & b2 == 1 && b3 == 0) {
cout << "Close" << endl;
} else if (b1 == 1 && b2 == 1 && b3 == 0) {
cout << "Open" << endl;
} else if (b1 == 0 && b2 == 0 && b3 == 0) {
cout << "Close" << endl;
} else if (b1 == 0 && b2 == 0 && b3 == 1) {
cout << "Open" << endl;
}
}
|
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 17, 98], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 67], ["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
| 1
| 151
| 12
|
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
int b1, b2, b3;
cin >> b1 >> b2 >> b3;
if (b1 == 1 && b2 == 1 && b3 == 0) {
cout << "Close" << endl;
} else if (b1 == 0 && b2 == 1 && b3 == 0) {
cout << "Close" << endl;
} else if (b1 == 1 && b2 == 1 && b3 == 0) {
cout << "Open" << endl;
} else if (b1 == 0 && b2 == 0 && b3 == 1) {
cout << "Open" << endl;
} else if (b1 == 0 && b2 == 0 && b3 == 0) {
cout << "Open" << endl;
}
return 0;
}
|
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
int b1, b2, b3;
cin >> b1 >> b2 >> b3;
if (b1 == 1 && b2 == 0 && b3 == 0) {
cout << "Close" << endl;
} else if (b1 == 0 && b2 == 1 && b3 == 0) {
cout << "Close" << endl;
} else if (b1 == 1 && b2 == 1 && b3 == 0) {
cout << "Open" << endl;
} else if (b1 == 0 && b2 == 0 && b3 == 1) {
cout << "Open" << endl;
} else if (b1 == 0 && b2 == 0 && b3 == 0) {
cout << "Close" << endl;
}
return 0;
}
|
[["-", 15, 339, 51, 16, 31, 16, 12, 16, 12, 13], ["+", 15, 339, 51, 16, 31, 16, 12, 16, 12, 13], ["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 156
| 4
|
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#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 PB push_back
#define INF INT_MAX / 3
#define ALL(a) (a).begin(), (a).end()
#define CLR(a) memset(a, 0, sizeof(a))
typedef long long int ll;
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a == 0 && c == 0)
cout << "Close" << endl;
else if (a == 1 && c == 0)
cout << "Close" << endl;
else
cout << "Open" << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#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 PB push_back
#define INF INT_MAX / 3
#define ALL(a) (a).begin(), (a).end()
#define CLR(a) memset(a, 0, sizeof(a))
typedef long long int ll;
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a == 0 && c == 0)
cout << "Close" << endl;
else if (a == 1 && b == 0 && c == 0)
cout << "Close" << endl;
else
cout << "Open" << endl;
return 0;
}
|
[["+", 15, 339, 51, 16, 31, 16, 12, 16, 31, 22], ["+", 15, 339, 51, 16, 31, 16, 12, 16, 17, 60], ["+", 15, 339, 51, 16, 31, 16, 12, 16, 12, 13], ["+", 75, 76, 0, 57, 15, 339, 51, 16, 17, 98]]
| 1
| 136
| 4
|
#include <stdio.h>
int main(void) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if (a == 0, b == 0, c == 1) {
printf("Open\n");
}
if (a == 1, b == 1, c == 0) {
printf("Open\n");
} else {
printf("Close\n");
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if (a == 0 && b == 0 && c == 1) {
printf("Open\n");
} else if (a == 1 && b == 1 && c == 0) {
printf("Open\n");
} else {
printf("Close\n");
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 34, 0, 21], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 98], ["-", 0, 57, 15, 339, 51, 34, 12, 34, 0, 21], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 98], ["+", 0, 14, 8, 9, 0, 57, 75, 76, 0, 95], ["+", 75, 76, 0, 57, 15, 339, 51, 16, 17, 98]]
| 1
| 94
| 9
|
#include <stdio.h>
int main() {
int x, y, z;
scanf("%d %d %d", &x, &y, &z);
if ((x == 1 && y == 1) || (z == 1)) {
printf("open\n");
} else {
printf("close\n");
}
return 0;
}
|
#include <stdio.h>
int main() {
int x, y, z;
scanf("%d %d %d", &x, &y, &z);
if ((x == 1 && y == 1) || (z == 1)) {
printf("Open\n");
} else {
printf("Close\n");
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 1
| 73
| 4
|
#include <iostream>
using namespace std;
int main() {
int a = 0, b = 0, i = 0;
cin >> a >> b >> i;
if (a == 1 && b == 1) {
cout << "open" << endl;
} else if (i == 1) {
cout << "open" << endl;
} else {
cout << "close" << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int a = 0, b = 0, i = 0;
cin >> a >> b >> i;
if (a == 1 && b == 1) {
cout << "Open" << endl;
} else if (i == 1) {
cout << "Open" << endl;
} else {
cout << "Close" << endl;
}
return 0;
}
|
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 84
| 6
|
#include <iostream>
using namespace std;
int main() {
int b, com = 0;
for (int i = 2; i >= 0; i--) {
cin >> b;
com += (b << i);
}
if (b == 6 || b == 1) {
cout << "Open\n";
} else {
cout << "Close\n";
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int b, com = 0;
for (int i = 2; i >= 0; i--) {
cin >> b;
com += (b << i);
}
if (com == 6 || com == 1) {
cout << "Open\n";
} else {
cout << "Close\n";
}
return 0;
}
|
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22]]
| 1
| 79
| 4
|
#include <stdio.h>
int main(void) {
int b1, b2, b3;
scanf("%d %d %d", &b1, &b2, &b3);
if (b1 == 1 && b2 == 0 && b3 == 0) {
printf("Close\n");
} else if (b1 == 0 && b2 == 1 && b3 == 0) {
printf("Close\n");
} else if (b1 == 1 && b2 == 1 && b3 == 0) {
printf("Open\n");
} else if (b1 == 0 && b2 == 0 && b3 == 1) {
printf("Open\n");
} else if (b1 == 0 && b2 == 0 && b3 == 0) {
printf("Clos\n");
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int b1, b2, b3;
scanf("%d %d %d", &b1, &b2, &b3);
if (b1 == 1 && b2 == 0 && b3 == 0) {
printf("Close\n");
} else if (b1 == 0 && b2 == 1 && b3 == 0) {
printf("Close\n");
} else if (b1 == 1 && b2 == 1 && b3 == 0) {
printf("Open\n");
} else if (b1 == 0 && b2 == 0 && b3 == 1) {
printf("Open\n");
} else if (b1 == 0 && b2 == 0 && b3 == 0) {
printf("Close\n");
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 1
| 159
| 2
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.