buggy_code
stringlengths 11
625k
| fixed_code
stringlengths 17
625k
| bug_type
stringlengths 2
4.45k
| language
int64 0
8
| token_count
int64 5
200k
|
|---|---|---|---|---|
#include <stdio.h>
int main(void) {
int n, i, l;
long a[5000], ans, s;
for (i = 0; i < 5000; i++)
a[i] = NULL;
while (scanf("%d", &n)) {
if (n == 0)
break;
ans = -100000;
for (i = 0; i < n; i++) {
scanf("%ld", &a[i]);
}
for (i = 0; i < n; i++) {
s = -100000;
for (l = i; l < n; l++) {
s += a[l];
if (ans < s)
ans = s;
}
}
printf("%ld\n", ans);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int n, i, l;
long a[5000], ans, s;
for (i = 0; i < 5000; i++)
a[i] = NULL;
while (scanf("%d", &n)) {
if (n == 0)
break;
ans = -100000;
for (i = 0; i < n; i++) {
scanf("%ld", &a[i]);
}
for (i = 0; i < n; i++) {
s = 0;
for (l = i; l < n; l++) {
s += a[l];
if (ans < s)
ans = s;
}
}
printf("%ld\n", ans);
}
return 0;
}
|
[["-", 0, 7, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 12, 13]]
| 0
| 164
|
#include <stdio.h>
int main() {
long int n, s, t, sum, max, d[5000];
while (scanf("%d", &n) && n) {
max = 0;
for (s = 0; s < n; s++)
scanf("%d", &d[s]);
for (s = 0; s < n; s++) {
sum = 0;
for (t = s; t < n; t++) {
sum += d[t];
if (sum > max)
max = sum;
}
}
printf("%ld\n", max);
}
return 0;
}
|
#include <stdio.h>
int main() {
long int n, s, t, sum, max, d[5000];
while (scanf("%d", &n) && n) {
max = -100000;
for (s = 0; s < n; s++)
scanf("%ld", &d[s]);
for (s = 0; s < n; s++) {
sum = 0;
for (t = s; t < n; t++) {
sum += d[t];
if (sum > max)
max = sum;
}
}
printf("%ld\n", max);
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["-", 8, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 8, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 0
| 135
|
a[9999];
main(n, i, j, m, s) {
for (; scanf("%d", &n), n; printf("%d\n", m)) {
for (i = 0; i < n; i++)
scanf("%d", a + i);
for (m = -999999, i = 0; i < n; i++)
for (s = 0, j = i; j < n; m = m < s ? m : s, j++)
s += a[j];
}
exit(0);
}
|
a[9999];
main(n, i, j, m, s) {
for (; scanf("%d", &n), n; printf("%d\n", m)) {
for (i = 0; i < n; i++)
scanf("%d", a + i);
for (m = -999999, i = 0; i < n; i++)
for (s = 0, j = i; j<n; m = m> s ? m : s, j++)
s += a[j];
}
exit(0);
}
|
[["-", 26, 34, 31, 11, 12, 41, 15, 16, 17, 18], ["+", 26, 34, 31, 11, 12, 41, 15, 16, 17, 47]]
| 0
| 127
|
#include <stdio.h>
int main() {
int n;
int a[5000];
long temp;
long max;
int i, j;
scanf("%d", &n);
while (n) {
max = -100000;
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
for (i = 0; i < n; i++) {
temp = 0;
for (j = i; j < n - i; j++) {
temp += a[j];
if (temp > max)
max = temp;
}
}
printf("%ld\n", max);
scanf("%d", &n);
}
return 0;
}
|
#include <stdio.h>
int main() {
int n;
int a[5000];
long temp;
long max;
int i, j;
scanf("%d", &n);
while (n) {
max = -100000;
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
for (i = 0; i < n; i++) {
temp = 0;
for (j = i; j < n; j++) {
temp += a[j];
if (temp > max)
max = temp;
}
}
printf("%ld\n", max);
scanf("%d", &n);
}
return 0;
}
|
[["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 12, 22]]
| 0
| 150
|
#include <stdio.h>
int n, x, s, ans;
int main(void) {
while (scanf("%d", &n) * n) {
s = 0;
ans = -999999;
for (; n > 0; n--) {
scanf("%d", &x);
s += x;
if (x > ans)
ans = x;
if (s < 0)
s = 0;
}
printf("%d\n", ans);
}
}
|
#include <stdio.h>
int n, x, s, ans;
int main(void) {
while (scanf("%d", &n) * n) {
s = 0;
ans = -999999;
for (; n > 0; n--) {
scanf("%d", &x);
s += x;
if (s > ans)
ans = s;
if (s < 0)
s = 0;
}
printf("%d\n", ans);
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 23, 0, 16, 31, 22], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 31, 22], ["-", 8, 9, 0, 57, 64, 1, 0, 11, 12, 22], ["+", 8, 9, 0, 57, 64, 1, 0, 11, 12, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 38], ["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 13], ["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 35]]
| 0
| 98
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
int n, i, j, k;
int tmp, max;
int *a;
while (1) {
scanf("%d", &n);
if (n == 0)
break;
a = malloc(sizeof(int) * n);
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
// for(i=0;i<n;i++)
// printf("a[%d]=%ld\n",i,a[i]);
max = a[0];
tmp = 0;
for (i = 0; i < n; i++) {
for (j = i; j < n; j++) {
tmp += a[j];
// printf("tmp=%ld\n",tmp);
if (tmp > max)
max = tmp;
}
tmp = 0;
}
printf("\nmax:%d\n", max);
free(a);
}
return 0;
}
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
int n, i, j, k;
int tmp, max;
int *a;
while (1) {
scanf("%d", &n);
if (n == 0)
break;
a = malloc(sizeof(int) * n);
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
// for(i=0;i<n;i++)
// printf("a[%d]=%ld\n",i,a[i]);
max = a[0];
tmp = 0;
for (i = 0; i < n; i++) {
for (j = i; j < n; j++) {
tmp += a[j];
// printf("tmp=%ld\n",tmp);
if (tmp > max)
max = tmp;
}
tmp = 0;
}
printf("%d\n", max);
free(a);
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 0
| 177
|
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#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 FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF LLONG_MAX
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;
#define ARRAY_MAX 5005
int main() {
ll n;
while (cin >> n, n) {
vector<ll> arr(ARRAY_MAX, 0);
REP(i, n) { cin >> arr[i + 1]; }
arr[0] = 0;
REP(i, n) { arr[i + 1] += arr[i]; }
ll maxi = -INF;
for (int i = n; i >= 0; i--) {
for (int j = 0; j < i - 1; j++) {
maxi = max(maxi, arr[i] - arr[j]);
}
}
cout << maxi << endl;
}
return 0;
}
|
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#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 FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF LLONG_MAX
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;
#define ARRAY_MAX 5005
int main() {
ll n;
while (cin >> n, n) {
vector<ll> arr(ARRAY_MAX, 0);
REP(i, n) { cin >> arr[i + 1]; }
arr[0] = 0;
REP(i, n) { arr[i + 1] += arr[i]; }
ll maxi = -INF;
for (int i = n; i >= 0; i--) {
for (int j = 0; j < i; j++) {
maxi = max(maxi, arr[i] - arr[j]);
}
}
cout << maxi << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13]]
| 1
| 273
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ll n;
cin >> n;
while (n != 0) {
vector<ll> vec(n);
for (ll i = 0; i < n; i++) {
cin >> vec.at(i);
}
vector<ll> rsw(n + 1);
rsw.at(0) = 0;
for (int i = 1; i < n + 1; i++) {
rsw.at(i) = rsw.at(i - 1) + vec.at(i - 1);
}
ll ans = vec.at(0);
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
if (ans > rsw.at(j + 1) - rsw.at(i)) {
ans = rsw.at(j + 1) - rsw.at(i);
}
}
}
cout << ans << endl;
cin >> n;
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ll n;
cin >> n;
while (n != 0) {
vector<ll> vec(n);
for (ll i = 0; i < n; i++) {
cin >> vec.at(i);
}
vector<ll> rsw(n + 1);
rsw.at(0) = 0;
for (int i = 1; i < n + 1; i++) {
rsw.at(i) = rsw.at(i - 1) + vec.at(i - 1);
}
ll ans = vec.at(0);
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
if (ans < rsw.at(j + 1) - rsw.at(i)) {
ans = rsw.at(j + 1) - rsw.at(i);
}
}
}
cout << ans << endl;
cin >> n;
}
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18]]
| 1
| 219
|
#include <iostream>
using namespace std;
int main() {
int n;
long int a[5000], sum, ans;
while (1) {
cin >> n;
if (n == 0)
break;
sum = 0;
ans = -1000000;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
sum = 0;
for (int j = 0; j < n; j++) {
sum += a[i + j];
if (ans < sum) {
ans = sum;
}
}
}
cout << ans << endl;
}
}
|
#include <iostream>
using namespace std;
int main() {
int n;
long int a[5000], sum, ans;
while (1) {
cin >> n;
if (n == 0)
break;
sum = 0;
ans = -1000000;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
sum = 0;
for (int j = 0; i + j < n; j++) {
sum += a[i + j];
if (ans < sum) {
ans = sum;
}
}
}
cout << ans << endl;
}
}
|
[["+", 8, 9, 0, 7, 15, 16, 31, 16, 31, 22], ["+", 8, 9, 0, 7, 15, 16, 31, 16, 17, 72]]
| 1
| 138
|
#include <iostream>
#include <vector>
using std::cin;
int main() {
int n;
while (cin >> n) {
if (n == 0) {
break;
}
std::vector<int> line(n);
for (auto i = 0; i < n; i++) {
int in;
cin >> in;
line.push_back(in);
}
int max = -100000;
for (auto i = 0; i < n; i++) {
int sum_ij;
int max_i;
max_i = sum_ij = line.at(i);
for (auto j = i + 1; j < n; j++) {
sum_ij += line.at(j);
if (sum_ij > max_i) {
max_i = sum_ij;
}
}
if (max_i > max) {
max = max_i;
}
}
std::cout << max << std::endl;
}
return 0;
}
|
#include <iostream>
#include <vector>
using std::cin;
int main() {
int n;
while (cin >> n) {
if (n == 0) {
break;
}
std::vector<int> line(n);
for (auto i = 0; i < n; i++) {
int in;
cin >> in;
line.at(i) = in;
}
int max = -100000;
for (auto i = 0; i < n; i++) {
int sum_ij;
int max_i;
max_i = sum_ij = line.at(i);
for (auto j = i + 1; j < n; j++) {
sum_ij += line.at(j);
if (sum_ij > max_i) {
max_i = sum_ij;
}
}
if (max_i > max) {
max = max_i;
}
}
std::cout << max << std::endl;
}
return 0;
}
|
[["-", 8, 9, 0, 1, 0, 2, 63, 118, 119, 120], ["+", 0, 1, 0, 11, 31, 2, 63, 118, 119, 120], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22], ["+", 0, 1, 0, 11, 31, 2, 3, 4, 0, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 12, 22]]
| 1
| 179
|
#include <cstdio>
#include <stack>
using namespace std;
int main() {
int a, b, n, i, j, x[10];
scanf("%d", &n);
for (j = 0; j < n; j++) {
for (i = 0; i < 10; i++) {
scanf("%d", &x[i]);
}
stack<int> B;
stack<int> C;
B.push(x[0]);
for (i = 1; i <= 9; i++) {
if (x[i - 1] > x[i]) {
C.push(x[i]);
goto ccc;
} else {
B.push(x[i]);
goto bbb;
}
bbb:;
}
ccc:
for (j = i; j < 9; j++) {
if (B.top() < x[j + 1]) {
B.push(x[j + 1]);
} else if (C.top() < x[j + 1]) {
C.push(x[j + 1]);
} else {
printf("NO\n");
goto aaa;
}
}
printf("YES\n");
aaa:;
}
return 0;
}
|
#include <cstdio>
#include <stack>
using namespace std;
int main() {
int k, n, i, j, x[10];
scanf("%d", &n);
for (k = 0; k < n; k++) {
for (i = 0; i < 10; i++) {
scanf("%d", &x[i]);
}
stack<int> B;
stack<int> C;
B.push(x[0]);
for (i = 1; i <= 9; i++) {
if (x[i - 1] > x[i]) {
C.push(x[i]);
goto ccc;
} else {
B.push(x[i]);
goto bbb;
}
bbb:;
}
ccc:
for (j = i; j < 9; j++) {
if (B.top() < x[j + 1]) {
B.push(x[j + 1]);
} else if (C.top() < x[j + 1]) {
C.push(x[j + 1]);
} else {
printf("NO\n");
goto aaa;
}
}
printf("YES\n");
aaa:;
}
return 0;
}
|
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 0, 21], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["-", 0, 14, 8, 9, 0, 7, 10, 11, 31, 22], ["+", 0, 14, 8, 9, 0, 7, 10, 11, 31, 22], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 31, 22], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 31, 22], ["-", 0, 14, 8, 9, 0, 7, 26, 27, 28, 22], ["+", 0, 14, 8, 9, 0, 7, 26, 27, 28, 22]]
| 1
| 272
|
#include <stdio.h>
main() {
int x[10], y[10], z[10], i, j, n, cz, cy, tmp;
scanf("%d", &n);
for (i = 0; i < n; i++) {
tmp = 0;
cy = 0;
cz = 0;
for (j = 0; j < 10; j++) {
scanf("%d", &x[j]);
z[j] = 0;
y[j] = 0;
}
for (j = 0; j < 10; j++) {
if (x[j] >= y[cy - 1 * cy > 0])
y[cy++] = x[j];
else if (x[j] >= z[cz - 1 * cz > 0])
z[cz++] = x[j];
else
tmp = 1;
}
if (tmp == 1)
printf("NO\n");
else
printf("YES\n");
}
}
|
#include <stdio.h>
main() {
int x[10], y[10], z[10], i, j, n, cz, cy, tmp;
scanf("%d", &n);
for (i = 0; i < n; i++) {
tmp = 0;
cy = 0;
cz = 0;
for (j = 0; j < 10; j++) {
scanf("%d", &x[j]);
z[j] = 0;
y[j] = 0;
}
for (j = 0; j < 10; j++) {
if (x[j] >= y[cy - 1 * (cy > 0)])
y[cy++] = x[j];
else if (x[j] >= z[cz - 1 * (cz > 0)])
z[cz++] = x[j];
else
tmp = 1;
}
if (tmp == 1)
printf("NO\n");
else
printf("YES\n");
}
}
|
[["+", 341, 342, 0, 16, 12, 16, 12, 23, 0, 24], ["+", 341, 342, 0, 16, 12, 16, 12, 23, 0, 25]]
| 1
| 216
|
#include <cstdio>
#define N 10
int D, Ball[N];
int R, L;
bool solve(int i) {
if (i == N)
return true;
if (R < Ball[i]) {
R = Ball[i];
if (solve(i + 1))
return true;
}
if (L < Ball[i]) {
L = Ball[i];
if (solve(i + 1))
return true;
}
return false;
}
int main() {
scanf("%d", D);
for (int i = 0; i < D; i++) {
R = L = 0;
for (int j = 0; j < N; j++)
scanf("%d", &Ball[j]);
R = Ball[0];
if (solve(1))
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
|
#include <cstdio>
#define N 10
int D, Ball[N];
int R, L;
bool solve(int i) {
if (i == N)
return true;
if (R < Ball[i]) {
R = Ball[i];
if (solve(i + 1))
return true;
}
if (L < Ball[i]) {
L = Ball[i];
if (solve(i + 1))
return true;
}
return false;
}
int main() {
scanf("%d", &D);
for (int i = 0; i < D; i++) {
R = L = 0;
for (int j = 0; j < N; j++)
scanf("%d", &Ball[j]);
R = Ball[0];
if (solve(1))
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 66, 17, 67]]
| 1
| 196
|
#include <algorithm> // sort などのアルゴリズム
#include <ctype.h> // C の文字種用
#include <iostream> // C++の入出力
#include <math.h>
#include <sstream>
#include <stdio.h> // C の入出力
#include <string.h> // C の文字列用
#include <string> // C++の文字列
using namespace std;
int ball[10];
bool dfs(int i, int b, int c);
int main(void) {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
for (int s = 0; s < 10; s++) {
cin >> ball[s];
}
if (dfs(0, 0, 0))
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
bool dfs(int i, int b, int c) {
if (i == 10)
return true;
if (b < ball[i]) {
if (dfs(i + 1, ball[i], c))
return true;
}
if (c < ball[i]) {
if (dfs(i + 1, b, ball[i]))
return true;
}
return false;
}
|
#include <algorithm> // sort などのアルゴリズム
#include <ctype.h> // C の文字種用
#include <iostream> // C++の入出力
#include <math.h>
#include <sstream>
#include <stdio.h> // C の入出力
#include <string.h> // C の文字列用
#include <string> // C++の文字列
using namespace std;
int ball[10];
bool dfs(int i, int b, int c);
int main(void) {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
for (int s = 0; s < 10; s++) {
cin >> ball[s];
}
if (dfs(0, 0, 0))
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
bool dfs(int i, int b, int c) {
if (i == 10)
return true;
if (b < ball[i]) {
if (dfs(i + 1, ball[i], c))
return true;
}
if (c < ball[i]) {
if (dfs(i + 1, b, ball[i]))
return true;
}
return false;
}
|
[["-", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 215
|
#include <iostream>
#include <string.h>
using namespace std;
int ball_list[10];
int right_list[10];
int left_list[10];
bool flag;
void dfs(int right, int left) {
int count = right + left;
if (count == 10) {
flag = true;
} else {
if (right == 0 || right_list[right - 1] < ball_list[count]) {
if (right == 0) {
right_list[0] = ball_list[count];
} else {
right_list[right - 1] = ball_list[count];
}
dfs(right + 1, left);
}
if (left == 0 || left_list[left - 1] < left_list[left]) {
if (left == 0) {
left_list[0] = ball_list[count];
} else {
left_list[left - 1] = ball_list[count];
}
dfs(right, left + 1);
}
}
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
flag = false;
memset(right_list, 0, sizeof(right_list));
memset(left_list, 0, sizeof(left_list));
for (int j = 0; j < 10; j++) {
cin >> ball_list[j];
}
dfs(0, 0);
if (flag) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}
|
#include <iostream>
#include <string.h>
using namespace std;
int ball_list[10];
int right_list[10];
int left_list[10];
bool flag;
void dfs(int right, int left) {
int count = right + left;
if (count == 10) {
flag = true;
} else {
if (right == 0 || right_list[right - 1] < ball_list[count]) {
if (right == 0) {
right_list[0] = ball_list[count];
} else {
right_list[right] = ball_list[count];
}
dfs(right + 1, left);
}
if (left == 0 || left_list[left - 1] < ball_list[count]) {
if (left == 0) {
left_list[0] = ball_list[count];
} else {
left_list[left] = ball_list[count];
}
dfs(right, left + 1);
}
}
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
flag = false;
memset(right_list, 0, sizeof(right_list));
memset(left_list, 0, sizeof(left_list));
for (int j = 0; j < 10; j++) {
cin >> ball_list[j];
}
dfs(0, 0);
if (flag) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}
|
[["-", 0, 11, 31, 69, 341, 342, 0, 16, 17, 33], ["-", 0, 11, 31, 69, 341, 342, 0, 16, 12, 13], ["-", 15, 339, 51, 16, 12, 16, 12, 69, 28, 22], ["+", 15, 339, 51, 16, 12, 16, 12, 69, 28, 22], ["-", 51, 16, 12, 16, 12, 69, 341, 342, 0, 22], ["+", 51, 16, 12, 16, 12, 69, 341, 342, 0, 22]]
| 1
| 301
|
#include <iostream>
using namespace std;
const int kBalln = 10;
int ball[kBalln];
bool ExistAsceOrder(int i, int a, int b) {
// 終了条件
if (i == kBalln)
return true;
// ボールiを筒Bに入れる場合
if (a < ball[i] && ExistAsceOrder(i + 1, ball[i], b))
return true;
// ボールiを筒Cに入れる場合
if (b < ball[i] && ExistAsceOrder(i + 1, a, ball[i]))
return true;
// どちらの筒に入れても昇順にならない場合
return false;
}
int main() {
int n;
cin >> n;
for (int j = 0; j < n; ++j) {
for (int i = 0; i < kBalln; ++i) {
cin >> ball[i];
}
if (ExistAsceOrder(0, 0, 0)) {
cout << "YEY" << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}
|
#include <iostream>
using namespace std;
const int kBalln = 10;
int ball[kBalln];
bool ExistAsceOrder(int i, int a, int b) {
// 終了条件
if (i == kBalln)
return true;
// ボールiを筒Bに入れる場合
if (a < ball[i] && ExistAsceOrder(i + 1, ball[i], b))
return true;
// ボールiを筒Cに入れる場合
if (b < ball[i] && ExistAsceOrder(i + 1, a, ball[i]))
return true;
// どちらの筒に入れても昇順にならない場合
return false;
}
int main() {
int n;
cin >> n;
for (int j = 0; j < n; ++j) {
for (int i = 0; i < kBalln; ++i) {
cin >> ball[i];
}
if (ExistAsceOrder(0, 0, 0)) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}
|
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 187
|
#include <iostream>
using namespace std;
const int kBalln = 10;
int main() {
int n;
int ball;
int b, c;
bool ans;
cin >> n;
for (int j = 0; j < n; ++j) {
b = 0;
c = 0;
ans = true;
for (int i = 0; i < kBalln; ++i) {
cin >> ball;
if (b < ball) {
b = ball;
} else if (c < ball) {
c = ball;
} else {
// cout << "NO" << endl;
break;
}
}
cout << (ans ? "YES" : "NO") << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
const int kBalln = 10;
int main() {
int n;
int ball;
int b, c;
bool ans;
cin >> n;
for (int j = 0; j < n; ++j) {
b = 0;
c = 0;
ans = true;
for (int i = 0; i < kBalln; ++i) {
cin >> ball;
if (b < ball) {
b = ball;
} else if (c < ball) {
c = ball;
} else {
ans = false;
// cout << "NO" << endl;
// break;
}
}
cout << (ans ? "YES" : "NO") << endl;
}
return 0;
}
|
[["-", 0, 57, 75, 76, 0, 9, 0, 93, 0, 94], ["+", 75, 76, 0, 9, 0, 1, 0, 11, 31, 22], ["+", 75, 76, 0, 9, 0, 1, 0, 11, 17, 32], ["+", 75, 76, 0, 9, 0, 1, 0, 11, 12, 147]]
| 1
| 134
|
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int n;
const int m = 10;
int *data;
int *lp;
int *rp;
// return...fail:0, success:1
bool dfs(int i, int l, int r) {
if (i == m)
return true;
if (i < m && l < m && lp[l - 1] < data[i]) {
lp[l] = data[i];
if (dfs(i + 1, l + 1, r))
return true;
}
if (i < m && r < m && rp[l - 1] < data[i]) {
rp[r] = data[i];
if (dfs(i + 1, l, r + 1))
return true;
}
return false;
}
int main() {
int i, j;
data = (int *)calloc(m, sizeof(int));
lp = (int *)calloc(m, sizeof(int));
rp = (int *)calloc(m, sizeof(int));
scanf("%d ", &n);
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++)
scanf("%d ", &(data[j]));
memset(lp, 0, sizeof(int));
memset(rp, 0, sizeof(int));
lp[0] = data[0];
if (dfs(1, 1, 0))
puts("YES");
else
puts("NO");
/*
//check input
for (j=0; j<m; j++)
printf("%d ", data[j]);
puts("");
*/
}
free(data);
free(lp);
free(rp);
return 0;
}
|
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int n;
const int m = 10;
int *data;
int *lp;
int *rp;
// return...fail:0, success:1
bool dfs(int i, int l, int r) {
if (i == m)
return true;
if (i < m && l < m && lp[l - 1] < data[i]) {
lp[l] = data[i];
if (dfs(i + 1, l + 1, r))
return true;
}
if (i < m && r < m && rp[r - 1] < data[i]) {
rp[r] = data[i];
if (dfs(i + 1, l, r + 1))
return true;
}
return false;
}
int main() {
int i, j;
data = (int *)calloc(m, sizeof(int));
lp = (int *)calloc(m, sizeof(int));
rp = (int *)calloc(m, sizeof(int));
scanf("%d ", &n);
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++)
scanf("%d ", &(data[j]));
memset(lp, 0, sizeof(int));
memset(rp, 0, sizeof(int));
lp[0] = data[0];
if (dfs(1, 1, 0))
puts("YES");
else
puts("NO");
/*
//check input
for (j=0; j<m; j++)
printf("%d ", data[j]);
puts("");
*/
}
free(data);
free(lp);
free(rp);
return 0;
}
|
[["-", 12, 16, 31, 69, 341, 342, 0, 16, 31, 22], ["+", 12, 16, 31, 69, 341, 342, 0, 16, 31, 22]]
| 1
| 351
|
#include <iostream>
using namespace std;
int main(void) {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int a[10] = {0};
for (int j = 0; j < 10; j++) {
int x;
cin >> x;
a[j] = x;
}
int b = a[0], c = a[0], k;
for (k = 1; k < 10; k++) {
if (b < a[k])
b = a[k];
else if (c < a[k])
c = a[k];
else {
cout << "NO" << endl;
break;
}
}
if (k == 10)
cout << "YES" << endl;
/*for(int i=0;i<10;i++)
{
cout<<b[i]<<" ";
}
cout<<endl;
for(int i=0;i<10;i++)
{
cout<<c[i]<<" ";
}
for(int i=0;i<10-1;i++)
{
if(b[i]>b[i+1] && b[i+1]!=0 || c[i]>c[i+1] && c[i+1]!=0)
{
cout<<"NO"<<endl;
break;
}
else
{
cout<<"YES"<<endl;
break;
}
}*/
}
return 0;
}
|
#include <iostream>
using namespace std;
int main(void) {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int a[10] = {0};
for (int j = 0; j < 10; j++) {
int x;
cin >> x;
a[j] = x;
}
int b = 0, c = 0, k;
for (k = 1; k < 10; k++) {
if (b < a[k])
b = a[k];
else if (c < a[k])
c = a[k];
else {
cout << "NO" << endl;
break;
}
}
if (k == 10)
cout << "YES" << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 43, 49, 50, 51, 69, 28, 22], ["-", 0, 43, 49, 50, 51, 69, 341, 342, 0, 70], ["-", 0, 43, 49, 50, 51, 69, 341, 342, 0, 73]]
| 1
| 172
|
#include <iostream>
using namespace std;
int main() {
int a[10], b[11], c[11];
int n;
cin >> n;
for (int jjj = 1; jjj <= n; jjj++) {
for (int kk = 0; kk < 10; kk++)
cin >> a[kk];
int bb = 0, cc = 0;
b[0] = 0;
c[0] = 0;
for (int k = 0; k < 10; k++) {
if (a[k] > b[bb] && b[bb] >= c[cc]) {
b[bb + 1] = a[k];
bb = bb + 1;
} else {
c[cc + 1] = a[k];
cc = cc + 1;
}
}
int l = 0, m = 0;
for (int i = 1; i < bb; i++) {
if (b[i] - b[i - 1] < 0) {
l = 2;
}
}
for (int j = 1; j < cc; j++) {
if (c[j] - c[j - 1] < 0) {
m = 2;
}
}
if (l + m == 0) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int a[10], b[11], c[11];
int n;
cin >> n;
for (int jjj = 1; jjj <= n; jjj++) {
for (int kk = 0; kk < 10; kk++)
cin >> a[kk];
int bb = 0, cc = 0;
b[0] = 0;
c[0] = 0;
for (int k = 0; k < 10; k++) {
if (a[k] > b[bb] && b[bb] >= c[cc]) {
b[bb + 1] = a[k];
bb = bb + 1;
} else {
c[cc + 1] = a[k];
cc = cc + 1;
}
}
int l = 0, m = 0;
for (int i = 1; i <= bb; i++) {
if (b[i] - b[i - 1] < 0) {
l = 2;
}
}
for (int j = 1; j <= cc; j++) {
if (c[j] - c[j - 1] < 0) {
m = 2;
}
}
if (l + m == 0) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}
|
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19]]
| 1
| 291
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int N, acnt, bcnt;
int x[10], A[10], B[10];
bool dfs(int cnt) {
if (cnt == 10)
return true;
// Aに入れる
if (A[acnt] < x[cnt]) {
A[++acnt] = x[cnt];
return dfs(cnt + 1);
}
// Bに入れる
else if (B[acnt] < x[cnt]) {
B[++bcnt] = x[cnt];
return dfs(cnt + 1);
}
return false;
}
int main(void) {
cin >> N;
for (int i = 0; i < N; i++) {
for (int j = 0; j < 10; j++) {
A[j] = 0;
B[j] = 0;
}
acnt = 0;
bcnt = 0;
for (int j = 0; j < 10; j++)
cin >> x[j];
if (dfs(0))
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int N, acnt, bcnt;
int x[10], A[10], B[10];
bool dfs(int cnt) {
if (cnt == 10)
return true;
// Aに入れる
if (A[acnt] < x[cnt]) {
A[++acnt] = x[cnt];
return dfs(cnt + 1);
}
// Bに入れる
else if (B[bcnt] < x[cnt]) {
B[++bcnt] = x[cnt];
return dfs(cnt + 1);
}
return false;
}
int main(void) {
cin >> N;
for (int i = 0; i < N; i++) {
for (int j = 0; j < 10; j++) {
A[j] = 0;
B[j] = 0;
}
acnt = 0;
bcnt = 0;
for (int j = 0; j < 10; j++)
cin >> x[j];
if (dfs(0))
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
|
[["-", 15, 339, 51, 16, 31, 69, 341, 342, 0, 22], ["+", 15, 339, 51, 16, 31, 69, 341, 342, 0, 22]]
| 1
| 257
|
n=gets.to_i
n.times do
ab,ac=[],[]
balls=split(/\s/).map(&:to_i)
balls.each do |inb|
if ab.size==0||ab.last<inb
ab << inb
else
(ac.size>0&&ac.last>inb) ? break : ac << inb
end
end
puts ((ab.size+ac.size)==10) ? 'YES' : 'NO'
end
|
n=gets.to_i
n.times do
ab,ac=[],[]
balls=gets.split(/\s/).map(&:to_i)
balls.each do |inb|
if ab.size==0||ab.last<inb
ab << inb
else
(ac.size>0&&ac.last>inb) ? break : ac << inb
end
end
puts ((ab.size+ac.size)==10) ? 'YES' : 'NO'
end
|
[["+", 8, 736, 0, 662, 12, 652, 486, 652, 486, 22], ["+", 8, 736, 0, 662, 12, 652, 486, 652, 17, 131]]
| 4
| 99
|
n = readline.chomp.to_i
n.times{
v = readline.chomp.split.map{|c| c.to_i}
stack1 = [0]
stack2 = [0]
v.each{|c|
if stack1[-1] > stack2[-1]
if stack1[-1] < c
stack1.push(c)
elsif stack2[-1] < c
stack2.push(c)
else
puts "NO"
break
end
else
if stack2[-1] < c
stack2.push(c)
elsif stack1[-1] < c
stack1.push(c)
else
puts "NO"
break
end
end
}
if stack1.size + stack2.size == 12
puts "YES"
end
p stack1
p stack2
}
|
n = readline.chomp.to_i
n.times{
v = readline.chomp.split.map{|c| c.to_i}
# (1..10).to_a.permutation{|v|
# p v
stack1 = [0]
stack2 = [0]
v.each{|c|
# if stack1[-1] < c
# stack1.push(c)
# elsif stack2[-1] < c
# stack2.push(c)
# else
# puts "NO"
# break
# end
if stack1[-1] > stack2[-1]
if stack1[-1] < c
stack1.push(c)
elsif stack2[-1] < c
stack2.push(c)
else
puts "NO"
break
end
else
if stack2[-1] < c
stack2.push(c)
elsif stack1[-1] < c
stack1.push(c)
else
puts "NO"
break
end
end
}
if stack1.size + stack2.size == 12
puts "YES"
end
# p stack1
# p stack2
}
|
[["-", 0, 652, 196, 196, 8, 734, 0, 652, 735, 22], ["-", 196, 196, 8, 734, 0, 652, 3, 4, 0, 22]]
| 4
| 150
|
n = gets.chomp.to_i
n.times do
balls = gets.chomp.split.map(&:to_i)
a,b = 0,0
10.times do |i|
if balls[i] > a || balls[i] > b
if balls[i] < a
b = balls[i]
elsif balls[i] < b
a = balls[i]
elsif balls[i] > a && balls[i] > b
if a > b
a = balls[i]
else
b = balls[i]
end
end
else
puts "NO"
break
end
print a,b
puts ""
puts "YES" if i == 9
end
end
|
n = gets.chomp.to_i
n.times do
balls = gets.chomp.split.map(&:to_i)
a,b = 0,0
10.times do |i|
if balls[i] > a || balls[i] > b
if balls[i] < a
b = balls[i]
elsif balls[i] < b
a = balls[i]
elsif balls[i] > a && balls[i] > b
if a > b
a = balls[i]
else
b = balls[i]
end
end
else
puts "NO"
break
end
puts "YES" if i == 9
end
end
|
[["-", 0, 652, 196, 737, 8, 736, 0, 652, 735, 22], ["-", 196, 737, 8, 736, 0, 652, 3, 4, 0, 22], ["-", 196, 737, 8, 736, 0, 652, 3, 4, 0, 21], ["-", 8, 736, 0, 652, 3, 4, 0, 557, 0, 62], ["-", 196, 737, 8, 736, 0, 751, 8, 652, 735, 22]]
| 4
| 135
|
n=int(input())
for i in range(n):
a=list(map(int,input().aplit()))
b,c=0,0
yes = True
for j in range(10):
if a[j]>b:b=a[j]
elif a[j]>c:c=a[j]
else:yes=False
print("YES" if yes else "NO")
|
n=int(input())
for i in range(n):
a=list(map(int,input().split()))
b,c=0,0
yes = True
for j in range(10):
if a[j]>b:b=a[j]
elif a[j]>c:c=a[j]
else:yes=False
print("YES" if yes else "NO")
|
[["-", 0, 652, 3, 4, 0, 652, 63, 319, 319, 22], ["+", 0, 652, 3, 4, 0, 652, 63, 319, 319, 22]]
| 5
| 96
|
def s(a):
for i in a:
if i > b:
b = i
elif i > c:
c = i
else:
return False
return True
for n in range(int(input())):
print("YES" if s(list(map(int,input().split()))) else "NO")
|
def s(a):
b = c = 0
for i in a:
if i > b:
b = i
elif i > c:
c = i
else:
return False
return True
for n in range(int(input())):
print("YES" if s(list(map(int,input().split()))) else "NO")
|
[["+", 0, 14, 8, 196, 0, 1, 0, 662, 31, 22], ["+", 0, 14, 8, 196, 0, 1, 0, 662, 0, 32], ["+", 8, 196, 0, 1, 0, 662, 12, 662, 31, 22], ["+", 8, 196, 0, 1, 0, 662, 12, 662, 0, 32], ["+", 8, 196, 0, 1, 0, 662, 12, 662, 12, 612]]
| 5
| 75
|
def check(x):
a, b = 0, 0
for ball in x:
if a > ball:
a = ball
elif b > ball:
b = ball
else:
return False
return True
n = int(input())
for i in range(n):
all = list(map(int, input().split()))
print("YES" if check(all) else "NO")
|
def check(x):
a, b = 0, 0
for ball in x:
if a < ball:
a = ball
elif b < ball:
b = ball
else:
return False
return True
n = int(input())
for i in range(n):
all = list(map(int, input().split()))
print("YES" if check(all) else "NO")
|
[["-", 0, 7, 8, 196, 0, 57, 15, 666, 667, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 666, 667, 18], ["-", 8, 196, 0, 57, 75, 665, 15, 666, 667, 47], ["+", 8, 196, 0, 57, 75, 665, 15, 666, 667, 18]]
| 5
| 88
|
# -*- coding: utf-8 -*-
n = int(input())
for i in range(n):
A, B, C = [], [0], [0]
A = list(map(int, input().split()))
for i in range(10):
if A[i] > B[0]:
B.insert(0, num[i])
elif A[i] > C[0]:
C.insert(0, num[i])
else:
break
if len(A) + len(B) == 12:
print("YES")
else:
print("NO")
|
# -*- coding: utf-8 -*-
n = int(input())
for i in range(n):
A, B, C = [], [0], [0]
A = list(map(int, input().split()))
for i in range(10):
if A[i] > B[0]:
B.insert(0, A[i])
elif A[i] > C[0]:
C.insert(0, A[i])
else:
break
if len(B) + len(C) == 12:
print("YES")
else:
print("NO")
|
[["-", 0, 1, 0, 652, 3, 4, 0, 206, 51, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 206, 51, 22], ["-", 15, 666, 0, 657, 31, 652, 3, 4, 0, 22], ["+", 15, 666, 0, 657, 31, 652, 3, 4, 0, 22], ["-", 15, 666, 0, 657, 12, 652, 3, 4, 0, 22], ["+", 15, 666, 0, 657, 12, 652, 3, 4, 0, 22]]
| 5
| 132
|
def solve(n,left,right):
if n==10:
return 1
if a[n]>left:
return solve(n+1,a[n],right)
if a[n]>right:
return solve(n+1,left,a[n])
return 0
n=int(input())
for _ in range(n):
a=[int(i) for i in input().split()]
print("YES" if solve(10,0,0) else "NO")
|
def solve(n,left,right):
if n==10:
return 1
if a[n]>left:
return solve(n+1,a[n],right)
if a[n]>right:
return solve(n+1,left,a[n])
return 0
n=int(input())
for _ in range(n):
a=[int(i) for i in input().split()]
print("YES" if solve(0,0,0) else "NO")
|
[["-", 3, 4, 0, 41, 0, 652, 3, 4, 0, 612], ["+", 3, 4, 0, 41, 0, 652, 3, 4, 0, 612]]
| 5
| 116
|
def main():
n = int(input())
for i in range(n):
Ball = map(int,input().split())
l = r = 0
for value in Ball:
if value > r:
r = value
elif value > l:
l = value
else:
print("NO")
r = -777
break
if r < l:
r,l = l,r
if r == -777:
continue
else:
print("Yes")
if __name__ == '__main__':
main()
|
def main():
n = int(input())
for i in range(n):
Ball = map(int,input().split())
l = r = 0
for value in Ball:
if value > r:
r = value
elif value > l:
l = value
else:
print("NO")
r = -777
break
if r < l:
r,l = l,r
if r == -777:
continue
else:
print("YES")
if __name__ == '__main__':
main()
|
[["-", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6]]
| 5
| 111
|
x=int(input())
for _ in range(x):
num=list(map(int,input().split()))
b,c=0,0
flag=True
for i in num:
if b<i:
b=i
elif c<i:
c=i
else:
print("No")
flag=False
break
if flag:
print("YES")
|
x=int(input())
for _ in range(x):
num=list(map(int,input().split()))
b,c=0,0
flag=True
for i in num:
if b<i:
b=i
elif c<i:
c=i
else:
print("NO")
flag=False
break
if flag:
print("YES")
|
[["-", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6]]
| 5
| 85
|
#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;
int rail[11], railal = 0, sp[2];
double c1, c2, t;
int main(void) {
int a;
while (~scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &rail[1], &rail[2],
&rail[3], &rail[4], &rail[5], &rail[6], &rail[7], &rail[8],
&rail[9], &rail[10], &sp[0], &sp[1])) {
railal = 0;
for (a = 1; a <= 10; a++)
railal += rail[a];
c1 = (double)sp[0] / 3600;
c2 = (double)sp[1] / 3600;
for (a = 1; a <= 10; a++) {
t += (double)rail[a] / c1;
if ((double)t * (sp[0] + sp[1]) / 3600 >= railal) {
cout << a << endl;
break;
}
}
}
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;
int rail[11], railal = 0, sp[2];
double c1, c2, t;
int main(void) {
int a;
while (~scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &rail[1], &rail[2],
&rail[3], &rail[4], &rail[5], &rail[6], &rail[7], &rail[8],
&rail[9], &rail[10], &sp[0], &sp[1])) {
railal = 0;
t = 0;
for (a = 1; a <= 10; a++)
railal += rail[a];
c1 = (double)sp[0] / 3600;
c2 = (double)sp[1] / 3600;
for (a = 1; a <= 10; a++) {
t += (double)rail[a] / c1;
if ((double)t * (sp[0] + sp[1]) / 3600 >= railal) {
cout << a << endl;
break;
}
}
}
return 0;
}
|
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 1
| 281
|
#include <cstdio>
using namespace std;
int main(void) {
int ku[11], i, ans = 0;
float v1, v2, zen = 0, hit;
while ((scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%f,%f", &ku[1], &ku[2], &ku[3],
&ku[4], &ku[5], &ku[6], &ku[7], &ku[8], &ku[9], &ku[10], &v1,
&v2)) != EOF) {
for (i = 1; i < 10; i++)
zen += ku[i];
hit = zen / (v1 + v2) * v1;
for (i = 1; i < 10; i++) {
ans += ku[i];
if (ans >= hit) {
printf("%d\n", i);
break;
}
}
zen = 0;
ans = 0;
}
return 0;
}
|
#include <cstdio>
using namespace std;
int main(void) {
int ku[11], i, ans = 0;
float v1, v2, zen = 0, hit;
while ((scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%f,%f", &ku[1], &ku[2], &ku[3],
&ku[4], &ku[5], &ku[6], &ku[7], &ku[8], &ku[9], &ku[10], &v1,
&v2)) != EOF) {
for (i = 1; i <= 10; i++)
zen += ku[i];
hit = zen / (v1 + v2) * v1;
for (i = 1; i <= 10; i++) {
ans += ku[i];
if (ans >= hit) {
printf("%d\n", i);
break;
}
}
zen = 0;
ans = 0;
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
| 1
| 202
|
#include <cstdio>
#include <iostream>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
double v1, v2;
int l[10];
while (~scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%lf,%lf", &l[0], &l[1], &l[2],
&l[3], &l[4], &l[5], &l[6], &l[7], &l[8], &l[9], &v1, &v2)) {
double sum = 0;
rep(i, 10) { sum += l[i]; }
double sum2 = 0;
v1 = (v1 / (v1 + v2)) * sum;
rep(i, 10) {
sum2 += l[i];
if (v1 < sum2) {
cout << i << endl;
break;
}
}
}
return 0;
}
|
#include <cstdio>
#include <iostream>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
double v1, v2;
int l[10];
while (~scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%lf,%lf", &l[0], &l[1], &l[2],
&l[3], &l[4], &l[5], &l[6], &l[7], &l[8], &l[9], &v1, &v2)) {
double sum = 0;
rep(i, 10) { sum += l[i]; }
double sum2 = 0;
v1 = (v1 / (v1 + v2)) * sum;
rep(i, 10) {
sum2 += l[i];
if (v1 <= sum2) {
cout << i + 1 << endl;
break;
}
}
}
return 0;
}
|
[["-", 0, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 0, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
| 1
| 186
|
#include <cstdio>
#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
int l[10];
int v1, v2;
int L;
while (scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &l[0], &l[1], &l[2],
&l[3], &l[4], &l[5], &l[6], &l[7], &l[8], &l[9], &v1,
&v2) != EOF) {
for (int i = 0; i < 9; i++) {
L += l[i];
}
double d;
d = (double)L * v1 / (v1 + v2);
L = 0;
for (int i = 0; i < 10; i++) {
L += l[i];
if (d <= L) {
printf("%d\n", i + 1);
break;
}
}
}
return 0;
}
|
#include <cstdio>
#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
int l[10];
int v1, v2;
int L;
while (scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &l[0], &l[1], &l[2],
&l[3], &l[4], &l[5], &l[6], &l[7], &l[8], &l[9], &v1,
&v2) != EOF) {
L = 0;
for (int i = 0; i < 10; i++) {
L += l[i];
}
double d;
d = (double)L * v1 / (v1 + v2);
L = 0;
for (int i = 0; i < 10; i++) {
L += l[i];
if (d <= L) {
printf("%d\n", i + 1);
break;
}
}
}
return 0;
}
|
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13]]
| 1
| 208
|
#include <iostream>
#include <vector>
using namespace std;
#define loop(i, a, b) for (int i = (a); i < int(b); i++)
#define rep(i, b) loop(i, 0, b)
int main() {
vector<int> l(10);
vector<int> v(2);
char c;
while (cin >> l[0]) {
rep(i, 9) cin >> c >> l[i + 1];
rep(i, 2) cin >> c >> v[i];
double sum = 0, sum2 = 0, sum3 = 0;
rep(i, l.size()) sum += l[i];
rep(i, v.size()) sum2 += v[i];
rep(i, l.size()) {
sum3 += l[i];
if (sum3 / sum > v[0] / sum2) {
cout << i + 1 << endl;
break;
}
}
}
}
|
#include <iostream>
#include <vector>
using namespace std;
#define loop(i, a, b) for (int i = (a); i < int(b); i++)
#define rep(i, b) loop(i, 0, b)
int main() {
vector<double> l(10);
vector<double> v(2);
char c;
while (cin >> l[0]) {
rep(i, 9) cin >> c >> l[i + 1];
rep(i, 2) cin >> c >> v[i];
double sum = 0, sum2 = 0, sum3 = 0;
rep(i, l.size()) sum += l[i];
rep(i, v.size()) sum2 += v[i];
rep(i, l.size()) {
sum3 += l[i];
if (sum3 / sum >= v[0] / sum2) {
cout << i + 1 << endl;
break;
}
}
}
}
|
[["-", 0, 43, 39, 344, 3, 347, 0, 77, 39, 40], ["+", 0, 43, 39, 344, 3, 347, 0, 77, 39, 40], ["-", 0, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 0, 9, 0, 57, 15, 339, 51, 16, 17, 20]]
| 1
| 188
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <istream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define vci vector<int>
#define vcs vector<string>
#define pb push_back
#define sz size()
#define mapii map<int, int>
#define mapci map<char, int>
#define mapsi map<string, int>
#define all(x) x.begin(), x.end()
#define minit(a, i) memset(a, i, sizeof(a));
#define for_(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define for_d(i, a, b) for (int i = (int)a - 1; i >= b; i--)
#define for_r(i, a, b, c) for (int i = (int)a; i < (int)b; i += c)
#define for_dr(i, a, b, c) for (int i = (int)a - 1; i >= b; i -= c)
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
typedef long long ll;
const int iINF = 2147483647;
const ll lINF = 9223372036854775807;
template <class T> inline void dbg(T t) { cout << t << endl; }
#define MAX 10
int main() {
vci dist(MAX);
int vi, vj;
char c;
while (cin >> dist[0]) {
for_(i, 1, MAX) {
int d;
cin >> c >> d;
dist[i] = dist[i - 1] + d;
}
cin >> c >> vi >> c >> vj;
double lb = 0.0, rb = (double)dist[MAX - 1] / (double)max(vi, vj);
while (rb - lb > 1e-9) {
double mb = (lb + rb) / 2.;
double pi = (double)vi * mb, pj = (double)dist[MAX - 1] - (double)vj * mb;
if (pi == pj) {
lb = mb;
break;
}
if (pi < pj)
lb = mb;
else
rb = mb;
}
double p = vi * lb;
for_(i, 0, MAX) if (dist[i] > p) {
cout << i + 1 << endl;
break;
}
}
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <istream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define vci vector<int>
#define vcs vector<string>
#define pb push_back
#define sz size()
#define mapii map<int, int>
#define mapci map<char, int>
#define mapsi map<string, int>
#define all(x) x.begin(), x.end()
#define minit(a, i) memset(a, i, sizeof(a));
#define for_(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define for_d(i, a, b) for (int i = (int)a - 1; i >= b; i--)
#define for_r(i, a, b, c) for (int i = (int)a; i < (int)b; i += c)
#define for_dr(i, a, b, c) for (int i = (int)a - 1; i >= b; i -= c)
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
typedef long long ll;
const int iINF = 2147483647;
const ll lINF = 9223372036854775807;
template <class T> inline void dbg(T t) { cout << t << endl; }
#define MAX 10
int main() {
vci dist(MAX);
int vi, vj;
char c;
while (cin >> dist[0]) {
for_(i, 1, MAX) {
int d;
cin >> c >> d;
dist[i] = dist[i - 1] + d;
}
cin >> c >> vi >> c >> vj;
double lb = 0.0, rb = (double)dist[MAX - 1] / (double)max(vi, vj);
while (rb - lb > 1e-9) {
double mb = (lb + rb) / 2.;
double pi = (double)vi * mb, pj = (double)dist[MAX - 1] - (double)vj * mb;
if (pi == pj) {
lb = mb;
break;
}
if (pi < pj)
lb = mb;
else
rb = mb;
}
double p = vi * lb;
for_(i, 0, MAX) if ((double)dist[i] >= p) {
cout << i + 1 << endl;
break;
}
}
return 0;
}
|
[["+", 0, 57, 15, 339, 51, 16, 31, 74, 0, 24], ["+", 15, 339, 51, 16, 31, 74, 39, 77, 39, 40], ["+", 0, 57, 15, 339, 51, 16, 31, 74, 0, 25], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20]]
| 1
| 385
|
while line=gets
line=line.chomp.split(",").map{|s| s.to_i}
length=(0..9).map{|i| line[0..i].inject{|sum,j| sum+j}}
v1=line[10]
v2=line[11]
p=length[9]*v1/(v1+v2).to_f
p p
10.times{|i|
if p<=length[i] then
puts i+1
break
end
}
end
|
while line=gets
line=line.chomp.split(",").map{|s| s.to_i}
length=(0..9).map{|i| line[0..i].inject{|sum,j| sum+j}}
v1=line[10]
v2=line[11]
p=length[9]*v1/(v1+v2).to_f
10.times{|i|
if p<=length[i] then
puts i+1
break
end
}
end
|
[["-", 0, 493, 0, 89, 8, 170, 0, 652, 735, 22], ["-", 0, 89, 8, 170, 0, 652, 3, 4, 0, 22]]
| 4
| 111
|
line = $stdin
lines = line.readlines
line.close
lines.each do |l|
arr = l.split(",")
arr_int = arr[0..9].map{|s| s.to_i}
dist_sum = arr_int.reduce(:+)
v1, v2 = arr[10].to_i, arr[11].to_i
meet_t = dist_sum.to_f / (v1.to_f + v2.to_f)
meet_l = meet_t * v1
ans = 0
for i in 0..9 do
ans += arr_int[i]
if ans >= meet_l then
p ans
break
end
end
end
|
line = $stdin
lines = line.readlines
line.close
lines.each do |l|
arr = l.split(",")
arr_int = arr[0..9].map{|s| s.to_i}
dist_sum = arr_int.reduce(:+)
v1, v2 = arr[10].to_i, arr[11].to_i
meet_t = dist_sum.to_f / (v1.to_f + v2.to_f)
meet_l = meet_t * v1
ans = 0
for i in 0..9 do
ans += arr_int[i]
if ans >= meet_l then
p i+1
break
end
end
end
|
[["-", 0, 121, 64, 749, 0, 652, 3, 4, 0, 22], ["+", 64, 749, 0, 652, 3, 4, 0, 738, 31, 22], ["+", 64, 749, 0, 652, 3, 4, 0, 738, 17, 72], ["+", 64, 749, 0, 652, 3, 4, 0, 738, 12, 612]]
| 4
| 118
|
while (list=gets)!=nil
sum=0
list=list.split(",").map{|i|i.to_i}
v1,v2=list[10,11]
for i in 0..9
sum+=list[i]
end
r=v1*sum.quo(v1+v2)
for i in 0..9
r-=list[i]
if r<0
puts i+1
break
end
end
end
|
while (list=gets)!=nil
sum=0
list=list.split(",").map{|i|i.to_i}
v1,v2=list[10,2]
for i in 0..9
sum+=list[i]
end
r=v1*sum.quo(v1+v2)
for i in 0..9
r-=list[i]
if r<=0.0
puts i+1
break
end
end
end
|
[["-", 0, 89, 8, 170, 0, 662, 12, 742, 0, 612], ["+", 0, 89, 8, 170, 0, 662, 12, 742, 0, 612], ["-", 0, 88, 8, 170, 0, 121, 15, 738, 17, 18], ["-", 0, 88, 8, 170, 0, 121, 15, 738, 12, 612], ["+", 0, 88, 8, 170, 0, 121, 15, 738, 17, 19], ["+", 0, 88, 8, 170, 0, 121, 15, 738, 12, 531]]
| 4
| 90
|
while (st=gets) != nil do
st = st.split(',').map! {|x| x=x.to_i}
b = st.pop.to_f
a = st.pop.to_f
sum = 0
i = 0
st.each {|x| sum += x}
a = sum*a/(a+b)
p a
while a>0 do
a -= st.shift
i += 1
end
p i
end
|
while (st=gets) != nil do
st = st.split(',').map! {|x| x=x.to_i}
b = st.pop.to_f
a = st.pop.to_f
sum = 0
i = 0
st.each {|x| sum += x}
a = sum*a/(a+b)
while a>0 do
a -= st.shift
i += 1
end
p i
end
|
[["-", 0, 493, 0, 89, 8, 170, 0, 652, 735, 22], ["-", 0, 89, 8, 170, 0, 652, 3, 4, 0, 22]]
| 4
| 92
|
loop {
t = gets
if t == nil
break
end
t = t.split(",")
dist = []
dist[0] = 0.0
10.times do |i|
dist[i+1] = dist[i] + t[i].to_f
end
v1 = t[10].to_f
v2 = t[11].to_f
v = v1 + v2
d = v1.to_f * dist[10].to_f / v.to_f
10.times do |i|
if dist[i].to_f >= d
puts i
break
end
end
}
|
loop {
t = gets
if t == nil
break
end
t = t.split(",")
dist = []
dist[0] = 0.0
10.times do |i|
dist[i+1] = dist[i] + t[i].to_f
end
v1 = t[10].to_f
v2 = t[11].to_f
v = v1 + v2
d = v1.to_f * dist[10].to_f / v.to_f
11.times do |i|
if dist[i].to_f >= d
puts i
break
end
end
}
|
[["-", 0, 652, 196, 196, 8, 734, 0, 652, 486, 612], ["+", 0, 652, 196, 196, 8, 734, 0, 652, 486, 612]]
| 4
| 116
|
while True:
try:
l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,v1,v2=map(int,input().split(","))
kyo=0
for i in l1,l2,l3,l4,l5,l6,l7,l8,l9,l10:
kyo +=i
v=v1+v2
x=kyo/v
ans=v1*x
flag=0
for j in l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,0:
if ans>0:
ans -=j
flag +=1
print(ans)
else:
print(flag)
break
except:break
|
while True:
try:
l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,v1,v2=map(int,input().split(","))
kyo=0
for i in l1,l2,l3,l4,l5,l6,l7,l8,l9,l10:
kyo +=i
v=v1+v2
x=kyo/v
ans=v1*x
flag=0
for j in l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,0:
if ans>0:
ans -=j
flag +=1
else:
print(flag)
break
except:break
|
[["-", 0, 57, 64, 196, 0, 1, 0, 652, 63, 22], ["-", 64, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 64, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 64, 196, 0, 1, 0, 652, 3, 4, 0, 25]]
| 5
| 141
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
for s in sys.stdin:
print()
d = list(map(float, s.split(",")))
dl,v1,v2 = d[:-2],d[-2],d[-1]
L = sum(dl)
x = L/(1+v2/v1)
m = 0
for i in range(len(dl)):
m += dl[i]
if m >= x: print(i+1); break
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
for s in sys.stdin:
d = list(map(float, s.split(",")))
dl,v1,v2 = d[:-2],d[-2],d[-1]
L = sum(dl)
x = L/(1+v2/v1)
m = 0
for i in range(len(dl)):
m += dl[i]
if m >= x: print(i+1); break
|
[["-", 0, 7, 8, 196, 0, 1, 0, 652, 63, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 25]]
| 5
| 106
|
while True:
try:
l = list(map(int, input().split(',')))
except:
break
d = sum(l[:10]) * l[10] / (l[10] + l[11])
for i in range(10):
if sum(l[:i]) >= d:
break
print(i)
|
while True:
try:
l = list(map(int, input().split(',')))
except:
break
d = sum(l[:10]) * l[10] / (l[10] + l[11])
for i in range(1,11):
if sum(l[:i]) >= d:
break
print(i)
|
[["-", 8, 196, 0, 7, 12, 652, 3, 4, 0, 612], ["+", 8, 196, 0, 7, 12, 652, 3, 4, 0, 612], ["+", 8, 196, 0, 7, 12, 652, 3, 4, 0, 21]]
| 5
| 80
|
while True:
try:
A = list(map(int,input().split(',')))
except EOFError:
break
V1 = A [-2]
V2 = A [-1]
del A [-1]
del A [-1]
for i in range(len(A)):
A [i] *= V1 + V2
point = sum(A) // (V1 + V2) * V1
print(point)
for i in range(len(A)):
if sum(A [0:i + 1]) >= point:
print(i + 1)
break
|
while True:
try:
A = list(map(int,input().split(',')))
except EOFError:
break
V1 = A [-2]
V2 = A [-1]
del A [-1]
del A [-1]
for i in range(len(A)):
A [i] *= V1 + V2
point = sum(A) // (V1 + V2) * V1
for i in range(len(A)):
if sum(A [0:i + 1]) >= point:
print(i + 1)
break
|
[["-", 0, 52, 8, 196, 0, 1, 0, 652, 63, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 25]]
| 5
| 125
|
import sys
for line in sys.stdin:
v = list(map(int, line.split(",")))
k = [sum(v[:i]) for i,j in enumerate(v[:-1])]
l = v[-2]/(v[-1]+v[-2]) * k[-1]
n = [a-l if a-l >= 0 else 1e10 for a in k]
print(n)
print(n.index(min(n)))
|
import sys
for line in sys.stdin:
v = list(map(int, line.split(",")))
k = [sum(v[:i]) for i,j in enumerate(v[:-1])]
l = v[-2]/(v[-1]+v[-2]) * k[-1]
n = [a-l if a-l >= 0 else 1e10 for a in k]
print(n.index(min(n)))
|
[["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 25], ["-", 0, 7, 8, 196, 0, 1, 0, 652, 63, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 0, 652, 3, 4, 0, 652, 63, 319, 500, 22]]
| 5
| 115
|
while True:
try:
inp = list(map(int, input().split(",")))
l = inp[0:10]
l_all = sum(l)
v1 = inp[10]
v2 = inp[11]
l_pass = l_all*v1/(v1 + v2)
for i in range(10):
if sum(l[:i]) >= l_pass:
print(i)
break
except:
break
|
while True:
try:
inp = list(map(int, input().split(",")))
l = inp[0:10]
l_all = sum(l)
v1 = inp[10]
v2 = inp[11]
l_pass = l_all*v1/(v1 + v2)
for i in range(11):
if sum(l[:i]) >= l_pass:
print(i)
break
except:
break
|
[["-", 8, 196, 0, 7, 12, 652, 3, 4, 0, 612], ["+", 8, 196, 0, 7, 12, 652, 3, 4, 0, 612]]
| 5
| 90
|
import sys
for line in sys.stdin.readlines():
line=list(map(int,line.strip().split(",")))
l,v1,v2=line[0:10],line[10],line[11]
dist=(sum(l)+0.0)/(v1+v2+0.0)*v1
for i in range(10):
if sum(l[:i])>=dist:
print(i)
break
|
import sys
for line in sys.stdin.readlines():
line=list(map(int,line.strip().split(",")))
l,v1,v2=line[0:10],line[10],line[11]
dist=(sum(l)+0.0)/(v1+v2+0.0)*v1
for i in range(11):
if sum(l[:i])>=dist:
print(i)
break
|
[["-", 8, 196, 0, 7, 12, 652, 3, 4, 0, 612], ["+", 8, 196, 0, 7, 12, 652, 3, 4, 0, 612]]
| 5
| 102
|
import sys
def solve(l,v1,v2):
dist=sum(l)/(v1+v2)*v1
for i in range(10):
if sum(l[:i])>=dist:
return i
return 0
for line in sys.stdin.readlines():
line=list(map(float,line.strip().split(",")))
l,v1,v2=line[0:10],line[10],line[11]
print(solve(l,v1,v2))
|
import sys
def solve(l,v1,v2):
dist=sum(l)/(v1+v2)*v1
for i in range(11):
if sum(l[:i])>=dist:
return i
return 0
for line in sys.stdin.readlines():
line=list(map(float,line.strip().split(",")))
l,v1,v2=line[:10],line[10],line[11]
print(solve(l,v1,v2))
|
[["-", 8, 196, 0, 7, 12, 652, 3, 4, 0, 612], ["+", 8, 196, 0, 7, 12, 652, 3, 4, 0, 612], ["-", 0, 662, 12, 432, 0, 206, 206, 663, 0, 612]]
| 5
| 116
|
import java.io.*;
import java.math.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class Main {
public static double calc_convex(double l1x, double l1y, double l2x,
double l2y, double p1x, double p1y,
double p2x, double p2y) {
return ((l1x - l2x) * (p1y - l1y) + (l1x - p1x) * (l1y - l2y)) *
((l1x - l2x) * (p2y - l1y) + (l1x - p2x) * (l1y - l2y));
}
public static void check_convec(ArrayList<Double> list) {
double xa, ya, xb, yb, xc, yc, xd, yd, p1, p2;
xa = list.get(0);
ya = list.get(1);
xb = list.get(2);
yb = list.get(3);
xc = list.get(4);
yc = list.get(5);
xd = list.get(6);
yd = list.get(7);
p1 = calc_convex(xa, ya, xc, yc, xb, yb, xd, yd);
p2 = calc_convex(xb, yb, xd, yd, xa, ya, xc, yc);
if (p1 < 0 && p2 < 0)
System.out.println("YES");
else
System.out.println("NO");
}
public static void print_convex(ArrayList<Double> list) {
ArrayList<Double> inp = new ArrayList<Double>();
for (int i = 0; i < list.size() / 8; i++) {
for (int j = 0; j < 8; j++) {
inp.add(list.get(i * 8 + j));
}
check_convec(inp);
inp.clear();
}
}
public static void main(String args[]) throws IOException {
String str;
ArrayList<Double> inp = new ArrayList<Double>();
Scanner scan = new Scanner(System.in);
while (scan.hasNext()) {
str = scan.next();
String[] strAry = new String[str.length()];
strAry = str.split(",");
for (int j = 0; j < strAry.length; j++) {
Pattern p = Pattern.compile("[0-9].[0-9]");
Matcher m = p.matcher(strAry[j]);
if (m.find()) {
double x = Double.parseDouble(m.group(0));
inp.add(x);
}
}
}
print_convex(inp);
}
}
|
import java.io.*;
import java.math.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class Main {
public static double calc_convex(double l1x, double l1y, double l2x,
double l2y, double p1x, double p1y,
double p2x, double p2y) {
return ((l1x - l2x) * (p1y - l1y) + (l1x - p1x) * (l1y - l2y)) *
((l1x - l2x) * (p2y - l1y) + (l1x - p2x) * (l1y - l2y));
}
public static void check_convec(ArrayList<Double> list) {
double xa, ya, xb, yb, xc, yc, xd, yd, p1, p2;
xa = list.get(0);
ya = list.get(1);
xb = list.get(2);
yb = list.get(3);
xc = list.get(4);
yc = list.get(5);
xd = list.get(6);
yd = list.get(7);
p1 = calc_convex(xa, ya, xc, yc, xb, yb, xd, yd);
p2 = calc_convex(xb, yb, xd, yd, xa, ya, xc, yc);
if (p1 < 0 && p2 < 0)
System.out.println("YES");
else
System.out.println("NO");
}
public static void print_convex(ArrayList<Double> list) {
ArrayList<Double> inp = new ArrayList<Double>();
for (int i = 0; i < list.size() / 8; i++) {
for (int j = 0; j < 8; j++) {
inp.add(list.get(i * 8 + j));
}
check_convec(inp);
inp.clear();
}
}
public static void main(String args[]) throws IOException {
String str;
ArrayList<Double> inp = new ArrayList<Double>();
Scanner scan = new Scanner(System.in);
while (scan.hasNext()) {
str = scan.next();
String[] strAry = new String[str.length()];
strAry = str.split(",");
for (int j = 0; j < strAry.length; j++) {
Pattern p = Pattern.compile("-?[0-9]*.[0-9]*");
Matcher m = p.matcher(strAry[j]);
if (m.find()) {
double x = Double.parseDouble(m.group(0));
inp.add(x);
}
}
}
print_convex(inp);
}
}
|
[["-", 49, 200, 51, 492, 3, 4, 0, 5, 0, 491], ["+", 49, 200, 51, 492, 3, 4, 0, 5, 0, 491]]
| 3
| 566
|
#include <stdio.h>
#include <stdlib.h>
int main(void) {
double x0, y0, x1, y1, x2, y2, x3, y3;
while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &x0, &y0, &x1, &y1, &x2, &y2,
&x3, &y3) != EOF) {
if ((x1 - x0) * (y3 - y0) - (x3 - x0) * (y1 - y0) > 0) {
if ((x2 - x1) * (y0 - y1) - (x0 - x1) * (y2 - y1) < 0) {
printf("NO\n");
} else if ((x3 - x2) * (y1 - y2) - (x1 - x2) * (y3 - y2) < 0) {
printf("NO\n");
} else if ((x0 - x3) * (y2 - y3) - (x2 - x3) * (y0 - y3) < 0) {
printf("NO\n");
} else {
printf("YES\n");
}
} else if ((x1 - x0) * (y3 - y0) - (x3 - x0) * (y1 - y0) < 0) {
if ((x2 - x1) * (y0 - y1) - (x0 - x1) * (y2 - y1) < 0) {
printf("NO\n");
} else if ((x3 - x2) * (y1 - y2) - (x1 - x2) * (y3 - y2) > 0) {
printf("NO\n");
} else if ((x0 - x3) * (y2 - y3) - (x2 - x3) * (y0 - y3) > 0) {
printf("NO\n");
} else {
printf("YES\n");
}
} else {
printf("NO\n");
}
}
return 0;
}
|
#include <stdio.h>
#include <stdlib.h>
int main(void) {
double x0, y0, x1, y1, x2, y2, x3, y3;
while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &x0, &y0, &x1, &y1, &x2, &y2,
&x3, &y3) != EOF) {
if ((x1 - x0) * (y3 - y0) - (x3 - x0) * (y1 - y0) > 0) {
if ((x2 - x1) * (y0 - y1) - (x0 - x1) * (y2 - y1) < 0) {
printf("NO\n");
} else if ((x3 - x2) * (y1 - y2) - (x1 - x2) * (y3 - y2) < 0) {
printf("NO\n");
} else if ((x0 - x3) * (y2 - y3) - (x2 - x3) * (y0 - y3) < 0) {
printf("NO\n");
} else {
printf("YES\n");
}
} else if ((x1 - x0) * (y3 - y0) - (x3 - x0) * (y1 - y0) < 0) {
if ((x2 - x1) * (y0 - y1) - (x0 - x1) * (y2 - y1) > 0) {
printf("NO\n");
} else if ((x3 - x2) * (y1 - y2) - (x1 - x2) * (y3 - y2) > 0) {
printf("NO\n");
} else if ((x0 - x3) * (y2 - y3) - (x2 - x3) * (y0 - y3) > 0) {
printf("NO\n");
} else {
printf("YES\n");
}
} else {
printf("NO\n");
}
}
return 0;
}
|
[["-", 64, 9, 0, 57, 15, 23, 0, 16, 17, 18], ["+", 64, 9, 0, 57, 15, 23, 0, 16, 17, 47]]
| 0
| 394
|
#include <math.h>
int main() {
double xa, ya, xb, yb, xc, yc, xd, yd;
while (0 <= scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc,
&yb, &xd, &yd)) {
if (xc == xa) {
if ((xd - xc) * (xb - xc) > 0 ||
(ya - (yd - yb) / (xd - xb) * (xa - xb) - yb) *
(yc - (yd - yb) / (xd - xb) * (xc - xb) - yb) >
0) {
printf("NO\n");
continue;
} else {
printf("YES\n");
continue;
}
}
if (xb == xd) {
if ((xa - xb) * (xc - xb) > 0 ||
(yb - (yc - ya) / (xc - xa) * (xb - xa) - ya) *
(yd - (yc - ya) / (xc - xa) * (xd - xa) - ya) >
0) {
printf("NO\n");
continue;
} else {
printf("YES\n");
continue;
}
}
if ((yb - (yc - ya) / (xc - xa) * (xb - xa) - ya) *
(yd - (yc - ya) / (xc - xa) * (xd - xa) - ya) >
0 ||
(ya - (yd - yb) / (xd - xb) * (xa - xb) - yb) *
(yc - (yd - yb) / (xd - xb) * (xc - xb) - yb) >
0) {
printf("NO\n");
} else {
printf("YES\n");
}
}
return 0;
}
|
#include <math.h>
int main() {
double xa, ya, xb, yb, xc, yc, xd, yd;
while (0 <= scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc,
&yc, &xd, &yd)) {
if (xc == xa) {
if ((xd - xc) * (xb - xc) > 0 ||
(ya - (yd - yb) / (xd - xb) * (xa - xb) - yb) *
(yc - (yd - yb) / (xd - xb) * (xc - xb) - yb) >
0) {
printf("NO\n");
continue;
} else {
printf("YES\n");
continue;
}
}
if (xb == xd) {
if ((xa - xb) * (xc - xb) > 0 ||
(yb - (yc - ya) / (xc - xa) * (xb - xa) - ya) *
(yd - (yc - ya) / (xc - xa) * (xd - xa) - ya) >
0) {
printf("NO\n");
continue;
} else {
printf("YES\n");
continue;
}
}
if ((yb - (yc - ya) / (xc - xa) * (xb - xa) - ya) *
(yd - (yc - ya) / (xc - xa) * (xd - xa) - ya) >
0 ||
(ya - (yd - yb) / (xd - xb) * (xa - xb) - yb) *
(yc - (yd - yb) / (xd - xb) * (xc - xb) - yb) >
0) {
printf("NO\n");
} else {
printf("YES\n");
}
}
return 0;
}
|
[["-", 0, 16, 12, 2, 3, 4, 0, 66, 28, 22], ["+", 0, 16, 12, 2, 3, 4, 0, 66, 28, 22]]
| 0
| 386
|
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define PI 3.14159265358979323
// int calc1(float a,float b,float c,float d,float e,float f,float *x,float *y);
// void quick(int *,long long,long long);
// int comp(char *a,char *b);
int main() {
float xa, ya, xb, yb, xc, yc, xd, yd;
int flag;
while (scanf("%f,%f,%f,%f,%f,%f,%f,%f", &xa, &ya, &xb, &yb, &xc, &yc, &xd,
&yd) != EOF) {
if ((xb - xa) * (yd - ya) - (xd - xa) * (yb - ya) > 0)
flag = 1;
else
flag = -1;
if (((xc - xb) * (ya - yb) - (xa - xb) * (yc - yb)) * flag < 0)
printf("N0\n");
else if (((xd - xc) * (yb - yc) - (xb - xc) * (yd - yc)) * flag < 0)
printf("N0\n");
else if (((xa - xd) * (yc - yd) - (xc - xd) * (ya - yd)) * flag < 0)
printf("N0\n");
else
printf("YES\n");
}
return 0;
}
|
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define PI 3.14159265358979323
// int calc1(float a,float b,float c,float d,float e,float f,float *x,float *y);
// void quick(int *,long long,long long);
// int comp(char *a,char *b);
int main() {
float xa, ya, xb, yb, xc, yc, xd, yd;
int flag;
while (scanf("%f,%f,%f,%f,%f,%f,%f,%f", &xa, &ya, &xb, &yb, &xc, &yc, &xd,
&yd) != EOF) {
if ((xb - xa) * (yd - ya) - (xd - xa) * (yb - ya) > 0)
flag = 1;
else
flag = -1;
if (((xc - xb) * (ya - yb) - (xa - xb) * (yc - yb)) * flag < 0)
printf("NO\n");
else if (((xd - xc) * (yb - yc) - (xb - xc) * (yd - yc)) * flag < 0)
printf("NO\n");
else if (((xa - xd) * (yc - yd) - (xc - xd) * (ya - yd)) * flag < 0)
printf("NO\n");
else
printf("YES\n");
}
return 0;
}
|
[["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 0
| 246
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <utility>
#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 FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
double dist(double x1, double y1, double x2, double y2) {
return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
}
double deg(double a, double b, double c) {
return acos((a * a + b * b - c * c) / (2 * a * b));
}
double calc_deg(double x1, double y1, double x2, double y2, double x3,
double y3) {
double x, y, z;
x = dist(x1, y1, x2, y2);
y = dist(x2, y2, x3, y3);
z = dist(x3, y3, x1, y1);
return deg(x, y, z);
}
int main() {
double x1, y1, x2, y2, x3, y3, x4, y4;
char c;
while (cin >> x1 >> c >> y1 >> c >> x2 >> c >> y2 >> c >> x3 >> c >> y3 >>
c >> x4 >> c >> y4) {
double deg1, deg2, deg3, deg4;
deg1 = calc_deg(x1, y1, x2, y2, x3, y3);
deg2 = calc_deg(x2, y2, x3, y3, x4, y4);
deg3 = calc_deg(x3, y3, x4, y4, x1, y1);
deg4 = calc_deg(x4, y4, x1, y1, x2, y2);
if (abs(deg1 + deg2 + deg3 + deg4 - 2 * M_PI) < 0.00001) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
return 0;
}
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <utility>
#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 FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
double dist(double x1, double y1, double x2, double y2) {
return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
}
double deg(double a, double b, double c) {
return acos((a * a + b * b - c * c) / (2 * a * b));
}
double calc_deg(double x1, double y1, double x2, double y2, double x3,
double y3) {
double x, y, z;
x = dist(x1, y1, x2, y2);
y = dist(x2, y2, x3, y3);
z = dist(x3, y3, x1, y1);
return deg(x, y, z);
}
int main() {
double x1, y1, x2, y2, x3, y3, x4, y4;
char c;
while (cin >> x1 >> c >> y1 >> c >> x2 >> c >> y2 >> c >> x3 >> c >> y3 >>
c >> x4 >> c >> y4) {
double deg1, deg2, deg3, deg4;
deg1 = calc_deg(x1, y1, x2, y2, x3, y3);
deg2 = calc_deg(x2, y2, x3, y3, x4, y4);
deg3 = calc_deg(x3, y3, x4, y4, x1, y1);
deg4 = calc_deg(x4, y4, x1, y1, x2, y2);
if (abs(deg1 + deg2 + deg3 + deg4 - 2 * M_PI) < 0.00001) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}
|
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 464
|
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iostream>
#define EPS 1e-10
#define EQ(a, b) (abs(a - b) < EPS)
#define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))
using namespace std;
typedef complex<double> P;
double cross(P a, P b) { return (a.real() * b.imag() - a.imag() * b.real()); }
int is_intersected_ls(P a1, P a2, P b1, P b2) {
return (cross(a2 - a1, b1 - a1) * cross(a2 - a1, b2 - a1) < EPS) &&
(cross(b2 - b1, a1 - b1) * cross(b2 - b1, a2 - b1) < EPS);
}
int main() {
double ax, ay, bx, by, cx, cy, dx, dy;
while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &ax, &ay, &bx, &by, &cx, &cy,
&dx, &dy) != EOF) {
P a = P(ax, by);
P b = P(bx, by);
P c = P(cx, cy);
P d = P(dx, dy);
if (EQ(is_intersected_ls(a, c, d, b), 0.0))
cout << "NO" << endl;
else
cout << "YES" << endl;
}
return 0;
}
|
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iostream>
#define EPS 1e-10
#define EQ(a, b) (abs(a - b) < EPS)
#define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))
using namespace std;
typedef complex<double> P;
double cross(P a, P b) { return (a.real() * b.imag() - a.imag() * b.real()); }
int is_intersected_ls(P a1, P a2, P b1, P b2) {
return (cross(a2 - a1, b1 - a1) * cross(a2 - a1, b2 - a1) < EPS) &&
(cross(b2 - b1, a1 - b1) * cross(b2 - b1, a2 - b1) < EPS);
}
int main() {
double ax, ay, bx, by, cx, cy, dx, dy;
while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &ax, &ay, &bx, &by, &cx, &cy,
&dx, &dy) != EOF) {
P a = P(ax, ay);
P b = P(bx, by);
P c = P(cx, cy);
P d = P(dx, dy);
if (EQ(is_intersected_ls(a, c, d, b), 0.0))
cout << "NO" << endl;
else
cout << "YES" << endl;
}
return 0;
}
|
[["-", 0, 43, 49, 50, 51, 2, 3, 4, 0, 22], ["+", 0, 43, 49, 50, 51, 2, 3, 4, 0, 22]]
| 1
| 284
|
#include <cstdio>
#include <iostream>
using namespace std;
double isConvex(double xa, double ya, double xb, double yb, double x,
double y) {
double ret;
ret = (xa - xb) * (y - ya) + (ya - yb) * (xa - x);
return ret;
}
int main() {
double xa, ya, xb, yb, xc, yc, xd, yd;
while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc,
&xd, &yd) != EOF) {
// 直線BDと線分ACが交わるか
double bd_ac =
isConvex(xb, yb, xd, yd, xa, ya) * isConvex(xb, yb, xd, yd, xc, yc);
// 直線ACと線分BDが交わるか
double ac_bd =
isConvex(xa, ya, xc, yc, xb, yb) * isConvex(xa, ya, xc, yc, xd, yd);
// bd_acが負またはac_bdが負ならば、交差している
if (bd_ac < 0.0 || ac_bd < 0.0) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}
|
#include <cstdio>
#include <iostream>
using namespace std;
double isConvex(double xa, double ya, double xb, double yb, double x,
double y) {
double ret;
ret = (xa - xb) * (y - ya) + (ya - yb) * (xa - x);
return ret;
}
int main() {
double xa, ya, xb, yb, xc, yc, xd, yd;
while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc,
&xd, &yd) != EOF) {
// 直線BDと線分ACが交わるか
double bd_ac =
isConvex(xb, yb, xd, yd, xa, ya) * isConvex(xb, yb, xd, yd, xc, yc);
// 直線ACと線分BDが交わるか
double ac_bd =
isConvex(xa, ya, xc, yc, xb, yb) * isConvex(xa, ya, xc, yc, xd, yd);
// bd_acが負またはac_bdが負ならば、交差している
if (bd_ac < 0.0 && ac_bd < 0.0) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 106], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 98]]
| 1
| 226
|
#include <iostream>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
struct Point {
Point(double _x, double _y) : x(_x), y(_y) {}
double x;
double y;
};
typedef Point Vector;
bool isConvex(Point &P1, Point &P2, Point &P3) {
Vector V1(P1.x - P2.x, P1.y - P2.y);
Vector V2(P3.x - P2.x, P3.y - P2.y);
return (V1.x * V2.y - V1.y * V2.x) > 0;
}
bool isConvexSquare(Point &P1, Point &P2, Point &P3, Point &P4) {
bool b1 = isConvex(P1, P2, P3);
bool b2 = isConvex(P2, P3, P4);
bool b3 = isConvex(P3, P4, P1);
bool b4 = isConvex(P4, P1, P2);
return (b1 == b2 && b2 == b3 && b3 == b4 && b4 == b1);
}
vector<double> Split(string &line) {
vector<double> vN(8, 0.0);
string::size_type p1 = 0;
string::size_type p2 = line.find(',');
int i = 0;
double v;
while (p1 != string::npos) {
if (p1 == 0)
v = atof(line.substr(0, p2).c_str());
else if (p2 != string::npos)
v = atof(line.substr(p1 + 1, p2 - p1 - 1).c_str());
else
v = atof(line.substr(p1 + 1).c_str());
vN[i] = v;
p1 = p2;
++i;
if (p1 != string::npos)
p2 = line.find(',', p1 + 1);
}
return vN;
}
void getValue(string &line, double *X, double *Y) {
vector<double> vN = Split(line);
X[0] = vN[0];
Y[0] = vN[1];
X[1] = vN[2];
Y[1] = vN[3];
X[2] = vN[4];
Y[2] = vN[5];
X[3] = vN[6];
Y[4] = vN[7];
}
int main() {
double X[4] = {}, Y[4] = {};
string line;
while (cin >> line) {
getValue(line, X, Y);
Point P1(X[0], Y[0]);
Point P2(X[1], Y[1]);
Point P3(X[2], Y[2]);
Point P4(X[3], Y[3]);
if (isConvexSquare(P1, P2, P3, P4))
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}
|
#include <iostream>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
struct Point {
Point(double _x, double _y) : x(_x), y(_y) {}
double x;
double y;
};
typedef Point Vector;
bool isConvex(Point &P1, Point &P2, Point &P3) {
Vector V1(P1.x - P2.x, P1.y - P2.y);
Vector V2(P3.x - P2.x, P3.y - P2.y);
return (V1.x * V2.y - V1.y * V2.x) > 0;
}
bool isConvexSquare(Point &P1, Point &P2, Point &P3, Point &P4) {
bool b1 = isConvex(P1, P2, P3);
bool b2 = isConvex(P2, P3, P4);
bool b3 = isConvex(P3, P4, P1);
bool b4 = isConvex(P4, P1, P2);
return (b1 == b2 && b2 == b3 && b3 == b4 && b4 == b1);
}
vector<double> Split(string &line) {
vector<double> vN(8, 0.0);
string::size_type p1 = 0;
string::size_type p2 = line.find(',');
int i = 0;
double v;
while (p1 != string::npos) {
if (p1 == 0)
v = atof(line.substr(0, p2).c_str());
else if (p2 != string::npos)
v = atof(line.substr(p1 + 1, p2 - p1 - 1).c_str());
else
v = atof(line.substr(p1 + 1).c_str());
vN[i] = v;
p1 = p2;
++i;
if (p1 != string::npos)
p2 = line.find(',', p1 + 1);
}
return vN;
}
void getValue(string &line, double *X, double *Y) {
vector<double> vN = Split(line);
X[0] = vN[0];
Y[0] = vN[1];
X[1] = vN[2];
Y[1] = vN[3];
X[2] = vN[4];
Y[2] = vN[5];
X[3] = vN[6];
Y[3] = vN[7];
}
int main() {
double X[4] = {}, Y[4] = {};
string line;
while (cin >> line) {
getValue(line, X, Y);
Point P1(X[0], Y[0]);
Point P2(X[1], Y[1]);
Point P3(X[2], Y[2]);
Point P4(X[3], Y[3]);
if (isConvexSquare(P1, P2, P3, P4))
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}
|
[["-", 0, 1, 0, 11, 31, 69, 341, 342, 0, 13], ["+", 0, 1, 0, 11, 31, 69, 341, 342, 0, 13]]
| 1
| 629
|
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for (int i = s; i < (int)n; i++)
#define per(i, n) for (int i = n; i >= 0; i--)
#define ROF(i, s, n) for (int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) \
for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define CLR(a) memset((a), 0, sizeof(a))
#define NCLR(a) memset((a), -1, sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) \
cout << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue<int, vector<int>, greater<int>> minpq;
typedef complex<double> P;
static const double EPS = 1e-10;
static const double PI = acos(-1.0);
static const int mod = 1000000007;
static const int INF = 1 << 30;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = {-1, 0, 1, 0, 1, -1, 1, -1};
static const int dy[] = {0, -1, 0, 1, 1, 1, -1, -1};
bool collision_detection(double x1, double y1, double x2, double y2, double x3,
double y3, double xp, double yp) {
x2 -= x1;
x3 -= x1;
xp -= x1;
y2 -= y1;
y3 -= y1;
yp -= y1;
double t_size = fabs((x2 * y3 - y2 * x3) / 2);
t_size -= fabs((x2 * yp - y2 * xp) / 2);
t_size -= fabs((x3 * yp - y3 * xp) / 2);
x2 -= xp;
x3 -= xp;
y2 -= yp;
y3 -= yp;
yp = xp = 0;
t_size -= fabs((x2 * y3 - y2 * x3) / 2);
return fabs(t_size) < 1e-10;
}
int main() {
double x[4], y[4];
while (~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &x[0], &y[0], &x[1], &y[1],
&x[2], &y[2], &x[3], &y[3])) {
bool print_yes = true;
for (int i = 0; i < 4; i++) {
if (collision_detection(x[(i + 1) % 4], y[(i + 1) % 4], x[(i + 2) % 4],
y[(i + 2) % 4], x[(i + 3) % 4], y[(i + 3) % 4],
x[i], y[i])) {
print_yes = false;
break;
}
}
printf("%s\n", !print_yes ? "YES" : "NO");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for (int i = s; i < (int)n; i++)
#define per(i, n) for (int i = n; i >= 0; i--)
#define ROF(i, s, n) for (int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) \
for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define CLR(a) memset((a), 0, sizeof(a))
#define NCLR(a) memset((a), -1, sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) \
cout << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue<int, vector<int>, greater<int>> minpq;
typedef complex<double> P;
static const double EPS = 1e-10;
static const double PI = acos(-1.0);
static const int mod = 1000000007;
static const int INF = 1 << 30;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = {-1, 0, 1, 0, 1, -1, 1, -1};
static const int dy[] = {0, -1, 0, 1, 1, 1, -1, -1};
bool collision_detection(double x1, double y1, double x2, double y2, double x3,
double y3, double xp, double yp) {
x2 -= x1;
x3 -= x1;
xp -= x1;
y2 -= y1;
y3 -= y1;
yp -= y1;
double t_size = fabs((x2 * y3 - y2 * x3) / 2);
t_size -= fabs((x2 * yp - y2 * xp) / 2);
t_size -= fabs((x3 * yp - y3 * xp) / 2);
x2 -= xp;
x3 -= xp;
y2 -= yp;
y3 -= yp;
yp = xp = 0;
t_size -= fabs((x2 * y3 - y2 * x3) / 2);
return fabs(t_size) < 1e-10;
}
int main() {
double x[4], y[4];
while (~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &x[0], &y[0], &x[1], &y[1],
&x[2], &y[2], &x[3], &y[3])) {
bool print_yes = true;
for (int i = 0; i < 4; i++) {
if (collision_detection(x[(i + 1) % 4], y[(i + 1) % 4], x[(i + 2) % 4],
y[(i + 2) % 4], x[(i + 3) % 4], y[(i + 3) % 4],
x[i], y[i])) {
print_yes = false;
break;
}
}
printf("%s\n", print_yes ? "YES" : "NO");
}
return 0;
}
|
[["-", 0, 2, 3, 4, 0, 41, 15, 91, 17, 111]]
| 1
| 665
|
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
double x[4], y[4];
char c;
while (cin >> x[0] >> c >> y[0] >> c >> x[1] >> c >> y[1] >> c >> x[2] >> c >>
y[2] >> c >> x[3] >> c >> y[3]) {
double a[4], b[4];
for (int i = 0; i < 4; i++) {
a[i] = x[(i + 1) % 4] - x[i];
b[i] = y[(i + 1) % 4] - y[i];
}
double c[4];
for (int i = 0; i < 4; i++)
c[i] = a[i] * b[(i + 1) % 4] - a[(i + 1) % 4] * b[i];
int d = 0;
for (int i = 0; i < 4; i++)
if (c[i] > 0.0)
d++;
if (d == 4 or d == 0)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
}
|
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
double x[4], y[4];
char c;
while (cin >> x[0] >> c >> y[0] >> c >> x[1] >> c >> y[1] >> c >> x[2] >> c >>
y[2] >> c >> x[3] >> c >> y[3]) {
double a[4], b[4];
for (int i = 0; i < 4; i++) {
a[i] = x[(i + 1) % 4] - x[i];
b[i] = y[(i + 1) % 4] - y[i];
}
double c[4];
for (int i = 0; i < 4; i++)
c[i] = a[i] * b[(i + 1) % 4] - a[(i + 1) % 4] * b[i];
int d = 0;
for (int i = 0; i < 4; i++)
if (c[i] > 0.0)
d++;
if (d == 4 or d == 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
|
[["-", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 272
|
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iostream>
#include <vector>
#define P complex<double>
using namespace std;
bool cmp_p(const P &a, const P &b) {
return a.real() == b.real() ? a.imag() < b.imag() : a.real() < b.real();
}
double det(P a, P b) { return a.real() * b.imag() - b.real() + a.imag(); }
vector<P> graham_scan(P *ps, int n) {
sort(ps, ps + n, cmp_p);
int k = 0;
vector<P> qs(n * 2);
for (int i = 0; i < n; i++) {
while (k > 1 && det(qs[k - 1] - qs[k - 2], ps[i] - qs[k - 1]) <= 0)
k--;
qs[k++] = ps[i];
}
for (int i = n - 2, t = k; i >= 0; i--) {
while (k > t && det(qs[k - 1] - qs[k - 2], ps[i] - qs[k - 1]) <= 0)
k--;
qs[k++] = ps[i];
}
qs.resize(k - 1);
return qs;
}
P p[4];
double xa, ya, xb, yb, xc, yc, xd, yd;
int main() {
while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc,
&xd, &yd) != -1) {
p[0] = P(xa, ya);
p[1] = P(xb, yb);
p[2] = P(xc, yc);
p[3] = P(xd, yd);
cout << (graham_scan(p, 4).size() == 4 ? "YES" : "NO") << endl;
}
}
|
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iostream>
#include <vector>
#define P complex<double>
using namespace std;
bool cmp_p(const P &a, const P &b) {
return a.real() == b.real() ? a.imag() < b.imag() : a.real() < b.real();
}
double det(P a, P b) { return a.real() * b.imag() - b.real() * a.imag(); }
vector<P> graham_scan(P *ps, int n) {
sort(ps, ps + n, cmp_p);
int k = 0;
vector<P> qs(n * 2);
for (int i = 0; i < n; i++) {
while (k > 1 && det(qs[k - 1] - qs[k - 2], ps[i] - qs[k - 1]) <= 0)
k--;
qs[k++] = ps[i];
}
for (int i = n - 2, t = k; i >= 0; i--) {
while (k > t && det(qs[k - 1] - qs[k - 2], ps[i] - qs[k - 1]) <= 0)
k--;
qs[k++] = ps[i];
}
qs.resize(k - 1);
return qs;
}
P p[4];
double xa, ya, xb, yb, xc, yc, xd, yd;
int main() {
while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc,
&xd, &yd) != -1) {
p[0] = P(xa, ya);
p[1] = P(xb, yb);
p[2] = P(xc, yc);
p[3] = P(xd, yd);
cout << (graham_scan(p, 4).size() == 4 ? "YES" : "NO") << endl;
}
}
|
[["-", 0, 14, 8, 9, 0, 37, 0, 16, 17, 72], ["+", 8, 9, 0, 37, 0, 16, 12, 16, 17, 48]]
| 1
| 440
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <typeinfo>
#include <vector>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(n) rep(i, n)
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;
#define EPS 1e-10
#define equals(a, b) (fabs((a) - (b)) < EPS)
class Point {
public:
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
Point operator+(Point p) { return Point(x + p.x, y + p.y); }
Point operator-(Point p) { return Point(x - p.x, y - p.y); }
Point operator*(double a) { return Point(a * x, a * y); }
Point operator/(double a) { return Point(x / a, y / a); }
double abs() { return sqrt(norm()); }
double norm() { return x * x + y * y; }
bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }
bool operator==(const Point &p) const {
return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
}
};
typedef Point Vector;
double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }
double xa, ya, xb, yb, xc, yc, xd, yd;
char comma;
int main() {
while (cin >> xa >> comma >> ya >> comma >> xb >> comma >> yb >> comma >>
xc >> comma >> yc >> comma >> xd >> comma >> yd) {
Point a(xa, ya);
Point b(xb, yb);
Point c(xc, yc);
Point d(xd, yd);
Vector ab = b - a;
Vector bc = c - b;
Vector cd = d - c;
Vector da = a - d;
if (cross(ab, bc) > EPS) {
//反時計回り
if (cross(bc, cd) > EPS && cross(cd, da) > EPS && cross(da, ab) > EPS) {
cout << "YES" << endl;
continue;
}
} else if (cross(ab, bc) < -EPS) {
//時計回り
if (cross(bc, cd) > -EPS && cross(cd, da) > -EPS &&
cross(da, ab) > -EPS) {
cout << "YES" << endl;
continue;
}
}
cout << "NO" << endl;
}
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <typeinfo>
#include <vector>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(n) rep(i, n)
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;
#define EPS 1e-10
#define equals(a, b) (fabs((a) - (b)) < EPS)
class Point {
public:
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
Point operator+(Point p) { return Point(x + p.x, y + p.y); }
Point operator-(Point p) { return Point(x - p.x, y - p.y); }
Point operator*(double a) { return Point(a * x, a * y); }
Point operator/(double a) { return Point(x / a, y / a); }
double abs() { return sqrt(norm()); }
double norm() { return x * x + y * y; }
bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }
bool operator==(const Point &p) const {
return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
}
};
typedef Point Vector;
double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }
double xa, ya, xb, yb, xc, yc, xd, yd;
char comma;
int main() {
while (cin >> xa >> comma >> ya >> comma >> xb >> comma >> yb >> comma >>
xc >> comma >> yc >> comma >> xd >> comma >> yd) {
Point a(xa, ya);
Point b(xb, yb);
Point c(xc, yc);
Point d(xd, yd);
Vector ab = b - a;
Vector bc = c - b;
Vector cd = d - c;
Vector da = a - d;
if (cross(ab, bc) > EPS) {
//反時計回り
if (cross(bc, cd) > EPS && cross(cd, da) > EPS && cross(da, ab) > EPS) {
cout << "YES" << endl;
continue;
}
} else if (cross(ab, bc) < -EPS) {
//時計回り
if (cross(bc, cd) < -EPS && cross(cd, da) < -EPS &&
cross(da, ab) < -EPS) {
cout << "YES" << endl;
continue;
}
}
cout << "NO" << endl;
}
return 0;
}
|
[["-", 15, 339, 51, 16, 31, 16, 31, 16, 17, 47], ["+", 15, 339, 51, 16, 31, 16, 31, 16, 17, 18], ["-", 15, 339, 51, 16, 31, 16, 12, 16, 17, 47], ["+", 15, 339, 51, 16, 31, 16, 12, 16, 17, 18], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 47], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 18]]
| 1
| 586
|
#include <iostream>
using namespace std;
struct Vector {
double x;
double y;
};
bool is_c_inner(double xa, double ya, double xb, double yb, double xc,
double yc, double xd, double yd) {
Vector ab = Vector{xb - xa, yb - ya};
Vector bc = Vector{xc - xb, yc - yb};
Vector bd = Vector{xd - xb, yd - yb};
Vector dc = Vector{xc - xd, yc - yd};
Vector da = Vector{xa - xd, ya - yd};
Vector ac = Vector{xc - xa, yc - ya};
double cross_product_1 = ab.x * bc.y - ab.y * bc.x;
double cross_product_2 = bd.x * dc.y - bd.y * dc.x;
double cross_product_3 = da.x * ac.y - da.y * ac.x;
return (cross_product_1 >= 0 && cross_product_2 >= 0 &&
cross_product_3 >= 0) ||
(cross_product_1 <= 0 || cross_product_2 <= 0 && cross_product_3 <= 0);
}
int main() {
double xa, ya, xb, yb, xc, yc, xd, yd;
string result;
while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc,
&xd, &yd) != EOF) {
if (is_c_inner(xa, ya, xb, yb, xc, yc, xd, yd) ||
is_c_inner(xb, yb, xc, yc, xd, yd, xa, ya) ||
is_c_inner(xc, yc, xd, yd, xa, ya, xb, yb) ||
is_c_inner(xd, yd, xa, ya, xb, yb, xc, yc)) {
result = "NO"; // no convex
} else {
result = "YES"; // convex
}
cout << result << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
struct Vector {
double x;
double y;
};
bool is_c_inner(double xa, double ya, double xb, double yb, double xc,
double yc, double xd, double yd) {
Vector ab = Vector{xb - xa, yb - ya};
Vector bc = Vector{xc - xb, yc - yb};
Vector bd = Vector{xd - xb, yd - yb};
Vector dc = Vector{xc - xd, yc - yd};
Vector da = Vector{xa - xd, ya - yd};
Vector ac = Vector{xc - xa, yc - ya};
double cross_product_1 = ab.x * bc.y - ab.y * bc.x;
double cross_product_2 = bd.x * dc.y - bd.y * dc.x;
double cross_product_3 = da.x * ac.y - da.y * ac.x;
return (cross_product_1 >= 0 && cross_product_2 >= 0 &&
cross_product_3 >= 0) ||
(cross_product_1 <= 0 && cross_product_2 <= 0 && cross_product_3 <= 0);
}
int main() {
double xa, ya, xb, yb, xc, yc, xd, yd;
string result;
while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc,
&xd, &yd) == 8) {
if (is_c_inner(xa, ya, xb, yb, xc, yc, xd, yd) ||
is_c_inner(xb, yb, xc, yc, xd, yd, xa, ya) ||
is_c_inner(xc, yc, xd, yd, xa, ya, xb, yb) ||
is_c_inner(xd, yd, xa, ya, xb, yb, xc, yc)) {
result = "NO"; // no convex
} else {
result = "YES"; // convex
}
cout << result << endl;
}
return 0;
}
|
[["-", 0, 37, 0, 16, 12, 23, 0, 16, 17, 106], ["+", 0, 16, 12, 23, 0, 16, 31, 16, 17, 98], ["-", 8, 9, 0, 52, 15, 339, 51, 16, 17, 79], ["-", 8, 9, 0, 52, 15, 339, 51, 16, 12, 22], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 60], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 12, 13]]
| 1
| 385
|
#include <stdio.h>
int main(void) {
int in[5] = {0};
while (scanf("%d,", &in[0]) != EOF) {
scanf("%d,%d,%d,%d", &in[1], &in[2], &in[3], &in[4]);
int sort[5] = {0};
int i, j;
int datesu = 0;
for (i = 0; i < 5; i++) {
for (j = datesu - 1; j >= 0; j--) {
if (in[i] > sort[j])
sort[j + 1] = sort[j];
else {
sort[j + 1] = in[i];
break;
}
}
if (j == -1)
sort[0] = in[i];
datesu++;
}
if (sort[0] == sort[3] || sort[1] == sort[4]) {
puts("four card");
} else if (sort[0] == sort[2]) {
if (sort[3] == sort[4])
puts("full house");
else
puts("three card");
} else if (sort[2] == sort[4]) {
if (sort[0] == sort[1])
puts("full house");
else
puts("three house");
} else if (sort[1] == sort[3]) {
puts("three card");
} else if ((sort[0] == sort[1] && sort[2] == sort[3]) ||
(sort[0] == sort[1] && sort[3] == sort[4]) ||
(sort[1] == sort[2] && sort[3] == sort[4])) {
puts("two pair");
} else if (sort[0] == sort[1] || sort[1] == sort[2] || sort[2] == sort[3] ||
sort[3] == sort[4]) {
puts("one pair");
} else if (sort[4] == 1 && sort[3] == 10) {
puts("straight");
} else if (sort[4] - sort[0] == -4) {
puts("straight");
} else
puts("null");
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int in[5] = {0};
while (scanf("%d,", &in[0]) != EOF) {
scanf("%d,%d,%d,%d", &in[1], &in[2], &in[3], &in[4]);
int sort[5] = {0};
int i, j;
int datesu = 0;
for (i = 0; i < 5; i++) {
for (j = datesu - 1; j >= 0; j--) {
if (in[i] > sort[j])
sort[j + 1] = sort[j];
else {
sort[j + 1] = in[i];
break;
}
}
if (j == -1)
sort[0] = in[i];
datesu++;
}
if (sort[0] == sort[3] || sort[1] == sort[4]) {
puts("four card");
} else if (sort[0] == sort[2]) {
if (sort[3] == sort[4])
puts("full house");
else
puts("three card");
} else if (sort[2] == sort[4]) {
if (sort[0] == sort[1])
puts("full house");
else
puts("three card");
} else if (sort[1] == sort[3]) {
puts("three card");
} else if ((sort[0] == sort[1] && sort[2] == sort[3]) ||
(sort[0] == sort[1] && sort[3] == sort[4]) ||
(sort[1] == sort[2] && sort[3] == sort[4])) {
puts("two pair");
} else if (sort[0] == sort[1] || sort[1] == sort[2] || sort[2] == sort[3] ||
sort[3] == sort[4]) {
puts("one pair");
} else if (sort[4] == 1 && sort[3] == 10) {
puts("straight");
} else if (sort[4] - sort[0] == -4) {
puts("straight");
} else
puts("null");
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 0
| 509
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i, n) for (i = 0; i < n; i++)
#define loop(i, a, n) for (i = a; i < n; i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
typedef vector<int> vi;
typedef pair<int, int> pii;
int main(void) {
int i, j;
int a, b, c, d, e;
while (scanf("%d,%d,%d,%d,%d", &a, &b, &c, &d, &e) != EOF) {
vi v(14, 0);
v[a]++;
v[b]++;
v[c]++;
v[d]++;
v[e]++;
bool ans = false;
if (v[1] && v[10] && v[11] && v[12] && v[13]) {
cout << "straight" << endl;
ans = true;
}
rep(i, 10) if (v[i] && v[i + 1] && v[i + 2] && v[i + 3] && v[i + 4]) {
cout << "straight" << endl;
ans = true;
}
if (ans)
continue;
int na = 0, nb = 0, nc = 0;
rep(i, 14) if (v[i] == 2) na++;
else if (v[i] == 3) nb++;
else if (v[i] == 4) nc++;
if (nc)
cout << "four card" << endl;
else if (na && nb)
cout << "full house" << endl;
else if (nb)
cout << "three pair" << endl;
else if (na == 2)
cout << "two pair" << endl;
else if (na)
cout << "one pair" << endl;
else
cout << "null" << endl;
END:;
}
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i, n) for (i = 0; i < n; i++)
#define loop(i, a, n) for (i = a; i < n; i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
typedef vector<int> vi;
typedef pair<int, int> pii;
int main(void) {
int i, j;
int a, b, c, d, e;
while (scanf("%d,%d,%d,%d,%d", &a, &b, &c, &d, &e) != EOF) {
vi v(14, 0);
v[a]++;
v[b]++;
v[c]++;
v[d]++;
v[e]++;
bool ans = false;
if (v[1] && v[10] && v[11] && v[12] && v[13]) {
cout << "straight" << endl;
ans = true;
}
rep(i, 10) if (v[i] && v[i + 1] && v[i + 2] && v[i + 3] && v[i + 4]) {
cout << "straight" << endl;
ans = true;
}
if (ans)
continue;
int na = 0, nb = 0, nc = 0;
rep(i, 14) if (v[i] == 2) na++;
else if (v[i] == 3) nb++;
else if (v[i] == 4) nc++;
if (nc)
cout << "four card" << endl;
else if (na && nb)
cout << "full house" << endl;
else if (nb)
cout << "three card" << endl;
else if (na == 2)
cout << "two pair" << endl;
else if (na)
cout << "one pair" << endl;
else
cout << "null" << endl;
END:;
}
}
|
[["-", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 430
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
int a, b, c, d, e;
char x;
while (cin >> a >> x >> b >> x >> c >> x >> d >> x >> e) {
string ans = "null";
int ta[14] = {0};
ta[a]++, ta[b]++, ta[c]++, ta[d]++, ta[e]++;
int two = 0, three = 0, four = 0;
for (int i = 1; i <= 13; i++) {
if (ta[i] == 2)
two++;
if (ta[i] == 3)
three++;
if (ta[i] == 4)
four++;
}
if (two == 1)
ans = "one pair";
if (two == 2)
ans = "double pair";
if (three == 1)
ans = "three card";
for (int i = 1; i <= 13 - 4; i++)
if (ta[i] == 1 && ta[i + 1] == 1 && ta[i + 2] == 1 && ta[i + 3] == 1 &&
ta[i + 4] == 1)
ans = "straight";
if (ta[10] == 1 && ta[11] == 1 && ta[12] == 1 && ta[13] == 1 && ta[1] == 1)
ans = "straight";
if (two == 1 && three == 1)
ans = "full house";
if (four == 1)
ans = "four card";
cout << ans << endl;
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
int a, b, c, d, e;
char x;
while (cin >> a >> x >> b >> x >> c >> x >> d >> x >> e) {
string ans = "null";
int ta[14] = {0};
ta[a]++, ta[b]++, ta[c]++, ta[d]++, ta[e]++;
int two = 0, three = 0, four = 0;
for (int i = 1; i <= 13; i++) {
if (ta[i] == 2)
two++;
if (ta[i] == 3)
three++;
if (ta[i] == 4)
four++;
}
if (two == 1)
ans = "one pair";
if (two == 2)
ans = "two pair";
if (three == 1)
ans = "three card";
for (int i = 1; i <= 13 - 4; i++)
if (ta[i] == 1 && ta[i + 1] == 1 && ta[i + 2] == 1 && ta[i + 3] == 1 &&
ta[i + 4] == 1)
ans = "straight";
if (ta[10] == 1 && ta[11] == 1 && ta[12] == 1 && ta[13] == 1 && ta[1] == 1)
ans = "straight";
if (two == 1 && three == 1)
ans = "full house";
if (four == 1)
ans = "four card";
cout << ans << endl;
}
return 0;
}
|
[["-", 0, 57, 64, 1, 0, 11, 12, 5, 0, 6], ["+", 0, 57, 64, 1, 0, 11, 12, 5, 0, 6]]
| 1
| 367
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> c(5);
while (~scanf("%d", &c[0])) {
int p = 0;
int tc = 0;
for (int i = 1; i < 5; i++)
scanf(",%d", &c[i]);
sort(c.begin(), c.end());
for (int i = 0; i < 5; i++) {
if (i != 0 && c[i] == c[i - 1])
p++;
if (i != 1 && c[i] == c[i - 2])
tc++;
}
if (p == 1)
puts("one pair");
else if (tc == 1 && p == 3)
puts("full house");
else if (tc && p == 2)
puts("three card");
else if (p == 2)
puts("two pair");
else if (p == 3)
puts("four card");
else if (c[4] - c[0] == 4 || (c[0] == 1 && c[1] == 10 && c[4] == 13))
puts("straght");
else
puts("null");
}
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> c(5);
while (~scanf("%d", &c[0])) {
int p = 0;
int tc = 0;
for (int i = 1; i < 5; i++)
scanf(",%d", &c[i]);
sort(c.begin(), c.end());
for (int i = 0; i < 5; i++) {
if (i != 0 && c[i] == c[i - 1])
p++;
if (i != 1 && c[i] == c[i - 2])
tc++;
}
if (p == 1)
puts("one pair");
else if (tc == 1 && p == 3)
puts("full house");
else if (tc && p == 2)
puts("three card");
else if (p == 2)
puts("two pair");
else if (p == 3)
puts("four card");
else if (c[4] - c[0] == 4 || (c[0] == 1 && c[1] == 10 && c[4] == 13))
puts("straight");
else
puts("null");
}
return 0;
}
|
[["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 1
| 286
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int check(vector<int> v) {
sort(v.begin(), v.end());
// for (int i = 0; i < v.size(); i++)cout << v[i] << " ";
if ((v[0] == v[1] && v[1] == v[2] && v[2] == v[3]) ||
(v[1] == v[2] && v[2] == v[3] && v[3] == v[4])) { // four cards
return 1;
} else if (((v[0] == v[1] && v[1] == v[2]) && (v[3] == v[4])) ||
((v[0] == v[1]) && (v[2] == v[3] && v[3] == v[4]))) { // full house
return 2;
} else if (v[0] == v[1] - 1 && v[0] == v[2] - 2 && v[0] == v[3] - 3 &&
v[0] == v[4] - 4) { // straight
return 3;
} else if (v[0] == 1 && v[1] == 10 && v[2] == 11 && v[3] == 12 &&
v[4] == 13) { // straight
return 3;
} else if (((v[0] == v[1] && v[1] == v[2]) ||
(v[1] == v[2] && v[2] == v[3])) ||
((v[2] == v[3] && v[3] == v[4]))) { // three cards
return 4;
} else if ((v[0] == v[1] && v[2] == v[3]) || (v[0] == v[1] && v[3] == v[4]) ||
(v[1] == v[2] && v[3] == v[4])) { // two pair
return 5;
} else if ((v[0] == v[1]) || (v[1] == v[2]) || (v[2] == v[3]) ||
(v[3] == v[4])) { // one pair
return 6;
} else {
return 7;
}
}
int main() {
vector<int> v;
int a, b, c, d, e;
while (scanf("%d,%d,%d,%d,%d", &a, &b, &c, &d, &e) != EOF) {
v.clear();
v.push_back(a);
v.push_back(b);
v.push_back(c);
v.push_back(d);
v.push_back(e);
switch (check(v)) {
case 1:
cout << "four cards" << endl;
break;
case 2:
cout << "full house" << endl;
break;
case 3:
cout << "straight" << endl;
break;
case 4:
cout << "three card" << endl;
break;
case 5:
cout << "two pair" << endl;
break;
case 6:
cout << "one pair" << endl;
break;
case 7:
cout << "null" << endl;
break;
default:
cout << "Error" << endl;
break;
}
}
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int check(vector<int> v) {
sort(v.begin(), v.end());
// for (int i = 0; i < v.size(); i++)cout << v[i] << " ";
if ((v[0] == v[1] && v[1] == v[2] && v[2] == v[3]) ||
(v[1] == v[2] && v[2] == v[3] && v[3] == v[4])) { // four cards
return 1;
} else if (((v[0] == v[1] && v[1] == v[2]) && (v[3] == v[4])) ||
((v[0] == v[1]) && (v[2] == v[3] && v[3] == v[4]))) { // full house
return 2;
} else if (v[0] == v[1] - 1 && v[0] == v[2] - 2 && v[0] == v[3] - 3 &&
v[0] == v[4] - 4) { // straight
return 3;
} else if (v[0] == 1 && v[1] == 10 && v[2] == 11 && v[3] == 12 &&
v[4] == 13) { // straight
return 3;
} else if (((v[0] == v[1] && v[1] == v[2]) ||
(v[1] == v[2] && v[2] == v[3])) ||
((v[2] == v[3] && v[3] == v[4]))) { // three cards
return 4;
} else if ((v[0] == v[1] && v[2] == v[3]) || (v[0] == v[1] && v[3] == v[4]) ||
(v[1] == v[2] && v[3] == v[4])) { // two pair
return 5;
} else if ((v[0] == v[1]) || (v[1] == v[2]) || (v[2] == v[3]) ||
(v[3] == v[4])) { // one pair
return 6;
} else {
return 7;
}
}
int main() {
vector<int> v;
int a, b, c, d, e;
while (scanf("%d,%d,%d,%d,%d", &a, &b, &c, &d, &e) != EOF) {
v.clear();
v.push_back(a);
v.push_back(b);
v.push_back(c);
v.push_back(d);
v.push_back(e);
switch (check(v)) {
case 1:
cout << "four card" << endl;
break;
case 2:
cout << "full house" << endl;
break;
case 3:
cout << "straight" << endl;
break;
case 4:
cout << "three card" << endl;
break;
case 5:
cout << "two pair" << endl;
break;
case 6:
cout << "one pair" << endl;
break;
case 7:
cout << "null" << endl;
break;
default:
cout << "Error" << endl;
break;
}
}
return 0;
}
|
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 717
|
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <complex>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
typedef complex<double> P;
#define X real()
#define Y imag()
int main() {
int mod = 1000000007;
int ax, ay;
char f[12][12];
int c[5];
while (scanf("%d,%d,%d,%d,%d", &c[0], &c[1], &c[2], &c[3], &c[4]) != EOF) {
vector<int> card(5);
for (int i = 0; i < 5; ++i) {
card[i] = c[i];
}
sort(card.begin(), card.end());
if ((card[1] == card[2] && card[2] == card[3]) &&
(card[0] == card[1] || card[4] == card[3]))
printf("four card\n");
else if ((card[0] == card[1] && card[3] == card[4]) &&
(card[2] == card[1] || card[2] == card[3]))
printf("full house\n");
else if (card[0] == card[1] - 1 && card[1] == card[2] - 1 &&
card[2] == card[3] - 1 && card[3] == card[4] - 1)
printf("straight\n");
else if (card[0] == 1 && card[1] == 10 && card[2] == 11 && card[3] == 12 &&
card[4] == 13)
printf("straight\n");
else if ((card[0] == card[1] && card[1] == card[2]) ||
(card[1] == card[2] && card[2] == card[3]) &&
(card[2] == card[3] && card[3] == card[4]))
printf("three card\n");
else if ((card[0] == card[1] &&
(card[2] == card[3] || card[3] == card[4])) ||
(card[1] == card[2] && card[3] == card[4]))
printf("two pair\n");
else if (card[0] == card[1] || card[1] == card[2] || card[2] == card[3] ||
card[3] == card[4])
printf("one pair\n");
else
printf("null\b");
}
return 0;
}
|
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <complex>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
typedef complex<double> P;
#define X real()
#define Y imag()
int main() {
int mod = 1000000007;
int ax, ay;
char f[12][12];
int c[5];
while (scanf("%d,%d,%d,%d,%d", &c[0], &c[1], &c[2], &c[3], &c[4]) != EOF) {
vector<int> card(5);
for (int i = 0; i < 5; ++i) {
card[i] = c[i];
}
sort(card.begin(), card.end());
if ((card[1] == card[2] && card[2] == card[3]) &&
(card[0] == card[1] || card[4] == card[3]))
printf("four card\n");
else if ((card[0] == card[1] && card[3] == card[4]) &&
(card[2] == card[1] || card[2] == card[3]))
printf("full house\n");
else if (card[0] == card[1] - 1 && card[1] == card[2] - 1 &&
card[2] == card[3] - 1 && card[3] == card[4] - 1)
printf("straight\n");
else if (card[0] == 1 && card[1] == 10 && card[2] == 11 && card[3] == 12 &&
card[4] == 13)
printf("straight\n");
else if ((card[0] == card[1] && card[1] == card[2]) ||
(card[1] == card[2] && card[2] == card[3]) ||
(card[2] == card[3] && card[3] == card[4]))
printf("three card\n");
else if ((card[0] == card[1] &&
(card[2] == card[3] || card[3] == card[4])) ||
(card[1] == card[2] && card[3] == card[4]))
printf("two pair\n");
else if (card[0] == card[1] || card[1] == card[2] || card[2] == card[3] ||
card[3] == card[4])
printf("one pair\n");
else
printf("null\n");
}
return 0;
}
|
[["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 98], ["+", 75, 76, 0, 57, 15, 339, 51, 16, 17, 106], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 1
| 580
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[6] = {};
while (scanf("%d", &a[0]) != EOF) {
for (int i = 1; i < 5; i++)
scanf(",%d", &a[i]);
int cnt = 0, flag = true, card[13] = {}, max = 4;
sort(a, a + 5);
for (int i = 0; i < 4; i++)
for (int j = i + 1; j < 5; j++)
if (a[i] == a[j])
cnt++;
int i = 0;
if (a[i] == 1 && a[i + 1] == 10) {
i = 1;
max = 5;
a[5] = 14;
}
for (; i < max; i++)
if (a[i] + 1 != a[i + 1])
flag = 0;
if (cnt == 6)
printf("four card\n");
else if (cnt == 4)
printf("full house\n");
else if (flag)
printf("straight\n");
else if (cnt == 3)
printf("three card\n");
else if (cnt == 2)
printf("two pir\n");
else if (cnt == 1)
printf("one pair\n");
else
printf("null\n");
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[6] = {};
while (scanf("%d", &a[0]) != EOF) {
for (int i = 1; i < 5; i++)
scanf(",%d", &a[i]);
int cnt = 0, flag = true, card[13] = {}, max = 4;
sort(a, a + 5);
for (int i = 0; i < 4; i++)
for (int j = i + 1; j < 5; j++)
if (a[i] == a[j])
cnt++;
int i = 0;
if (a[i] == 1 && a[i + 1] == 10) {
i = 1;
max = 5;
a[5] = 14;
}
for (; i < max; i++)
if (a[i] + 1 != a[i + 1])
flag = 0;
if (cnt == 6)
printf("four card\n");
else if (cnt == 4)
printf("full house\n");
else if (flag)
printf("straight\n");
else if (cnt == 3)
printf("three card\n");
else if (cnt == 2)
printf("two pair\n");
else if (cnt == 1)
printf("one pair\n");
else
printf("null\n");
}
}
|
[["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 1
| 308
|
#include <algorithm>
#include <cstdio>
using namespace std;
int n[5];
int main() {
while (scanf("%d,%d,%d,%d,%d", &n[0], &n[1], &n[2], &n[3], &n[4]) != EOF) {
sort(n, n + 5);
if ((n[0] == n[1] && n[1] == n[2] && n[2] == n[3]) ||
(n[1] == n[2] && n[2] == n[3] && n[3] == n[4]))
printf("four card\n");
else if ((n[0] == n[1] && n[1] == n[2] && n[3] == n[4]) ||
(n[0] == n[1] && n[2] == n[3] && n[3] == n[4]))
printf("full house\n");
else if ((n[4] == n[3] + 1 && n[3] == n[2] + 1 && n[2] == n[1] + 1 &&
n[1] == n[0] + 1) ||
(n[0] == 10 && n[1] == 11 && n[2] == 12 && n[3] == 13 &&
n[4] == 1))
printf("straight\n");
else if ((n[0] == n[1] && n[1] == n[2]) || (n[1] == n[2] && n[2] == n[3]) ||
(n[2] == n[3] && n[3] == n[4]))
printf("three card\n");
else if ((n[0] == n[1] && n[2] == n[3]) || (n[0] == n[1] && n[3] == n[4]) ||
(n[1] == n[2] && n[3] == n[4]))
printf("two pair\n");
else if (n[0] == n[1] || n[1] == n[2] || n[2] == n[3] || n[3] == n[4])
printf("one pair\n");
else
printf("null\n");
}
return 0;
}
|
#include <algorithm>
#include <cstdio>
using namespace std;
int n[5];
int main() {
while (scanf("%d,%d,%d,%d,%d", &n[0], &n[1], &n[2], &n[3], &n[4]) != EOF) {
sort(n, n + 5);
if ((n[0] == n[1] && n[1] == n[2] && n[2] == n[3]) ||
(n[1] == n[2] && n[2] == n[3] && n[3] == n[4]))
printf("four card\n");
else if ((n[0] == n[1] && n[1] == n[2] && n[3] == n[4]) ||
(n[0] == n[1] && n[2] == n[3] && n[3] == n[4]))
printf("full house\n");
else if ((n[4] == n[3] + 1 && n[3] == n[2] + 1 && n[2] == n[1] + 1 &&
n[1] == n[0] + 1) ||
(n[0] == 1 && n[1] == 10 && n[2] == 11 && n[3] == 12 &&
n[4] == 13))
printf("straight\n");
else if ((n[0] == n[1] && n[1] == n[2]) || (n[1] == n[2] && n[2] == n[3]) ||
(n[2] == n[3] && n[3] == n[4]))
printf("three card\n");
else if ((n[0] == n[1] && n[2] == n[3]) || (n[0] == n[1] && n[3] == n[4]) ||
(n[1] == n[2] && n[3] == n[4]))
printf("two pair\n");
else if (n[0] == n[1] || n[1] == n[2] || n[2] == n[3] || n[3] == n[4])
printf("one pair\n");
else
printf("null\n");
}
return 0;
}
|
[["-", 31, 16, 31, 16, 31, 16, 31, 16, 12, 13], ["+", 31, 16, 31, 16, 31, 16, 31, 16, 12, 13], ["-", 31, 16, 31, 16, 31, 16, 12, 16, 12, 13], ["+", 31, 16, 31, 16, 31, 16, 12, 16, 12, 13], ["-", 0, 16, 31, 16, 31, 16, 12, 16, 12, 13], ["+", 0, 16, 31, 16, 31, 16, 12, 16, 12, 13], ["-", 12, 23, 0, 16, 31, 16, 12, 16, 12, 13], ["+", 12, 23, 0, 16, 31, 16, 12, 16, 12, 13], ["-", 51, 16, 12, 23, 0, 16, 12, 16, 12, 13], ["+", 51, 16, 12, 23, 0, 16, 12, 16, 12, 13]]
| 1
| 536
|
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
int c[5];
while (scanf("%d,%d,%d,%d,%d", &c[0], &c[1], &c[2], &c[3], &c[4]) != EOF) {
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (c[j] > c[j + 1]) {
int tmp = c[j];
c[j] = c[j + 1];
c[j + 1] = tmp;
}
}
}
if ((c[0] == c[1] && c[1] == c[2] && c[2] == c[3]) ||
(c[1] == c[2] && c[2] == c[3] && c[3] == c[4]))
cout << "four cards" << endl;
else if ((c[0] == c[1] && c[1] == c[2] && c[3] == c[4]) ||
(c[0] == c[1] && c[2] == c[3] && c[3] == c[4]))
cout << "full house" << endl;
else if ((c[0] == 1 && c[1] == 10 && c[2] == 11 && c[3] == 12 &&
c[4] == 13) ||
(c[0] + 1 == c[1] && c[0] + 2 == c[2] && c[0] + 3 == c[3] &&
c[0] + 4 == c[4]))
cout << "straight" << endl;
else if ((c[0] == c[1] && c[1] == c[2]) || (c[1] == c[2] && c[2] == c[3]) ||
(c[2] == c[3] && c[3] == c[4]))
cout << "three cards" << endl;
else if ((c[0] == c[1] && c[2] == c[3]) || (c[1] == c[2] && c[3] == c[4]) ||
(c[0] == c[1] && c[3] == c[4]))
cout << "two pair" << endl;
else if ((c[0] == c[1]) || (c[1] == c[2]) || (c[2] == c[3]) ||
(c[3] == c[4]))
cout << "one pair" << endl;
else
cout << "null" << endl;
}
}
|
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
int c[5];
while (scanf("%d,%d,%d,%d,%d", &c[0], &c[1], &c[2], &c[3], &c[4]) != EOF) {
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (c[j] > c[j + 1]) {
int tmp = c[j];
c[j] = c[j + 1];
c[j + 1] = tmp;
}
}
}
if ((c[0] == c[1] && c[1] == c[2] && c[2] == c[3]) ||
(c[1] == c[2] && c[2] == c[3] && c[3] == c[4]))
cout << "four card" << endl;
else if ((c[0] == c[1] && c[1] == c[2] && c[3] == c[4]) ||
(c[0] == c[1] && c[2] == c[3] && c[3] == c[4]))
cout << "full house" << endl;
else if ((c[0] == 1 && c[1] == 10 && c[2] == 11 && c[3] == 12 &&
c[4] == 13) ||
(c[0] + 1 == c[1] && c[0] + 2 == c[2] && c[0] + 3 == c[3] &&
c[0] + 4 == c[4]))
cout << "straight" << endl;
else if ((c[0] == c[1] && c[1] == c[2]) || (c[1] == c[2] && c[2] == c[3]) ||
(c[2] == c[3] && c[3] == c[4]))
cout << "three card" << endl;
else if ((c[0] == c[1] && c[2] == c[3]) || (c[1] == c[2] && c[3] == c[4]) ||
(c[0] == c[1] && c[3] == c[4]))
cout << "two pair" << endl;
else if ((c[0] == c[1]) || (c[1] == c[2]) || (c[2] == c[3]) ||
(c[3] == c[4]))
cout << "one pair" << endl;
else
cout << "null" << endl;
}
}
|
[["-", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 609
|
#include <algorithm>
#include <iostream>
using namespace std;
int main(void) {
int a[5];
char c;
while (cin >> a[0] >> c >> a[1] >> c >> a[2] >> c >> a[3] >> c >> a[4]) {
int b[13] = {};
for (int i = 0; i < 5; ++i)
++b[a[i]];
sort(a, a + 5);
sort(b, b + 13, greater<int>());
if (b[0] == 4 || b[0] == 5)
cout << "four card" << endl;
else if (b[0] == 3 && b[1] == 2)
cout << "full house" << endl;
else if (((a[0] + 1 == a[1]) && (a[1] + 1 == a[2]) && (a[2] + 1 == a[3]) &&
(a[3] + 1 == a[4])) ||
(a[0] == 1 && a[1] == 10 && a[2] == 11 && a[3] == 12 &&
a[4] == 13))
cout << "straight" << endl;
else if (b[0] == 3)
cout << "three card" << endl;
else if (b[0] == 2 && b[1] == 2)
cout << "two pair" << endl;
else if (b[0] == 2)
cout << "one pair" << endl;
else
cout << "null" << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
int main(void) {
int a[5];
char c;
while (cin >> a[0] >> c >> a[1] >> c >> a[2] >> c >> a[3] >> c >> a[4]) {
int b[14] = {};
for (int i = 0; i < 5; ++i)
++b[a[i]];
sort(a, a + 5);
sort(b, b + 14, greater<int>());
if (b[0] == 4 || b[0] == 5)
cout << "four card" << endl;
else if (b[0] == 3 && b[1] == 2)
cout << "full house" << endl;
else if (((a[0] + 1 == a[1]) && (a[1] + 1 == a[2]) && (a[2] + 1 == a[3]) &&
(a[3] + 1 == a[4])) ||
(a[0] == 1 && a[1] == 10 && a[2] == 11 && a[3] == 12 &&
a[4] == 13))
cout << "straight" << endl;
else if (b[0] == 3)
cout << "three card" << endl;
else if (b[0] == 2 && b[1] == 2)
cout << "two pair" << endl;
else if (b[0] == 2)
cout << "one pair" << endl;
else
cout << "null" << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 43, 49, 50, 49, 80, 81, 13], ["+", 8, 9, 0, 43, 49, 50, 49, 80, 81, 13], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
| 1
| 348
|
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define ERASE(v, i) (v).erase(remove(all(v), i), (v).end())
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define each(it, c) \
for (typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define debug(x) cerr << #x << " = " << (x) << endl;
#define LINE cerr << "LINE: " << __LINE__ << endl;
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
template <class T> void preview(T a, T b) {
for (T it = a; it != b; ++it)
cerr << *it << " ";
cerr << endl;
}
const int INF = 100000000;
const double PI = acos(-1.0), EPS = 1e-10;
int main() {
for (string line; cin >> line;) {
rep(i, line.length()) if (line[i] == ',') line[i] = ' ';
istringstream is(line);
vector<int> card(5);
rep(i, 5) is >> card[i];
sort(all(card));
map<int, int> m;
rep(i, 5) m[card[i]]++;
// four cards
{
bool four_card = false;
int two_pair = 0;
bool three_cards = false;
each(it, m) {
if (it->second == 4)
four_card = true;
if (it->second == 3)
three_cards = true;
if (it->second == 2)
two_pair++;
}
bool streat = true;
for (int i = 1; i < 5; i++) {
if (card[i] != card[i - 1] + 1)
streat = false;
}
if (card[0] == 1 && card[1] == 10 && card[2] == 11 && card[3] == 12 &&
card[4] == 13)
streat = true;
string ans;
if (four_card)
ans = "four cards";
else if (three_cards && two_pair)
ans = "full house";
else if (streat)
ans = "straight";
else if (three_cards)
ans = "three card";
else if (two_pair == 2)
ans = "two pair";
else if (two_pair == 1)
ans = "one pair";
else
ans = "null";
cout << ans << endl;
}
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define ERASE(v, i) (v).erase(remove(all(v), i), (v).end())
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define each(it, c) \
for (typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define debug(x) cerr << #x << " = " << (x) << endl;
#define LINE cerr << "LINE: " << __LINE__ << endl;
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
template <class T> void preview(T a, T b) {
for (T it = a; it != b; ++it)
cerr << *it << " ";
cerr << endl;
}
const int INF = 100000000;
const double PI = acos(-1.0), EPS = 1e-10;
int main() {
for (string line; cin >> line;) {
rep(i, line.length()) if (line[i] == ',') line[i] = ' ';
istringstream is(line);
vector<int> card(5);
rep(i, 5) is >> card[i];
sort(all(card));
map<int, int> m;
rep(i, 5) m[card[i]]++;
// four cards
{
bool four_card = false;
int two_pair = 0;
bool three_cards = false;
each(it, m) {
if (it->second == 4)
four_card = true;
if (it->second == 3)
three_cards = true;
if (it->second == 2)
two_pair++;
}
bool streat = true;
for (int i = 1; i < 5; i++) {
if (card[i] != card[i - 1] + 1)
streat = false;
}
if (card[0] == 1 && card[1] == 10 && card[2] == 11 && card[3] == 12 &&
card[4] == 13)
streat = true;
string ans;
if (four_card)
ans = "four card";
else if (three_cards && two_pair)
ans = "full house";
else if (streat)
ans = "straight";
else if (three_cards)
ans = "three card";
else if (two_pair == 2)
ans = "two pair";
else if (two_pair == 1)
ans = "one pair";
else
ans = "null";
cout << ans << endl;
}
}
return 0;
}
|
[["-", 0, 57, 64, 1, 0, 11, 12, 5, 0, 6], ["+", 0, 57, 64, 1, 0, 11, 12, 5, 0, 6]]
| 1
| 557
|
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int straight(int[]);
int main() {
int ans, h[5];
while (scanf("%d,%d,%d,%d,%d", &h[0], &h[1], &h[2], &h[3], &h[4]) != EOF) {
ans = 0;
for (int i = 0; i < 4; i++) {
for (int j = i + 1; j < 5; j++) {
if (h[i] == h[j])
ans++;
}
}
switch (ans) {
case 1:
cout << "one pair" << endl;
break;
case 2:
cout << "two pair" << endl;
break;
case 3:
cout << "three cards" << endl;
break;
case 4:
cout << "full house" << endl;
break;
case 6:
cout << "four cards" << endl;
break;
default:
if (straight(h))
cout << "straight" << endl;
else
cout << "null" << endl;
}
}
return 0;
}
int straight(int h[5]) {
sort(h, h + 5);
for (int i = 0; i < 9; i++) {
if (h[0] == i && h[1] == i + 1 && h[2] == i + 2 && h[3] == i + 3 &&
h[4] == i + 4 ||
h[0] == 1 && h[1] == 10 && h[2] == 11 && h[3] == 12 && h[4] == 13)
return 1;
}
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int straight(int[]);
int main() {
int ans, h[5];
while (scanf("%d,%d,%d,%d,%d", &h[0], &h[1], &h[2], &h[3], &h[4]) != EOF) {
ans = 0;
for (int i = 0; i < 4; i++) {
for (int j = i + 1; j < 5; j++) {
if (h[i] == h[j])
ans++;
}
}
switch (ans) {
case 1:
cout << "one pair" << endl;
break;
case 2:
cout << "two pair" << endl;
break;
case 3:
cout << "three card" << endl;
break;
case 4:
cout << "full house" << endl;
break;
case 6:
cout << "four card" << endl;
break;
default:
if (straight(h))
cout << "straight" << endl;
else
cout << "null" << endl;
}
}
return 0;
}
int straight(int h[5]) {
sort(h, h + 5);
for (int i = 0; i < 9; i++) {
if (h[0] == i && h[1] == i + 1 && h[2] == i + 2 && h[3] == i + 3 &&
h[4] == i + 4 ||
h[0] == 1 && h[1] == 10 && h[2] == 11 && h[3] == 12 && h[4] == 13)
return 1;
}
return 0;
}
|
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 350
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> c(5);
while (scanf("%d,%d,%d,%d,%d", &c[0], &c[1], &c[2], &c[3], &c[4]) != EOF) {
int ans = 0;
sort(c.begin(), c.end());
for (int i = 0; i < 5; i++) {
if (i < 2) {
if (c[i] == c[i + 1] && c[i + 1] == c[i + 2] && c[i + 2] == c[i + 3]) {
ans += 6;
i += 3;
}
}
if (i < 3) {
if (c[i] == c[i + 1] && c[i + 1] == c[i + 2]) {
ans += 3;
i += 2;
}
}
if (i < 4) {
if (c[i] == c[i + 1]) {
ans += 2;
i++;
}
}
}
if (ans == 6)
cout << "four card" << endl;
else if (ans == 5)
cout << "full house" << endl;
else if (ans == 4)
cout << "two pair" << endl;
else if (ans == 3)
cout << "three card" << endl;
else if (ans == 2)
cout << "one pair" << endl;
else if (c[0] + 1 == c[1] && c[1] + 1 == c[2] && c[2] + 1 == c[3] &&
c[3] + 1 == c[4])
cout << "straight" << endl;
else if (c[0] == 1 && c[1] == 2 && c[2] == 11 && c[3] == 12 && c[4] == 13)
cout << "straight" << endl;
else
cout << "null" << endl;
}
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> c(5);
while (scanf("%d,%d,%d,%d,%d", &c[0], &c[1], &c[2], &c[3], &c[4]) != EOF) {
int ans = 0;
sort(c.begin(), c.end());
for (int i = 0; i < 5; i++) {
if (i < 2) {
if (c[i] == c[i + 1] && c[i + 1] == c[i + 2] && c[i + 2] == c[i + 3]) {
ans += 6;
i += 3;
}
}
if (i < 3) {
if (c[i] == c[i + 1] && c[i + 1] == c[i + 2]) {
ans += 3;
i += 2;
}
}
if (i < 4) {
if (c[i] == c[i + 1]) {
ans += 2;
i++;
}
}
}
if (ans == 6)
cout << "four card" << endl;
else if (ans == 5)
cout << "full house" << endl;
else if (ans == 4)
cout << "two pair" << endl;
else if (ans == 3)
cout << "three card" << endl;
else if (ans == 2)
cout << "one pair" << endl;
else if (c[0] + 1 == c[1] && c[1] + 1 == c[2] && c[2] + 1 == c[3] &&
c[3] + 1 == c[4])
cout << "straight" << endl;
else if (c[0] == 1 && c[1] == 10 && c[2] == 11 && c[3] == 12 && c[4] == 13)
cout << "straight" << endl;
else
cout << "null" << endl;
}
return 0;
}
|
[["-", 31, 16, 31, 16, 31, 16, 12, 16, 12, 13], ["+", 31, 16, 31, 16, 31, 16, 12, 16, 12, 13]]
| 1
| 434
|
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main() {
int hand[5];
while (~scanf("%d", &hand[0])) {
for (int i = 1; i < 5; i++) {
scanf(",%d", &hand[i]);
}
int num[15] = {0};
for (int i = 0; i < 5; i++) {
if (hand[i] == 1)
num[14]++;
num[hand[i]]++;
}
int h[7] = {0};
string s[] = {"null", "one pair", "two pair", "three card",
"straight", "full house", "four card"};
int seq = 0;
h[0] = 1;
for (int i = 1; i < 15; i++) {
if (num[i - 1] && num[i])
seq++;
if (num[i] == 2)
h[1]++;
if (num[i] == 3)
h[3]++;
if (num[i] == 4)
h[6]++;
}
if (h[1] > 1)
h[2]++;
if (h[1] && h[3])
h[5]++;
if (seq == 4)
if (!(num[2] && num[13]))
h[4]++;
for (int i = 6; i >= 0; i--) {
if (h[i]) {
cout << s[i] << endl;
break;
}
}
}
return 0;
}
|
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main() {
int hand[5];
while (~scanf("%d", &hand[0])) {
for (int i = 1; i < 5; i++) {
scanf(",%d", &hand[i]);
}
int num[15] = {0};
for (int i = 0; i < 5; i++) {
if (hand[i] == 1)
num[14]++;
num[hand[i]]++;
}
int h[7] = {0};
string s[] = {"null", "one pair", "two pair", "three card",
"straight", "full house", "four card"};
int seq = 0;
h[0] = 1;
for (int i = 1; i < 15; i++) {
if (num[i - 1] && num[i])
seq++;
if (num[i] == 2 && i != 14)
h[1]++;
if (num[i] == 3)
h[3]++;
if (num[i] == 4)
h[6]++;
}
if (h[1] > 1)
h[2]++;
if (h[1] && h[3])
h[5]++;
if (seq == 4)
if (!(num[2] && num[13]))
h[4]++;
for (int i = 6; i >= 0; i--) {
if (h[i]) {
cout << s[i] << endl;
break;
}
}
}
return 0;
}
|
[["+", 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, 79], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
| 1
| 355
|
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
int a, b, c, d, e;
while (scanf("%d,%d,%d,%d,%d", &a, &b, &c, &d, &e) != EOF) {
int cards[13] = {0};
int dbl = 0, thr = 0, four = 0, straight = 0, tmp = 0;
cards[a - 1]++;
cards[b - 1]++;
cards[c - 1]++;
cards[d - 1]++;
cards[e - 1]++;
for (int i = 0; i < 13; ++i) {
if (cards[i] == 2)
dbl++;
else if (cards[i] == 3)
thr++;
else if (cards[i] == 4)
four++;
if (0 < i && cards[i] == 1 && cards[i - 1] == 1)
tmp++;
straight = max(tmp, straight);
}
if (four)
cout << "four cards" << endl;
else if (thr && dbl)
cout << "full house" << endl;
else if (straight == 4 || cards[0] == 1 && cards[9] == 1 &&
cards[10] == 1 && cards[11] == 1 &&
cards[12] == 1)
cout << "straight" << endl;
else if (thr)
cout << "three cards" << endl;
else if (dbl == 2)
cout << "two pairs" << endl;
else if (dbl)
cout << "one pair" << endl;
else
cout << "null" << endl;
}
return 0;
}
|
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
int a, b, c, d, e;
while (scanf("%d,%d,%d,%d,%d", &a, &b, &c, &d, &e) != EOF) {
int cards[13] = {0};
int dbl = 0, thr = 0, four = 0, straight = 0, tmp = 0;
cards[a - 1]++;
cards[b - 1]++;
cards[c - 1]++;
cards[d - 1]++;
cards[e - 1]++;
for (int i = 0; i < 13; ++i) {
if (cards[i] == 2)
dbl++;
else if (cards[i] == 3)
thr++;
else if (cards[i] == 4)
four++;
if (0 < i && cards[i] == 1 && cards[i - 1] == 1)
tmp++;
straight = max(tmp, straight);
}
if (four)
cout << "four card" << endl;
else if (thr && dbl)
cout << "full house" << endl;
else if (straight == 4 || cards[0] == 1 && cards[9] == 1 &&
cards[10] == 1 && cards[11] == 1 &&
cards[12] == 1)
cout << "straight" << endl;
else if (thr)
cout << "three card" << endl;
else if (dbl == 2)
cout << "two pair" << endl;
else if (dbl)
cout << "one pair" << endl;
else
cout << "null" << endl;
}
return 0;
}
|
[["-", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 342
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
void check_multiplicity(const int *sorted_cards,
std::map<int, int> &multiplicities) {
multiplicities.clear();
const int *current = sorted_cards;
const int *end = sorted_cards + 5;
while (current != end) {
const int *next = std::upper_bound(current, end, *current);
++multiplicities[next - current];
current = next;
}
}
int count(const std::map<int, int> multiplicities, int multiplicity) {
std::map<int, int>::const_iterator i = multiplicities.find(multiplicity);
return (i != multiplicities.end()) ? i->second : 0;
}
bool check_straight(const int *sorted_cards,
std::map<int, int> multiplicities) {
if (count(multiplicities, 1) != 5) {
return false;
}
return (sorted_cards[4] == sorted_cards[0] + 4) ||
(sorted_cards[0] == 1 && sorted_cards[1] == 10);
}
int main() {
int cards[5] = {};
while (scanf("%d,%d,%d,%d,%d", &cards[0], &cards[1], &cards[2], &cards[3],
&cards[4]) == 5) {
std::sort(cards, cards + 5);
std::map<int, int> multiplicities;
check_multiplicity(cards, multiplicities);
if (count(multiplicities, 4) > 0) {
std::cout << "for card\n";
} else if (count(multiplicities, 3) > 0 && count(multiplicities, 2) > 0) {
std::cout << "full house\n";
} else if (check_straight(cards, multiplicities)) {
std::cout << "straight\n";
} else if (count(multiplicities, 3) > 0) {
std::cout << "three card\n";
} else if (count(multiplicities, 2) == 2) {
std::cout << "two pair\n";
} else if (count(multiplicities, 2) == 1) {
std::cout << "one pair\n";
} else {
std::cout << "null\n";
}
}
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
void check_multiplicity(const int *sorted_cards,
std::map<int, int> &multiplicities) {
multiplicities.clear();
const int *current = sorted_cards;
const int *end = sorted_cards + 5;
while (current != end) {
const int *next = std::upper_bound(current, end, *current);
++multiplicities[next - current];
current = next;
}
}
int count(const std::map<int, int> multiplicities, int multiplicity) {
std::map<int, int>::const_iterator i = multiplicities.find(multiplicity);
return (i != multiplicities.end()) ? i->second : 0;
}
bool check_straight(const int *sorted_cards,
std::map<int, int> multiplicities) {
if (count(multiplicities, 1) != 5) {
return false;
}
return (sorted_cards[4] == sorted_cards[0] + 4) ||
(sorted_cards[0] == 1 && sorted_cards[1] == 10);
}
int main() {
int cards[5] = {};
while (scanf("%d,%d,%d,%d,%d", &cards[0], &cards[1], &cards[2], &cards[3],
&cards[4]) == 5) {
std::sort(cards, cards + 5);
std::map<int, int> multiplicities;
check_multiplicity(cards, multiplicities);
if (count(multiplicities, 4) > 0) {
std::cout << "four card\n";
} else if (count(multiplicities, 3) > 0 && count(multiplicities, 2) > 0) {
std::cout << "full house\n";
} else if (check_straight(cards, multiplicities)) {
std::cout << "straight\n";
} else if (count(multiplicities, 3) > 0) {
std::cout << "three card\n";
} else if (count(multiplicities, 2) == 2) {
std::cout << "two pair\n";
} else if (count(multiplicities, 2) == 1) {
std::cout << "one pair\n";
} else {
std::cout << "null\n";
}
}
return 0;
}
|
[["-", 64, 9, 0, 1, 0, 16, 12, 5, 0, 6], ["+", 64, 9, 0, 1, 0, 16, 12, 5, 0, 6]]
| 1
| 455
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> a(5);
while (~scanf("%d,%d,%d,%d,%d", &a[0], &a[1], &a[2], &a[3], &a[4])) {
sort(a.begin(), a.end());
if (count(a.begin(), a.end(), a[3]) == 4) {
cout << "four card" << endl;
} else if (count(a.begin(), a.end(), a[0]) +
count(a.begin(), a.end(), a[4]) ==
5) {
cout << "full house" << endl;
} else if (count(a.begin(), a.end(), a[3]) == 3) {
cout << "three card" << endl;
} else if (count(a.begin(), a.end(), a[1]) +
count(a.begin(), a.end(), a[3]) ==
4) {
cout << "two pair" << endl;
} else {
for (int i = 0; i < 5; i++) {
if (count(a.begin(), a.end(), a[i]) == 2) {
cout << "one pair" << endl;
goto done;
}
}
if (a[0] == 1 && a[1] == 10 && a[2] == 11 && a[3] == 12 && a[4] == 13) {
cout << "straight" << endl;
goto done;
}
for (int i = 0; i < 5; i++) {
if (a[i] != a[0] + i)
break;
if (i == 4) {
cout << "straight" << endl;
goto done;
}
}
cout << "null" << endl;
}
done:;
}
}
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> a(5);
while (~scanf("%d,%d,%d,%d,%d", &a[0], &a[1], &a[2], &a[3], &a[4])) {
sort(a.begin(), a.end());
if (count(a.begin(), a.end(), a[3]) == 4) {
cout << "four card" << endl;
} else if (count(a.begin(), a.end(), a[0]) +
count(a.begin(), a.end(), a[4]) ==
5) {
cout << "full house" << endl;
} else if (count(a.begin(), a.end(), a[2]) == 3) {
cout << "three card" << endl;
} else if (count(a.begin(), a.end(), a[1]) +
count(a.begin(), a.end(), a[3]) ==
4) {
cout << "two pair" << endl;
} else {
for (int i = 0; i < 5; i++) {
if (count(a.begin(), a.end(), a[i]) == 2) {
cout << "one pair" << endl;
goto done;
}
}
if (a[0] == 1 && a[1] == 10 && a[2] == 11 && a[3] == 12 && a[4] == 13) {
cout << "straight" << endl;
goto done;
}
for (int i = 0; i < 5; i++) {
if (a[i] != a[0] + i)
break;
if (i == 4) {
cout << "straight" << endl;
goto done;
}
}
cout << "null" << endl;
}
done:;
}
}
|
[["-", 31, 2, 3, 4, 0, 69, 341, 342, 0, 13], ["+", 31, 2, 3, 4, 0, 69, 341, 342, 0, 13]]
| 1
| 431
|
#include <algorithm>
#include <iostream>
using namespace std;
int main(void) {
int card[5];
char ten;
while (cin >> card[0]) {
cin >> ten >> card[1] >> ten >> card[2] >> ten >> card[3] >> ten >> card[4];
sort(card, card + 5);
if (card[4] == card[1] || card[3] == card[0]) { // four card
cout << "four card" << endl;
goto end;
}
if ((card[0] == card[2] && card[3] == card[4]) ||
(card[0] == card[1] && card[2] == card[4])) {
cout << "hull house" << endl;
goto end;
}
int cnt;
int r;
cnt = 0;
r = card[0];
for (int i = 1; i < 5; i++) { // straight
if (r + 1 == card[i]) {
cnt++;
r = card[i];
} else
r = card[i];
}
if (cnt == 4) {
cout << "straight" << endl;
goto end;
} else if (card[0] == 1 && card[1] == 10 && card[2] == 11 &&
card[3] == 12 && card[4] == 13) {
cout << "straight" << endl;
goto end;
}
if (card[0] == card[2] || card[1] == card[3] ||
card[2] == card[4]) { // three card
cout << "three card" << endl;
goto end;
}
if (card[0] == card[1] && card[2] == card[3]) { // two pair
cout << "two pair" << endl;
goto end;
} else if (card[0] == card[1] && card[3] == card[4]) {
cout << "two pair" << endl;
goto end;
} else if (card[1] == card[2] && card[3] == card[4]) {
cout << "two pair" << endl;
goto end;
}
for (int i = 0; i < 4; i++) { // two card
if (card[i] == card[i + 1]) {
cout << "one pair" << endl;
goto end;
}
}
cout << "null" << endl;
end:;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
int main(void) {
int card[5];
char ten;
while (cin >> card[0]) {
cin >> ten >> card[1] >> ten >> card[2] >> ten >> card[3] >> ten >> card[4];
sort(card, card + 5);
if (card[4] == card[1] || card[3] == card[0]) { // four card
cout << "four card" << endl;
goto end;
}
if ((card[0] == card[2] && card[3] == card[4]) ||
(card[0] == card[1] && card[2] == card[4])) {
cout << "full house" << endl;
goto end;
}
int cnt;
int r;
cnt = 0;
r = card[0];
for (int i = 1; i < 5; i++) { // straight
if (r + 1 == card[i]) {
cnt++;
r = card[i];
} else
r = card[i];
}
if (cnt == 4) {
cout << "straight" << endl;
goto end;
} else if (card[0] == 1 && card[1] == 10 && card[2] == 11 &&
card[3] == 12 && card[4] == 13) {
cout << "straight" << endl;
goto end;
}
if (card[0] == card[2] || card[1] == card[3] ||
card[2] == card[4]) { // three card
cout << "three card" << endl;
goto end;
}
if (card[0] == card[1] && card[2] == card[3]) { // two pair
cout << "two pair" << endl;
goto end;
} else if (card[0] == card[1] && card[3] == card[4]) {
cout << "two pair" << endl;
goto end;
} else if (card[1] == card[2] && card[3] == card[4]) {
cout << "two pair" << endl;
goto end;
}
for (int i = 0; i < 4; i++) { // two card
if (card[i] == card[i + 1]) {
cout << "one pair" << endl;
goto end;
}
}
cout << "null" << endl;
end:;
}
return 0;
}
|
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 516
|
#include <algorithm>
#include <cstdio>
using namespace std;
int main() {
int card[5];
while (scanf("%d", &card[0]) != EOF) {
for (int i = 1; i < 5; i++) {
scanf(",%d", &card[i]);
}
int cnt = 0;
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
if (card[i] == card[j] && i != j)
cnt++;
}
}
int flg = 0;
switch (cnt) {
case 2:
printf("one pair\n");
flg = 2;
break;
case 4:
printf("two pair\n");
flg = 2;
break;
case 6:
printf("three card\n");
flg = 2;
break;
case 8:
printf("full house\n");
flg = 2;
case 12:
printf("four card\n");
flg = 2;
break;
default:
flg = 1;
}
if (flg == 2)
continue;
int ct = 0;
if (flg) {
sort(card, card + 5);
for (int i = 1; i < 5; i++) {
if (card[i] - card[i - 1] == 1)
ct++;
}
}
if (ct == 4)
printf("straight\n");
else if (card[0] == 1 && card[1] == 10 && card[2] == 11 && card[3] == 12 &&
card[4] == 13)
printf("straight\n");
else
printf("null\n");
}
return 0;
}
|
#include <algorithm>
#include <cstdio>
using namespace std;
int main() {
int card[5];
while (scanf("%d", &card[0]) != EOF) {
for (int i = 1; i < 5; i++) {
scanf(",%d", &card[i]);
}
int cnt = 0;
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
if (card[i] == card[j] && i != j)
cnt++;
}
}
int flg = 0;
switch (cnt) {
case 2:
printf("one pair\n");
flg = 2;
break;
case 4:
printf("two pair\n");
flg = 2;
break;
case 6:
printf("three card\n");
flg = 2;
break;
case 8:
printf("full house\n");
flg = 2;
break;
case 12:
printf("four card\n");
flg = 2;
break;
default:
flg = 1;
}
if (flg == 2)
continue;
int ct = 0;
if (flg) {
sort(card, card + 5);
for (int i = 1; i < 5; i++) {
if (card[i] - card[i - 1] == 1)
ct++;
}
}
if (ct == 4)
printf("straight\n");
else if (card[0] == 1 && card[1] == 10 && card[2] == 11 && card[3] == 12 &&
card[4] == 13)
printf("straight\n");
else
printf("null\n");
}
return 0;
}
|
[["+", 0, 99, 8, 9, 0, 100, 0, 93, 0, 94], ["+", 0, 99, 8, 9, 0, 100, 0, 93, 0, 35]]
| 1
| 359
|
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
int a[5];
int kari;
char d;
while (cin >> a[0] >> d >> a[1] >> d >> a[2] >> d >> a[3] >> d >> a[4]) {
for (int i = 4; i > 0; i--) {
for (int j = 0; j < i; j++) {
if (a[j] > a[j + 1]) {
kari = a[j];
a[j] = a[j + 1];
a[j + 1] = kari;
}
}
}
if (a[0] == a[1] || a[1] == a[2] || a[2] == a[3] || a[3] == a[4]) {
if ((a[0] == a[1] && a[1] == a[2]) || (a[1] == a[2] && a[2] == a[3]) ||
(a[2] == a[3] && a[3] == a[4])) {
if (((a[0] == a[1] && a[1] == a[2]) && (a[3] == a[4])) ||
((a[0] == a[1]) && (a[2] == a[3] && a[3] == a[4]))) {
cout << "full house" << endl;
} else if ((a[0] == a[1] && a[1] == a[2] && a[3]) ||
(a[1] == a[2] && a[2] == a[3] && a[3] == a[4])) {
cout << "four card" << endl;
} else {
cout << "three card" << endl;
}
} else if ((a[0] == a[1] && a[2] == a[3]) ||
(a[0] == a[1] && a[3] == a[4]) ||
(a[1] == a[2] && a[3] == a[4])) {
if ((a[0] == a[1] && a[1] == a[2] && a[2] == a[3]) ||
(a[1] == a[2] && a[2] == a[3] && a[3] == a[4])) {
cout << "four card" << endl;
} else {
cout << "two pair" << endl;
}
} else {
cout << "one pair" << endl;
}
} else if ((a[1] == a[0] + 1 && a[2] == a[1] + 1 && a[3] == a[2] + 1 &&
a[4] == a[3] + 1) ||
(a[0] == 1 && a[1] == 10 && a[2] == a[1] + 1 &&
a[3] == a[2] + 1 && a[4] == a[3] + 1)) {
cout << "straight" << endl;
} else {
cout << "null" << endl;
}
}
return 0;
}
|
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
int a[5];
int kari;
char d;
while (cin >> a[0] >> d >> a[1] >> d >> a[2] >> d >> a[3] >> d >> a[4]) {
for (int i = 4; i > 0; i--) {
for (int j = 0; j < i; j++) {
if (a[j] > a[j + 1]) {
kari = a[j];
a[j] = a[j + 1];
a[j + 1] = kari;
}
}
}
if (a[0] == a[1] || a[1] == a[2] || a[2] == a[3] || a[3] == a[4]) {
if ((a[0] == a[1] && a[1] == a[2]) || (a[1] == a[2] && a[2] == a[3]) ||
(a[2] == a[3] && a[3] == a[4])) {
if (((a[0] == a[1] && a[1] == a[2]) && (a[3] == a[4])) ||
((a[0] == a[1]) && (a[2] == a[3] && a[3] == a[4]))) {
cout << "full house" << endl;
} else if ((a[0] == a[1] && a[1] == a[2] && a[2] == a[3]) ||
(a[1] == a[2] && a[2] == a[3] && a[3] == a[4])) {
cout << "four card" << endl;
} else {
cout << "three card" << endl;
}
} else if ((a[0] == a[1] && a[2] == a[3]) ||
(a[0] == a[1] && a[3] == a[4]) ||
(a[1] == a[2] && a[3] == a[4])) {
if ((a[0] == a[1] && a[1] == a[2] && a[2] == a[3]) ||
(a[1] == a[2] && a[2] == a[3] && a[3] == a[4])) {
cout << "four card" << endl;
} else {
cout << "two pair" << endl;
}
} else {
cout << "one pair" << endl;
}
} else if ((a[1] == a[0] + 1 && a[2] == a[1] + 1 && a[3] == a[2] + 1 &&
a[4] == a[3] + 1) ||
(a[0] == 1 && a[1] == 10 && a[2] == a[1] + 1 &&
a[3] == a[2] + 1 && a[4] == a[3] + 1)) {
cout << "straight" << endl;
} else {
cout << "null" << endl;
}
}
return 0;
}
|
[["+", 0, 16, 12, 16, 31, 69, 341, 342, 0, 13], ["+", 0, 16, 12, 16, 31, 69, 341, 342, 0, 73], ["+", 51, 16, 31, 23, 0, 16, 12, 16, 17, 60], ["+", 31, 23, 0, 16, 12, 16, 12, 69, 28, 22], ["+", 0, 16, 12, 16, 12, 69, 341, 342, 0, 70]]
| 1
| 720
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ctype.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr) / sizeof(value), (value))
template <typename T> void FILL_(void *ptr, size_t size, T value) {
std::fill((T *)ptr, (T *)ptr + size, value);
}
// 4方向ベクトル→↑←↓
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
int card[5];
int main() {
while (scanf("%d,%d,%d,%d,%d", &card[0], &card[1], &card[2], &card[3],
&card[4]) != EOF) {
sort(card, card + 5);
bool four, one, two, three, full, straight, flag;
flag = false;
one = two = three = four = full = straight = false;
if (!flag) {
if (card[0] == card[1] && card[0] == card[2] && card[0] == card[3] ||
card[1] == card[2] && card[1] == card[3] && card[1] == card[4]) {
four = true;
flag = true;
} else if (card[0] == card[1] && card[0] == card[2] &&
(card[3] == card[4]) ||
card[0] == card[1] && card[2] == card[3] &&
card[2] == card[4]) {
full = true;
flag = true;
} else if (card[0] == 1 && card[1] == 10 && card[2] == 11 &&
card[3] == 12 && card[4] == 13 ||
card[1] == card[0] + 1 && card[2] == card[0] + 2 &&
card[3] == card[0] + 3 && card[4] == card[0] + 4) {
straight = true;
flag = true;
} else if (card[0] == card[1] && card[0] == card[2] ||
card[1] == card[2] && card[1] == card[3] ||
card[2] == card[3] && card[2] == card[4]) {
three = true;
flag = true;
} else if (card[0] == card[1] &&
(card[2] == card[3] || card[3] == card[4]) ||
card[1] == card[2] && card[3] == card[4]) {
two = true;
flag = true;
} else if (card[0] == card[1] ||
card[1] == card[2] && card[2] == card[3] ||
card[3] == card[4]) {
one = true;
flag = true;
}
}
if (!flag)
cout << "null" << endl;
else if (four)
cout << "four card" << endl;
else if (full)
cout << "full house" << endl;
else if (straight)
cout << "straight" << endl;
else if (three)
cout << "three card" << endl;
else if (two)
cout << "two pair" << endl;
else if (one)
cout << "one pair" << endl;
}
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ctype.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr) / sizeof(value), (value))
template <typename T> void FILL_(void *ptr, size_t size, T value) {
std::fill((T *)ptr, (T *)ptr + size, value);
}
// 4方向ベクトル→↑←↓
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
int card[5];
int main() {
while (scanf("%d,%d,%d,%d,%d", &card[0], &card[1], &card[2], &card[3],
&card[4]) != EOF) {
sort(card, card + 5);
bool four, one, two, three, full, straight, flag;
flag = false;
one = two = three = four = full = straight = false;
if (!flag) {
if (card[0] == card[1] && card[0] == card[2] && card[0] == card[3] ||
card[1] == card[2] && card[1] == card[3] && card[1] == card[4]) {
four = true;
flag = true;
} else if (card[0] == card[1] && card[0] == card[2] &&
(card[3] == card[4]) ||
card[0] == card[1] && card[2] == card[3] &&
card[2] == card[4]) {
full = true;
flag = true;
} else if (card[0] == 1 && card[1] == 10 && card[2] == 11 &&
card[3] == 12 && card[4] == 13 ||
card[1] == card[0] + 1 && card[2] == card[0] + 2 &&
card[3] == card[0] + 3 && card[4] == card[0] + 4) {
straight = true;
flag = true;
} else if (card[0] == card[1] && card[0] == card[2] ||
card[1] == card[2] && card[1] == card[3] ||
card[2] == card[3] && card[2] == card[4]) {
three = true;
flag = true;
} else if (card[0] == card[1] &&
(card[2] == card[3] || card[3] == card[4]) ||
card[1] == card[2] && card[3] == card[4]) {
two = true;
flag = true;
} else if (card[0] == card[1] || card[1] == card[2] ||
card[2] == card[3] || card[3] == card[4]) {
one = true;
flag = true;
}
}
if (!flag)
cout << "null" << endl;
else if (four)
cout << "four card" << endl;
else if (full)
cout << "full house" << endl;
else if (straight)
cout << "straight" << endl;
else if (three)
cout << "three card" << endl;
else if (two)
cout << "two pair" << endl;
else if (one)
cout << "one pair" << endl;
}
return 0;
}
|
[["-", 15, 339, 51, 16, 31, 16, 12, 16, 17, 98], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 106]]
| 1
| 790
|
while gets do
a = Array.new(13,0)
$_.split(",").map(&:to_i).each do |i|
a[i-1]+=1
end
if a.member?(4) then
puts "for card"
elsif a.member?(2) then
if a.member?(3) then
puts "full house"
elsif a.index(2) == a.rindex(2) then
puts "one pair"
else
puts "two pair"
end
elsif a.member?(3) then
puts "three card"
elsif a.join =~ /1{5}/ || a.join =~ /10{8}1{4}/ then
puts "straight"
else
puts "null"
end
end
|
while gets do
a = Array.new(13,0)
$_.split(",").map(&:to_i).each do |i|
a[i-1]+=1
end
if a.member?(4) then
puts "four card"
elsif a.member?(2) then
if a.member?(3) then
puts "full house"
elsif a.index(2) == a.rindex(2) then
puts "one pair"
else
puts "two pair"
end
elsif a.member?(3) then
puts "three card"
elsif a.join =~ /1{5}/ || a.join =~ /10{8}1{4}/ then
puts "straight"
else
puts "null"
end
end
|
[["-", 64, 749, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 64, 749, 0, 652, 3, 4, 0, 557, 0, 6]]
| 4
| 139
|
while query = gets
hand = query.chomp.split(",").map(&:to_i)
cnt_max = hand.max_by{|x| hand.count(x)}
same = hand.count(cnt_max)
case same
when 4
puts "four card"
when 3
cnt_min = hand.min_by{|x| hand.count(x)}
p cnt_min
if hand.count(cnt_min) == 2
puts "full house"
else puts "three card"
end
when 2
if hand.uniq.length == 3
puts "two pair"
else puts "one pair"
end
else
hand.sort!
str_flag = true
4.times do |i|
unless hand[i+1] - hand[i] == 1
str_flag = false
break
end
end
if str_flag
puts "straight"
elsif hand == [1, 10, 11, 12, 13]
puts "straight"
else puts "null"
end
end
end
|
while query = gets
hand = query.chomp.split(",").map(&:to_i)
cnt_max = hand.max_by{|x| hand.count(x)}
same = hand.count(cnt_max)
case same
when 4
puts "four card"
when 3
cnt_min = hand.min_by{|x| hand.count(x)}
if hand.count(cnt_min) == 2
puts "full house"
else puts "three card"
end
when 2
if hand.uniq.length == 3
puts "two pair"
else puts "one pair"
end
else
hand.sort!
str_flag = true
4.times do |i|
unless hand[i+1] - hand[i] == 1
str_flag = false
break
end
end
if str_flag
puts "straight"
elsif hand == [1, 10, 11, 12, 13]
puts "straight"
else puts "null"
end
end
end
|
[["-", 0, 173, 0, 763, 8, 749, 0, 652, 735, 22], ["-", 0, 763, 8, 749, 0, 652, 3, 4, 0, 22]]
| 4
| 179
|
def q*a;a.delete a[0];a.empty?end
$<.map{|x|
a,b,c,d,e=x.chop.split(",").map(&:to_i).sort;
puts case
when q(a,b,c,d)||q(b,c,d,e);"four card"
when a==b&&q(c,d,e)||q(a,b,c)&&d==e;"full house"
when (s=[a,b,c,d,e])==(a..e).to_a||s==[10,11,12,13,1];"straight"
when q(a,b,c)||q(b,c,d)||q(c,d,e);"three card"
when a==b&&(c==d||d==e)||b==c&&d==e;"two pair"
when a==b||b==c||c==d||d==e;"one pair"
else "null"
end
}
|
def q*a;a.delete a[0];a.empty?end
$<.map{|x|
a,b,c,d,e=x.chop.split(",").map(&:to_i).sort;
puts case
when q(a,b,c,d)||q(b,c,d,e);"four card"
when a==b&&q(c,d,e)||q(a,b,c)&&d==e;"full house"
when (s=[a,b,c,d,e])==(a..e).to_a||s==[1,10,11,12,13];"straight"
when q(a,b,c)||q(b,c,d)||q(c,d,e);"three card"
when a==b&&(c==d||d==e)||b==c&&d==e;"two pair"
when a==b||b==c||c==d||d==e;"one pair"
else "null"
end
}
|
[["+", 374, 374, 0, 738, 12, 738, 12, 516, 0, 612], ["+", 374, 374, 0, 738, 12, 738, 12, 516, 0, 21], ["-", 374, 374, 0, 738, 12, 738, 12, 516, 0, 21], ["-", 374, 374, 0, 738, 12, 738, 12, 516, 0, 612]]
| 4
| 236
|
#encoding=utf-8
import sys
def inp():
word = []
for line in sys.stdin:
word = list(map(int, line.split(",")))
syori(sorted(word))
def syori(word):
flag = [0,0]
if sum(word[1:5]) == 46:
word.append(int(word[0]))
del word[0]
if word == [10,11,12,13,1]:
print("straight")
else:
for j in range(1,14):
if word.count(j) == 2:
flag[0] += 1
elif word.count(j) == 3:
flag[1] += 1
elif word.count(j) == 4:
print("four card")
flag = [10,10]
break
elif word[0] + 2 == word[1] + 1 == word[2] == word[3] - 1 == word[4] - 2:
print("straight")
flag = [10,10]
break
if flag[0] == flag[1] == 1:
print("full house")
elif flag[0] == 1:
print("one pair")
elif flag[0] == 2:
print("two pair")
elif flag[1] == 1:
print("three pair")
elif flag[0] < 1 or flag[1] < 1:
print("null")
if __name__ == "__main__":
inp()
|
import sys
def inp():
word = []
for line in sys.stdin:
word = list(map(int, line.split(",")))
syori(sorted(word))
def syori(word):
flag = [0,0]
if sum(word[1:5]) == 46:
word.append(int(word[0]))
del word[0]
if word == [10,11,12,13,1]:
print("straight")
else:
for j in range(1,14):
if word.count(j) == 2:
flag[0] += 1
elif word.count(j) == 3:
flag[1] += 1
elif word.count(j) == 4:
print("four card")
flag = [10,10]
break
elif word[0] + 2 == word[1] + 1 == word[2] == word[3] - 1 == word[4] - 2:
print("straight")
flag = [10,10]
break
if flag[0] == flag[1] == 1:
print("full house")
elif flag[0] == 1:
print("one pair")
elif flag[0] == 2:
print("two pair")
elif flag[1] == 1:
print("three card")
elif flag[0] < 1 or flag[1] < 1:
print("null")
if __name__ == "__main__":
inp()
|
[["-", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6]]
| 5
| 316
|
from collections import Counter
import sys
for t in sys.stdin:
l=sorted(map(int,t[:-1].split(",")))
s=False
p1=Counter(l)
p2=Counter(p1.values())
if 3 in p2 and 2 in p2:
print("full house")
elif 2 in p2:
if p2[2]==1:
print("one pair")
elif p2[2]==2:
print("two pair")
elif 3 in p2:
print("three card")
elif 4 in p2:
print("four card")
else:
for i in range(1,10):
if list(range(i,i+5))==l:
print("straight")
s=True
break
if [1,10,11,12,13]==i:
print("straight")
s=True
if not s:
print("null")
|
from collections import Counter
import sys
for t in sys.stdin:
l=sorted(map(int,t[:-1].split(",")))
s=False
p1=Counter(l)
p2=Counter(p1.values())
if 3 in p2 and 2 in p2:
print("full house")
elif 2 in p2:
if p2[2]==1:
print("one pair")
elif p2[2]==2:
print("two pair")
elif 3 in p2:
print("three card")
elif 4 in p2:
print("four card")
else:
for i in range(1,10):
if list(range(i,i+5))==l:
print("straight")
s=True
break
if [1,10,11,12,13]==l:
print("straight")
s=True
if not s:
print("null")
|
[["-", 75, 76, 8, 196, 0, 57, 15, 666, 0, 22], ["+", 75, 76, 8, 196, 0, 57, 15, 666, 0, 22]]
| 5
| 196
|
while True:
try:
nums = [0 for x in range(13)]
hands = list(map(int,input().split(',')))
for val in hands: nums[val-1] += 1
if 4 in nums: print('four card')
else:
if 3 in nums:
if 2 in nums: print('full house')
else: print('four card')
else:
if nums.count(2) == 2: print('two pair')
elif nums.count(2) == 1: print('one pair')
else:
hands2 = ''
for val in range(14): hands2 += str(nums[val%13])
if '11111' in hands2: print('straight')
else: print('null')
except: break
|
while True:
try:
nums = [0 for x in range(13)]
hands = list(map(int,input().split(',')))
for val in hands: nums[val-1] += 1
if 4 in nums: print('four card')
else:
if 3 in nums:
if 2 in nums: print('full house')
else: print('three card')
else:
if nums.count(2) == 2: print('two pair')
elif nums.count(2) == 1: print('one pair')
else:
hands2 = ''
for val in range(14): hands2 += str(nums[val%13])
if '11111' in hands2: print('straight')
else: print('null')
except: break
|
[["-", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6]]
| 5
| 170
|
while True:
try:
hand = list(map(int, input().split(",")))
kind = list(set(hand))
rank =[]
for card in kind:
rank.append(hand.count(card))
rank.sort()
rank.reverse()
if rank[0] == 4:
print("four card")
elif rank[0] == 3:
if rank[1] == 2:
print("hull house")
else:
print("three card")
elif rank[0] == 2:
if rank[1] == 2:
print("two pair")
else:
print("one pair")
else:
hand.sort()
if hand[4] - hand[0] == 4 or (hand[0] == 1 and hand[1] == 10):
print("straight")
else:
print("null")
except:
break
|
while True:
try:
hand = list(map(int, input().split(",")))
kind = list(set(hand))
rank =[]
for card in kind:
rank.append(hand.count(card))
rank.sort()
rank.reverse()
if rank[0] == 4:
print("four card")
elif rank[0] == 3:
if rank[1] == 2:
print("full house")
else:
print("three card")
elif rank[0] == 2:
if rank[1] == 2:
print("two pair")
else:
print("one pair")
else:
hand.sort()
if hand[4] - hand[0] == 4 or (hand[0] == 1 and hand[1] == 10):
print("straight")
else:
print("null")
except:
break
|
[["-", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6]]
| 5
| 191
|
for (r = {I : 1, V : 5, X : 10, L : 50, C : 100, D : 500, M : 1000},
k = n = s = 0, j = require("fs").readFileSync("/dev/stdin", "utf8");
p = n, i = j[k]; k++)
n = r[i] ? (s += n, n > p ? s -= p * 2 : 0) : (console.log(s), n = s = 0)
|
for (r = {I : 1, V : 5, X : 10, L : 50, C : 100, D : 500, M : 1000},
k = n = s = 0, j = require("fs").readFileSync("/dev/stdin", "utf8");
p = n, i = j[k]; k++)
(n = r[i]) ? (s += n, n > p ? s -= p * 2 : 0) : (console.log(s), n = s = 0)
|
[["+", 0, 7, 8, 1, 0, 510, 15, 23, 0, 24], ["+", 0, 7, 8, 1, 0, 510, 15, 23, 0, 25]]
| 2
| 115
|
#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
// CCW??¨///////////////////////////////////
static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;
/////////////////////////////////////////
class Point {
public:
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
Point operator+(Point p) { return Point(x + p.x, y + p.y); }
Point operator-(Point p) { return Point(x - p.x, y - p.y); }
Point operator*(double a) { return Point(a * x, a * y); }
Point operator/(double a) { return Point(x / a, y / a); }
bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }
bool operator==(const Point &p) const {
return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
}
};
struct Circle {
Point c;
double r;
};
typedef Point vect;
struct seg {
Point p1, p2;
};
//????????´?????????????????????
double norm(Point p) { return p.x * p.x + p.y * p.y; }
//??¶????????????????????¬
double abs(Point p) { return sqrt(norm(p)); }
//?????????????????????????????????
double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; }
//?????? ????????????????????????
double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; }
//??´?????????????????¨?????\?????????????????????
bool C90(seg s1, seg s2) {
return equals(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
//????????????????????¨?????\??????????????????????????????????????????
bool C0(seg s1, seg s2) {
return equals(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
//?°???± ??????????????´???????????????
Point project(seg s, Point p) {
Point base = s.p2 - s.p1;
double r = dot(p - s.p1, base) / norm(base);
return s.p1 + base * r;
}
//????°????????????????????????????
Point reflection(seg s, Point p) { return p + (project(s, p) - p) * 2.0; }
// 2???????????¢ ???????????????
double getDistancePP(Point a, Point b) { return abs(a - b); }
//??´??????????????¢(????°?)???????????????
double getDistanceLP(seg l, Point p) {
return abs(cross(l.p2 - l.p1, p - l.p1) / abs(l.p2 - l.p1));
}
//?????????????????¢??????????????????
double getDistanceSP(seg s, Point p) {
if (dot(s.p2 - s.p1, p - s.p1) < 0.0)
return abs(p - s.p1);
if (dot(s.p1 - s.p2, p - s.p2) < 0.0)
return abs(p - s.p2);
return getDistanceLP(s, p);
}
//????¨?????????????????¨??????????????????????????????????
int CCW(Point p0, Point p1, Point p2) {
Point a = p1 - p0;
Point b = p2 - p0;
if (cross(a, b) > EPS)
return COUNTER_CLOCKWISE;
if (cross(a, b) < -EPS)
return CLOCKWISE;
if (dot(a, b) < -EPS)
return ONLINE_BACK;
if (norm(a) < norm(b))
return ONLINE_FRONT;
return ON_SEGMENT;
}
//????????????????????????????????????????????§?\????
bool intersect(Point p1, Point p2, Point p3, Point p4) {
return (CCW(p1, p2, p3) * CCW(p1, p2, p4) <= 0 &&
CCW(p3, p4, p1) * CCW(p3, p4, p2) <= 0);
}
bool intersect(seg s1, seg s2) { return intersect(s1.p1, s1.p2, s2.p1, s2.p2); }
// 2??????????§???¢?????\??????????????????...????????????????????????
bool squareintersect(seg s1, seg s2) {
if (s1.p2.x < s2.p1.x || s2.p2.x < s1.p1.x)
return 0;
if (s1.p2.y < s2.p1.y || s2.p2.y < s1.p1.y)
return 0;
return 1;
}
//??????????????¢?????????????????????????????§??¨???????????????
double getDistance(seg s1, seg s2) {
if (intersect(s1, s2))
return 0.0;
return min(min(getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2)),
min(getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2)));
}
//??????????????????????????????(?´????????`)
Point getCrossPoint(seg s1, seg s2) {
Point base = s2.p2 - s2.p1;
double d1 = abs(cross(base, s1.p1 - s2.p1));
double d2 = abs(cross(base, s1.p2 - s2.p1));
double t = d1 / (d1 + d2);
return s1.p1 + (s1.p2 - s1.p1) * t;
}
//?????¨??´???????????????2??????
seg getCrossPoint(Circle c, seg l) {
// assert(intersect(cc,l));
Point pr = project(l, c.c);
Point e = (l.p2 - l.p1) / abs(l.p2 - l.p1);
double base = sqrt(c.r * c.r - norm(pr - c.c));
seg pp;
pp.p1 = (pr + e * base);
pp.p2 = (pr - e * base);
return pp;
}
//????´???°2D///////////A???)///////////
typedef complex<double> comp;
typedef vector<comp> cvec;
//????´???????
double dot(comp a, comp b) { return real(b * conj(a)); }
//????´???????
double cross(comp a, comp b) { return imag(b * conj(a)); }
double Area(cvec &a) {
double b = 0;
int n = a.size();
for (int i = 0; i < n; i++)
b += cross(a[i], a[(i + 1 == n ? 0 : i + 1)]);
return abs(b / 2.0);
}
////how to use(exp)/////////////////////
// double a,b; cvec t; cin>>n; //
// while(n--){ //
// cin>>a>>b; //
// t.push_back(comp(a,b)); //
// }printf("%.11f\n",Area(t)); //
////////////////////////////////////////
//???????£????????????¢??????????????¢??????????????????????????\????????????????????§???????????£???????????????????????????????????§?????????????????????
int intersectCC(Circle a, Circle b) {
double dist = abs(a.c - b.c);
if (dist > a.r + b.r + EPS)
return 4;
if (dist > a.r + b.r - EPS)
return 3;
if (dist > abs(a.r - b.r) + EPS)
return 2;
if (dist > abs(a.r - b.r) - EPS)
return 1;
return 0;
}
seg scan() {
seg a;
scanf("%lf%lf%lf%lf", &a.p1.x, &a.p1.y, &a.p2.x, &a.p2.y);
return a;
}
int main() {
Point a, b, c, d;
while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &a.x, &a.y, &b.x, &b.y, &c.x,
&c.y, &c.x, &c.y) != EOF) {
int q1 = CCW(a, c, b), q2 = CCW(b, d, c), q3 = CCW(c, a, d),
q4 = CCW(d, b, a), q = CCW(a, c, b);
if (q1 == q2 && q3 == q4 && q1 == q4)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
|
#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
// CCW??¨///////////////////////////////////
static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;
/////////////////////////////////////////
class Point {
public:
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
Point operator+(Point p) { return Point(x + p.x, y + p.y); }
Point operator-(Point p) { return Point(x - p.x, y - p.y); }
Point operator*(double a) { return Point(a * x, a * y); }
Point operator/(double a) { return Point(x / a, y / a); }
bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }
bool operator==(const Point &p) const {
return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
}
};
struct Circle {
Point c;
double r;
};
typedef Point vect;
struct seg {
Point p1, p2;
};
//????????´?????????????????????
double norm(Point p) { return p.x * p.x + p.y * p.y; }
//??¶????????????????????¬
double abs(Point p) { return sqrt(norm(p)); }
//?????????????????????????????????
double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; }
//?????? ????????????????????????
double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; }
//??´?????????????????¨?????\?????????????????????
bool C90(seg s1, seg s2) {
return equals(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
//????????????????????¨?????\??????????????????????????????????????????
bool C0(seg s1, seg s2) {
return equals(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
//?°???± ??????????????´???????????????
Point project(seg s, Point p) {
Point base = s.p2 - s.p1;
double r = dot(p - s.p1, base) / norm(base);
return s.p1 + base * r;
}
//????°????????????????????????????
Point reflection(seg s, Point p) { return p + (project(s, p) - p) * 2.0; }
// 2???????????¢ ???????????????
double getDistancePP(Point a, Point b) { return abs(a - b); }
//??´??????????????¢(????°?)???????????????
double getDistanceLP(seg l, Point p) {
return abs(cross(l.p2 - l.p1, p - l.p1) / abs(l.p2 - l.p1));
}
//?????????????????¢??????????????????
double getDistanceSP(seg s, Point p) {
if (dot(s.p2 - s.p1, p - s.p1) < 0.0)
return abs(p - s.p1);
if (dot(s.p1 - s.p2, p - s.p2) < 0.0)
return abs(p - s.p2);
return getDistanceLP(s, p);
}
//????¨?????????????????¨??????????????????????????????????
int CCW(Point p0, Point p1, Point p2) {
Point a = p1 - p0;
Point b = p2 - p0;
if (cross(a, b) > EPS)
return COUNTER_CLOCKWISE;
if (cross(a, b) < -EPS)
return CLOCKWISE;
if (dot(a, b) < -EPS)
return ONLINE_BACK;
if (norm(a) < norm(b))
return ONLINE_FRONT;
return ON_SEGMENT;
}
//????????????????????????????????????????????§?\????
bool intersect(Point p1, Point p2, Point p3, Point p4) {
return (CCW(p1, p2, p3) * CCW(p1, p2, p4) <= 0 &&
CCW(p3, p4, p1) * CCW(p3, p4, p2) <= 0);
}
bool intersect(seg s1, seg s2) { return intersect(s1.p1, s1.p2, s2.p1, s2.p2); }
// 2??????????§???¢?????\??????????????????...????????????????????????
bool squareintersect(seg s1, seg s2) {
if (s1.p2.x < s2.p1.x || s2.p2.x < s1.p1.x)
return 0;
if (s1.p2.y < s2.p1.y || s2.p2.y < s1.p1.y)
return 0;
return 1;
}
//??????????????¢?????????????????????????????§??¨???????????????
double getDistance(seg s1, seg s2) {
if (intersect(s1, s2))
return 0.0;
return min(min(getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2)),
min(getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2)));
}
//??????????????????????????????(?´????????`)
Point getCrossPoint(seg s1, seg s2) {
Point base = s2.p2 - s2.p1;
double d1 = abs(cross(base, s1.p1 - s2.p1));
double d2 = abs(cross(base, s1.p2 - s2.p1));
double t = d1 / (d1 + d2);
return s1.p1 + (s1.p2 - s1.p1) * t;
}
//?????¨??´???????????????2??????
seg getCrossPoint(Circle c, seg l) {
// assert(intersect(cc,l));
Point pr = project(l, c.c);
Point e = (l.p2 - l.p1) / abs(l.p2 - l.p1);
double base = sqrt(c.r * c.r - norm(pr - c.c));
seg pp;
pp.p1 = (pr + e * base);
pp.p2 = (pr - e * base);
return pp;
}
//????´???°2D///////////A???)///////////
typedef complex<double> comp;
typedef vector<comp> cvec;
//????´???????
double dot(comp a, comp b) { return real(b * conj(a)); }
//????´???????
double cross(comp a, comp b) { return imag(b * conj(a)); }
double Area(cvec &a) {
double b = 0;
int n = a.size();
for (int i = 0; i < n; i++)
b += cross(a[i], a[(i + 1 == n ? 0 : i + 1)]);
return abs(b / 2.0);
}
////how to use(exp)/////////////////////
// double a,b; cvec t; cin>>n; //
// while(n--){ //
// cin>>a>>b; //
// t.push_back(comp(a,b)); //
// }printf("%.11f\n",Area(t)); //
////////////////////////////////////////
//???????£????????????¢??????????????¢??????????????????????????\????????????????????§???????????£???????????????????????????????????§?????????????????????
int intersectCC(Circle a, Circle b) {
double dist = abs(a.c - b.c);
if (dist > a.r + b.r + EPS)
return 4;
if (dist > a.r + b.r - EPS)
return 3;
if (dist > abs(a.r - b.r) + EPS)
return 2;
if (dist > abs(a.r - b.r) - EPS)
return 1;
return 0;
}
seg scan() {
seg a;
scanf("%lf%lf%lf%lf", &a.p1.x, &a.p1.y, &a.p2.x, &a.p2.y);
return a;
}
int main() {
Point a, b, c, d;
while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &a.x, &a.y, &b.x, &b.y, &c.x,
&c.y, &d.x, &d.y) != EOF) {
int q1 = CCW(a, c, b), q2 = CCW(b, d, c), q3 = CCW(c, a, d),
q4 = CCW(d, b, a), q = CCW(a, c, b);
if (q1 == q2 && q3 == q4 && q1 == q4)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
|
[["-", 31, 2, 3, 4, 0, 66, 28, 118, 28, 22], ["+", 31, 2, 3, 4, 0, 66, 28, 118, 28, 22]]
| 1
| 1,644
|
#include <algorithm> // require sort next_permutation count __gcd reverse etc.
#include <cctype> // require tolower, toupper
#include <cfloat>
#include <climits>
#include <cmath> // require fabs
#include <cstdio> // require scanf printf
#include <cstdlib> // require abs exit atof atoi
#include <cstring> // require memset
#include <ctime> // require srand
#include <deque>
#include <fstream> // require freopen
#include <functional>
#include <iomanip> // require setw
#include <iostream>
#include <limits>
#include <map>
#include <numeric> // require accumulate
#include <queue>
#include <set>
#include <sstream> // require stringstream
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(A) A.begin(), A.end()
using namespace std;
#define EPS (1e-10)
#define PI (3.141592653589793238462643383279)
template <class T> struct point {
T x, y;
point &operator+=(const point &a) {
x += a.x;
y += a.y;
}
point &operator-=(const point &a) {
x -= a.x;
y -= a.y;
}
point operator+(const point &a) const { return (point){x + a.x, y + a.y}; }
point operator-(const point &a) const { return (point){x - a.x, y - a.y}; }
operator point<double>() const { return (point<double>){x, y}; }
};
template <class T> point<T> operator*(T c, const point<T> &a) {
return (point<T>){c * a.x, c * a.y};
}
point<double> &operator/=(point<double> &a, double c) {
a.x /= c;
a.y /= c;
return a;
}
template <class T> point<double> operator/(const point<T> &a, double c) {
return (point<double>){a.x / c, a.y / c};
}
// for integar number
template <class T> bool operator<(const point<T> &a, const point<T> &b) {
return (a.x < b.x || ((a.x == b.x) && (a.y < b.y)));
}
template <class T> bool operator==(const point<T> &a, const point<T> &b) {
return a.x == b.x && a.y == b.y;
}
template <class T> bool operator!=(const point<T> &a, const point<T> &b) {
return a.x != b.x || a.y != b.y;
}
// for real number
bool operator<(const point<double> &a, const point<double> &b) {
return (a.x + EPS < b.x || (abs(a.x - b.x) < EPS && (a.y + EPS < b.y)));
}
bool operator==(const point<double> &a, const point<double> &b) {
return abs(a.x - b.x) < EPS && abs(a.y - b.y) < EPS;
}
bool operator!=(const point<double> &a, const point<double> &b) {
return abs(a.x - b.x) > EPS || abs(a.y - b.y) > EPS;
}
// inner product
template <class T> T dot(const point<T> &a, const point<T> &b) {
return a.x * b.x + a.y * b.y;
}
// outer product
template <class T> T cross(const point<T> &a, const point<T> &b) {
return a.x * b.y - a.y * b.x;
}
// distance between origin(0,0) to point a
template <class T> double abs(const point<T> &a) {
return sqrt(a.x * a.x + a.y * a.y);
}
template <class T> T abs2(const point<T> &a) { return a.x * a.x + a.y * a.y; }
point<double> rot(const point<double> &a, double theta) {
return (point<double>){a.x * cos(theta) - a.y * sin(theta),
a.x * sin(theta) + a.y * cos(theta)};
}
// x 軸の正方向を基準とした場合のベクトル a の角度を [0, 2*PI) の範囲で求める
template <class T> double arg(const point<T> &a) {
double t = atan2(a.y, a.x);
return t < 0. ? t + 2. * PI : t;
}
template <class T> struct line {
point<T> a, b;
operator line<double>() const { return (line<double>){a, b}; }
};
template <class T> struct segment {
point<T> a, b;
operator line<T>() const { return (line<T>){a, b}; }
};
template <class T> struct polygon : vector<point<T>> {
polygon() {}
polygon(int n) : vector<point<T>>(n) {}
};
template <class T> struct circle {
point<T> c;
T r;
};
// 点 p を直線 L 上に射影した点を求める
template <class T> point<double> proj(const point<T> &p, const line<T> &L) {
return L.a + dot(p - L.a, L.b - L.a) / abs2(L.b - L.a) * (L.b - L.a);
}
/*
回転方向
説明
3点の位置関係を求める
(A) 座標値が整数
(B) 座標値が実数
引数
a : 点
b : 点
c : 点
戻り値
a-b-c の順に反時計回りに回転しているとき CCW
a-b-c の順に時計回りに回転しているとき CW
a-b-c が同一直線上にあるとき ON
制約
なし
計算量
O(1)
備考
2 点以上が同一の点であれば常に ON を返すことに注意
*/
/*
// (A)
enum{CCW = 1, CW = -1, ON = 0 };
template<class T>
int ccw(const point<T> &a, const point<T> &b, const point<T> &c ){
T rdir = cross (b-a, c-a );
if (rdir > 0 ) return CCW;
if (rdir < 0 ) return CW;
return ON;
}
*/
// (B)
enum { CCW = 1, CW = -1, ON = 0 };
int ccw(const point<double> &a, const point<double> &b,
const point<double> &c) {
double rdir = cross(b - a, c - a);
if (rdir > 0)
return CCW;
if (rdir < 0)
return CW;
return ON;
}
/*
点と点の距離
説明
点と点の距離を求める
dist : 距離そのもの
dist2 : 距離の二乗
引数
a : 点
b : 点
戻り値
点 a と 点 b の距離
制約
なし
計算量
O(1)
備考
*/
template <class T> double dist(const point<T> &a, const point<T> &b) {
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
template <class T> T dist2(const point<T> &a, const point<T> &b) {
return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
/*
直線と点の距離
説明
直線と点の距離を求める
dist : 距離そのもの
dist2 : 距離の二乗
引数
L : 直線
p : 点
戻り値
直線 L と点 p の距離
制約
なし
計算量
O(1)
備考
*/
template <class T> double dist(const line<T> &L, const point<T> &p) {
return abs(cross(L.b - L.a, p - L.a)) / dist(L.a, L.b);
}
/*
線分と点の距離
説明
線分と点の距離を求める
dist : 距離そのもの
dist2 : 距離の2乗
引数
S : 線分
p : 点
戻り値
線分 S と点 p の距離
計算量
O(1)
備考
dist2 は <= 0 で正しい。(ESP を使わなくてよい. )
*/
template <class T> double dist(const segment<T> &S, const point<T> &p) {
if (dot(S.b - S.a, p - S.a) <= 0)
return dist(p, S.a);
if (dot(S.a - S.b, p - S.b) <= 0)
return dist(p, S.b);
return abs(cross(S.b - S.a, p - S.a)) / dist(S.a, S.b);
}
template <class T> double dist2(const segment<T> &S, const point<T> &p) {
if (dot(S.b - S.a, p - S.a) <= 0)
return dist2(p, S.a);
if (dot(S.a - S.b, p - S.b) <= 0)
return dist2(p, S.b);
return (double)cross(S.b - S.a, p - S.a) * cross(S.b - S.a, p - S.a) /
dist(S.a, S.b);
}
/*
円と直線の交差判定
説明
円と直線が交わるかどうかを判定する
引数
C: 円
L: 直線
戻り値
交点の個数
制約
なし
計算量
O(1)
備考
*/
int intersect(const circle<double> &C, const line<double> &L) {
point<double> m = proj(C.c, L);
double d = abs(C.c - m);
if (C.r + EPS < d)
return 0;
if (C.r - EPS < d)
return 1;
return 2;
}
/*
円と線分の交差判定
説明
円と線分が交わるかどうかを判定する
(A) 座標値が整数
(B) 座標値が実数
引数
C : 円
S : 線分
戻り値
交わるなら true 交わらないなら false
制約
なし
計算量
O(1)
備考
線分が円の内部になるときは交わると判定する。
*/
// (A)
template <class T> bool intersect(const circle<T> &C, const segment<T> &S) {
return dist2(S, C.c) <= C.r * C.r;
}
// (B)
bool intersect(const circle<double> &C, const segment<double> &S) {
return dist(S, C.c) < C.r + EPS;
}
/*
三角形と点の包含判定
説明
三角形 abc が点 p を含むかどうかを判定する
引数
a : 頂点
b : 頂点
c : 頂点
戻り値
含むなら true, 含まないなら false
制約
三角形は縮退していないこと
すなわち、三点が同一直線上にないこと、(特に、どの二点も等しくないこと
計算量
O(1)
備考
三角形は CCW でも CW でもよい
点が三角形の境界になるときは含むと判定する
Verified: AOJ 0143 Altair and Vega
*/
template <class T>
bool cover(const point<T> &a, const point<T> &b, const point<T> &c,
const point<T> &p) {
int d1 = ccw(p, a, b);
int d2 = ccw(p, b, c);
int d3 = ccw(p, c, a);
return !((d1 == CCW && d2 == CW) || (d1 == CCW && d3 == CW) ||
(d2 == CCW && d3 == CW) || (d1 == CW && d2 == CCW) ||
(d1 == CW && d3 == CCW) || (d2 == CW && d3 == CCW));
}
/*
内接円の半径
説明
辺長がそれぞれ、a, b, c である三角形の内接円の半径を求める
引数
a: 辺長
b: 辺長
c: 辺長
戻り値
内接円の半径
制約
a >= 0, b >= 0, c >= 0
a < b + c, c < c + a, c < a + b (三角形の成立条件)
計算量
O(1)
備考
三角形が縮退しているときは nan を返すかもしれない
*/
double inradius(double a, double b, double c) {
return sqrt((b + c - a) * (c + a - b) * (a + b - c) / (a + b + c)) / 2.;
}
/*
外接円
説明
三角形 abc の外接円を求める
引数
a: 頂点
b: 頂点
c: 頂点
戻り値
外接円
制約
a, b, c は同一直線上にないこと
計算量
O(1)
備考
a, b, c が同一直線上にあるときは外接円は存在しない
頂点が整数座標のとき、外心の座標と半径の二乗は有理数となる
Verified: AOJ 0010 Circumscribed Circle of a Triangle
*/
circle<double> circumcircle(const point<double> &a, point<double> b,
point<double> c) {
b -= a;
c -= a;
double A2 = abs2(b - c), B2 = abs2(b), C2 = abs2(c);
double d = 2 * cross(b, c);
double nx = c.y * B2 - b.y * C2;
double ny = b.x * C2 - c.x * B2;
double r2 = A2 * B2 * C2 / (d * d);
return (circle<double>){a + (point<double>){nx / d, ny / d}, sqrt(r2)};
}
/*
外接円の半径
説明
辺長がそれぞれ a, b, c である三角形の外接円の半径を求める
引数
a : 辺長
b : 辺長
c : 辺長
戻り値
外接円の半径
制約
a >= 0, b >= 0, c >= 0
a < b + c, b < c + a, c < a + b (三角形の成立条件)
計算量
O(1)
備考
三角形が縮退しているときは nan を返すかもしれない
Verified: AOJ 0010 Circumscribed Circle of a Triangle
*/
double circumradius(double a, double b, double c) {
return a * b * c /
sqrt((a + b + c) * (b + c - a) * (c + a - b) * (a + b - c));
}
/*
反時計回りに変換
説明
多角形の頂点の順番が CW であれば CCW に変換する
元々 CCW であれば何もしない
(A) 座標値が整数
(B) 座標値が実数
引数
G : 多角形
戻り値
なし(引数 G が更新される)
制約
G は単純
計算量
O(n)
備考
単純多角形とは自己交差しない多角形のこと
*/
// (A)
template <class T> void to_ccw(polygon<T> &G) {
int n = G.size();
T A = 0;
rep(i, n) A += cross(G[i], G[(i + 1) % n]);
if (A < 0)
reverse(ALL(G));
}
// (B)
void to_ccw(polygon<double> &G) {
int n = G.size();
double A = 0.;
rep(i, n) A += cross(G[i], G[(i + 1) % n]);
if (A < -EPS)
reverse(ALL(G));
}
/*
凸性判定
説明
多角形が凸かどうかを判定する
引数
G : 多角形
戻り値
G は単調かつ頂点の順番が CCW で与えられていること
計算量
O(n)
備考
*/
template <class T> bool is_convex(const polygon<T> &G) {
int n = G.size();
rep(i, n) if (ccw(G[i], G[(i + 1) % n], G[(i + 2) % n]) == CW) return false;
return true;
}
/*
線分と線分の交差判定
説明
線分と線分が交わるかどうかを判定する
(A) 座標値が整数
(B) 座標値が実数
引数
S1 : 線分
S2 : 線分
戻り値
交わるなら true, 交わらないなら false
制約
なし
計算量
O(1)
備考
bounding box によるラフチェックは必要。( ccw
による判定だと、二線分が同一直線上にあるとき間違う。)
*/
// (A)
template <class T> bool intersect(const segment<T> &S1, const segment<T> &S2) {
if (max(S1.a.x, S1.b.x) < min(S2.a.x, S2.b.x) ||
max(S1.a.y, S1.b.y) < min(S2.a.y, S2.b.y) ||
max(S2.a.x, S2.b.x) < min(S1.a.x, S1.b.x) ||
max(S2.a.y, S2.b.y) < min(S1.a.y, S1.b.y))
return false;
return ccw(S1.a, S1.b, S2.a) * ccw(S1.a, S1.b, S2.b) <= 0 &&
ccw(S2.a, S2.b, S1.a) * ccw(S2.a, S2.b, S1.b) <= 0;
}
/*
多角形と線分の交差判定
説明
多角形と線分が交わるかどうかを判定する
引数
G : 多角形
S : 線分
戻り値
交わるなら true, 交わらないなら false
制約
なし
計算量
O(n)
備考
G は凸でなくていい。
G は境界を含む
S が G の内部にあるときは交わると判定する
*/
template <class T> bool intersect(const polygon<T> &G, const segment<T> &S) {
int n = G.size();
if (cover(G, S.a) || cover(G, S.b))
return true;
rep(i, n) if (intersect((segment<T>){G[i], G[(i + 1) % n]}, S)) return true;
return false;
}
int main() {
// cut here before submit
// freopen ("testcase.0035", "r", stdin );
ios_base::sync_with_stdio(0);
string str = "";
while (getline(cin, str)) {
int n = str.length();
rep(i, n) if (str[i] == ',') str[i] = ' ';
polygon<double> G(n);
stringstream ss(str);
rep(i, 4) ss >> G[i].x >> G[i].y;
to_ccw(G);
if (is_convex(G)) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
} // end if
} // end loop
// printf ("%d\n", res );
return 0;
}
|
#include <algorithm> // require sort next_permutation count __gcd reverse etc.
#include <cctype> // require tolower, toupper
#include <cfloat>
#include <climits>
#include <cmath> // require fabs
#include <cstdio> // require scanf printf
#include <cstdlib> // require abs exit atof atoi
#include <cstring> // require memset
#include <ctime> // require srand
#include <deque>
#include <fstream> // require freopen
#include <functional>
#include <iomanip> // require setw
#include <iostream>
#include <limits>
#include <map>
#include <numeric> // require accumulate
#include <queue>
#include <set>
#include <sstream> // require stringstream
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(A) A.begin(), A.end()
using namespace std;
#define EPS (1e-10)
#define PI (3.141592653589793238462643383279)
template <class T> struct point {
T x, y;
point &operator+=(const point &a) {
x += a.x;
y += a.y;
}
point &operator-=(const point &a) {
x -= a.x;
y -= a.y;
}
point operator+(const point &a) const { return (point){x + a.x, y + a.y}; }
point operator-(const point &a) const { return (point){x - a.x, y - a.y}; }
operator point<double>() const { return (point<double>){x, y}; }
};
template <class T> point<T> operator*(T c, const point<T> &a) {
return (point<T>){c * a.x, c * a.y};
}
point<double> &operator/=(point<double> &a, double c) {
a.x /= c;
a.y /= c;
return a;
}
template <class T> point<double> operator/(const point<T> &a, double c) {
return (point<double>){a.x / c, a.y / c};
}
// for integar number
template <class T> bool operator<(const point<T> &a, const point<T> &b) {
return (a.x < b.x || ((a.x == b.x) && (a.y < b.y)));
}
template <class T> bool operator==(const point<T> &a, const point<T> &b) {
return a.x == b.x && a.y == b.y;
}
template <class T> bool operator!=(const point<T> &a, const point<T> &b) {
return a.x != b.x || a.y != b.y;
}
// for real number
bool operator<(const point<double> &a, const point<double> &b) {
return (a.x + EPS < b.x || (abs(a.x - b.x) < EPS && (a.y + EPS < b.y)));
}
bool operator==(const point<double> &a, const point<double> &b) {
return abs(a.x - b.x) < EPS && abs(a.y - b.y) < EPS;
}
bool operator!=(const point<double> &a, const point<double> &b) {
return abs(a.x - b.x) > EPS || abs(a.y - b.y) > EPS;
}
// inner product
template <class T> T dot(const point<T> &a, const point<T> &b) {
return a.x * b.x + a.y * b.y;
}
// outer product
template <class T> T cross(const point<T> &a, const point<T> &b) {
return a.x * b.y - a.y * b.x;
}
// distance between origin(0,0) to point a
template <class T> double abs(const point<T> &a) {
return sqrt(a.x * a.x + a.y * a.y);
}
template <class T> T abs2(const point<T> &a) { return a.x * a.x + a.y * a.y; }
point<double> rot(const point<double> &a, double theta) {
return (point<double>){a.x * cos(theta) - a.y * sin(theta),
a.x * sin(theta) + a.y * cos(theta)};
}
// x 軸の正方向を基準とした場合のベクトル a の角度を [0, 2*PI) の範囲で求める
template <class T> double arg(const point<T> &a) {
double t = atan2(a.y, a.x);
return t < 0. ? t + 2. * PI : t;
}
template <class T> struct line {
point<T> a, b;
operator line<double>() const { return (line<double>){a, b}; }
};
template <class T> struct segment {
point<T> a, b;
operator line<T>() const { return (line<T>){a, b}; }
};
template <class T> struct polygon : vector<point<T>> {
polygon() {}
polygon(int n) : vector<point<T>>(n) {}
};
template <class T> struct circle {
point<T> c;
T r;
};
// 点 p を直線 L 上に射影した点を求める
template <class T> point<double> proj(const point<T> &p, const line<T> &L) {
return L.a + dot(p - L.a, L.b - L.a) / abs2(L.b - L.a) * (L.b - L.a);
}
/*
回転方向
説明
3点の位置関係を求める
(A) 座標値が整数
(B) 座標値が実数
引数
a : 点
b : 点
c : 点
戻り値
a-b-c の順に反時計回りに回転しているとき CCW
a-b-c の順に時計回りに回転しているとき CW
a-b-c が同一直線上にあるとき ON
制約
なし
計算量
O(1)
備考
2 点以上が同一の点であれば常に ON を返すことに注意
*/
/*
// (A)
enum{CCW = 1, CW = -1, ON = 0 };
template<class T>
int ccw(const point<T> &a, const point<T> &b, const point<T> &c ){
T rdir = cross (b-a, c-a );
if (rdir > 0 ) return CCW;
if (rdir < 0 ) return CW;
return ON;
}
*/
// (B)
enum { CCW = 1, CW = -1, ON = 0 };
int ccw(const point<double> &a, const point<double> &b,
const point<double> &c) {
double rdir = cross(b - a, c - a);
if (rdir > 0)
return CCW;
if (rdir < 0)
return CW;
return ON;
}
/*
点と点の距離
説明
点と点の距離を求める
dist : 距離そのもの
dist2 : 距離の二乗
引数
a : 点
b : 点
戻り値
点 a と 点 b の距離
制約
なし
計算量
O(1)
備考
*/
template <class T> double dist(const point<T> &a, const point<T> &b) {
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
template <class T> T dist2(const point<T> &a, const point<T> &b) {
return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
/*
直線と点の距離
説明
直線と点の距離を求める
dist : 距離そのもの
dist2 : 距離の二乗
引数
L : 直線
p : 点
戻り値
直線 L と点 p の距離
制約
なし
計算量
O(1)
備考
*/
template <class T> double dist(const line<T> &L, const point<T> &p) {
return abs(cross(L.b - L.a, p - L.a)) / dist(L.a, L.b);
}
/*
線分と点の距離
説明
線分と点の距離を求める
dist : 距離そのもの
dist2 : 距離の2乗
引数
S : 線分
p : 点
戻り値
線分 S と点 p の距離
計算量
O(1)
備考
dist2 は <= 0 で正しい。(ESP を使わなくてよい. )
*/
template <class T> double dist(const segment<T> &S, const point<T> &p) {
if (dot(S.b - S.a, p - S.a) <= 0)
return dist(p, S.a);
if (dot(S.a - S.b, p - S.b) <= 0)
return dist(p, S.b);
return abs(cross(S.b - S.a, p - S.a)) / dist(S.a, S.b);
}
template <class T> double dist2(const segment<T> &S, const point<T> &p) {
if (dot(S.b - S.a, p - S.a) <= 0)
return dist2(p, S.a);
if (dot(S.a - S.b, p - S.b) <= 0)
return dist2(p, S.b);
return (double)cross(S.b - S.a, p - S.a) * cross(S.b - S.a, p - S.a) /
dist(S.a, S.b);
}
/*
円と直線の交差判定
説明
円と直線が交わるかどうかを判定する
引数
C: 円
L: 直線
戻り値
交点の個数
制約
なし
計算量
O(1)
備考
*/
int intersect(const circle<double> &C, const line<double> &L) {
point<double> m = proj(C.c, L);
double d = abs(C.c - m);
if (C.r + EPS < d)
return 0;
if (C.r - EPS < d)
return 1;
return 2;
}
/*
円と線分の交差判定
説明
円と線分が交わるかどうかを判定する
(A) 座標値が整数
(B) 座標値が実数
引数
C : 円
S : 線分
戻り値
交わるなら true 交わらないなら false
制約
なし
計算量
O(1)
備考
線分が円の内部になるときは交わると判定する。
*/
// (A)
template <class T> bool intersect(const circle<T> &C, const segment<T> &S) {
return dist2(S, C.c) <= C.r * C.r;
}
// (B)
bool intersect(const circle<double> &C, const segment<double> &S) {
return dist(S, C.c) < C.r + EPS;
}
/*
三角形と点の包含判定
説明
三角形 abc が点 p を含むかどうかを判定する
引数
a : 頂点
b : 頂点
c : 頂点
戻り値
含むなら true, 含まないなら false
制約
三角形は縮退していないこと
すなわち、三点が同一直線上にないこと、(特に、どの二点も等しくないこと
計算量
O(1)
備考
三角形は CCW でも CW でもよい
点が三角形の境界になるときは含むと判定する
Verified: AOJ 0143 Altair and Vega
*/
template <class T>
bool cover(const point<T> &a, const point<T> &b, const point<T> &c,
const point<T> &p) {
int d1 = ccw(p, a, b);
int d2 = ccw(p, b, c);
int d3 = ccw(p, c, a);
return !((d1 == CCW && d2 == CW) || (d1 == CCW && d3 == CW) ||
(d2 == CCW && d3 == CW) || (d1 == CW && d2 == CCW) ||
(d1 == CW && d3 == CCW) || (d2 == CW && d3 == CCW));
}
/*
内接円の半径
説明
辺長がそれぞれ、a, b, c である三角形の内接円の半径を求める
引数
a: 辺長
b: 辺長
c: 辺長
戻り値
内接円の半径
制約
a >= 0, b >= 0, c >= 0
a < b + c, c < c + a, c < a + b (三角形の成立条件)
計算量
O(1)
備考
三角形が縮退しているときは nan を返すかもしれない
*/
double inradius(double a, double b, double c) {
return sqrt((b + c - a) * (c + a - b) * (a + b - c) / (a + b + c)) / 2.;
}
/*
外接円
説明
三角形 abc の外接円を求める
引数
a: 頂点
b: 頂点
c: 頂点
戻り値
外接円
制約
a, b, c は同一直線上にないこと
計算量
O(1)
備考
a, b, c が同一直線上にあるときは外接円は存在しない
頂点が整数座標のとき、外心の座標と半径の二乗は有理数となる
Verified: AOJ 0010 Circumscribed Circle of a Triangle
*/
circle<double> circumcircle(const point<double> &a, point<double> b,
point<double> c) {
b -= a;
c -= a;
double A2 = abs2(b - c), B2 = abs2(b), C2 = abs2(c);
double d = 2 * cross(b, c);
double nx = c.y * B2 - b.y * C2;
double ny = b.x * C2 - c.x * B2;
double r2 = A2 * B2 * C2 / (d * d);
return (circle<double>){a + (point<double>){nx / d, ny / d}, sqrt(r2)};
}
/*
外接円の半径
説明
辺長がそれぞれ a, b, c である三角形の外接円の半径を求める
引数
a : 辺長
b : 辺長
c : 辺長
戻り値
外接円の半径
制約
a >= 0, b >= 0, c >= 0
a < b + c, b < c + a, c < a + b (三角形の成立条件)
計算量
O(1)
備考
三角形が縮退しているときは nan を返すかもしれない
Verified: AOJ 0010 Circumscribed Circle of a Triangle
*/
double circumradius(double a, double b, double c) {
return a * b * c /
sqrt((a + b + c) * (b + c - a) * (c + a - b) * (a + b - c));
}
/*
反時計回りに変換
説明
多角形の頂点の順番が CW であれば CCW に変換する
元々 CCW であれば何もしない
(A) 座標値が整数
(B) 座標値が実数
引数
G : 多角形
戻り値
なし(引数 G が更新される)
制約
G は単純
計算量
O(n)
備考
単純多角形とは自己交差しない多角形のこと
*/
// (A)
template <class T> void to_ccw(polygon<T> &G) {
int n = G.size();
T A = 0;
rep(i, n) A += cross(G[i], G[(i + 1) % n]);
if (A < 0)
reverse(ALL(G));
}
// (B)
void to_ccw(polygon<double> &G) {
int n = G.size();
double A = 0.;
rep(i, n) A += cross(G[i], G[(i + 1) % n]);
if (A < -EPS)
reverse(ALL(G));
}
/*
凸性判定
説明
多角形が凸かどうかを判定する
引数
G : 多角形
戻り値
G は単調かつ頂点の順番が CCW で与えられていること
計算量
O(n)
備考
*/
template <class T> bool is_convex(const polygon<T> &G) {
int n = G.size();
rep(i, n) if (ccw(G[i], G[(i + 1) % n], G[(i + 2) % n]) == CW) return false;
return true;
}
/*
線分と線分の交差判定
説明
線分と線分が交わるかどうかを判定する
(A) 座標値が整数
(B) 座標値が実数
引数
S1 : 線分
S2 : 線分
戻り値
交わるなら true, 交わらないなら false
制約
なし
計算量
O(1)
備考
bounding box によるラフチェックは必要。( ccw
による判定だと、二線分が同一直線上にあるとき間違う。)
*/
// (A)
template <class T> bool intersect(const segment<T> &S1, const segment<T> &S2) {
if (max(S1.a.x, S1.b.x) < min(S2.a.x, S2.b.x) ||
max(S1.a.y, S1.b.y) < min(S2.a.y, S2.b.y) ||
max(S2.a.x, S2.b.x) < min(S1.a.x, S1.b.x) ||
max(S2.a.y, S2.b.y) < min(S1.a.y, S1.b.y))
return false;
return ccw(S1.a, S1.b, S2.a) * ccw(S1.a, S1.b, S2.b) <= 0 &&
ccw(S2.a, S2.b, S1.a) * ccw(S2.a, S2.b, S1.b) <= 0;
}
/*
多角形と線分の交差判定
説明
多角形と線分が交わるかどうかを判定する
引数
G : 多角形
S : 線分
戻り値
交わるなら true, 交わらないなら false
制約
なし
計算量
O(n)
備考
G は凸でなくていい。
G は境界を含む
S が G の内部にあるときは交わると判定する
*/
template <class T> bool intersect(const polygon<T> &G, const segment<T> &S) {
int n = G.size();
if (cover(G, S.a) || cover(G, S.b))
return true;
rep(i, n) if (intersect((segment<T>){G[i], G[(i + 1) % n]}, S)) return true;
return false;
}
int main() {
// cut here before submit
// freopen ("testcase.0035", "r", stdin );
ios_base::sync_with_stdio(0);
string str = "";
while (getline(cin, str)) {
int n = str.length();
rep(i, n) if (str[i] == ',') str[i] = ' ';
polygon<double> G(4);
stringstream ss(str);
rep(i, 4) ss >> G[i].x >> G[i].y;
// rep (i, 4 ) cerr << '(' << G[i].x << ',' << G[i].y << ')' <<
//endl;
to_ccw(G);
// rep (i, 4 ) cerr << '(' << G[i].x << ',' << G[i].y << ')' <<
//endl;
if (is_convex(G)) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
} // end if
} // end loop
return 0;
}
|
[["-", 0, 43, 49, 53, 54, 55, 0, 56, 39, 78], ["+", 8, 9, 0, 43, 49, 50, 51, 4, 0, 13]]
| 1
| 2,937
|
#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;
class Point {
public:
double y, x;
Point(double y0, double x0) {
y = y0;
x = x0;
}
Point() { y = x = 0.0; }
double cross(const Point &p) const { return x * p.y - y * p.x; }
Point operator-(const Point &p) const { return Point(y - p.y, x - p.x); }
};
int main() {
for (;;) {
vector<Point> p(4);
for (int i = 0; i < 4; ++i) {
char c;
if (!(cin >> p[i].x >> c >> p[i].y))
return 0;
if (i < 3)
cin >> c;
}
bool plus = true;
bool minus = true;
for (int i = 0; i < 4; ++i) {
Point p1 = p[(i + 2) % 3] - p[(i + 1) % 3];
Point p2 = p[i] - p[(i + 1) % 3];
if (p1.cross(p2) < 0)
plus = false;
else
minus = false;
}
if (plus != minus)
cout << "YES" << endl;
else
cout << "NO" << 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;
class Point {
public:
double y, x;
Point(double y0, double x0) {
y = y0;
x = x0;
}
Point() { y = x = 0.0; }
double cross(const Point &p) const { return x * p.y - y * p.x; }
Point operator-(const Point &p) const { return Point(y - p.y, x - p.x); }
};
int main() {
for (;;) {
vector<Point> p(4);
for (int i = 0; i < 4; ++i) {
char c;
if (!(cin >> p[i].x >> c >> p[i].y))
return 0;
if (i < 3)
cin >> c;
}
bool plus = true;
bool minus = true;
for (int i = 0; i < 4; ++i) {
Point p1 = p[(i + 2) % 4] - p[(i + 1) % 4];
Point p2 = p[i] - p[(i + 1) % 4];
if (p1.cross(p2) < 0)
plus = false;
else
minus = false;
}
if (plus || minus)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
|
[["-", 51, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["+", 51, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["-", 51, 16, 12, 69, 341, 342, 0, 16, 12, 13], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 12, 13], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 79], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 106]]
| 1
| 319
|
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(n) rep(i, n)
#define all(n) n.begin(), n.end()
// vector(geometric) definition
typedef complex<double> cdouble;
// define with polor
const int N = 4;
int main() {
cdouble v[N + 2];
double x[N], y[N];
char t;
while (cin >> x[0] >> t >> y[0] >> t >> x[1] >> t >> y[1] >> t >> x[2] >> t >>
y[2] >> t >> x[3] >> t >> y[3]) {
REP(N) v[i] = cdouble(x[i], y[i]);
v[N] = v[0];
v[N + 1] = v[1];
double ang[N + 2];
// REP(6)cout << v[i] << endl;
for (int i = 1; i <= 4; i++) {
ang[i] = fmod(arg(v[i - 1] - v[i]) - arg(v[i + 1] - v[i]) + 10 * M_PI,
M_PI * 2);
// cout << i << "th angle = " << ang[i] << endl;
}
int ans = 1;
if (ang[1] > M_PI) {
REP(4) if (ang[i + 1] < M_PI) ans = 0;
} else {
REP(4) if (ang[i + 1] > M_PI) ans = 0;
}
if (ans)
cout << "yes" << endl;
else
cout << "no" << endl;
}
return 0;
}
|
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(n) rep(i, n)
#define all(n) n.begin(), n.end()
// vector(geometric) definition
typedef complex<double> cdouble;
// define with polor
const int N = 4;
int main() {
cdouble v[N + 2];
double x[N], y[N];
char t;
while (cin >> x[0] >> t >> y[0] >> t >> x[1] >> t >> y[1] >> t >> x[2] >> t >>
y[2] >> t >> x[3] >> t >> y[3]) {
REP(N) v[i] = cdouble(x[i], y[i]);
v[N] = v[0];
v[N + 1] = v[1];
double ang[N + 2];
// REP(6)cout << v[i] << endl;
for (int i = 1; i <= 4; i++) {
ang[i] = fmod(arg(v[i - 1] - v[i]) - arg(v[i + 1] - v[i]) + (10 * M_PI),
M_PI * 2);
// cout << i << "th angle = " << ang[i] << endl;
}
int ans = 1;
if (ang[1] > M_PI) {
REP(4) if (ang[i + 1] < M_PI) ans = 0;
} else {
REP(4) if (ang[i + 1] > M_PI) ans = 0;
}
if (ans)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
|
[["+", 12, 2, 3, 4, 0, 16, 12, 23, 0, 24], ["+", 12, 2, 3, 4, 0, 16, 12, 23, 0, 25], ["-", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 338
|
#include <complex>
#include <cstdio>
#include <iostream>
bool read_data(std::complex<double> *points) {
double coords[8];
for (int i = 0; i < 8; ++i) {
if (scanf((i == 0) ? "%lf" : ",%lf", &coords[i]) != 1) {
return false;
}
}
for (int i = 0; i < 4; ++i) {
points[i] = std::complex<double>(coords[i * 2], coords[i * 2 + 1]);
}
return true;
}
int main() {
std::complex<double> points[4];
while (read_data(points)) {
int imag[4] = {};
for (int i = 0; i < 4; ++i) {
imag[i] = ((points[(i + 2) % 4] - points[(i + 1) % 4]) /
(points[i % 4] - points[(i + 1) % 4]))
.imag();
}
if ((imag[0] > 0 && imag[1] > 0 && imag[2] > 0 && imag[3] > 0) ||
(imag[0] < 0 && imag[1] < 0 && imag[2] < 0 && imag[3] < 0)) {
std::cout << "YES\n";
} else {
std::cout << "NO\n";
}
}
return 0;
}
|
#include <complex>
#include <cstdio>
#include <iostream>
bool read_data(std::complex<double> *points) {
double coords[8];
for (int i = 0; i < 8; ++i) {
if (scanf((i == 0) ? "%lf" : ",%lf", &coords[i]) != 1) {
return false;
}
}
for (int i = 0; i < 4; ++i) {
points[i] = std::complex<double>(coords[i * 2], coords[i * 2 + 1]);
}
return true;
}
int main() {
std::complex<double> points[4];
while (read_data(points)) {
double imag[4] = {};
for (int i = 0; i < 4; ++i) {
imag[i] = ((points[(i + 2) % 4] - points[(i + 1) % 4]) /
(points[i % 4] - points[(i + 1) % 4]))
.imag();
}
if ((imag[0] > 0 && imag[1] > 0 && imag[2] > 0 && imag[3] > 0) ||
(imag[0] < 0 && imag[1] < 0 && imag[2] < 0 && imag[3] < 0)) {
std::cout << "YES\n";
} else {
std::cout << "NO\n";
}
}
return 0;
}
|
[["-", 8, 9, 0, 52, 8, 9, 0, 43, 39, 40], ["+", 8, 9, 0, 52, 8, 9, 0, 43, 39, 40]]
| 1
| 316
|
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toStr(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) FOR(i, 0, (n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX / 10;
#include <complex>
typedef complex<double> P;
double dot(P a, P b) { return (a.real() * b.real() + a.imag() * b.imag()); }
double cross(P a, P b) { return (a.real() * b.imag() - a.imag() * b.imag()); }
int ccw(P a, P b, P c) {
b -= a;
c -= a;
if (cross(b, c) > 0)
return +1;
if (cross(b, c) < 0)
return -1;
if (dot(b, c) < 0)
return +2;
if (norm(b) < norm(c))
return -2;
return 0;
}
namespace std {
bool operator<(const P &a, const P &b) {
return a.real() != b.real() ? a.real() < b.real() : a.imag() < b.imag();
}
} // namespace std
vector<P> convex_hull(vector<P> ps) {
int n = ps.size(), k = 0;
sort(ALL(ps));
vector<P> ch(2 * n);
for (int i = 0; i < n; ch[k++] = ps[i++])
while (k >= 2 && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0)
--k;
for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = ps[i--])
while (k >= t && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0)
--k;
ch.resize(k - 1);
return ch;
}
int main() {
double xa, ya, xb, yb, xc, yc, xd, yd;
char c;
while (cin >> xa >> c >> ya >> c >> xb >> c >> yb >> c >> xc >> c >> yc >>
c >> xd >> c >> yd) {
P a(xa, ya), b(xb, yb), c(xc, yc), d(xd, yd);
vector<P> points;
points.push_back(a);
points.push_back(b);
points.push_back(c);
points.push_back(d);
if (convex_hull(points).size() != 4) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
return 0;
}
|
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toStr(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) FOR(i, 0, (n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX / 10;
#include <complex>
typedef complex<double> P;
double dot(P a, P b) { return (a.real() * b.real() + a.imag() * b.imag()); }
double cross(P a, P b) { return (a.real() * b.imag() - a.imag() * b.real()); }
int ccw(P a, P b, P c) {
b -= a;
c -= a;
if (cross(b, c) > 0)
return +1;
if (cross(b, c) < 0)
return -1;
if (dot(b, c) < 0)
return +2;
if (norm(b) < norm(c))
return -2;
return 0;
}
namespace std {
bool operator<(const P &a, const P &b) {
return a.real() != b.real() ? a.real() < b.real() : a.imag() < b.imag();
}
} // namespace std
vector<P> convex_hull(vector<P> ps) {
int n = ps.size(), k = 0;
sort(ALL(ps));
vector<P> ch(2 * n);
for (int i = 0; i < n; ch[k++] = ps[i++])
while (k >= 2 && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0)
--k;
for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = ps[i--])
while (k >= t && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0)
--k;
ch.resize(k - 1);
return ch;
}
int main() {
double xa, ya, xb, yb, xc, yc, xd, yd;
char c;
while (cin >> xa >> c >> ya >> c >> xb >> c >> yb >> c >> xc >> c >> yc >>
c >> xd >> c >> yd) {
P a(xa, ya), b(xb, yb), c(xc, yc), d(xd, yd);
vector<P> points;
points.push_back(a);
points.push_back(b);
points.push_back(c);
points.push_back(d);
if (convex_hull(points).size() != 4) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
return 0;
}
|
[["-", 0, 16, 12, 16, 12, 2, 63, 118, 119, 120], ["+", 0, 16, 12, 16, 12, 2, 63, 118, 119, 120]]
| 1
| 748
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ctype.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr) / sizeof(value), (value))
template <typename T> void FILL_(void *ptr, size_t size, T value) {
std::fill((T *)ptr, (T *)ptr + size, value);
}
// 4方向ベクトル→↑←↓
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
int main() {
double xa, xb, xc, xd, ya, yb, yc, yd;
while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc,
&xd, &yd) != EOF) {
double td = (xa - xc) * (yd - ya) + (ya - yc) * (xa - xd);
double tb = (xa - xc) * (yb - ya) + (ya - yc) * (xa - xd);
double ta = (xb - xd) * (ya - yb) + (yb - yd) * (xb - xa);
double tc = (xb - xd) * (yc - yb) + (yb - yd) * (xb - xc);
if (td * tb > 0.0 || ta * tc > 0.0)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ctype.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr) / sizeof(value), (value))
template <typename T> void FILL_(void *ptr, size_t size, T value) {
std::fill((T *)ptr, (T *)ptr + size, value);
}
// 4方向ベクトル→↑←↓
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
int main() {
double xa, xb, xc, xd, ya, yb, yc, yd;
while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc,
&xd, &yd) != EOF) {
double td = (xa - xc) * (yd - ya) + (ya - yc) * (xa - xd);
double tb = (xa - xc) * (yb - ya) + (ya - yc) * (xa - xb);
double ta = (xb - xd) * (ya - yb) + (yb - yd) * (xb - xa);
double tc = (xb - xd) * (yc - yb) + (yb - yd) * (xb - xc);
if (td * tb > 0.0 || ta * tc > 0.0)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
return 0;
}
|
[["-", 51, 16, 12, 16, 12, 23, 0, 16, 12, 22], ["+", 51, 16, 12, 16, 12, 23, 0, 16, 12, 22]]
| 1
| 360
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
char trash;
double x[4], y[4];
while (cin >> x[0] >> trash >> y[0]) {
double a, b, c, d, e, f, t, r;
for (int i = 1; i < 4; i++) {
cin >> trash >> x[i] >> trash >> y[i];
}
a = y[2] - y[0];
b = -x[2] + x[0];
e = -1 * (y[0] * (x[2] - x[0]) - x[0] * (y[2] - y[0]));
c = y[3] - y[1];
d = -x[3] + x[1];
f = -1 * (y[1] * (x[3] - x[1]) - x[1] * (y[3] - y[1]));
t = (e * d - b * f) / (a * d - b * c);
r = (a * f - c * e) / (a * d - b * c);
if (x[2] < x[0]) {
swap(x[0], x[2]);
}
if (x[3] < x[1]) {
swap(x[1], x[3]);
}
if (y[2] < y[0]) {
swap(y[0], y[2]);
}
if (y[3] < y[1]) {
swap(y[1], y[3]);
}
if ((t >= x[0] && t <= x[2]) && (t >= x[1] && t <= x[3]) &&
(r >= y[0] && r < y[2]) && (r >= y[1] && r < y[3])) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
}
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
char trash;
double x[4], y[4];
while (cin >> x[0] >> trash >> y[0]) {
double a, b, c, d, e, f, t, r;
for (int i = 1; i < 4; i++) {
cin >> trash >> x[i] >> trash >> y[i];
}
a = y[2] - y[0];
b = -x[2] + x[0];
e = -1 * (y[0] * (x[2] - x[0]) - x[0] * (y[2] - y[0]));
c = y[3] - y[1];
d = -x[3] + x[1];
f = -1 * (y[1] * (x[3] - x[1]) - x[1] * (y[3] - y[1]));
t = (e * d - b * f) / (a * d - b * c);
r = (a * f - c * e) / (a * d - b * c);
if (x[2] < x[0]) {
swap(x[0], x[2]);
}
if (x[3] < x[1]) {
swap(x[1], x[3]);
}
if (y[2] < y[0]) {
swap(y[0], y[2]);
}
if (y[3] < y[1]) {
swap(y[1], y[3]);
}
if ((t >= x[0] && t <= x[2]) && (t >= x[1] && t <= x[3]) &&
(r >= y[0] && r <= y[2]) && (r >= y[1] && r <= y[3])) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
}
|
[["-", 31, 16, 12, 23, 0, 16, 12, 16, 17, 18], ["+", 31, 16, 12, 23, 0, 16, 12, 16, 17, 19], ["-", 51, 16, 12, 23, 0, 16, 12, 16, 17, 18], ["+", 51, 16, 12, 23, 0, 16, 12, 16, 17, 19]]
| 1
| 464
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.