buggy_code
stringlengths 11
625k
| fixed_code
stringlengths 17
625k
| bug_type
stringlengths 2
4.45k
| language
int64 0
8
| token_count
int64 5
200k
| change_count
int64 0
100
|
|---|---|---|---|---|---|
#include <stdio.h>
#include <string.h>
int main(void) {
int x, i, c, w;
char n[1001];
while (1) {
c = 0;
w = 0;
scanf("%s", n);
if (n[0] == '0')
break;
for (i = 1; i < strlen(n); i++) {
if (n[i] == 'A') {
c++;
} else {
w++;
}
}
if (c < w) {
w++;
} else {
c++;
}
printf("%d %d", c, w);
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
int main(void) {
int i, c, w;
char n[1001];
while (1) {
c = 0;
w = 0;
scanf("%s", n);
if (n[0] == '0')
break;
for (i = 1; i < strlen(n); i++) {
if (n[i] == 'A') {
c++;
} else {
w++;
}
}
if (c < w) {
w++;
} else {
c++;
}
printf("%d %d\n", c, w);
}
return 0;
}
|
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 0, 21], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 1
| 133
| 3
|
#include <cstdio>
#include <iostream>
using namespace std;
int max(int, int);
int main(void) {
char str[200];
int a, b;
while (1) {
for (int i = 0; i < 200; i++) {
str[i] = '\0';
}
scanf("%[^\n]%*c", str);
a = 0;
b = 0;
if (str[0] == '0')
break;
for (int i = 1; str[i] != '\n'; i++) {
if (str[i] == 'A')
a++;
else if (str[i] == 'B')
b++;
}
if (a == max(a, b))
a++;
else if (b == max(a, b))
b++;
cout << a << " " << b << endl;
}
return 0;
}
int max(int x, int y) { return (x < y) ? y : x; }
|
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int max(int, int);
int main(void) {
char str[200];
int a, b;
while (1) {
for (int i = 0; i < 200; i++) {
str[i] = '\0';
}
scanf("%[^\n]%*c", str);
a = 0;
b = 0;
if (str[0] == '0')
break;
for (int i = 1; str[i] != '\0'; i++) {
if (str[i] == 'A')
a++;
else if (str[i] == 'B')
b++;
}
if (a == max(a, b))
a++;
else if (b == max(a, b))
b++;
cout << a << " " << b << endl;
}
return 0;
}
int max(int x, int y) { return (x < y) ? y : x; }
|
[["+", 36, 36, 36, 36, 0, 30, 0, 135, 0, 138], ["+", 36, 36, 36, 36, 0, 30, 0, 135, 136, 137], ["-", 8, 9, 0, 7, 15, 16, 12, 103, 0, 44], ["+", 8, 9, 0, 7, 15, 16, 12, 103, 0, 44]]
| 1
| 213
| 4
|
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr = (input.trim()).split("\n").map(Number);
for (var i = 0; i < Arr.length; i++) {
if (Arr[i] == -1)
break;
console.log(parseInt(Arr[i], 4));
}
|
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr = (input.trim()).split("\n").map(Number);
for (var i = 0; i < Arr.length; i++) {
if (Arr[i] == -1)
break;
console.log(Arr[i].toString(4));
}
|
[["-", 0, 1, 0, 2, 3, 3, 0, 2, 63, 22], ["-", 0, 2, 3, 3, 0, 2, 3, 3, 0, 24], ["-", 0, 2, 3, 3, 0, 2, 3, 3, 0, 21], ["+", 0, 2, 3, 3, 0, 2, 63, 558, 0, 131], ["+", 0, 2, 3, 3, 0, 2, 63, 558, 559, 560], ["+", 0, 2, 3, 3, 0, 2, 3, 3, 0, 24]]
| 2
| 89
| 6
|
import java.util.Scanner;
class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
while (true) {
int n = sc.nextInt();
if (n == -1)
break;
int order = 0;
for (; Math.pow(4, order) <= n; order++)
;
order--;
while (n > 3) {
int x = (int)(n / Math.pow(4, order));
System.out.print(x);
n = (int)(n % Math.pow(4, order));
order--;
}
System.out.println(n);
}
}
}
|
import java.util.Scanner;
class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
while (true) {
int n = sc.nextInt();
if (n == -1)
break;
int order = 1;
for (; Math.pow(4, order) <= n; order++)
;
order--;
while (order > 0) {
int x = (int)(n / Math.pow(4, order));
System.out.print(x);
n = (int)(n % Math.pow(4, order));
order--;
}
System.out.println(n);
}
}
}
|
[["-", 0, 52, 8, 196, 0, 503, 49, 200, 51, 499], ["+", 0, 52, 8, 196, 0, 503, 49, 200, 51, 499], ["-", 8, 196, 0, 52, 15, 15, 0, 16, 31, 22], ["+", 8, 196, 0, 52, 15, 15, 0, 16, 31, 22], ["-", 8, 196, 0, 52, 15, 15, 0, 16, 12, 499], ["+", 8, 196, 0, 52, 15, 15, 0, 16, 12, 499]]
| 3
| 150
| 6
|
#include <stdio.h>
int main(void) {
char s[9][15] = {};
int a[2][9] = {};
int j, i = 0;
while (i++ < 9) {
j = 0;
scanf("%s ", s);
scanf("%d %d", &a[0][i], &a[1][i]);
printf("%s", s);
printf("%d %d\n", a[0][i] + a[1][i], a[0][i] * 200 + a[1][i] * 300);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
char s[9][15] = {};
int a[2][9] = {};
int j, i = 0;
while (i++ < 9) {
j = 0;
scanf("%s", s);
scanf("%d %d", &a[0][i], &a[1][i]);
printf("%s", s);
printf(" %d %d\n", a[0][i] + a[1][i], a[0][i] * 200 + a[1][i] * 300);
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 0
| 143
| 4
|
#include <stdio.h>
int main() {
int i, N = 9, c[1000], a[1000], n[1000], s[100] = {0};
char S[100][100];
for (i = 0; i < N; i++) {
scanf("%s %d %d", S[i], &a[i], &n[i]);
s[i] = a[i] + n[i];
c[i] = a[i] * 200 + n[i] * 300;
}
for (i = 0; i < N; i++) {
printf("%s %d,%d\n", S[i], s[i], c[i]);
}
return 0;
}
|
#include <stdio.h>
int main() {
int i, N = 9, c[1000], a[1000], n[1000], s[100] = {0};
char S[100][100];
for (i = 0; i < N; i++) {
scanf("%s %d %d", S[i], &a[i], &n[i]);
s[i] = a[i] + n[i];
c[i] = a[i] * 200 + n[i] * 300;
}
for (i = 0; i < N; i++) {
printf("%s %d %d\n", S[i], s[i], c[i]);
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 0
| 162
| 2
|
#include <stdio.h>
int main() {
char cl[20];
int i, am, pm, yen;
for (i = 0; i < 9; i++) {
scanf("%s%d%d", &cl, &am, &pm);
printf("%s%d%d\n", cl, am + pm, am * 200 + pm * 300);
}
return 0;
}
|
#include <stdio.h>
int main() {
char cl[20];
int i, am, pm, yen;
for (i = 0; i < 9; i++) {
scanf("%s%d%d", &cl, &am, &pm);
printf("%s %d %d\n", cl, am + pm, am * 200 + pm * 300);
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 0
| 79
| 2
|
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
string s;
int a, b;
while (cin >> s >> a >> b) {
cout << a << " " << a + b << " " << a * 200 + b * 300 << endl;
}
return 0;
}
|
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
string s;
int a, b;
while (cin >> s >> a >> b) {
cout << s << " " << a + b << " " << a * 200 + b * 300 << endl;
}
return 0;
}
|
[["-", 31, 16, 31, 16, 31, 16, 31, 16, 12, 22], ["+", 31, 16, 31, 16, 31, 16, 31, 16, 12, 22]]
| 1
| 65
| 2
|
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <map>
//#include <utility>
#include <iostream>
#include <set>
//#include <memory>
#include <algorithm>
#include <string>
#include <vector>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <cstdio>
#include <queue>
#include <stack>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <bitset>
#include <iterator>
//#include <numeric>
//#include <list>
//#include <iomanip>
#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <initializer_list>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#define cauto const auto &
#else
#endif
using namespace std;
namespace {
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long>> vvll, vvLL;
#define VV(T) vector<vector<T>>
template <class T>
void initvv(vector<vector<T>> &v, int a, int b, const T &t = T()) {
v.assign(a, vector<T>(b, t));
}
template <class F, class T> void convert(const F &f, T &t) {
stringstream ss;
ss << f;
ss >> t;
}
#define reep(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) reep((i), 0, (n))
#define ALL(v) (v).begin(), (v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(), (v).rend()
#define MOD 1000000007LL
#define EPS 1e-8
static const int INF = 1 << 24;
void mainmain() {
string s;
while (getline(cin, s)) {
stringstream ss;
ss << s;
string s1;
ss >> s1;
cout << s1 << " ";
int a, b, c = 0;
ss >> a >> b;
cout << a + b << " ";
cout << a * 200 + b + 300 << endl;
}
}
} // namespace
main() try { mainmain(); } catch (...) {
}
|
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <map>
//#include <utility>
#include <iostream>
#include <set>
//#include <memory>
#include <algorithm>
#include <string>
#include <vector>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <cstdio>
#include <queue>
#include <stack>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <bitset>
#include <iterator>
//#include <numeric>
//#include <list>
//#include <iomanip>
#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <initializer_list>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#define cauto const auto &
#else
#endif
using namespace std;
namespace {
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long>> vvll, vvLL;
#define VV(T) vector<vector<T>>
template <class T>
void initvv(vector<vector<T>> &v, int a, int b, const T &t = T()) {
v.assign(a, vector<T>(b, t));
}
template <class F, class T> void convert(const F &f, T &t) {
stringstream ss;
ss << f;
ss >> t;
}
#define reep(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) reep((i), 0, (n))
#define ALL(v) (v).begin(), (v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(), (v).rend()
#define MOD 1000000007LL
#define EPS 1e-8
static const int INF = 1 << 24;
void mainmain() {
string s;
while (getline(cin, s)) {
stringstream ss;
ss << s;
string s1;
ss >> s1;
cout << s1 << " ";
int a, b, c = 0;
ss >> a >> b;
cout << a + b << " ";
cout << a * 200 + b * 300 << endl;
}
}
} // namespace
main() try { mainmain(); } catch (...) {
}
|
[["-", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 16, 31, 16, 12, 16, 12, 16, 17, 48]]
| 1
| 381
| 2
|
#include <iostream>
#include <string>
using namespace std;
string S;
int a, b;
int main() {
while (cin >> S >> a >> b) {
cout << S << ' ' << a + b << ' ' << a * 200 + b * 300;
}
}
|
#include <iostream>
#include <string>
using namespace std;
string S;
int a, b;
int main() {
while (cin >> S >> a >> b) {
cout << S << ' ' << a + b << ' ' << a * 200 + b * 300 << endl;
}
}
|
[["+", 0, 52, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 52, 8, 9, 0, 1, 0, 16, 12, 22]]
| 1
| 58
| 2
|
#include <iostream>
#include <string>
using namespace std;
int main() {
while (1) {
string a;
int b, c;
cin >> a >> b >> c;
if (cin.fill())
break;
cout << a << " " << b + c << " " << b * 200 + c * 300 << endl;
}
}
|
#include <iostream>
#include <string>
using namespace std;
int main() {
while (1) {
string a;
int b, c;
cin >> a >> b >> c;
if (cin.fail())
break;
cout << a << " " << b + c << " " << b * 200 + c * 300 << endl;
}
}
|
[["-", 0, 57, 15, 339, 51, 2, 63, 118, 119, 120], ["+", 0, 57, 15, 339, 51, 2, 63, 118, 119, 120]]
| 1
| 72
| 2
|
#include <cstdio>
int main() {
char n[32];
int m, a;
for (int i = 0; i < 9; i++) {
scanf("%s%d%d", n, &m, &a);
printf("%s %d %d\n", m + a, m * 200 + a * 300);
}
return 0;
}
|
#include <cstdio>
int main() {
char n[32];
int m, a;
for (int i = 0; i < 9; i++) {
scanf("%s%d%d", n, &m, &a);
printf("%s %d %d\n", n, m + a, m * 200 + a * 300);
}
return 0;
}
|
[["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 21]]
| 1
| 73
| 2
|
#include <stdio.h>
int main(void) {
int n, m, c, i;
int a[100000];
while (1) {
scanf("%d", &n);
if (n == -1)
break;
if (n == 0)
printf("0");
else {
c = 0;
while (n / 4) {
a[c++] = n % 4;
n /= 4;
}
a[c] = n % 4;
for (i = c; i >= 0; i--)
printf("%d", a[i]);
putchar('\n');
}
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int n, m, c, i;
int a[100000];
while (1) {
scanf("%d", &n);
if (n == -1)
break;
if (n == 0)
printf("0\n");
else {
c = 0;
while (n / 4) {
a[c++] = n % 4;
n /= 4;
}
a[c] = n % 4;
for (i = c; i >= 0; i--)
printf("%d", a[i]);
putchar('\n');
}
}
return 0;
}
|
[["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 134
| 1
|
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void) {
int a[100], n, i, j;
while (scanf("%d", &n), n != -1) {
if (n < 4)
printf("%d\n", n);
else {
for (i = 0; n != 0; i++) {
a[i] = n % 4;
n /= 4;
}
for (j = i - 1; j >= 0; j--)
printf("%d", a[i]);
printf("\n");
}
}
return 0;
}
|
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void) {
int a[100], n, i, j;
while (scanf("%d", &n), n != -1) {
if (n < 4)
printf("%d\n", n);
else {
for (i = 0; n != 0; i++) {
a[i] = n % 4;
n /= 4;
}
for (j = i - 1; j >= 0; j--)
printf("%d", a[j]);
printf("\n");
}
}
return 0;
}
|
[["-", 8, 1, 0, 2, 3, 4, 0, 69, 71, 22], ["+", 8, 1, 0, 2, 3, 4, 0, 69, 71, 22]]
| 0
| 125
| 2
|
#include <stdio.h>
int main(void) {
int num[10000];
int i;
int input;
while (1) {
scanf("%d", &input);
if (input == -1)
break;
i = 0;
while (input) {
num[i] = input % 4;
input /= 4;
i++;
if (i >= 10000)
return 1;
}
if (i == 0)
puts("0");
else {
for (; i >= 0; i--)
printf("%d", num[i]);
puts("");
}
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int num[10000];
int i;
int input;
while (1) {
scanf("%d", &input);
if (input == -1)
break;
i = 0;
while (input) {
num[i] = input % 4;
input /= 4;
i++;
if (i >= 10000)
return 1;
}
if (i == 0)
puts("0");
else {
for (i--; i >= 0; i--)
printf("%d", num[i]);
puts("");
}
}
return 0;
}
|
[["+", 75, 76, 0, 9, 0, 7, 10, 27, 28, 22], ["+", 75, 76, 0, 9, 0, 7, 10, 27, 17, 68]]
| 0
| 127
| 2
|
f(n) {
n > 3 && f(n / 4);
putchar(n % 4 + 65);
}
main(n) {
for (; scanf("%d", &n), ~n; puts(""))
f(n);
}
|
f(n) {
n > 3 && f(n / 4);
putchar(n % 4 + 48);
}
main(n) {
for (; scanf("%d", &n) + n; puts(""))
f(n);
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["-", 0, 14, 8, 9, 0, 7, 15, 34, 0, 21], ["-", 8, 9, 0, 7, 15, 34, 12, 91, 17, 92], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 72]]
| 0
| 59
| 5
|
#include <stdio.h>
#include <string.h>
int main(void) {
int n;
int i;
int flag;
char temp[8];
while (1) {
scanf("%d", &n);
if (n == -1)
break;
if (n == 0) {
puts("0");
continue;
}
i = 0;
while (n) {
temp[i] = n % 4 + '0';
n /= 4;
i++;
}
for (i = strlen(temp); i > 0; i--) {
putchar(temp[i - 1]);
}
putchar('\n');
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
int main(void) {
int n;
int i;
int flag;
char temp[8];
while (1) {
scanf("%d", &n);
if (n == -1)
break;
if (n == 0) {
puts("0");
continue;
}
i = 0;
while (n) {
temp[i] = n % 4 + '0';
n /= 4;
i++;
}
for (; i > 0; i--) {
putchar(temp[i - 1]);
}
putchar('\n');
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 7, 10, 11, 31, 22], ["-", 0, 52, 8, 9, 0, 7, 10, 11, 17, 32], ["-", 8, 9, 0, 7, 10, 11, 12, 2, 63, 22], ["-", 0, 7, 10, 11, 12, 2, 3, 4, 0, 24], ["-", 0, 7, 10, 11, 12, 2, 3, 4, 0, 22], ["-", 0, 7, 10, 11, 12, 2, 3, 4, 0, 25]]
| 0
| 135
| 6
|
#include <algorithm>
#include <cstdio>
using namespace std;
int main() {
int n;
while (scanf("%d", &n), n != -1) {
char adic[1000];
int i = 0;
if (n == 0)
printf("0\n");
else {
while (n > 0) {
adic[i] = n % 4 + '0';
n /= 4;
i++;
}
reverse(adic, adic + i);
printf("%s\n", adic);
}
}
return (0);
}
|
#include <algorithm>
#include <cstdio>
using namespace std;
int main() {
int n;
while (scanf("%d", &n), n != -1) {
char adic[1000] = {0};
int i = 0;
if (n == 0)
printf("0\n");
else {
while (n > 0) {
adic[i] = n % 4 + '0';
n /= 4;
i++;
}
reverse(adic, adic + i);
printf("%s\n", adic);
}
}
return (0);
}
|
[["+", 0, 52, 8, 9, 0, 43, 49, 50, 0, 32], ["+", 8, 9, 0, 43, 49, 50, 51, 83, 0, 45], ["+", 8, 9, 0, 43, 49, 50, 51, 83, 0, 13], ["+", 8, 9, 0, 43, 49, 50, 51, 83, 0, 46]]
| 1
| 115
| 4
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define pb(n) push_back(n)
#define mp(n, m) make_pair(n, m)
#define fi first
#define se second
#define all(r) (r).begin(), (r).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, a, b) for (int i = (a); i < (b); i++)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int IMAX = ((1 << 30) - 1) * 2 + 1;
const double EPS = 1e-10;
// int mod=1000000007
int n;
string s;
int main() {
while (cin >> n && n != -1) {
s = "";
int d = 1;
while (d * 4 < n)
d *= 4;
// cout<<n<<" "<<d<<endl;
for (int i = d; i > 0; i /= 4) {
s += (n / i + '0');
n %= i;
}
// s+=(n+'0');
cout << s << endl;
}
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define pb(n) push_back(n)
#define mp(n, m) make_pair(n, m)
#define fi first
#define se second
#define all(r) (r).begin(), (r).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, a, b) for (int i = (a); i < (b); i++)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int IMAX = ((1 << 30) - 1) * 2 + 1;
const double EPS = 1e-10;
// int mod=1000000007
int n;
string s;
int main() {
while (cin >> n && n != -1) {
s = "";
int d = 1;
while (d * 4 <= n)
d *= 4;
// cout<<n<<" "<<d<<endl;
for (int i = d; i > 0; i /= 4) {
s += (n / i + '0');
n %= i;
}
// s+=(n+'0');
cout << s << endl;
}
}
|
[["-", 8, 9, 0, 52, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 19]]
| 1
| 223
| 2
|
#include <cmath>
#include <iostream>
using namespace std;
int a, b[20], ok;
int main() {
while (true) {
ok = 0;
cin >> a;
if (a == -1) {
break;
}
for (int i = 0; i < 15; i++) {
b[i] = (a / (int)pow(4, i)) % 4;
}
for (int i = 14; i >= 0; i--) {
if (b[i] >= 1) {
ok = 1;
}
if (ok == 1 || i == 0) {
cout << b[i] << endl;
}
}
}
}
|
#include <cmath>
#include <iostream>
using namespace std;
int a, b[20], ok;
int main() {
while (true) {
ok = 0;
cin >> a;
if (a == -1) {
break;
}
for (int i = 0; i < 15; i++) {
b[i] = (a / (int)pow(4, i)) % 4;
}
for (int i = 14; i >= 0; i--) {
if (b[i] >= 1) {
ok = 1;
}
if (ok == 1 || i == 0) {
cout << b[i];
}
}
cout << endl;
}
}
|
[["-", 0, 57, 64, 9, 0, 1, 0, 16, 17, 151], ["-", 0, 57, 64, 9, 0, 1, 0, 16, 12, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 16, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 52, 8, 9, 0, 1, 0, 16, 12, 22], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 1
| 137
| 6
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a;
while (cin >> a, a >= 0) {
vector<int> ans;
if (a == 0)
ans.push_back(0);
while (a) {
ans.push_back(a % 4);
a /= 4;
}
reverse(ans.begin(), ans.end());
for (int i = 0; i < (int)ans.size(); i++)
cout << ans[i] << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a;
while (cin >> a, a >= 0) {
vector<int> ans;
if (a == 0)
ans.push_back(0);
while (a) {
ans.push_back(a % 4);
a /= 4;
}
reverse(ans.begin(), ans.end());
for (int i = 0; i < (int)ans.size(); i++)
cout << ans[i];
cout << endl;
}
}
|
[["+", 0, 52, 8, 9, 0, 7, 8, 1, 0, 35], ["+", 0, 52, 8, 9, 0, 1, 0, 16, 31, 22]]
| 1
| 110
| 2
|
#include <iostream>
using namespace std;
int main() {
int a, b, cou;
while (1) {
cin >> a;
if (a == -1)
break;
b = 4;
for (b = 4; b < a; b = b * 4)
;
b = b / 4;
while (1) {
cout << a / b;
a %= b;
if (b == 1)
break;
b = b / 4;
}
cout << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int a, b, cou;
while (1) {
cin >> a;
if (a == -1)
break;
b = 4;
for (b = 4; b <= a; b = b * 4)
;
b = b / 4;
while (1) {
cout << a / b;
a %= b;
if (b == 1)
break;
b = b / 4;
}
cout << endl;
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
| 1
| 101
| 2
|
#include <iostream>
#include <vector>
#define MAX_N 1000000
using namespace std;
int main() {
int n;
while (cin >> n) {
if (n == -1)
break;
vector<int> vec;
int shift = 0;
for (long int i = 3; i <= MAX_N; i = i << 2) {
int tmp = n & i;
for (int j = 0; j < shift; j++) {
tmp = tmp >> 2;
}
shift++;
vec.push_back(tmp);
}
int stop = vec.size() - 1;
while (vec[stop] == 0) {
stop--;
if (stop == 0)
break;
}
if (stop == 0) {
cout << "0" << endl;
} else {
for (int i = stop; i >= 0; i--) {
cout << vec[i];
}
cout << endl;
}
}
return 0;
}
|
#include <iostream>
#include <vector>
#define MAX_N 1000000
using namespace std;
int main() {
long int n;
while (cin >> n) {
if (n == -1)
break;
vector<int> vec;
int shift = 0;
for (long int i = 3; i <= MAX_N; i = i << 2) {
int tmp = n & i;
for (int j = 0; j < shift; j++) {
tmp = tmp >> 2;
}
shift++;
vec.push_back(tmp);
}
int stop = vec.size() - 1;
while (vec[stop] == 0) {
stop--;
if (stop < 0)
break;
}
if (stop < 0) {
cout << "0" << endl;
} else {
for (int i = stop; i >= 0; i--) {
cout << vec[i];
}
cout << endl;
}
}
return 0;
}
|
[["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18]]
| 1
| 188
| 5
|
#include <iostream>
using namespace std;
int main() {
int n;
while (cin >> n) {
if (n == -1)
break;
string s;
string temp;
for (int i = 0; n >> i; i += 2) {
temp += ((char)(n >> i) % 4) + '0';
}
if (temp.empty())
temp = "0";
for (int i = temp.size() - 1; i >= 0; --i)
s += temp[i];
cout << s << "\n";
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int n;
while (cin >> n) {
if (n == -1)
break;
string s;
string temp;
for (int i = 0; n >> i; i += 2) {
temp += (char)((n >> i) % 4) + '0';
}
if (temp.empty())
temp = "0";
for (int i = temp.size() - 1; i >= 0; --i)
s += temp[i];
cout << s << "\n";
}
return 0;
}
|
[["-", 12, 16, 31, 23, 0, 16, 31, 74, 0, 24], ["+", 0, 11, 12, 16, 31, 74, 51, 23, 0, 24]]
| 1
| 125
| 2
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
int n;
vector<int> num;
while (cin >> n) {
if (n == 0) {
cout << 0 << endl;
continue;
}
for (int i = 0; n > 0; i++) {
num.push_back(n % 4);
n /= 4;
}
for (int i = num.size() - 1; i >= 0; i--)
cout << num[i];
cout << endl;
num.clear();
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
int n;
vector<int> num;
while (cin >> n, ~n) {
if (n == 0) {
cout << 0 << endl;
continue;
}
for (int i = 0; n > 0; i++) {
num.push_back(n % 4);
n /= 4;
}
for (int i = num.size() - 1; i >= 0; i--)
cout << num[i];
cout << endl;
num.clear();
}
return 0;
}
|
[["+", 8, 9, 0, 52, 15, 339, 51, 34, 0, 21], ["+", 0, 52, 15, 339, 51, 34, 12, 91, 17, 92], ["+", 0, 52, 15, 339, 51, 34, 12, 91, 28, 22]]
| 1
| 119
| 3
|
#include <stdio.h>
int main() {
long int a, b, c[1024] = {0}, i, j;
scanf("%ld\n", &a);
do {
i = 0;
if (a == 0) {
printf("%ld\n", a);
} else if (a != -1) {
b = a;
do {
a = b % 4;
b /= 4;
c[i++] = a;
// printf("%d",a);
} while (b > 3);
if (b != 0)
c[i] = b;
for (j = i; j >= 0; j--) {
printf("%ld", c[j]);
}
printf("\n");
} else {
break;
}
scanf("%ld\n", &a);
} while (1);
return 0;
}
|
#include <stdio.h>
int main() {
long int a, b, c[1024] = {0}, i, j;
scanf("%ld\n", &a);
do {
i = 0;
if (a >= 0 && a <= 3) {
printf("%ld\n", a);
} else if (a != -1) {
b = a;
do {
a = b % 4;
b /= 4;
c[i++] = a;
// printf("%d",a);
} while (b > 3);
if (b != 0)
c[i] = b;
for (j = i; j >= 0; j--) {
printf("%ld", c[j]);
}
printf("\n");
} else {
break;
}
scanf("%ld\n", &a);
} while (1);
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 98], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 19], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
| 1
| 176
| 6
|
#include <stdio.h>
int main(void) {
int keta, n, i;
int kai[10000];
while (0 == 0) {
scanf("%d", &n);
keta = 0;
if (n == -1)
break;
while (n > 4) {
kai[keta] = n % 4;
n = n / 4;
keta++;
}
kai[keta] = n;
for (i = keta; i > 0; i--)
printf("%d", kai[i]);
printf("%d\n", kai[0]);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int keta, n, i;
int kai[100000];
while (0 == 0) {
scanf("%d", &n);
keta = 0;
if (n == -1)
break;
while (n > 3) {
kai[keta] = n % 4;
n = n / 4;
keta++;
}
kai[keta] = n;
for (i = keta; i > 0; i--)
printf("%d", kai[i]);
printf("%d\n", kai[0]);
}
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["-", 8, 9, 0, 52, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 12, 13]]
| 1
| 126
| 4
|
while(n=gets.to_i)>-1
p n.to_s(4)end
|
while(n=gets.to_i)>-1
puts n.to_s(4)end
|
[["-", 0, 493, 0, 89, 8, 170, 0, 652, 735, 22], ["+", 0, 493, 0, 89, 8, 170, 0, 652, 735, 22]]
| 4
| 19
| 2
|
<?php
$ref = array(
'black' => array(0, 0, 0),
'blue' => array(0, 0, 255),
'lime' => array(0, 255, 0),
'aqua' => array(0, 255, 255),
'red' => array(255, 0, 0),
'fuchsia' => array(255, 0, 255),
'yellow' => array(255, 0, 0),
'white' => array(255, 255, 255),
);
while ($line = trim(fgets(STDIN))) {
$r = hexdec(substr($line, 1, 2));
$g = hexdec(substr($line, 3, 2));
$b = hexdec(substr($line, 5, 2));
$d2 = PHP_INT_MAX;
$color = '';
foreach ($ref as $name => $c) {
$dtmp = ($r - $c[0]) * ($r - $c[0]) + ($g - $c[1]) * ($g - $c[1]) + ($b - $c[2]) * ($b - $c[2]);
if ($dtmp < $d2) {
$color = $name;
$d2 = $dtmp;
}
}
echo $color . "\n";
}
|
<?php
$ref = array(
'black' => array(0, 0, 0),
'blue' => array(0, 0, 255),
'lime' => array(0, 255, 0),
'aqua' => array(0, 255, 255),
'red' => array(255, 0, 0),
'fuchsia' => array(255, 0, 255),
'yellow' => array(255, 255, 0),
'white' => array(255, 255, 255),
);
while ($line = trim(fgets(STDIN))) {
$r = hexdec(substr($line, 1, 2));
$g = hexdec(substr($line, 3, 2));
$b = hexdec(substr($line, 5, 2));
$d2 = PHP_INT_MAX;
$color = '';
foreach ($ref as $name => $c) {
$dtmp = ($r - $c[0]) * ($r - $c[0]) + ($g - $c[1]) * ($g - $c[1]) + ($b - $c[2]) * ($b - $c[2]);
if ($dtmp < $d2) {
$color = $name;
$d2 = $dtmp;
}
}
echo $color . "\n";
}
|
[["-", 12, 227, 0, 618, 0, 227, 0, 618, 0, 612], ["+", 12, 227, 0, 618, 0, 227, 0, 618, 0, 612]]
| 6
| 298
| 2
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
int[][] color = {{0, 0, 0}, {0, 0, 255}, {0, 255, 0},
{0, 255, 255}, {255, 0, 0}, {255, 0, 255},
{255, 255, 0}, {255, 255, 255}};
String[] name = {"black", "blue", "lime", "aqua",
"red", "fuchsia", "yellow", "white"};
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
String str = sc.nextLine();
if (str.equals("0"))
break;
String ans = "";
double max = 0;
for (int i = 0; i < 8; i++) {
double d = Math.sqrt(
(Integer.parseInt(str.substring(1, 3), 16) - color[i][0]) *
(Integer.parseInt(str.substring(1, 3), 16) - color[i][0]) +
(Integer.parseInt(str.substring(3, 5), 16) - color[i][1]) *
(Integer.parseInt(str.substring(3, 5), 16) - color[i][1]) +
(Integer.parseInt(str.substring(5, 7), 16) - color[i][2]) *
(Integer.parseInt(str.substring(5, 7), 16) - color[i][2]));
if (d > max) {
max = d;
ans = name[i];
}
}
System.out.println(ans);
}
}
}
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
int[][] color = {{0, 0, 0}, {0, 0, 255}, {0, 255, 0},
{0, 255, 255}, {255, 0, 0}, {255, 0, 255},
{255, 255, 0}, {255, 255, 255}};
String[] name = {"black", "blue", "lime", "aqua",
"red", "fuchsia", "yellow", "white"};
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
String str = sc.nextLine();
if (str.equals("0"))
break;
String ans = "";
double max = 0;
for (int i = 0; i < 8; i++) {
double d = Math.sqrt(
(Integer.parseInt(str.substring(1, 3), 16) - color[i][0]) *
(Integer.parseInt(str.substring(1, 3), 16) - color[i][0]) +
(Integer.parseInt(str.substring(3, 5), 16) - color[i][1]) *
(Integer.parseInt(str.substring(3, 5), 16) - color[i][1]) +
(Integer.parseInt(str.substring(5, 7), 16) - color[i][2]) *
(Integer.parseInt(str.substring(5, 7), 16) - color[i][2]));
if (d > max) {
max = d;
ans = name[7 - i];
}
}
System.out.println(ans);
}
}
}
|
[["+", 0, 1, 0, 11, 12, 504, 71, 16, 31, 499], ["+", 0, 1, 0, 11, 12, 504, 71, 16, 17, 33]]
| 3
| 400
| 2
|
import java.lang.*;
import java.math.*;
import java.util.*;
public class Main {
Scanner sc = new Scanner(System.in);
class color {
int r, g, b;
String s;
color(int value, String s) {
r = value >> 16;
g = (value >> 8) & 255;
b = value & 255;
this.s = s;
}
int diff(color c) {
return ((c.r - r) * (c.r - r) + (c.b - b) * (c.b - b) +
(c.g - g) * (c.g - g));
}
}
void run() {
color db[] = {
new color(0, "black"), new color(0, "blue"), new color(0, "lime"),
new color(0, "aqua"), new color(0, "red"), new color(0, "funchsia"),
new color(0, "yellow"), new color(0, "white"),
};
db[1].b = 0xff;
db[2].g = 0xff;
db[3].g = 0xff;
db[3].b = 0xff;
db[4].r = 0xff;
db[5].b = 0xff;
db[5].r = 0xff;
db[6].g = 0xff;
db[6].r = 0xff;
db[7].r = 0xff;
db[7].b = 0xff;
db[7].g = 0xff;
for (;;) {
String buffer = sc.next();
if (buffer.equals("0")) {
break;
}
Scanner in = new Scanner(buffer.substring(1));
int value = in.nextInt(16);
color ti = new color(value, "");
int max = Integer.MAX_VALUE >> 1;
String ret = "";
for (color t : db) {
if (max > t.diff(ti)) {
max = t.diff(ti);
ret = t.s;
}
}
System.out.println(ret);
}
}
public static void main(String[] args) {
Main m = new Main();
m.run();
}
}
|
import java.lang.*;
import java.math.*;
import java.util.*;
public class Main {
Scanner sc = new Scanner(System.in);
class color {
int r, g, b;
String s;
color(int value, String s) {
r = value >> 16;
g = (value >> 8) & 255;
b = value & 255;
this.s = s;
}
int diff(color c) {
return ((c.r - r) * (c.r - r) + (c.b - b) * (c.b - b) +
(c.g - g) * (c.g - g));
}
}
void run() {
color db[] = {
new color(0, "black"), new color(0, "blue"), new color(0, "lime"),
new color(0, "aqua"), new color(0, "red"), new color(0, "fuchsia"),
new color(0, "yellow"), new color(0, "white"),
};
db[1].b = 0xff;
db[2].g = 0xff;
db[3].g = 0xff;
db[3].b = 0xff;
db[4].r = 0xff;
db[5].b = 0xff;
db[5].r = 0xff;
db[6].g = 0xff;
db[6].r = 0xff;
db[7].r = 0xff;
db[7].b = 0xff;
db[7].g = 0xff;
for (;;) {
String buffer = sc.next();
if (buffer.equals("0")) {
break;
}
Scanner in = new Scanner(buffer.substring(1));
int value = in.nextInt(16);
color ti = new color(value, "");
int max = Integer.MAX_VALUE >> 1;
String ret = "";
for (color t : db) {
if (max > t.diff(ti)) {
max = t.diff(ti);
ret = t.s;
}
}
System.out.println(ret);
}
}
public static void main(String[] args) {
Main m = new Main();
m.run();
}
}
|
[["-", 51, 518, 0, 230, 3, 4, 0, 5, 0, 491], ["+", 51, 518, 0, 230, 3, 4, 0, 5, 0, 491]]
| 3
| 504
| 2
|
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.concurrent.LinkedBlockingDeque;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int colors[][] = {
{0, 0, 0}, {0, 0, 255}, {0, 255, 0}, {0, 255, 255},
{255, 0, 0}, {255, 0, 255}, {0, 255, 255}, {255, 255, 255},
};
String[] names = {"black", "blue", "lime", "aqua",
"red", "fuchsia", "yellow", "white"};
while (true) {
String str = sc.next();
if ("0".equals(str)) {
break;
}
int r = Integer.parseInt(str.substring(1, 3), 16);
int g = Integer.parseInt(str.substring(3, 5), 16);
int b = Integer.parseInt(str.substring(5, 7), 16);
double min = Integer.MAX_VALUE;
int min_num = -1;
for (int i = 0; i < 8; i++) {
double d = Math.sqrt((colors[i][0] - r) * (colors[i][0] - r) +
(colors[i][1] - g) * (colors[i][1] - g) +
(colors[i][2] - b) * (colors[i][2] - b));
if (min > d) {
min = d;
min_num = i;
}
}
System.out.println(names[min_num]);
}
}
}
|
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.concurrent.LinkedBlockingDeque;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int colors[][] = {
{0, 0, 0}, {0, 0, 255}, {0, 255, 0}, {0, 255, 255},
{255, 0, 0}, {255, 0, 255}, {255, 255, 0}, {255, 255, 255},
};
String[] names = {"black", "blue", "lime", "aqua",
"red", "fuchsia", "yellow", "white"};
while (true) {
String str = sc.next();
if ("0".equals(str)) {
break;
}
int r = Integer.parseInt(str.substring(1, 3), 16);
int g = Integer.parseInt(str.substring(3, 5), 16);
int b = Integer.parseInt(str.substring(5, 7), 16);
double min = Integer.MAX_VALUE;
int min_num = -1;
for (int i = 0; i < 8; i++) {
double d = Math.sqrt((colors[i][0] - r) * (colors[i][0] - r) +
(colors[i][1] - g) * (colors[i][1] - g) +
(colors[i][2] - b) * (colors[i][2] - b));
if (min > d) {
min = d;
min_num = i;
}
}
System.out.println(names[min_num]);
}
}
}
|
[["-", 0, 503, 49, 200, 51, 518, 0, 518, 0, 499], ["-", 0, 503, 49, 200, 51, 518, 0, 518, 0, 21], ["+", 0, 503, 49, 200, 51, 518, 0, 518, 0, 21], ["+", 0, 503, 49, 200, 51, 518, 0, 518, 0, 499]]
| 3
| 395
| 4
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>
//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else
//#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long>> vvll, vvLL;
#define VV(T) vector<vector<T>>
template <class T>
void initvv(vector<vector<T>> &v, int a, int b, const T &t = T()) {
v.assign(a, vector<T>(b, t));
}
template <class F, class T> void convert(const F &f, T &t) {
stringstream ss;
ss << f;
ss >> t;
}
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) reep((i), 0, (n))
#define ALL(v) (v).begin(), (v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(), (v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x) cout << #x << " = " << (x) << endl;
#define debug(x) \
cout << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
#else
#define dump(x)
#define debug(x)
#endif
#define LDcout(x, n) fixed << setprecision(n) << x
#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x, y) x = max(x, y)
#define mins(x, y) x = min(x, y)
int foo(int a, int b, int c) {
int t = a * a + b * b + c * c;
return t;
}
void mainmain() {
vector<string> v;
v.PB("black");
v.PB("blue");
v.PB("lime");
v.PB("aqua");
v.PB("red");
v.PB("fuchsia");
v.PB("yellow");
v.PB("white");
string s;
while (cin >> s) {
if (s.size() == 1)
return;
vint w(3, 0);
rep(i, 3) {
string tmp = s.substr(1 + i * 2, 2);
if (isdigit(tmp[0]))
w[i] = 16 * (tmp[0] - '0');
else {
w[i] = 16 * (tmp[0] - 'a' + 10);
}
if (isdigit(tmp[1]))
w[i] += (tmp[1] - '0');
else {
w[i] += (tmp[1] - 'a' + 10);
}
}
// cout<<w[0]<<" "<<w[1]<<" "<<w[2]<<endl;
vector<pii> vv(8);
rep(i, 8) {
vint tmp(3);
rep(j, 3) {
if ((1 << j) & i)
tmp[j] = 255;
else
tmp[j] = 0;
}
vv[i].S = i;
vv[i].F = foo(w[0] - tmp[0], w[1] - tmp[1], w[2] - tmp[2]);
}
sort(ALL(vv));
cout << v[vv[0].S] << endl;
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(20);
mainmain();
}
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>
//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else
//#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long>> vvll, vvLL;
#define VV(T) vector<vector<T>>
template <class T>
void initvv(vector<vector<T>> &v, int a, int b, const T &t = T()) {
v.assign(a, vector<T>(b, t));
}
template <class F, class T> void convert(const F &f, T &t) {
stringstream ss;
ss << f;
ss >> t;
}
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) reep((i), 0, (n))
#define ALL(v) (v).begin(), (v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(), (v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x) cout << #x << " = " << (x) << endl;
#define debug(x) \
cout << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
#else
#define dump(x)
#define debug(x)
#endif
#define LDcout(x, n) fixed << setprecision(n) << x
#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x, y) x = max(x, y)
#define mins(x, y) x = min(x, y)
int foo(int a, int b, int c) {
int t = a * a + b * b + c * c;
return t;
}
void mainmain() {
vector<string> v;
v.PB("black");
v.PB("blue");
v.PB("lime");
v.PB("aqua");
v.PB("red");
v.PB("fuchsia");
v.PB("yellow");
v.PB("white");
string s;
while (cin >> s) {
if (s.size() == 1)
return;
vint w(3, 0);
rep(i, 3) {
string tmp = s.substr(1 + i * 2, 2);
if (isdigit(tmp[0]))
w[i] = 16 * (tmp[0] - '0');
else {
w[i] = 16 * (tmp[0] - 'a' + 10);
}
if (isdigit(tmp[1]))
w[i] += (tmp[1] - '0');
else {
w[i] += (tmp[1] - 'a' + 10);
}
}
vector<pii> vv(8);
rep(i, 8) {
vint tmp(3);
rep(j, 3) {
if ((1 << j) & i)
tmp[2 - j] = 255;
else
tmp[2 - j] = 0;
}
vv[i].S = i;
vv[i].F = foo(w[0] - tmp[0], w[1] - tmp[1], w[2] - tmp[2]);
}
sort(ALL(vv));
cout << v[vv[0].S] << endl;
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(20);
mainmain();
}
|
[["+", 0, 11, 31, 69, 341, 342, 0, 16, 31, 13], ["+", 0, 11, 31, 69, 341, 342, 0, 16, 17, 33]]
| 1
| 770
| 4
|
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
int to_int(string s) {
int k = 1, res = 0;
for (int i = s.size() - 1; i >= 0; i--) {
if ('0' <= s[i] && s[i] <= '9') {
res += k * (s[i] - '0');
} else {
res += k * (s[i] - 'a' + 10);
}
k *= 16;
}
return res;
}
int main() {
string ans[2][2][2];
ans[0][0][0] = "black";
ans[0][0][1] = "blue";
ans[0][1][0] = "lime";
ans[0][1][1] = "aqua";
ans[1][0][0] = "red";
ans[1][0][1] = "fuchsia";
ans[1][1][0] = "yellow";
ans[1][1][1] = "white";
string s;
while (cin >> s && s[0] != '0') {
int a, b, c, dat[3];
for (int i = 1; i < 6; i += 2) {
string tmp;
int ans[3];
tmp.assign(s, i, 2);
int d = to_int(tmp);
if (d <= (to_int("ff") - d))
ans[i / 2] = 0;
else
ans[i / 2] = 1;
}
cout << ans[dat[0]][dat[1]][dat[2]] << endl;
}
}
|
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
int to_int(string s) {
int k = 1, res = 0;
for (int i = s.size() - 1; i >= 0; i--) {
if ('0' <= s[i] && s[i] <= '9') {
res += k * (s[i] - '0');
} else {
res += k * (s[i] - 'a' + 10);
}
k *= 16;
}
return res;
}
int main() {
string ans[2][2][2];
ans[0][0][0] = "black";
ans[0][0][1] = "blue";
ans[0][1][0] = "lime";
ans[0][1][1] = "aqua";
ans[1][0][0] = "red";
ans[1][0][1] = "fuchsia";
ans[1][1][0] = "yellow";
ans[1][1][1] = "white";
string s;
while (cin >> s && s[0] != '0') {
int a, b, c, dat[3];
for (int i = 1; i < 6; i += 2) {
string tmp;
int ans[3];
tmp.assign(s, i, 2);
int d = to_int(tmp);
if (d <= (to_int("ff") - d))
dat[i / 2] = 0;
else
dat[i / 2] = 1;
}
cout << ans[dat[0]][dat[1]][dat[2]] << endl;
}
}
|
[["-", 0, 57, 64, 1, 0, 11, 31, 69, 28, 22], ["+", 0, 57, 64, 1, 0, 11, 31, 69, 28, 22], ["-", 75, 76, 0, 1, 0, 11, 31, 69, 28, 22], ["+", 75, 76, 0, 1, 0, 11, 31, 69, 28, 22]]
| 1
| 393
| 4
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define pb push_back
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define dep(i, a, n) for (int i = (a); i >= (n); i--)
#define mod 1e9 + 7
__attribute__((constructor)) void initial() {
cin.tie(0);
ios::sync_with_stdio(false);
}
int hen(char a) {
if ((int)a - 48 >= 0 && (int)a - 48 < 10)
return (int)a - 48;
if (a == 'a')
return 10;
else if (a == 'b')
return 11;
else if (a == 'c')
return 12;
else if (a == 'd')
return 13;
else if (a == 'e')
return 14;
else
return 15;
}
int main() {
string s;
while (cin >> s) {
if (s == "0")
return 0;
int r = hen(s[1]) * 16 + hen(s[2]);
int g = hen(s[3]) * 16 + hen(s[4]);
int b = hen(s[5]) * 16 + hen(s[6]);
int ans = INT_MAX;
string mans;
if (r * r + g * g + b * b < ans)
ans = r * r + g * g + b * b, mans = "brack";
if (r * r + g * g + (b - 255) * (b - 255) < ans)
ans = r * r + g * g + (b - 255) * (b - 255), mans = "blue";
if (r * r + (g - 255) * (g - 255) + b * b < ans)
ans = r * r + (g - 255) * (g - 255) + b * b, mans = "lime";
if (r * r + (g - 255) * (g - 255) + (b - 255) * (b - 255) < ans)
ans = r * r + (g - 255) * (g - 255) + (b - 255) * (b - 255),
mans = " aqua";
if ((r - 255) * (r - 255) + g * g + b * b < ans)
ans = (r - 255) * (r - 255) + g * g + b * b, mans = "red";
if ((r - 255) * (r - 255) + g * g + (b - 255) * (b - 255) < ans)
ans = (r - 255) * (r - 255) + g * g + (b - 255) * (b - 255),
mans = "fuchsia";
if ((r - 255) * (r - 255) + (g - 255) * (g - 255) + b * b < ans)
ans = (r - 255) * (r - 255) + (g - 255) * (g - 255) + b * b,
mans = "yello";
if ((r - 255) * (r - 255) + (g - 255) * (g - 255) + (b - 255) * (b - 255) <
ans)
ans =
(r - 255) * (r - 255) + (g - 255) * (g - 255) + (b - 255) * (b - 255),
mans = "white";
cout << mans << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define pb push_back
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define dep(i, a, n) for (int i = (a); i >= (n); i--)
#define mod 1e9 + 7
__attribute__((constructor)) void initial() {
cin.tie(0);
ios::sync_with_stdio(false);
}
int hen(char a) {
if ((int)a - 48 >= 0 && (int)a - 48 < 10)
return (int)a - 48;
if (a == 'a')
return 10;
else if (a == 'b')
return 11;
else if (a == 'c')
return 12;
else if (a == 'd')
return 13;
else if (a == 'e')
return 14;
else
return 15;
}
int main() {
string s;
while (cin >> s) {
if (s == "0")
return 0;
int r = hen(s[1]) * 16 + hen(s[2]);
int g = hen(s[3]) * 16 + hen(s[4]);
int b = hen(s[5]) * 16 + hen(s[6]);
int ans = INT_MAX;
string mans;
if (r * r + g * g + b * b < ans)
ans = r * r + g * g + b * b, mans = "black";
if (r * r + g * g + (b - 255) * (b - 255) < ans)
ans = r * r + g * g + (b - 255) * (b - 255), mans = "blue";
if (r * r + (g - 255) * (g - 255) + b * b < ans)
ans = r * r + (g - 255) * (g - 255) + b * b, mans = "lime";
if (r * r + (g - 255) * (g - 255) + (b - 255) * (b - 255) < ans)
ans = r * r + (g - 255) * (g - 255) + (b - 255) * (b - 255),
mans = "aqua";
if ((r - 255) * (r - 255) + g * g + b * b < ans)
ans = (r - 255) * (r - 255) + g * g + b * b, mans = "red";
if ((r - 255) * (r - 255) + g * g + (b - 255) * (b - 255) < ans)
ans = (r - 255) * (r - 255) + g * g + (b - 255) * (b - 255),
mans = "fuchsia";
if ((r - 255) * (r - 255) + (g - 255) * (g - 255) + b * b < ans)
ans = (r - 255) * (r - 255) + (g - 255) * (g - 255) + b * b,
mans = "yellow";
if ((r - 255) * (r - 255) + (g - 255) * (g - 255) + (b - 255) * (b - 255) <
ans)
ans =
(r - 255) * (r - 255) + (g - 255) * (g - 255) + (b - 255) * (b - 255),
mans = "white";
cout << mans << endl;
}
}
|
[["-", 64, 1, 0, 34, 12, 11, 12, 5, 0, 6], ["+", 64, 1, 0, 34, 12, 11, 12, 5, 0, 6]]
| 1
| 756
| 6
|
import java.io.*;
import java.util.*;
public class Main {
static ArrayList<Integer> list = new ArrayList<Integer>();
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
makePrimeList();
while (true) {
int n = sc.nextInt();
if (n == 0)
break;
int sum = 0;
for (int i = 0; i < n; i++) {
int p = sc.nextInt();
int m = sc.nextInt();
if (m == 0) {
if (Collections.binarySearch(list, m) < 0) {
sum -= 1;
}
continue;
} else {
int min = Collections.binarySearch(list, p - m);
if (min < 0) {
min *= -1;
min -= 1;
}
int max = Collections.binarySearch(list, p + m);
if (max < 0) {
max *= -1;
max -= 2;
}
sum += max - min;
}
}
System.out.println(sum);
}
}
static void makePrimeList() {
boolean[] isntPrime = new boolean[1000000];
int i = 2;
for (; i * i < isntPrime.length; i++) {
if (!isntPrime[i]) {
list.add(i);
for (int j = i + i; j < isntPrime.length; j += i) {
isntPrime[j] = true;
}
}
}
for (; i < isntPrime.length; i++) {
if (!isntPrime[i]) {
list.add(i);
}
}
}
}
|
import java.io.*;
import java.util.*;
public class Main {
static ArrayList<Integer> list = new ArrayList<Integer>();
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
makePrimeList();
while (true) {
int n = sc.nextInt();
if (n == 0)
break;
int sum = 0;
for (int i = 0; i < n; i++) {
int p = sc.nextInt();
int m = sc.nextInt();
if (m == 0) {
if (Collections.binarySearch(list, p) < 0) {
sum -= 1;
}
continue;
} else {
int min = Collections.binarySearch(list, p - m);
if (min < 0) {
min *= -1;
min -= 1;
}
int max = Collections.binarySearch(list, p + m);
if (max < 0) {
max *= -1;
max -= 2;
}
sum += max - min;
}
}
System.out.println(sum);
}
}
static void makePrimeList() {
boolean[] isntPrime = new boolean[1000000];
int i = 2;
for (; i * i < isntPrime.length; i++) {
if (!isntPrime[i]) {
list.add(i);
for (int j = i + i; j < isntPrime.length; j += i) {
isntPrime[j] = true;
}
}
}
for (; i < isntPrime.length; i++) {
if (!isntPrime[i]) {
list.add(i);
}
}
}
}
|
[["-", 15, 15, 0, 16, 31, 492, 3, 4, 0, 22], ["+", 15, 15, 0, 16, 31, 492, 3, 4, 0, 22]]
| 3
| 347
| 2
|
#define M 999999
P[M], N[M];
main(i, j, k, r, n, p, m) {
for (P[0] = P[1] = 1, i = 2; i < M; i++)
if (!P[i])
for (j = i * 2; j < M; j += i)
P[j] = 1;
for (i = 1; i < M; i++)
N[i] = N[i - 1] + !P[i];
for (; scanf("%d", &n), n; printf("%d\n", r))
for (r = -n, i = 0; i < n; i++) {
scanf("%d%d", &p, &m);
j = p - m - 1;
if (j < 2)
j = 2;
k = p + m;
if (k >= M)
k = M - 1;
r += N[k] - N[j];
}
}
|
#define M 999999
P[M], N[M];
main(i, j, k, r, n, p, m) {
for (P[0] = P[1] = 1, i = 2; i < M; i++)
if (!P[i])
for (j = i * 2; j < M; j += i)
P[j] = 1;
for (i = 1; i < M; i++)
N[i] = N[i - 1] + !P[i];
for (; scanf("%d", &n), n; printf("%d\n", r))
for (r = -n, i = 0; i < n; i++) {
scanf("%d%d", &p, &m);
j = p - m - 1;
if (j < 0)
j = 0;
k = p + m;
if (k >= M)
k = M - 1;
r += N[k] - N[j];
}
}
|
[["-", 8, 9, 0, 57, 15, 23, 0, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 12, 13], ["-", 8, 9, 0, 57, 64, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 57, 64, 1, 0, 11, 12, 13]]
| 0
| 225
| 4
|
#include <algorithm>
#include <iostream>
using namespace std;
int n, m, p, prime[1000009], s[1000009];
int main() {
fill(prime + 2, prime + 1000000, 1);
for (int i = 2; i < 1000; i++) {
if (!prime[i])
continue;
for (int j = i * i; j < 1000000; j += i)
prime[j] = 0;
}
for (int i = 2; i < 1000009; i++)
s[i] = s[i - 1] + prime[i];
while (cin >> n, n) {
int ret = 0;
for (int i = 0; i < n; i++) {
cin >> p >> m;
ret += s[min(p + m + 1, 1000000)] - s[max(p - m, 0)] - 1;
}
cout << ret << endl;
}
}
|
#include <algorithm>
#include <iostream>
using namespace std;
int n, m, p, prime[1000009], s[1000009];
int main() {
fill(prime + 2, prime + 1000000, 1);
for (int i = 2; i < 1000; i++) {
if (!prime[i])
continue;
for (int j = i * i; j < 1000000; j += i)
prime[j] = 0;
}
for (int i = 2; i < 1000009; i++)
s[i] = s[i - 1] + prime[i];
while (cin >> n, n) {
int ret = 0;
for (int i = 0; i < n; i++) {
cin >> p >> m;
ret += s[min(p + m, 1000000)] - s[max(p - m - 1, 0)] - 1;
}
cout << ret << endl;
}
}
|
[["-", 341, 342, 0, 2, 3, 4, 0, 16, 17, 72], ["-", 341, 342, 0, 2, 3, 4, 0, 16, 12, 13], ["+", 341, 342, 0, 2, 3, 4, 0, 16, 17, 33], ["+", 341, 342, 0, 2, 3, 4, 0, 16, 12, 13]]
| 1
| 198
| 4
|
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.io.*;
import java.lang.*;
import java.math.*;
import java.util.*;
// AC
public class Main {
Scanner sc = new Scanner(System.in);
int INF = 1 << 28;
double EPS = 1e-9;
void run() {
for (;;) {
double[] area = new double[2];
for (int j = 0; j < 2; j++) {
int m = sc.nextInt();
if (m == 0) {
break;
}
int sum = 0;
for (int i = 0; i < m - 1; i++) {
int deg = sc.nextInt();
area[j] += Math.sin(Math.toRadians(deg)) / 2;
sum += deg;
}
area[j] += Math.sin(Math.toRadians(360 - sum)) / 2;
}
if (area[0] > area[1] + EPS) {
println("1");
} else if (area[0] + EPS < area[1]) {
println("2");
} else {
println("0");
}
}
}
void debug(Object... os) { System.err.println(Arrays.deepToString(os)); }
void print(String s) { System.out.print(s); }
void println(String s) { System.out.println(s); }
public static void main(String[] args) {
// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
new Main().run();
}
}
|
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.io.*;
import java.lang.*;
import java.math.*;
import java.util.*;
// AC
public class Main {
Scanner sc = new Scanner(System.in);
int INF = 1 << 28;
double EPS = 1e-9;
void run() {
for (;;) {
double[] area = new double[2];
for (int j = 0; j < 2; j++) {
int m = sc.nextInt();
if (m == 0) {
return;
}
int sum = 0;
for (int i = 0; i < m - 1; i++) {
int deg = sc.nextInt();
area[j] += Math.sin(Math.toRadians(deg)) / 2;
sum += deg;
}
area[j] += Math.sin(Math.toRadians(360 - sum)) / 2;
}
if (area[0] > area[1] + EPS) {
println("1");
} else if (area[0] + EPS < area[1]) {
println("2");
} else {
println("0");
}
}
}
void debug(Object... os) { System.err.println(Arrays.deepToString(os)); }
void print(String s) { System.out.print(s); }
void println(String s) { System.out.println(s); }
public static void main(String[] args) {
// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
new Main().run();
}
}
|
[["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38]]
| 3
| 348
| 2
|
// Aizu Vol-1 0166: Area of Polygon
// 2017.8.8
#include <math.h>
#include <stdio.h>
#define M 0.00872664625997164788461845384244
#define EPS 1e-8
int main() {
int i, n, v;
double s[2];
int a[2];
while (1) {
i = 2;
while (i-- > 0) {
s[i] = a[i] = 0;
scanf("%d", &n);
if (n == 0)
return 0;
while (--n > 0) {
scanf("%d", &v);
a[i] += v;
s[i] += sin(M * v) * cos(M * v);
}
v = 360 - a[i];
s[i] += sin(M * v) * cos(M * v);
}
if (fabs(s[0] - s[1]) <= EPS)
putchar('0');
else if (s[0] >= s[1])
putchar('1');
else
putchar('2');
putchar('\n');
}
return 0;
}
|
// Aizu Vol-1 0166: Area of Polygon
// 2017.8.8
#include <math.h>
#include <stdio.h>
#define M 0.00872664625997164788461845384244
#define EPS 1e-8
int main() {
int i, n, v;
double s[2];
int a[2];
while (1) {
i = 2;
while (i-- > 0) {
s[i] = a[i] = 0;
scanf("%d", &n);
if (n == 0)
return 0;
while (--n > 0) {
scanf("%d", &v);
a[i] += v;
s[i] += sin(M * v) * cos(M * v);
}
v = 360 - a[i];
s[i] += sin(M * v) * cos(M * v);
}
if (fabs(s[0] - s[1]) <= EPS)
putchar('0');
else if (s[0] >= s[1])
putchar('2');
else
putchar('1');
putchar('\n');
}
return 0;
}
|
[["-", 64, 1, 0, 2, 3, 4, 0, 103, 0, 125], ["+", 64, 1, 0, 2, 3, 4, 0, 103, 0, 125], ["-", 0, 1, 0, 2, 3, 4, 0, 103, 0, 125], ["+", 0, 1, 0, 2, 3, 4, 0, 103, 0, 125]]
| 0
| 222
| 4
|
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int n, i;
double ang, deg, a[2];
int main() {
while (1) {
for (i = 0; i < 2; i++) {
scanf("%d", &n);
if (n == 0)
break;
a[i] = 0;
for (ang = 360; n > 1; n--) {
scanf("%lf", °);
ang -= deg;
deg = deg / 180 * 3.1415926535897932384626433832795;
a[i] += cos(deg / 2) * sin(deg / 2);
}
ang = ang / 180 * 3.1415926535897932384626433832795;
a[i] += cos(ang / 2) * sin(ang / 2);
}
if (i == 0)
break;
if (a[0] > a[1])
printf("--1\n");
else if (a[0] < a[1])
printf("--2\n");
else
printf("--0\n");
}
return 0;
}
|
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int n, i;
double ang, deg, a[2];
int main() {
while (1) {
for (i = 0; i < 2; i++) {
scanf("%d", &n);
if (n == 0)
break;
a[i] = 0;
for (ang = 360; n > 1; n--) {
scanf("%lf", °);
ang -= deg;
deg = deg / 180 * 3.1415926535897932384626433832795;
a[i] += cos(deg / 2) * sin(deg / 2);
}
ang = ang / 180 * 3.1415926535897932384626433832795;
a[i] += cos(ang / 2) * sin(ang / 2);
}
if (i == 0)
break;
if (a[0] > a[1])
printf("1\n");
else if (a[0] < a[1])
printf("2\n");
else
printf("0\n");
}
return 0;
}
|
[["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 0
| 217
| 6
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double ESP = 1e-12;
using namespace std;
int main() {
int n;
while (cin >> n, n) {
double m1, m2;
int m = 360;
rep(i, n - 1) {
int tmp;
cin >> tmp;
m -= tmp;
m1 += sin(PI * tmp / 180.0);
}
m1 += sin(PI * m / 180.0);
cin >> n;
m = 360;
rep(i, n - 1) {
int tmp;
cin >> tmp;
m -= tmp;
m2 += sin(PI * tmp / 180.0);
}
m2 += sin(PI * m / 180.0);
if (abs(m1 - m2) < ESP)
cout << 0 << endl;
else if (m1 > m2)
cout << 1 << endl;
else
cout << 2 << endl;
}
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double ESP = 1e-8;
using namespace std;
int main() {
int n;
while (cin >> n, n) {
double m1 = 0, m2 = 0;
int m = 360;
rep(i, n - 1) {
int tmp;
cin >> tmp;
m -= tmp;
m1 += sin(PI * tmp / 180.0);
}
m1 += sin(PI * m / 180.0);
cin >> n;
m = 360;
rep(i, n - 1) {
int tmp;
cin >> tmp;
m -= tmp;
m2 += sin(PI * tmp / 180.0);
}
m2 += sin(PI * m / 180.0);
if (abs(m1 - m2) < ESP)
cout << 0 << endl;
else if (m1 > m2)
cout << 1 << endl;
else
cout << 2 << endl;
}
}
|
[["-", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 0, 32], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
| 1
| 232
| 6
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
const double EPS = 1e-9;
int main() {
int m;
while (cin >> m, m) {
vector<int> v0, v1;
int n;
int sum = 0;
for (int i = 0; i < m - 1; i++) {
int tmp;
cin >> tmp;
v0.push_back(tmp);
sum += tmp;
}
v0.push_back(360 - sum);
cin >> n;
sum = 0;
for (int i = 0; i < n - 1; i++) {
int tmp;
cin >> tmp;
v1.push_back(tmp);
sum += tmp;
}
v1.push_back(360 - sum);
double s0 = 0, s1 = 0;
for (int i = 0; i < v0.size(); i++) {
s0 += sin(M_PI * v0[i] / 360.0);
}
for (int i = 0; i < v1.size(); i++) {
s1 += sin(M_PI * v1[i] / 360.0);
}
if (fabs(s0 - s1) < EPS)
cout << 0 << endl;
else if (s0 > s1)
cout << 1 << endl;
else
cout << 2 << endl;
}
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
const double EPS = 1e-9;
int main() {
int m;
while (cin >> m, m) {
vector<int> v0, v1;
int n;
int sum = 0;
for (int i = 0; i < m - 1; i++) {
int tmp;
cin >> tmp;
v0.push_back(tmp);
sum += tmp;
}
v0.push_back(360 - sum);
cin >> n;
sum = 0;
for (int i = 0; i < n - 1; i++) {
int tmp;
cin >> tmp;
v1.push_back(tmp);
sum += tmp;
}
v1.push_back(360 - sum);
double s0 = 0, s1 = 0;
for (int i = 0; i < v0.size(); i++) {
s0 += sin(M_PI * v0[i] / 180.0);
}
for (int i = 0; i < v1.size(); i++) {
s1 += sin(M_PI * v1[i] / 180.0);
}
if (fabs(s0 - s1) < EPS)
cout << 0 << endl;
else if (s0 > s1)
cout << 1 << endl;
else
cout << 2 << endl;
}
}
|
[["-", 0, 11, 12, 2, 3, 4, 0, 16, 12, 13], ["+", 0, 11, 12, 2, 3, 4, 0, 16, 12, 13]]
| 1
| 265
| 4
|
#define _USE_MATH_DEFINES
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
const int EPS = 1e-8;
int main() {
while (true) {
int N[2], V, V_;
double S[2] = {};
for (int i = 0; i < 2; i++) {
cin >> N[i];
if (N[i] == 0)
return 0;
V_ = 360;
for (int j = 0; j < N[i] - 1; j++) {
cin >> V;
V_ -= V;
S[i] += sin(M_PI * V / 180);
}
S[i] += sin(M_PI * V_ / 180);
}
if (S[0] - S[1] > EPS)
puts("1");
if (S[1] - S[0] > EPS)
puts("2");
else
puts("0");
}
return 0;
}
|
#define _USE_MATH_DEFINES
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
const double EPS = 1e-6;
int main() {
while (true) {
int N[2], V, V_;
double S[2] = {};
for (int i = 0; i < 2; i++) {
cin >> N[i];
if (N[i] == 0)
return 0;
V_ = 360;
for (int j = 0; j < N[i] - 1; j++) {
cin >> V;
V_ -= V;
S[i] += sin(M_PI * V / 180);
}
S[i] += sin(M_PI * V_ / 180);
}
if (S[0] - S[1] > EPS)
puts("1");
else if (S[1] - S[0] > EPS)
puts("2");
else
puts("0");
}
return 0;
}
|
[["-", 36, 36, 36, 36, 0, 30, 0, 43, 39, 40], ["+", 36, 36, 36, 36, 0, 30, 0, 43, 39, 40], ["-", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 57, 75, 76, 0, 95]]
| 1
| 208
| 5
|
#include <cmath>
#include <iostream>
using namespace std;
#define PI 3.1415926535
#define EPS 0.00000000001
int main() {
int n, a;
int a1, a2;
double h1, h2;
while (cin >> n, n) {
a1 = a2 = 0;
h1 = h2 = 0;
while (--n) {
cin >> a;
a1 += a;
h1 += sin(a * PI / 360.0);
}
cin >> n;
while (--n) {
cin >> a;
a2 += a;
h2 += sin(a * PI / 360.0);
}
h1 += sin((360 - a1) * PI / 360.0);
h2 += sin((360 - a2) * PI / 360.0);
if (-EPS < h1 - h2 && h1 - h2 < EPS) {
cout << 0 << endl;
} else if (h1 > h2) {
cout << 1 << endl;
} else {
cout << 2 << endl;
}
}
return 0;
}
|
#include <cmath>
#include <iostream>
using namespace std;
#define PI 3.1415926535
#define EPS 0.00000000001
int main() {
int n, a;
int a1, a2;
double h1, h2;
while (cin >> n, n) {
a1 = a2 = 0;
h1 = h2 = 0;
while (--n) {
cin >> a;
a1 += a;
h1 += sin(a * PI / 180.0);
}
cin >> n;
while (--n) {
cin >> a;
a2 += a;
h2 += sin(a * PI / 180.0);
}
h1 += sin((360 - a1) * PI / 180.0);
h2 += sin((360 - a2) * PI / 180.0);
if (-EPS < h1 - h2 && h1 - h2 < EPS) {
cout << 0 << endl;
} else if (h1 > h2) {
cout << 1 << endl;
} else {
cout << 2 << endl;
}
}
return 0;
}
|
[["-", 0, 11, 12, 2, 3, 4, 0, 16, 12, 13], ["+", 0, 11, 12, 2, 3, 4, 0, 16, 12, 13]]
| 1
| 193
| 8
|
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>
using namespace std;
#define dump(n) cout << "# " << #n << "=" << (n) << endl
#define debug(n) \
cout << __FILE__ << "," << __LINE__ << ": #" << #n << "=" << (n) << endl
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, n) repi(i, 0, n)
#define iter(c) __typeof((c).begin())
#define foreach(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define allof(c) (c).begin(), (c).end()
#define mp make_pair
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const double EPS = 1e-10;
int main() {
for (int m, n; cin >> m, m;) {
vi a(m, 180);
rep(i, m - 1) {
cin >> a[i];
a[m - 1] -= a[i];
}
cin >> n;
vi b(n, 180);
rep(i, n - 1) {
cin >> b[i];
b[n - 1] -= b[i];
}
double sa = 0, sb = 0;
rep(i, m) sa += sin(a[i] * M_PI / 180);
rep(i, n) sb += sin(b[i] * M_PI / 180);
if (abs(sa - sb) < EPS)
cout << 0 << endl;
else if (sa > sb)
cout << 1 << endl;
else
cout << 2 << endl;
}
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>
using namespace std;
#define dump(n) cout << "# " << #n << "=" << (n) << endl
#define debug(n) \
cout << __FILE__ << "," << __LINE__ << ": #" << #n << "=" << (n) << endl
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, n) repi(i, 0, n)
#define iter(c) __typeof((c).begin())
#define foreach(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define allof(c) (c).begin(), (c).end()
#define mp make_pair
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const double EPS = 1e-10;
int main() {
for (int m, n; cin >> m, m;) {
vi a(m, 360);
rep(i, m - 1) {
cin >> a[i];
a[m - 1] -= a[i];
}
cin >> n;
vi b(n, 360);
rep(i, n - 1) {
cin >> b[i];
b[n - 1] -= b[i];
}
double sa = 0, sb = 0;
rep(i, m) sa += sin(a[i] * M_PI / 180);
rep(i, n) sb += sin(b[i] * M_PI / 180);
if (abs(sa - sb) < EPS)
cout << 0 << endl;
else if (sa > sb)
cout << 1 << endl;
else
cout << 2 << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 43, 49, 50, 51, 4, 0, 13], ["+", 8, 9, 0, 43, 49, 50, 51, 4, 0, 13]]
| 1
| 351
| 4
|
#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;
}
vector<string> Split(char c, string s) {
vector<string> res(0);
string str = "";
rep(i, s.size()) {
if (s[i] == c) {
res.push_back(str);
str.clear();
} else {
str += s[i];
}
}
res.push_back(str);
return res;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string s;
while (getline(cin, s)) {
if (s[0] == '0')
break;
auto ss = Split(' ', s);
vector<int> v(ss.size());
int one = 0;
rep(i, v.size()) {
v[i] = ston(ss[i], 1);
v[i] = (v[i] > 10) ? 10 : v[i];
if (v[i] == 1) {
++one;
}
}
sort(all(v), greater<int>());
int sc = 0;
bool f = true;
rep(i, v.size()) {
if (v[i] != 1) {
sc += v[i];
if (sc > 21) {
sc = 0;
f = false;
cout << sc << endl;
break;
}
}
}
if (f) {
while (one) {
if (sc + 11 < 22) {
sc += 11;
--one;
} else {
sc += 1;
--one;
}
}
if (sc > 21) {
sc = 0;
}
cout << sc << 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;
}
vector<string> Split(char c, string s) {
vector<string> res(0);
string str = "";
rep(i, s.size()) {
if (s[i] == c) {
res.push_back(str);
str.clear();
} else {
str += s[i];
}
}
res.push_back(str);
return res;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string s;
while (getline(cin, s)) {
if (s[0] == '0')
break;
auto ss = Split(' ', s);
vector<int> v(ss.size());
int one = 0;
rep(i, v.size()) {
v[i] = ston(ss[i], 1);
v[i] = (v[i] > 10) ? 10 : v[i];
if (v[i] == 1) {
++one;
}
}
sort(all(v), greater<int>());
int sc = 0;
bool f = true;
rep(i, v.size()) {
if (v[i] != 1) {
sc += v[i];
if (sc > 21) {
sc = 0;
f = false;
cout << sc << endl;
break;
}
}
}
if (f) {
while (one) {
if (sc + 11 + one - 1 < 22) {
sc += 11;
--one;
} else {
sc += 1;
--one;
}
}
if (sc > 21) {
sc = 0;
}
cout << sc << endl;
}
}
return 0;
}
|
[["+", 15, 339, 51, 16, 31, 16, 31, 16, 17, 72], ["+", 15, 339, 51, 16, 31, 16, 31, 16, 12, 22], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 33], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 12, 13]]
| 1
| 736
| 4
|
[*$<][0..-2].map{|s|
c=0;s=0;
s.split.map(&:to_i).map{|a|c+=1 if a==1;s+=[a,10].min if a>1;};
p [*0..c].map{|i|a=s+i+(c-i)*11;a=0 if a>21;a}.max
}
|
[*$<][0..-2].map{|s|
c=0;t=0;
s.split.map(&:to_i).map{|a|c+=1 if a==1;t+=[a,10].min if a>1;};
p [*0..c].map{|i|a=t+i+(c-i)*11;a=0 if a>21;a}.max
}
|
[["-", 0, 652, 196, 196, 8, 734, 0, 662, 31, 22], ["+", 0, 652, 196, 196, 8, 734, 0, 662, 31, 22], ["-", 196, 196, 8, 734, 0, 751, 8, 755, 31, 22], ["+", 196, 196, 8, 734, 0, 751, 8, 755, 31, 22], ["-", 8, 734, 0, 662, 12, 738, 31, 738, 31, 22], ["+", 8, 734, 0, 662, 12, 738, 31, 738, 31, 22]]
| 4
| 103
| 6
|
from collections import Counter
def point(lst):
counter = Counter(lst)
acc = 0
for i in range(2, 10):
acc += i * counter[i]
for i in range(11, 14):
acc += 10 * counter[i]
one_num = counter[1]
for i in range(one_num + 1):
if i + (one_num - i) * 11 + acc <= 21:
acc += i + (one_num - i) * 11
break
else:
acc += one_num
if acc > 21:
return 0
else:
return acc
while True:
s = input()
if s == "0":
break
lst = list(map(int, s.split()))
print(point(lst))
|
from collections import Counter
def point(lst):
counter = Counter(lst)
acc = 0
for i in range(2, 10):
acc += i * counter[i]
for i in range(10, 14):
acc += 10 * counter[i]
one_num = counter[1]
for i in range(one_num + 1):
if i + (one_num - i) * 11 + acc <= 21:
acc += i + (one_num - i) * 11
break
else:
acc += one_num
if acc > 21:
return 0
else:
return acc
while True:
s = input()
if s == "0":
break
lst = list(map(int, s.split()))
print(point(lst))
|
[["-", 8, 196, 0, 7, 12, 652, 3, 4, 0, 612], ["+", 8, 196, 0, 7, 12, 652, 3, 4, 0, 612]]
| 5
| 152
| 2
|
while True:
L = list(map(int,input().split()))
if L == [0]:
break
a = L.count(0)
s = sum([min(10,x) for x in L])
for _ in range(a):
if s <= 11:
s += 10
print(s if s <= 21 else 0)
|
while True:
L = list(map(int,input().split()))
if L == [0]:
break
a = L.count(1)
s = sum([min(10,x) for x in L])
for _ in range(a):
if s <= 11:
s += 10
print(s if s <= 21 else 0)
|
[["-", 0, 1, 0, 662, 12, 652, 3, 4, 0, 612], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 612]]
| 5
| 79
| 2
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
struct Food {
string f;
int w, s;
bool operator<(const Food &a) const {
if (w == a.w)
return s > a.s;
return w > a.w;
}
};
int main() {
int N;
while (cin >> N, N) {
int sumW = 0;
Food food[10];
for (int i = 0; i < N; i++) {
cin >> food[i].f >> food[i].w >> food[i].s;
sumW += food[i].w;
}
sort(food, food + N);
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (food[j].w == -1)
continue;
if (food[j].s >= sumW - food[j].w) {
cout << food[j].f << endl;
sumW -= food[j].w;
food[j].w = -1;
}
}
}
}
return 0;
}
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
struct Food {
string f;
int w, s;
bool operator<(const Food &a) const {
if (w == a.w)
return s > a.s;
return w > a.w;
}
};
int main() {
int N;
while (cin >> N, N) {
int sumW = 0;
Food food[10];
for (int i = 0; i < N; i++) {
cin >> food[i].f >> food[i].w >> food[i].s;
sumW += food[i].w;
}
sort(food, food + N);
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (food[j].w == -1)
continue;
if (food[j].s >= sumW - food[j].w) {
cout << food[j].f << endl;
sumW -= food[j].w;
food[j].w = -1;
break;
}
}
}
}
return 0;
}
|
[["+", 8, 9, 0, 57, 64, 9, 0, 93, 0, 94], ["+", 8, 9, 0, 57, 64, 9, 0, 93, 0, 35]]
| 1
| 263
| 2
|
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
const int MAX = 10000100;
#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()
#define ll long long int
#define gcd(a, b) __gcd(a, b)
int GCD(int a, int b) {
if (!b)
return a;
return gcd(b, a % b);
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
struct food {
string fn;
int g;
int s;
};
int f[10], an[10], m;
food fd[10], sf;
int ans(int n, int s) {
if (n == -1) {
for (int i = m - 1; i >= 0; i--) {
cout << fd[an[i]].fn << endl;
return 1;
}
}
for (int i = m - 1; i >= 0; i--) {
if (f[i] == 0 && fd[i].s >= s - fd[i].g) {
f[i] = 1;
an[n] = i;
if (ans(n - 1, s - fd[i].g) == 1)
return 1;
f[i] = 0;
}
}
return 0;
}
int main(void) {
int i, j, s;
while (cin >> m) {
if (m == 0)
break;
for (i = 0, s = 0; i < m; i++) {
f[i] = 0;
cin >> fd[i].fn >> fd[i].g >> fd[i].s;
s += fd[i].g;
}
for (i = 1; i < m; i++) {
for (j = 0; j < m - i; j++) {
if (fd[j].g > fd[j + 1].g) {
sf = fd[j];
fd[j] = fd[j + 1];
fd[j + 1] = sf;
}
}
}
ans(m - 1, s);
}
return 0;
}
|
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
const int MAX = 10000100;
#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()
#define ll long long int
#define gcd(a, b) __gcd(a, b)
int GCD(int a, int b) {
if (!b)
return a;
return gcd(b, a % b);
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
struct food {
string fn;
int g;
int s;
};
int f[10], an[10], m;
food fd[10], sf;
int ans(int n, int s) {
if (n == -1) {
for (int i = m - 1; i >= 0; i--)
cout << fd[an[i]].fn << endl;
return 1;
}
for (int i = m - 1; i >= 0; i--) {
if (f[i] == 0 && fd[i].s >= s - fd[i].g) {
f[i] = 1;
an[n] = i;
if (ans(n - 1, s - fd[i].g) == 1)
return 1;
f[i] = 0;
}
}
return 0;
}
int main(void) {
int i, j, s;
while (cin >> m) {
if (m == 0)
break;
for (i = 0, s = 0; i < m; i++) {
f[i] = 0;
cin >> fd[i].fn >> fd[i].g >> fd[i].s;
s += fd[i].g;
}
for (i = 1; i < m; i++) {
for (j = 0; j < m - i; j++) {
if (fd[j].g > fd[j + 1].g) {
sf = fd[j];
fd[j] = fd[j + 1];
fd[j + 1] = sf;
}
}
}
ans(m - 1, s);
}
return 0;
}
|
[["-", 0, 57, 64, 9, 0, 7, 8, 9, 0, 45], ["-", 0, 57, 64, 9, 0, 7, 8, 9, 0, 46]]
| 1
| 476
| 2
|
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
string f[11];
int n, s[11], w[11], p[11], q[11];
bool ok() {
for (int i = 0; i < n - 1; i++) {
int r = 0;
for (int j = i + 1; j < n; j++)
r += w[p[j]];
if (r > s[p[i]])
return false;
}
return true;
}
int main() {
while (cin >> n, n) {
for (int i = 0; i < n; i++)
cin >> f[i] >> w[i] >> s[i];
for (int i = 0; i < n; i++)
p[i] = i, q[i] = -1;
do {
if (ok()) {
if (q[0] == -1)
for (int i = 0; i < n; i++)
q[i] = p[i];
else {
int sum1 = 0, sum2 = 0;
for (int i = 0; i < n; i++)
sum1 += w[p[i]] * (i + 1), sum2 += w[q[i]] * (i + 1);
if (sum1 < sum2)
for (int i = 0; i < n; i++)
q[i] = p[i];
}
}
} while (next_permutation(p, p + n));
for (int i = 0; i < n; i++)
cout << s[q[i]] << endl;
}
}
|
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
string f[11];
int n, s[11], w[11], p[11], q[11];
bool ok() {
for (int i = 0; i < n - 1; i++) {
int r = 0;
for (int j = i + 1; j < n; j++)
r += w[p[j]];
if (r > s[p[i]])
return false;
}
return true;
}
int main() {
while (cin >> n, n) {
for (int i = 0; i < n; i++)
cin >> f[i] >> w[i] >> s[i];
for (int i = 0; i < n; i++)
p[i] = i, q[i] = -1;
do {
if (ok()) {
if (q[0] == -1)
for (int i = 0; i < n; i++)
q[i] = p[i];
else {
int sum1 = 0, sum2 = 0;
for (int i = 0; i < n; i++)
sum1 += w[p[i]] * (i + 1), sum2 += w[q[i]] * (i + 1);
if (sum1 < sum2)
for (int i = 0; i < n; i++)
q[i] = p[i];
}
}
} while (next_permutation(p, p + n));
for (int i = 0; i < n; i++)
cout << f[q[i]] << endl;
}
}
|
[["-", 8, 1, 0, 16, 31, 16, 12, 69, 28, 22], ["+", 8, 1, 0, 16, 31, 16, 12, 69, 28, 22]]
| 1
| 357
| 2
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
struct food {
string name;
int weight;
int ue;
int id;
};
struct com {
inline bool operator()(const food &f1, const food &f2) {
return (f1.id > f2.id);
}
};
int main() {
int n;
while (cin >> n, n) {
vector<food> vec, v;
int totWeight = 0;
for (int i = 0; i < n; i++) {
food f;
cin >> f.name >> f.weight >> f.ue;
f.id = i;
totWeight += f.weight;
vec.push_back(f);
v.push_back(f);
}
sort(vec.begin(), vec.end(), com());
vector<pair<double, vector<int>>> ve;
do {
bool ok = true;
int tot = 0;
for (int i = n - 1; i >= 0; i--) {
if (tot > vec[i].ue) {
ok = false;
break;
}
tot += vec[i].weight;
}
if (ok) {
double x = 0;
for (int i = 1; i <= n; i++) {
x += (n - i) * vec[i].weight;
}
x /= totWeight;
vector<int> ids;
for (int i = 0; i < n; i++) {
ids.push_back(vec[i].id);
}
ve.push_back(make_pair(x, ids));
}
} while (next_permutation(vec.begin(), vec.end(), com()));
sort(ve.begin(), ve.end());
for (int i = 0; i < n; i++) {
cout << v[ve[ve.size() - 1].second[i]].name << endl;
}
}
return 0;
}
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
struct food {
string name;
int weight;
int ue;
int id;
};
struct com {
inline bool operator()(const food &f1, const food &f2) {
return (f1.id > f2.id);
}
};
int main() {
int n;
while (cin >> n, n) {
vector<food> vec, v;
int totWeight = 0;
for (int i = 0; i < n; i++) {
food f;
cin >> f.name >> f.weight >> f.ue;
f.id = i;
totWeight += f.weight;
vec.push_back(f);
v.push_back(f);
}
sort(vec.begin(), vec.end(), com());
vector<pair<double, vector<int>>> ve;
do {
bool ok = true;
int tot = 0;
for (int i = n - 1; i >= 0; i--) {
if (tot > vec[i].ue) {
ok = false;
break;
}
tot += vec[i].weight;
}
if (ok) {
double x = 0;
for (int i = 0; i < n; i++) {
x += (n - i) * vec[i].weight;
}
x /= totWeight;
vector<int> ids;
for (int i = 0; i < n; i++) {
ids.push_back(vec[i].id);
}
ve.push_back(make_pair(x, ids));
}
} while (next_permutation(vec.begin(), vec.end(), com()));
sort(ve.begin(), ve.end());
for (int i = 0; i < n; i++) {
cout << v[ve[ve.size() - 1].second[i]].name << endl;
}
}
return 0;
}
|
[["-", 64, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 64, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["-", 0, 57, 64, 9, 0, 7, 15, 16, 17, 19], ["+", 0, 57, 64, 9, 0, 7, 15, 16, 17, 18]]
| 1
| 432
| 4
|
#include <iostream>
#include <string>
using namespace std;
string f[11];
int ans[11];
int n;
int w[11], s[11];
void solve() {
for (int i = 1; i <= n; i++)
ans[i] = i;
for (int k = 1; k <= n; k++) {
for (int i = n; i > k; i--) {
if (s[ans[i]] > s[ans[i - 1]]) {
int tmp = ans[i];
ans[i] = ans[i - 1];
ans[i - 1] = tmp;
}
}
}
bool flag = true;
for (int i = 1; i <= n; i++) {
if (i == n && flag) {
i = 1;
flag = true;
} else if (i == n)
break;
if (w[ans[i]] < w[ans[i + 1]]) {
int tmp = w[ans[i]];
for (int k = i + 2; k <= n; k++)
tmp += w[ans[k]];
if (s[ans[i + 1]] >= tmp) {
tmp = ans[i];
ans[i] = ans[i + 1];
ans[i + 1] = tmp;
flag = false;
}
}
}
}
int main() {
while (true) {
cin >> n;
if (!n)
return 0;
for (int i = 1; i <= n; i++)
cin >> f[i] >> w[i] >> s[i];
solve();
for (int i = 1; i <= n; i++)
cout << f[ans[i]] << endl;
}
}
|
#include <iostream>
#include <string>
using namespace std;
string f[11];
int ans[11];
int n;
int w[11], s[11];
void solve() {
for (int i = 1; i <= n; i++)
ans[i] = i;
for (int k = 1; k <= n; k++) {
for (int i = n; i > k; i--) {
if (s[ans[i]] > s[ans[i - 1]]) {
int tmp = ans[i];
ans[i] = ans[i - 1];
ans[i - 1] = tmp;
}
}
}
bool flag = true;
for (int i = 1; i <= n; i++) {
if (i == n && !flag) {
i = 1;
flag = true;
} else if (i == n)
break;
if (w[ans[i]] < w[ans[i + 1]]) {
int tmp = w[ans[i]];
for (int k = i + 2; k <= n; k++)
tmp += w[ans[k]];
if (s[ans[i + 1]] >= tmp) {
tmp = ans[i];
ans[i] = ans[i + 1];
ans[i + 1] = tmp;
flag = false;
}
}
}
}
int main() {
while (true) {
cin >> n;
if (!n)
return 0;
for (int i = 1; i <= n; i++)
cin >> f[i] >> w[i] >> s[i];
solve();
for (int i = 1; i <= n; i++)
cout << f[ans[i]] << endl;
}
}
|
[["+", 0, 57, 15, 339, 51, 16, 12, 91, 17, 111]]
| 1
| 384
| 1
|
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
static String[] list =
new String[] {"012345", "024135", "031425", "043215", "103254", "120534",
"135024", "152304", "201453", "215043", "240513", "254103",
"304152", "310542", "345012", "351402", "402351", "425031",
"430521", "453201", "513240", "521430", "534120", "542310"};
static Dice[][] data;
static int h;
static int w;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
IN:
while (true) {
data = new Dice[8][24];
for (int i = 0; i < 8; i++) {
String in = sc.next();
if (in.equals("0"))
break IN;
for (int j = 0; j < 24; j++) {
String tmp = "";
for (int k = 0; k < 6; k++) {
tmp += in.charAt(list[j].charAt(k) - '0');
}
data[i][j] = new Dice(tmp);
}
}
if (dfs(new Data(data))) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
static class Dice {
char[] c;
Dice(String a) { c = a.toCharArray(); }
}
static class Block {
Dice[] list;
int count = 0;
Block() { list = new Dice[8]; }
Block(Block a) {
list = Arrays.copyOf(a.list, a.list.length);
count = a.count;
}
boolean set(Dice a) {
list[count++] = a;
if (count == 1) {
return true;
}
if (count == 2) {
if (Character.toUpperCase(list[0].c[2]) ==
Character.toUpperCase(list[1].c[3]) &&
list[0].c[2] != list[1].c[3]) {
return true;
}
}
if (count == 3) {
if (Character.toUpperCase(list[2].c[4]) ==
Character.toUpperCase(list[0].c[1]) &&
list[2].c[4] != list[0].c[1]) {
return true;
}
}
if (count == 4) {
if (Character.toUpperCase(list[3].c[4]) ==
Character.toUpperCase(list[1].c[1]) &&
list[3].c[4] != list[1].c[1]) {
if (Character.toUpperCase(list[3].c[3]) ==
Character.toUpperCase(list[2].c[2]) &&
list[3].c[3] != list[2].c[2]) {
return true;
}
}
}
if (count == 5) {
if (Character.toUpperCase(list[4].c[5]) ==
Character.toUpperCase(list[0].c[0]) &&
list[4].c[5] != list[0].c[0]) {
return true;
}
}
if (count == 6) {
if (Character.toUpperCase(list[5].c[5]) ==
Character.toUpperCase(list[1].c[0]) &&
list[5].c[5] != list[1].c[0]) {
if (Character.toUpperCase(list[5].c[3]) ==
Character.toUpperCase(list[4].c[2]) &&
list[5].c[3] != list[4].c[2]) {
return true;
}
}
}
if (count == 7) {
if (Character.toUpperCase(list[6].c[5]) ==
Character.toUpperCase(list[2].c[0]) &&
list[6].c[5] != list[2].c[0]) {
if (Character.toUpperCase(list[6].c[4]) ==
Character.toUpperCase(list[4].c[1]) &&
list[6].c[4] != list[4].c[1]) {
return true;
}
}
}
if (count == 8) {
if (Character.toUpperCase(list[7].c[5]) ==
Character.toUpperCase(list[3].c[0]) &&
list[7].c[5] != list[3].c[0]) {
if (Character.toUpperCase(list[7].c[3]) ==
Character.toUpperCase(list[6].c[2]) &&
list[7].c[3] != list[6].c[2]) {
if (Character.toUpperCase(list[7].c[4]) ==
Character.toUpperCase(list[5].c[1]) &&
list[7].c[4] != list[5].c[1]) {
return true;
}
}
}
}
list[--count] = null;
return false;
}
}
static class Data {
boolean[] useDice;
Dice[][] DiceList;
Block block;
Data(Dice[][] a) {
useDice = new boolean[8];
DiceList = a;
block = new Block();
}
}
static boolean dfs(Data a) {
for (int i = 0; i < 8; i++) {
if (a.useDice[i]) {
continue;
}
for (int j = 0; j < 24; j++) {
if (a.block.set(data[i][j])) {
if (a.block.count == 8)
return true;
a.useDice[i] = true;
dfs(a);
a.useDice[i] = false;
a.block.list[--a.block.count] = null;
}
}
}
return false;
}
}
|
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
static String[] list =
new String[] {"012345", "024135", "031425", "043215", "103254", "120534",
"135024", "152304", "201453", "215043", "240513", "254103",
"304152", "310542", "345012", "351402", "402351", "425031",
"430521", "453201", "513240", "521430", "534120", "542310"};
static Dice[][] data;
static int h;
static int w;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
IN:
while (true) {
data = new Dice[8][24];
for (int i = 0; i < 8; i++) {
String in = sc.next();
if (in.equals("0"))
break IN;
for (int j = 0; j < 24; j++) {
String tmp = "";
for (int k = 0; k < 6; k++) {
tmp += in.charAt(list[j].charAt(k) - '0');
}
data[i][j] = new Dice(tmp);
}
}
if (dfs(new Data(data))) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
static class Dice {
char[] c;
Dice(String a) { c = a.toCharArray(); }
}
static class Block {
Dice[] list;
int count = 0;
Block() { list = new Dice[8]; }
Block(Block a) {
list = Arrays.copyOf(a.list, a.list.length);
count = a.count;
}
boolean set(Dice a) {
list[count++] = a;
if (count == 1) {
return true;
}
if (count == 2) {
if (Character.toUpperCase(list[0].c[2]) ==
Character.toUpperCase(list[1].c[3]) &&
list[0].c[2] != list[1].c[3]) {
return true;
}
}
if (count == 3) {
if (Character.toUpperCase(list[2].c[4]) ==
Character.toUpperCase(list[0].c[1]) &&
list[2].c[4] != list[0].c[1]) {
return true;
}
}
if (count == 4) {
if (Character.toUpperCase(list[3].c[4]) ==
Character.toUpperCase(list[1].c[1]) &&
list[3].c[4] != list[1].c[1]) {
if (Character.toUpperCase(list[3].c[3]) ==
Character.toUpperCase(list[2].c[2]) &&
list[3].c[3] != list[2].c[2]) {
return true;
}
}
}
if (count == 5) {
if (Character.toUpperCase(list[4].c[5]) ==
Character.toUpperCase(list[0].c[0]) &&
list[4].c[5] != list[0].c[0]) {
return true;
}
}
if (count == 6) {
if (Character.toUpperCase(list[5].c[5]) ==
Character.toUpperCase(list[1].c[0]) &&
list[5].c[5] != list[1].c[0]) {
if (Character.toUpperCase(list[5].c[3]) ==
Character.toUpperCase(list[4].c[2]) &&
list[5].c[3] != list[4].c[2]) {
return true;
}
}
}
if (count == 7) {
if (Character.toUpperCase(list[6].c[5]) ==
Character.toUpperCase(list[2].c[0]) &&
list[6].c[5] != list[2].c[0]) {
if (Character.toUpperCase(list[6].c[4]) ==
Character.toUpperCase(list[4].c[1]) &&
list[6].c[4] != list[4].c[1]) {
return true;
}
}
}
if (count == 8) {
if (Character.toUpperCase(list[7].c[5]) ==
Character.toUpperCase(list[3].c[0]) &&
list[7].c[5] != list[3].c[0]) {
if (Character.toUpperCase(list[7].c[3]) ==
Character.toUpperCase(list[6].c[2]) &&
list[7].c[3] != list[6].c[2]) {
if (Character.toUpperCase(list[7].c[4]) ==
Character.toUpperCase(list[5].c[1]) &&
list[7].c[4] != list[5].c[1]) {
return true;
}
}
}
}
list[--count] = null;
return false;
}
}
static class Data {
boolean[] useDice;
Dice[][] DiceList;
Block block;
Data(Dice[][] a) {
useDice = new boolean[8];
DiceList = a;
block = new Block();
}
}
static boolean dfs(Data a) {
for (int i = 0; i < 8; i++) {
if (a.useDice[i]) {
continue;
}
for (int j = 0; j < 24; j++) {
if (a.block.set(data[i][j])) {
if (a.block.count == 8)
return true;
a.useDice[i] = true;
if (dfs(a))
return true;
a.useDice[i] = false;
a.block.list[--a.block.count] = null;
}
}
}
return false;
}
}
|
[["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 0, 57, 64, 196, 0, 57, 15, 15, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 15, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 37, 0, 38], ["+", 0, 57, 64, 196, 0, 57, 64, 37, 0, 146]]
| 3
| 1,364
| 5
|
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
public class Main {
final int INF = 1 << 28;
void run() {
Scanner sc = new Scanner(System.in);
while (true) {
Dice[][] ds = new Dice[8][24];
String str = sc.next();
if (str.equals("0"))
break;
for (int i = 0; i < 8; i++) {
if (i != 0) {
str = sc.next();
}
Dice d = new Dice(str);
Set<Dice> set = new HashSet<Dice>();
for (int j = 0; j < 4; j++) {
d = d.North();
for (int k = 0; k < 4; k++) {
d = d.Right();
set.add(d);
}
}
d = d.East();
for (int k = 0; k < 4; k++) {
d = d.Right();
set.add(d);
}
d = d.East().East();
for (int k = 0; k < 4; k++) {
d = d.Right();
set.add(d);
}
ds[i] = set.toArray(ds[i]);
}
boolean yes = false;
for (int a = 0; a < 8; a++) {
Dice da = ds[a][0];
for (int b = 0; b < 8; b++) {
if (b == a)
continue;
Dice db = ds[b][0];
boolean f1 = true;
for (int i = 1; i <= 6; i++) {
for (int j = 1; j <= 6; j++) {
if (abs(da.cs[i] - db.cs[j]) == 32) {
f1 = false;
i = INF;
break;
}
}
}
if (f1)
continue;
for (int c = 0; c < 8; c++) {
if (a == c || b == c)
continue;
Dice dc = ds[c][0];
boolean f2 = true;
for (int i = 1; i <= 6; i++) {
for (int j = 1; j <= 6; j++) {
if (abs(dc.cs[i] - db.cs[j]) == 32) {
f2 = false;
i = INF;
break;
}
}
}
if (f2)
continue;
for (int d = 0; d < 8; d++) {
if (a == d || b == d || c == d)
continue;
Dice dd = ds[d][0];
boolean f3 = true;
boolean f4 = true;
for (int i = 1; i <= 6; i++) {
for (int j = 1; j <= 6; j++) {
if (abs(dd.cs[i] - dc.cs[j]) == 32) {
f3 = false;
}
if (abs(dd.cs[i] - da.cs[j]) == 32) {
f4 = false;
}
}
}
if (f3 || f4)
continue;
for (int e = 0; e < 8; e++) {
if (a == e || b == e || c == e || d == e)
continue;
Dice de = ds[e][0];
boolean f5 = true;
for (int i = 1; i <= 6; i++) {
for (int j = 1; j <= 6; j++) {
if (abs(de.cs[i] - da.cs[j]) == 32) {
f5 = false;
i = INF;
break;
}
}
}
if (f5)
continue;
for (int f = 0; f < 8; f++) {
if (a == f || b == f || c == f || d == f || e == f)
continue;
Dice df = ds[f][0];
boolean f6 = true;
boolean f7 = true;
for (int i = 1; i <= 6; i++) {
for (int j = 1; j <= 6; j++) {
if (abs(de.cs[i] - df.cs[j]) == 32) {
f6 = false;
}
if (abs(df.cs[i] - db.cs[j]) == 32) {
f7 = false;
}
}
}
if (f6 || f7)
continue;
for (int g = 0; g < 8; g++) {
if (a == g || b == g || c == g || d == g || e == g ||
f == g)
continue;
Dice dg = ds[g][0];
boolean f8 = true;
boolean f9 = true;
for (int i = 1; i <= 6; i++) {
for (int j = 1; j <= 6; j++) {
if (abs(dg.cs[i] - df.cs[j]) == 32) {
f8 = false;
}
if (abs(dg.cs[i] - dc.cs[j]) == 32) {
f9 = false;
}
}
}
if (f8 || f9)
continue;
for (int h = 0; h < 8; h++) {
if (a == h || b == h || c == h || d == h || e == h ||
f == h || g == h)
continue;
Dice dh = ds[h][0];
boolean f10 = true;
boolean f11 = true;
boolean f12 = true;
for (int i = 1; i <= 6; i++) {
for (int j = 1; j <= 6; j++) {
if (abs(dg.cs[i] - dh.cs[j]) == 32) {
f10 = false;
}
if (abs(dh.cs[i] - dd.cs[j]) == 32) {
f11 = false;
}
if (abs(dh.cs[i] - de.cs[j]) == 32) {
f12 = false;
}
}
}
if (f10 || f11 | f12)
continue;
Dice[] pos = new Dice[8];
for (int i = 0; i <= 0; i++) {
pos[0] = ds[a][i];
for (int j = 0; j < 24; j++) {
pos[1] = ds[b][j];
if (abs(pos[0].cs[5] - pos[1].cs[2]) != 32)
continue;
for (int k = 0; k < 24; k++) {
pos[2] = ds[c][k];
if (abs(pos[1].cs[3] - pos[2].cs[4]) != 32)
continue;
for (int p = 0; p < 24; p++) {
pos[3] = ds[d][p];
if (abs(pos[2].cs[2] - pos[3].cs[5]) != 32 ||
abs(pos[0].cs[3] - pos[3].cs[4]) != 32)
continue;
for (int q = 0; q < 24; q++) {
pos[4] = ds[e][q];
if (abs(pos[0].cs[6] - pos[4].cs[1]) != 32)
continue;
for (int r = 0; r < 24; r++) {
pos[5] = ds[f][r];
if (abs(pos[5].cs[2] - pos[4].cs[5]) != 32 ||
abs(pos[1].cs[6] - pos[5].cs[1]) != 32)
continue;
for (int s = 0; s < 24; s++) {
pos[6] = ds[g][s];
if (abs(pos[5].cs[3] - pos[6].cs[4]) !=
32 ||
abs(pos[6].cs[1] - pos[2].cs[6]) != 32)
continue;
for (int t = 0; t < 24; t++) {
pos[7] = ds[h][t];
if (abs(pos[4].cs[3] - pos[7].cs[4]) !=
32 ||
abs(pos[6].cs[2] - pos[7].cs[5]) !=
32 ||
abs(pos[7].cs[1] - pos[3].cs[6]) !=
32)
continue;
yes = true;
a = b = c = d = e = f = g = h = i = j =
k = p = q = r = s = INF;
break;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
System.out.println(yes ? "YES" : "NO");
}
}
int abs(int n) { return n > 0 ? n : -n; }
public static void main(String[] args) throws Exception { new Main().run(); }
}
class Dice {
char cs[] = new char[7];
Dice(char c1, char c2, char c3, char c4, char c5, char c6) {
cs[1] = c1;
cs[2] = c2;
cs[3] = c3;
cs[4] = c4;
cs[5] = c5;
cs[6] = c6;
}
Dice(String str) {
char[] tmp = str.toCharArray();
for (int i = 0; i < 6; i++) {
cs[i + 1] = tmp[i];
}
}
public Dice North() {
return new Dice(cs[2], cs[6], cs[3], cs[4], cs[1], cs[5]);
}
public Dice East() {
return new Dice(cs[4], cs[2], cs[1], cs[6], cs[5], cs[3]);
}
public Dice Right() {
return new Dice(cs[1], cs[4], cs[2], cs[5], cs[3], cs[6]);
}
public String toString() { return Arrays.toString(cs); }
}
|
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
public class Main {
final int INF = 1 << 28;
void run() {
Scanner sc = new Scanner(System.in);
while (true) {
Dice[][] ds = new Dice[8][24];
String str = sc.next();
if (str.equals("0"))
break;
for (int i = 0; i < 8; i++) {
if (i != 0) {
str = sc.next();
}
Dice d = new Dice(str);
Set<Dice> set = new HashSet<Dice>();
for (int j = 0; j < 4; j++) {
d = d.North();
for (int k = 0; k < 4; k++) {
d = d.Right();
set.add(d);
}
}
d = d.East();
for (int k = 0; k < 4; k++) {
d = d.Right();
set.add(d);
}
d = d.East().East();
for (int k = 0; k < 4; k++) {
d = d.Right();
set.add(d);
}
ds[i] = set.toArray(ds[i]);
}
boolean yes = false;
for (int a = 0; a < 8; a++) {
Dice da = ds[a][0];
for (int b = 0; b < 8; b++) {
if (b == a)
continue;
Dice db = ds[b][0];
boolean f1 = true;
for (int i = 1; i <= 6; i++) {
for (int j = 1; j <= 6; j++) {
if (abs(da.cs[i] - db.cs[j]) == 32) {
f1 = false;
i = INF;
break;
}
}
}
if (f1)
continue;
for (int c = 0; c < 8; c++) {
if (a == c || b == c)
continue;
Dice dc = ds[c][0];
boolean f2 = true;
for (int i = 1; i <= 6; i++) {
for (int j = 1; j <= 6; j++) {
if (abs(dc.cs[i] - db.cs[j]) == 32) {
f2 = false;
i = INF;
break;
}
}
}
if (f2)
continue;
for (int d = 0; d < 8; d++) {
if (a == d || b == d || c == d)
continue;
Dice dd = ds[d][0];
boolean f3 = true;
boolean f4 = true;
for (int i = 1; i <= 6; i++) {
for (int j = 1; j <= 6; j++) {
if (abs(dd.cs[i] - dc.cs[j]) == 32) {
f3 = false;
}
if (abs(dd.cs[i] - da.cs[j]) == 32) {
f4 = false;
}
}
}
if (f3 || f4)
continue;
for (int e = 0; e < 8; e++) {
if (a == e || b == e || c == e || d == e)
continue;
Dice de = ds[e][0];
boolean f5 = true;
for (int i = 1; i <= 6; i++) {
for (int j = 1; j <= 6; j++) {
if (abs(de.cs[i] - da.cs[j]) == 32) {
f5 = false;
i = INF;
break;
}
}
}
if (f5)
continue;
for (int f = 0; f < 8; f++) {
if (a == f || b == f || c == f || d == f || e == f)
continue;
Dice df = ds[f][0];
boolean f6 = true;
boolean f7 = true;
for (int i = 1; i <= 6; i++) {
for (int j = 1; j <= 6; j++) {
if (abs(de.cs[i] - df.cs[j]) == 32) {
f6 = false;
}
if (abs(df.cs[i] - db.cs[j]) == 32) {
f7 = false;
}
}
}
if (f6 || f7)
continue;
for (int g = 0; g < 8; g++) {
if (a == g || b == g || c == g || d == g || e == g ||
f == g)
continue;
Dice dg = ds[g][0];
boolean f8 = true;
boolean f9 = true;
for (int i = 1; i <= 6; i++) {
for (int j = 1; j <= 6; j++) {
if (abs(dg.cs[i] - df.cs[j]) == 32) {
f8 = false;
}
if (abs(dg.cs[i] - dc.cs[j]) == 32) {
f9 = false;
}
}
}
if (f8 || f9)
continue;
for (int h = 0; h < 8; h++) {
if (a == h || b == h || c == h || d == h || e == h ||
f == h || g == h)
continue;
Dice dh = ds[h][0];
boolean f10 = true;
boolean f11 = true;
boolean f12 = true;
for (int i = 1; i <= 6; i++) {
for (int j = 1; j <= 6; j++) {
if (abs(dg.cs[i] - dh.cs[j]) == 32) {
f10 = false;
}
if (abs(dh.cs[i] - dd.cs[j]) == 32) {
f11 = false;
}
if (abs(dh.cs[i] - de.cs[j]) == 32) {
f12 = false;
}
}
}
if (f10 || f11 | f12)
continue;
Dice[] pos = new Dice[8];
for (int i = 0; i <= 6; i++) {
pos[0] = ds[a][i];
for (int j = 0; j < 24; j++) {
pos[1] = ds[b][j];
if (abs(pos[0].cs[5] - pos[1].cs[2]) != 32)
continue;
for (int k = 0; k < 24; k++) {
pos[2] = ds[c][k];
if (abs(pos[1].cs[3] - pos[2].cs[4]) != 32)
continue;
for (int p = 0; p < 24; p++) {
pos[3] = ds[d][p];
if (abs(pos[2].cs[2] - pos[3].cs[5]) != 32 ||
abs(pos[0].cs[3] - pos[3].cs[4]) != 32)
continue;
for (int q = 0; q < 24; q++) {
pos[4] = ds[e][q];
if (abs(pos[0].cs[6] - pos[4].cs[1]) != 32)
continue;
for (int r = 0; r < 24; r++) {
pos[5] = ds[f][r];
if (abs(pos[5].cs[2] - pos[4].cs[5]) != 32 ||
abs(pos[1].cs[6] - pos[5].cs[1]) != 32)
continue;
for (int s = 0; s < 24; s++) {
pos[6] = ds[g][s];
if (abs(pos[5].cs[3] - pos[6].cs[4]) !=
32 ||
abs(pos[6].cs[1] - pos[2].cs[6]) != 32)
continue;
for (int t = 0; t < 24; t++) {
pos[7] = ds[h][t];
if (abs(pos[4].cs[3] - pos[7].cs[4]) !=
32 ||
abs(pos[6].cs[2] - pos[7].cs[5]) !=
32 ||
abs(pos[7].cs[1] - pos[3].cs[6]) !=
32)
continue;
yes = true;
a = b = c = d = e = f = g = h = i = j =
k = p = q = r = s = INF;
break;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
System.out.println(yes ? "YES" : "NO");
}
}
int abs(int n) { return n > 0 ? n : -n; }
public static void main(String[] args) throws Exception { new Main().run(); }
}
class Dice {
char cs[] = new char[7];
Dice(char c1, char c2, char c3, char c4, char c5, char c6) {
cs[1] = c1;
cs[2] = c2;
cs[3] = c3;
cs[4] = c4;
cs[5] = c5;
cs[6] = c6;
}
Dice(String str) {
char[] tmp = str.toCharArray();
for (int i = 0; i < 6; i++) {
cs[i + 1] = tmp[i];
}
}
public Dice North() {
return new Dice(cs[2], cs[6], cs[3], cs[4], cs[1], cs[5]);
}
public Dice East() {
return new Dice(cs[4], cs[2], cs[1], cs[6], cs[5], cs[3]);
}
public Dice Right() {
return new Dice(cs[1], cs[4], cs[2], cs[5], cs[3], cs[6]);
}
public String toString() { return Arrays.toString(cs); }
}
|
[["-", 0, 7, 8, 196, 0, 7, 15, 16, 12, 499], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 12, 499]]
| 3
| 2,281
| 2
|
// AOJ 0171: Dice Puzzle
// 2017.8.17 bal4u@uu
// 2017.12.29
// ?????????????????¢??¨??????????????????????????°
#include <stdio.h>
int rot[24][7] = {
{0, 1, 2, 3, 4, 5, 6}, {0, 1, 3, 5, 2, 4, 6}, {0, 1, 4, 2, 5, 3, 6},
{0, 1, 5, 4, 3, 2, 6}, {0, 2, 6, 3, 4, 1, 5}, {0, 2, 3, 1, 6, 4, 5},
{0, 2, 1, 4, 3, 6, 5}, {0, 2, 4, 6, 1, 3, 5}, {0, 3, 1, 2, 5, 6, 4},
{0, 3, 2, 6, 1, 5, 4}, {0, 3, 5, 1, 6, 2, 4}, {0, 3, 6, 5, 2, 1, 4},
{0, 4, 1, 5, 2, 6, 3}, {0, 4, 2, 1, 6, 5, 3}, {0, 4, 5, 6, 1, 2, 3},
{0, 4, 6, 2, 5, 1, 3}, {0, 5, 1, 3, 4, 6, 2}, {0, 5, 3, 6, 1, 4, 2},
{0, 5, 4, 1, 6, 3, 2}, {0, 5, 6, 4, 3, 1, 2}, {0, 6, 2, 4, 3, 5, 1},
{0, 6, 3, 2, 5, 4, 1}, {0, 6, 5, 3, 4, 2, 1}, {0, 6, 4, 5, 2, 3, 1}};
int con[8][7][2] = {
{{0}},
{{0}, {0}, {0}, {0}, {0, 3}, {0}, {0}}, // ?????????????????¨??¢??????
{{0}, {0}, {1, 5}, {0}, {0}, {0}, {0}},
{{0}, {0}, {0, 5}, {2, 4}, {0}, {0}, {0}},
{{0}, {0}, {0}, {0}, {0}, {0}, {0, 1}},
{{0}, {0}, {0}, {0}, {4, 3}, {0}, {1, 1}},
{{0}, {0}, {5, 5}, {0}, {0}, {0}, {2, 1}},
{{0}, {0}, {4, 5}, {6, 4}, {0}, {0}, {3, 1}}};
char dice[8][8];
char kari[8][8], f[9];
char tr[128];
int rec(int n) {
int i, j, k, cnt;
char tbl[7][2], c;
if (n == 8)
return 1;
for (i = 0; i < 8; i++) {
if (f[i])
continue;
cnt = 0;
for (j = 1; j <= 6; j++)
if (con[n][j][1]) {
c = tr[kari[con[n][j][0]][con[n][j][1]]];
for (k = 1;; k++) {
if (k > 6)
goto next;
if (dice[i][k] == c) {
tbl[cnt][0] = j, tbl[cnt++][1] = c;
break;
}
}
}
for (j = 0; j < 12; j++) {
for (k = 1; k <= 6; k++)
kari[n][k] = dice[i][rot[j][k]];
for (k = 0; k < cnt; k++) {
if (kari[n][tbl[k][0]] != tbl[k][1])
break;
}
if (k < cnt)
continue;
f[i] = 1;
if (rec(n + 1))
return 1;
f[i] = 0;
}
next:;
}
return 0;
}
int main() {
int i, j, k;
char buf[10];
for (i = 0; i < 26; i++)
tr['a' + i] = 'A' + i, tr['A' + i] = 'a' + i;
while (1) {
for (i = 0; i < 8; i++) {
fgets(buf, 10, stdin);
if (*buf == '0')
return 0;
for (j = 0; j < 6; j++)
dice[i][j + 1] = buf[j];
f[i] = 0;
}
for (i = 0;; i++) {
if (i == 7) {
puts("NO");
break;
}
f[i] = 1;
for (j = 0; j < 12; j++) {
for (k = 1; k <= 6; k++)
kari[0][k] = dice[i][rot[j][k]];
if (rec(1)) {
puts("YES");
goto next;
}
}
f[i] = 0;
}
next:;
}
return 0;
}
|
// AOJ 0171: Dice Puzzle
// 2017.8.17 bal4u@uu
// 2017.12.29
// ?????????????????¢??¨??????????????????????????°
#include <stdio.h>
int rot[24][7] = {
{0, 1, 2, 3, 4, 5, 6}, {0, 1, 3, 5, 2, 4, 6}, {0, 1, 4, 2, 5, 3, 6},
{0, 1, 5, 4, 3, 2, 6}, {0, 2, 6, 3, 4, 1, 5}, {0, 2, 3, 1, 6, 4, 5},
{0, 2, 1, 4, 3, 6, 5}, {0, 2, 4, 6, 1, 3, 5}, {0, 3, 1, 2, 5, 6, 4},
{0, 3, 2, 6, 1, 5, 4}, {0, 3, 5, 1, 6, 2, 4}, {0, 3, 6, 5, 2, 1, 4},
{0, 4, 1, 5, 2, 6, 3}, {0, 4, 2, 1, 6, 5, 3}, {0, 4, 5, 6, 1, 2, 3},
{0, 4, 6, 2, 5, 1, 3}, {0, 5, 1, 3, 4, 6, 2}, {0, 5, 3, 6, 1, 4, 2},
{0, 5, 4, 1, 6, 3, 2}, {0, 5, 6, 4, 3, 1, 2}, {0, 6, 2, 4, 3, 5, 1},
{0, 6, 3, 2, 5, 4, 1}, {0, 6, 5, 3, 4, 2, 1}, {0, 6, 4, 5, 2, 3, 1}};
int con[8][7][2] = {
{{0}},
{{0}, {0}, {0}, {0}, {0, 3}, {0}, {0}}, // ?????????????????¨??¢??????
{{0}, {0}, {1, 5}, {0}, {0}, {0}, {0}},
{{0}, {0}, {0, 5}, {2, 4}, {0}, {0}, {0}},
{{0}, {0}, {0}, {0}, {0}, {0}, {0, 1}},
{{0}, {0}, {0}, {0}, {4, 3}, {0}, {1, 1}},
{{0}, {0}, {5, 5}, {0}, {0}, {0}, {2, 1}},
{{0}, {0}, {4, 5}, {6, 4}, {0}, {0}, {3, 1}}};
char dice[8][8];
char kari[8][8], f[9];
char tr[128];
int rec(int n) {
int i, j, k, cnt;
char tbl[7][2], c;
if (n == 8)
return 1;
for (i = 0; i < 8; i++) {
if (f[i])
continue;
cnt = 0;
for (j = 1; j <= 6; j++)
if (con[n][j][1]) {
c = tr[kari[con[n][j][0]][con[n][j][1]]];
for (k = 1;; k++) {
if (k > 6)
goto next;
if (dice[i][k] == c) {
tbl[cnt][0] = j, tbl[cnt++][1] = c;
break;
}
}
}
for (j = 0; j < 24; j++) {
for (k = 1; k <= 6; k++)
kari[n][k] = dice[i][rot[j][k]];
for (k = 0; k < cnt; k++) {
if (kari[n][tbl[k][0]] != tbl[k][1])
break;
}
if (k < cnt)
continue;
f[i] = 1;
if (rec(n + 1))
return 1;
f[i] = 0;
}
next:;
}
return 0;
}
int main() {
int i, j, k;
char buf[10];
for (i = 0; i < 26; i++)
tr['a' + i] = 'A' + i, tr['A' + i] = 'a' + i;
while (1) {
for (i = 0; i < 8; i++) {
fgets(buf, 10, stdin);
if (*buf == '0')
return 0;
for (j = 0; j < 6; j++)
dice[i][j + 1] = buf[j];
f[i] = 0;
}
for (i = 0;; i++) {
if (i == 7) {
puts("NO");
break;
}
f[i] = 1;
for (j = 0; j < 12; j++) {
for (k = 1; k <= 6; k++)
kari[0][k] = dice[i][rot[j][k]];
if (rec(1)) {
puts("YES");
goto next;
}
}
f[i] = 0;
}
next:;
}
return 0;
}
|
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13]]
| 0
| 1,255
| 2
|
TOP, FRONT, RIGHT, LEFT, BACK, BOTTOM = *0...6
Direction = [
[0, 1, 2, 3, 4, 5],
[0, 2, 4, 1, 3, 5],
[0, 4, 3, 2, 1, 5],
[0, 3, 1, 4, 2, 5],
[1, 5, 2, 3, 0, 4],
[1, 3, 5, 0, 2, 4],
[2, 5, 4, 1, 0, 3],
[3, 4, 5, 0, 1, 2],
[4, 0, 2, 3, 5, 1],
[4, 2, 5, 0, 3, 1],
[4, 5, 3, 2, 0, 1],
[4, 3, 0, 5, 2, 1],
[5, 4, 2, 3, 1, 0],
[5, 2, 1, 4, 3, 0],
[5, 1, 3, 2, 4, 0],
[5, 3, 4, 1, 2, 0],
[1, 2, 0, 5, 3, 4],
[1, 0, 3, 2, 5, 4],
[2, 1, 5, 0, 4, 3],
[2, 4, 0, 5, 1, 3],
[2, 0, 1, 4, 5, 3],
[3, 1, 0, 5, 4, 2],
[3, 0, 4, 1, 5, 2],
[3, 5, 1, 4, 0, 2],
]
Connect = [
[],
[nil, nil, nil, [0, RIGHT], nil, nil],
[nil, nil, nil, nil, [0, FRONT], nil],
[nil, nil, nil, [2, RIGHT], [1, FRONT], nil],
[[0, BOTTOM], nil, nil, nil, nil, nil],
[[1, BOTTOM], nil, nil, [4, RIGHT], nil, nil],
[[2, BOTTOM], nil, nil, nil, [4, FRONT], nil],
[[3, BOTTOM], nil, nil, [6, RIGHT], [5, FRONT], nil],
]
def dfs(result, result_direction)
return true if result.size == 8
position = result.size
8.times do |die|
next if result.include?(die)
Direction.each do |dir|
ok = true
6.times do |i|
next unless Connect[position][i]
id, face = Connect[position][i]
a, b = @die[die][dir[i]], @die[result[id]][result_direction[id][face]]
if a == b || a.downcase != b.downcase
ok = false
break
end
end
if ok
return true if dfs(result + [die], result_direction + [dir])
end
end
end
false
end
def check?
Direction[0...8].each do |d|
return true if dfs([0], [d])
end
false
end
until (list = [gets.chomp]) == ["0"]
list += 7.times.map{gets.chomp}
@die = list.map{|l| l.chars}
puts check? ? "YES" : "NO"
end
|
TOP, FRONT, RIGHT, LEFT, BACK, BOTTOM = *0...6
Direction = [
[0, 1, 2, 3, 4, 5],
[0, 2, 4, 1, 3, 5],
[0, 4, 3, 2, 1, 5],
[0, 3, 1, 4, 2, 5],
[1, 5, 2, 3, 0, 4],
[1, 3, 5, 0, 2, 4],
[2, 5, 4, 1, 0, 3],
[3, 4, 5, 0, 1, 2],
[4, 0, 2, 3, 5, 1],
[4, 2, 5, 0, 3, 1],
[4, 5, 3, 2, 0, 1],
[4, 3, 0, 5, 2, 1],
[5, 4, 2, 3, 1, 0],
[5, 2, 1, 4, 3, 0],
[5, 1, 3, 2, 4, 0],
[5, 3, 4, 1, 2, 0],
[1, 2, 0, 5, 3, 4],
[1, 0, 3, 2, 5, 4],
[2, 1, 5, 0, 4, 3],
[2, 4, 0, 5, 1, 3],
[2, 0, 1, 4, 5, 3],
[3, 1, 0, 5, 4, 2],
[3, 0, 4, 1, 5, 2],
[3, 5, 1, 4, 0, 2],
]
Connect = [
[],
[nil, nil, nil, [0, RIGHT], nil, nil],
[nil, nil, nil, nil, [0, FRONT], nil],
[nil, nil, nil, [2, RIGHT], [1, FRONT], nil],
[[0, BOTTOM], nil, nil, nil, nil, nil],
[[1, BOTTOM], nil, nil, [4, RIGHT], nil, nil],
[[2, BOTTOM], nil, nil, nil, [4, FRONT], nil],
[[3, BOTTOM], nil, nil, [6, RIGHT], [5, FRONT], nil],
]
def dfs(result, result_direction)
return true if result.size == 8
position = result.size
8.times do |die|
next if result.include?(die)
Direction.each do |dir|
ok = true
6.times do |i|
next unless Connect[position][i]
id, face = Connect[position][i]
a, b = @die[die][dir[i]], @die[result[id]][result_direction[id][face]]
if a == b || a.downcase != b.downcase
ok = false
break
end
end
if ok
return true if dfs(result + [die], result_direction + [dir])
end
end
end
false
end
def check?
Direction.each do |d|
return true if dfs([0], [d])
end
false
end
until (list = [gets.chomp]) == ["0"]
list += 7.times.map{gets.chomp}
@die = list.map{|l| l.chars}
puts check? ? "YES" : "NO"
end
|
[["-", 0, 735, 8, 736, 0, 652, 486, 742, 0, 70], ["-", 8, 736, 0, 652, 486, 742, 0, 475, 756, 612], ["-", 8, 736, 0, 652, 486, 742, 0, 475, 17, 389], ["-", 8, 736, 0, 652, 486, 742, 0, 475, 444, 612], ["-", 0, 735, 8, 736, 0, 652, 486, 742, 0, 73]]
| 4
| 736
| 5
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <vector>
#define F first
#define S second
using namespace std;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
struct Pox {
int cost;
int p;
int bit;
vector<P> step;
// P(1,R) -> Move to room R.
// P(2,R) -> Switch off room R.
// P(3,R) -> Switch on room R.
Pox(int p, int bit, int cost) : p(p), bit(bit), cost(cost) { step.clear(); }
};
int n, m;
int main() {
while (cin >> n >> m, (n || m)) {
VVI G;
G.resize(n);
for (int i = 0; i < m; i++) {
int s, t;
scanf("%d %d", &s, &t);
t--, s--;
G[s].push_back(t);
G[t].push_back(s);
}
int initial_bit = 0;
for (int i = 0; i < n; i++) {
int b;
cin >> b;
if (b)
initial_bit |= (1 << i);
}
VVI E;
E.resize(n);
for (int i = 0; i < n; i++) {
int k;
cin >> k;
for (int j = 0; j < k; j++) {
int r;
cin >> r;
r--;
E[i].push_back(r);
}
sort(E[i].begin(), E[i].end());
}
int mincost[1 << n][n];
for (int i = 0; i <= (1 << n) - 1; i++)
for (int j = 0; j < n; j++)
mincost[i][j] = (1 << 29);
deque<Pox> deq;
mincost[initial_bit][0] = 0;
deq.push_back(Pox(0, initial_bit, 0));
int men_cost = (1 << 29);
vector<P> men_step;
bool sub = false;
while (!deq.empty()) {
Pox pox = deq.front();
deq.pop_front();
if (!((pox.bit >> pox.p) & 1))
continue;
if (pox.p == n - 1 && __builtin_popcount(pox.bit) == 1 &&
(pox.bit >> (n - 1)) & 1) {
if (men_cost > pox.cost) {
men_cost = pox.cost;
men_step = pox.step;
}
} else if (pox.p == n - 1) {
sub = true;
}
for (int i = 0; i < G[pox.p].size(); i++) { // Move
int next = G[pox.p][i];
if (!((pox.bit >> next) & 1))
continue;
if (mincost[pox.bit][next] > pox.cost + 1) {
mincost[pox.bit][next] = pox.cost + 1;
Pox next_pox = Pox(next, pox.bit, pox.cost + 1);
next_pox.step = pox.step;
next_pox.step.push_back(P(1, next));
deq.push_front(next_pox);
}
} // Move
for (int i = 0; i < E[pox.p].size(); i++) {
int next = E[pox.p][i];
if (next == pox.p)
continue;
bool swit = (pox.bit >> next) & 1 ? 0 : 1;
int nbit;
if (swit)
nbit = pox.bit, nbit |= (1 << next);
else
nbit = pox.bit, nbit &= ~(1 << next);
bitset<10> before(nbit);
if (mincost[nbit][pox.p] > pox.cost + 1) {
mincost[nbit][pox.p] = pox.cost + 1;
Pox next_pox = Pox(pox.p, nbit, pox.cost + 1);
next_pox.step = pox.step;
next_pox.step.push_back(P(swit ? 3 : 2, next));
deq.push_front(next_pox);
}
}
}
if (men_cost == (1 << 29) && !sub)
cout << "Help me!" << endl;
else if (men_cost == (1 << 29) && sub)
cout << "You can not switch off all lights." << endl;
else if (men_cost != (1 << 29)) {
cout << "You can go home in " << men_cost << " steps." << endl;
for (int i = 0; i < men_step.size(); i++) {
P p = men_step[i];
if (p.F == 1)
cout << "Move to room " << p.S + 1 << "." << endl;
else if (p.F == 2)
cout << "Switch off room " << p.S + 1 << "." << endl;
else if (p.F == 3)
cout << "Switch on room " << p.S + 1 << "." << endl;
else
assert(false);
}
}
}
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <vector>
#define F first
#define S second
using namespace std;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
struct Pox {
int cost;
int p;
int bit;
vector<P> step;
// P(1,R) -> Move to room R.
// P(2,R) -> Switch off room R.
// P(3,R) -> Switch on room R.
Pox(int p, int bit, int cost) : p(p), bit(bit), cost(cost) { step.clear(); }
};
int n, m;
int main() {
while (cin >> n >> m, (n || m)) {
VVI G;
G.resize(n);
for (int i = 0; i < m; i++) {
int s, t;
scanf("%d %d", &s, &t);
t--, s--;
G[s].push_back(t);
G[t].push_back(s);
}
int initial_bit = 0;
for (int i = 0; i < n; i++) {
int b;
cin >> b;
if (b)
initial_bit |= (1 << i);
}
VVI E;
E.resize(n);
for (int i = 0; i < n; i++) {
int k;
cin >> k;
for (int j = 0; j < k; j++) {
int r;
cin >> r;
r--;
E[i].push_back(r);
}
sort(E[i].begin(), E[i].end());
}
int mincost[1 << n][n];
for (int i = 0; i <= (1 << n) - 1; i++)
for (int j = 0; j < n; j++)
mincost[i][j] = (1 << 29);
deque<Pox> deq;
mincost[initial_bit][0] = 0;
deq.push_back(Pox(0, initial_bit, 0));
int men_cost = (1 << 29);
vector<P> men_step;
bool sub = false;
while (!deq.empty()) {
Pox pox = deq.front();
deq.pop_front();
if (!((pox.bit >> pox.p) & 1))
continue;
if (pox.p == n - 1 && __builtin_popcount(pox.bit) == 1 &&
(pox.bit >> (n - 1)) & 1) {
if (men_cost > pox.cost) {
men_cost = pox.cost;
men_step = pox.step;
}
} else if (pox.p == n - 1) {
sub = true;
}
for (int i = 0; i < G[pox.p].size(); i++) { // Move
int next = G[pox.p][i];
if (!((pox.bit >> next) & 1))
continue;
if (mincost[pox.bit][next] > pox.cost + 1) {
mincost[pox.bit][next] = pox.cost + 1;
Pox next_pox = Pox(next, pox.bit, pox.cost + 1);
next_pox.step = pox.step;
next_pox.step.push_back(P(1, next));
deq.push_back(next_pox);
}
} // Move
for (int i = 0; i < E[pox.p].size(); i++) {
int next = E[pox.p][i];
if (next == pox.p)
continue;
bool swit = (pox.bit >> next) & 1 ? 0 : 1;
int nbit;
if (swit)
nbit = pox.bit, nbit |= (1 << next);
else
nbit = pox.bit, nbit &= ~(1 << next);
bitset<10> before(nbit);
if (mincost[nbit][pox.p] > pox.cost + 1) {
mincost[nbit][pox.p] = pox.cost + 1;
Pox next_pox = Pox(pox.p, nbit, pox.cost + 1);
next_pox.step = pox.step;
next_pox.step.push_back(P(swit ? 3 : 2, next));
deq.push_back(next_pox);
}
}
}
if (men_cost == (1 << 29) && !sub)
cout << "Help me!" << endl;
else if (men_cost == (1 << 29) && sub)
cout << "You can not switch off all lights." << endl;
else if (men_cost != (1 << 29)) {
cout << "You can go home in " << men_cost << " steps." << endl;
for (int i = 0; i < men_step.size(); i++) {
P p = men_step[i];
if (p.F == 1)
cout << "Move to room " << p.S + 1 << "." << endl;
else if (p.F == 2)
cout << "Switch off room " << p.S + 1 << "." << endl;
else if (p.F == 3)
cout << "Switch on room " << p.S + 1 << "." << endl;
else
assert(false);
}
}
}
return 0;
}
|
[["-", 64, 9, 0, 1, 0, 2, 63, 118, 119, 120], ["+", 64, 9, 0, 1, 0, 2, 63, 118, 119, 120]]
| 1
| 1,085
| 4
|
<?php
for ($i = 0; $i < 9; $i++) {
list($name, $morning, $afternoon) = explode(' ', trim(fgets(STDIN)));
$sold = 200 * $morning + 300 * $afternoon;
$total = $morning + $afternoon;
echo "$name, $total $sold\n";
}
|
<?php
for ($i = 0; $i < 9; $i++) {
list($name, $morning, $afternoon) = explode(' ', trim(fgets(STDIN)));
$sold = 200 * $morning + 300 * $afternoon;
$total = $morning + $afternoon;
echo "$name $total $sold\n";
}
|
[["-", 0, 7, 0, 9, 0, 608, 0, 609, 0, 610], ["+", 0, 7, 0, 9, 0, 608, 0, 609, 0, 610]]
| 6
| 81
| 2
|
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String str;
int am, pm;
for (int i = 0; i < 9; i++) {
str = scan.next();
am = scan.nextInt();
pm = scan.nextInt();
System.out.println(str + " " + am + pm + " " + am * 200 + pm * 300);
}
}
}
|
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String str;
int am, pm;
for (int i = 0; i < 9; i++) {
str = scan.next();
am = scan.nextInt();
pm = scan.nextInt();
System.out.println(str + " " + (am + pm) + " " + (am * 200 + pm * 300));
}
}
}
|
[["+", 0, 16, 31, 16, 31, 16, 12, 23, 0, 24], ["+", 0, 16, 31, 16, 31, 16, 12, 23, 0, 25], ["+", 0, 492, 3, 4, 0, 16, 12, 23, 0, 24], ["+", 0, 492, 3, 4, 0, 16, 12, 23, 0, 25]]
| 3
| 111
| 4
|
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
String c = scanner.nextLine();
int am = scanner.nextInt();
int pm = scanner.nextInt();
System.out.printf("%s %d %d\n", c, am + pm, (am * 2 + pm * 3) * 100);
}
}
}
|
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
String c = scanner.next();
int am = scanner.nextInt();
int pm = scanner.nextInt();
System.out.printf("%s %d %d\n", c, am + pm, (am * 2 + pm * 3) * 100);
}
}
}
|
[["-", 8, 196, 0, 503, 49, 200, 51, 492, 141, 22], ["+", 8, 196, 0, 503, 49, 200, 51, 492, 141, 22]]
| 3
| 101
| 2
|
import java.util.Scanner;
class Main {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
for (int i = 0; i < 9; i++) {
String name = scan.next();
int mor, aft;
mor = scan.nextInt();
aft = scan.nextInt();
System.out.println(name + " " + mor + aft + " " + 200 * mor + 300 * aft);
}
}
}
|
import java.util.Scanner;
class Main {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
for (int i = 0; i < 9; i++) {
String name = scan.next();
int mor, aft;
mor = scan.nextInt();
aft = scan.nextInt();
System.out.println(name + " " + (mor + aft) + " " +
(200 * mor + 300 * aft));
}
}
}
|
[["+", 0, 16, 31, 16, 31, 16, 12, 23, 0, 24], ["+", 0, 16, 31, 16, 31, 16, 12, 23, 0, 25], ["+", 0, 492, 3, 4, 0, 16, 12, 23, 0, 24], ["+", 0, 492, 3, 4, 0, 16, 12, 23, 0, 25]]
| 3
| 109
| 4
|
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long int;
using P = pair<string, int>;
using edge = struct {
int to;
int cost;
};
int wfs(string worm) {
queue<P> que;
que.push(P(worm, 0));
map<string, int> mp;
while (!que.empty()) {
P p = que.front();
que.pop();
string tmp = p.first;
if (mp[p.first])
continue;
bool flag = true;
for (int i = 0; i < tmp.size() - 1; i++) {
if (tmp[i] != tmp[i + 1]) {
flag = false;
break;
}
}
if (flag)
return p.second;
mp[p.first] = p.second;
for (int i = 0; i < tmp.size() - 1; i++) {
if (tmp[i] == tmp[i + 1])
continue;
string nworm = tmp;
if (tmp[i] != 'g' && tmp[i + 1] != 'g') {
nworm[i] = 'g';
nworm[i + 1] = 'g';
} else if (tmp[i] != 'b' && tmp[i + 1] != 'b') {
nworm[i] = 'b';
nworm[i + 1] = 'b';
} else {
nworm[i] = 'r';
nworm[i + 1] = 'r';
}
que.push(P(nworm, p.second + 1));
}
}
return -1;
}
int main() {
string input;
while (cin >> input && input != "0") {
cout << (wfs(input) ? to_string(wfs(input)) : "NA") << endl;
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long int;
using P = pair<string, int>;
using edge = struct {
int to;
int cost;
};
int wfs(string worm) {
queue<P> que;
que.push(P(worm, 0));
map<string, int> mp;
while (!que.empty()) {
P p = que.front();
que.pop();
string tmp = p.first;
if (mp[p.first])
continue;
bool flag = true;
for (int i = 0; i < tmp.size() - 1; i++) {
if (tmp[i] != tmp[i + 1]) {
flag = false;
break;
}
}
if (flag)
return p.second;
mp[p.first] = p.second;
for (int i = 0; i < tmp.size() - 1; i++) {
if (tmp[i] == tmp[i + 1])
continue;
string nworm = tmp;
if (tmp[i] != 'g' && tmp[i + 1] != 'g') {
nworm[i] = 'g';
nworm[i + 1] = 'g';
} else if (tmp[i] != 'b' && tmp[i + 1] != 'b') {
nworm[i] = 'b';
nworm[i + 1] = 'b';
} else {
nworm[i] = 'r';
nworm[i + 1] = 'r';
}
que.push(P(nworm, p.second + 1));
}
}
return -1;
}
int main() {
string input;
while (cin >> input && input != "0") {
cout << (wfs(input) != -1 ? to_string(wfs(input)) : "NA") << endl;
}
return 0;
}
|
[["+", 31, 16, 12, 23, 0, 41, 15, 16, 17, 79], ["+", 31, 16, 12, 23, 0, 41, 15, 16, 12, 13]]
| 1
| 456
| 2
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define SORT(v, n) sort(v, v + n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(), v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
using namespace std;
typedef pair<int, int> pii;
bool isAns(string s) {
int len = s.length();
FOR(i, 1, len) {
if (s[0] != s[i])
return false;
}
return true;
}
char diffColor(char a, char b) {
if ((a == 'r' && b == 'g') || (a == 'g' && b == 'r')) {
return 'b';
} else if ((a == 'g' && b == 'b') || (a == 'b' && b == 'g')) {
return 'r';
} else {
return 'g';
}
}
int main() {
while (true) {
string s;
cin >> s;
if (s == "0")
break;
map<string, int> mp;
mp[s] = 1;
queue<string> que;
que.push(s);
bool found = false;
while (!que.empty()) {
s = que.front();
que.pop();
if (isAns(s)) {
found = true;
cout << mp[s] - 1 << "\n";
break;
}
int len = s.length();
REP(i, len - 1) {
if (s[i] != s[i + 1]) {
string v = s;
char tmp = diffColor(s[i], s[i + 1]);
v[i] = tmp;
v[i + 1] = tmp;
if (mp[v] == 0) {
mp[v] = mp[s] + 1;
que.push(v);
}
}
}
}
if (!found) {
cout << "Na\n";
}
}
return 0;
}
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define SORT(v, n) sort(v, v + n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(), v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
using namespace std;
typedef pair<int, int> pii;
bool isAns(string s) {
int len = s.length();
FOR(i, 1, len) {
if (s[0] != s[i])
return false;
}
return true;
}
char diffColor(char a, char b) {
if ((a == 'r' && b == 'g') || (a == 'g' && b == 'r')) {
return 'b';
} else if ((a == 'g' && b == 'b') || (a == 'b' && b == 'g')) {
return 'r';
} else {
return 'g';
}
}
int main() {
while (true) {
string s;
cin >> s;
if (s == "0")
break;
map<string, int> mp;
mp[s] = 1;
queue<string> que;
que.push(s);
bool found = false;
while (!que.empty()) {
s = que.front();
que.pop();
if (isAns(s)) {
found = true;
cout << mp[s] - 1 << "\n";
break;
}
int len = s.length();
REP(i, len - 1) {
if (s[i] != s[i + 1]) {
string v = s;
char tmp = diffColor(s[i], s[i + 1]);
v[i] = tmp;
v[i + 1] = tmp;
if (mp[v] == 0) {
mp[v] = mp[s] + 1;
que.push(v);
}
}
}
}
if (!found) {
cout << "NA\n";
}
}
return 0;
}
|
[["-", 64, 9, 0, 1, 0, 16, 12, 5, 0, 6], ["+", 64, 9, 0, 1, 0, 16, 12, 5, 0, 6]]
| 1
| 528
| 2
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#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++)
class S {
public:
string s;
int n;
S(string s, int n) : s(s), n(n) {}
};
int main() {
while (1) {
string a;
cin >> a;
if (a == "0")
break;
queue<S> que;
map<string, int> memo;
char cc[111][111];
rep(i, 111) rep(j, 111) cc[i][j] = -1;
que.push(S(a, 0));
int ans = 0;
int kn = 0;
while (1) {
if (que.empty() == 1) {
break;
}
S u = que.front();
que.pop();
ans = u.n;
// cout<<u.s<<" "<<u.n<<endl;
if (memo[u.s] != 0) {
continue;
}
memo[u.s] = 1;
int comp = 1;
int ch = u.s[0];
reps(i, u.s.size() - 1) {
if (ch != u.s[i]) {
comp = 0;
break;
}
}
if (comp == 1) {
kn = 1;
break;
}
cc['r']['g'] = cc['g']['r'] = 'b';
cc['r']['b'] = cc['b']['r'] = 'g';
cc['b']['g'] = cc['g']['b'] = 'r';
rep(i, u.s.size() - 1) {
string cop = u.s;
if (u.s[i] != u.s[i + 1]) {
cop[i] = cop[i + 1] = cc[cop[i]][cop[i + 1]];
que.push(S(cop, u.n + 1));
}
}
}
if (kn == 1) {
printf("%d\n", ans);
} else {
printf("-1\n");
}
}
}
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#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++)
class S {
public:
string s;
int n;
S(string s, int n) : s(s), n(n) {}
};
int main() {
while (1) {
string a;
cin >> a;
if (a == "0")
break;
queue<S> que;
map<string, int> memo;
char cc[111][111];
rep(i, 111) rep(j, 111) cc[i][j] = -1;
que.push(S(a, 0));
int ans = 0;
int kn = 0;
while (1) {
if (que.empty() == 1) {
break;
}
S u = que.front();
que.pop();
ans = u.n;
// cout<<u.s<<" "<<u.n<<endl;
if (memo[u.s] != 0) {
continue;
}
memo[u.s] = 1;
int comp = 1;
int ch = u.s[0];
reps(i, u.s.size() - 1) {
if (ch != u.s[i]) {
comp = 0;
break;
}
}
if (comp == 1) {
kn = 1;
break;
}
cc['r']['g'] = cc['g']['r'] = 'b';
cc['r']['b'] = cc['b']['r'] = 'g';
cc['b']['g'] = cc['g']['b'] = 'r';
rep(i, u.s.size() - 1) {
string cop = u.s;
if (u.s[i] != u.s[i + 1]) {
cop[i] = cop[i + 1] = cc[cop[i]][cop[i + 1]];
que.push(S(cop, u.n + 1));
}
}
}
if (kn == 1) {
printf("%d\n", ans);
} else {
printf("NA\n");
}
}
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 1
| 496
| 2
|
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
int n, m;
vector<P> branch[128];
int prim();
int main() {
while (scanf("%d %d", &n, &m), n != 0) {
for (int i = 0; i < n; i++)
branch[i].clear();
for (int i = 0; i < m; i++) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
branch[a].push_back(P(c, b));
branch[b].push_back(P(c, a));
}
printf("%d\n", prim());
}
return 0;
}
int prim() {
bool v[1024];
priority_queue<P, vector<P>, greater<P>> q;
int sum = 0;
q.push(P(0, 0));
v[0] = 0;
while (!q.empty()) {
P p = q.top();
q.pop();
if (v[p.second])
continue;
v[p.second] = true;
sum += p.first;
for (int i = 0; i < branch[p.second].size(); i++) {
q.push(branch[p.second][i]);
}
}
return sum;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
int n, m;
vector<P> branch[128];
int prim();
int main() {
while (scanf("%d %d", &n, &m), n != 0) {
for (int i = 0; i < n; i++)
branch[i].clear();
for (int i = 0; i < m; i++) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
branch[a].push_back(P(c, b));
branch[b].push_back(P(c, a));
}
printf("%d\n", prim());
}
return 0;
}
int prim() {
bool v[1024] = {false};
priority_queue<P, vector<P>, greater<P>> q;
int sum = 0;
q.push(P(0, 0));
v[0] = 0;
while (!q.empty()) {
P p = q.top();
q.pop();
if (v[p.second])
continue;
v[p.second] = true;
sum += p.first;
for (int i = 0; i < branch[p.second].size(); i++) {
q.push(branch[p.second][i]);
}
}
return sum;
}
|
[["+", 0, 14, 8, 9, 0, 43, 49, 50, 0, 32], ["+", 8, 9, 0, 43, 49, 50, 51, 83, 0, 45], ["+", 8, 9, 0, 43, 49, 50, 51, 83, 0, 147], ["+", 8, 9, 0, 43, 49, 50, 51, 83, 0, 46]]
| 1
| 315
| 4
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
typedef long long int ll;
#define FOR(i, a, n) for (int i = a; i < n; ++i)
#define TFOR(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end();
const int INF = 1LL << 30;
const ll LLINF = 1LL << 60;
int V; //??????
int E; //???
struct edge {
int from, to, cost;
};
typedef std::pair<int, int> PP;
std::vector<edge> e;
int Par[100000];
int Rank[100000];
void init(int n) {
for (int i = 0; i < n; i++) {
Par[i] = i;
Rank[i] = 0;
}
}
int find(int x) {
if (Par[x] == x) {
return x;
} else {
return Par[x] = find(Par[x]);
}
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y)
return;
if (Rank[x] < Rank[y]) {
Par[x] = y;
} else {
Par[y] = x;
if (Rank[x] == Rank[y])
Rank[x]++;
}
}
bool same(int x, int y) { return find(x) == find(y); }
// ??????????????????????????????????????¢??°
bool comp(const edge &e1, const edge &e2) { return e1.cost < e2.cost; }
int kruskal() {
init(V);
sort(e.begin(), e.end(), comp);
int ans = 0;
for (int i = 0; i < E; i++) {
if (!same(e[i].from, e[i].to)) {
unite(e[i].from, e[i].to);
ans += e[i].cost;
}
}
return ans;
}
int main() {
while (std::cin >> V >> E && V) {
int a, b, c;
for (int i = 0; i < E; i++) {
std::cin >> a >> b >> c;
e.push_back(edge{a, b, c});
}
std::cout << kruskal() << std::endl;
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
typedef long long int ll;
#define FOR(i, a, n) for (int i = a; i < n; ++i)
#define TFOR(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end();
const int INF = 1LL << 30;
const ll LLINF = 1LL << 60;
int V; //??????
int E; //???
struct edge {
int from, to, cost;
};
typedef std::pair<int, int> PP;
std::vector<edge> e;
int Par[100000];
int Rank[100000];
void init(int n) {
for (int i = 0; i < n; i++) {
Par[i] = i;
Rank[i] = 0;
}
}
int find(int x) {
if (Par[x] == x) {
return x;
} else {
return Par[x] = find(Par[x]);
}
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y)
return;
if (Rank[x] < Rank[y]) {
Par[x] = y;
} else {
Par[y] = x;
if (Rank[x] == Rank[y])
Rank[x]++;
}
}
bool same(int x, int y) { return find(x) == find(y); }
// ??????????????????????????????????????¢??°
bool comp(const edge &e1, const edge &e2) { return e1.cost < e2.cost; }
int kruskal() {
init(V);
sort(e.begin(), e.end(), comp);
int ans = 0;
for (int i = 0; i < E; i++) {
if (!same(e[i].from, e[i].to)) {
unite(e[i].from, e[i].to);
ans += e[i].cost;
}
}
return ans;
}
int main() {
while (std::cin >> V >> E && V) {
int a, b, c;
for (int i = 0; i < E; i++) {
std::cin >> a >> b >> c;
e.push_back(edge{a, b, c});
}
std::cout << kruskal() << std::endl;
e = {};
}
return 0;
}
|
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 8, 9, 0, 1, 0, 11, 12, 83, 0, 45], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
| 1
| 497
| 5
|
#include <iostream>
#define TOSHI_MAX 100
#define COST_MAX 10
using namespace std;
int prim(int data[TOSHI_MAX][TOSHI_MAX], int toshiNum) {
bool visited[toshiNum];
int cost[toshiNum];
for (int i = 0; i < toshiNum; i++) {
visited[i] = false;
cost[i] = COST_MAX;
}
cost[0] = 0;
while (1) {
int min = COST_MAX;
int p;
for (int i = 0; i < toshiNum; i++) {
if (!visited[i] && cost[i] < min) {
min = cost[i];
p = i;
}
}
if (min == COST_MAX)
break;
visited[p] = true;
for (int i = 0; i < toshiNum; i++) {
if (!visited[i] && data[p][i] < cost[i]) {
cost[i] = data[p][i];
}
}
}
int ans = 0;
for (int i = 0; i < toshiNum; i++) {
if (cost[i] != COST_MAX)
ans += cost[i];
}
return ans;
}
int main() {
while (1) {
int n, m;
cin >> n >> m;
if (n == 0 && m == 0)
break;
int data[TOSHI_MAX][TOSHI_MAX];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
data[i][j] = COST_MAX;
}
}
for (int i = 0; i < m; i++) {
int a, b, cost;
cin >> a >> b >> cost;
data[a][b] = data[b][a] = cost;
}
cout << prim(data, n) << endl;
}
return 0;
}
|
#include <iostream>
#define TOSHI_MAX 100
#define COST_MAX 100000
using namespace std;
int prim(int data[TOSHI_MAX][TOSHI_MAX], int toshiNum) {
bool visited[toshiNum];
int cost[toshiNum];
for (int i = 0; i < toshiNum; i++) {
visited[i] = false;
cost[i] = COST_MAX;
}
cost[0] = 0;
while (1) {
int min = COST_MAX;
int p;
for (int i = 0; i < toshiNum; i++) {
if (!visited[i] && cost[i] < min) {
min = cost[i];
p = i;
}
}
if (min == COST_MAX)
break;
visited[p] = true;
for (int i = 0; i < toshiNum; i++) {
if (!visited[i] && data[p][i] < cost[i]) {
cost[i] = data[p][i];
}
}
}
int ans = 0;
for (int i = 0; i < toshiNum; i++) {
if (cost[i] != COST_MAX)
ans += cost[i];
}
return ans;
}
int main() {
while (1) {
int n, m;
cin >> n >> m;
if (n == 0 && m == 0)
break;
int data[TOSHI_MAX][TOSHI_MAX];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
data[i][j] = COST_MAX;
}
}
for (int i = 0; i < m; i++) {
int a, b, cost;
cin >> a >> b >> cost;
data[a][b] = data[b][a] = cost;
}
cout << prim(data, n) << endl;
}
return 0;
}
|
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59]]
| 1
| 392
| 2
|
#include <cstdlib>
#include <iostream>
using namespace std;
struct Bridge {
int a, b, cost;
};
int n, m, ans, parent[10001];
Bridge bridge[10001];
int bridge_comp(const void *a, const void *b) {
return ((Bridge *)a)->cost - ((Bridge *)b)->cost;
}
int root(int a) {
if (parent[a] == a)
return a;
else
return (parent[a] = root(parent[a]));
}
int main() {
while ((cin >> n >> m), n && m) {
for (int i = 0; i < n; i++)
parent[i] = i;
for (int i = 0; i < m; i++)
cin >> bridge[i].a >> bridge[i].b >> bridge[i].cost;
qsort(bridge, m, sizeof(Bridge), bridge_comp);
ans = 0;
for (int i = 0; i < m; i++) {
if ((n = root(bridge[i].a)) != root(bridge[i].b)) {
parent[bridge[i].b] = n;
ans += bridge[i].cost;
}
}
cout << ans << endl;
}
return 0;
}
|
#include <cstdlib>
#include <iostream>
using namespace std;
struct Bridge {
int a, b, cost;
};
int n, m, ans, parent[10001];
Bridge bridge[10001];
int bridge_comp(const void *a, const void *b) {
return ((Bridge *)a)->cost - ((Bridge *)b)->cost;
}
int root(int a) {
if (parent[a] == a)
return a;
else
return (parent[a] = root(parent[a]));
}
int main() {
while ((cin >> n >> m), n && m) {
for (int i = 0; i < n; i++)
parent[i] = i;
for (int i = 0; i < m; i++)
cin >> bridge[i].a >> bridge[i].b >> bridge[i].cost;
qsort(bridge, m, sizeof(Bridge), bridge_comp);
ans = 0;
for (int i = 0; i < m; i++) {
if ((n = root(bridge[i].a)) != root(bridge[i].b)) {
parent[root(bridge[i].b)] = n;
ans += bridge[i].cost;
}
}
cout << ans << endl;
}
return 0;
}
|
[["+", 0, 11, 31, 69, 341, 342, 0, 2, 63, 22], ["+", 31, 69, 341, 342, 0, 2, 3, 4, 0, 24], ["+", 31, 69, 341, 342, 0, 2, 3, 4, 0, 25]]
| 1
| 283
| 3
|
// kruskal tree
#include <algorithm>
#include <iostream>
using namespace std;
#define M 101
int parent[M], a[M], b[M];
pair<int, int> node[M];
int root(int a) {
if (parent[a] == a)
return a;
return parent[a] = root(parent[a]);
}
int unite(int a, int b) {
if (root(a) != root(b))
return 0;
parent[root(a)] = root(b);
return 1;
}
int main() {
int i, s, n, m;
for (; cin >> n >> m, n; cout << s << endl) {
for (i = 0; i < m; i++)
cin >> a[i] >> b[i] >> node[i].first, node[i].second = i;
sort(node, node + m);
for (i = 0; i < n; i++)
parent[i] = i;
for (s = i = 0; i < m; i++)
if (unite(a[node[i].second], b[node[i].second]))
s += node[i].first;
}
}
|
// kruskal tree
#include <algorithm>
#include <iostream>
using namespace std;
#define M 9999
int parent[M], a[M], b[M];
pair<int, int> node[M];
int root(int a) {
if (parent[a] == a)
return a;
return parent[a] = root(parent[a]);
}
int unite(int a, int b) {
if (root(a) == root(b))
return 0;
parent[root(a)] = root(b);
return 1;
}
int main() {
int i, s, n, m;
for (; cin >> n >> m, n; cout << s << endl) {
for (i = 0; i < m; i++)
cin >> a[i] >> b[i] >> node[i].first, node[i].second = i;
sort(node, node + m);
for (i = 0; i < n; i++)
parent[i] = i;
for (s = i = 0; i < m; i++)
if (unite(a[node[i].second], b[node[i].second]))
s += node[i].first;
}
}
|
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 79], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60]]
| 1
| 268
| 4
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
const int MAXN = 105;
using namespace std;
struct UnionFind {
vector<int> data;
UnionFind(int size) : data(size, -1) {}
bool unionSet(int x, int y) {
x = root(x);
y = root(y);
if (x != y) {
if (data[y] < data[x])
swap(x, y);
data[x] += data[y];
data[y] = x;
}
return x != y;
}
bool findSet(int x, int y) { return root(x) == root(y); }
int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
int size(int x) { return -data[root(x)]; }
};
struct edge {
edge(int from, int to) : from(from), to(to) {}
int from, to;
};
bool operator<(edge a, edge b) {
if (a.from != b.from)
return a.from < b.from;
else
return a.to < b.to;
}
typedef pair<int, pair<int, int>> P;
int main() {
int n, m;
while (cin >> n >> m && (n | m) != 0) {
priority_queue<P, vector<P>, greater<P>> que;
for (int i = 0; i < m; ++i) {
int a, b, c;
cin >> a >> b >> c;
que.push(make_pair(c, make_pair(a, b)));
}
UnionFind u(MAXN);
int ans = 0;
for (int i = 0; i < m; ++i) {
int from = que.top().second.first;
int to = que.top().second.second;
int cost = que.top().first;
if (!u.findSet(to, from)) {
// cout << "cost:" << cost << " " << top.to << " " << top.from << endl;
ans += cost;
u.unionSet(to, from);
}
}
cout << ans << endl;
}
return 0;
}
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
const int MAXN = 105;
using namespace std;
struct UnionFind {
vector<int> data;
UnionFind(int size) : data(size, -1) {}
bool unionSet(int x, int y) {
x = root(x);
y = root(y);
if (x != y) {
if (data[y] < data[x])
swap(x, y);
data[x] += data[y];
data[y] = x;
}
return x != y;
}
bool findSet(int x, int y) { return root(x) == root(y); }
int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
int size(int x) { return -data[root(x)]; }
};
struct edge {
edge(int from, int to) : from(from), to(to) {}
int from, to;
};
bool operator<(edge a, edge b) {
if (a.from != b.from)
return a.from < b.from;
else
return a.to < b.to;
}
typedef pair<int, pair<int, int>> P;
int main() {
int n, m;
while (cin >> n >> m && (n | m) != 0) {
priority_queue<P, vector<P>, greater<P>> que;
for (int i = 0; i < m; ++i) {
int a, b, c;
cin >> a >> b >> c;
que.push(make_pair(c, make_pair(a, b)));
}
UnionFind u(MAXN);
int ans = 0;
for (int i = 0; i < m; ++i) {
int from = que.top().second.first;
int to = que.top().second.second;
int cost = que.top().first;
que.pop();
if (!u.findSet(to, from)) {
// cout << "cost:" << cost << " " << top.to << " " << top.from << endl;
ans += cost;
u.unionSet(to, from);
}
}
cout << ans << endl;
}
return 0;
}
|
[["+", 8, 9, 0, 1, 0, 2, 63, 118, 28, 22], ["+", 8, 9, 0, 1, 0, 2, 63, 118, 17, 131], ["+", 8, 9, 0, 1, 0, 2, 63, 118, 119, 120], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["+", 8, 9, 0, 7, 8, 9, 0, 1, 0, 35]]
| 1
| 485
| 6
|
#include <stdio.h>
int main(void) {
int prime[1000001], i, j, n;
for (i = 0; i < 1000001; i++)
prime[i] = 0;
prime[0] = prime[1] = 1;
for (i = 2; i * i < 1000001; i++) {
if (prime[i] == 0) {
for (j = 2 * i; j < 1000001; j += i) {
prime[j] = 1;
}
}
}
while (scanf("%d", &n), n) {
int count = 0;
for (i = 2; i < n / 2; i++)
if (prime[i] == 0 && prime[n - i] == 0)
count++;
printf("%d\n", count);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int prime[1000001], i, j, n;
for (i = 0; i < 1000001; i++)
prime[i] = 0;
prime[0] = prime[1] = 1;
for (i = 2; i * i < 1000001; i++) {
if (prime[i] == 0) {
for (j = 2 * i; j < 1000001; j += i) {
prime[j] = 1;
}
}
}
while (scanf("%d", &n), n) {
int count = 0;
for (i = 2; i <= n / 2; i++)
if (prime[i] == 0 && prime[n - i] == 0)
count++;
printf("%d\n", count);
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
| 0
| 176
| 2
|
#include <iostream>
using namespace std;
bool isp[1 << 20];
main() {
for (int i = 2; i < 1 << 20; i++)
isp[i] = 1;
for (int i = 2; i < 1 << 20; i++) {
if (!isp[i])
continue;
for (int j = i + i; j < 1 << 20; j += i)
isp[j] = 0;
}
int n;
while (cin >> n, n) {
int cnt = 0;
for (int i = 2; i + 2 <= n; i++) {
cnt += isp[i] && isp[n - i];
}
cout << cnt << endl;
}
}
|
#include <iostream>
using namespace std;
bool isp[1 << 20];
main() {
for (int i = 2; i < 1 << 20; i++)
isp[i] = 1;
for (int i = 2; i < 1 << 20; i++) {
if (!isp[i])
continue;
for (int j = i + i; j < 1 << 20; j += i)
isp[j] = 0;
}
int n;
while (cin >> n, n) {
int cnt = 0;
for (int i = 2; i * 2 <= n; i++) {
cnt += isp[i] && isp[n - i];
}
cout << cnt << endl;
}
}
|
[["-", 8, 9, 0, 7, 15, 16, 31, 16, 17, 72], ["+", 8, 9, 0, 7, 15, 16, 31, 16, 17, 48]]
| 1
| 152
| 2
|
#include <iostream>
#include <vector>
using namespace std;
const int NMAX = 1000000;
int main() {
bool p[NMAX + 1];
vector<int> pv;
for (int i = 2; i < NMAX; i++) {
p[i] = true;
}
for (int i = 2; i * i <= NMAX; i++) {
if (!p[i])
continue;
for (int j = i + i; j <= NMAX; j += i) {
p[j] = false;
}
}
for (int i = 2; i <= NMAX; i++) {
if (p[i])
pv.push_back(i);
}
int n, ans;
while (1) {
cin >> n;
if (!n)
break;
ans = 0;
for (int i = 0; i < pv.size(); i++) {
if (pv[i] >= n - pv[i])
break;
if (p[n - pv[i]])
++ans;
}
cout << ans << endl;
}
return 0;
}
|
#include <iostream>
#include <vector>
using namespace std;
const int NMAX = 1000000;
int main() {
bool p[NMAX + 1];
vector<int> pv;
for (int i = 2; i <= NMAX; i++) {
p[i] = true;
}
for (int i = 2; i * i <= NMAX; i++) {
if (!p[i])
continue;
for (int j = i + i; j <= NMAX; j += i) {
p[j] = false;
}
}
for (int i = 2; i <= NMAX; i++) {
if (p[i])
pv.push_back(i);
}
int n, ans;
while (1) {
cin >> n;
if (!n)
break;
ans = 0;
for (int i = 0; i < pv.size(); i++) {
if (pv[i] > n - pv[i])
break;
if (p[n - pv[i]])
++ans;
}
cout << ans << endl;
}
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47]]
| 1
| 227
| 4
|
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
#define MAX 1000000
#define sqrtMAX sqrt(MAX)
int main(void) {
int n;
vector<int> b(MAX + 1);
int i, j;
int count;
// ツエツδ可トツスツテツネツスツづ個づ督づゥツつ「
b[0] = 1;
b[1] = 1;
for (i = 4; i <= MAX; i += 2)
b[i] = 1;
for (i = 3; i < sqrtMAX; i += 2)
for (j = i + i; j <= MAX; j += i)
b[j] = 1;
while (scanf("%d", &n) != EOF) {
if (n == 0)
break;
count = 0;
for (i = 0; i < n / 2; i++)
if (!b[i] && !b[n - i])
count++;
printf("%d\n", count);
}
return 0;
}
|
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
#define MAX 1000000
#define sqrtMAX sqrt(MAX)
int main(void) {
int n;
vector<int> b(MAX + 1);
int i, j;
int count;
// ツエツδ可トツスツテツネツスツづ個づ督づゥツつ「
b[0] = 1;
b[1] = 1;
for (i = 4; i <= MAX; i += 2)
b[i] = 1;
for (i = 3; i < sqrtMAX; i += 2)
for (j = i + i; j <= MAX; j += i)
b[j] = 1;
while (scanf("%d", &n) != EOF) {
if (n == 0)
break;
count = 0;
for (i = 0; i <= n / 2; i++)
if (!b[i] && !b[n - i])
count++;
printf("%d\n", count);
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
| 1
| 193
| 2
|
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
void makePrimeNumber(
int N,
vector<bool> &
prime) // 0ツ暗按湘」Nツ暗按可コツづ個青ョツ青板つゥツづァツ素ツ青板づーツ探ツつキ
{
prime.assign(N + 1, true);
prime[0] = prime[1] = false;
for (int i = 2; i * i <= N; i++) {
if (prime[i]) {
for (int j = i; i * j <= N; j++) {
prime[i * j] = false;
}
}
}
}
int main() {
vector<bool> prime;
makePrimeNumber(50000, prime);
vector<int> num;
for (int i = 0; i <= 50000; ++i) {
if (prime[i])
num.push_back(i);
}
for (;;) {
int n;
cin >> n;
if (n == 0)
return 0;
int ret = 0;
for (unsigned i = 0; num[i] <= n / 2; ++i) {
if (prime[n - num[i]])
++ret;
}
cout << ret << endl;
}
}
|
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
void makePrimeNumber(
int N,
vector<bool> &
prime) // 0ツ暗按湘」Nツ暗按可コツづ個青ョツ青板つゥツづァツ素ツ青板づーツ探ツつキ
{
prime.assign(N + 1, true);
prime[0] = prime[1] = false;
for (int i = 2; i * i <= N; i++) {
if (prime[i]) {
for (int j = i; i * j <= N; j++) {
prime[i * j] = false;
}
}
}
}
int main() {
vector<bool> prime;
makePrimeNumber(1000000, prime);
vector<int> num;
for (int i = 0; i <= 1000000; ++i) {
if (prime[i])
num.push_back(i);
}
for (;;) {
int n;
cin >> n;
if (n == 0)
return 0;
int ret = 0;
for (unsigned i = 0; num[i] <= n / 2; ++i) {
if (prime[n - num[i]])
++ret;
}
cout << ret << endl;
}
}
|
[["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13]]
| 1
| 254
| 4
|
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
bool isPrime[1000000];
int primes[1000000];
int primeSize = 0;
int main() {
fill(isPrime, isPrime + 1000000, true);
for (int i = 2; i < 1000; ++i) {
if (isPrime[i]) {
for (int j = 2 * i; j < 1000000; j += i)
isPrime[j] = false;
}
}
for (int i = 0; i < 1000000; ++i)
if (isPrime[i])
primes[primeSize++] = i;
int n;
while (scanf("%d", &n), n) {
int ans = 0;
for (int i = 0; primes[i] <= n / 2; ++i)
if (isPrime[n - primes[i]])
++ans;
printf("%d\n", ans);
}
return 0;
}
|
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
bool isPrime[1000000];
int primes[1000000];
int primeSize = 0;
int main() {
fill(isPrime, isPrime + 1000000, true);
for (int i = 2; i < 1000; ++i) {
if (isPrime[i]) {
for (int j = 2 * i; j < 1000000; j += i)
isPrime[j] = false;
}
}
for (int i = 3; i < 1000000; ++i)
if (isPrime[i])
primes[primeSize++] = i;
int n;
while (scanf("%d", &n), n) {
int ans = 0;
for (int i = 0; primes[i] <= n / 2; ++i)
if (isPrime[n - primes[i]])
++ans;
printf("%d\n", ans);
}
return 0;
}
|
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13]]
| 1
| 219
| 2
|
#define _USE_MATH_DEFINES
#define INF 10000000
#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, string> P;
static const double eps = 1e-8;
int main() {
bool table[1000001];
fill((bool *)table, (bool *)table + 1000001, true);
table[0] = 0;
table[1] = 0;
for (int i = 2; i * i <= 1000000; i++) {
if (table[i]) {
for (int j = i + i; j <= 1000000; j += i) {
table[j] = false;
}
}
}
int n;
while (~scanf("%d", &n)) {
if (n == 0)
break;
int res = 0;
for (int i = n, j = 0; j < n / 2; j++, i--) {
if (table[i] && table[j])
res++;
}
printf("%d\n", res);
}
}
|
#define _USE_MATH_DEFINES
#define INF 10000000
#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, string> P;
static const double eps = 1e-8;
int main() {
bool table[1000001];
fill((bool *)table, (bool *)table + 1000001, true);
table[0] = false;
table[1] = false;
for (int i = 2; i * i <= 1000000; i++) {
if (table[i]) {
for (int j = i + i; j <= 1000000; j += i) {
table[j] = false;
}
}
}
int n;
while (~scanf("%d", &n)) {
if (n == 0)
break;
int res = 0;
for (int i = n, j = 0; j <= n / 2; j++, i--) {
if (table[i] && table[j])
res++;
}
printf("%d\n", res);
}
}
|
[["-", 0, 14, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 12, 147], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
| 1
| 235
| 6
|
#include <iostream>
using namespace std;
#define MAX 50100
int prime[MAX - 4];
void is_prime() {
for (int i = 0; i < MAX; i++)
prime[i] = 0;
prime[0] = prime[1] = 1;
for (int i = 4; i < MAX; i += 2)
prime[i] = 1;
for (int i = 3; i * i < MAX; i++) {
if (prime[i])
continue;
for (int j = i * 2; j < MAX; j += i)
prime[j] = 1;
}
}
int main() {
int n;
is_prime();
while (true) {
cin >> n;
if (!n)
break;
int cnt = 0;
for (int i = 2; i <= n / 2; i++) {
if (!prime[i] && !prime[n - i])
cnt++;
}
cout << cnt << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
#define MAX 1000100
int prime[MAX - 4];
void is_prime() {
for (int i = 0; i < MAX; i++)
prime[i] = 0;
prime[0] = prime[1] = 1;
for (int i = 4; i < MAX; i += 2)
prime[i] = 1;
for (int i = 3; i * i < MAX; i++) {
if (prime[i])
continue;
for (int j = i * 2; j < MAX; j += i)
prime[j] = 1;
}
}
int main() {
int n;
is_prime();
while (true) {
cin >> n;
if (!n)
break;
int cnt = 0;
for (int i = 2; i <= n / 2; i++) {
if (!prime[i] && !prime[n - i])
cnt++;
}
cout << cnt << endl;
}
return 0;
}
|
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59]]
| 1
| 210
| 2
|
require'prime'
a=[]
Prime.each(1e6){|i|a[i]=1}
p (2..(n=$_.to_i)/2+1).count{|i|a[i]&&a[n-i]}while gets>?1
|
require'prime'
a=[]
Prime.each(1e6){|i|a[i]=1}
p (2..(n=$_.to_i)/2).count{|i|a[i]&&a[n-i]}while gets>?1
|
[["-", 0, 652, 486, 739, 0, 475, 444, 738, 17, 72], ["-", 0, 652, 486, 739, 0, 475, 444, 738, 12, 612]]
| 4
| 63
| 2
|
#include <stdio.h>
int main(void) {
int q1, b, c1, c2, q2;
int aizu_c, normal_c = 0, leaveMoney;
while (1) {
scanf("%d", &q1);
if (q1 == 0)
break;
scanf("%d %d %d %d", &b, &c1, &c2, &q2);
aizu_c = 0;
normal_c = 0;
leaveMoney = b;
while (b - c1 >= 0 && aizu_c < q2) {
leaveMoney -= c1;
aizu_c++;
}
while (leaveMoney - c2 >= 0) {
leaveMoney -= c2;
normal_c++;
}
while (1) {
if (aizu_c == 0) {
printf("NA\n");
break;
} else if (aizu_c + normal_c >= q1) {
printf("%d %d\n", aizu_c, normal_c);
break;
} else if (aizu_c != 0) {
aizu_c--;
leaveMoney += c1;
normal_c += leaveMoney / c2;
leaveMoney -= c2 * (leaveMoney / c2);
}
}
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int q1, b, c1, c2, q2;
int aizu_c, normal_c, leaveMoney;
while (1) {
scanf("%d", &q1);
if (q1 == 0)
break;
scanf("%d %d %d %d", &b, &c1, &c2, &q2);
aizu_c = 0;
normal_c = 0;
leaveMoney = b;
while (leaveMoney - c1 >= 0 && aizu_c < q2) {
leaveMoney -= c1;
aizu_c++;
}
while (leaveMoney - c2 >= 0) {
leaveMoney -= c2;
normal_c++;
}
while (1) {
if (aizu_c == 0) {
printf("NA\n");
break;
} else if (aizu_c + normal_c >= q1) {
printf("%d %d\n", aizu_c, normal_c);
break;
} else if (aizu_c != 0) {
aizu_c--;
leaveMoney += c1;
normal_c += leaveMoney / c2;
leaveMoney -= c2 * (leaveMoney / c2);
}
}
}
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 0, 32], ["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["-", 15, 23, 0, 16, 31, 16, 31, 16, 31, 22], ["+", 15, 23, 0, 16, 31, 16, 31, 16, 31, 22]]
| 0
| 206
| 4
|
#include <stdio.h>
void getWeightOfAizuAndNormalChicken(int minWeight, int money, int aizuPrime,
int normalPrime, int maxAizuWeight,
int *weightOfAizu, int *weightOfNormal);
int main(void) {
char string[64];
int min; //最低限これ以上は買わなければならない
int money; //予算
int AizuChickenPrice; //会津地鶏の価格
int NormalChickenPrice; //普通の鶏肉の価格
int max; //買える会津地鶏の制限
int weightOfAizu;
int weightOfNormal;
while (1) {
fgets(string, 64, stdin);
if (string[1] == '\n')
break;
sscanf(string, "%d%d%d%d%d", &min, &money, &AizuChickenPrice,
&NormalChickenPrice, &max);
/*sscanf( string, "%d", &money );
sscanf( string, "%d", &AizuChickenPrice );
sscanf( string, "%d", &NormalChickenPrice );
sscanf( string, "%d", &max );*/
getWeightOfAizuAndNormalChicken(min, money, AizuChickenPrice,
NormalChickenPrice, max, &weightOfAizu,
&weightOfNormal);
if (weightOfAizu == -1 && weightOfNormal == -1) {
printf("NA\n");
} else {
printf("%d %d\n", weightOfAizu, weightOfNormal);
}
}
return (0);
}
void getWeightOfAizuAndNormalChicken(int minWeight, int money, int aizuPrice,
int normalPrice, int maxAizuWeight,
int *weightOfAizu, int *weightOfNormal) {
int lackWeight; //足りない重さ
int addWeight; //重さの合計
int overWeight; //多かった重さ
int remainMoney;
remainMoney = money;
*weightOfAizu = remainMoney / aizuPrice; //とりあえず買えるだけ買ってみる
remainMoney = money % aizuPrice;
*weightOfNormal = remainMoney / normalPrice; //とりあえず買えるだけ買ってみる
remainMoney = money % normalPrice;
if ((*weightOfAizu) >
maxAizuWeight) //会津地鶏の重さが買える限界より多ければ実行
{
overWeight = (*weightOfAizu) - maxAizuWeight;
*weightOfAizu = maxAizuWeight;
remainMoney += (overWeight * aizuPrice);
*weightOfNormal += remainMoney / normalPrice;
remainMoney = remainMoney % normalPrice;
}
addWeight = (*weightOfAizu) + (*weightOfNormal);
while (addWeight < minWeight) //重さの下限より小さければ実行
{
(*weightOfAizu)--;
if (*weightOfAizu <= 0) {
break;
}
remainMoney += aizuPrice;
*weightOfNormal += remainMoney / normalPrice;
remainMoney = remainMoney % normalPrice;
addWeight = (*weightOfAizu) + (*weightOfNormal);
}
if (*weightOfAizu <= 0) {
*weightOfAizu = -1;
*weightOfNormal = -1;
return;
}
}
|
#include <stdio.h>
void getWeightOfAizuAndNormalChicken(int minWeight, int money, int aizuPrime,
int normalPrime, int maxAizuWeight,
int *weightOfAizu, int *weightOfNormal);
int main(void) {
char string[64];
int min; //最低限これ以上は買わなければならない
int money; //予算
int AizuChickenPrice; //会津地鶏の価格
int NormalChickenPrice; //普通の鶏肉の価格
int max; //買える会津地鶏の制限
int weightOfAizu;
int weightOfNormal;
while (1) {
fgets(string, 64, stdin);
if (string[1] == '\n')
break;
sscanf(string, "%d%d%d%d%d", &min, &money, &AizuChickenPrice,
&NormalChickenPrice, &max);
getWeightOfAizuAndNormalChicken(min, money, AizuChickenPrice,
NormalChickenPrice, max, &weightOfAizu,
&weightOfNormal);
if (weightOfAizu == -1 && weightOfNormal == -1) {
printf("NA\n");
} else {
printf("%d %d\n", weightOfAizu, weightOfNormal);
}
}
return (0);
}
void getWeightOfAizuAndNormalChicken(int minWeight, int money, int aizuPrice,
int normalPrice, int maxAizuWeight,
int *weightOfAizu, int *weightOfNormal) {
int lackWeight; //足りない重さ
int addWeight; //重さの合計
int overWeight; //多かった重さ
int remainMoney; //現在のお金
remainMoney = money;
*weightOfAizu = remainMoney / aizuPrice; //とりあえず買えるだけ買ってみる
remainMoney = money % aizuPrice;
*weightOfNormal = remainMoney / normalPrice; //とりあえず買えるだけ買ってみる
remainMoney = remainMoney % normalPrice;
if ((*weightOfAizu) >
maxAizuWeight) //会津地鶏の重さが買える限界より多ければ実行
{
overWeight = (*weightOfAizu) - maxAizuWeight;
*weightOfAizu = maxAizuWeight;
remainMoney += (overWeight * aizuPrice);
*weightOfNormal += remainMoney / normalPrice;
remainMoney = remainMoney % normalPrice;
}
addWeight = (*weightOfAizu) + (*weightOfNormal);
while (addWeight < minWeight) //重さの下限より小さければ実行
{
(*weightOfAizu)--;
if (*weightOfAizu <= 0) {
break;
}
remainMoney += aizuPrice;
*weightOfNormal += remainMoney / normalPrice;
remainMoney = remainMoney % normalPrice;
addWeight = (*weightOfAizu) + (*weightOfNormal);
}
if (*weightOfAizu <= 0) {
*weightOfAizu = -1;
*weightOfNormal = -1;
return;
}
}
|
[["-", 8, 9, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 31, 22]]
| 0
| 390
| 2
|
#include <iostream>
using namespace std;
main() {
int max, min, mid;
int q1, q2, b, c1, c2;
int aizumoney, sosomoney, sosonum;
while (1) {
cin >> q1;
if (q1 == 0)
break;
cin >> b >> c1 >> c2 >> q2;
//会津地鶏二分探索
min = 0;
max = q2;
while (min <= max) {
mid = (max + min) / 2;
aizumoney = mid * c1;
sosomoney = b - aizumoney;
sosonum = sosomoney / c2;
// cout<<min<<" "<<max<<" "<<mid<<" "<<aizumoney<<" "<<sosomoney<<"
// "<<sosonum<<endl;
if (mid + sosonum >= q1 && mid > 0 && sosonum >= 0 && sosomoney >= 0) {
// cout<<"OK"<<endl;
min = mid + 1;
} else {
// cout<<"NG"<<endl;
max = mid - 1;
}
}
mid = (max + min) / 2;
aizumoney = mid * c1;
sosomoney = b - aizumoney;
sosonum = sosomoney / c2;
// cout<<min<<" "<<max<<" "<<mid<<" "<<aizumoney<<" "<<sosomoney<<"
// "<<sosonum<<endl;
if (mid + sosonum >= q1 && mid > 0 && sosonum >= 0 && sosomoney >= 0) {
cout << mid << " " << sosonum << endl;
} else {
cout << "NA" << endl;
}
}
}
|
#include <iostream>
using namespace std;
main() {
int max, min, mid;
int q1, q2, b, c1, c2;
int aizumoney, sosomoney, sosonum;
while (1) {
cin >> q1;
if (q1 == 0)
break;
cin >> b >> c1 >> c2 >> q2;
//会津地鶏二分探索
min = 0;
max = q2;
while (min <= max) {
mid = (max + min) / 2;
aizumoney = mid * c1;
sosomoney = b - aizumoney;
sosonum = sosomoney / c2;
// cout<<min<<" "<<max<<" "<<mid<<" "<<aizumoney<<" "<<sosomoney<<"
// "<<sosonum<<endl;
if (mid + sosonum >= q1 && mid > 0 && sosonum >= 0 && sosomoney >= 0 ||
mid <= 0) {
// cout<<"OK"<<endl;
min = mid + 1;
} else {
// cout<<"NG"<<endl;
max = mid - 1;
}
}
mid = (max + min) / 2;
aizumoney = mid * c1;
sosomoney = b - aizumoney;
sosonum = sosomoney / c2;
// cout<<min<<" "<<max<<" "<<mid<<" "<<aizumoney<<" "<<sosomoney<<"
// "<<sosonum<<endl;
if (mid + sosonum >= q1 && mid > 0 && sosonum >= 0 && sosomoney >= 0) {
cout << mid << " " << sosonum << endl;
} else {
cout << "NA" << endl;
}
}
}
|
[["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 106], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 19], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
| 1
| 225
| 4
|
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)
#define PB push_back
#define INF INT_MAX / 3
#define ALL(a) (a).begin(), (a).end()
#define CLR(a) memset(a, 0, sizeof(a))
typedef long long int ll;
using namespace std;
int main() {
while (true) {
int a, b, c, d, e;
cin >> a;
if (a == 0)
break;
cin >> b >> c >> d >> e;
int m1 = min(e, b / c);
int m = b / d;
REP(i, m1 + 1) {
int tm, tm1;
tm = m;
tm1 = m1 - i;
while ((tm)*d + (tm1)*c > b) {
tm--;
if (tm == 0) {
break;
}
}
if (tm + tm1 >= a) {
m = tm;
m1 = tm1;
break;
} else if (i == m1) {
m = 0;
m1 = 0;
}
}
if (m == 0 && m1 == 0)
cout << "NA" << endl;
else
cout << m1 << " " << m << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)
#define PB push_back
#define INF INT_MAX / 3
#define ALL(a) (a).begin(), (a).end()
#define CLR(a) memset(a, 0, sizeof(a))
typedef long long int ll;
using namespace std;
int main() {
while (true) {
int a, b, c, d, e;
cin >> a;
if (a == 0)
break;
cin >> b >> c >> d >> e;
int m1 = min(e, b / c);
int m = b / d;
REP(i, m1 + 1) {
int tm, tm1;
tm = m;
tm1 = m1 - i;
while ((tm)*d + (tm1)*c > b) {
tm--;
if (tm == 0) {
break;
}
}
if (tm + tm1 >= a) {
m = tm;
m1 = tm1;
break;
} else if (i == m1) {
m = 0;
m1 = 0;
}
}
if (m1 == 0)
cout << "NA" << endl;
else
cout << m1 << " " << m << endl;
}
return 0;
}
|
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 339, 51, 16, 31, 16, 17, 60], ["-", 0, 57, 15, 339, 51, 16, 31, 16, 12, 13], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 98]]
| 1
| 258
| 4
|
#include <bits/stdc++.h>
using namespace std;
int q, b, c1, c2, limit;
int check(int M) {
int B = b, cnt = M;
B -= c1 * M;
if (B < 0)
return 0;
cnt += (B / c2);
return (cnt >= q);
}
int main() {
while (cin >> q, q) {
;
cin >> b >> c1 >> c2 >> limit;
int L = 0, M, R = limit + 1;
while (L < R) {
M = (R + L) / 2;
if (!check(M))
R = M;
else
L = M + 1;
}
if (L == 0)
cout << "NA" << endl;
else
cout << (L - 1) << " " << ((b - (L - 1) * c1) / c2) << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int q, b, c1, c2, limit;
int check(int M) {
int B = b, cnt = M;
B -= c1 * M;
if (B < 0)
return 0;
cnt += (B / c2);
return (cnt >= q);
}
int main() {
while (cin >> q, q) {
;
cin >> b >> c1 >> c2 >> limit;
int L = 0, M, R = limit + 1;
while (L < R) {
M = (R + L) / 2;
if (!check(M))
R = M;
else
L = M + 1;
}
if (L <= 1)
cout << "NA" << endl;
else
cout << (L - 1) << " " << ((b - (L - 1) * c1) / c2) << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
| 1
| 189
| 4
|
#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() {
long les, m, a, c, w;
while (cin >> les, les) {
cin >> m >> a >> c >> w;
int ch = 0;
long cc = 0;
int i = 0;
long k = m / a;
if (m / c < les || k == 0) {
cout << "NA 2" << endl;
continue;
}
if (k > w)
k = w;
for (i = k; i > 0; i--) {
cc = (m - i * a) / c;
if (cc + i >= les) {
ch = 1;
break;
}
}
if (ch)
cout << i << " " << cc << endl;
else
cout << "NA" << 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() {
long les, m, a, c, w;
while (cin >> les, les) {
cin >> m >> a >> c >> w;
int ch = 0;
long cc = 0;
int i = 0;
long k = m / a;
if (m / c < les || k == 0) {
cout << "NA" << endl;
continue;
}
if (k > w)
k = w;
for (i = k; i > 0; i--) {
cc = (m - i * a) / c;
if (cc + i >= les) {
ch = 1;
break;
}
}
if (ch)
cout << i << " " << cc << endl;
else
cout << "NA" << endl;
}
return 0;
}
|
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 199
| 2
|
#include <stdio.h>
int main() {
int a, b, c, d, e;
while (scanf("%d", &a), a) {
scanf("%d%d%d%d", &b, &c, &d, &e);
bool ok = false;
int bestA = 0;
int bestB = 0;
for (int i = 0; i <= e; i++) {
int f = b - c * i;
int g = f / d;
if (f >= 0 && i + g >= a) {
bestA = i;
bestB = g;
ok = true;
}
}
if (!ok)
printf("NA\n");
else
printf("%d %d\n", bestA, bestB);
}
}
|
#include <stdio.h>
int main() {
int a, b, c, d, e;
while (scanf("%d", &a), a) {
scanf("%d%d%d%d", &b, &c, &d, &e);
bool ok = false;
int bestA = 0;
int bestB = 0;
for (int i = 1; i <= e; i++) {
int f = b - c * i;
int g = f / d;
if (f >= 0 && i + g >= a) {
bestA = i;
bestB = g;
ok = true;
}
}
if (!ok)
printf("NA\n");
else
printf("%d %d\n", bestA, bestB);
}
}
|
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13]]
| 1
| 153
| 2
|
# Aizu Problem 0186: Aizu Chicken
#
import sys, math, os, bisect
# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
sys.stdin = open("sample-input.txt", "rt")
def aizu_chicken(q1, b, c1, c2, q2):
for i in range(q2, 0, -1):
cj = i * c1
normal = int((b - cj) / c2)
if i + normal < q1:
continue
elif normal >= 0:
print(i, normal)
break
else:
print("NA")
while True:
inp = [int(_) for _ in input().split()]
if len(inp) == 1:
break
q1, b, c1, c2, q2 = inp[:]
aizu_chicken(q1, b, c1, c2, q2)
|
# Aizu Problem 0186: Aizu Chicken
#
import sys, math, os, bisect
# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
sys.stdin = open("sample-input.txt", "rt")
def aizu_chicken(q1, b, c1, c2, q2):
for i in range(q2, 0, -1):
cj = i * c1
normal = int((b - cj) // c2)
if i + normal < q1:
continue
elif normal >= 0:
print(i, normal)
break
else:
print("NA")
while True:
inp = [int(_) for _ in input().split()]
if len(inp) == 1:
break
q1, b, c1, c2, q2 = inp[:]
aizu_chicken(q1, b, c1, c2, q2)
|
[["-", 0, 662, 12, 652, 3, 4, 0, 657, 17, 85], ["+", 0, 662, 12, 652, 3, 4, 0, 657, 17, 676]]
| 5
| 172
| 2
|
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int i, j, k, xa, ya, xb, yb;
double sp[3][2], vec[3][2], pot[3][2], area;
int crosspoint(int i, int j) {
double px = sp[i][0], py = sp[i][1];
double ax = vec[i][0], ay = vec[i][1];
double qx = sp[j][0], qy = sp[j][1];
double bx = vec[j][0], by = vec[j][1];
if ((ax * bx + ay * by != 0) && (ax * by == ay * bx))
return 0;
double a = ax, b = -bx, c = qx - px;
double d = ay, e = -by, f = qy - py;
double t, x, y;
if (a != 0) {
t = d / a;
e -= b * t;
f -= c * t;
y = f / e;
x = (c - b * y) / a;
} else {
y = c / b;
x = (f - e * y) / d;
}
if (x < 0 || x > 1 || y < 0 || y > 1)
return 0;
pot[i][0] = px + ax * x;
pot[i][1] = py + ay * x;
return 1;
}
int main() {
while (1) {
for (i = 0; i < 3; i++) {
if (scanf("%d %d %d %d", &xa, &ya, &xb, &yb) == EOF)
goto exit;
vec[i][0] = xb - xa;
vec[i][1] = yb - ya;
sp[i][0] = xa;
sp[i][1] = ya;
}
for (i = 0; i < 3; i++) {
if (crosspoint(i, (i + 1) % 3) == 0)
goto bad;
}
double vx = pot[1][0] - pot[0][0];
double vy = pot[1][1] - pot[1][0];
double wx = pot[2][0] - pot[0][0];
double wy = pot[2][1] - pot[1][0];
area = fabs((vx * wy - vy * wx) / 2);
if (area >= 1900000) {
printf("dai-kichi\n");
continue;
}
if (area >= 1000000) {
printf("chu-kichi\n");
continue;
}
if (area >= 100000) {
printf("kichi\n");
continue;
}
if (area > 0) {
printf("sho-kichi\n");
continue;
}
bad:
printf("kyo\n");
}
exit:
return 0;
}
|
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int i, j, k, xa, ya, xb, yb;
double sp[3][2], vec[3][2], pot[3][2], area;
int crosspoint(int i, int j) {
double px = sp[i][0], py = sp[i][1];
double ax = vec[i][0], ay = vec[i][1];
double qx = sp[j][0], qy = sp[j][1];
double bx = vec[j][0], by = vec[j][1];
if ((ax * bx + ay * by != 0) && (ax * by == ay * bx))
return 0;
double a = ax, b = -bx, c = qx - px;
double d = ay, e = -by, f = qy - py;
double t, x, y;
if (a != 0) {
t = d / a;
e -= b * t;
f -= c * t;
y = f / e;
x = (c - b * y) / a;
} else {
y = c / b;
x = (f - e * y) / d;
}
if (x < 0 || x > 1 || y < 0 || y > 1)
return 0;
pot[i][0] = px + ax * x;
pot[i][1] = py + ay * x;
return 1;
}
int main() {
while (1) {
for (i = 0; i < 3; i++) {
if (scanf("%d %d %d %d", &xa, &ya, &xb, &yb) == EOF)
goto exit;
vec[i][0] = xb - xa;
vec[i][1] = yb - ya;
sp[i][0] = xa;
sp[i][1] = ya;
}
for (i = 0; i < 3; i++) {
if (crosspoint(i, (i + 1) % 3) == 0)
goto bad;
}
double vx = pot[1][0] - pot[0][0];
double vy = pot[1][1] - pot[0][1];
double wx = pot[2][0] - pot[0][0];
double wy = pot[2][1] - pot[0][1];
area = fabs((vx * wy - vy * wx) / 2);
if (area >= 1900000) {
printf("dai-kichi\n");
continue;
}
if (area >= 1000000) {
printf("chu-kichi\n");
continue;
}
if (area >= 100000) {
printf("kichi\n");
continue;
}
if (area > 0) {
printf("syo-kichi\n");
continue;
}
bad:
printf("kyo\n");
}
exit:
return 0;
}
|
[["-", 49, 50, 51, 16, 12, 69, 28, 69, 71, 13], ["+", 49, 50, 51, 16, 12, 69, 28, 69, 71, 13], ["-", 0, 43, 49, 50, 51, 16, 12, 69, 71, 13], ["+", 0, 43, 49, 50, 51, 16, 12, 69, 71, 13], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 0
| 638
| 10
|
/*include*/
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define rp(a) while (a--)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double EPS = 1e-10;
using namespace std;
typedef complex<double> P;
typedef vector<P> G;
struct L : public vector<P> {
L(const P &a, const P &b) {
push_back(a);
push_back(b);
}
};
struct C {
P c;
double r;
C(const P &c, double r) : c(c), r(r) {}
};
#define curr(P, i) P[i]
#define next(P, i) P[(i + 1) % P.size()]
#define diff(P, i) (next(P, i) - curr(P, i))
namespace std {
bool operator<(const P &a, const P &b) {
return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
// return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b);
}
bool operator==(const P &a, const P &b) {
return a.real() == b.real() && a.imag() == b.imag();
}
} // namespace std
P pin() {
double x, y;
char d;
cin >> x >> y;
P p(x, y);
return p;
}
void PIN(P *a, int n) { rep(i, n) a[i] = pin(); }
double dot(P a, P b) { return real(conj(a) * b); }
double cross(P a, P b) { return imag(conj(a) * b); }
int ccw(P a, P b, P c) {
b -= a;
c -= a;
if (cross(b, c) > 0)
return +1; // counter clockwise
if (cross(b, c) < 0)
return -1; // clockwise
if (dot(b, c) < 0)
return +2; // c--a--b on line
if (norm(b) < norm(c))
return -2; // a--b--c on line
return 0;
}
P projection(L a, P p) {
double t = dot(p - a[0], a[0] - a[1]) / norm(a[0] - a[1]);
return a[0] + t * (a[0] - a[1]);
}
P reflection(L a, P p) { return p + 2.0 * (projection(a, p) - p); }
bool intersectLL(const L &l, const L &m) {
return abs(cross(l[1] - l[0], m[1] - m[0])) > EPS || // non-parallel
abs(cross(l[1] - l[0], m[0] - l[0])) < EPS; // same line
}
bool intersectLS(const L &l, const L &s) {
return cross(l[1] - l[0], s[0] - l[0]) * // s[0] is left of l
cross(l[1] - l[0], s[1] - l[0]) <
EPS; // s[1] is right of l
}
bool intersectLP(const L &l, const P &p) {
return abs(cross(l[1] - p, l[0] - p)) < EPS;
}
bool intersectSS(const L &s, const L &t) {
return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 &&
ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
}
bool intersectSP(const L &s, const P &p) {
return abs(s[0] - p) + abs(s[1] - p) - abs(s[1] - s[0]) <
EPS; // triangle inequality
}
P intersect_ls(L a, L b) {
double t1 = abs(cross(a[1] - a[0], b[0] - a[0]));
double t2 = abs(cross(a[1] - a[0], b[1] - a[0]));
return b[0] + (b[1] - b[0]) * t1 / (t1 + t2);
}
double distanceLP(const L &l, const P &p) {
if (dot(l[1] - l[0], p - l[0]) < EPS)
return abs(p - l[0]);
if (dot(l[0] - l[1], p - l[1]) < EPS)
return abs(p - l[1]);
return abs(p - projection(l, p));
}
double distanceLL(const L &l, const L &m) {
return intersectLL(l, m) ? 0 : distanceLP(l, m[0]);
}
double distanceLS(const L &l, const L &s) {
if (intersectLS(l, s))
return 0;
return min(distanceLP(l, s[0]), distanceLP(l, s[1]));
}
double distanceSP(const L &s, const P &p) {
const P r = projection(s, p);
if (intersectSP(s, r))
return abs(r - p);
return min(abs(s[0] - p), abs(s[1] - p));
}
double distanceSS(const L &s, const L &t) {
if (intersectSS(s, t))
return 0;
return min(min(distanceSP(s, t[0]), distanceSP(s, t[1])),
min(distanceSP(t, s[0]), distanceSP(t, s[1])));
}
bool intersectCL(C c, const L &l) {
return (distanceLP(l, c.c) < c.r + EPS &&
(c.r < abs(c.c - l[0]) + EPS || c.r < abs(c.c - l[1]) + EPS));
}
L crosspointCL(C c, L l) {
P pr = projection(l, c.c);
P e = (l[1] - l[0]) / abs(l[1] - l[0]);
double t = sqrt(c.r * c.r - norm(pr - c.c));
P a = pr + t * e;
P b = pr - t * e;
if (b < a)
swap(a, b);
return L(a, b);
}
L crosspointCC(C a, C b) {
P tmp = b.c - a.c;
double d = abs(tmp);
double q = acos((a.r * a.r + d * d - b.r * b.r) / (2 * a.r * d));
double t = arg(tmp); // atan(tmp.imag()/tmp.real());
P p1 = a.c + polar(a.r, t + q);
P p2 = a.c + polar(a.r, t - q);
if (p2 < p1)
swap(p1, p2);
return L(p1, p2);
}
P crosspointLL(const L &l, const L &m) {
double A = cross(l[1] - l[0], m[1] - m[0]);
double B = cross(l[1] - l[0], l[1] - m[0]);
if (abs(A) < EPS && abs(B) < EPS)
return m[0]; // same line
return m[0] + B / A * (m[1] - m[0]);
}
double area(const G &g) {
double S = 0;
for (int i = 0; i < g.size(); i++) {
S += (cross(g[i], g[(i + 1) % g.size()]));
}
return abs(S / 2.0);
}
bool isconvex(const G &g) {
int n = g.size();
rep(i, n) if (ccw(g[(i + n - 1) % n], g[i % n], g[(i + 1) % n]) ==
-1) return false;
return true;
}
int inconvex(const G &g, const P &p) {
bool in = false;
int n = g.size();
rep(i, n) {
P a = g[i % n] - p;
P b = g[(i + 1) % n] - p;
if (imag(a) > imag(b))
swap(a, b);
if (imag(a) <= 0 && 0 < imag(b))
if (cross(a, b) < 0)
in = !in;
if (cross(a, b) == 0 && dot(a, b) <= 0)
return 1; // ON
}
return in ? 2 : 0; // IN : OUT;
}
G convex_hull(G &ps) {
int n = ps.size(), k = 0;
sort(ps.begin(), ps.end());
G ch(2 * n);
for (int i = 0; i < n; ch[k++] = ps[i++]) // lower-hull
while (k >= 2 && ccw(ch[k - 2], ch[k - 1], ps[i]) == -1)
--k; //<=0 -> ==-1
for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = ps[i--]) // upper-hull
while (k >= t && ccw(ch[k - 2], ch[k - 1], ps[i]) == -1)
--k; //
ch.resize(k - 1);
return ch;
}
double convex_diameter(const G &pt) {
const int n = pt.size();
int is = 0, js = 0;
for (int i = 1; i < n; ++i) {
if (imag(pt[i]) > imag(pt[is]))
is = i;
if (imag(pt[i]) < imag(pt[js]))
js = i;
}
double maxd = norm(pt[is] - pt[js]);
int i, maxi, j, maxj;
i = maxi = is;
j = maxj = js;
do {
if (cross(diff(pt, i), diff(pt, j)) >= 0)
j = (j + 1) % n;
else
i = (i + 1) % n;
if (norm(pt[i] - pt[j]) > maxd) {
maxd = norm(pt[i] - pt[j]);
maxi = i;
maxj = j;
}
} while (i != is || j != js);
return sqrt(maxd); /* farthest pair is (maxi, maxj). */
} // convex_diameter(g)
G convex_cut(const G &g, const L &l) {
G Q;
for (int i = 0; i < g.size(); ++i) {
P a = curr(g, i), b = next(g, i);
if (ccw(l[0], l[1], a) != -1)
Q.push_back(a);
if (ccw(l[0], l[1], a) * ccw(l[0], l[1], b) < 0)
Q.push_back(crosspointLL(L(a, b), l));
}
return Q;
}
P turn(P p, double t) { return p * exp(P(.0, t * PI / 180.0)); }
void printL(const L &out) {
printf("%.9f %.9f %.9f %.9f\n", out[0].real(), out[0].imag(), out[1].real(),
out[1].imag());
}
C CIN() {
P p = pin();
double r;
cin >> r;
return C(p, r);
}
bool para(L a, L b) { return (abs(cross(a[1] - a[0], b[1] - b[0])) < EPS); }
int main() {
double q1, q2, q3, q4;
while (cin >> q1 >> q2 >> q3 >> q4, q1 + q2 + q3 + q4) {
L a(P(q1, q2), P(q3, q4));
cin >> q1 >> q2 >> q3 >> q4;
L b(P(q1, q2), P(q3, q4));
cin >> q1 >> q2 >> q3 >> q4;
L c(P(q1, q2), P(q3, q4));
if (para(a, b) || para(b, c) || para(c, a)) {
cout << "kyo" << endl;
continue;
}
if ((!intersectSS(a, b)) || (!intersectSS(c, b)) || (!intersectSS(a, c))) {
cout << "kyo" << endl;
continue;
}
P p1 = crosspointLL(a, b);
P p2 = crosspointLL(c, b);
P p3 = crosspointLL(a, c);
if (p1 == p2 || p2 == p3 || p3 == p1) {
cout << "kyo" << endl;
continue;
}
p2 -= p1;
p3 -= p1;
double S = abs(p2.real() * p3.imag() - p2.imag() * p3.real()) / 2.0;
if (S < 100000)
cout << "syo-kichi" << endl;
else if (S < 1000000)
cout << "kichi" << endl;
else if (S < 1900000)
cout << "chu-kichi" << endl;
else
cout << "dai-kichi" << endl;
}
}
|
/*include*/
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define rp(a) while (a--)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double EPS = 1e-10;
using namespace std;
typedef complex<double> P;
typedef vector<P> G;
struct L : public vector<P> {
L(const P &a, const P &b) {
push_back(a);
push_back(b);
}
};
struct C {
P c;
double r;
C(const P &c, double r) : c(c), r(r) {}
};
#define curr(P, i) P[i]
#define next(P, i) P[(i + 1) % P.size()]
#define diff(P, i) (next(P, i) - curr(P, i))
namespace std {
bool operator<(const P &a, const P &b) {
return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
// return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b);
}
bool operator==(const P &a, const P &b) {
return a.real() == b.real() && a.imag() == b.imag();
}
} // namespace std
P pin() {
double x, y;
char d;
cin >> x >> y;
P p(x, y);
return p;
}
void PIN(P *a, int n) { rep(i, n) a[i] = pin(); }
double dot(P a, P b) { return real(conj(a) * b); }
double cross(P a, P b) { return imag(conj(a) * b); }
int ccw(P a, P b, P c) {
b -= a;
c -= a;
if (cross(b, c) > 0)
return +1; // counter clockwise
if (cross(b, c) < 0)
return -1; // clockwise
if (dot(b, c) < 0)
return +2; // c--a--b on line
if (norm(b) < norm(c))
return -2; // a--b--c on line
return 0;
}
P projection(L a, P p) {
double t = dot(p - a[0], a[0] - a[1]) / norm(a[0] - a[1]);
return a[0] + t * (a[0] - a[1]);
}
P reflection(L a, P p) { return p + 2.0 * (projection(a, p) - p); }
bool intersectLL(const L &l, const L &m) {
return abs(cross(l[1] - l[0], m[1] - m[0])) > EPS || // non-parallel
abs(cross(l[1] - l[0], m[0] - l[0])) < EPS; // same line
}
bool intersectLS(const L &l, const L &s) {
return cross(l[1] - l[0], s[0] - l[0]) * // s[0] is left of l
cross(l[1] - l[0], s[1] - l[0]) <
EPS; // s[1] is right of l
}
bool intersectLP(const L &l, const P &p) {
return abs(cross(l[1] - p, l[0] - p)) < EPS;
}
bool intersectSS(const L &s, const L &t) {
return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 &&
ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
}
bool intersectSP(const L &s, const P &p) {
return abs(s[0] - p) + abs(s[1] - p) - abs(s[1] - s[0]) <
EPS; // triangle inequality
}
P intersect_ls(L a, L b) {
double t1 = abs(cross(a[1] - a[0], b[0] - a[0]));
double t2 = abs(cross(a[1] - a[0], b[1] - a[0]));
return b[0] + (b[1] - b[0]) * t1 / (t1 + t2);
}
double distanceLP(const L &l, const P &p) {
if (dot(l[1] - l[0], p - l[0]) < EPS)
return abs(p - l[0]);
if (dot(l[0] - l[1], p - l[1]) < EPS)
return abs(p - l[1]);
return abs(p - projection(l, p));
}
double distanceLL(const L &l, const L &m) {
return intersectLL(l, m) ? 0 : distanceLP(l, m[0]);
}
double distanceLS(const L &l, const L &s) {
if (intersectLS(l, s))
return 0;
return min(distanceLP(l, s[0]), distanceLP(l, s[1]));
}
double distanceSP(const L &s, const P &p) {
const P r = projection(s, p);
if (intersectSP(s, r))
return abs(r - p);
return min(abs(s[0] - p), abs(s[1] - p));
}
double distanceSS(const L &s, const L &t) {
if (intersectSS(s, t))
return 0;
return min(min(distanceSP(s, t[0]), distanceSP(s, t[1])),
min(distanceSP(t, s[0]), distanceSP(t, s[1])));
}
bool intersectCL(C c, const L &l) {
return (distanceLP(l, c.c) < c.r + EPS &&
(c.r < abs(c.c - l[0]) + EPS || c.r < abs(c.c - l[1]) + EPS));
}
L crosspointCL(C c, L l) {
P pr = projection(l, c.c);
P e = (l[1] - l[0]) / abs(l[1] - l[0]);
double t = sqrt(c.r * c.r - norm(pr - c.c));
P a = pr + t * e;
P b = pr - t * e;
if (b < a)
swap(a, b);
return L(a, b);
}
L crosspointCC(C a, C b) {
P tmp = b.c - a.c;
double d = abs(tmp);
double q = acos((a.r * a.r + d * d - b.r * b.r) / (2 * a.r * d));
double t = arg(tmp); // atan(tmp.imag()/tmp.real());
P p1 = a.c + polar(a.r, t + q);
P p2 = a.c + polar(a.r, t - q);
if (p2 < p1)
swap(p1, p2);
return L(p1, p2);
}
P crosspointLL(const L &l, const L &m) {
double A = cross(l[1] - l[0], m[1] - m[0]);
double B = cross(l[1] - l[0], l[1] - m[0]);
if (abs(A) < EPS && abs(B) < EPS)
return m[0]; // same line
return m[0] + B / A * (m[1] - m[0]);
}
double area(const G &g) {
double S = 0;
for (int i = 0; i < g.size(); i++) {
S += (cross(g[i], g[(i + 1) % g.size()]));
}
return abs(S / 2.0);
}
bool isconvex(const G &g) {
int n = g.size();
rep(i, n) if (ccw(g[(i + n - 1) % n], g[i % n], g[(i + 1) % n]) ==
-1) return false;
return true;
}
int inconvex(const G &g, const P &p) {
bool in = false;
int n = g.size();
rep(i, n) {
P a = g[i % n] - p;
P b = g[(i + 1) % n] - p;
if (imag(a) > imag(b))
swap(a, b);
if (imag(a) <= 0 && 0 < imag(b))
if (cross(a, b) < 0)
in = !in;
if (cross(a, b) == 0 && dot(a, b) <= 0)
return 1; // ON
}
return in ? 2 : 0; // IN : OUT;
}
G convex_hull(G &ps) {
int n = ps.size(), k = 0;
sort(ps.begin(), ps.end());
G ch(2 * n);
for (int i = 0; i < n; ch[k++] = ps[i++]) // lower-hull
while (k >= 2 && ccw(ch[k - 2], ch[k - 1], ps[i]) == -1)
--k; //<=0 -> ==-1
for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = ps[i--]) // upper-hull
while (k >= t && ccw(ch[k - 2], ch[k - 1], ps[i]) == -1)
--k; //
ch.resize(k - 1);
return ch;
}
double convex_diameter(const G &pt) {
const int n = pt.size();
int is = 0, js = 0;
for (int i = 1; i < n; ++i) {
if (imag(pt[i]) > imag(pt[is]))
is = i;
if (imag(pt[i]) < imag(pt[js]))
js = i;
}
double maxd = norm(pt[is] - pt[js]);
int i, maxi, j, maxj;
i = maxi = is;
j = maxj = js;
do {
if (cross(diff(pt, i), diff(pt, j)) >= 0)
j = (j + 1) % n;
else
i = (i + 1) % n;
if (norm(pt[i] - pt[j]) > maxd) {
maxd = norm(pt[i] - pt[j]);
maxi = i;
maxj = j;
}
} while (i != is || j != js);
return sqrt(maxd); /* farthest pair is (maxi, maxj). */
} // convex_diameter(g)
G convex_cut(const G &g, const L &l) {
G Q;
for (int i = 0; i < g.size(); ++i) {
P a = curr(g, i), b = next(g, i);
if (ccw(l[0], l[1], a) != -1)
Q.push_back(a);
if (ccw(l[0], l[1], a) * ccw(l[0], l[1], b) < 0)
Q.push_back(crosspointLL(L(a, b), l));
}
return Q;
}
P turn(P p, double t) { return p * exp(P(.0, t * PI / 180.0)); }
void printL(const L &out) {
printf("%.9f %.9f %.9f %.9f\n", out[0].real(), out[0].imag(), out[1].real(),
out[1].imag());
}
C CIN() {
P p = pin();
double r;
cin >> r;
return C(p, r);
}
bool para(L a, L b) { return (abs(cross(a[1] - a[0], b[1] - b[0])) < EPS); }
int main() {
double q1, q2, q3, q4;
while (cin >> q1 >> q2 >> q3 >> q4, q1 || q2 || q3 || q4) {
L a(P(q1, q2), P(q3, q4));
cin >> q1 >> q2 >> q3 >> q4;
L b(P(q1, q2), P(q3, q4));
cin >> q1 >> q2 >> q3 >> q4;
L c(P(q1, q2), P(q3, q4));
if (para(a, b) || para(b, c) || para(c, a)) {
cout << "kyo" << endl;
continue;
}
if ((!intersectSS(a, b)) || (!intersectSS(c, b)) || (!intersectSS(a, c))) {
cout << "kyo" << endl;
continue;
}
P p1 = crosspointLL(a, b);
P p2 = crosspointLL(c, b);
P p3 = crosspointLL(a, c);
if (p1 == p2 || p2 == p3 || p3 == p1) {
cout << "kyo" << endl;
continue;
}
p2 -= p1;
p3 -= p1;
double S = abs(p2.real() * p3.imag() - p2.imag() * p3.real()) / 2.0;
if (S < 100000)
cout << "syo-kichi" << endl;
else if (S < 1000000)
cout << "kichi" << endl;
else if (S < 1900000)
cout << "chu-kichi" << endl;
else
cout << "dai-kichi" << endl;
}
}
|
[["-", 51, 34, 12, 16, 31, 16, 31, 16, 17, 72], ["+", 51, 34, 12, 16, 31, 16, 31, 16, 17, 106], ["-", 15, 339, 51, 34, 12, 16, 31, 16, 17, 72], ["+", 15, 339, 51, 34, 12, 16, 31, 16, 17, 106], ["-", 0, 52, 15, 339, 51, 34, 12, 16, 17, 72], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 17, 106]]
| 1
| 3,063
| 6
|
#include <algorithm>
#include <complex>
#include <iostream>
#include <vector>
using namespace std;
typedef complex<double> P;
typedef pair<P, P> L;
const double EPS = 1e-10;
double dot(P a, P b) { return real(conj(a) * b); }
double cross(P a, P b) { return imag(conj(a) * b); }
int ccw(P a, P b, P c) {
c -= a;
b -= a;
if (cross(b, c) > EPS)
return 1;
if (cross(b, c) < -EPS)
return -1;
if (dot(b, c) < -EPS)
return 2;
if (norm(b) < norm(c))
return -2;
return 0;
}
bool isIntersect(L s1, L s2) {
return (ccw(s1.first, s1.second, s2.first) *
ccw(s1.first, s1.second, s2.second) <=
0 &&
ccw(s2.first, s2.second, s2.first) *
ccw(s2.first, s2.second, s1.second) <=
0);
}
P crossPoint(L l, L m) {
double A = cross(l.second - l.first, m.second - m.first);
double B = cross(l.second - l.first, l.second - m.first);
if (fabs(A) < EPS && fabs(B) < EPS)
return m.first;
else if (fabs(A) >= EPS)
return m.first + B / A * (m.second - m.first);
}
double area(vector<P> v) {
double sum = 0.0;
int n = v.size();
for (int i = 0; i < n; i++)
sum += (real(v[i]) - real(v[(i + 1) % n])) *
(imag(v[i]) + imag(v[(i + 1) % n]));
return fabs(sum / 2.0);
}
string ans(vector<P> v) {
double a = area(v);
if (a < EPS)
return "kyo";
if (a < 100000.0 - EPS)
return "syo-kichi";
if (a < 1000000.0 - EPS)
return "kichi";
if (a < 1900000.0 - EPS)
return "chu-kichi";
return "dai-kichi";
}
int main() {
double x1, y1, x2, y2;
while (cin >> x1 >> y1 >> x2 >> y2 && (x1 || y1 || x2 || y2)) {
L v[3];
vector<P> p;
bool f = false;
v[0] = L(P(x1, y1), P(x2, y2));
for (int i = 1; i < 3; i++) {
cin >> x1 >> y1 >> x2 >> y2;
v[i] = L(P(x1, y1), P(x2, y2));
if (!isIntersect(v[0], v[i]))
f = true;
else
p.push_back(crossPoint(v[0], v[i]));
}
if (!isIntersect(v[1], v[2]))
f = true;
else
p.push_back(crossPoint(v[1], v[2]));
if (!f) {
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 3; j++) {
if (abs(p[i] - p[j]) < EPS)
f = true;
}
}
}
if (f)
cout << "kyo" << endl;
else
cout << ans(p) << endl;
}
}
|
#include <algorithm>
#include <complex>
#include <iostream>
#include <vector>
using namespace std;
typedef complex<double> P;
typedef pair<P, P> L;
const double EPS = 1e-8;
double dot(P a, P b) { return real(conj(a) * b); }
double cross(P a, P b) { return imag(conj(a) * b); }
int ccw(P a, P b, P c) {
c -= a;
b -= a;
if (cross(b, c) > EPS)
return 1;
if (cross(b, c) < -EPS)
return -1;
if (dot(b, c) < -EPS)
return 2;
if (norm(b) < norm(c))
return -2;
return 0;
}
bool isIntersect(L s1, L s2) {
return (ccw(s1.first, s1.second, s2.first) *
ccw(s1.first, s1.second, s2.second) <=
0 &&
ccw(s2.first, s2.second, s1.first) *
ccw(s2.first, s2.second, s1.second) <=
0);
}
P crossPoint(L l, L m) {
double A = cross(l.second - l.first, m.second - m.first);
double B = cross(l.second - l.first, l.second - m.first);
if (fabs(A) < EPS && fabs(B) < EPS)
return m.first;
else if (fabs(A) >= EPS)
return m.first + B / A * (m.second - m.first);
}
double area(vector<P> v) {
double sum = 0.0;
int n = v.size();
for (int i = 0; i < n; i++)
sum += (real(v[i]) - real(v[(i + 1) % n])) *
(imag(v[i]) + imag(v[(i + 1) % n]));
return fabs(sum / 2.0);
}
string ans(vector<P> v) {
double a = area(v);
if (a < EPS)
return "kyo";
if (a < 100000.0 - EPS)
return "syo-kichi";
if (a < 1000000.0 - EPS)
return "kichi";
if (a < 1900000.0 - EPS)
return "chu-kichi";
return "dai-kichi";
}
int main() {
double x1, y1, x2, y2;
while (cin >> x1 >> y1 >> x2 >> y2 && (x1 || y1 || x2 || y2)) {
L v[3];
vector<P> p;
bool f = false;
v[0] = L(P(x1, y1), P(x2, y2));
for (int i = 1; i < 3; i++) {
cin >> x1 >> y1 >> x2 >> y2;
v[i] = L(P(x1, y1), P(x2, y2));
if (!isIntersect(v[0], v[i]))
f = true;
else
p.push_back(crossPoint(v[0], v[i]));
}
if (!isIntersect(v[1], v[2]))
f = true;
else
p.push_back(crossPoint(v[1], v[2]));
if (!f) {
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 3; j++) {
if (abs(p[i] - p[j]) < EPS)
f = true;
}
}
}
if (f)
cout << "kyo" << endl;
else
cout << ans(p) << endl;
}
}
|
[["-", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["-", 31, 16, 31, 2, 3, 4, 0, 118, 28, 22], ["+", 31, 16, 31, 2, 3, 4, 0, 118, 28, 22]]
| 1
| 804
| 4
|
#include <iostream>
using namespace std;
int main() {
char field[3][3];
while (true) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cin >> field[i][j];
if (field[i][j] == '0')
return 0;
}
}
bool flag = false;
for (int i = 0; i < 3; i++) {
if (field[i][1] == field[i][0] && field[i][1] == field[i][2] &&
field[i][1] != '+') {
cout << field[i][1] << endl;
flag = true;
break;
}
if (field[1][i] == field[0][i] && field[1][i] == field[2][i] &&
field[i][1] != '+') {
cout << field[1][i] << endl;
flag = true;
break;
}
}
if (flag)
continue;
if (((field[1][1] == field[0][0] && field[1][1] == field[2][2]) ||
(field[1][1] == field[2][0] && field[1][1] == field[0][2])) &&
field[1][1] != '+') {
cout << field[1][1] << endl;
continue;
}
cout << "NA" << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
char field[3][3];
while (true) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cin >> field[i][j];
if (field[i][j] == '0')
return 0;
}
}
bool flag = false;
for (int i = 0; i < 3; i++) {
if (field[i][1] == field[i][0] && field[i][1] == field[i][2] &&
field[i][1] != '+') {
cout << field[i][1] << endl;
flag = true;
break;
}
if (field[1][i] == field[0][i] && field[1][i] == field[2][i] &&
field[1][i] != '+') {
cout << field[1][i] << endl;
flag = true;
break;
}
}
if (flag)
continue;
if (((field[1][1] == field[0][0] && field[1][1] == field[2][2]) ||
(field[1][1] == field[2][0] && field[1][1] == field[0][2])) &&
field[1][1] != '+') {
cout << field[1][1] << endl;
continue;
}
cout << "NA" << endl;
}
return 0;
}
|
[["-", 12, 16, 31, 69, 28, 69, 341, 342, 0, 22], ["+", 12, 16, 31, 69, 28, 69, 341, 342, 0, 13], ["-", 51, 16, 12, 16, 31, 69, 341, 342, 0, 13], ["+", 51, 16, 12, 16, 31, 69, 341, 342, 0, 22]]
| 1
| 356
| 4
|
#include <iostream>
using namespace std;
char field[3][4];
char solve() {
for (int i = 0; i < 3; i++) {
if (field[i][0] == field[i][1] && field[i][1] == field[i][2] &&
(field[i][0] == 'w' || field[i][0] == 'b'))
return field[i][0];
}
for (int k = 0; k < 3; k++) {
if (field[0][k] == field[1][k] && field[1][k] == field[2][k] &&
(field[0][k] == 'w' || field[0][k] == 'b'))
return field[0][k];
}
if (field[0][0] == field[1][1] && field[1][1] == field[2][2] &&
(field[0][0] == 'w' || field[0][0] == 'b'))
return field[0][0];
if (field[0][2] == field[1][1] && field[1][1] == field[2][0] &&
(field[0][2] == 'w' || field[0][2] == 'b'))
return field[0][2];
return 'N';
}
int main() {
while (true) {
for (int i = 0; i < 3; i++) {
cin >> field[i];
if (field[0][0] == '0')
return 0;
}
char ans = solve();
if (ans != 'N')
cout << "NA\n";
else
cout << ans << endl;
}
}
|
#include <iostream>
using namespace std;
char field[3][4];
char solve() {
for (int i = 0; i < 3; i++) {
if (field[i][0] == field[i][1] && field[i][1] == field[i][2] &&
(field[i][0] == 'w' || field[i][0] == 'b'))
return field[i][0];
}
for (int k = 0; k < 3; k++) {
if (field[0][k] == field[1][k] && field[1][k] == field[2][k] &&
(field[0][k] == 'w' || field[0][k] == 'b'))
return field[0][k];
}
if (field[0][0] == field[1][1] && field[1][1] == field[2][2] &&
(field[0][0] == 'w' || field[0][0] == 'b'))
return field[0][0];
if (field[0][2] == field[1][1] && field[1][1] == field[2][0] &&
(field[0][2] == 'w' || field[0][2] == 'b'))
return field[0][2];
return 'N';
}
int main() {
while (true) {
for (int i = 0; i < 3; i++) {
cin >> field[i];
if (field[0][0] == '0')
return 0;
}
char ans = solve();
if (ans == 'N')
cout << "NA\n";
else
cout << ans << endl;
}
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 79], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60]]
| 1
| 415
| 2
|
#include <iostream>
int main() {
std::string m[3];
while (std::cin >> m[0], m[0][0] != '0') {
for (int i = 1; i < 3; i++)
std::cin >> m[i];
std::string w = "NA";
for (int i = 0; i < 3; i++) {
if (!(m[i][0] + m[i][1] - m[i][2] * 2))
if (m[i][0] != '+')
w = m[i][0];
if (!(m[0][i] + m[1][i] - m[2][i] * 2))
if (m[0][i] != '+')
w = m[0][i];
}
if (m[0][0] + m[1][1] - m[2][2] * 2)
if (m[0][0] != '+')
w = m[0][0];
if (m[0][2] + m[1][1] - m[2][0] * 2)
if (m[0][2] != '+')
w = m[0][2];
std::cout << w << std::endl;
}
}
|
#include <iostream>
int main() {
std::string m[3];
while (std::cin >> m[0], m[0][0] != '0') {
for (int i = 1; i < 3; i++)
std::cin >> m[i];
std::string w = "NA";
for (int i = 0; i < 3; i++) {
if (!(m[i][0] + m[i][1] - m[i][2] * 2))
if (m[i][0] != '+')
w = m[i][0];
if (!(m[0][i] + m[1][i] - m[2][i] * 2))
if (m[0][i] != '+')
w = m[0][i];
}
if (!(m[0][0] + m[1][1] - m[2][2] * 2))
if (m[0][0] != '+')
w = m[0][0];
if (!(m[0][2] + m[1][1] - m[2][0] * 2))
if (m[0][2] != '+')
w = m[0][2];
std::cout << w << std::endl;
}
}
|
[["+", 8, 9, 0, 57, 15, 339, 51, 91, 17, 111], ["+", 0, 57, 15, 339, 51, 91, 28, 23, 0, 24], ["+", 0, 57, 15, 339, 51, 91, 28, 23, 0, 25], ["+", 0, 52, 8, 9, 0, 57, 15, 339, 0, 24]]
| 1
| 313
| 6
|
#include <iostream>
#include <string>
using namespace std;
int main() {
for (string s1, s2, s3; cin >> s1, s1 != "0";) {
cin >> s2 >> s3;
string s = s1 + s2 + s3;
string bit[] = {"111000000", "000111000", "000000111", "100100100",
"010010010", "001001001", "100010001", "001010100"};
int winner = -1;
for (int i = 0; i < 8; i++) {
string t;
for (int j = 0; j < 8; j++) {
if (bit[i][j] == '1')
t.push_back(s[j]);
}
if (t[0] == 'w' && t[1] == 'w' && t[2] == 'w')
winner = 0;
if (t[0] == 'b' && t[1] == 'b' && t[2] == 'b')
winner = 1;
}
if (winner == 0) {
cout << 'w' << endl;
} else if (winner == 1) {
cout << 'b' << endl;
} else {
cout << "NA" << endl;
}
}
}
|
#include <iostream>
#include <string>
using namespace std;
int main() {
for (string s1, s2, s3; cin >> s1, s1 != "0";) {
cin >> s2 >> s3;
string s = s1 + s2 + s3;
string bit[] = {"111000000", "000111000", "000000111", "100100100",
"010010010", "001001001", "100010001", "001010100"};
int winner = -1;
for (int i = 0; i < 8; i++) {
string t;
for (int j = 0; j < 9; j++) {
if (bit[i][j] == '1')
t.push_back(s[j]);
}
if (t[0] == 'w' && t[1] == 'w' && t[2] == 'w')
winner = 0;
if (t[0] == 'b' && t[1] == 'b' && t[2] == 'b')
winner = 1;
}
if (winner == 0) {
cout << 'w' << endl;
} else if (winner == 1) {
cout << 'b' << endl;
} else {
cout << "NA" << endl;
}
}
}
|
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13]]
| 1
| 264
| 2
|
#include <iostream>
using namespace std;
bool win_check(char c, char d, char e) {
if (c == 'b' && d == 'b' && e == 'b') {
cout << 'b' << endl;
return true;
} else if (c == 'w' && d == 'w' && e == 'w') {
cout << 'w' << endl;
return true;
}
return false;
}
int main() {
while (true) {
char board[3][3];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cin >> board[i][j];
if (board[i][j] == '0')
return 0;
}
}
bool flag = false;
for (int i = 0; i < 3; i++) {
flag = win_check(board[i][0], board[i][1], board[i][2]);
if (flag)
break;
}
if (flag)
continue;
for (int j = 0; j < 3; j++) {
flag = win_check(board[0][j], board[1][j], board[2][j]);
if (flag)
break;
}
if (flag)
continue;
flag = win_check(board[0][0], board[1][1], board[2][2]);
if (flag)
continue;
flag = win_check(board[0][3], board[1][1], board[2][0]);
if (flag)
continue;
cout << "NA" << endl;
}
}
|
#include <iostream>
using namespace std;
bool win_check(char c, char d, char e) {
if (c == 'b' && d == 'b' && e == 'b') {
cout << 'b' << endl;
return true;
} else if (c == 'w' && d == 'w' && e == 'w') {
cout << 'w' << endl;
return true;
}
return false;
}
int main() {
while (true) {
char board[3][3];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cin >> board[i][j];
if (board[i][j] == '0')
return 0;
}
}
bool flag = false;
for (int i = 0; i < 3; i++) {
flag = win_check(board[i][0], board[i][1], board[i][2]);
if (flag)
break;
}
if (flag)
continue;
for (int j = 0; j < 3; j++) {
flag = win_check(board[0][j], board[1][j], board[2][j]);
if (flag)
break;
}
if (flag)
continue;
flag = win_check(board[0][0], board[1][1], board[2][2]);
if (flag)
continue;
flag = win_check(board[0][2], board[1][1], board[2][0]);
if (flag)
continue;
cout << "NA" << endl;
}
}
|
[["-", 12, 2, 3, 4, 0, 69, 341, 342, 0, 13], ["+", 12, 2, 3, 4, 0, 69, 341, 342, 0, 13]]
| 1
| 367
| 2
|
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int main() {
char grid[3][3];
while (1) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cin >> grid[i][j];
if (grid[i][j] == '0')
return 0;
}
}
for (int i = 0; i < 3; i++) {
bool b = 1, w = 1;
for (int j = 0; j < 3; j++) {
if (grid[i][j] == 'b')
w = 0;
else if (grid[i][j] == 'w')
b = 0;
else
b = 0, w = 0;
}
if (b) {
cout << 'b' << endl;
goto EXIT;
}
if (w) {
cout << 'w' << endl;
goto EXIT;
}
}
for (int i = 0; i < 3; i++) {
bool b = 1, w = 1;
for (int j = 0; j < 3; j++) {
if (grid[j][i] == 'b')
w = 0;
else if (grid[j][i] == 'w')
b = 0;
else
b = 0, w = 0;
}
if (b) {
cout << 'b' << endl;
goto EXIT;
}
if (w) {
cout << 'w' << endl;
goto EXIT;
}
}
bool b, w;
b = 1, w = 1;
for (int i = 0; i < 3; i++) {
if (grid[i][i] == 'b')
w = 0;
if (grid[i][i] == 'w')
b = 0;
else
b = 0, w = 0;
}
if (b) {
cout << 'b' << endl;
goto EXIT;
}
if (w) {
cout << 'w' << endl;
goto EXIT;
}
b = 1, w = 1;
for (int i = 0; i < 3; i++) {
if (grid[i][2 - i] == 'b')
w = 0;
if (grid[i][2 - i] == 'w')
b = 0;
else
b = 0, w = 0;
}
if (b) {
cout << 'b' << endl;
goto EXIT;
}
if (w) {
cout << 'w' << endl;
goto EXIT;
}
cout << "NA" << endl;
EXIT:;
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int main() {
char grid[3][3];
while (1) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cin >> grid[i][j];
if (grid[i][j] == '0')
return 0;
}
}
for (int i = 0; i < 3; i++) {
bool b = 1, w = 1;
for (int j = 0; j < 3; j++) {
if (grid[i][j] == 'b')
w = 0;
else if (grid[i][j] == 'w')
b = 0;
else
b = 0, w = 0;
}
if (b) {
cout << 'b' << endl;
goto EXIT;
}
if (w) {
cout << 'w' << endl;
goto EXIT;
}
}
for (int i = 0; i < 3; i++) {
bool b = 1, w = 1;
for (int j = 0; j < 3; j++) {
if (grid[j][i] == 'b')
w = 0;
else if (grid[j][i] == 'w')
b = 0;
else
b = 0, w = 0;
}
if (b) {
cout << 'b' << endl;
goto EXIT;
}
if (w) {
cout << 'w' << endl;
goto EXIT;
}
}
bool b, w;
b = 1, w = 1;
for (int i = 0; i < 3; i++) {
if (grid[i][i] == 'b')
w = 0;
else if (grid[i][i] == 'w')
b = 0;
else
b = 0, w = 0;
}
if (b) {
cout << 'b' << endl;
goto EXIT;
}
if (w) {
cout << 'w' << endl;
goto EXIT;
}
b = 1, w = 1;
for (int i = 0; i < 3; i++) {
if (grid[i][2 - i] == 'b')
w = 0;
else if (grid[i][2 - i] == 'w')
b = 0;
else
b = 0, w = 0;
}
if (b) {
cout << 'b' << endl;
goto EXIT;
}
if (w) {
cout << 'w' << endl;
goto EXIT;
}
cout << "NA" << endl;
EXIT:;
}
return 0;
}
|
[["+", 0, 7, 8, 9, 0, 57, 75, 76, 0, 95]]
| 1
| 561
| 2
|
#include <iostream>
#include <string>
using namespace std;
string s[9];
int dx[] = {0, 0, 1, -1, 1, 1 - 1, -1};
int dy[] = {1, -1, 0, 0, -1, 1, -1, 1};
int k;
bool solve(char c, int p, int y, int x) {
if (y < 0 || x < 0 || y == 3 || x == 3)
return false;
if (c != s[y][x] || c == '+')
return false;
if (p == 3)
return true;
solve(c, p + 1, y + dy[k], x + dx[k]);
}
int main() {
while (true) {
cin >> s[0];
if (s[0] == "0")
break;
cin >> s[1] >> s[2];
char c = '@';
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
for (k = 0; k < 4; k++)
if (solve(s[i][j], 1, i, j))
c = s[i][j];
}
}
if (c == '@')
cout << "NA" << endl;
else
cout << c << endl;
}
}
|
#include <iostream>
#include <string>
using namespace std;
string s[9];
int dx[] = {0, 0, 1, -1, 1, 1 - 1, -1};
int dy[] = {1, -1, 0, 0, -1, 1, -1, 1};
int k;
bool solve(char c, int p, int y, int x) {
if (y < 0 || x < 0 || y == 3 || x == 3)
return false;
if (c != s[y][x] || c == '+')
return false;
if (p == 3)
return true;
solve(c, p + 1, y + dy[k], x + dx[k]);
}
int main() {
while (true) {
cin >> s[0];
if (s[0] == "0")
break;
cin >> s[1] >> s[2];
char c = '@';
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
for (k = 0; k < 8; k++)
if (solve(s[i][j], 1, i, j))
c = s[i][j];
}
}
if (c == '@')
cout << "NA" << endl;
else
cout << c << endl;
}
}
|
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13]]
| 1
| 302
| 2
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.