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
|
|---|---|---|---|---|---|
def check_bingo(board)
board.each do |l|
stone = l.first
return stone if l.all?{ |x| x == stone } && stone != '+'
end
return false
end
def choose_winner(board)
diagonal_board = [[0,1,2].map{|x| board[x][x]}, [0,1,2].map{|x| board[x][2-x]}]
[board, board.transpose, diagonal_board].each do |b|
stone = check_bingo(b)
return stone unless stone
end
return "NA"
end
loop do
board = [gets.chomp.chars]
break if board[0] == ['0']
board[1,2] = [nil, nil].map!{ gets.chomp.chars }
puts choose_winner(board)
end
|
def check_bingo(board)
board.each do |l|
stone = l.first
return stone if l.all?{ |x| x == stone } && stone != '+'
end
return false
end
def choose_winner(board)
diagonal_board = [[0,1,2].map{|x| board[x][x]}, [0,1,2].map{|x| board[x][2-x]}]
[board, board.transpose, diagonal_board].each do |b|
stone = check_bingo(b)
return stone if stone
end
return "NA"
end
loop do
board = [gets.chomp.chars]
break if board[0] == ['0']
board[1,2] = [nil, nil].map!{ gets.chomp.chars }
puts choose_winner(board)
end
|
[["-", 0, 652, 196, 737, 8, 736, 0, 745, 0, 747], ["+", 0, 652, 196, 737, 8, 736, 0, 751, 0, 121]]
| 4
| 176
| 2
|
while True:
try:
f = [list(input()) for _ in range(3)]
except EOFError:
break
g = ["".join(x) for x in f+list(zip(*f))+[f[0][0],f[1][1],f[2][2]]+[f[2][0]+f[1][1]+f[0][2]]]
print("b" if "b"*3 in g else "w" if "w"*3 in g else "NA")
|
while True:
try:
f = [list(input()) for _ in range(3)]
except EOFError:
break
g = ["".join(x) for x in f+list(zip(*f))+[(f[0][0],f[1][1],f[2][2])]+[(f[2][0],f[1][1],f[0][2])]]
print("b" if "b"*3 in g else "w" if "w"*3 in g else "NA")
|
[["+", 12, 657, 31, 657, 12, 634, 0, 660, 0, 24], ["+", 12, 657, 31, 657, 12, 634, 0, 660, 0, 25], ["+", 0, 659, 12, 657, 12, 634, 0, 660, 0, 24], ["-", 12, 657, 12, 634, 0, 657, 31, 657, 17, 72], ["+", 0, 659, 12, 657, 12, 634, 0, 660, 0, 21], ["-", 0, 659, 12, 657, 12, 634, 0, 657, 17, 72], ["+", 0, 659, 12, 657, 12, 634, 0, 660, 0, 25]]
| 5
| 132
| 8
|
#include <stdio.h>
int main(void) {
int all, peo, i, zero = 0, one = 0, two = 0, thr = 0, fou = 0, fiv = 0,
six = 0;
scanf("%d", &all);
while (all != 0) {
zero = 0;
one = 0;
two = 0;
thr = 0;
fou = 0;
fiv = 0;
six = 0;
for (i = 0; i < all; i++) {
scanf("%d", &peo);
if (peo < 10)
zero++;
else if (peo < 20)
one++;
else if (peo < 30)
two++;
else if (peo < 40)
thr++;
else if (peo < 50)
fou++;
else if (peo < 60)
fiv++;
else if (peo < 60)
six++;
}
printf("%d\n", zero);
printf("%d\n", one);
printf("%d\n", two);
printf("%d\n", thr);
printf("%d\n", fou);
printf("%d\n", fiv);
printf("%d\n", six);
scanf("%d", &all);
}
return (0);
}
|
#include <stdio.h>
int main(void) {
int all, peo, i, zero = 0, one = 0, two = 0, thr = 0, fou = 0, fiv = 0,
six = 0;
scanf("%d", &all);
while (all != 0) {
zero = 0;
one = 0;
two = 0;
thr = 0;
fou = 0;
fiv = 0;
six = 0;
for (i = 0; i < all; i++) {
scanf("%d", &peo);
if (peo < 10)
zero++;
else if (peo < 20)
one++;
else if (peo < 30)
two++;
else if (peo < 40)
thr++;
else if (peo < 50)
fou++;
else if (peo < 60)
fiv++;
else
six++;
}
printf("%d\n", zero);
printf("%d\n", one);
printf("%d\n", two);
printf("%d\n", thr);
printf("%d\n", fou);
printf("%d\n", fiv);
printf("%d\n", six);
scanf("%d", &all);
}
return (0);
}
|
[["-", 75, 76, 0, 57, 75, 76, 0, 57, 0, 121], ["-", 0, 57, 75, 76, 0, 57, 15, 23, 0, 24], ["-", 75, 76, 0, 57, 15, 23, 0, 16, 31, 22], ["-", 75, 76, 0, 57, 15, 23, 0, 16, 17, 18], ["-", 75, 76, 0, 57, 15, 23, 0, 16, 12, 13], ["-", 0, 57, 75, 76, 0, 57, 15, 23, 0, 25]]
| 0
| 269
| 6
|
#include <stdio.h>
int main(void) {
int n;
int i;
int age;
int than_ten, ten, twen, thir, four, fif, six;
while (1) {
scanf("%d", &n);
if (n == 0) {
break;
}
than_ten = ten = twen = thir = four = fif = six = 0;
for (i = 0; i < n; i++) {
scanf("%d", &age);
if (age >= 0 && age < 9) {
than_ten++;
} else if (age < 19) {
ten++;
} else if (age < 29) {
twen++;
} else if (age < 39) {
thir++;
} else if (age < 49) {
four++;
} else if (age < 59) {
fif++;
} else if (age >= 60) {
six++;
}
}
printf("%d\n%d\n%d\n%d\n%d\n%d\n%d\n", than_ten, ten, twen, thir, four, fif,
six);
}
return (0);
}
|
#include <stdio.h>
int main(void) {
int n;
int i;
int age;
int than_ten, ten, twen, thir, four, fif, six;
while (1) {
scanf("%d", &n);
if (n == 0) {
break;
}
than_ten = ten = twen = thir = four = fif = six = 0;
for (i = 0; i < n; i++) {
scanf("%d", &age);
if (age >= 0 && age <= 9) {
than_ten++;
} else if (age <= 19) {
ten++;
} else if (age <= 29) {
twen++;
} else if (age <= 39) {
thir++;
} else if (age <= 49) {
four++;
} else if (age <= 59) {
fif++;
} else if (age >= 60) {
six++;
}
}
printf("%d\n%d\n%d\n%d\n%d\n%d\n%d\n", than_ten, ten, twen, thir, four, fif,
six);
}
return (0);
}
|
[["-", 0, 57, 15, 23, 0, 16, 12, 16, 17, 18], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 17, 19], ["-", 75, 76, 0, 57, 15, 23, 0, 16, 17, 18], ["+", 75, 76, 0, 57, 15, 23, 0, 16, 17, 19]]
| 0
| 226
| 12
|
#include <stdio.h>
int main(void) {
int n;
int i;
int age;
int than_ten, ten, twen, thir, four, fif, six;
while (1) {
scanf("%d", &n);
if (n == 0) {
break;
}
than_ten = ten = twen = thir = four = fif = six = 0;
for (i = 0; i < n; i++) {
scanf("%d", &age);
if (age >= 0 && age < 9) {
than_ten++;
} else if (age < 19) {
ten++;
} else if (age < 29) {
twen++;
} else if (age < 39) {
thir++;
} else if (age < 49) {
four++;
} else if (age < 59) {
fif++;
} else if (age >= 60) {
six++;
}
}
printf("%d\n%d\n%d\n%d\n%d\n%d\n%d\n", than_ten, ten, twen, thir, four, fif,
six);
}
return (0);
}
|
#include <stdio.h>
int main(void) {
int n;
int i;
int age;
int than_ten, ten, twen, thir, four, fif, six;
while (1) {
scanf("%d", &n);
if (n == 0) {
break;
}
than_ten = ten = twen = thir = four = fif = six = 0;
for (i = 0; i < n; i++) {
scanf("%d", &age);
if (age >= 0 && age < 10) {
than_ten++;
} else if (age < 20) {
ten++;
} else if (age < 30) {
twen++;
} else if (age < 40) {
thir++;
} else if (age < 50) {
four++;
} else if (age < 60) {
fif++;
} else if (age >= 60) {
six++;
}
}
printf("%d\n%d\n%d\n%d\n%d\n%d\n%d\n", than_ten, ten, twen, thir, four, fif,
six);
}
return (0);
}
|
[["-", 0, 57, 15, 23, 0, 16, 12, 16, 12, 13], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 12, 13], ["-", 75, 76, 0, 57, 15, 23, 0, 16, 12, 13], ["+", 75, 76, 0, 57, 15, 23, 0, 16, 12, 13]]
| 0
| 226
| 12
|
#include <stdio.h>
int main(void) {
while (1) {
int n;
scanf("%d", &n);
if (n == 0)
break;
int i, a[n];
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
int p = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0;
for (i = 0; i < n; i++) {
if (a[i] < 10) {
p++;
} else if (a[i] <= 10 && a[i] < 20) {
b++;
} else if (a[i] <= 20 && a[i] < 30) {
c++;
} else if (a[i] <= 30 && a[i] < 40) {
d++;
} else if (a[i] <= 40 && a[i] < 50) {
e++;
} else if (a[i] <= 50 && a[i] < 60) {
f++;
} else {
g++;
}
}
printf("%d\n", p);
printf("%d\n", b);
printf("%d\n", c);
printf("%d\n", d);
printf("%d\n", e);
printf("%d\n", f);
printf("%d\n", g);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
while (1) {
int n;
scanf("%d", &n);
if (n == 0)
break;
int i, a[n];
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
int p = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0;
for (i = 0; i < n; i++) {
if (a[i] < 10) {
p++;
} else if (a[i] >= 10 && a[i] < 20) {
b++;
} else if (a[i] >= 20 && a[i] < 30) {
c++;
} else if (a[i] >= 30 && a[i] < 40) {
d++;
} else if (a[i] >= 40 && a[i] < 50) {
e++;
} else if (a[i] >= 50 && a[i] < 60) {
f++;
} else {
g++;
}
}
printf("%d\n", p);
printf("%d\n", b);
printf("%d\n", c);
printf("%d\n", d);
printf("%d\n", e);
printf("%d\n", f);
printf("%d\n", g);
}
return 0;
}
|
[["-", 0, 57, 15, 23, 0, 16, 31, 16, 17, 19], ["+", 0, 57, 15, 23, 0, 16, 31, 16, 17, 20]]
| 0
| 319
| 10
|
a[7], n;
main(b) {
for (; scanf("%d", &n) && n; memset(a, 0, 28)) {
for (; n--; b /= 10, a[b > 6 ? 6 : b])
scanf("%d", &b);
for (; ++n < 7; printf("%d\n", a[n]))
;
}
}
|
a[7], n;
main(b) {
for (; scanf("%d", &n) && n; memset(a, 0, 28)) {
for (; n--; b /= 10, a[b > 6 ? 6 : b]++)
scanf("%d", &b);
for (; ++n < 7; printf("%d\n", a[n]))
;
}
}
|
[["+", 8, 9, 0, 7, 26, 34, 12, 27, 17, 29]]
| 0
| 92
| 1
|
#include <stdio.h>
int main(void) {
int x[7], n, a, i;
while (scanf("%d", &n) != EOF) {
for (i = 0; i < 7; i++)
x[i] = 0;
for (i = 0; i < n; i++) {
scanf("%d", &a);
if (a < 10)
x[0]++;
else if (10 <= a && a < 20)
x[1]++;
else if (20 <= a && a < 30)
x[2]++;
else if (30 <= a && a < 40)
x[3]++;
else if (40 <= a && a < 50)
x[4]++;
else if (50 <= a && a < 60)
x[5]++;
else if (60 <= a)
x[6]++;
}
for (i = 0; i < 7; i++)
printf("%d\n", x[i]);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int x[7], n, a, i;
while (scanf("%d", &n), n) {
for (i = 0; i < 7; i++)
x[i] = 0;
for (i = 0; i < n; i++) {
scanf("%d", &a);
if (a < 10)
x[0]++;
else if (10 <= a && a < 20)
x[1]++;
else if (20 <= a && a < 30)
x[2]++;
else if (30 <= a && a < 40)
x[3]++;
else if (40 <= a && a < 50)
x[4]++;
else if (50 <= a && a < 60)
x[5]++;
else if (60 <= a)
x[6]++;
}
for (i = 0; i < 7; i++)
printf("%d\n", x[i]);
}
return 0;
}
|
[["-", 8, 9, 0, 52, 15, 23, 0, 16, 17, 79], ["-", 8, 9, 0, 52, 15, 23, 0, 16, 12, 22], ["+", 8, 9, 0, 52, 15, 23, 0, 34, 0, 21], ["+", 8, 9, 0, 52, 15, 23, 0, 34, 12, 22]]
| 0
| 221
| 4
|
a[7];
main(x, n) {
for (; scanf("%d", &n), n;) {
for (memset(a, 0, 28); n--;)
scanf("%d", &x), x > 60 ? a[6]++ : a[x / 10]++;
for (x = 0; x < 8; x++)
printf("%d\n", a[x]);
}
exit(0);
}
|
a[7];
main(x, n) {
for (; scanf("%d", &n), n;) {
for (memset(a, 0, 28); n--;)
scanf("%d", &x), x > 60 ? a[6]++ : a[x / 10]++;
for (x = 0; x < 7; x++)
printf("%d\n", a[x]);
}
exit(0);
}
|
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13]]
| 0
| 106
| 2
|
#include <iostream>
using namespace std;
int main() {
int n, in;
int i;
while (cin >> n && n != '0') {
int k[7] = {0};
for (i = 0; i < n; i++) {
cin >> in;
if (in > 60)
in = 60;
(k[in / 10])++;
}
for (i = 0; i < 7; i++) {
cout << k[i] << endl;
}
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int n, in;
int i;
while (cin >> n && n != 0) {
int k[7] = {0};
for (i = 0; i < n; i++) {
cin >> in;
if (in > 60)
in = 60;
(k[in / 10])++;
}
for (i = 0; i < 7; i++) {
cout << k[i] << endl;
}
}
return 0;
}
|
[["-", 15, 339, 51, 16, 12, 16, 12, 103, 0, 104]]
| 1
| 110
| 2
|
#include <iostream>
using namespace std;
int judge(int);
int main() {
int n, age;
for (;;) {
int cnt[7] = {0};
cin >> n;
if (n == 0)
break;
for (int i = 0; i < n; i++) {
cin >> age;
cnt[judge(age)]++;
}
for (int i = 0; i < 7; i++)
cout << cnt[i] << endl;
}
return 0;
}
int judge(int age) { return age / 10; }
|
#include <iostream>
using namespace std;
int judge(int);
int main() {
int n, age;
for (;;) {
int cnt[7] = {0};
cin >> n;
if (n == 0)
break;
for (int i = 0; i < n; i++) {
cin >> age;
cnt[judge(age)]++;
}
for (int i = 0; i < 7; i++)
cout << cnt[i] << endl;
}
return 0;
}
int judge(int age) { return min(age / 10, 6); }
|
[["+", 0, 14, 8, 9, 0, 37, 0, 2, 63, 22], ["+", 8, 9, 0, 37, 0, 2, 3, 4, 0, 24], ["+", 8, 9, 0, 37, 0, 2, 3, 4, 0, 21], ["+", 8, 9, 0, 37, 0, 2, 3, 4, 0, 13], ["+", 8, 9, 0, 37, 0, 2, 3, 4, 0, 25]]
| 1
| 120
| 5
|
// aoj0184
#include <iostream>
using namespace std;
int main() {
int n;
while (cin >> n, n) {
int agenum[7] = {};
for (int i = 0; i < n; i++) {
int a;
cin >> a;
if (a < 10) {
agenum[0] += 1;
} else if (a < 20) {
agenum[1] += 1;
} else if (a < 30) {
agenum[2] += 1;
} else if (a < 40) {
agenum[3] += 1;
} else if (a < 50) {
agenum[4] += 1;
} else if (a < 60) {
agenum[5] += 1;
} else {
agenum[6] += 1;
}
}
for (int i = 0; i < 7; i++) {
cout << agenum[i] << endl;
}
return 0;
}
}
|
// aoj0184
#include <iostream>
using namespace std;
int main() {
int n;
while (cin >> n, n) {
int agenum[7] = {};
for (int i = 0; i < n; i++) {
int a;
cin >> a;
if (a < 10) {
agenum[0] += 1;
} else if (a < 20) {
agenum[1] += 1;
} else if (a < 30) {
agenum[2] += 1;
} else if (a < 40) {
agenum[3] += 1;
} else if (a < 50) {
agenum[4] += 1;
} else if (a < 60) {
agenum[5] += 1;
} else {
agenum[6] += 1;
}
}
for (int i = 0; i < 7; i++) {
cout << agenum[i] << endl;
}
}
return 0;
}
|
[["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46], ["-", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
| 1
| 191
| 2
|
#include <algorithm>
#include <complex>
#include <cstdio>
#include <functional>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
int cnt[7];
int main() {
int i, n, p;
while (cin >> n && n) {
for (i = 0; i < 7; i++)
cnt[7] = 0;
for (i = 0; i < n; i++) {
cin >> p;
if (p < 10)
cnt[0]++;
else if (p < 20)
cnt[1]++;
else if (p < 30)
cnt[2]++;
else if (p < 40)
cnt[3]++;
else if (p < 50)
cnt[4]++;
else if (p < 60)
cnt[5]++;
else
cnt[6]++;
}
for (i = 0; i < 7; i++)
cout << cnt[i] << endl;
}
return 0;
}
|
#include <algorithm>
#include <complex>
#include <cstdio>
#include <functional>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
int cnt[7];
int main() {
int i, n, p;
while (cin >> n && n) {
for (i = 0; i < 7; i++)
cnt[i] = 0;
for (i = 0; i < n; i++) {
cin >> p;
if (p < 10)
cnt[0]++;
else if (p < 20)
cnt[1]++;
else if (p < 30)
cnt[2]++;
else if (p < 40)
cnt[3]++;
else if (p < 50)
cnt[4]++;
else if (p < 60)
cnt[5]++;
else
cnt[6]++;
}
for (i = 0; i < 7; i++)
cout << cnt[i] << endl;
}
return 0;
}
|
[["-", 8, 1, 0, 11, 31, 69, 341, 342, 0, 13], ["+", 8, 1, 0, 11, 31, 69, 341, 342, 0, 22]]
| 1
| 206
| 2
|
#include <iostream>
using namespace std;
int m, n;
int p[7];
int main() {
cin >> n;
if (!n)
return 0;
for (int i = 0; i < 7; i++)
p[i] = 0;
for (int i = 0; i < n; i++) {
cin >> m;
if (m >= 70)
m = 60;
p[m / 10]++;
}
for (int i = 0; i < 7; i++)
cout << p[i] << endl;
}
|
#include <iostream>
using namespace std;
int m, n;
int p[7];
int main() {
while (true) {
cin >> n;
if (!n)
return 0;
for (int i = 0; i < 7; i++)
p[i] = 0;
for (int i = 0; i < n; i++) {
cin >> m;
if (m >= 70)
m = 60;
p[m / 10]++;
}
for (int i = 0; i < 7; i++)
cout << p[i] << endl;
}
}
|
[["+", 0, 30, 0, 14, 8, 9, 0, 52, 0, 89], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 24], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 51, 146], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
| 1
| 117
| 6
|
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);
int N = 1000000;
boolean[] primes = new boolean[N + 1];
primes[0] = true;
primes[1] = true;
for (int i = 2; i <= Math.sqrt(N); i++) {
if (!primes[i]) {
for (int j = i * 2; j <= N; j += i) {
primes[j] = true;
}
}
}
while (true) {
int n = scanner.nextInt();
if (n == 0)
break;
int count = 0;
for (int i = n; i >= n / 2; i -= 2) {
if (!primes[i - 1] && !primes[n - i + 1]) {
count++;
}
}
System.out.println(count);
}
}
}
|
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);
int N = 1000000;
boolean[] primes = new boolean[N + 1];
primes[0] = true;
primes[1] = true;
for (int i = 2; i <= Math.sqrt(N); i++) {
if (!primes[i]) {
for (int j = i * 2; j <= N; j += i) {
primes[j] = true;
}
}
}
while (true) {
int n = scanner.nextInt();
if (n == 0)
break;
int count = 0;
for (int i = n - 1; i >= n / 2; i -= 2) {
if (!primes[i] && !primes[n - i]) {
count++;
}
}
System.out.println(count);
}
}
}
|
[["+", 0, 7, 502, 503, 49, 200, 51, 16, 17, 33], ["+", 0, 7, 502, 503, 49, 200, 51, 16, 12, 499], ["-", 0, 16, 31, 91, 439, 504, 71, 16, 17, 33], ["-", 0, 16, 31, 91, 439, 504, 71, 16, 12, 499], ["-", 0, 16, 12, 91, 439, 504, 71, 16, 17, 72], ["-", 0, 16, 12, 91, 439, 504, 71, 16, 12, 499]]
| 3
| 221
| 6
|
def f(n, ans):
for k, c in list(dic.items()):
a, b = k
if a == n:
if not b in cost or c < cost[b]:
cost[b] = c
elif b == n:
if not a in cost or c < cost[a]:
cost[a] = c
for k, c in sorted(list(cost.items()), key=lambda x: x[1]):
if not k in res:
res.append(k)
ans += c
del dic[k]
return f(k, ans)
return ans
while True:
n, m = list(map(int, input().split()))
if n == m == 0: break
dic = {}
s, b, c = list(map(int, input().split()))
dic[(s, b)] = c
for i in range(m-1):
a, b, c = list(map(int, input().split()))
dic[(a, b)] = c
cost = {}
res = [s]
print(f(s, 0))
|
def f(n, ans):
for k, c in list(dic.items()):
a, b = k
if a == n:
if not b in cost or c < cost[b]:
cost[b] = c
elif b == n:
if not a in cost or c < cost[a]:
cost[a] = c
for k, c in sorted(list(cost.items()), key=lambda x: x[1]):
if not k in res:
res.append(k)
ans += c
del cost[k]
return f(k, ans)
return ans
while True:
n, m = list(map(int, input().split()))
if n == m == 0: break
dic = {}
s, b, c = list(map(int, input().split()))
dic[(s, b)] = c
for i in range(m-1):
a, b, c = list(map(int, input().split()))
dic[(a, b)] = c
cost = {}
res = [s]
print(f(s, 0))
|
[["-", 0, 57, 64, 196, 0, 688, 0, 206, 51, 22], ["+", 0, 57, 64, 196, 0, 688, 0, 206, 51, 22]]
| 5
| 255
| 2
|
def f(s, cost, route, ans):
route.append(s)
ans += cost[s]
del cost[s]
for k, c in list(data.items()):
if s in k:
a, b = k
b = b if s == a else a
if not b in route:
if not b in cost or c < cost[b]:
cost[b] = c
if cost:
s = sorted(list(cost.items()), key=lambda x: x[1])[0][0]
return f(s, cost, route, ans)
else:
return ans
while True:
n, m = list(map(int, input().split()))
if n == m == 0: break
data = {}
for i in range(m):
a, b, c = list(map(int, input().split()))
data[(a, b)] = c
else:
print(f(0, {0:0}, [], 0))
|
def f(s, cost, route, ans):
route.append(s)
ans += cost[s]
del cost[s]
for k, c in list(data.items()):
if s in k:
a, b = k
b = b if s == a else a
if not b in route:
if not b in cost or c < cost[b]:
cost[b] = c
if cost:
s = sorted(list(cost.items()), key=lambda x: x[1])[0][0]
return f(s, cost, route, ans)
return ans
while True:
n, m = list(map(int, input().split()))
if n == m == 0: break
data = {}
for i in range(m):
a, b, c = list(map(int, input().split()))
data[(a, b)] = c
print(f(0, {0:0}, [], 0))
|
[["-", 0, 14, 8, 196, 0, 57, 75, 76, 0, 95], ["-", 0, 14, 8, 196, 0, 57, 75, 76, 0, 102], ["-", 0, 52, 8, 196, 0, 7, 75, 76, 0, 95], ["-", 0, 52, 8, 196, 0, 7, 75, 76, 0, 102]]
| 5
| 227
| 4
|
#include <stdio.h>
int n, m, d[110];
int f(int l, int r) { // printf("%d %d ",l,r);
if (r - l < 1)
return l;
int mid = (l + r) / 2, c = 1, i, s = 0;
for (i = 0; i < n; i++) {
if (s + d[i] > mid) {
s = 0;
c++;
}
s += d[i];
if (mid < d[i]) {
c = 100;
break;
}
} // printf("%d\n",c);
return c > m ? f(mid + 1, r) : f(l, mid);
}
int main() {
int i;
while (scanf("%d %d", &m, &n), m || n) {
for (i = 0; i < n; i++)
scanf("%d", &d[i]);
printf("%d\n", f(0, 2000));
}
return 0;
}
|
#include <stdio.h>
int n, m, d[110];
int f(int l, int r) { // printf("%d %d ",l,r);
if (r - l < 1)
return l;
int mid = (l + r) / 2, c = 1, i, s = 0;
for (i = 0; i < n; i++) {
if (s + d[i] > mid) {
s = 0;
c++;
}
s += d[i];
if (mid < d[i]) {
c = 1000;
break;
}
} // printf("%d\n",c);
return c > m ? f(mid + 1, r) : f(l, mid);
}
int main() {
int i;
while (scanf("%d %d", &m, &n), m || n) {
for (i = 0; i < n; i++)
scanf("%d", &d[i]);
printf("%d\n", f(0, 1500000));
}
return 0;
}
|
[["-", 0, 57, 64, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 13], ["-", 0, 2, 3, 4, 0, 2, 3, 4, 0, 13], ["+", 0, 2, 3, 4, 0, 2, 3, 4, 0, 13]]
| 0
| 211
| 4
|
#include <iostream>
using namespace std;
int main() {
int n, m;
while (1) {
cin >> n >> m;
if (n == 0 && m == 0) {
break;
}
int hon[150];
for (int i = 0; i < m; i++) {
cin >> hon[i];
}
int right, left;
right = left = 0;
for (int i = 0; i < m; i++) {
left += hon[i];
}
while (1) {
double h = (double)(left + right) / 2;
// printf("%d %d %lf\n",right,left,h);
int ans = 0;
int now = 0;
int dan = 1;
for (int i = 0; i < m; i++) {
if (now + hon[i] > h) {
if (now == 0) {
dan = 100000;
break;
}
now = 0;
dan++;
i--;
continue;
}
now += hon[i];
}
// printf("%lf zi dan = %d\n",h,dan);
if (dan <= n) {
ans = 1;
}
if (ans == 1) {
left = h + 0.499;
} else {
right = h;
}
if ((int)left == (int)right + 1) {
printf("%d\n", (int)h);
break;
}
}
}
}
|
#include <iostream>
using namespace std;
int main() {
int n, m;
while (1) {
cin >> n >> m;
if (n == 0 && m == 0) {
break;
}
int hon[150];
for (int i = 0; i < m; i++) {
cin >> hon[i];
}
int right, left;
right = left = 0;
for (int i = 0; i < m; i++) {
left += hon[i];
}
while (1) {
double h = (double)(left + right) / 2;
// printf("%d %d %lf\n",right,left,h);
int ans = 0;
int now = 0;
int dan = 1;
for (int i = 0; i < m; i++) {
if (now + hon[i] > h) {
if (now == 0) {
dan = 100000;
break;
}
now = 0;
dan++;
i--;
continue;
}
now += hon[i];
}
// printf("%lf zi dan = %d\n",h,dan);
if (dan <= n) {
ans = 1;
}
if (ans == 1) {
left = h + 0.499;
} else {
right = h;
}
if ((int)left == (int)right + 1) {
printf("%d\n", left);
break;
}
}
}
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 74, 0, 24], ["-", 0, 2, 3, 4, 0, 74, 39, 77, 39, 40], ["-", 0, 1, 0, 2, 3, 4, 0, 74, 0, 25], ["-", 0, 1, 0, 2, 3, 4, 0, 74, 51, 22], ["+", 64, 9, 0, 1, 0, 2, 3, 4, 0, 22]]
| 1
| 269
| 5
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define f first
#define s second
int main() {
while (1) {
int n, m;
cin >> n >> m;
if (n == 0)
break;
int hon[111];
rep(i, m) { cin >> hon[i]; }
double left = 0;
double right = 15000001;
while (1) {
double h = (left + right) / 2;
int dan = 0;
int now = 0;
rep(i, m) {
if (now + hon[i] > h) {
now = 0;
i--;
dan++;
} else {
now += hon[i];
}
if (dan > n)
break;
}
if (dan > n) {
left = h;
} else {
right = h;
}
if (right - left < 0.0001) {
printf("%d\n", (int)(right + 0.001));
break;
}
}
}
}
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define f first
#define s second
int main() {
while (1) {
int n, m;
cin >> n >> m;
if (n == 0)
break;
int hon[111];
rep(i, m) { cin >> hon[i]; }
double left = 0;
double right = 15000001;
while (1) {
double h = (left + right) / 2;
int dan = 1;
int now = 0;
rep(i, m) {
if (now + hon[i] > h) {
now = 0;
i--;
dan++;
} else {
now += hon[i];
}
if (dan > n)
break;
}
if (dan > n) {
left = h;
} else {
right = h;
}
if (right - left < 0.0001) {
printf("%d\n", (int)(right + 0.001));
break;
}
}
}
}
|
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
| 1
| 224
| 2
|
#include <stdio.h>
int m, n, a[100];
bool check(int x) {
int pos = 0, r = 0;
for (int i = 0; i < m; i++) {
while (pos != n && r + a[pos] <= x)
r += a[pos++];
if (pos == n)
return true;
r = 0;
}
return false;
}
int main() {
while (scanf("%d%d", &m, &n), n) {
for (int i = 0; i < n; i++)
scanf("%d", &a[i]);
int l = 0, r = 1000000000;
while (r - l > 1) {
int m = (l + r) / 2;
if (check(m))
l = m;
else
r = m;
}
printf("%d\n", r);
}
}
|
#include <stdio.h>
int m, n, a[100];
bool check(int x) {
int pos = 0, r = 0;
for (int i = 0; i < m; i++) {
while (pos != n && r + a[pos] <= x)
r += a[pos++];
if (pos == n)
return true;
r = 0;
}
return false;
}
int main() {
while (scanf("%d%d", &m, &n), n) {
for (int i = 0; i < n; i++)
scanf("%d", &a[i]);
int l = 0, r = 1000000000;
while (r - l > 1) {
int m = (l + r) / 2;
if (check(m))
r = m;
else
l = m;
}
printf("%d\n", r);
}
}
|
[["-", 8, 9, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 8, 9, 0, 57, 64, 1, 0, 11, 31, 22], ["-", 0, 57, 75, 76, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 75, 76, 0, 1, 0, 11, 31, 22]]
| 1
| 192
| 4
|
#include <iostream>
using namespace std;
int m, n;
int a[1000];
bool check(int v) {
int cnt = 0, s = 0;
for (int i = 0; i < n; i++) {
if (a[i] > v)
return false;
}
for (int i = 0; i < n; i++) {
if (s + a[i] > v) {
cnt++;
s = a[i];
} else {
s += a[i];
}
}
if (cnt > m)
return false;
return true;
}
int main() {
while (true) {
cin >> m >> n;
if (m == 0 && n == 0) {
break;
}
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int L = 0, R = 100000000, M;
for (int i = 0; i < 50; i++) {
M = (L + R) / 2;
bool r1 = check(M - 1);
bool r2 = check(M);
if (r1 == true)
R = M;
if (r2 == false) {
L = M;
}
}
cout << M << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int m, n;
int a[1000];
bool check(int v) {
int cnt = 0, s = 1000000000;
for (int i = 0; i < n; i++) {
if (a[i] > v)
return false;
}
for (int i = 0; i < n; i++) {
if (s + a[i] > v) {
cnt++;
s = a[i];
} else {
s += a[i];
}
}
if (cnt > m)
return false;
return true;
}
int main() {
while (true) {
cin >> m >> n;
if (m == 0 && n == 0) {
break;
}
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int L = 0, R = 100000000, M;
for (int i = 0; i < 50; i++) {
M = (L + R) / 2;
bool r1 = check(M - 1);
bool r2 = check(M);
if (r1 == true)
R = M;
if (r2 == false) {
L = M;
}
}
cout << M << endl;
}
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13]]
| 1
| 264
| 2
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int m, n;
while (cin >> m >> n, m, n) {
int w[110];
int f = 0;
for (int i = 0; i < n; i++) {
cin >> w[i];
f = max(w[i], f);
}
while (1) {
int p = 1, q = f;
for (int i = 0; i < n; i++) {
if (w[i] <= q)
q -= w[i];
else {
p++;
q = f - w[i];
}
}
if (p <= m)
break;
f += 100;
}
cout << f << endl;
}
}
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int m, n;
while (cin >> m >> n, m, n) {
int w[110];
int f = 0;
for (int i = 0; i < n; i++) {
cin >> w[i];
f = max(w[i], f);
}
while (1) {
int p = 1, q = f;
for (int i = 0; i < n; i++) {
if (w[i] <= q)
q -= w[i];
else {
p++;
q = f - w[i];
}
}
if (p <= m)
break;
f++;
}
cout << f << endl;
}
}
|
[["-", 0, 52, 8, 9, 0, 1, 0, 11, 17, 107], ["-", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 52, 8, 9, 0, 1, 0, 27, 17, 29]]
| 1
| 159
| 3
|
#include <cstdio>
#include <cstring> // require memset
#include <fstream> // require freopen
#include <iostream>
using namespace std;
const int MaxW = 1500000;
int m,
n; // {IÌi 1
m
20, {̪ 1
n
100
int w[100];
bool calc_m(int curr_w) {
int l[20];
memset(l, 0, sizeof(l));
int j = 0;
for (int i = 0; i < n; i++) {
if (l[j] + w[i] > curr_w)
j++;
if (j == m)
return false;
l[j] += w[i];
} // end for
return true;
}
int main() {
// cut here before submit
// freopen ("testcase.persistence", "r", stdin );
for (;;) { // {IÌ ans
1500000
scanf("%d%d", &m, &n);
if (!m)
break;
memset(w, 0, sizeof(w));
for (int i = 0; i < n; i++) {
scanf("%d", w + i);
} // end for
int l = w[0];
int r = MaxW;
int mid = 0;
int res = MaxW;
while (l <= r) {
mid = (l + r) / 2;
if (calc_m(mid)) {
res = min(res, mid);
r = mid - 1;
} else {
l = mid + 1;
} // end if
} // end while
cout << res << endl;
} // end loop
return 0;
}
|
#include <cstdio>
#include <cstring> // require memset
#include <fstream> // require freopen
#include <iostream>
using namespace std;
const int MaxW = 1500000;
int m,
n; // {IÌi 1
m
20, {̪ 1
n
100
int w[100];
bool calc_m(int curr_w) {
int l[20];
memset(l, 0, sizeof(l));
int j = 0;
for (int i = 0; i < n; i++) {
while (j < m && l[j] + w[i] > curr_w)
j++;
if (j == m)
return false;
l[j] += w[i];
} // end for
return true;
}
int main() {
// cut here before submit
// freopen ("testcase.persistence", "r", stdin );
for (;;) { // {IÌ ans
1500000
scanf("%d%d", &m, &n);
if (!m)
break;
memset(w, 0, sizeof(w));
for (int i = 0; i < n; i++) {
scanf("%d", w + i);
} // end for
int l = w[0];
int r = MaxW;
int mid = 0;
int res = MaxW;
while (l <= r) {
mid = (l + r) / 2;
if (calc_m(mid)) {
res = min(res, mid);
r = mid - 1;
} else {
l = mid + 1;
} // end if
} // end while
cout << res << endl;
} // end loop
return 0;
}
|
[["-", 8, 9, 0, 7, 8, 9, 0, 57, 0, 121], ["+", 8, 9, 0, 7, 8, 9, 0, 52, 0, 89], ["+", 0, 52, 15, 339, 51, 16, 31, 16, 31, 22], ["+", 0, 52, 15, 339, 51, 16, 31, 16, 17, 18], ["+", 0, 52, 15, 339, 51, 16, 31, 16, 12, 22], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 98]]
| 1
| 281
| 6
|
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
vector<int> books;
int m, n;
bool judge(int obs) {
int sum = 0;
int cont = 1;
for (int i = 0; i < books.size(); i++) {
if (books[i] > obs)
return false;
if (sum + books[i] > obs) {
cont++;
sum = 0;
}
sum += books[i];
}
return ((m >= cont) ? true : false);
}
int main() {
int c;
while (cin >> m >> n) {
if (m == 0 && n == 0)
break;
for (int i = 0; i < n; i++) {
cin >> c;
books.push_back(c);
}
int ub = 1500000, lb = 0;
while (ub - lb > 1) {
int mid = (ub + lb) / 2;
if (judge(mid)) {
ub = mid;
} else {
lb = mid;
}
}
cout << ub << endl;
}
}
|
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
vector<int> books;
int m, n;
bool judge(int obs) {
int sum = 0;
int cont = 1;
for (int i = 0; i < books.size(); i++) {
if (books[i] > obs)
return false;
if (sum + books[i] > obs) {
cont++;
sum = 0;
}
sum += books[i];
}
return ((m >= cont) ? true : false);
}
int main() {
int c;
while (cin >> m >> n) {
if (m == 0 && n == 0)
break;
for (int i = 0; i < n; i++) {
cin >> c;
books.push_back(c);
}
int ub = 1500000, lb = 0;
while (ub - lb > 1) {
int mid = (ub + lb) / 2;
if (judge(mid)) {
ub = mid;
} else {
lb = mid;
}
}
cout << ub << endl;
books.clear();
}
}
|
[["+", 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
| 225
| 6
|
#include <iostream>
#include <vector>
using namespace std;
int n, m;
vector<int> v;
bool f(int sz) {
int temp = sz;
int ret = 1;
for (int i = 0; i < m; i++) {
if (sz - v[i] >= 0) {
sz -= v[i];
} else {
ret++;
sz = temp - v[i];
}
}
return ret <= n;
}
int main() {
while (cin >> n >> m, n || m) {
v = vector<int>(m);
int l = 1000000000, r = 0;
for (int i = 0; i < m; i++) {
cin >> v[i];
r += v[i];
l = min(l, v[i]);
}
while (r > l) {
int mid = (l + r) / 2;
if (f(mid)) {
r = mid;
} else {
l = mid + 1;
}
}
cout << r << endl;
}
return 0;
}
|
#include <iostream>
#include <vector>
using namespace std;
int n, m;
vector<int> v;
bool f(int sz) {
int temp = sz;
int ret = 1;
for (int i = 0; i < m; i++) {
if (sz - v[i] >= 0) {
sz -= v[i];
} else {
ret++;
sz = temp - v[i];
}
}
return ret <= n;
}
int main() {
while (cin >> n >> m, n || m) {
v = vector<int>(m);
int l = 0, r = 0;
for (int i = 0; i < m; i++) {
cin >> v[i];
r += v[i];
l = max(l, v[i]);
}
while (r > l) {
int mid = (l + r) / 2;
if (f(mid)) {
r = mid;
} else {
l = mid + 1;
}
}
cout << r << endl;
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["-", 8, 9, 0, 1, 0, 11, 12, 2, 63, 22], ["+", 8, 9, 0, 1, 0, 11, 12, 2, 63, 22]]
| 1
| 224
| 4
|
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define all(c) ((c).begin()), ((c).end())
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define mp make_pair
#define fst first
#define snd second
#define pb push_back
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int INF = 1 << 29;
const double EPS = 1e-10;
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
return os << '(' << p.first << ',' << p.second << ')';
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &a) {
os << '[';
rep(i, a.size()) os << (i ? " " : "") << a[i];
return os << ']';
}
int main() {
for (int m, n; cin >> m >> n, (m | n) != 0;) {
int bs[100];
rep(i, n) cin >> bs[i];
int lb = 0, ub = 1500001;
while (ub - lb > 1) {
int mid = (ub + lb) / 2;
int c = 1;
int l = 0;
bool suc = true;
rep(i, n) {
if (l + bs[i] > mid) {
if (c == m || l == 0) {
suc = false;
break;
}
c++;
l = bs[i];
} else {
l += bs[i];
}
}
if (suc)
ub = mid;
else
lb = mid;
}
cout << ub << endl;
}
return 0;
}
|
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define all(c) ((c).begin()), ((c).end())
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define mp make_pair
#define fst first
#define snd second
#define pb push_back
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int INF = 1 << 29;
const double EPS = 1e-10;
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
return os << '(' << p.first << ',' << p.second << ')';
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &a) {
os << '[';
rep(i, a.size()) os << (i ? " " : "") << a[i];
return os << ']';
}
int main() {
for (int m, n; cin >> m >> n, (m | n) != 0;) {
int bs[100];
rep(i, n) cin >> bs[i];
int lb = 0, ub = 1500001;
while (ub - lb > 1) {
int mid = (ub + lb) / 2;
int c = 1;
int l = 0;
bool suc = true;
rep(i, n) {
if (l + bs[i] > mid) {
if (c == m || bs[i] > mid) {
suc = false;
break;
}
c++;
l = bs[i];
} else {
l += bs[i];
}
}
if (suc)
ub = mid;
else
lb = mid;
}
cout << ub << endl;
}
return 0;
}
|
[["-", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 60], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13], ["+", 15, 339, 51, 16, 12, 16, 31, 69, 28, 22], ["+", 51, 16, 12, 16, 31, 69, 341, 342, 0, 70], ["+", 51, 16, 12, 16, 31, 69, 341, 342, 0, 22], ["+", 51, 16, 12, 16, 31, 69, 341, 342, 0, 73], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 47], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22]]
| 1
| 459
| 9
|
#include <bits/stdc++.h>
using namespace std;
int main() {
for (int m, n; cin >> m >> n && (m | n);) {
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
int l = *min_element(a.begin(), a.end()), r = 1500001;
while (r - l > 1) {
int mid = (l + r) / 2;
int x = 0, y = 1;
for (int i = 0; i < n; ++i) {
if (x + a[i] > mid) {
x = a[i];
++y;
} else {
x += a[i];
}
}
if (y <= m) {
r = mid;
} else {
l = mid + 1;
}
}
cout << l << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
for (int m, n; cin >> m >> n && (m | n);) {
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
int l = *max_element(a.begin(), a.end()), r = 1500001;
while (r - l) {
int mid = (l + r) / 2;
int x = 0, y = 1;
for (int i = 0; i < n; ++i) {
if (x + a[i] > mid) {
x = a[i];
++y;
} else {
x += a[i];
}
}
if (y <= m) {
r = mid;
} else {
l = mid + 1;
}
}
cout << l << endl;
}
return 0;
}
|
[["-", 0, 43, 49, 50, 51, 66, 28, 2, 63, 22], ["+", 0, 43, 49, 50, 51, 66, 28, 2, 63, 22], ["-", 8, 9, 0, 52, 15, 339, 51, 16, 17, 47], ["-", 8, 9, 0, 52, 15, 339, 51, 16, 12, 13]]
| 1
| 198
| 4
|
#include <algorithm>
#include <iostream>
using namespace std;
int n;
int a[50];
bool b[50];
bool pourAll(int p);
bool pour(int p, int q, int rest) {
if (!rest) {
return pourAll(p + 1);
}
if (q == n) {
return false;
}
if (!b[q] && a[q] <= rest) {
b[q] = true;
if (pour(p, q + 1, rest - a[q])) {
return true;
}
b[q] = false;
}
return pour(p, q + 1, rest);
}
bool pourAll(int p) {
if (p == n - 1) {
return true;
}
if (!b[p]) {
return false;
}
if (pour(p, p + 1, a[p])) {
return true;
}
return pourAll(p + 1);
}
bool solve() {
sort(a, a + n, greater<int>());
b[0] = true;
for (int i = 1; i < n; i++) {
b[i] = false;
}
return pourAll(0);
}
int main() {
bool ans;
while (1) {
cin >> n;
if (!n) {
break;
}
for (int i = 0; i < n; i++) {
cin >> a[i];
}
ans = solve();
cout << (ans ? "YES" : "NO") << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
int n;
int a[50];
bool b[50];
bool pourAll(int p);
bool pour(int p, int q, int rest) {
if (!rest) {
return pourAll(p + 1);
}
if (q == n) {
return false;
}
if (!b[q] && a[q] <= rest) {
b[q] = true;
if (pour(p, q + 1, rest - a[q])) {
return true;
}
b[q] = false;
}
return pour(p, q + 1, rest);
}
bool pourAll(int p) {
if (p == n) {
return true;
}
if (!b[p]) {
return false;
}
if (pour(p, p + 1, a[p])) {
return true;
}
return pourAll(p + 1);
}
bool solve() {
sort(a, a + n, greater<int>());
b[0] = true;
for (int i = 1; i < n; i++) {
b[i] = false;
}
return pourAll(0);
}
int main() {
bool ans;
while (1) {
cin >> n;
if (!n) {
break;
}
for (int i = 0; i < n; i++) {
cin >> a[i];
}
ans = solve();
cout << (ans ? "YES" : "NO") << endl;
}
return 0;
}
|
[["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 33], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
| 1
| 333
| 2
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
bool dfs(int i);
int n, a[50];
bool fil[50];
bool dfs2(int i, int j, int rem) {
if (rem == 0)
return dfs(i + 1);
if (j == n)
return false;
if (!fil[j] && a[j] <= rem) {
fil[j] = true;
if (dfs2(i, j + 1, rem - a[j]))
return true;
fil[j] = false;
}
return dfs2(i, j + 1, rem);
}
bool dfs(int i) {
if (i == n)
return true;
if (!fil[i])
return false;
return dfs2(i, i + 1, a[i]) || dfs(i + 1);
}
int main() {
for (; scanf("%d", &n), n;) {
rep(i, n) {
scanf("%d", a[i]);
fil[i] = false;
}
sort(a, a + n, greater<int>());
fil[0] = true;
puts(dfs(0) ? "YES" : "NO");
}
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
bool dfs(int i);
int n, a[50];
bool fil[50];
bool dfs2(int i, int j, int rem) {
if (rem == 0)
return dfs(i + 1);
if (j == n)
return false;
if (!fil[j] && a[j] <= rem) {
fil[j] = true;
if (dfs2(i, j + 1, rem - a[j]))
return true;
fil[j] = false;
}
return dfs2(i, j + 1, rem);
}
bool dfs(int i) {
if (i == n)
return true;
if (!fil[i])
return false;
return dfs2(i, i + 1, a[i]) || dfs(i + 1);
}
int main() {
for (; scanf("%d", &n), n;) {
rep(i, n) {
scanf("%d", a + i);
fil[i] = false;
}
sort(a, a + n, greater<int>());
fil[0] = true;
puts(dfs(0) ? "YES" : "NO");
}
return 0;
}
|
[["-", 0, 2, 3, 4, 0, 69, 341, 342, 0, 70], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 72], ["-", 0, 2, 3, 4, 0, 69, 341, 342, 0, 73]]
| 1
| 279
| 3
|
#include <iostream>
using namespace std;
int search(int s);
int num[50], a[50], u[50], d[51], n, g;
int fnd(int v, int t, int s, int k) {
int i, j, w = -1;
if (k == 0) {
j = a[v];
a[v] = 0;
if (g == n || search(s + 1) == 1)
return 1;
a[v] = j;
return 0;
}
if (k > d[s] || t == n - 1)
return 0;
for (i = s; i < n; i++) {
if (u[i] == 0 && a[i] != w && k - a[i] >= 0) {
u[i] = 1;
g++;
if (fnd(v, t, i + 1, k - a[i]) == 1)
return 1;
u[i] = 0;
g--;
w = a[i];
}
}
return 0;
}
int search(int s) {
int i, k;
if (g == n)
return 1;
while (u[s] == 1 && s < n)
s++;
if (s == n)
return 0;
for (i = 0; i < s; i++)
if (a[i] >= a[s]) {
a[i] -= a[s];
g++;
if (a[i] == 0) {
u[s] = 1;
k = search(s + 1);
} else
k = fnd(i, s, s + 1, a[i]);
if (k == 1)
return 1;
else {
a[i] += a[s];
u[s] = 0;
g--;
}
}
return 0;
}
int main() {
int i, j, k;
while (cin >> n) {
if (n == 0)
break;
for (i = 0; i < n; i++) {
cin >> num[i];
}
for (i = n - 1; i > 0; i--)
for (j = 0; j < i; j++)
if (num[j] < num[j + 1]) {
k = num[j];
num[j] = num[j + 1];
num[j + 1] = k;
}
d[n] = 0;
for (i = n - 1; i >= 0; i--) {
a[i] = num[i];
d[i] = d[i + 1] + num[i];
u[i] = 0;
}
u[0] = 1;
g = 1;
if (search(1) == 1)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int search(int s);
int num[50], a[50], u[50], d[51], n, g;
int fnd(int v, int t, int s, int k) {
int i, j, w = -1;
if (k == 0) {
j = a[v];
a[v] = 0;
if (g == n || search(t + 1) == 1)
return 1;
a[v] = j;
return 0;
}
if (k > d[s] || t == n - 1)
return 0;
for (i = s; i < n; i++) {
if (u[i] == 0 && a[i] != w && k - a[i] >= 0) {
u[i] = 1;
g++;
if (fnd(v, t, i + 1, k - a[i]) == 1)
return 1;
u[i] = 0;
g--;
w = a[i];
}
}
return 0;
}
int search(int s) {
int i, k;
if (g == n)
return 1;
while (u[s] == 1 && s < n)
s++;
if (s == n)
return 0;
for (i = 0; i < s; i++)
if (a[i] >= a[s]) {
a[i] -= a[s];
g++;
if (a[i] == 0) {
u[s] = 1;
k = search(s + 1);
} else
k = fnd(i, s, s + 1, a[i]);
if (k == 1)
return 1;
else {
a[i] += a[s];
u[s] = 0;
g--;
}
}
return 0;
}
int main() {
int i, j, k;
while (cin >> n) {
if (n == 0)
break;
for (i = 0; i < n; i++) {
cin >> num[i];
}
for (i = n - 1; i > 0; i--)
for (j = 0; j < i; j++)
if (num[j] < num[j + 1]) {
k = num[j];
num[j] = num[j + 1];
num[j + 1] = k;
}
d[n] = 0;
for (i = n - 1; i >= 0; i--) {
a[i] = num[i];
d[i] = d[i + 1] + num[i];
u[i] = 0;
}
u[0] = 1;
g = 1;
if (search(1) == 1)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
|
[["-", 12, 16, 31, 2, 3, 4, 0, 16, 31, 22], ["+", 12, 16, 31, 2, 3, 4, 0, 16, 31, 22]]
| 1
| 618
| 2
|
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr = (input.replace(/\n$/, "")).split("\n");
while (true) {
var x = Arr.shift().split("");
if (x[0] == "0")
break;
var y = Arr.shift().split("");
var z = Arr.shift().split("");
var ans = "NA";
for (var i = 0; i < 2; i++) {
var s = ([ "b", "w" ])[i];
if (x[0] + x[1] + x[2] == s + s + s)
ans = s;
if (y[0] + y[1] + y[2] == s + s + s)
ans = s;
if (z[0] + z[1] + z[2] == s + s + s)
ans = s;
if (x[0] + y[0] + z[0] == s + s + s)
ans = s;
if (x[1] + y[1] + z[1] == s + s + s)
ans = s;
if (x[2] + y[2] + z[2] == s + s + s)
ans = s;
if (x[0] + y[1] + z[2] == s + s + s)
ans = s;
if (x[2] + y[1] + z[0] == s + s + s)
ans = s;
}
console.log(s);
}
|
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr = (input.replace(/\n$/, "")).split("\n");
while (true) {
var x = Arr.shift().split("");
if (x[0] == "0")
break;
var y = Arr.shift().split("");
var z = Arr.shift().split("");
var ans = "NA";
for (var i = 0; i < 2; i++) {
var s = ([ "b", "w" ])[i];
if (x[0] + x[1] + x[2] == s + s + s)
ans = s;
if (y[0] + y[1] + y[2] == s + s + s)
ans = s;
if (z[0] + z[1] + z[2] == s + s + s)
ans = s;
if (x[0] + y[0] + z[0] == s + s + s)
ans = s;
if (x[1] + y[1] + z[1] == s + s + s)
ans = s;
if (x[2] + y[2] + z[2] == s + s + s)
ans = s;
if (x[0] + y[1] + z[2] == s + s + s)
ans = s;
if (x[2] + y[1] + z[0] == s + s + s)
ans = s;
}
console.log(ans);
}
|
[["-", 8, 556, 0, 1, 0, 2, 3, 3, 0, 22], ["+", 8, 556, 0, 1, 0, 2, 3, 3, 0, 22]]
| 2
| 373
| 2
|
import java.util.Scanner;
public class Main {
char[][] data;
private char check(int x, int y) {
char ans = data[y][x];
// tate
if (ans == data[y + 1][x] && ans == data[y - 1][x]) {
return ans;
}
// yoko
if (ans == data[y][x + 1] && ans == data[y][x + 1]) {
return ans;
}
// naname
if (ans == data[y - 1][x - 1] && ans == data[y + 1][x + 1]) {
return ans;
}
if (ans == data[y - 1][x + 1] && ans == data[y + 1][x - 1]) {
return ans;
}
return '+';
}
private void doit() {
Scanner sc = new Scanner(System.in);
while (true) {
String str = sc.next();
if (str.equals("0")) {
break;
}
data = new char[5][5];
for (int i = 0; i < 5; i++) {
data[0][i] = '*';
data[4][i] = '*';
}
for (int i = 0; i < 5; i++) {
data[i][0] = '*';
data[i][4] = '*';
}
for (int i = 0; i < 3; i++) {
data[1][i + 1] = str.charAt(i);
}
for (int i = 2; i <= 3; i++) {
str = sc.next();
for (int j = 0; j < 3; j++) {
data[i][j + 1] = str.charAt(j);
}
}
char ans = '+';
for (int i = 1; i < 4; i++) {
for (int j = 1; j < 4; j++) {
if (data[i][j] == '+')
continue;
char result = check(j, i);
if (result == 'b' || result == 'w') {
ans = result;
break;
}
}
if (ans == 'b' || ans == 'w')
break;
}
if (ans == 'b')
System.out.println("b");
else if (ans == 'w')
System.out.println("w");
else
System.out.println("NA");
}
}
public static void main(String[] args) {
Main obj = new Main();
obj.doit();
}
}
|
import java.util.Scanner;
public class Main {
char[][] data;
private char check(int x, int y) {
char ans = data[y][x];
// tate
if (ans == data[y + 1][x] && ans == data[y - 1][x]) {
return ans;
}
// yoko
if (ans == data[y][x + 1] && ans == data[y][x - 1]) {
return ans;
}
// naname
if (ans == data[y - 1][x - 1] && ans == data[y + 1][x + 1]) {
return ans;
}
if (ans == data[y - 1][x + 1] && ans == data[y + 1][x - 1]) {
return ans;
}
return '+';
}
private void doit() {
Scanner sc = new Scanner(System.in);
while (true) {
String str = sc.next();
if (str.equals("0")) {
break;
}
data = new char[5][5];
for (int i = 0; i < 5; i++) {
data[0][i] = '*';
data[4][i] = '*';
}
for (int i = 0; i < 5; i++) {
data[i][0] = '*';
data[i][4] = '*';
}
for (int i = 0; i < 3; i++) {
data[1][i + 1] = str.charAt(i);
}
for (int i = 2; i <= 3; i++) {
str = sc.next();
for (int j = 0; j < 3; j++) {
data[i][j + 1] = str.charAt(j);
}
}
char ans = '+';
for (int i = 1; i < 4; i++) {
for (int j = 1; j < 4; j++) {
if (data[i][j] == '+')
continue;
char result = check(j, i);
if (result == 'b' || result == 'w') {
ans = result;
break;
}
}
if (ans == 'b' || ans == 'w')
break;
}
if (ans == 'b')
System.out.println("b");
else if (ans == 'w')
System.out.println("w");
else
System.out.println("NA");
}
}
public static void main(String[] args) {
Main obj = new Main();
obj.doit();
}
}
|
[["-", 0, 16, 12, 16, 12, 504, 71, 16, 17, 72], ["+", 0, 16, 12, 16, 12, 504, 71, 16, 17, 33]]
| 3
| 565
| 2
|
#include <stdio.h>
int main(void) {
char str[3][3];
int i, j;
int flag = 0;
while (scanf(" %c", &str[0][0])) {
if (str[0][0] == '0') {
break;
} else {
scanf(" %c", &str[0][1]);
scanf(" %c", &str[0][2]);
for (i = 1; i < 3; i++) {
for (j = 0; j < 3; j++) {
scanf(" %c", &str[i][j]);
}
}
// debug
/*for(i = 0;i < 3;i++){
for(j = 0;j < 3;j++){
printf(" %c",str[i][j]);
}
puts("");
}*/
if (str[0][0] == str[0][1] && str[0][1] == str[0][2]) {
if (str[0][0] != '+' && flag == 0) {
printf("%c\n", str[0][0]);
flag = 1;
}
}
if (str[1][0] == str[1][1] && str[1][1] == str[1][2]) {
if (str[1][0] != '+' && flag == 0) {
printf("%c\n", str[1][0]);
flag = 1;
}
}
if (str[2][0] == str[2][1] && str[2][1] == str[2][2]) {
if (str[2][0] != '+' && flag == 0) {
printf("%c\n", str[2][0]);
flag = 1;
}
}
if (str[0][0] == str[1][0] && str[1][0] == str[2][0]) {
if (str[0][0] != '+' && flag == 0) {
printf("%c\n", str[0][0]);
flag = 1;
}
}
if (str[0][1] == str[1][1] && str[1][1] == str[2][1]) {
if (str[0][1] != '+' && flag == 0) {
printf("%c\n", str[0][0]);
flag = 1;
}
}
if (str[0][2] == str[1][2] && str[1][2] == str[2][2]) {
if (str[0][2] != '+' && flag == 0) {
printf("%c\n", str[0][2]);
flag = 1;
}
}
if (str[0][0] == str[1][1] && str[1][1] == str[2][2]) {
if (str[0][0] != '+' && flag == 0) {
printf("%c\n", str[0][0]);
flag = 1;
}
}
if (str[0][2] == str[1][1] && str[1][1] == str[2][0]) {
if (str[0][2] != '+' && flag == 0) {
printf("%c\n", str[0][2]);
flag = 1;
}
}
if (flag == 0) {
printf("NA\n");
}
}
flag = 0;
}
return 0;
}
|
#include <stdio.h>
int main(void) {
char str[3][3];
int i, j;
int flag = 0;
while (scanf(" %c", &str[0][0])) {
if (str[0][0] == '0') {
break;
} else {
scanf(" %c", &str[0][1]);
scanf(" %c", &str[0][2]);
for (i = 1; i < 3; i++) {
for (j = 0; j < 3; j++) {
scanf(" %c", &str[i][j]);
}
}
// debug
/*for(i = 0;i < 3;i++){
for(j = 0;j < 3;j++){
printf(" %c",str[i][j]);
}
puts("");
}*/
if (str[0][0] == str[0][1] && str[0][1] == str[0][2]) {
if (str[0][0] != '+' && flag == 0) {
printf("%c\n", str[0][0]);
flag = 1;
}
}
if (str[1][0] == str[1][1] && str[1][1] == str[1][2]) {
if (str[1][0] != '+' && flag == 0) {
printf("%c\n", str[1][0]);
flag = 1;
}
}
if (str[2][0] == str[2][1] && str[2][1] == str[2][2]) {
if (str[2][0] != '+' && flag == 0) {
printf("%c\n", str[2][0]);
flag = 1;
}
}
if (str[0][0] == str[1][0] && str[1][0] == str[2][0]) {
if (str[0][0] != '+' && flag == 0) {
printf("%c\n", str[0][0]);
flag = 1;
}
}
if (str[0][1] == str[1][1] && str[1][1] == str[2][1]) {
if (str[0][1] != '+' && flag == 0) {
printf("%c\n", str[0][1]);
flag = 1;
}
}
if (str[0][2] == str[1][2] && str[1][2] == str[2][2]) {
if (str[0][2] != '+' && flag == 0) {
printf("%c\n", str[0][2]);
flag = 1;
}
}
if (str[0][0] == str[1][1] && str[1][1] == str[2][2]) {
if (str[0][0] != '+' && flag == 0) {
printf("%c\n", str[0][0]);
flag = 1;
}
}
if (str[0][2] == str[1][1] && str[1][1] == str[2][0]) {
if (str[0][2] != '+' && flag == 0) {
printf("%c\n", str[0][2]);
flag = 1;
}
}
if (flag == 0) {
printf("NA\n");
}
}
flag = 0;
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 69, 71, 13], ["+", 0, 1, 0, 2, 3, 4, 0, 69, 71, 13]]
| 0
| 780
| 2
|
#include <stdio.h>
/** Application main entry point. */
int main(int argc, char *argv[]) {
for (;;) {
char d[4][8];
scanf(" %s", d[0]);
if (d[0][0] == '0')
break;
scanf(" %s", d[1]);
scanf(" %s", d[2]);
if (d[0][0] != '+' && ((d[0][0] == d[0][1] && d[0][0] == d[0][2]) ||
(d[0][0] == d[1][0] && d[0][0] == d[2][0]))) {
printf("%c\n", d[0][0]);
}
if (d[2][2] != '+' && ((d[2][2] == d[2][1] && d[2][2] == d[2][0]) ||
(d[2][2] == d[1][2] && d[2][2] == d[0][2]))) {
printf("%c\n", d[2][2]);
} else if (d[1][1] != '+' && ((d[1][1] == d[1][0] && d[1][1] == d[1][2]) ||
(d[1][1] == d[0][1] && d[1][1] == d[2][1]) ||
(d[1][1] == d[0][0] && d[1][1] == d[2][2]) ||
(d[1][1] == d[0][2] && d[1][1] == d[2][0]))) {
printf("%c\n", d[1][1]);
} else {
puts("NA");
}
}
return (0);
}
|
#include <stdio.h>
/** Application main entry point. */
int main(int argc, char *argv[]) {
for (;;) {
char d[4][8];
scanf(" %s", d[0]);
if (d[0][0] == '0')
break;
scanf(" %s", d[1]);
scanf(" %s", d[2]);
if (d[0][0] != '+' && ((d[0][0] == d[0][1] && d[0][0] == d[0][2]) ||
(d[0][0] == d[1][0] && d[0][0] == d[2][0]))) {
printf("%c\n", d[0][0]);
} else if (d[2][2] != '+' && ((d[2][2] == d[2][1] && d[2][2] == d[2][0]) ||
(d[2][2] == d[1][2] && d[2][2] == d[0][2]))) {
printf("%c\n", d[2][2]);
} else if (d[1][1] != '+' && ((d[1][1] == d[1][0] && d[1][1] == d[1][2]) ||
(d[1][1] == d[0][1] && d[1][1] == d[2][1]) ||
(d[1][1] == d[0][0] && d[1][1] == d[2][2]) ||
(d[1][1] == d[0][2] && d[1][1] == d[2][0]))) {
printf("%c\n", d[1][1]);
} else {
puts("NA");
}
}
return (0);
}
|
[["+", 0, 7, 8, 9, 0, 57, 75, 76, 0, 95]]
| 0
| 475
| 1
|
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
while (1) {
vector<string> v;
for (int i = 0; i < 3; i++) {
string str;
cin >> str;
if (str == "0")
goto EXIT;
v.push_back(str);
}
for (int i = 0; i < 2; i++) {
bool tate, yoko;
bool naname0, naname1;
char c;
naname0 = naname1 = false;
c = i ? 'b' : 'w';
for (int j = 0; j < 3; j++) {
tate = yoko = true;
for (int k = 0; k < 3; k++) {
tate &= v[k][j] == c;
yoko &= v[j][k] == c;
}
naname0 &= v[j][2 - j] == c;
naname1 &= v[j][j] == c;
if (tate || yoko) {
cout << c << endl;
goto NEXT;
}
}
if (naname0 || naname1) {
cout << c << endl;
goto NEXT;
}
}
cout << "NA" << endl;
NEXT:;
}
EXIT:;
}
|
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
while (1) {
vector<string> v;
for (int i = 0; i < 3; i++) {
string str;
cin >> str;
if (str == "0")
goto EXIT;
v.push_back(str);
}
for (int i = 0; i < 2; i++) {
bool tate, yoko;
bool naname0, naname1;
char c;
naname0 = naname1 = true;
c = i ? 'b' : 'w';
for (int j = 0; j < 3; j++) {
tate = yoko = true;
for (int k = 0; k < 3; k++) {
tate &= v[k][j] == c;
yoko &= v[j][k] == c;
}
naname0 &= v[j][2 - j] == c;
naname1 &= v[j][j] == c;
if (tate || yoko) {
cout << c << endl;
goto NEXT;
}
}
if (naname0 || naname1) {
cout << c << endl;
goto NEXT;
}
}
cout << "NA" << endl;
NEXT:;
}
EXIT:;
}
|
[["-", 8, 9, 0, 1, 0, 11, 12, 11, 12, 147], ["+", 8, 9, 0, 1, 0, 11, 12, 11, 12, 146]]
| 1
| 252
| 2
|
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
typedef unsigned long long ull;
#define rep(i, a) for (int i = 0; i < a; i++)
#define loop(i, a, b) for (int i = a; i < b; i++)
using namespace std;
const double eps = 1e-10;
const double pi = acos(-1);
const double inf = (int)1e8;
int main(void) {
char maze[3][3];
while (cin >> maze[0][0]) {
if (maze[0][0] == '0')
break;
rep(i, 3) rep(j, 3) {
if (i == 0 && j == 0)
continue;
cin >> maze[i][j];
}
bool find = false;
rep(i, 3) if (maze[0][i] == maze[1][i] && maze[1][i] == maze[2][i] &&
maze[0][i] != '+') {
cout << maze[0][i] << endl;
find = true;
}
if (find)
continue;
rep(i, 3) if (maze[i][0] == maze[1][i] && maze[i][1] == maze[2][i] &&
maze[i][2] != '+') {
cout << maze[i][1] << endl;
find = true;
}
if (find)
continue;
if (maze[0][0] == maze[1][1] && maze[1][1] == maze[2][2] &&
maze[1][1] != '+') {
cout << maze[0][0] << endl;
continue;
} else if (maze[2][0] == maze[1][1] && maze[1][1] == maze[0][2] &&
maze[2][0] != '+') {
cout << maze[1][1] << endl;
continue;
} else {
cout << "NA" << endl;
}
}
return 0;
}
|
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
typedef unsigned long long ull;
#define rep(i, a) for (int i = 0; i < a; i++)
#define loop(i, a, b) for (int i = a; i < b; i++)
using namespace std;
const double eps = 1e-10;
const double pi = acos(-1);
const double inf = (int)1e8;
int main(void) {
char maze[3][3];
while (cin >> maze[0][0]) {
if (maze[0][0] == '0')
break;
rep(i, 3) rep(j, 3) {
if (i == 0 && j == 0)
continue;
cin >> maze[i][j];
}
bool find = false;
rep(i, 3) if (maze[0][i] == maze[1][i] && maze[1][i] == maze[2][i] &&
maze[0][i] != '+') {
cout << maze[0][i] << endl;
find = true;
}
if (find)
continue;
rep(i, 3) if (maze[i][0] == maze[i][1] && maze[i][1] == maze[i][2] &&
maze[i][2] != '+') {
cout << maze[i][1] << endl;
find = true;
}
if (find)
continue;
if (maze[0][0] == maze[1][1] && maze[1][1] == maze[2][2] &&
maze[1][1] != '+') {
cout << maze[0][0] << endl;
continue;
} else if (maze[2][0] == maze[1][1] && maze[1][1] == maze[0][2] &&
maze[2][0] != '+') {
cout << maze[1][1] << endl;
continue;
} else {
cout << "NA" << endl;
}
}
return 0;
}
|
[["-", 31, 16, 12, 69, 28, 69, 341, 342, 0, 13], ["+", 31, 16, 12, 69, 28, 69, 341, 342, 0, 22], ["-", 31, 16, 31, 16, 12, 69, 341, 342, 0, 22], ["+", 31, 16, 31, 16, 12, 69, 341, 342, 0, 13], ["-", 12, 16, 12, 69, 28, 69, 341, 342, 0, 13], ["+", 12, 16, 12, 69, 28, 69, 341, 342, 0, 22], ["-", 31, 16, 12, 16, 12, 69, 341, 342, 0, 22], ["+", 31, 16, 12, 16, 12, 69, 341, 342, 0, 13]]
| 1
| 442
| 8
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, e) for (int i = (s); i < (e); i++)
#define pb(n) push_back((n))
#define mp(n, m) make_pair((n), (m))
#define all(r) r.begin(), r.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int main() {
vector<string> s(3, "");
string ans;
while (1) {
cin >> s[0] >> s[1] >> s[2];
if (cin.eof())
break;
ans = "NA";
for (int i = 0; i < 3; i++) {
if ((s[i][0] != '+' && s[i][0] == s[i][1] && s[i][1] == s[i][2])) {
ans = s[i][0];
break;
}
if ((s[0][i] != '+' && s[0][i] == s[1][i] && s[1][i] == s[0][i])) {
ans = s[0][i];
break;
}
}
if (s[1][1] != '+') {
if ((s[1][1] == s[0][2] && s[1][1] == s[2][0]) ||
(s[1][1] == s[0][0] && s[1][1] == s[2][2])) {
ans = s[1][1];
}
}
cout << ans << endl;
}
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, e) for (int i = (s); i < (e); i++)
#define pb(n) push_back((n))
#define mp(n, m) make_pair((n), (m))
#define all(r) r.begin(), r.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int main() {
vector<string> s(3, "");
string ans;
while (1) {
cin >> s[0] >> s[1] >> s[2];
if (cin.eof())
break;
ans = "NA";
for (int i = 0; i < 3; i++) {
if ((s[i][0] != '+' && s[i][0] == s[i][1] && s[i][1] == s[i][2])) {
ans = s[i][0];
break;
}
if ((s[0][i] != '+' && s[0][i] == s[1][i] && s[1][i] == s[2][i])) {
ans = s[0][i];
break;
}
}
if (s[1][1] != '+') {
if ((s[1][1] == s[0][2] && s[1][1] == s[2][0]) ||
(s[1][1] == s[0][0] && s[1][1] == s[2][2])) {
ans = s[1][1];
}
}
cout << ans << endl;
}
}
|
[["-", 12, 16, 12, 69, 28, 69, 341, 342, 0, 13], ["+", 12, 16, 12, 69, 28, 69, 341, 342, 0, 13]]
| 1
| 431
| 2
|
#include <iostream>
#include <string>
using namespace std;
char T[3][3];
string blackwhite() {
for (int i = 0; i < 3; i++) {
if (T[i][0] == T[i][1] && T[i][1] == T[i][2]) {
if (T[i][0] == 'b') {
return "b";
}
if (T[i][0] == 'w') {
return "w";
}
}
}
for (int i = 0; i < 3; i++) {
if (T[0][i] == T[1][i] && T[1][i] == T[2][i]) {
if (T[0][i] == 'b') {
return "b";
}
if (T[0][i] == 'w') {
return "w";
}
}
}
if (T[0][0] == T[1][1] && T[1][1] == T[2][2]) {
if (T[0][0] == 'b') {
return "b";
}
if (T[0][0] == 'w') {
return "w";
}
}
if (T[0][2] == T[1][1] && T[1][1] && T[2][0]) {
if (T[0][0] == 'b') {
return "b";
}
if (T[0][0] == 'w') {
return "w";
}
}
return "NA";
}
int main() {
while (true) {
cin >> T[0][0];
if (T[0][0] == '0') {
break;
}
cin >> T[0][1];
cin >> T[0][2];
for (int i = 1; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cin >> T[i][j];
}
}
cout << blackwhite() << endl;
}
}
|
#include <iostream>
#include <string>
using namespace std;
char T[3][3];
string blackwhite() {
for (int i = 0; i < 3; i++) {
if (T[i][0] == T[i][1] && T[i][1] == T[i][2]) {
if (T[i][0] == 'b') {
return "b";
}
if (T[i][0] == 'w') {
return "w";
}
}
}
for (int i = 0; i < 3; i++) {
if (T[0][i] == T[1][i] && T[1][i] == T[2][i]) {
if (T[0][i] == 'b') {
return "b";
}
if (T[0][i] == 'w') {
return "w";
}
}
}
if (T[0][0] == T[1][1] && T[1][1] == T[2][2]) {
if (T[0][0] == 'b') {
return "b";
}
if (T[0][0] == 'w') {
return "w";
}
}
if (T[0][2] == T[1][1] && T[1][1] == T[2][0]) {
if (T[0][2] == 'b') {
return "b";
}
if (T[0][2] == 'w') {
return "w";
}
}
return "NA";
}
int main() {
while (true) {
cin >> T[0][0];
if (T[0][0] == '0') {
break;
}
cin >> T[0][1];
cin >> T[0][2];
for (int i = 1; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cin >> T[i][j];
}
}
cout << blackwhite() << endl;
}
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 98], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 60], ["-", 15, 339, 51, 16, 31, 69, 341, 342, 0, 13], ["+", 15, 339, 51, 16, 31, 69, 341, 342, 0, 13]]
| 1
| 482
| 6
|
#include <iostream>
using namespace std;
int main() {
int i;
string s[3], ans;
while (cin >> s[0] >> s[1] >> s[2], s[0] != "0") {
ans = "NA";
for (i = 0; i < 3; i++) {
if (s[i][0] != '+' && s[i][0] == s[i][1] && s[i][0] == s[i][2])
ans = s[i][0];
if (s[0][i] != '+' && s[0][i] == s[1][i] && s[0][i] == s[2][i])
ans = s[0][i];
}
if (s[1][1] != '+' && s[1][1] == s[1][1] && s[1][1] == s[2][2])
ans = s[1][1];
if (s[1][1] != '+' && s[1][1] == s[0][2] && s[1][1] == s[2][0])
ans = s[1][1];
cout << ans << endl;
}
}
|
#include <iostream>
using namespace std;
int main() {
int i;
string s[3], ans;
while (cin >> s[0] >> s[1] >> s[2], s[0] != "0") {
ans = "NA";
for (i = 0; i < 3; i++) {
if (s[i][0] != '+' && s[i][0] == s[i][1] && s[i][0] == s[i][2])
ans = s[i][0];
if (s[0][i] != '+' && s[0][i] == s[1][i] && s[0][i] == s[2][i])
ans = s[0][i];
}
if (s[1][1] != '+' && s[1][1] == s[0][0] && s[1][1] == s[2][2])
ans = s[1][1];
if (s[1][1] != '+' && s[1][1] == s[0][2] && s[1][1] == s[2][0])
ans = s[1][1];
cout << ans << endl;
}
}
|
[["-", 12, 16, 12, 69, 28, 69, 341, 342, 0, 13], ["+", 12, 16, 12, 69, 28, 69, 341, 342, 0, 13], ["-", 31, 16, 12, 16, 12, 69, 341, 342, 0, 13], ["+", 31, 16, 12, 16, 12, 69, 341, 342, 0, 13]]
| 1
| 304
| 4
|
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
string str;
while (cin >> str && str != "0") {
vector<string> field;
field.push_back(str);
for (int i = 0; i < 2; i++) {
cin >> str;
field.push_back(str);
}
bool fin = false;
// æ±
for (int i = 0; i < 3; i++) {
bool f = false;
char ch = field[i][0];
if (ch != '+') {
for (int j = 1; j < 3; j++) {
if (ch != field[i][j]) {
f = true;
break;
}
}
// sè
if (!f) {
cout << ch << endl;
fin = true;
break;
}
}
}
if (!fin) {
// ½Ä
for (int i = 0; i < 3; i++) {
bool f = false;
char ch = field[0][i];
if (ch != '+') {
for (int j = 1; j < 3; j++) {
if (ch != field[j][i]) {
f = true;
break;
}
}
// sè
if (!f) {
fin = true;
cout << ch << endl;
break;
}
}
}
if (!fin) {
// ÈÈß
char ch = field[0][0];
if (ch != '+' && field[1][1] == ch && field[2][2] == ch) {
fin = true;
cout << ch << endl;
} else if (field[1][1] != '+' && field[1][1] == field[2][0] &&
field[2][0] == field[0][2]) {
fin = true;
cout << field[1][1] << endl;
}
} else
cout << "NA" << endl;
}
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
string str;
while (cin >> str && str != "0") {
vector<string> field;
field.push_back(str);
for (int i = 0; i < 2; i++) {
cin >> str;
field.push_back(str);
}
bool fin = false;
// æ±
for (int i = 0; i < 3; i++) {
bool f = false;
char ch = field[i][0];
if (ch != '+') {
for (int j = 1; j < 3; j++) {
if (ch != field[i][j]) {
f = true;
break;
}
}
// sè
if (!f) {
cout << ch << endl;
fin = true;
break;
}
}
}
if (!fin) {
// ½Ä
for (int i = 0; i < 3; i++) {
bool f = false;
char ch = field[0][i];
if (ch != '+') {
for (int j = 1; j < 3; j++) {
if (ch != field[j][i]) {
f = true;
break;
}
}
// sè
if (!f) {
fin = true;
cout << ch << endl;
break;
}
}
}
if (!fin) {
// ÈÈß
char ch = field[0][0];
if (ch != '+' && field[1][1] == ch && field[2][2] == ch) {
fin = true;
cout << ch << endl;
} else if (field[1][1] != '+' && field[1][1] == field[2][0] &&
field[2][0] == field[0][2]) {
fin = true;
cout << field[1][1] << endl;
} else
cout << "NA" << endl;
}
}
}
return 0;
}
|
[["-", 0, 57, 64, 9, 0, 57, 64, 9, 0, 46], ["+", 0, 57, 64, 9, 0, 57, 64, 9, 0, 46]]
| 1
| 421
| 2
|
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 1 << 30
int main() {
string color[] = {"black", "blue", "lime", "aqua",
"red", "fuchsia", "yellow", "white"};
string s;
while (cin >> s, s != "0") {
int rgb[3];
REP(i, 3)
sscanf(s.substr(i * 2 + 1, 2).c_str(), "%x", rgb + i);
int mi = INF;
int ans;
REP(i, 8) {
int hoge = 0;
REP(j, 3) {
if (i >> j & 1)
hoge += pow(255 - rgb[j], 2);
else
hoge += pow(rgb[j], 2);
}
if (hoge < mi) {
mi = hoge;
ans = i;
}
}
cout << color[ans] << endl;
}
}
|
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 1 << 30
int main() {
string color[] = {"black", "blue", "lime", "aqua",
"red", "fuchsia", "yellow", "white"};
string s;
while (cin >> s, s != "0") {
int rgb[3];
REP(i, 3)
sscanf(s.substr(i * 2 + 1, 2).c_str(), "%x", rgb + i);
int mi = INF;
int ans;
REP(i, 8) {
int hoge = 0;
REP(j, 3) {
if (i << j & 4)
hoge += pow(255 - rgb[j], 2);
else
hoge += pow(rgb[j], 2);
}
if (hoge < mi) {
mi = hoge;
ans = i;
}
}
cout << color[ans] << endl;
}
}
|
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 17, 152], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 151], ["-", 0, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 0, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
| 1
| 244
| 4
|
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(n) rep(i, n)
#define all(n) n.begin(), n.end()
const int FF = 255, F = 16;
string name[] = {"black", "blue", "lime", "aqua",
"red", "fuchsia", "yellow", "while"};
int R[] = {0, 0, 0, 0, FF, FF, FF, FF};
int G[] = {0, 0, FF, FF, 0, 0, FF, FF};
int B[] = {0, FF, 0, FF, 0, FF, 0, FF};
int num(char t) {
if (t >= '0' && t <= '9')
return t - '0';
else
return t - 'a' + 10;
}
int f(int n) { return n * n; }
int main() {
string s;
while (cin >> s) {
if (s == "0")
break;
int mind = FF * FF * F, d = 0, ans = 0;
REP(8) {
d = f(R[i] - (num(s[1]) * F + num(s[2]))) +
f(G[i] - (num(s[3]) * F + num(s[4]))) +
f(B[i] - (num(s[5]) * F + num(s[6])));
if (mind > d) {
ans = i;
mind = d;
}
}
cout << name[ans] << endl;
}
return 0;
}
|
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(n) rep(i, n)
#define all(n) n.begin(), n.end()
const int FF = 255, F = 16;
string name[] = {"black", "blue", "lime", "aqua",
"red", "fuchsia", "yellow", "white"};
int R[] = {0, 0, 0, 0, FF, FF, FF, FF};
int G[] = {0, 0, FF, FF, 0, 0, FF, FF};
int B[] = {0, FF, 0, FF, 0, FF, 0, FF};
int num(char t) {
if (t >= '0' && t <= '9')
return t - '0';
else
return t - 'a' + 10;
}
int f(int n) { return n * n; }
int main() {
string s;
while (cin >> s) {
if (s == "0")
break;
int mind = FF * FF * F, d = 0, ans = 0;
REP(8) {
d = f(R[i] - (num(s[1]) * F + num(s[2]))) +
f(G[i] - (num(s[3]) * F + num(s[4]))) +
f(B[i] - (num(s[5]) * F + num(s[6])));
if (mind > d) {
ans = i;
mind = d;
}
}
cout << name[ans] << endl;
}
return 0;
}
|
[["-", 0, 43, 49, 50, 51, 83, 0, 5, 0, 6], ["+", 0, 43, 49, 50, 51, 83, 0, 5, 0, 6]]
| 1
| 371
| 2
|
import math
def solve(line):
R = int(line[1:3], 16)
G = int(line[3:5], 16)
B = int(line[5:7], 16)
sa_black = math.sqrt(R**2 + G**2 + B**2)
sa_max = sa_black
ans_color = "black"
sa_blue = math.sqrt(R**2 + G**2 + (B - 255)**2)
if sa_blue < sa_max:
sa_max = sa_blue
ans_color = "blue"
sa_lime = math.sqrt(R**2 + (G - 255)**2 + B**2)
if sa_lime < sa_max:
sa_max = sa_lime
ans_color = "lime"
sa_aqua = math.sqrt(R**2 + (G - 255)**2 + (B - 255)**2)
if sa_aqua < sa_max:
sa_max = sa_aqua
ans_color = "aqua"
sa_red = math.sqrt((R - 255)**2 + G**2 + B**2)
if sa_red < sa_max:
sa_max = sa_red
ans_color = "red"
sa_fuchsia = math.sqrt((R - 255)**2 + G**2 + (B - 255)**2)
if sa_fuchsia < sa_max:
sa_max = sa_fuchsia
ans_color = "fuchsia"
sa_yellow = math.sqrt((R - 255)**2 + (G - 255)**2 + B**2)
if sa_yellow < sa_max:
sa_max = sa_yellow
ans_color = "blue"
sa_white = math.sqrt((R - 255)**2 + (G - 255)**2 + (B - 255)**2)
if sa_white < sa_max:
sa_max = sa_white
ans_color = "white"
return ans_color
while True:
line = input()
if line == '0': break
print(solve(line))
|
import math
def solve(line):
R = int(line[1:3], 16)
G = int(line[3:5], 16)
B = int(line[5:7], 16)
sa_black = math.sqrt(R**2 + G**2 + B**2)
sa_max = sa_black
ans_color = "black"
sa_blue = math.sqrt(R**2 + G**2 + (B - 255)**2)
if sa_blue < sa_max:
sa_max = sa_blue
ans_color = "blue"
sa_lime = math.sqrt(R**2 + (G - 255)**2 + B**2)
if sa_lime < sa_max:
sa_max = sa_lime
ans_color = "lime"
sa_aqua = math.sqrt(R**2 + (G - 255)**2 + (B - 255)**2)
if sa_aqua < sa_max:
sa_max = sa_aqua
ans_color = "aqua"
sa_red = math.sqrt((R - 255)**2 + G**2 + B**2)
if sa_red < sa_max:
sa_max = sa_red
ans_color = "red"
sa_fuchsia = math.sqrt((R - 255)**2 + G**2 + (B - 255)**2)
if sa_fuchsia < sa_max:
sa_max = sa_fuchsia
ans_color = "fuchsia"
sa_yellow = math.sqrt((R - 255)**2 + (G - 255)**2 + B**2)
if sa_yellow < sa_max:
sa_max = sa_yellow
ans_color = "yellow"
sa_white = math.sqrt((R - 255)**2 + (G - 255)**2 + (B - 255)**2)
if sa_white < sa_max:
sa_max = sa_white
ans_color = "white"
return ans_color
while True:
line = input()
if line == '0': break
print(solve(line))
|
[["-", 64, 196, 0, 1, 0, 662, 12, 557, 0, 6], ["+", 64, 196, 0, 1, 0, 662, 12, 557, 0, 6]]
| 5
| 363
| 2
|
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
using namespace std;
#define EPS 1e-10
#define EQ(a, b) (fabs(a - b) < EPS)
int main(void) {
const long double radius = 6378.1;
const long double pi = acos(-1);
long double x[2], y[2];
long double dx;
long double d;
while (1) {
int i;
bool f = true;
for (i = 0; i < 2; i++) {
cin >> y[i] >> x[i];
if (y[i] != -1 || x[i] != -1)
f = false;
x[i] = x[i] * pi / 180;
y[i] = y[i] * pi / 180;
}
if (f)
return 0;
dx = x[1] - x[0];
d = radius * acos(sin(y[0]) * sin(y[1]) + cos(y[0]) * cos(y[1]) * cos(dx));
cout << (int)d << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
using namespace std;
#define EPS 1e-10
#define EQ(a, b) (fabs(a - b) < EPS)
int main(void) {
const long double radius = 6378.1;
const long double pi = acos(-1);
long double x[2], y[2];
long double dx;
long double d;
while (1) {
int i;
bool f = true;
for (i = 0; i < 2; i++) {
cin >> y[i] >> x[i];
if (y[i] != -1 || x[i] != -1)
f = false;
x[i] = x[i] * pi / 180;
y[i] = y[i] * pi / 180;
}
if (f)
return 0;
dx = x[1] - x[0];
d = radius * acos(sin(y[0]) * sin(y[1]) + cos(y[0]) * cos(y[1]) * cos(dx));
cout << round(d) << endl;
}
return 0;
}
|
[["+", 0, 1, 0, 16, 31, 16, 12, 2, 63, 22], ["-", 0, 16, 31, 16, 12, 74, 39, 77, 39, 40], ["-", 0, 1, 0, 16, 31, 16, 12, 74, 0, 25], ["+", 0, 16, 31, 16, 12, 2, 3, 4, 0, 25]]
| 1
| 231
| 4
|
#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;
ld pi = acos(-1.0);
const ld dtop = pi / 180.;
const ld ptod = 1. / dtop;
ld rad = 6378.1;
int main() {
while (1) {
ld a, b, c, d;
cin >> a >> b >> c >> d;
if (b < -eps)
break;
ld wd = (d - b);
ld ax = rad * (cos(a * dtop));
ld ay = 0;
ld az = rad * (sin(a * dtop));
ld bx = (rad * cos(wd * dtop)) * (cos(c * dtop));
ld by = (rad * sin(wd * dtop)) * (sin(c * dtop));
ld bz = rad * (sin(c * dtop));
ld dx = ax - bx;
ld dy = ay - by;
ld dz = az - bz;
ld dis = sqrt(dx * dx + dy * dy + dz * dz);
ld arad = asin((dis / 2) / rad);
ld ans = rad * 2 * arad;
int ians = int(round(ans));
cout << ians << endl;
}
return 0;
}
|
#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;
ld pi = acos(-1.0);
const ld dtop = pi / 180.;
const ld ptod = 1. / dtop;
ld rad = 6378.1;
int main() {
while (1) {
ld a, b, c, d;
cin >> a >> b >> c >> d;
if (b < -eps)
break;
ld wd = (d - b);
ld ax = rad * (cos(a * dtop));
ld ay = 0;
ld az = rad * (sin(a * dtop));
ld bx = (rad * cos(wd * dtop)) * (cos(c * dtop));
ld by = (rad * sin(wd * dtop)) * (cos(c * dtop));
ld bz = rad * (sin(c * dtop));
ld dx = ax - bx;
ld dy = ay - by;
ld dz = az - bz;
ld dis = sqrt(dx * dx + dy * dy + dz * dz);
ld arad = asin((dis / 2) / rad);
ld ans = rad * 2 * arad;
int ians = int(round(ans));
cout << ians << endl;
}
return 0;
}
|
[["-", 49, 50, 51, 16, 12, 23, 0, 2, 63, 22], ["+", 49, 50, 51, 16, 12, 23, 0, 2, 63, 22]]
| 1
| 295
| 2
|
#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;
//// < "d:\d_download\visual studio
///2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual
///studio 2015\projects\programing_contest_c++\debug\b.txt"
int fall(vector<vector<int>> &field, vector<vector<int>> &pino, int l) {
{}
int y = 0;
for (y = 0; y < field.size() - pino.size(); ++y) {
bool ok = true;
for (int i = 0; i < pino.size(); ++i) {
for (int j = 0; j < pino[i].size(); ++j) {
if (pino[i][j]) {
if (field[y + i + 1][l + j])
ok = false;
}
}
}
if (!ok) {
break;
}
}
for (int i = 0; i < pino.size(); ++i) {
for (int j = 0; j < pino[i].size(); ++j) {
if (pino[i][j]) {
assert(!field[y + i][l + j]);
field[y + i][l + j] = true;
}
}
}
int delline = 0;
for (int i = y + pino.size() - 1; i >= y; --i) {
while (all_of(field[i].begin(), field[i].end(),
[](const int a) { return a == 1; })) {
transform(field[i].begin(), field[i].end(), field[i].begin(),
[](const int a) { return false; });
for (int j = i - 1; j >= 0; --j) {
swap(field[j], field[j + 1]);
}
delline += 1;
}
}
return delline;
}
int main() {
while (1) {
int N;
cin >> N;
if (!N)
break;
int sum = 0;
vector<vector<int>> field(10, vector<int>(5));
for (int i = 0; i < N; ++i) {
int d, p, q;
cin >> d >> p >> q;
q--;
int w = d == 2 ? 1 : p;
int h = d == 1 ? 1 : p;
sum += p;
vector<vector<int>> pino(h, vector<int>(w, 1));
sum -= fall(field, pino, q) * 5;
}
cout << sum << endl;
}
return 0;
}
|
#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;
//// < "d:\d_download\visual studio
///2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual
///studio 2015\projects\programing_contest_c++\debug\b.txt"
int fall(vector<vector<int>> &field, vector<vector<int>> &pino, int l) {
{}
int y = 0;
for (y = 0; y < field.size() - pino.size(); ++y) {
bool ok = true;
for (int i = 0; i < pino.size(); ++i) {
for (int j = 0; j < pino[i].size(); ++j) {
if (pino[i][j]) {
if (field[y + i + 1][l + j])
ok = false;
}
}
}
if (!ok) {
break;
}
}
for (int i = 0; i < pino.size(); ++i) {
for (int j = 0; j < pino[i].size(); ++j) {
if (pino[i][j]) {
assert(!field[y + i][l + j]);
field[y + i][l + j] = true;
}
}
}
int delline = 0;
for (int i = y + pino.size() - 1; i >= y; --i) {
while (all_of(field[i].begin(), field[i].end(),
[](const int a) { return a == 1; })) {
transform(field[i].begin(), field[i].end(), field[i].begin(),
[](const int a) { return false; });
for (int j = i - 1; j >= 0; --j) {
swap(field[j], field[j + 1]);
}
delline += 1;
}
}
return delline;
}
int main() {
while (1) {
int N;
cin >> N;
if (!N)
break;
int sum = 0;
vector<vector<int>> field(5 * N + 10, vector<int>(5));
for (int i = 0; i < N; ++i) {
int d, p, q;
cin >> d >> p >> q;
q--;
int w = d == 2 ? 1 : p;
int h = d == 1 ? 1 : p;
sum += p;
vector<vector<int>> pino(h, vector<int>(w, 1));
sum -= fall(field, pino, q) * 5;
}
cout << sum << endl;
}
return 0;
}
|
[["+", 49, 50, 51, 4, 0, 16, 31, 16, 31, 13], ["+", 49, 50, 51, 4, 0, 16, 31, 16, 17, 48], ["+", 49, 50, 51, 4, 0, 16, 31, 16, 12, 22], ["+", 0, 43, 49, 50, 51, 4, 0, 16, 17, 72]]
| 1
| 570
| 4
|
#include <algorithm>
#include <iostream>
using namespace std;
#define REP(i, b, n) for (int i = b; i < n; i++)
#define rep(i, n) REP(i, 0, n)
// const int N = 6000;
const int N = 10;
bool block[N][5];
void output() {
cout << "Begin" << endl;
rep(i, 10) {
rep(j, 5) { cout << block[9 - i][j] << " "; }
cout << endl;
}
cout << "end" << endl;
}
void all_fall(int y) {
rep(j, 5) block[y][j] = false;
REP(i, y, N - 1) { rep(j, 5) block[i][j] = block[i + 1][j]; }
rep(j, 5) block[N - 1][j] = false;
}
int getmax(int l, int r) {
int ret = 0;
REP(j, l, r) {
int tmp = N - 1;
for (int i = N - 1; i >= 0; i--) {
if (block[i][j])
break;
tmp = i;
}
ret = max(ret, tmp);
}
return ret;
}
void fall() {
rep(i, N) {
if (block[i][0] & block[i][1] & block[i][2] & block[i][3] & block[i][4]) {
all_fall(i);
i--;
}
}
}
main() {
int n;
while (cin >> n && n) {
rep(i, N) rep(j, 5) block[i][j] = false;
rep(i, n) {
int d, p, q;
int wid = 1, hei = 1, pos;
cin >> d >> p >> q;
q--;
if (d == 1) { // yoko
pos = getmax(q, q + p);
wid = p;
} else if (d == 2) { // tate
pos = getmax(q, q + 1);
hei = p;
}
rep(i, hei) {
rep(j, wid) { block[pos + i][q + j] = true; }
}
fall();
// output();
}
cout << count(&block[0][0], &block[N][0], true) << endl;
// cout << cnt << endl;
}
}
|
#include <algorithm>
#include <iostream>
using namespace std;
#define REP(i, b, n) for (int i = b; i < n; i++)
#define rep(i, n) REP(i, 0, n)
const int N = 6000;
// const int N = 10;
bool block[N][5];
void output() {
cout << "Begin" << endl;
rep(i, 10) {
rep(j, 5) { cout << block[9 - i][j] << " "; }
cout << endl;
}
cout << "end" << endl;
}
void all_fall(int y) {
rep(j, 5) block[y][j] = false;
REP(i, y, N - 1) { rep(j, 5) block[i][j] = block[i + 1][j]; }
rep(j, 5) block[N - 1][j] = false;
}
int getmax(int l, int r) {
int ret = 0;
REP(j, l, r) {
int tmp = N - 1;
for (int i = N - 1; i >= 0; i--) {
if (block[i][j])
break;
tmp = i;
}
ret = max(ret, tmp);
}
return ret;
}
void fall() {
rep(i, N) {
if (block[i][0] & block[i][1] & block[i][2] & block[i][3] & block[i][4]) {
all_fall(i);
i--;
}
}
}
main() {
int n;
while (cin >> n && n) {
rep(i, N) rep(j, 5) block[i][j] = false;
rep(i, n) {
int d, p, q;
int wid = 1, hei = 1, pos;
cin >> d >> p >> q;
q--;
if (d == 1) { // yoko
pos = getmax(q, q + p);
wid = p;
} else if (d == 2) { // tate
pos = getmax(q, q + 1);
hei = p;
}
rep(i, hei) {
rep(j, wid) { block[pos + i][q + j] = true; }
}
fall();
// output();
}
cout << count(&block[0][0], &block[N][0], true) << endl;
// cout << cnt << endl;
}
}
|
[["-", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13]]
| 1
| 514
| 2
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long Int;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define mp make_pair
template <class T> void pv(T a, T b) {
for (T i = a; i != b; ++i)
cout << *i << " ";
cout << endl;
}
template <class T> void chmin(T &t, T f) {
if (t > f)
t = f;
}
template <class T> void chmax(T &t, T f) {
if (t < f)
t = f;
}
int in() {
int x;
scanf("%d", &x);
return x;
}
int ban[5010][5];
int d, p, q;
void clear(int h) {
int i, j;
bool no;
for (i = 0; i < (d == 1 ? 1 : p); i++) {
no = true;
for (j = 0; j < 5; j++) {
if (ban[h + i][j] == 0)
no = false;
}
if (no) {
int k;
for (k = h + i + 1; k < 5010; k++) {
for (j = 0; j < 5; j++) {
ban[k - 1][j] = ban[k][j];
}
}
i--;
}
}
}
int fall() {
int i, j;
if (d == 2) {
for (i = 5005; i >= 0; i--) {
if (ban[i][q])
break;
}
i++;
for (j = 0; j < p; j++) {
ban[i + j][q] = 1;
}
} else {
for (i = 5005; i >= 0; i--) {
for (j = 0; j < p; j++) {
if (ban[i][q + j])
goto aaa;
}
}
aaa:;
i++;
for (j = 0; j < p; j++) {
ban[i][q + j] = 1;
}
}
return i;
}
int main() {
int n;
while (n = in()) {
memset(ban, 0, sizeof(ban));
int i;
for (i = 0; i < n; i++) {
cin >> d >> p >> q;
q--;
clear(fall());
// int x,y;
// for(y=10;y>=0;y--){
// for(x=0;x<5;x++){
// cout<<ban[y][x];
// }
// cout<<endl;
//}
// cout<<endl;
}
int j;
int res = 0;
for (i = 0; i < n; i++) {
for (j = 0; j < 5; j++) {
if (ban[i][j])
res++;
}
}
cout << res << endl;
}
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long Int;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define mp make_pair
template <class T> void pv(T a, T b) {
for (T i = a; i != b; ++i)
cout << *i << " ";
cout << endl;
}
template <class T> void chmin(T &t, T f) {
if (t > f)
t = f;
}
template <class T> void chmax(T &t, T f) {
if (t < f)
t = f;
}
int in() {
int x;
scanf("%d", &x);
return x;
}
int ban[5010][5];
int d, p, q;
void clear(int h) {
int i, j;
bool no;
for (i = 0; i < (d == 1 ? 1 : p); i++) {
no = true;
for (j = 0; j < 5; j++) {
if (ban[h + i][j] == 0)
no = false;
}
if (no) {
int k;
for (k = h + i + 1; k < 5010; k++) {
for (j = 0; j < 5; j++) {
ban[k - 1][j] = ban[k][j];
}
}
i--;
}
}
}
int fall() {
int i, j;
if (d == 2) {
for (i = 5005; i >= 0; i--) {
if (ban[i][q])
break;
}
i++;
for (j = 0; j < p; j++) {
ban[i + j][q] = 1;
}
} else {
for (i = 5005; i >= 0; i--) {
for (j = 0; j < p; j++) {
if (ban[i][q + j])
goto aaa;
}
}
aaa:;
i++;
for (j = 0; j < p; j++) {
ban[i][q + j] = 1;
}
}
return i;
}
int main() {
int n;
while (n = in()) {
memset(ban, 0, sizeof(ban));
int i;
for (i = 0; i < n; i++) {
cin >> d >> p >> q;
q--;
clear(fall());
// int x,y;
// for(y=10;y>=0;y--){
// for(x=0;x<5;x++){
// cout<<ban[y][x];
// }
// cout<<endl;
// }
// cout<<endl;
}
int j;
int res = 0;
for (i = 0; i < 5010; i++) {
for (j = 0; j < 5; j++) {
if (ban[i][j])
res++;
}
}
cout << res << endl;
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13]]
| 1
| 632
| 2
|
#define _USE_MATH_DEFINES
#define MAX_N 1000000
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
static const double eps = 1e-8;
int gStage[6000][5];
void putBlock(int dir, int len, int pos) {
if (dir == 1) {
for (int i = 6000 - 1; i >= 0; i--) {
bool isok = true;
for (int j = pos; j < pos + len; j++) {
if (gStage[i][j] == 1)
isok = false;
}
if (!isok) {
for (int j = pos; j < pos + len; j++) {
gStage[i + 1][j] = 1;
}
return;
}
else if (isok && i == 0) {
for (int j = pos; j < pos + len; j++) {
gStage[i + 1][j] = 1;
}
return;
}
}
} else {
for (int i = 6000 - 1; i >= 0; i--) {
bool isok = true;
if (gStage[i][pos] == 1)
isok = false;
if (!isok) {
for (int j = i + 1; j < i + 1 + len; j++) {
gStage[j][pos] = 1;
}
return;
}
else if (isok && i == 0) {
for (int j = i; j < i + len; j++) {
gStage[j][pos] = 1;
}
return;
}
}
}
}
int countBlock() {
int res = 0;
for (int i = 0; i < 6000; i++) {
for (int j = 0; j < 5; j++) {
res += gStage[i][j];
}
}
return res;
}
void eraseBlock() {
for (int i = 0; i < 6000; i++) {
bool isok = true;
for (int j = 0; j < 5; j++) {
if (gStage[i][j] == 0)
isok = false;
}
if (isok) {
for (int j = i; j + 1 < 6000; j++) {
for (int k = 0; k < 5; k++) {
gStage[j][k] = gStage[j + 1][k];
}
}
i--;
}
}
}
void printBlock() {
for (int i = 0; i < 50; i++) {
for (int j = 0; j < 5; j++) {
printf("%d", gStage[i][j]);
}
printf("\n");
}
printf("\n");
}
int main() {
int n;
while (~scanf("%d", &n)) {
if (n == 0)
break;
memset(gStage, 0, sizeof(gStage));
for (int i = 0; i < n; i++) {
int dir, len, pos;
scanf("%d %d %d", &dir, &len, &pos);
pos -= 1;
putBlock(dir, len, pos);
// printBlock();
eraseBlock();
// printBlock();
}
printf("%d\n", countBlock());
}
}
|
#define _USE_MATH_DEFINES
#define MAX_N 1000000
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
static const double eps = 1e-8;
int gStage[6000][5];
void putBlock(int dir, int len, int pos) {
if (dir == 1) {
for (int i = 6000 - 1; i >= 0; i--) {
bool isok = true;
for (int j = pos; j < pos + len; j++) {
if (gStage[i][j] == 1)
isok = false;
}
if (!isok) {
for (int j = pos; j < pos + len; j++) {
gStage[i + 1][j] = 1;
}
return;
}
else if (isok && i == 0) {
for (int j = pos; j < pos + len; j++) {
gStage[i][j] = 1;
}
return;
}
}
} else {
for (int i = 6000 - 1; i >= 0; i--) {
bool isok = true;
if (gStage[i][pos] == 1)
isok = false;
if (!isok) {
for (int j = i + 1; j < i + 1 + len; j++) {
gStage[j][pos] = 1;
}
return;
}
else if (isok && i == 0) {
for (int j = i; j < i + len; j++) {
gStage[j][pos] = 1;
}
return;
}
}
}
}
int countBlock() {
int res = 0;
for (int i = 0; i < 6000; i++) {
for (int j = 0; j < 5; j++) {
res += gStage[i][j];
}
}
return res;
}
void eraseBlock() {
for (int i = 0; i < 6000; i++) {
bool isok = true;
for (int j = 0; j < 5; j++) {
if (gStage[i][j] == 0)
isok = false;
}
if (isok) {
for (int j = i; j + 1 < 6000; j++) {
for (int k = 0; k < 5; k++) {
gStage[j][k] = gStage[j + 1][k];
}
}
i--;
}
}
}
void printBlock() {
for (int i = 0; i < 50; i++) {
for (int j = 0; j < 5; j++) {
printf("%d", gStage[i][j]);
}
printf("\n");
}
printf("\n");
}
int main() {
int n;
while (~scanf("%d", &n)) {
if (n == 0)
break;
memset(gStage, 0, sizeof(gStage));
for (int i = 0; i < n; i++) {
int dir, len, pos;
scanf("%d %d %d", &dir, &len, &pos);
pos -= 1;
putBlock(dir, len, pos);
// printBlock();
eraseBlock();
// printBlock();
}
printf("%d\n", countBlock());
}
}
|
[["-", 31, 69, 28, 69, 341, 342, 0, 16, 17, 72], ["-", 31, 69, 28, 69, 341, 342, 0, 16, 12, 13]]
| 1
| 707
| 2
|
while True:
n=eval(input())
if n==0:break
hmax=10000
block=[list(map(int,input().split())) for i in range(n)]
field=[[0]*5 for i in range(hmax)]
h=0
for d,p,q in block:
if d==1:
for li in range(h+1,-2,-1):
if field[li][q-1:q+p-1]!=[0]*p or li==-1:
field[li+1][q-1:q+p-1]=[1]*p
h=max(h,li+1)
break
else:
for li in range(h+1,-2,-1):
if field[li][q-1]!=0 or li==-1:
for i in range(p):
field[li+i+1][q-1]=1
h=max(h,li+1+q)
break
i=0
while True:
if field[i]==[1]*5:
del field[i]
h-=1
elif field[i]==[0]*5:
break
else:
i+=1
print(sum([sum(field[li]) for li in range(len(field))]))
|
while True:
n=eval(input())
if n==0:break
hmax=10000
block=[list(map(int,input().split())) for i in range(n)]
field=[[0]*5 for i in range(hmax)]
h=0
for d,p,q in block:
if d==1:
for li in range(h+2,-2,-1):
if field[li][q-1:q+p-1]!=[0]*p or li==-1:
field[li+1][q-1:q+p-1]=[1]*p
h=max(h,li+1+1)
break
else:
for li in range(h+2,-2,-1):
if field[li][q-1]!=0 or li==-1:
for i in range(p):
field[li+i+1][q-1]=1
h=max(h,li+1+p)
break
i=0
while True:
if field[i]==[1]*5:
del field[i]
h-=1
elif field[i]==[0]*5:
break
else:
i+=1
print(sum([sum(field[li]) for li in range(len(field))]))
|
[["-", 0, 7, 12, 652, 3, 4, 0, 657, 12, 612], ["+", 0, 7, 12, 652, 3, 4, 0, 657, 12, 612], ["+", 12, 652, 3, 4, 0, 657, 31, 657, 17, 72], ["+", 12, 652, 3, 4, 0, 657, 31, 657, 12, 612], ["-", 0, 662, 12, 652, 3, 4, 0, 657, 12, 22], ["+", 0, 662, 12, 652, 3, 4, 0, 657, 12, 22]]
| 5
| 298
| 8
|
// Aizu Vol-1 0179: Mysterious Worm
// 2017.8.22 bal4u@uu
#include <stdio.h>
#include <string.h>
#define MAX 0xaaaaa
#define QMAX 5000000
char chk[MAX + 10];
int Q[QMAX + 10], *top, *end, *qmax = Q + QMAX;
int N, K, mask;
int nxt[16] = {0, 10, 5, 0, 10, 5, 0, 0, 5, 0, 10};
int main() {
int s, r, g, b, step;
int i, k;
char buf[15], *bp;
while (1) {
scanf("%s", buf);
if (buf[0] == '0')
break;
memset(chk, 0, sizeof(chk));
for (N = s = 0, bp = buf; *bp; bp++, N += 2) {
if (*bp == 'r')
k = 0;
else if (*bp == 'g')
k = 1;
else
k = 2;
s = (s << 2) | k;
}
mask = (1 << N) - 1, r = 0, g = 0x55555 & mask, b = 0xaaaaa & mask;
top = end = Q, qmax = Q + QMAX;
*end++ = s, *end++ = -1, chk[s] = 1, step = 0, K = N - 4;
while (top < end) {
s = *top;
if (++top >= qmax)
top = Q;
if (s < 0) {
step++, *end = -1;
if (++end >= qmax)
end = Q;
continue;
}
if (s == r || s == g || s == b) {
printf("%d\n", step);
goto Done;
}
for (i = 0; i <= K; i += 2) {
int s2, k2;
k = (s >> i) & 0xf;
k2 = nxt[k];
if (k2 == k)
continue;
s2 = (s & ~(0xf << i)) | (k2 << i);
// s2 &= mask;
if (!chk[s2])
chk[s2] = 1;
*end = s2;
if (++end >= qmax)
end = Q;
}
}
if (top >= end)
puts("NA");
Done:;
}
return 0;
}
|
// Aizu Vol-1 0179: Mysterious Worm
// 2017.8.22 bal4u@uu
#include <stdio.h>
#include <string.h>
#define MAX 0xaaaaa
#define QMAX 5000000
char chk[MAX + 10];
int Q[QMAX + 10], *top, *end, *qmax = Q + QMAX;
int N, K, mask;
int nxt[16] = {0, 10, 5, 0, 10, 5, 0, 0, 5, 0, 10};
int main() {
int s, r, g, b, step;
int i, k;
char buf[15], *bp;
while (1) {
scanf("%s", buf);
if (buf[0] == '0')
break;
memset(chk, 0, sizeof(chk));
for (N = s = 0, bp = buf; *bp; bp++, N += 2) {
if (*bp == 'r')
k = 0;
else if (*bp == 'g')
k = 1;
else
k = 2;
s = (s << 2) | k;
}
mask = (1 << N) - 1, r = 0, g = 0x55555 & mask, b = 0xaaaaa & mask;
top = end = Q, qmax = Q + QMAX;
*end++ = s, *end++ = -1, chk[s] = 1, step = 0, K = N - 4;
while (top < end) {
s = *top;
if (++top >= qmax)
top = Q;
if (s < 0) {
step++, *end = -1;
if (++end >= qmax)
end = Q;
continue;
}
if (s == r || s == g || s == b) {
printf("%d\n", step);
goto Done;
}
for (i = 0; i <= K; i += 2) {
int s2, k2;
k = (s >> i) & 0xf;
k2 = nxt[k];
if (k2 == k)
continue;
s2 = (s & ~(0xf << i)) | (k2 << i);
// s2 &= mask;
if (chk[s2])
continue;
chk[s2] = 1;
*end = s2;
if (++end >= qmax)
end = Q;
}
}
if (top >= end)
puts("NA");
Done:;
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 23, 0, 91, 17, 111], ["+", 0, 7, 8, 9, 0, 57, 64, 116, 0, 117], ["+", 0, 7, 8, 9, 0, 57, 64, 116, 0, 35]]
| 0
| 480
| 3
|
#include <stdio.h>
int main(void) {
int x, a, b, c, d;
while (1) {
scanf("%d%d", &a, &b);
if (a == 0 && b == 0 || (c = a + b)) {
break;
}
d = 0;
for (x = 1; x < 5; x++) {
scanf("%d%d", &a, &b);
if (a + b > c) {
c = a + b;
d = x;
}
}
printf("%c %d\n", 'A' + d, c);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int x, a, b, c, d;
while (1) {
scanf("%d%d", &a, &b);
if (a == 0 && b == 0 || !(c = a + b)) {
break;
}
d = 0;
for (x = 1; x < 5; x++) {
scanf("%d%d", &a, &b);
if (a + b > c) {
c = a + b;
d = x;
}
}
printf("%c %d\n", 'A' + d, c);
}
return 0;
}
|
[["+", 0, 57, 15, 23, 0, 16, 12, 91, 17, 111]]
| 0
| 132
| 10
|
#include <stdio.h>
int main(void) {
int bn, an;
int maxi;
char maxi_c;
int i;
while (scanf("%d %d", &bn, &an) * bn != 0) {
maxi = bn + an;
maxi_c = 'A';
for (i = 0; i < 4; i++) {
scanf("%d %d", &bn, &an);
if (maxi < bn + an) {
maxi = bn + an;
maxi_c = 'A' + i;
}
}
printf("%c %d\n", maxi_c, maxi);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int bn, an;
int maxi;
char maxi_c;
int i;
while (scanf("%d %d", &bn, &an) * bn != 0) {
maxi = bn + an;
maxi_c = 'A';
for (i = 0; i < 4; i++) {
scanf("%d %d", &bn, &an);
if (maxi < bn + an) {
maxi = bn + an;
maxi_c = 'A' + i + 1;
}
}
printf("%c %d\n", maxi_c, maxi);
}
return 0;
}
|
[["+", 64, 9, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 64, 9, 0, 1, 0, 11, 12, 16, 12, 13]]
| 0
| 123
| 2
|
#include <stdio.h>
int main(void) {
int m, a;
int i;
int sum[5];
int max;
char c;
while (1) {
scanf("%d %d", &m, &a);
if (m + a == 0) {
break;
}
max = m + a;
c = 'A';
for (i = 1; i < 4; i++) {
scanf("%d %d", &m, &a);
sum[i] = m + a;
if (max < sum[i]) {
max = sum[i];
c = 'A' + i;
}
}
printf("%c %d\n", c, max);
}
return (0);
}
|
#include <stdio.h>
int main(void) {
int m, a;
int i;
int sum[5];
int max;
char c;
while (1) {
scanf("%d %d", &m, &a);
if (m + a == 0) {
break;
}
max = m + a;
c = 'A';
for (i = 1; i < 5; i++) {
scanf("%d %d", &m, &a);
sum[i] = m + a;
if (max < sum[i]) {
max = sum[i];
c = 'A' + i;
}
}
printf("%c %d\n", c, max);
}
return (0);
}
|
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13]]
| 0
| 152
| 2
|
#include <stdio.h>
int main(void) {
int x, a, b, c, d;
while (1) {
scanf("%d%d", &a, &b);
if ((c = a + b) == 0)
break;
for (x = 1; x < 5; x++) {
scanf("%d%d", &a, &b);
if (a + b > c) {
c = a + b;
d = x;
}
}
printf("%c %d\n", d + 'A', c);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int x, a, b, c, d;
while (1) {
scanf("%d%d", &a, &b);
if ((c = a + b) == 0)
break;
d = 0;
for (x = 1; x < 5; x++) {
scanf("%d%d", &a, &b);
if (a + b > c) {
c = a + b;
d = x;
}
}
printf("%c %d\n", d + 'A', c);
}
return 0;
}
|
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 0
| 120
| 4
|
#include <stdio.h>
int main() {
int A, a, B, b, C, c, D, d, E, e, ta, tb, tc, td, te;
while (1) {
scanf("%d %d", &A, &a);
if (A == 0 && a == 0)
break;
scanf("%d %d %d %d %d %d %d %d", &B, &b, &C, &c, &D, &d, &E, &e);
ta = A + a;
tb = B + b;
tc = C + c;
td = D + d;
te = E + e;
if (ta > tb && ta > tc && ta > td && a > te)
printf("A %d\n", ta);
else if (tb > ta && tb > tc && tb > td && tb > te)
printf("B %d\n", tb);
else if (tc > ta && tc > tb && tc > td && tc > te)
printf("C %d\n", tc);
else if (td > ta && td > tb && td > tc && td > te)
printf("D %d\n", td);
else if (te > ta && te > tb && te > tc && te > td)
printf("E %d\n", te);
}
return 0;
}
|
#include <stdio.h>
int main() {
int A, a, B, b, C, c, D, d, E, e, ta, tb, tc, td, te;
while (1) {
scanf("%d %d", &A, &a);
if (A == 0 && a == 0)
break;
scanf("%d %d %d %d %d %d %d %d", &B, &b, &C, &c, &D, &d, &E, &e);
ta = A + a;
tb = B + b;
tc = C + c;
td = D + d;
te = E + e;
if (ta > tb && ta > tc && ta > td && ta > te)
printf("A %d\n", ta);
else if (tb > ta && tb > tc && tb > td && tb > te)
printf("B %d\n", tb);
else if (tc > ta && tc > tb && tc > td && tc > te)
printf("C %d\n", tc);
else if (td > ta && td > tb && td > tc && td > te)
printf("D %d\n", td);
else if (te > ta && te > tb && te > tc && te > td)
printf("E %d\n", te);
}
return 0;
}
|
[["-", 0, 57, 15, 23, 0, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 31, 22]]
| 0
| 278
| 2
|
#include <stdio.h>
int main() {
char r[5] = {'A', 'B', 'C', 'D', 'E'};
int s1[5], i, s2[5], m = 0, l;
while (1) {
for (i = 0; i < 5; i++) {
scanf("%d%d", &s1[i], &s2[i]);
if (s1[i] == 0 && s2[i] == 0) {
return 0;
}
}
for (i = 0; i < 5; i++) {
if (m < s1[i] + s2[i]) {
m = s1[i] + s2[i];
l = i;
}
}
printf("%c %d\n", r[l], m);
}
return 0;
}
|
#include <stdio.h>
int main() {
char r[5] = {'A', 'B', 'C', 'D', 'E'};
int s1[5], i, s2[5], m = 0, l;
while (1) {
for (i = 0; i < 5; i++) {
scanf("%d%d", &s1[i], &s2[i]);
if (s1[i] == 0 && s2[i] == 0) {
return 0;
}
}
for (i = 0; i < 5; i++) {
if (m < s1[i] + s2[i]) {
m = s1[i] + s2[i];
l = i;
}
}
printf("%c %d\n", r[l], m);
m = 0;
}
return 0;
}
|
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 0
| 181
| 4
|
#include <stdio.h>
main() {
int s1, s2, i, a, max = 0;
while (1) {
for (i = 0; i < 5; i++) {
scanf("%d %d", &s1, &s2);
if (s1 == 0 && s2 == 0)
break;
if (max < s1 + s2) {
max = s1 + s2;
a = i;
}
}
if (s1 == 0 && s2 == 0)
break;
switch (a) {
case 0:
printf("A ");
break;
case 1:
printf("B ");
break;
case 2:
printf("C ");
break;
case 3:
printf("D ");
break;
case 4:
printf("E ");
break;
}
printf("%d\n", max);
}
return 0;
}
|
#include <stdio.h>
main() {
int s1, s2, i, a, max = 0;
while (1) {
max = 0;
for (i = 0; i < 5; i++) {
scanf("%d %d", &s1, &s2);
if (s1 == 0 && s2 == 0)
break;
if (max < s1 + s2) {
max = s1 + s2;
a = i;
}
}
if (s1 == 0 && s2 == 0)
break;
switch (a) {
case 0:
printf("A ");
break;
case 1:
printf("B ");
break;
case 2:
printf("C ");
break;
case 3:
printf("D ");
break;
case 4:
printf("E ");
break;
}
printf("%d\n", max);
}
return 0;
}
|
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 0
| 178
| 4
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define F first
#define S second
typedef pair<int, int> pii;
int main() {
vector<pii> v(5);
while (cin >> v[0].F, v[0].F) {
int t;
cin >> t;
t += v[0].F;
v[0].S = 0;
for (int i = 1; i < 5; i++) {
cin >> t;
v[i].F = t;
cin >> t;
v[i].F += t;
v[i].S = i;
}
sort(v.begin(), v.end());
char r = 'A' + v[4].S;
cout << r << " " << v[4].F << endl;
}
}
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define F first
#define S second
typedef pair<int, int> pii;
int main() {
vector<pii> v(5);
while (cin >> v[0].F, v[0].F) {
int t;
cin >> t;
v[0].F += t;
v[0].S = 0;
for (int i = 1; i < 5; i++) {
cin >> t;
v[i].F = t;
cin >> t;
v[i].F += t;
v[i].S = i;
}
sort(v.begin(), v.end());
char r = 'A' + v[4].S;
cout << r << " " << v[4].F << endl;
}
}
|
[["-", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["-", 0, 52, 8, 9, 0, 1, 0, 11, 17, 107], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 107], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 22]]
| 1
| 182
| 4
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s1, s2;
while (cin >> s1 >> s2, s1 + s2) {
int maxn = s1 + s1;
char maxi = 'A';
for (int i = 1; i < 5; i++) {
cin >> s1 >> s2;
if (maxn < s1 + s2) {
maxn = s1 + s2;
maxi = 'A' + i;
}
}
cout << maxi << ' ' << maxn << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s1, s2;
while (cin >> s1 >> s2, s1 + s2) {
int maxn = s1 + s2;
char maxi = 'A';
for (int i = 1; i < 5; i++) {
cin >> s1 >> s2;
if (maxn < s1 + s2) {
maxn = s1 + s2;
maxi = 'A' + i;
}
}
cout << maxi << ' ' << maxn << endl;
}
}
|
[["-", 8, 9, 0, 43, 49, 50, 51, 16, 12, 22], ["+", 8, 9, 0, 43, 49, 50, 51, 16, 12, 22]]
| 1
| 103
| 2
|
#include <iostream>
using namespace std;
int main() {
int n, m;
while (cin >> n >> m, n || m) {
int maxn = n + m;
char s = 'A', store;
for (int i = 1; i < 5; i++) {
cin >> n >> m;
int sum = n + m;
if (maxn < sum) {
maxn = sum;
store = s + i;
}
}
cout << store << ' ' << maxn << endl;
}
return (0);
}
|
#include <iostream>
using namespace std;
int main() {
int n, m;
while (cin >> n >> m, n || m) {
int maxn = n + m;
char s = 'A', store = s;
for (int i = 1; i < 5; i++) {
cin >> n >> m;
int sum = n + m;
if (maxn < sum) {
maxn = sum;
store = s + i;
}
}
cout << store << ' ' << maxn << endl;
}
return (0);
}
|
[["+", 0, 52, 8, 9, 0, 43, 49, 50, 0, 32], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 22]]
| 1
| 111
| 2
|
#include <stdio.h>
int main(void) {
int i, a[5], b[5], c = 0, d;
char mise[5] = {'A', 'B', 'C', 'D', 'E'};
while (1) {
scanf("%d %d", &a[0], &b[0]);
if (a[0] == 0 && b[0] == 0)
break;
for (i = 1; i < 5; i++) {
scanf("%d %d", &a[i], &b[i]);
}
for (i = 0; i < 5; i++) {
if (c < a[i] + b[i]) {
c = a[i] + b[i];
d = i;
}
}
printf("%c %d\n", mise[d], c);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int i, a[5], b[5], c, d;
char mise[5] = {'A', 'B', 'C', 'D', 'E'};
while (1) {
c = 0;
scanf("%d %d", &a[0], &b[0]);
if (a[0] == 0 && b[0] == 0)
break;
for (i = 1; i < 5; i++) {
scanf("%d %d", &a[i], &b[i]);
}
for (i = 0; i < 5; i++) {
if (c < a[i] + b[i]) {
c = a[i] + b[i];
d = i;
}
}
printf("%c %d\n", mise[d], c);
}
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 0, 32], ["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 1
| 198
| 6
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
enum tol { a, b, c, d, e };
vector<tol> l;
vector<int> ll;
int a1, a2;
while (cin >> a1 >> a2) {
if (a1 == 0 && a2 == 0)
break;
int o[5];
int oo[5];
a1 += a2;
o[0] = a1;
for (int i = 1; i < 5; i++) {
cin >> a1 >> a2;
a1 += a2;
o[i] = a1;
}
for (int i = 0; i < 5; i++)
oo[i] = o[i];
sort(oo, oo + 5);
if (oo[4] == o[0]) {
l.push_back(a);
ll.push_back(o[0]);
} else if (oo[4] == o[1]) {
l.push_back(b);
ll.push_back(o[1]);
} else if (oo[4] == o[2]) {
l.push_back(c);
ll.push_back(o[2]);
} else if (oo[4] == o[3]) {
l.push_back(d);
ll.push_back(o[3]);
} else if (oo[4] == o[4]) {
l.push_back(e);
ll.push_back(o[4]);
}
}
for (int p = 0; p < l.size(); p++) {
if (l[p] == a)
cout << "A";
else if (l[p] == b)
cout << "B";
else if (l[p] == c)
cout << "C";
else if (l[p] == d)
cout << "D";
else if (l[p] == e)
cout << "E";
cout << ' ' << ll[p] << endl;
cout << endl;
}
char ch;
cin >> ch;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
enum tol { a, b, c, d, e };
vector<tol> l;
vector<int> ll;
int a1, a2;
while (cin >> a1 >> a2) {
if (a1 == 0 && a2 == 0)
break;
int o[5];
int oo[5];
a1 += a2;
o[0] = a1;
for (int i = 1; i < 5; i++) {
cin >> a1 >> a2;
a1 += a2;
o[i] = a1;
}
for (int i = 0; i < 5; i++)
oo[i] = o[i];
sort(oo, oo + 5);
if (oo[4] == o[0]) {
l.push_back(a);
ll.push_back(o[0]);
} else if (oo[4] == o[1]) {
l.push_back(b);
ll.push_back(o[1]);
} else if (oo[4] == o[2]) {
l.push_back(c);
ll.push_back(o[2]);
} else if (oo[4] == o[3]) {
l.push_back(d);
ll.push_back(o[3]);
} else if (oo[4] == o[4]) {
l.push_back(e);
ll.push_back(o[4]);
}
}
for (int p = 0; p < l.size(); p++) {
if (l[p] == a)
cout << "A";
else if (l[p] == b)
cout << "B";
else if (l[p] == c)
cout << "C";
else if (l[p] == d)
cout << "D";
else if (l[p] == e)
cout << "E";
cout << ' ' << ll[p] << endl;
}
char ch;
cin >> ch;
}
|
[["-", 0, 7, 8, 9, 0, 1, 0, 16, 31, 22], ["-", 0, 7, 8, 9, 0, 1, 0, 16, 17, 151], ["-", 0, 7, 8, 9, 0, 1, 0, 16, 12, 22], ["-", 8, 9, 0, 7, 8, 9, 0, 1, 0, 35]]
| 1
| 440
| 4
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int a[5], b[5], c[5], i, max = 0, num = 0;
string str[5] = {"A", "B", "C", "D", "E"};
while (cin >> a[0] >> b[0]) {
if (a[0] == 0 && b[0] == 0)
break;
for (i = 1; i < 5; i++) {
cin >> a[i] >> b[i];
}
for (i = 0; i < 5; i++) {
c[i] = a[i] + b[i];
}
for (i = 0; i < 5; i++) {
if (max < c[i]) {
max = c[i];
num = i;
}
}
cout << str[num] << " " << max << endl;
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int a[5], b[5], c[5], i, max = 0, num = 0;
string str[5] = {"A", "B", "C", "D", "E"};
while (cin >> a[0] >> b[0]) {
if (a[0] == 0 && b[0] == 0)
break;
for (i = 1; i < 5; i++) {
cin >> a[i] >> b[i];
}
for (i = 0; i < 5; i++) {
c[i] = a[i] + b[i];
}
for (i = 0; i < 5; i++) {
if (max < c[i]) {
max = c[i];
num = i;
}
}
cout << str[num] << " " << max << endl;
max = 0;
}
return 0;
}
|
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 1
| 222
| 4
|
#include <stdio.h>
#include <string.h>
int main(void) {
int a, b, d, i, j;
char c[6] = "ABCDE";
scanf("%d %d", &a, &b);
while (a != 0 && b != 0) {
j = 0;
d = a + b;
for (i = 1; i < 5; i++) {
scanf("%d %d", &a, &b);
if (a + b > d) {
d = a + b;
j = i;
}
}
printf("%c %d\n", c[j], d);
scanf("% %d", &a, &b);
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
int main(void) {
int a, b, d, i, j;
char c[6] = "ABCDE";
scanf("%d %d", &a, &b);
while (a != 0 && b != 0) {
j = 0;
d = a + b;
for (i = 1; i < 5; i++) {
scanf("%d %d", &a, &b);
if (a + b > d) {
d = a + b;
j = i;
}
}
printf("%c %d\n", c[j], d);
scanf("%d %d", &a, &b);
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 1
| 146
| 2
|
#include <algorithm>
#include <iostream>
using namespace std;
#define REP(i, b, n) for (int i = b; i < n; i++)
#define rep(i, n) REP(i, 0, n)
main() {
int ans, t, a, b;
while (cin >> a >> b) {
if (a == 0 && b == 0)
break;
ans = a;
b;
t = 0;
REP(i, 1, 5) {
cin >> a >> b;
if (a + b > ans) {
ans = a + b;
t = i;
}
}
cout << (char)(t + 'A') << " " << ans << endl;
}
}
|
#include <algorithm>
#include <iostream>
using namespace std;
#define REP(i, b, n) for (int i = b; i < n; i++)
#define rep(i, n) REP(i, 0, n)
main() {
int ans, t, a, b;
while (cin >> a >> b) {
if (a == 0 && b == 0)
break;
ans = a + b;
t = 0;
REP(i, 1, 5) {
cin >> a >> b;
if (a + b > ans) {
ans = a + b;
t = i;
}
}
cout << (char)(t + 'A') << " " << ans << endl;
}
}
|
[["-", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 17, 72]]
| 1
| 130
| 2
|
#include <algorithm>
#include <stdio.h>
using namespace std;
int main() {
while (1) {
int max;
int maxnum;
max = 0;
for (int i = 0; i < 5; i++) {
int a, b;
scanf("%d%d", &a, &b);
if (a == 0 && b == 0) {
goto A;
}
if (a + b > max) {
max = a + b;
maxnum = i;
}
}
printf("%c%d\n", 'A' + maxnum, max);
}
A:
return 0;
}
|
#include <algorithm>
#include <stdio.h>
using namespace std;
int main() {
while (1) {
int max;
int maxnum;
max = 0;
for (int i = 0; i < 5; i++) {
int a, b;
scanf("%d%d", &a, &b);
if (a == 0 && b == 0) {
goto A;
}
if (a + b > max) {
max = a + b;
maxnum = i;
}
}
printf("%c %d\n", 'A' + maxnum, max);
}
A:
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 1
| 120
| 2
|
#include <iostream>
using namespace std;
int main() {
while (1) {
int s1, s2;
int maxc = 0;
int max = 0;
for (int i = 0; i < 5; i++) {
cin >> s1 >> s2;
if (!s1 && !s2)
return 0;
if (s1 + s2 > max) {
max = s1 + s2;
maxc = 'A' + i;
}
}
cout << maxc << " " << max << endl;
}
}
|
#include <iostream>
using namespace std;
int main() {
while (1) {
int s1, s2;
int maxc = 0;
int max = 0;
for (int i = 0; i < 5; i++) {
cin >> s1 >> s2;
if (!s1 && !s2)
return 0;
if (s1 + s2 > max) {
max = s1 + s2;
maxc = 'A' + i;
}
}
cout << (char)maxc << " " << max << endl;
}
}
|
[["+", 31, 16, 31, 16, 31, 16, 12, 74, 0, 24], ["+", 31, 16, 31, 16, 12, 74, 39, 77, 39, 40], ["+", 31, 16, 31, 16, 31, 16, 12, 74, 0, 25]]
| 1
| 102
| 3
|
#include <iostream>
using namespace std;
int main(int argc, char **argv) {
int a, b, tmp, tmp2;
char w;
while (1) {
cin >> a >> b;
if (a == 0 && b == 0) {
break;
}
w = 'A';
tmp = a + b;
tmp = 0;
for (int i = 1; i <= 4; i++) {
cin >> a >> b;
if (tmp < (a + b)) {
tmp = a + b;
tmp2 = i;
}
}
cout << (char)(w + tmp2) << " " << tmp << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main(int argc, char **argv) {
int a, b, tmp, tmp2;
char w;
while (1) {
cin >> a >> b;
if (a == 0 && b == 0) {
break;
}
w = 'A';
tmp = a + b;
tmp2 = 0;
for (int i = 1; i <= 4; i++) {
cin >> a >> b;
if (tmp < (a + b)) {
tmp = a + b;
tmp2 = i;
}
}
cout << (char)(w + tmp2) << " " << tmp << endl;
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22]]
| 1
| 139
| 2
|
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1 << 30;
int main() {
int a, b;
int i = 0;
int res, ma = 0;
while (cin >> a >> b, a + b) {
if (ma < a + b) {
ma = a + b;
res = i;
}
++i;
if (i == 5) {
i = 0;
printf("%c %d\n", 'A' + res, ma);
}
}
}
|
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1 << 30;
int main() {
int a, b;
int i = 0;
int res, ma = 0;
while (cin >> a >> b, a + b) {
if (ma < a + b) {
ma = a + b;
res = i;
}
++i;
if (i == 5) {
i = 0;
printf("%c %d\n", 'A' + res, ma);
ma = 0;
}
}
}
|
[["+", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 57, 64, 9, 0, 1, 0, 35]]
| 1
| 143
| 4
|
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
int s1, s2;
while (cin >> s1 >> s2, s1 || s2) {
int ms = s1 + s2;
int mi = 0;
rep(i, 4) {
cin >> s1 >> s2;
if (ms < s1 + s2) {
ms = s1 + s2;
mi = i;
}
}
cout << (char)('A' + mi) << " " << ms << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
int s1, s2;
while (cin >> s1 >> s2, s1 || s2) {
int ms = s1 + s2;
int mi = 0;
rep(i, 4) {
cin >> s1 >> s2;
if (ms < s1 + s2) {
ms = s1 + s2;
mi = i + 1;
}
}
cout << (char)('A' + mi) << " " << ms << endl;
}
return 0;
}
|
[["+", 64, 9, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 64, 9, 0, 1, 0, 11, 12, 16, 12, 13]]
| 1
| 110
| 2
|
l=[]
while True:
n,k=list(map(int,input().split()))
cnt+=1
if n==k==0:
break
l.append(n+k)
if cnt%5==0:
print(chr(l.index(max(l))+65),max(l))
l=[]
|
cnt=0
l=[]
while True:
n,k=list(map(int,input().split()))
cnt+=1
if n==k==0:
break
l.append(n+k)
if cnt%5==0:
print(chr(l.index(max(l))+65),max(l))
l=[]
|
[["+", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 0, 32], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 12, 612]]
| 5
| 78
| 3
|
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
for (int n; (n = s.nextInt()) > 0;) {
char[] c = new char[n];
int[][] a = new int[n][3];
for (int i = 0; i < n; ++i) {
c[i] = s.next().charAt(0);
a[i][0] = i;
for (int j = 1; j < n; ++j) {
int x = s.nextInt();
if (x == 0) {
++a[i][1];
} else if (x == 1) {
++a[i][2];
}
}
}
Arrays.sort(a, new Comparator<int[]>() {
@Override
public int compare(int[] o1, int[] o2) {
if (o2[1] == o1[1]) {
if (o1[2] == o2[2]) {
return o1[0] - o2[1];
} else {
return o1[2] - o2[2];
}
}
return o2[1] - o1[1];
}
});
for (int i = 0; i < n; ++i) {
System.out.println(c[a[i][0]]);
}
}
}
}
|
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
for (int n; (n = s.nextInt()) > 0;) {
char[] c = new char[n];
int[][] a = new int[n][3];
for (int i = 0; i < n; ++i) {
c[i] = s.next().charAt(0);
a[i][0] = i;
for (int j = 1; j < n; ++j) {
int x = s.nextInt();
if (x == 0) {
++a[i][1];
} else if (x == 1) {
++a[i][2];
}
}
}
Arrays.sort(a, new Comparator<int[]>() {
@Override
public int compare(int[] o1, int[] o2) {
if (o2[1] == o1[1]) {
if (o1[2] == o2[2]) {
return o1[0] - o2[0];
} else {
return o1[2] - o2[2];
}
}
return o2[1] - o1[1];
}
});
for (int i = 0; i < n; ++i) {
System.out.println(c[a[i][0]]);
}
}
}
}
|
[["-", 64, 196, 0, 37, 0, 16, 12, 504, 71, 499], ["+", 64, 196, 0, 37, 0, 16, 12, 504, 71, 499]]
| 3
| 319
| 2
|
#include <stdio.h>
#include <string.h>
typedef struct {
char team[3];
int win;
int lose;
} DATA;
int main(void) {
int n;
int i, j;
DATA data[11], temp;
int r;
while (1) {
scanf("%d", &n);
if (n == 0)
break;
for (i = 0; i < n; i++) {
data[i].win = data[i].lose = 0;
scanf("%s", data[i].team);
for (j = 0; j < n - 1; j++) {
scanf("%d", &r);
if (r == 0) {
data[i].win++;
} else if (r == 1) {
data[i].lose++;
}
}
}
for (i = 0; i < n; i++) {
for (j = 0; j < n - 1; j++) {
if (data[j].win < data[j + 1].win) {
temp = data[j];
data[j] = data[j + 1];
data[j + 1] = temp;
} else if (data[j].win == data[j + 1].win &&
data[j].lose > data[j].lose) {
temp = data[j];
data[j] = data[j + 1];
data[j + 1] = temp;
}
}
}
for (i = 0; i < n; i++) {
printf("%s\n", data[i].team);
}
}
return (0);
}
|
#include <stdio.h>
#include <string.h>
typedef struct {
char team[3];
int win;
int lose;
} DATA;
int main(void) {
int n;
int i, j;
DATA data[11], temp;
int r;
while (1) {
scanf("%d", &n);
if (n == 0)
break;
for (i = 0; i < n; i++) {
data[i].win = data[i].lose = 0;
scanf("%s", data[i].team);
for (j = 0; j < n - 1; j++) {
scanf("%d", &r);
if (r == 0) {
data[i].win++;
} else if (r == 1) {
data[i].lose++;
}
}
}
for (i = 0; i < n; i++) {
for (j = 0; j < n - 1; j++) {
if (data[j].win < data[j + 1].win) {
temp = data[j];
data[j] = data[j + 1];
data[j + 1] = temp;
} else if (data[j].win == data[j + 1].win &&
data[j].lose > data[j + 1].lose) {
temp = data[j];
data[j] = data[j + 1];
data[j + 1] = temp;
}
}
}
for (i = 0; i < n; i++) {
printf("%s\n", data[i].team);
}
}
return (0);
}
|
[["+", 12, 16, 12, 118, 28, 69, 71, 16, 17, 72], ["+", 12, 16, 12, 118, 28, 69, 71, 16, 12, 13]]
| 0
| 355
| 2
|
#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 RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset(a, 0, sizeof(a))
typedef long long int ll;
using namespace std;
void ins(vector<pair<int, pair<int, char>>> &a) {
int s = a.size() - 1;
if (s == 0)
return;
while (a[s].first < a[s - 1].first) {
swap(a[s], a[s - 1]);
s--;
if (s == 0)
break;
}
if (s == 0)
return;
while (a[s].first == a[s - 1].first &&
a[s].second.first > a[s - 1].second.first) {
swap(a[s], a[s - 1]);
s--;
if (s == 0)
break;
}
return;
}
int main() {
while (true) {
int n;
cin >> n;
vector<pair<int, pair<int, char>>> ans;
if (n == 0)
break;
REP(i, n) {
char t;
int temp;
int w, l;
w = 0;
l = 0;
cin >> t;
REP(i, n - 1) {
cin >> temp;
if (temp == 0)
w++;
else if (temp == 1)
l++;
}
ans.PB(pair<int, pair<int, char>>(w, pair<int, char>(l, t)));
ins(ans);
}
REP(i, n) cout << ans[i].second.second << 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 RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset(a, 0, sizeof(a))
typedef long long int ll;
using namespace std;
void ins(vector<pair<int, pair<int, char>>> &a) {
int s = a.size() - 1;
if (s == 0)
return;
while (a[s].first > a[s - 1].first) {
swap(a[s], a[s - 1]);
s--;
if (s == 0)
break;
}
if (s == 0)
return;
while (a[s].first == a[s - 1].first &&
a[s].second.first < a[s - 1].second.first) {
swap(a[s], a[s - 1]);
s--;
if (s == 0)
break;
}
return;
}
int main() {
while (true) {
int n;
cin >> n;
vector<pair<int, pair<int, char>>> ans;
if (n == 0)
break;
REP(i, n) {
char t;
int temp;
int w, l;
w = 0;
l = 0;
cin >> t;
REP(i, n - 1) {
cin >> temp;
if (temp == 0)
w++;
else if (temp == 1)
l++;
}
ans.PB(pair<int, pair<int, char>>(w, pair<int, char>(l, t)));
ins(ans);
}
REP(i, n) cout << ans[i].second.second << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 52, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 47], ["-", 0, 52, 15, 339, 51, 16, 12, 16, 17, 47], ["+", 0, 52, 15, 339, 51, 16, 12, 16, 17, 18]]
| 1
| 402
| 4
|
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
typedef struct {
char t;
int pt[10];
int win;
int lose;
} GAME;
int main() {
GAME game[10], tmp;
int n;
while (scanf("%d", &n), n) {
for (int i = 0; i < n; i++) {
game[i].win = game[i].lose = 0;
cin >> game[i].t;
for (int j = 0; j < n - 1; j++) {
cin >> game[i].pt[j];
if (game[i].pt[j] == 0) {
game[i].win++;
} else if (game[i].pt[j] == 1) {
game[i].lose++;
}
}
}
for (int i = 0; i < n; i++) {
for (int j = n - 1; j > i; j--) {
if (game[j].win > game[j - 1].win) {
swap(game[j], game[j - 1]);
} else if (game[j].win == game[j - 1].win &&
game[j].lose < game[j].lose) {
swap(game[j], game[j - 1]);
}
}
}
for (int i = 0; i < n; i++) {
cout << game[i].t << endl;
}
}
return (0);
}
|
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
typedef struct {
char t;
int pt[10];
int win;
int lose;
} GAME;
int main() {
GAME game[10], tmp;
int n;
while (scanf("%d", &n), n) {
for (int i = 0; i < n; i++) {
game[i].win = game[i].lose = 0;
cin >> game[i].t;
for (int j = 0; j < n - 1; j++) {
cin >> game[i].pt[j];
if (game[i].pt[j] == 0) {
game[i].win++;
} else if (game[i].pt[j] == 1) {
game[i].lose++;
}
}
}
for (int i = 0; i < n; i++) {
for (int j = n - 1; j > i; j--) {
if (game[j].win > game[j - 1].win) {
swap(game[j], game[j - 1]);
} else if (game[j].win == game[j - 1].win &&
game[j].lose < game[j - 1].lose) {
swap(game[j], game[j - 1]);
}
}
}
for (int i = 0; i < n; i++) {
cout << game[i].t << endl;
}
}
return (0);
}
|
[["+", 12, 118, 28, 69, 341, 342, 0, 16, 17, 33], ["+", 12, 118, 28, 69, 341, 342, 0, 16, 12, 13]]
| 1
| 335
| 2
|
#include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define vi vector<int>
#define vvi vector<vector<int>>
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
template <class T, class S> void cmin(T &a, const S &b) {
if (a > b)
a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
if (a < b)
a = b;
}
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
int main() {
int n;
while (cin >> n, n) {
vector<pii> ujimatsu(n, pii(0, 0));
vc anko(n);
rep(i, n) {
cin >> anko[i];
rep(j, n - 1) {
int tiya;
cin >> tiya;
if (tiya == 0)
ujimatsu[i].first += 10000000000;
else if (tiya == 1)
ujimatsu[i].second += 1;
else if (tiya == 2)
ujimatsu[i].first += 1;
}
}
vector<bool> flag(1000, true);
rep(i, n) {
int maxi = -INF;
int ans = 0;
rep(j, n) {
if (!flag[j])
continue;
if (ujimatsu[j].first > maxi) {
maxi = ujimatsu[j].first;
ans = j;
} else if (ujimatsu[j].first == maxi) {
if (ujimatsu[ans].second > ujimatsu[j].second) {
ans = j;
}
}
}
flag[ans] = false;
cout << anko[ans] << endl;
}
}
}
|
#include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define vi vector<int>
#define vvi vector<vector<int>>
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
template <class T, class S> void cmin(T &a, const S &b) {
if (a > b)
a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
if (a < b)
a = b;
}
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
int main() {
int n;
while (cin >> n, n) {
vector<pii> ujimatsu(n, pii(0, 0));
vc anko(n);
rep(i, n) {
cin >> anko[i];
rep(j, n - 1) {
int tiya;
cin >> tiya;
if (tiya == 0)
ujimatsu[i].first += 100000000;
else if (tiya == 1)
ujimatsu[i].second += 1;
else if (tiya == 2)
ujimatsu[i].first += 1;
}
}
vector<bool> flag(1000, true);
rep(i, n) {
int maxi = -INF;
int ans = 0;
rep(j, n) {
if (!flag[j])
continue;
if (ujimatsu[j].first > maxi) {
maxi = ujimatsu[j].first;
ans = j;
} else if (ujimatsu[j].first == maxi) {
if (ujimatsu[ans].second > ujimatsu[j].second) {
ans = j;
}
}
}
flag[ans] = false;
cout << anko[ans] << endl;
}
}
}
|
[["-", 0, 9, 0, 57, 64, 1, 0, 11, 12, 13], ["+", 0, 9, 0, 57, 64, 1, 0, 11, 12, 13]]
| 1
| 444
| 2
|
#include <stdio.h>
#include <string.h>
int main(void) {
char x[10], r;
int n, a[10], b[10], c[10], i, k, t;
scanf("%d", &n);
while (1) {
if (n == 0)
break;
for (i = 0; i < n; i++) {
scanf(" %c", &x[i]);
a[i] = 0;
b[i] = 0;
c[i] = i;
for (k = 0; k < n - 1; k++) {
scanf("%d", &t);
if (t == 1)
a[i]++;
if (t == 0)
b[i]++;
}
}
for (i = 0; i < n - 1; i++) {
for (k = i + 1; k < n; k++) {
if ((a[i] > a[k]) || (a[i] == a[k] && b[i] > b[k]) ||
(a[i] == a[k] && b[i] == b[k] && c[i] > c[k])) {
t = a[i];
a[i] = a[k];
a[k] = t;
t = b[i];
b[i] = b[k];
b[k] = t;
t = c[i];
c[i] = c[k];
c[k] = t;
r = x[i];
x[i] = x[k];
x[k] = r;
}
}
}
for (i = 0; i < n; i++)
printf("%c\n", x[i]);
scanf("%d", &n);
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
int main(void) {
char x[10], r;
int n, a[10], b[10], c[10], i, k, t;
scanf("%d", &n);
while (1) {
if (n == 0)
break;
for (i = 0; i < n; i++) {
scanf(" %c", &x[i]);
a[i] = 0;
b[i] = 0;
c[i] = i;
for (k = 0; k < n - 1; k++) {
scanf("%d", &t);
if (t == 0)
a[i]++;
if (t == 1)
b[i]++;
}
}
for (i = 0; i < n - 1; i++) {
for (k = i + 1; k < n; k++) {
if ((a[i] < a[k]) || (a[i] == a[k] && b[i] > b[k]) ||
(a[i] == a[k] && b[i] == b[k] && c[i] > c[k])) {
t = a[i];
a[i] = a[k];
a[k] = t;
t = b[i];
b[i] = b[k];
b[k] = t;
t = c[i];
c[i] = c[k];
c[k] = t;
r = x[i];
x[i] = x[k];
x[k] = r;
}
}
}
for (i = 0; i < n; i++)
printf("%c\n", x[i]);
scanf("%d", &n);
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["-", 51, 16, 31, 16, 31, 23, 0, 16, 17, 47], ["+", 51, 16, 31, 16, 31, 23, 0, 16, 17, 18]]
| 1
| 406
| 6
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
while (1) {
int n;
cin >> n;
if (n == 0)
break;
vector<int> id(n);
vector<char> names(n);
vector<int> wins(n, 0);
vector<int> loses(n, 0);
for (int i = 0; i < n; i++) {
id[i] = i;
cin >> names[i];
for (int j = 0; j < n - 1; j++) {
int s;
cin >> s;
if (s == 0)
wins[i]++;
else if (s == 1)
loses[i]++;
}
}
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (wins[i] < wins[j]) {
swap(id[i], id[j]);
swap(wins[i], wins[j]);
swap(loses[i], loses[j]);
swap(names[i], names[j]);
} else if (wins[i] == wins[j]) {
if (loses[i] > loses[j]) {
swap(id[i], id[j]);
swap(wins[i], wins[j]);
swap(loses[i], loses[j]);
swap(names[i], names[j]);
} else if (loses[i] == loses[j]) {
if (i > j) {
swap(id[i], id[j]);
swap(wins[i], wins[j]);
swap(loses[i], loses[j]);
swap(names[i], names[j]);
}
}
}
}
}
for (int i = 0; i < n; i++) {
cout << names[i] << endl;
}
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
while (1) {
int n;
cin >> n;
if (n == 0)
break;
vector<int> id(n);
vector<char> names(n);
vector<int> wins(n, 0);
vector<int> loses(n, 0);
for (int i = 0; i < n; i++) {
id[i] = i;
cin >> names[i];
for (int j = 0; j < n - 1; j++) {
int s;
cin >> s;
if (s == 0)
wins[i]++;
else if (s == 1)
loses[i]++;
}
}
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (wins[i] < wins[j]) {
swap(id[i], id[j]);
swap(wins[i], wins[j]);
swap(loses[i], loses[j]);
swap(names[i], names[j]);
} else if (wins[i] == wins[j]) {
if (loses[i] > loses[j]) {
swap(id[i], id[j]);
swap(wins[i], wins[j]);
swap(loses[i], loses[j]);
swap(names[i], names[j]);
} else if (loses[i] == loses[j]) {
if (id[i] > id[j]) {
swap(id[i], id[j]);
swap(wins[i], wins[j]);
swap(loses[i], loses[j]);
swap(names[i], names[j]);
}
}
}
}
}
for (int i = 0; i < n; i++) {
cout << names[i] << endl;
}
}
return 0;
}
|
[["+", 0, 57, 15, 339, 51, 16, 31, 69, 28, 22], ["+", 15, 339, 51, 16, 31, 69, 341, 342, 0, 70], ["+", 15, 339, 51, 16, 31, 69, 341, 342, 0, 73], ["+", 0, 57, 15, 339, 51, 16, 12, 69, 28, 22], ["+", 15, 339, 51, 16, 12, 69, 341, 342, 0, 70], ["+", 15, 339, 51, 16, 12, 69, 341, 342, 0, 73]]
| 1
| 444
| 6
|
#include <cstdio>
#include <iostream>
using namespace std;
int i, j, make[100], kati[100];
char name[100];
void change() {
int tmp1, tmp2;
char tmp3;
tmp1 = kati[j + 1];
kati[j + 1] = kati[j];
kati[j] = tmp1;
tmp2 = make[j + 1];
make[j + 1] = make[j];
make[j] = tmp2;
tmp3 = name[j + 1];
name[j + 1] = name[j];
name[j] = tmp3;
}
int main() {
int n, s;
while (1) {
cin >> n;
if (n == 0)
break;
for (i = 0; i < 100; i++) {
kati[i] = 0;
make[i] = 0;
}
for (i = 0; i < n; i++) {
cin >> name[i];
for (j = 0; j < n - 1; j++) {
cin >> s;
if (s == 0)
kati[i]++;
if (s == 1)
make[i]++;
}
}
for (i = n - 1; i > 0; i--) {
for (j = 0; j < i; j++) {
if (make[j] < make[j + 1]) {
change();
}
}
}
for (i = n - 1; i > 0; i--) {
for (j = 0; j < i; j++) {
if (kati[j] < kati[j + 1]) {
change();
}
}
}
for (i = 0; i < n; i++)
cout << name[i] << endl;
}
return 0;
}
|
#include <cstdio>
#include <iostream>
using namespace std;
int i, j, make[100], kati[100];
char name[100];
void change() {
int tmp1, tmp2;
char tmp3;
tmp1 = kati[j + 1];
kati[j + 1] = kati[j];
kati[j] = tmp1;
tmp2 = make[j + 1];
make[j + 1] = make[j];
make[j] = tmp2;
tmp3 = name[j + 1];
name[j + 1] = name[j];
name[j] = tmp3;
}
int main() {
int n, s;
while (1) {
cin >> n;
if (n == 0)
break;
for (i = 0; i < 100; i++) {
kati[i] = 0;
make[i] = 0;
}
for (i = 0; i < n; i++) {
cin >> name[i];
for (j = 0; j < n - 1; j++) {
cin >> s;
if (s == 0)
kati[i]++;
if (s == 1)
make[i]++;
}
}
for (i = n - 1; i > 0; i--) {
for (j = 0; j < i; j++) {
if (make[j] > make[j + 1]) {
change();
}
}
}
for (i = n - 1; i > 0; i--) {
for (j = 0; j < i; j++) {
if (kati[j] < kati[j + 1]) {
change();
}
}
}
for (i = 0; i < n; i++)
cout << name[i] << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47]]
| 1
| 381
| 2
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
struct node {
char name;
int win, lost;
node(char n, int w, int l) : name(n), win(w), lost(l) {}
bool operator<(const node &e) const {
if (win == e.win)
lost < e.lost;
else
return win > e.win;
}
bool operator>(const node &e) const {
if (win == e.win)
lost > e.lost;
else
return win < e.win;
}
};
int main() {
int n;
for (; cin >> n, n;) {
vector<node> data;
for (int i = 0; i < n; i++) {
char t;
cin >> t;
int win = 0;
int lost = 0;
for (int i = 1; i < n; i++) {
int tmp;
cin >> tmp;
if (tmp == 0)
win++;
else if (tmp == 1)
lost++;
}
data.push_back(node(t, win, lost));
}
sort(data.begin(), data.end());
for (int i = 0; i < n; i++)
cout << data[i].name << endl;
}
}
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
struct node {
char name;
int win, lost;
node(char n, int w, int l) : name(n), win(w), lost(l) {}
bool operator<(const node &e) const {
if (win == e.win)
return lost < e.lost;
else
return win > e.win;
}
bool operator>(const node &e) const {
if (win == e.win)
return lost > e.lost;
else
return win < e.win;
}
};
int main() {
int n;
for (; cin >> n, n;) {
vector<node> data;
for (int i = 0; i < n; i++) {
char t;
cin >> t;
int win = 0;
int lost = 0;
for (int i = 1; i < n; i++) {
int tmp;
cin >> tmp;
if (tmp == 0)
win++;
else if (tmp == 1)
lost++;
}
data.push_back(node(t, win, lost));
}
sort(data.begin(), data.end());
for (int i = 0; i < n; i++)
cout << data[i].name << endl;
}
}
|
[["+", 0, 14, 8, 9, 0, 57, 64, 37, 0, 38]]
| 1
| 275
| 2
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main(void) {
multimap<int, char, greater<int>> team;
char t;
int n;
while (1) {
cin >> n;
if (!n)
break;
for (int j = 0; j < n; j++) {
cin >> t;
int point = 0, r;
for (int i = 0; i < n - 1; i++) {
cin >> r;
if (r == 0)
++point;
else if (r == 1)
--point;
}
team.insert(make_pair(point, t));
}
for (multimap<int, char, greater<int>>::iterator it = team.begin();
it != team.end(); ++it)
cout << (*it).second << endl;
team.clear();
}
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main(void) {
multimap<int, char, greater<int>> team;
char t;
int n;
while (1) {
cin >> n;
if (!n)
break;
for (int j = 0; j < n; j++) {
cin >> t;
int point = 0, r;
for (int i = 0; i < n - 1; i++) {
cin >> r;
if (r == 0)
point += 100;
else if (r == 1)
--point;
}
team.insert(make_pair(point, t));
}
for (multimap<int, char, greater<int>>::iterator it = team.begin();
it != team.end(); ++it)
cout << (*it).second << endl;
team.clear();
}
return 0;
}
|
[["-", 8, 9, 0, 57, 64, 1, 0, 27, 17, 29], ["+", 8, 9, 0, 57, 64, 1, 0, 11, 17, 107], ["+", 8, 9, 0, 57, 64, 1, 0, 11, 12, 13]]
| 1
| 199
| 3
|
loop{
n=gets.to_i;
exit if n==0;
[*1..n].map{s,*a=gets.split;t=0;a.map{|b|b=b.to_i;t+=b==0 ? 2*n : b==1 ? -1 : 0};[-t,s]}.sort.map{|a|puts a[1]}
}
|
loop{
n=gets.to_i;
exit if n==0;
[*1..n].map{|i|s,*a=gets.split;t=0;a.map{|b|b=b.to_i;t+=b==0 ? 2*n : b==1 ? -1 : 0};[-t,i,s]}.sort.map{|a|puts a[2]}
}
|
[["+", 486, 652, 486, 652, 196, 196, 54, 758, 0, 139], ["+", 486, 652, 486, 652, 196, 196, 54, 758, 0, 22], ["+", 486, 652, 196, 196, 8, 734, 0, 516, 0, 22], ["+", 486, 652, 196, 196, 8, 734, 0, 516, 0, 21], ["-", 8, 734, 0, 652, 3, 4, 0, 742, 0, 612], ["+", 8, 734, 0, 652, 3, 4, 0, 742, 0, 612]]
| 4
| 91
| 7
|
import sys
f = sys.stdin
while True:
n = int(f.readline())
if n == 0:
break
teams = [f.readline().split() for i in range(n)]
teams = [(t[0], -t.count('0'), t.count('1'), i) for i, t in enumerate(teams)]
teams.sort(key=operator.itemgetter(1,2,3))
print('\n'.join([t[0] for t in teams]))
|
import sys
import operator
f = sys.stdin
while True:
n = int(f.readline())
if n == 0:
break
teams = [f.readline().split() for i in range(n)]
teams = [(t[0], -t.count('0'), t.count('1'), i) for i, t in enumerate(teams)]
teams.sort(key=operator.itemgetter(1,2,3))
print('\n'.join([t[0] for t in teams]))
|
[["+", 36, 36, 36, 36, 0, 656, 0, 596, 0, 487], ["+", 36, 36, 0, 656, 0, 596, 141, 673, 0, 22]]
| 5
| 123
| 2
|
#include <stdio.h>
int main(void) {
int a, b, c, i;
while (1) {
scanf("%d %d", &a, &b);
if (a == 0 && b == 0)
break;
if (a < b) {
c = b;
b = a;
a = c;
}
for (i = 0; i < 0; i++) {
a = a % b;
c = a;
a = b;
b = c;
if (b == 0)
break;
}
printf("%d %d\n", a, i + 1);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int a, b, c, i;
while (1) {
scanf("%d %d", &a, &b);
if (a == 0 && b == 0)
break;
if (a < b) {
c = b;
b = a;
a = c;
}
for (i = 0;; i++) {
a = a % b;
c = a;
a = b;
b = c;
if (b == 0)
break;
}
printf("%d %d\n", a, i + 1);
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 31, 22], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13]]
| 0
| 127
| 3
|
#include <stdio.h>
int main(void) {
int a, b, x, cnt;
scanf("%d %d", &a, &b);
while (a != 0 && b != 0) {
cnt = 0;
if (a >= b) {
x = a;
a = b;
b = x;
}
while (b != 0) {
cnt++;
a = a % b;
x = a;
a = b;
b = x;
}
printf("%d %d\n", a, cnt);
scanf("%d %d", &a, &b);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int a, b, x, cnt;
scanf("%d %d", &a, &b);
while (a != 0 && b != 0) {
cnt = 0;
if (b >= a) {
x = a;
a = b;
b = x;
}
while (b != 0) {
cnt++;
a = a % b;
x = a;
a = b;
b = x;
}
printf("%d %d\n", a, cnt);
scanf("%d %d", &a, &b);
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 23, 0, 16, 31, 22], ["-", 8, 9, 0, 57, 15, 23, 0, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 12, 22]]
| 0
| 124
| 4
|
#include <stdio.h>
int main(void) {
int a, b;
int x, y, t;
int steps;
while (1) {
scanf("%d %d", &a, &b);
if (a == 0 && b == 0)
break;
if (a >= b) {
x = a;
y = b;
} else {
x = b;
y = a;
}
for (steps = 0; y > 0; steps++) {
y = x % y;
t = x;
x = y;
y = t;
}
printf("%d %d\n", x, steps);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int a, b;
int x, y, t;
int steps;
while (1) {
scanf("%d %d", &a, &b);
if (a == 0 && b == 0)
break;
if (a >= b) {
x = a;
y = b;
} else {
x = b;
y = a;
}
for (steps = 0; y > 0; steps++) {
x = x % y;
t = x;
x = y;
y = t;
}
printf("%d %d\n", x, steps);
}
return 0;
}
|
[["-", 0, 7, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 31, 22]]
| 0
| 130
| 2
|
#include <stdio.h>
int cnt = 0;
int GCD(int x, int y) {
int tmp;
if (x >= y) {
tmp = x;
x = y;
y = tmp;
}
while (1) {
if (y == 0)
break;
x %= y;
tmp = x;
x = y;
y = tmp;
cnt++;
}
return x;
}
int main(void) {
int x, y, ans;
while (1) {
cnt = 0;
scanf("%d %d", &x, &y);
if (x == 0 && y == 0)
break;
ans = GCD(x, y);
printf("%d %d\n", ans, cnt);
}
return 0;
}
|
#include <stdio.h>
int cnt = 0;
int GCD(int x, int y) {
int tmp;
if (!(x >= y)) {
tmp = x;
x = y;
y = tmp;
}
while (1) {
if (y == 0)
break;
x %= y;
tmp = x;
x = y;
y = tmp;
cnt++;
}
return x;
}
int main(void) {
int x, y, ans;
while (1) {
cnt = 0;
scanf("%d %d", &x, &y);
if (x == 0 && y == 0)
break;
ans = GCD(x, y);
printf("%d %d\n", ans, cnt);
}
return 0;
}
|
[["+", 8, 9, 0, 57, 15, 23, 0, 91, 17, 111], ["+", 0, 57, 15, 23, 0, 91, 28, 23, 0, 24], ["+", 0, 57, 15, 23, 0, 91, 28, 23, 0, 25]]
| 0
| 150
| 3
|
#include <algorithm>
#include <cstdio>
int main() {
int x = 0, y = 0;
int temp;
int count;
while (scanf("%d %d", &x, &y) != EOF) {
if (x == 0 && y == 0) {
break;
}
temp = 0;
if (x < y) {
temp = x;
x = y;
y = temp;
}
for (count = 0; y != 0; count++) {
x = x % y;
temp = x;
x = y;
y = temp;
}
printf("%d %d", x, count);
}
return 0;
}
|
#include <algorithm>
#include <cstdio>
int main() {
int x = 0, y = 0;
int temp;
int count;
while (scanf("%d %d", &x, &y) != EOF) {
if (x == 0 && y == 0) {
break;
}
temp = 0;
if (x < y) {
temp = x;
x = y;
y = temp;
}
for (count = 0; y != 0; count++) {
x = x % y;
temp = x;
x = y;
y = temp;
}
printf("%d %d\n", x, count);
}
return 0;
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 1
| 129
| 1
|
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define all(a) (a).begin(), (a).end()
int cnt;
int main(void) {
int a, b;
while (cin >> a >> b, a + b) {
cnt = 0;
if (a > b) {
int tmp = a;
a = b;
b = tmp;
}
int tmp;
while (b != 0) {
cnt++;
tmp = a % b;
a = b;
b = tmp;
}
cout << a << " " << cnt << endl;
}
}
|
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define all(a) (a).begin(), (a).end()
int cnt;
int main(void) {
int a, b;
while (cin >> a >> b, a + b) {
cnt = 0;
if (a < b) {
int tmp = a;
a = b;
b = tmp;
}
int tmp;
while (b != 0) {
cnt++;
// cout << a <<" " << b << endl;
tmp = a % b;
a = b;
b = tmp;
}
cout << a << " " << cnt << endl;
}
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18]]
| 1
| 173
| 2
|
#include <stdio.h>
long step;
long enclidean(long a, long b) {
step++;
long c;
c = a % b;
if (c)
return enclidean(b, c);
else
return b;
}
int main() {
long a, b, c;
while (scanf("%ld %ld", &a, &b), a + b != 0L) {
step = 0;
if (a > b)
c = enclidean(a, b);
else
c = enclidean(b, a);
putchar('w');
printf("%d %d\n", c, step);
}
return 0;
}
|
#include <stdio.h>
long step;
long enclidean(long a, long b) {
step++;
long c;
c = a % b;
if (c)
return enclidean(b, c);
else
return b;
}
int main() {
long a, b, c;
while (scanf("%ld %ld", &a, &b), a + b != 0L) {
step = 0;
if (a > b)
c = enclidean(a, b);
else
c = enclidean(b, a);
printf("%d %d\n", c, step);
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 1, 0, 2, 63, 22], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["-", 0, 1, 0, 2, 3, 4, 0, 103, 0, 104], ["-", 0, 1, 0, 2, 3, 4, 0, 103, 0, 125], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["-", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 1
| 131
| 7
|
#include <algorithm>
#include <cstdio>
int ans = 0;
int GCD(int a, int b) {
if (b == 0)
return a;
ans++;
return GCD(b, a % b);
}
int main() {
int x, y;
while (scanf("%d %d", &x, &y), x + y) {
ans = 0;
if (x > y)
std::swap(x, y);
int gcd = GCD(x, y);
printf("%d %d\n", gcd, ans);
}
}
|
#include <algorithm>
#include <cstdio>
int ans = 0;
int GCD(int a, int b) {
if (b == 0)
return a;
ans++;
return GCD(b, a % b);
}
int main() {
int x, y;
while (scanf("%d %d", &x, &y), x + y) {
ans = 0;
if (x < y)
std::swap(x, y);
int gcd = GCD(x, y);
printf("%d %d\n", gcd, ans);
}
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18]]
| 1
| 115
| 2
|
#include <algorithm>
#include <iostream>
using namespace std;
int euclid(int a, int b) {
int cnt = 0;
while (a == 0 || b == 0) {
if (a >= b) {
a = a % b;
} else {
b = b % a;
}
cnt++;
}
return cnt;
}
int main() {
int x, y;
while (true) {
cin >> x >> y;
if (x + y == 0) {
break;
}
cout << __gcd(x, y) << ' ' << euclid(x, y) << endl;
}
}
|
#include <algorithm>
#include <iostream>
using namespace std;
int euclid(int a, int b) {
int cnt = 0;
while (a != 0 && b != 0) {
if (a >= b) {
a = a % b;
} else {
b = b % a;
}
cnt++;
}
return cnt;
}
int main() {
int x, y;
while (true) {
cin >> x >> y;
if (x + y == 0) {
break;
}
cout << __gcd(x, y) << ' ' << euclid(x, y) << endl;
}
}
|
[["-", 0, 52, 15, 339, 51, 16, 31, 16, 17, 60], ["+", 0, 52, 15, 339, 51, 16, 31, 16, 17, 79], ["-", 8, 9, 0, 52, 15, 339, 51, 16, 17, 106], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 98], ["-", 0, 52, 15, 339, 51, 16, 12, 16, 17, 60], ["+", 0, 52, 15, 339, 51, 16, 12, 16, 17, 79]]
| 1
| 122
| 6
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
using namespace std;
int main(void) {
int cnt = 0;
;
int i, j, n, m, amari, syo;
while (1) {
scanf("%d %d", &n, &m);
if (n == 0 && m == 0)
break;
if (n < m)
swap(n, m);
while (1) {
n = n % m;
swap(n, m);
cnt++;
if (m == 0)
break;
}
printf("%d %d\n", n, cnt);
}
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
using namespace std;
int main(void) {
int cnt = 0;
;
int i, j, n, m, amari, syo;
while (1) {
scanf("%d %d", &n, &m);
if (n == 0 && m == 0)
break;
if (n < m)
swap(n, m);
while (1) {
n = n % m;
swap(n, m);
cnt++;
if (m == 0)
break;
}
printf("%d %d\n", n, cnt);
cnt = 0;
}
return 0;
}
|
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 1
| 127
| 4
|
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, x, y) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
int main() {
long long int x, y;
while (cin >> x >> y, x + y) {
int cnt = 0;
if (x < y)
swap(x, y);
while (y != 0) {
y = x % y;
swap(x, y);
cnt++;
}
cout << x << " " << cnt << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, x, y) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
int main() {
long long int x, y;
while (cin >> x >> y, x + y) {
int cnt = 0;
if (x < y)
swap(x, y);
while (y != 0) {
x = x % y;
swap(x, y);
cnt++;
}
cout << x << " " << cnt << endl;
}
}
|
[["-", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22]]
| 1
| 105
| 2
|
#include <bits/stdc++.h>
using namespace std;
#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(), (r).end()
#define gsort(st, en) sort((st), (en), greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout << #x << ": " << x << endl
#define fcout(n) cout << fixed << setprecision((n))
#define scout(n) cout << setw(n)
#define vary(type, name, size, init) vector<type> name(size, init)
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define repi(it, array) \
for (auto it = array.begin(), end = array.end(); it != end; ++it)
#define repa(n, array) for (auto &n : (array))
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string, int>;
using pii = pair<int, int>;
const int mod = 1000000007;
constexpr int imax = ((1 << 30) - 1) * 2 + 1;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0);
double eps = 1e-10;
const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, -1, 0, 1};
inline bool value(int x, int y, int w, int h) {
return (x >= 0 && x < w && y >= 0 && y < h);
}
template <typename T> void Unique(vector<T> &v) {
sort(all(v));
v.erase(unique(all(v)), v.end());
}
template <typename T> T ston(string &str, T n) {
istringstream sin(str);
T num;
sin >> num;
return num;
}
void Ans(bool f) {
if (f)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
int ans;
int gcd(int a, int b) {
if (a < b)
swap(a, b);
if (b == 0)
return a;
++ans;
return gcd(b, a % b);
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int a, b;
while (cin >> a >> b) {
ans = 0;
int k = gcd(a, b);
cout << k << " " << ans << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(), (r).end()
#define gsort(st, en) sort((st), (en), greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout << #x << ": " << x << endl
#define fcout(n) cout << fixed << setprecision((n))
#define scout(n) cout << setw(n)
#define vary(type, name, size, init) vector<type> name(size, init)
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define repi(it, array) \
for (auto it = array.begin(), end = array.end(); it != end; ++it)
#define repa(n, array) for (auto &n : (array))
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string, int>;
using pii = pair<int, int>;
const int mod = 1000000007;
constexpr int imax = ((1 << 30) - 1) * 2 + 1;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0);
double eps = 1e-10;
const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, -1, 0, 1};
inline bool value(int x, int y, int w, int h) {
return (x >= 0 && x < w && y >= 0 && y < h);
}
template <typename T> void Unique(vector<T> &v) {
sort(all(v));
v.erase(unique(all(v)), v.end());
}
template <typename T> T ston(string &str, T n) {
istringstream sin(str);
T num;
sin >> num;
return num;
}
void Ans(bool f) {
if (f)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
int ans;
int gcd(int a, int b) {
if (a < b)
swap(a, b);
if (b == 0)
return a;
++ans;
return gcd(b, a % b);
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int a, b;
while (cin >> a >> b && a && b) {
ans = 0;
int k = gcd(a, b);
cout << k << " " << ans << endl;
}
return 0;
}
|
[["+", 0, 52, 15, 339, 51, 16, 31, 16, 17, 98], ["+", 0, 52, 15, 339, 51, 16, 31, 16, 12, 22], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 98], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 12, 22]]
| 1
| 483
| 4
|
#include <bits/stdc++.h>
using namespace std;
void swap(unsigned int *a, unsigned int *b) {
if (*a != *b) {
*a ^= *b;
*b ^= *a;
*a ^= *b;
}
}
int main() {
unsigned int a, b, cnt;
while (cin >> a >> b, a & b) {
if (a < b)
swap(&a, &b);
cnt = 0;
while (b != 0) {
a = a % b;
swap(&a, &b);
++cnt;
}
cout << a << " " << cnt << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void swap(unsigned int *a, unsigned int *b) {
if (*a != *b) {
*a ^= *b;
*b ^= *a;
*a ^= *b;
}
}
int main() {
unsigned int a, b, cnt;
while (cin >> a >> b, a) {
if (a < b)
swap(&a, &b);
cnt = 0;
while (b != 0) {
a = a % b;
swap(&a, &b);
++cnt;
}
cout << a << " " << cnt << endl;
}
return 0;
}
|
[["-", 0, 52, 15, 339, 51, 34, 12, 16, 17, 67], ["-", 0, 52, 15, 339, 51, 34, 12, 16, 12, 22]]
| 1
| 137
| 2
|
#include <cstdio>
#include <iostream>
using namespace std;
int counter;
int gcd(int a, int b) {
if (b == 0)
return a;
counter++;
return gcd(b, a % b);
}
int main(void) {
int a, b, x;
while (cin >> a >> b) {
if (a < b) {
x = a;
a = b;
b = x;
}
if (a == 0 && b == 0)
return 0;
counter = 0;
cout << gcd(a, b) << "";
cout << counter << endl;
}
return 0;
}
|
#include <cstdio>
#include <iostream>
using namespace std;
int counter;
int gcd(int a, int b) {
if (b == 0)
return a;
counter++;
return gcd(b, a % b);
}
int main(void) {
int a, b, x;
while (cin >> a >> b) {
if (a < b) {
x = a;
a = b;
b = x;
}
if (a == 0 && b == 0)
return 0;
counter = 0;
cout << gcd(a, b) << " ";
cout << counter << endl;
}
return 0;
}
|
[["+", 8, 9, 0, 1, 0, 16, 12, 5, 0, 6]]
| 1
| 126
| 1
|
#include <iostream>
using namespace std;
int main(void) {
for (int i = 0; i < 1000; i++) {
int a, b;
cin >> a >> b;
if (a == 0 && b == 0)
break;
int j, r, COUNT = 1;
if (b > a) {
j = a;
a = b;
b = a;
}
while ((r = a % b) != 0) {
a = b;
b = r;
COUNT++;
}
cout << b << " " << COUNT << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main(void) {
for (int i = 0; i < 1000; i++) {
int a, b;
cin >> a >> b;
if (a == 0 && b == 0)
break;
int j, r, COUNT = 1;
if (b > a) {
j = a;
a = b;
b = j;
}
while ((r = a % b) != 0) {
a = b;
b = r;
COUNT++;
}
cout << b << " " << COUNT << endl;
}
return 0;
}
|
[["-", 0, 57, 64, 9, 0, 1, 0, 11, 12, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 22]]
| 1
| 121
| 2
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.