buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
change_count
int64
0
100
#include <iostream> using namespace std; main() { int n; int w; cin >> n; for (int i = 0; i < n; i++) { cin >> w; cout << "case " << i + 1 << ":" << endl; for (int j = 0; j < 10; j++) { w = w * w; w /= 100; w = w % 10000; cout << w << endl; } } }
#include <iostream> using namespace std; main() { int n; int w; cin >> n; for (int i = 0; i < n; i++) { cin >> w; cout << "Case " << i + 1 << ":" << endl; for (int j = 0; j < 10; j++) { w = w * w; w /= 100; w = w % 10000; cout << w << endl; } } }
[["-", 31, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 31, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
1
95
2
#include <iostream> using namespace std; int main() { int s, n; cin >> n; for (int i = 0; i < n; i++) { cin >> s; cout << "case " << i + 1 << ":\n"; for (int k = 0; k < 10; k++) { s = s * s; s /= 100; s %= 10000; cout << s << endl; } } }
#include <iostream> using namespace std; int main() { long long s, n; cin >> n; for (int i = 0; i < n; i++) { cin >> s; cout << "Case " << i + 1 << ":\n"; for (int k = 0; k < 10; k++) { s = s * s; s /= 100; s %= 10000; cout << s << endl; } } }
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96], ["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
1
92
5
#include <iostream> using namespace std; int main() { int num; int s; int rand; cin >> num; for (int i = 0; i < num; i++) { cin >> s; cout << "Case " << i + 1 << endl; rand = s; for (int j = 0; j < 10; j++) { rand = rand * rand; if (rand >= 1000000) rand %= 1000000; rand /= 100; cout << rand << endl; } } return 0; }
#include <iostream> using namespace std; int main() { int num; int s; int rand; cin >> num; for (int i = 0; i < num; i++) { cin >> s; cout << "Case " << i + 1 << ":" << endl; rand = s; for (int j = 0; j < 10; j++) { rand = rand * rand; if (rand >= 1000000) rand %= 1000000; rand /= 100; cout << rand << endl; } } return 0; }
[["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 62], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 7, 8, 9, 0, 1, 0, 16, 17, 151]]
1
106
4
#include <cmath> #include <iostream> using namespace std; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { int a; cin >> a; cout << "Case" << i << ":" << endl; for (int j = 0; j < 10; j++) { a *= a; a = a / 100; int tmp = a / 10000 * 10000; a = a - tmp; cout << a << endl; } } return 0; }
#include <cmath> #include <iostream> using namespace std; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { int a; cin >> a; cout << "Case " << i << ":" << endl; for (int j = 0; j < 10; j++) { a *= a; a = a / 100; int tmp = a / 10000 * 10000; a = a - tmp; cout << a << endl; } } return 0; }
[["-", 31, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 31, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
1
108
2
#include <stdio.h> int rand(int s); int main() { int i, s, j, n; int a[8]; scanf("%d", &n); j = n; while (n--) { scanf("%d", &s); printf("case %d:\n", j - n); for (i = 0; i < 10; i++) { s = rand(s); printf("%d\n", s); } } return 0; } int rand(int s) { int i, r = 0; s *= s; s /= 100; for (i = 1; i < 1001; i *= 10) { r += (s % 10) * i; s /= 10; } return r; }
#include <stdio.h> int rand(int s); int main() { int i, s, j, n; int a[8]; scanf("%d", &n); j = n; while (n--) { scanf("%d", &s); printf("Case %d:\n", j - n); for (i = 0; i < 10; i++) { s = rand(s); printf("%d\n", s); } } return 0; } int rand(int s) { int i, r = 0; s *= s; s /= 100; for (i = 1; i < 1001; i *= 10) { r += (s % 10) * i; s /= 10; } return r; } /* for(i=0;i<8;i++) a[i] = 0; for(i=0;i<8;i++){ a[i] = s%10; s/=10; } for(i=2;i<6;i++){ s += a[i]*j; j*=10; }*/
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
164
2
#include <iostream> using namespace std; int main() { int n; cin >> n; for (int dataset = 0; dataset < n; dataset++) { int rand; cin >> rand; cout << "Case " << dataset << ':' << endl; for (int i = 0; i < 10; i++) { rand = rand * rand; rand = rand / 100 - (rand / 1000000) * 10000; cout << rand << endl; } } }
#include <iostream> using namespace std; int main() { int n; cin >> n; for (int dataset = 0; dataset < n; dataset++) { int rand; cin >> rand; cout << "Case " << dataset + 1 << ':' << endl; for (int i = 0; i < 10; i++) { rand = rand * rand; rand = rand / 100 - (rand / 1000000) * 10000; cout << rand << endl; } } }
[["+", 0, 16, 31, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 16, 31, 16, 31, 16, 12, 16, 12, 13]]
1
98
2
#include <iostream> using namespace std; int rand(int a) { return a = a * a / 100 - a * a / 1000000 * 10000; } int main() { int d, l; cin >> d; for (int i = 1; i <= d; i++) { cin >> l; cout << "case " << i << ":" << endl; for (int j = 0; j < 10; j++) { l = rand(l); cout << l << endl; } } }
#include <iostream> using namespace std; int rand(int a) { return a = a * a / 100 - a * a / 1000000 * 10000; } int main() { int d, l; cin >> d; for (int i = 1; i <= d; i++) { cin >> l; cout << "Case " << i << ":" << endl; for (int j = 0; j < 10; j++) { l = rand(l); cout << l << endl; } } }
[["-", 31, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 31, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
1
109
2
#include <iostream> using namespace std; int main(void) { int n, m; cin >> m; for (int i = 1; i <= m; i++) { cin >> n; cout << "case " << i << ":" << endl; for (int j = 0; j < 10; j++) { n = n * n; n = ((n % 1000000) / 100); cout << n << endl; } } }
#include <iostream> using namespace std; int main(void) { int n, m; cin >> m; for (int i = 1; i <= m; i++) { cin >> n; cout << "Case " << i << ":" << endl; for (int j = 0; j < 10; j++) { n = n * n; n = ((n % 1000000) / 100); cout << n << endl; } } }
[["-", 31, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 31, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
1
96
2
#include <algorithm> #include <iostream> #include <sstream> #include <string> using namespace std; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { int in; cin >> in; cout << "Case" << " " << i << endl; for (int j = 0; j < 10; j++) { in *= in; in = in % 1000000; in /= 100; cout << in << endl; } } }
#include <algorithm> #include <iostream> #include <sstream> #include <string> using namespace std; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { int in; cin >> in; cout << "Case" << " " << i << ":" << endl; for (int j = 0; j < 10; j++) { in *= in; in = in % 1000000; in /= 100; cout << in << endl; } } }
[["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 62], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 7, 8, 9, 0, 1, 0, 16, 17, 151]]
1
98
4
#include <cstdio> #include <iostream> using namespace std; int main() { int n; int s; cin >> n; for (int i = 0; i < n; i++) { cin >> s; cout << "Case" << i + 1 << ":" << endl; for (int i = 0; i < 10; i++) { s *= s; s /= 100; s %= 10000; cout << s << endl; } } }
#include <cstdio> #include <iostream> using namespace std; int main() { int n; int s; cin >> n; for (int i = 0; i < n; i++) { cin >> s; cout << "Case " << i + 1 << ":" << endl; for (int i = 0; i < 10; i++) { s *= s; s /= 100; s %= 10000; cout << s << endl; } } }
[["-", 31, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 31, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
1
94
2
k = int(input()) for j in range(k): x = int(input()) print(("Case " + str(k + 1))) for i in range(10): x = "00000000" + str(x**2) x = int(x[-6:-2]) print(x)
n = int(input()) for j in range(n): x = int(input()) print(("Case " + str(j + 1) + ":")) for i in range(10): x = "00000000" + str(x**2) x = int(x[-6:-2]) print(x)
[["-", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22], ["-", 0, 656, 0, 7, 12, 652, 3, 4, 0, 22], ["+", 0, 656, 0, 7, 12, 652, 3, 4, 0, 22], ["-", 0, 657, 12, 652, 3, 4, 0, 657, 31, 22], ["+", 31, 657, 12, 652, 3, 4, 0, 657, 31, 22], ["+", 0, 652, 3, 4, 0, 23, 0, 657, 17, 72], ["+", 3, 4, 0, 23, 0, 657, 12, 557, 0, 654], ["+", 3, 4, 0, 23, 0, 657, 12, 557, 0, 6], ["+", 3, 4, 0, 23, 0, 657, 12, 557, 0, 655]]
5
76
10
n = int(input()) for i in range(n): s = int(input()) print("Case {}:".format(i+1)) for _ in range(10): s = int("{:08d}".format(s ** 2)[2:7]) print(s)
n = int(input()) for i in range(n): s = int(input()) print("Case {}:".format(i+1)) for _ in range(10): s = int("{:08d}".format(s ** 2)[2:6]) print(s)
[["-", 12, 652, 3, 4, 0, 206, 206, 663, 0, 612], ["+", 12, 652, 3, 4, 0, 206, 206, 663, 0, 612]]
5
69
2
import sys R = lambda:list(map(int,input().split())) digit = 4 n = int(input()) for i in range(n): s = int(input()) ran = [] for j in range(10): s2 = str(s*s) s2 = s2.zfill(8) #print s2 s = int(s2[digit-2:digit+2]) ran.append(s) print("Case %d" % (i+1)) for j in range(len(ran)): print(ran[j])
import sys R = lambda:list(map(int,input().split())) digit = 4 n = int(input()) for i in range(n): s = int(input()) ran = [] for j in range(10): s2 = str(s*s) s2 = s2.zfill(8) #print s2 s = int(s2[digit-2:digit+2]) ran.append(s) print("Case %d:" % (i+1)) for j in range(len(ran)): print(ran[j])
[["-", 0, 652, 3, 4, 0, 657, 31, 557, 0, 6], ["+", 0, 652, 3, 4, 0, 657, 31, 557, 0, 6]]
5
128
2
#define _USE_MATH_DEFINES #include <algorithm> #include <cfloat> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; int main() { map<double, string> s; vector<double> t1(8); vector<double> t2(8); vector<double> t3(8); vector<double> t4; for (int i = 0; i < 8; i++) { string a; cin >> a >> t1[i]; s[t1[i]] = a; } for (int i = 0; i < 8; i++) { string a; cin >> a >> t2[i]; s[t2[i]] = a; } for (int i = 0; i < 8; i++) { string a; cin >> a >> t3[i]; s[t3[i]] = a; } sort(t1.begin(), t1.end()); sort(t2.begin(), t2.end()); sort(t3.begin(), t3.end()); for (int i = 2; i < 8; i++) { t4.push_back(t1[i]); t4.push_back(t2[i]); t4.push_back(t3[i]); } sort(t4.begin(), t4.end()); cout << s[t1[0]] << " " << t1[0] << endl; cout << s[t1[1]] << " " << t2[1] << endl; cout << s[t2[0]] << " " << t2[0] << endl; cout << s[t2[1]] << " " << t2[1] << endl; cout << s[t3[0]] << " " << t3[0] << endl; cout << s[t3[1]] << " " << t3[1] << endl; cout << s[t4[0]] << " " << t4[0] << endl; cout << s[t4[1]] << " " << t4[1] << endl; }
#define _USE_MATH_DEFINES #include <algorithm> #include <cfloat> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; int main() { map<double, string> s; vector<double> t1(8); vector<double> t2(8); vector<double> t3(8); vector<double> t4; for (int i = 0; i < 8; i++) { string a; cin >> a >> t1[i]; s[t1[i]] = a; } for (int i = 0; i < 8; i++) { string a; cin >> a >> t2[i]; s[t2[i]] = a; } for (int i = 0; i < 8; i++) { string a; cin >> a >> t3[i]; s[t3[i]] = a; } sort(t1.begin(), t1.end()); sort(t2.begin(), t2.end()); sort(t3.begin(), t3.end()); for (int i = 2; i < 8; i++) { t4.push_back(t1[i]); t4.push_back(t2[i]); t4.push_back(t3[i]); } sort(t4.begin(), t4.end()); cout << s[t1[0]] << " " << t1[0] << endl; cout << s[t1[1]] << " " << t1[1] << endl; cout << s[t2[0]] << " " << t2[0] << endl; cout << s[t2[1]] << " " << t2[1] << endl; cout << s[t3[0]] << " " << t3[0] << endl; cout << s[t3[1]] << " " << t3[1] << endl; cout << s[t4[0]] << " " << t4[0] << endl; cout << s[t4[1]] << " " << t4[1] << endl; }
[["-", 0, 1, 0, 16, 31, 16, 12, 69, 28, 22], ["+", 0, 1, 0, 16, 31, 16, 12, 69, 28, 22]]
1
469
2
#include <algorithm> #include <iostream> using namespace std; #define MAX_N 8000 #define MAX_M 23994 pair<double, int> a[MAX_N]; pair<double, int> b[MAX_N]; pair<double, int> c[MAX_N]; pair<double, int> d[MAX_M]; void _cin(int p) { for (int i = 0; i < p; i++) { cin >> a[i].second >> a[i].first; } for (int i = 0; i < p; i++) { cin >> b[i].second >> b[i].first; } for (int i = 0; i < p; i++) { cin >> b[i].second >> b[i].first; } } void sort1(int p) { sort(a, a + p); sort(b, b + p); sort(c, c + p); for (int i = 0; i < 6; i++) { d[i].first = a[i + 2].first; d[i].second = a[i + 2].second; } for (int i = 0; i < 6; i++) { d[i + p - 2].first = b[i + 2].first; d[i + p - 2].second = b[i + 2].second; } for (int i = 0; i < 6; i++) { d[i + p + p - 4].first = c[i + 2].first; d[i + p + p - 4].second = c[i + 2].second; } sort(d, d + p * 3 - 6); } void print() { cout << a[0].second << ' ' << a[0].first << endl; cout << a[1].second << ' ' << a[1].first << endl; cout << b[0].second << ' ' << b[0].first << endl; cout << b[1].second << ' ' << b[1].first << endl; cout << c[0].second << ' ' << c[0].first << endl; cout << c[1].second << ' ' << c[1].first << endl; cout << d[0].second << ' ' << d[0].first << endl; cout << d[1].second << ' ' << d[1].first << endl; } int main() { _cin(8); sort1(8); print(); return 0; }
#include <algorithm> #include <iostream> using namespace std; #define MAX_N 8000 #define MAX_M 23994 pair<double, int> a[MAX_N]; pair<double, int> b[MAX_N]; pair<double, int> c[MAX_N]; pair<double, int> d[MAX_M]; void _cin(int p) { for (int i = 0; i < p; i++) { cin >> a[i].second >> a[i].first; } for (int i = 0; i < p; i++) { cin >> b[i].second >> b[i].first; } for (int i = 0; i < p; i++) { cin >> c[i].second >> c[i].first; } } void sort1(int p) { sort(a, a + p); sort(b, b + p); sort(c, c + p); for (int i = 0; i < 6; i++) { d[i].first = a[i + 2].first; d[i].second = a[i + 2].second; } for (int i = 0; i < 6; i++) { d[i + p - 2].first = b[i + 2].first; d[i + p - 2].second = b[i + 2].second; } for (int i = 0; i < 6; i++) { d[i + p + p - 4].first = c[i + 2].first; d[i + p + p - 4].second = c[i + 2].second; } sort(d, d + p * 3 - 6); } void print() { cout << a[0].second << ' ' << a[0].first << endl; cout << a[1].second << ' ' << a[1].first << endl; cout << b[0].second << ' ' << b[0].first << endl; cout << b[1].second << ' ' << b[1].first << endl; cout << c[0].second << ' ' << c[0].first << endl; cout << c[1].second << ' ' << c[1].first << endl; cout << d[0].second << ' ' << d[0].first << endl; cout << d[1].second << ' ' << d[1].first << endl; } int main() { _cin(8); sort1(8); print(); return 0; }
[["-", 0, 16, 31, 16, 12, 118, 28, 69, 28, 22], ["+", 0, 16, 31, 16, 12, 118, 28, 69, 28, 22], ["-", 0, 1, 0, 16, 12, 118, 28, 69, 28, 22], ["+", 0, 1, 0, 16, 12, 118, 28, 69, 28, 22]]
1
579
4
#define _USE_MATH_DEFINES #include <algorithm> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define EPS 1e-10 using namespace std; typedef long long llong; bool f(pair<int, double> a, pair<int, double> b) { return a.second < b.second; } int main() { vector<pair<int, double>> v(24); for (int i = 0; i < 24; i++) { cin >> v[i].first >> v[i].second; } // cout << endl << endl; sort(v.begin(), v.begin() + 8, f); cout << v[0].first << " " << v[0].second << endl; cout << v[1].first << " " << v[0].second << endl; sort(v.begin() + 8, v.begin() + 8 + 8, f); cout << v[8].first << " " << v[8].second << endl; cout << v[9].first << " " << v[9].second << endl; sort(v.begin() + 8 + 8, v.end(), f); cout << v[16].first << " " << v[16].second << endl; cout << v[17].first << " " << v[17].second << endl; v.erase(v.begin() + 8 + 8, v.begin() + 8 + 8 + 2); v.erase(v.begin() + 8, v.begin() + 8 + 2); v.erase(v.begin(), v.begin() + 2); sort(v.begin(), v.end(), f); cout << v[0].first << " " << v[0].second << endl; cout << v[1].first << " " << v[0].second << endl; return 0; }
#define _USE_MATH_DEFINES #include <algorithm> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define EPS 1e-10 using namespace std; typedef long long llong; bool f(pair<int, double> a, pair<int, double> b) { return a.second < b.second; } int main() { vector<pair<int, double>> v(24); for (int i = 0; i < 24; i++) { cin >> v[i].first >> v[i].second; } // cout << endl << endl; // cout << setprecision(4); sort(v.begin(), v.begin() + 8, f); cout << v[0].first << " " << v[0].second << endl; cout << v[1].first << " " << v[1].second << endl; sort(v.begin() + 8, v.begin() + 8 + 8, f); cout << v[8].first << " " << v[8].second << endl; cout << v[9].first << " " << v[9].second << endl; sort(v.begin() + 8 + 8, v.end(), f); cout << v[16].first << " " << v[16].second << endl; cout << v[17].first << " " << v[17].second << endl; v.erase(v.begin() + 8 + 8, v.begin() + 8 + 8 + 2); v.erase(v.begin() + 8, v.begin() + 8 + 2); v.erase(v.begin(), v.begin() + 2); sort(v.begin(), v.end(), f); cout << v[0].first << " " << v[0].second << endl; cout << v[1].first << " " << v[1].second << endl; return 0; }
[["-", 31, 16, 12, 118, 28, 69, 341, 342, 0, 13], ["+", 31, 16, 12, 118, 28, 69, 341, 342, 0, 13]]
1
457
4
cat rb.rb sum = 0; n = gets.to_i n.times do sum += gets.to_i end puts sum/n
sum = 0; n = gets.to_i n.times do sum += gets.to_i end puts sum/n
[["-", 36, 36, 36, 36, 0, 493, 0, 652, 735, 22], ["-", 0, 493, 0, 652, 3, 4, 0, 652, 486, 22], ["-", 0, 493, 0, 652, 3, 4, 0, 652, 17, 131], ["-", 0, 493, 0, 652, 3, 4, 0, 652, 735, 22]]
4
27
4
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String ans[] = new String[n]; for (int i = 0; i < n; i++) { String s = sc.next(); String ss[] = s.split(":"); int h = Integer.parseInt(ss[0]); int m = Integer.parseInt(ss[1]); int k = Math.abs(60 * h + m - 12 * m); if (k < 60 || k > 660) { ans[i] = "alert"; } else if (k >= 180 && k <= 360) { ans[i] = "safe"; } else { ans[i] = "warning"; } } for (int i = 0; i < n; i++) { System.out.println(ans[i]); } } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String ans[] = new String[n]; for (int i = 0; i < n; i++) { String s = sc.next(); String ss[] = s.split(":"); int h = Integer.parseInt(ss[0]); int m = Integer.parseInt(ss[1]); int k = Math.abs(60 * h + m - 12 * m); if (k < 60 || k > 660) { ans[i] = "alert"; } else if (k >= 180 && k <= 540) { ans[i] = "safe"; } else { ans[i] = "warning"; } } for (int i = 0; i < n; i++) { System.out.println(ans[i]); } } }
[["-", 75, 57, 15, 15, 0, 16, 12, 16, 12, 499], ["+", 75, 57, 15, 15, 0, 16, 12, 16, 12, 499]]
3
221
2
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for (int i = 0; i < n; i++) { String[] s = sc.next().split(":"); double a = Double.parseDouble(s[0]) * 60; double b = Double.parseDouble(s[1]) * 11; double d = Math.min(Math.abs((a - b) / 2), Math.abs((-a + b) / 2)); if (d >= 180) d = 360 - d; System.out.println(d < 30 ? "alert" : 90 < d ? "warning" : "safe"); } } }
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for (int i = 0; i < n; i++) { String[] s = sc.next().split(":"); double a = Double.parseDouble(s[0]) * 60; double b = Double.parseDouble(s[1]) * 11; double d = Math.min(Math.abs((a - b) / 2), Math.abs((-a + b) / 2)); if (d >= 180) d = 360 - d; System.out.println(d < 30 ? "alert" : d < 90 ? "warning" : "safe"); } } }
[["-", 3, 4, 0, 510, 75, 510, 15, 16, 31, 499], ["-", 3, 4, 0, 510, 75, 510, 15, 16, 17, 18], ["+", 3, 4, 0, 510, 75, 510, 15, 16, 17, 18], ["+", 3, 4, 0, 510, 75, 510, 15, 16, 12, 499]]
3
181
4
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for (int i = 0; i < n; i++) { String[] s = sc.next().split(":"); int c = Math.abs(Integer.parseInt(s[0]) * 120 - Integer.parseInt(s[1]) * 22); // double d=Math.min(c,360-c); // System.out.println(d<30?"alert":d<90?"warning":"safe"); System.out.println(c < 60 || c > 660 ? "alert" : c < 180 || c > 540 ? "warning" : "safe"); } } }
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for (int i = 0; i < n; i++) { String[] s = sc.next().split(":"); int c = Math.abs(Integer.parseInt(s[0]) * 60 - Integer.parseInt(s[1]) * 11); // double d=Math.min(c,360-c); // System.out.println(d<30?"alert":d<90?"warning":"safe"); System.out.println(c < 60 || c > 660 ? "alert" : c < 180 || c > 540 ? "warning" : "safe"); } } }
[["-", 51, 492, 3, 4, 0, 16, 31, 16, 12, 499], ["+", 51, 492, 3, 4, 0, 16, 31, 16, 12, 499], ["-", 51, 492, 3, 4, 0, 16, 12, 16, 12, 499], ["+", 51, 492, 3, 4, 0, 16, 12, 16, 12, 499]]
3
146
4
#include <stdio.h> int main() { int n, h, m; scanf("%d", &n); while (n--) { scanf("%d:%d", &h, &m); h = h * 300 + m; m *= 60; h = abs(h - m); if (h > 60 * 60 - h) h = 60 * 60 - h; if (h < 5 * 60) printf("alert\n"); else if (h < 15 * 60) printf("warning\n"); else /*if(h< 45*60)*/ printf("safe\n"); // else if(h<=55*60)printf("warning\n"); // else printf("alert\n"); } return 0; }
#include <stdio.h> int main() { int n, h, m; scanf("%d", &n); while (n--) { scanf("%d:%d", &h, &m); h = h * 300 + m * 5; m *= 60; h = abs(h - m); if (h > 60 * 60 - h) h = 60 * 60 - h; if (h < 5 * 60) printf("alert\n"); else if (h < 15 * 60) printf("warning\n"); else printf("safe\n"); } return 0; }
[["+", 0, 1, 0, 11, 12, 16, 12, 16, 17, 48], ["+", 0, 1, 0, 11, 12, 16, 12, 16, 12, 13]]
0
132
2
#define _CRT_SECURE_NO_WARNINGS //#define _USE_MATH_DEFINES #include <stdio.h> //#include<stdlib.h> #include <math.h> //#include<string.h> #define P(type, x) fprintf(stdout, "%" #type "\n", x) int main() { int h, m, n; double s, l, t, d; fscanf(stdin, "%d", &n); s = l = 0.0; while (n--) { fscanf(stdin, "%d%*c%d", &h, &m); l = m * 6.0; s = h * 30.0 + 30.0 * m / 60.0; if (l < s) t = l, l = s, s = t; d = (l - s) > 180 ? 360 - l - s : l - s; if (d < 30.0) puts("alert"); else if (d < 90.0) puts("warning"); else puts("safe"); } return 0; }
#define _CRT_SECURE_NO_WARNINGS //#define _USE_MATH_DEFINES #include <stdio.h> //#include<stdlib.h> #include <math.h> //#include<string.h> #define P(type, x) fprintf(stdout, "%" #type "\n", x) int main() { int h, m, n; double s, l, t, d; fscanf(stdin, "%d", &n); s = l = 0.0; while (n--) { fscanf(stdin, "%d%*c%d", &h, &m); l = m * 6.0; s = h * 30.0 + 30.0 * m / 60.0; if (l < s) t = l, l = s, s = t; d = (l - s) > 180 ? 360 - l + s : l - s; if (d < 30.0) puts("alert"); else if (d < 90.0) puts("warning"); else puts("safe"); } return 0; }
[["-", 0, 1, 0, 11, 12, 41, 64, 16, 17, 33], ["+", 0, 1, 0, 11, 12, 41, 64, 16, 17, 72]]
0
173
2
#include <math.h> #include <stdio.h> int main() { int i, h, m, num; double l, s, d; scanf("%d", &num); for (i = 0; i < num; i++) { scanf("%d:%d", &h, &m); l = h * 30 + m * 0.5; s = m * 6; d = fabs(l - s); if (d > 180) { d = 360 - d; } if (90 <= d && d <= 180) { puts("safe"); } else if (!(0 <= d && d <= 30)) { puts("warning"); } else { puts("alert"); } } return 0; }
#include <math.h> #include <stdio.h> int main() { int i, h, m, num; double l, s, d; scanf("%d", &num); for (i = 0; i < num; i++) { scanf("%d:%d", &h, &m); l = h * 30 + m * 0.5; s = m * 6; d = fabs(l - s); if (d > 180) { d = 360 - d; } if (90 <= d && d <= 180) { puts("safe"); } else if (30 <= d && d <= 90) { puts("warning"); } else { puts("alert"); } } return 0; }
[["-", 75, 76, 0, 57, 15, 23, 0, 91, 17, 111], ["-", 0, 57, 15, 23, 0, 91, 28, 23, 0, 24], ["-", 0, 91, 28, 23, 0, 16, 31, 16, 31, 13], ["+", 0, 57, 15, 23, 0, 16, 31, 16, 31, 13], ["-", 0, 91, 28, 23, 0, 16, 12, 16, 12, 13], ["-", 0, 57, 15, 23, 0, 91, 28, 23, 0, 25], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 12, 13]]
0
158
7
#include <stdio.h> int main() { int i; long long n = 0; int d, e = 0; double a, b, c = 0; scanf("%lld", &n); for (i = 0; i < n; i++) { scanf("%d:%d", &d, &e); a = (double)d * 30 + (double)e * 0.5; b = (double)e * 6; if ((b - a) >= 0 && 180 >= (b - a)) { c = b - a; } else if ((a - b) >= 0 && 180 >= (a - b)) { c = a - b; } else if (b - a > 180) { b = 360 - b; c = a + b; } else if (b - a < 0) { b = 360 - a; c = a + b; } if (c >= 0 && c < 30) { printf("alert\n"); } else if (90 <= c && c <= 180) { printf("safe\n"); } else { printf(",warning\n"); } } return (0); }
#include <stdio.h> int main() { int i; long long n = 0; int d, e = 0; double a, b, c = 0; scanf("%lld", &n); for (i = 0; i < n; i++) { scanf("%d:%d", &d, &e); a = (double)d * 30 + (double)e * 0.5; b = (double)e * 6; if ((b - a) >= 0 && 180 >= (b - a)) { c = b - a; } else if ((a - b) >= 0 && 180 >= (a - b)) { c = a - b; } else if ((b - a) > 180) { b = 360 - b; c = a + b; } else if ((b - a) < 0) { a = 360 - a; c = a + b; } if (c >= 0 && c < 30) { printf("alert\n"); } else if (90 <= c && c <= 180) { printf("safe\n"); } else { printf("warning\n"); } } return (0); }
[["+", 0, 57, 15, 23, 0, 16, 31, 23, 0, 24], ["+", 0, 57, 15, 23, 0, 16, 31, 23, 0, 25], ["+", 0, 57, 75, 76, 0, 57, 15, 23, 0, 24], ["-", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
252
8
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <string> #include <vector> #define pb(in, tmp) in.push_back(tmp) #define loop(i, a, b) for (int i = a; i < b; i++) #define rep(i, b) loop(i, 0, b) #define all(in) in.begin(), in.end() const double PI = acos(-1); using namespace std; int main() { int n; cin >> n; while (n--) { int a, b; char d; cin >> a >> d >> b; double h = abs(30.0 * a - 6.5 * b); // cout<<h<<endl; if (h < 30 || 360 - h < 30) cout << "alert" << endl; else if (h >= 90 && h <= 270) cout << "safe" << endl; else cout << "warning" << endl; } }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <string> #include <vector> #define pb(in, tmp) in.push_back(tmp) #define loop(i, a, b) for (int i = a; i < b; i++) #define rep(i, b) loop(i, 0, b) #define all(in) in.begin(), in.end() const double PI = acos(-1); using namespace std; int main() { int n; cin >> n; while (n--) { int a, b; char d; cin >> a >> d >> b; double h = abs(30.0 * a - 5.5 * b); // cout<<h<<endl; if (h < 30 || 360 - h < 30) cout << "alert" << endl; else if (h >= 90 && h <= 270) cout << "safe" << endl; else cout << "warning" << endl; } }
[["-", 51, 2, 3, 4, 0, 16, 12, 16, 31, 13], ["+", 51, 2, 3, 4, 0, 16, 12, 16, 31, 13]]
1
158
2
#include <algorithm> #include <cmath> #include <cstdio> using namespace std; double ang(double a, double b) { return min(abs(a - b), 360 - abs(a - b)); } int main() { int n; for (scanf("%d", &n); n--;) { double a, b; scanf("%lf:%lf", &a, &b); a = a * 30 + b / 20; b = b * 6; if (ang(a, b) < 30) puts("alert"); else if (ang(a, b) < 90) puts("warning"); else puts("safe"); } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> using namespace std; double ang(double a, double b) { return min(abs(a - b), 360 - abs(a - b)); } int main() { int n; for (scanf("%d", &n); n--;) { double a, b; scanf("%lf:%lf", &a, &b); a = a * 30 + b / 2; b = b * 6; if (ang(a, b) < 30) puts("alert"); else if (ang(a, b) < 90) puts("warning"); else puts("safe"); } return 0; }
[["-", 0, 1, 0, 11, 12, 16, 12, 16, 12, 13], ["+", 0, 1, 0, 11, 12, 16, 12, 16, 12, 13]]
1
150
2
#include <math.h> #include <stdio.h> int main() { int n, i; scanf("%d", &n); for (i = 0; i < n; i++) { int h, m, x; scanf("%d:%d", &h, &m); x = fmod(5.5 * (60 * h + m), 360); if ((x >= 0 && x < 30) || x > 330) { printf("alert\n"); } else if (x >= 90 && x <= 270) { printf("safe\n"); } else { printf("warning\n"); } } return 0; }
#include <math.h> #include <stdio.h> int main() { int n, i; scanf("%d", &n); for (i = 0; i < n; i++) { int h, m; double x; scanf("%d:%d", &h, &m); x = fmod(5.5 * (60 * h + m), 360); if ((x >= 0 && x < 30) || x > 330) { printf("alert\n"); } else if (x >= 90 && x <= 270) { printf("safe\n"); } else { printf("warning\n"); } } return 0; }
[["-", 8, 9, 0, 7, 8, 9, 0, 43, 0, 21], ["+", 8, 9, 0, 7, 8, 9, 0, 43, 0, 35], ["+", 8, 9, 0, 7, 8, 9, 0, 43, 39, 40]]
1
138
3
#include <cmath> #include <cstdio> #include <iostream> int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { int h, m; scanf("%d:%d", &h, &m); long double ang; ang = 6 * m - (30 * h + 30 * ((long double)m / 60)); ang = std::abs(ang); if (ang > 180) ang -= 180; if (0 <= ang && ang < 30) printf("alert\n"); else if (90 <= ang && ang <= 180) printf("safe\n"); else printf("warning\n"); } return 0; }
#include <cmath> #include <cstdio> #include <iostream> int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { int h, m; scanf("%d:%d", &h, &m); long double ang; ang = 6 * m - (30 * h + 30 * ((long double)m / 60)); ang = std::abs(ang); if (ang > 180) ang = 360 - ang; if (0 <= ang && ang < 30) printf("alert\n"); else if (90 <= ang && ang <= 180) printf("safe\n"); else printf("warning\n"); } return 0; }
[["-", 8, 9, 0, 57, 64, 1, 0, 11, 17, 110], ["-", 8, 9, 0, 57, 64, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 57, 64, 1, 0, 11, 17, 32], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 31, 13], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 17, 33], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 12, 22]]
1
155
6
#include <stdio.h> int main() { int n; double h, m; double g = 0, gm = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%lf:%lf", &h, &m); g = 30 * h; gm = 6 * m; g += (30 / 60 * m); double H = 0; H = gm - g; if (H < 0) H *= -1; if (H > 180) H = 360 - H; if (H < 30) printf("alert\n"); else if (H < 90) printf("warning\n"); else if (H <= 180) printf("safe\n"); } return 0; }
#include <stdio.h> int main() { int n; double h, m; double g = 0, gm = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%lf:%lf", &h, &m); g = 30 * h; gm = 6 * m; g += (0.5 * m); double H = 0; H = gm - g; if (H < 0) H *= -1; if (H > 180) H = 360 - H; if (H < 30) printf("alert\n"); else if (H < 90) printf("warning\n"); else if (H <= 180) printf("safe\n"); } return 0; }
[["-", 0, 11, 12, 23, 0, 16, 31, 16, 31, 13], ["-", 0, 11, 12, 23, 0, 16, 31, 16, 17, 85], ["-", 0, 11, 12, 23, 0, 16, 31, 16, 12, 13], ["+", 0, 1, 0, 11, 12, 23, 0, 16, 31, 13]]
1
166
4
#include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <stack> #include <stdio.h> #include <string.h> #include <vector> #define range(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, b) range(i, 0, b) #define debug(x) cout << "debug " << x << endl; using namespace std; int main() { int n; while (cin >> n) { rep(i, n) { double hour, mini; scanf("%lf%*c%lf", &hour, &mini); double angle1 = (hour * 300 + mini * 5); double angle2 = (mini * 60); double angle = sqrt((angle1 - angle2) * (angle1 - angle2)); if (angle > 1800) angle -= 1800; if (angle >= 0 && angle < 300) cout << "alert" << endl; else if (angle >= 900 && angle <= 1800) cout << "safe" << endl; else cout << "warning" << endl; } } }
#include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <stack> #include <stdio.h> #include <string.h> #include <vector> #define range(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, b) range(i, 0, b) #define debug(x) cout << "debug " << x << endl; using namespace std; int main() { int n; while (cin >> n) { rep(i, n) { double hour, mini; scanf("%lf%*c%lf", &hour, &mini); double angle1 = (hour * 300 + mini * 5); double angle2 = (mini * 60); double angle = sqrt((angle1 - angle2) * (angle1 - angle2)); if (angle > 1800) angle = 3600 - angle; if (angle >= 0 && angle < 300) cout << "alert" << endl; else if (angle >= 900 && angle <= 1800) cout << "safe" << endl; else cout << "warning" << endl; } } }
[["-", 8, 9, 0, 57, 64, 1, 0, 11, 17, 110], ["-", 8, 9, 0, 57, 64, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 57, 64, 1, 0, 11, 17, 32], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 31, 13], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 17, 33], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 12, 22]]
1
187
6
#include <bits/stdc++.h> #define rep(i, l, n) for (int i = l; i < n; i++) #define rer(i, l, n) for (int i = l; i <= n; i++) #define all(a) a.begin(), a.end() #define o(a) cout << a << endl #define pb(a) push_back(a) #define mk(a, b) make_pair(a, b) #define fi first #define se second using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; int main() { int n; cin >> n; double h, m; rep(i, 0, n) { scanf("%lf:%lf", &h, &m); if (h >= 12) h -= 12; h = 30 * h + 0.5 * m; m = 6 * m; double ans = abs(h - m); o(ans); if (ans > 180) ans = 360 - ans; if (ans < 30) o("alert"); else if (ans >= 90) o("safe"); else o("warning"); } }
#include <bits/stdc++.h> #define rep(i, l, n) for (int i = l; i < n; i++) #define rer(i, l, n) for (int i = l; i <= n; i++) #define all(a) a.begin(), a.end() #define o(a) cout << a << endl #define pb(a) push_back(a) #define mk(a, b) make_pair(a, b) #define fi first #define se second using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; int main() { int n; cin >> n; double h, m; rep(i, 0, n) { scanf("%lf:%lf", &h, &m); if (h >= 12) h -= 12; h = 30 * h + 0.5 * m; m = 6 * m; double ans = abs(h - m); // o(ans); if (ans > 180) ans = 360 - ans; if (ans < 30) o("alert"); else if (ans >= 90) o("safe"); else o("warning"); } }
[["-", 8, 9, 0, 9, 0, 1, 0, 2, 63, 22], ["-", 0, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["-", 0, 9, 0, 1, 0, 2, 3, 4, 0, 22], ["-", 0, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["-", 0, 14, 8, 9, 0, 9, 0, 1, 0, 35]]
1
216
5
#include <cmath> #include <cstdio> #include <iostream> using namespace std; int a, b, n; double d, e, f; int main() { cin >> n; for (int i = 0; i < n; i++) { scanf("%d:%d", &a, &b); f = abs(a * 30 + b * 11.0 / 2.0); if (f > 180) { f = 360 - f; } if (f < 30) { cout << "alert" << endl; } else if (f < 90) { cout << "warning" << endl; } else { cout << "safe" << endl; } } }
#include <cmath> #include <cstdio> #include <iostream> using namespace std; int a, b, n; double d, e, f; int main() { cin >> n; for (int i = 0; i < n; i++) { scanf("%d:%d", &a, &b); f = abs(a * 30 - b * 11.0 / 2.0); if (f > 180) { f = 360 - f; } if (f < 30) { cout << "alert" << endl; } else if (f < 90) { cout << "warning" << endl; } else { cout << "safe" << endl; } } }
[["-", 0, 11, 12, 2, 3, 4, 0, 16, 17, 72], ["+", 0, 11, 12, 2, 3, 4, 0, 16, 17, 33]]
1
136
2
#include <bits/stdc++.h> using namespace std; int main() { int n, h, s; double a, b, ans; cin >> n; while (n--) { scanf("%d:%d", &h, &s); b = s * 6; a = h * 30 + b / 360; ans = abs(a - b); if (ans > 180) ans = 360 - ans; if (0 <= ans && ans < 30) cout << "alert" << endl; else if (90 <= ans && ans <= 180) cout << "safe" << endl; else cout << "warning" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, h, s; double a, b, ans; cin >> n; while (n--) { scanf("%d:%d", &h, &s); b = s * 6; a = h * 30 + 30 * b / 360; ans = abs(a - b); if (ans > 180) ans = 360 - ans; if (0 <= ans && ans < 30) cout << "alert" << endl; else if (90 <= ans && ans <= 180) cout << "safe" << endl; else cout << "warning" << endl; } return 0; }
[["+", 0, 11, 12, 16, 12, 16, 31, 16, 31, 13], ["+", 0, 11, 12, 16, 12, 16, 31, 16, 17, 48]]
1
136
2
#include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <functional> #include <iostream> #include <map> #include <memory> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long LL; typedef pair<int, int> PII; static const double EPS = 1e-5; #define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i) #define REP(i, n) FOR(i, 0, n) int main(void) { int n; cin >> n; REP(i, n) { int h, m; scanf("%d:%d", &h, &m); if (h >= 12) h -= 12; double t1 = h * 30 + (double)m / 4; double t2 = m * 6; if (abs(t1 - t2) < 30 || abs(t1 - t2) > 330) { cout << "alert" << endl; } else if (abs(t1 - t2) >= 90 && abs(t1 - t2) <= 270) { cout << "safe" << endl; } else { cout << "warning" << endl; } } return 0; }
#include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <functional> #include <iostream> #include <map> #include <memory> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long LL; typedef pair<int, int> PII; static const double EPS = 1e-5; #define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i) #define REP(i, n) FOR(i, 0, n) int main(void) { int n; cin >> n; REP(i, n) { int h, m; scanf("%d:%d", &h, &m); if (h >= 12) h -= 12; double t1 = h * 30 + (double)m / 2; double t2 = m * 6; if (abs(t1 - t2) < 30 || abs(t1 - t2) > 330) { cout << "alert" << endl; } else if (abs(t1 - t2) >= 90 && abs(t1 - t2) <= 270) { cout << "safe" << endl; } else { cout << "warning" << endl; } } return 0; }
[["-", 0, 43, 49, 50, 51, 16, 12, 16, 12, 13], ["+", 0, 43, 49, 50, 51, 16, 12, 16, 12, 13]]
1
229
2
#include <algorithm> #include <cassert> #include <cctype> #include <complex> #include <cstdio> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; int n, h, m; char com; double s, l; int main() { cin >> n; while (cin >> h >> com >> m) { s = 6.0 * m; l = 0.5 * (h * 60 + m); double a = l - s; if (a < 0) a *= -1; a = min(a, 180.0); if (a < 30) cout << "alert" << endl; else if (a < 90) cout << "warning" << endl; else cout << "safe" << endl; } }
#include <algorithm> #include <cassert> #include <cctype> #include <complex> #include <cstdio> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; int n, h, m; char com; double s, l; int main() { cin >> n; while (cin >> h >> com >> m) { s = 6.0 * m; l = 0.5 * (h * 60 + m); double a = l - s; if (a < 0) a *= -1; a = min(a, 360.0 - a); if (a < 30) cout << "alert" << endl; else if (a < 90) cout << "warning" << endl; else cout << "safe" << endl; } }
[["-", 0, 1, 0, 11, 12, 2, 3, 4, 0, 13], ["+", 0, 11, 12, 2, 3, 4, 0, 16, 31, 13], ["+", 0, 11, 12, 2, 3, 4, 0, 16, 17, 33], ["+", 0, 11, 12, 2, 3, 4, 0, 16, 12, 22]]
1
149
4
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <typeinfo> #include <utility> #include <vector> using namespace std; #define dump(n) cout << "# " << #n << "=" << (n) << endl #define debug(n) \ cout << __FILE__ << "," << __LINE__ << ": #" << #n << "=" << (n) << endl #define repi(i, a, b) for (int i = int(a); i < int(b); i++) #define rep(i, n) repi(i, 0, n) #define iter(c) __typeof((c).begin()) #define foreach(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++) #define allof(c) (c).begin(), (c).end() #define mp make_pair typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<string> vs; typedef pair<int, int> pii; const double EPS = 1e-10; int main() { int n; cin >> n; rep(i, n) { int h, m; scanf("%d:%d", &h, &m); //‰~‚ð720•ªŠ„ int ha = h * 60 + m; int ma = m * 12; int da = abs(ha - ma); da = min(da, 720 - da); if (da < 60) cout << "aleart" << endl; else if (da >= 180) cout << "safe" << endl; else cout << "warning" << endl; } return 0; }
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <typeinfo> #include <utility> #include <vector> using namespace std; #define dump(n) cout << "# " << #n << "=" << (n) << endl #define debug(n) \ cout << __FILE__ << "," << __LINE__ << ": #" << #n << "=" << (n) << endl #define repi(i, a, b) for (int i = int(a); i < int(b); i++) #define rep(i, n) repi(i, 0, n) #define iter(c) __typeof((c).begin()) #define foreach(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++) #define allof(c) (c).begin(), (c).end() #define mp make_pair typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<string> vs; typedef pair<int, int> pii; const double EPS = 1e-10; int main() { int n; cin >> n; rep(i, n) { int h, m; scanf("%d:%d", &h, &m); //‰~‚ð720•ªŠ„ int ha = h * 60 + m; int ma = m * 12; int da = abs(ha - ma); da = min(da, 720 - da); if (da < 60) cout << "alert" << endl; else if (da >= 180) cout << "safe" << endl; else cout << "warning" << endl; } return 0; }
[["-", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
278
2
#include <algorithm> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <memory> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; static const double EPS = 1e-5; typedef long long ll; typedef pair<int, int> PI; typedef vector<int> vi; #define rep(i, n) for (int i = 0; i < (int)n; ++i) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define ALL(c) (c).begin(), (c).end() #define mp make_pair #define pb push_back #define f first #define s second main() { int n; cin >> n; while (n--) { long double hh, mm; scanf("%Lf:%Lf", &hh, &mm); hh = 30 * hh + mm * 0.5; mm *= 6; // cout<<hh<<":"<<mm<<endl; int diff = abs(hh - mm); if (mm > hh) diff = abs(mm - hh); if (diff > 180) diff = 360 - diff; if (diff <= 30) puts("alert"); else if (diff >= 90) puts("safe"); else puts("warning"); } }
#include <algorithm> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <memory> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; static const double EPS = 1e-5; typedef long long ll; typedef pair<int, int> PI; typedef vector<int> vi; #define rep(i, n) for (int i = 0; i < (int)n; ++i) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define ALL(c) (c).begin(), (c).end() #define mp make_pair #define pb push_back #define f first #define s second main() { int n; cin >> n; while (n--) { long double hh, mm; scanf("%Lf:%Lf", &hh, &mm); hh = 30 * hh + mm * 0.5; mm *= 6; // cout<<hh<<":"<<mm<<endl; long double diff = abs(hh - mm); if (mm > hh) diff = abs(mm - hh); if (diff > 180) diff = 360 - diff; if (diff < 30) puts("alert"); else if (diff >= 90) puts("safe"); else puts("warning"); } }
[["-", 8, 9, 0, 52, 8, 9, 0, 43, 39, 40], ["+", 0, 52, 8, 9, 0, 43, 39, 86, 0, 96], ["+", 0, 52, 8, 9, 0, 43, 39, 86, 39, 40], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18]]
1
232
5
#include <cstdio> #include <iostream> using namespace std; int different(double h, double m) { h += m / 120; double a = h - m; if (a < 0) a = -a; if (360 - a < a) a = 360 - a; return a; } int main(int argc, char const *argv[]) { double h, m; int n; cin >> n; for (int i = 0; i < n; i++) { scanf("%lf:%lf", &h, &m); h *= 30; m *= 6; double answer = different(h, m); if (answer >= 0 && answer < 30) cout << "alert" << endl; else if (answer >= 90 && answer <= 180) cout << "safe" << endl; else cout << "warning" << endl; } return 0; }
#include <cstdio> #include <iostream> using namespace std; int different(double h, double m) { h += m / 12; double a = h - m; if (a < 0) a = -a; if (360 - a < a) a = 360 - a; return a; } int main(int argc, char const *argv[]) { double h, m; int n; cin >> n; for (int i = 0; i < n; i++) { scanf("%lf:%lf", &h, &m); h *= 30; m *= 6; double answer = different(h, m); if (answer >= 0 && answer < 30) cout << "alert" << endl; else if (answer >= 90 && answer <= 180) cout << "safe" << endl; else cout << "warning" << endl; } return 0; }
[["-", 8, 9, 0, 1, 0, 11, 12, 16, 12, 13], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 12, 13]]
1
183
2
#include <algorithm> #include <cmath> #include <cstdlib> #include <iostream> #include <string> #include <vector> using namespace std; #define EPS (1e-10) #define EQ(a, b) (abs((a) - (b)) < EPS) int main() { int n; cin >> n; for (int i = 0; i < n; i++) { string str; double lg, sh; cin >> str; lg = atoi(str.substr(0, 2).c_str()) * 30; sh = ((atoi(str.substr(3, 2).c_str()))) * 6; lg += ((double)sh / 120); double dis = abs(lg - sh); dis = min(dis, 360 - dis); if ((dis > 0 || EQ(dis, 0)) && dis < 30) { cout << "alert" << endl; } else if ((dis > 90 || EQ(dis, 90)) && (dis < 180 || EQ(dis, 180))) { cout << "safe" << endl; } else { cout << "warning" << endl; } } return 0; }
#include <algorithm> #include <cmath> #include <cstdlib> #include <iostream> #include <string> #include <vector> using namespace std; #define EPS (1e-10) #define EQ(a, b) (abs((a) - (b)) < EPS) int main() { int n; cin >> n; for (int i = 0; i < n; i++) { string str; double lg, sh; cin >> str; lg = atoi(str.substr(0, 2).c_str()) * 30; sh = ((atoi(str.substr(3, 2).c_str()))) * 6; lg += ((double)sh / 12); double dis = abs(lg - sh); dis = min(dis, 360 - dis); if ((dis > 0 || EQ(dis, 0)) && dis < 30) { cout << "alert" << endl; } else if ((dis > 90 || EQ(dis, 90)) && (dis < 180 || EQ(dis, 180))) { cout << "safe" << endl; } else { cout << "warning" << endl; } } return 0; }
[["-", 0, 1, 0, 11, 12, 23, 0, 16, 12, 13], ["+", 0, 1, 0, 11, 12, 23, 0, 16, 12, 13]]
1
226
2
#include <algorithm> #include <bitset> #include <cfloat> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; int main() { int n; cin >> n; while (--n >= 0) { int h, m; char c; cin >> h >> c >> m; int a = 60 * h - 11 * m; if (a < 30 * 2 || a > 330 * 2) cout << "alert" << endl; else if (90 * 2 <= a && a <= 270 * 2) cout << "safe" << endl; else cout << "warning" << endl; } return 0; }
#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; int main() { int n; cin >> n; while (--n >= 0) { int h, m; char c; cin >> h >> c >> m; int a = abs(60 * h - 11 * m); if (a < 30 * 2 || a > 330 * 2) cout << "alert" << endl; else if (90 * 2 <= a && a <= 270 * 2) cout << "safe" << endl; else cout << "warning" << endl; } return 0; }
[["+", 8, 9, 0, 43, 49, 50, 51, 2, 63, 22], ["+", 0, 43, 49, 50, 51, 2, 3, 4, 0, 24], ["+", 0, 43, 49, 50, 51, 2, 3, 4, 0, 25]]
1
142
3
#include <cstdio> int main() { int n; scanf("%d", &n); while (n--) { int h, m; scanf("%d:%d", &h, &m); int diff = h * 300 - m * 55; if (diff < 0) diff *= -1; if (diff > 1800) diff = 3600 - diff; if (0 <= diff && diff <= 300) puts("alert"); else if (900 <= diff && diff <= 1800) puts("safe"); else puts("warning"); } return 0; }
#include <cstdio> int main() { int n; scanf("%d", &n); while (n--) { int h, m; scanf("%d:%d", &h, &m); int diff = h * 300 - m * 55; if (diff < 0) diff *= -1; if (diff > 1800) diff = 3600 - diff; if (0 <= diff && diff < 300) puts("alert"); else if (900 <= diff && diff <= 1800) puts("safe"); else puts("warning"); } return 0; }
[["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 19], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 18]]
1
125
2
#include <cmath> #include <iostream> #include <string> using namespace std; double degree(int h, int m) { double s = m * 6; double l = h * 30 + m * 0.5; double d = abs(l - s); if (d >= 180) d -= 180; return d; } string judge(int h, int m) { double d = degree(h, m); if (d < 30) return "alert"; else if (d < 90) return "warning"; return "safe"; } int main() { int n; cin >> n; while (n--) { int h, m; char d; cin >> h >> d >> m; cout << judge(h, m) << endl; } return 0; }
#include <cmath> #include <iostream> #include <string> using namespace std; double degree(int h, int m) { double s = m * 6; double l = h * 30 + m * 0.5; double d = abs(l - s); if (d > 180) d = 360 - d; return d; } string judge(int h, int m) { double d = degree(h, m); if (d < 30) return "alert"; else if (d < 90) return "warning"; return "safe"; } int main() { int n; cin >> n; while (n--) { int h, m; char d; cin >> h >> d >> m; cout << judge(h, m) << endl; } return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["-", 8, 9, 0, 57, 64, 1, 0, 11, 17, 110], ["-", 8, 9, 0, 57, 64, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 57, 64, 1, 0, 11, 17, 32], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 31, 13], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 17, 33], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 12, 22]]
1
161
8
#include <algorithm> #include <cmath> #include <cstring> #include <iostream> #include <map> #include <string> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define REP(n) rep(i, n) #define all(n) n.begin(), n.end() int main() { int n; cin >> n; double h, m; char t; double lv, sv; REP(n) { cin >> h >> t >> m; lv = m * 360 / 60; //[deg] sv = (h * 360 / 12) + m * 15 / 60; double dd = fabs(lv - sv); if (dd > 180) dd = 360 - dd; if (fabs(dd) < 30) { cout << "alert" << endl; continue; } if (fabs(dd) < 90) { cout << "warning" << endl; continue; } cout << "safe" << endl; } return 0; }
#include <algorithm> #include <cmath> #include <cstring> #include <iostream> #include <map> #include <string> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define REP(n) rep(i, n) #define all(n) n.begin(), n.end() int main() { int n; cin >> n; double h, m; char t; double lv, sv; REP(n) { cin >> h >> t >> m; lv = m * 360 / 60; //[deg] sv = (h * 360 / 12) + m * 30 / 60; double dd = fabs(lv - sv); if (dd > 180) dd = 360 - dd; if (fabs(dd) < 30) { cout << "alert" << endl; continue; } if (fabs(dd) < 90) { cout << "warning" << endl; continue; } cout << "safe" << endl; } return 0; }
[["-", 0, 11, 12, 16, 12, 16, 31, 16, 12, 13], ["+", 0, 11, 12, 16, 12, 16, 31, 16, 12, 13]]
1
178
2
#include <cstdio> #include <cstdlib> #include <iostream> using namespace std; int main(void) { int n; double h, m; double ans; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%lf:%lf", &h, &m); h = h * 30 + m / 4; m = m * 6; if (h > m) ans = h - m; else ans = m - h; if (ans < 30 || ans > 330) cout << "alert" << endl; else if (90 <= ans && ans <= 270) cout << "safe" << endl; else cout << "warning" << endl; } return 0; }
#include <cstdio> #include <cstdlib> #include <iostream> using namespace std; int main(void) { int n; double h, m; double ans; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%lf:%lf", &h, &m); h = h * 30 + m / 2; m = m * 6; if (h > m) ans = h - m; else ans = m - h; if (ans < 30 || ans > 330) cout << "alert" << endl; else if (90 <= ans && ans <= 270) cout << "safe" << endl; else cout << "warning" << endl; } return 0; }
[["-", 0, 1, 0, 11, 12, 16, 12, 16, 12, 13], ["+", 0, 1, 0, 11, 12, 16, 12, 16, 12, 13]]
1
151
2
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> using namespace std; #define fr first #define sc second #define INF 100 typedef pair<int, int> Pt; int main() { int n; double H, M, hh, mm, mini; scanf("%d", &n); while (n--) { scanf("%lf:%lf", &hh, &mm); H = hh * 30.0 + mm * 0.25; M = mm * 6.0; mini = fabs(H - M); if (H < M) H += 360.0; else M += 360.0; mini = min(mini, fabs(H - M)); if (mini < 30) cout << "alert" << endl; else if (mini >= 90) cout << "safe" << endl; else cout << "warning" << endl; } }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> using namespace std; #define fr first #define sc second #define INF 100 typedef pair<int, int> Pt; int main() { int n; double H, M, hh, mm, mini; scanf("%d", &n); while (n--) { scanf("%lf:%lf", &hh, &mm); H = hh * 30.0 + mm * 0.5; M = mm * 6.0; mini = fabs(H - M); if (H < M) H += 360.0; else M += 360.0; mini = min(mini, fabs(H - M)); if (mini < 30) cout << "alert" << endl; else if (mini >= 90) cout << "safe" << endl; else cout << "warning" << endl; } }
[["-", 0, 1, 0, 11, 12, 16, 12, 16, 12, 13], ["+", 0, 1, 0, 11, 12, 16, 12, 16, 12, 13]]
1
178
2
#include <iostream> #include <string> using namespace std; int main() { int n; while (cin >> n) { for (int i = 0; i < n; ++i) { int h, m; char dummy; cin >> h >> dummy >> m; int hAngle = h * 300 + m * 10 / 4; int mAngle = m * 10 * 360 / 60; int angle = hAngle > mAngle ? hAngle - mAngle : mAngle - hAngle; string message; if ((angle < 300 && angle >= 0) || (angle <= 3600 && angle > 3300)) { message = "alert"; } else if ((angle >= 900 && angle <= 2700)) { message = "safe"; } else { message = "warning"; } cout << message << endl; } } return 0; }
#include <iostream> #include <string> using namespace std; int main() { int n; while (cin >> n) { for (int i = 0; i < n; ++i) { int h, m; char dummy; cin >> h >> dummy >> m; int hAngle = h * 300 + m * 10 / 2; int mAngle = m * 10 * 360 / 60; int angle = hAngle > mAngle ? hAngle - mAngle : mAngle - hAngle; string message; if ((angle < 300 && angle >= 0) || (angle <= 3600 && angle > 3300)) { message = "alert"; } else if ((angle >= 900 && angle <= 2700)) { message = "safe"; } else { message = "warning"; } cout << message << endl; } } return 0; }
[["-", 0, 43, 49, 50, 51, 16, 12, 16, 12, 13], ["+", 0, 43, 49, 50, 51, 16, 12, 16, 12, 13]]
1
168
2
n = gets.chomp.to_i n.times do h, m = gets.chomp.split(':').map(&:to_f) diff = (h * 30 + m * 0.5 - m * 6).abs diff = 360 - diff if diff > 180 puts diff if diff < 30 puts :alert elsif diff < 90 puts :warning else puts :safe end end
n = gets.chomp.to_i n.times do h, m = gets.chomp.split(':').map(&:to_f) diff = (h * 30 + m * 0.5 - m * 6).abs diff = 360 - diff if diff > 180 if diff < 30 puts :alert elsif diff < 90 puts :warning else puts :safe end end
[["-", 0, 652, 196, 737, 8, 736, 0, 652, 735, 22], ["-", 196, 737, 8, 736, 0, 652, 3, 4, 0, 22]]
4
76
2
def angle(h, m) v = (30 * h + m/2.0 - 6 * m).abs v > 180 ? v - 180 : v end def to_msg(angle) if angle < 30 "alert" elsif angle >= 90 "safe" else "warning" end end gets.to_i.times do h, m = gets.split(":").map(&:to_i) puts to_msg(angle(h, m)) end
def angle(h, m) v = (30 * h + m/2.0 - 6 * m).abs v > 180 ? (v - 360).abs : v end def to_msg(angle) if angle < 30 "alert" elsif angle >= 90 "safe" else "warning" end end gets.to_i.times do h, m = gets.split(":").map(&:to_i) puts to_msg(angle(h, m)) end
[["+", 8, 736, 0, 754, 64, 652, 486, 739, 0, 24], ["-", 0, 735, 8, 736, 0, 754, 64, 738, 12, 612], ["+", 0, 754, 64, 652, 486, 739, 0, 738, 12, 612], ["+", 8, 736, 0, 754, 64, 652, 486, 739, 0, 25], ["+", 0, 735, 8, 736, 0, 754, 64, 652, 17, 131], ["+", 0, 735, 8, 736, 0, 754, 64, 652, 735, 22]]
4
94
6
n = eval(input()) for i in range(n): h,m = list(map(int, input().split(":"))) sangle = 1.0 * 360 * (h * 60 + m) / 720 langle = 1.0 * 360 * m / 60 angle = abs(sangle - langle) if angle > 180: angle = 360 - d if (0 <= angle < 30): print("alert") elif (90 <= angle <= 180): print("safe") else: print("warning")
n = eval(input()) for i in range(n): h,m = list(map(int, input().split(":"))) sangle = 1.0 * 360 * (h * 60 + m) / 720 langle = 1.0 * 360 * m / 60 angle = abs(sangle - langle) if angle > 180: angle = 360 - angle if (0 <= angle < 30): print("alert") elif (90 <= angle <= 180): print("safe") else: print("warning")
[["-", 64, 196, 0, 1, 0, 662, 12, 657, 12, 22], ["+", 64, 196, 0, 1, 0, 662, 12, 657, 12, 22]]
5
118
2
for roop in range(int(input())): h,m = list(map(int,input().split(":"))) s = 60*h + m l = 24*m if l > s: l,s = s,l arg = l - s if l - s < 180*4 else 360*4-(l-s) if arg < 30*4: print("alert") elif arg < 90*4: print("warning") else : print("safe")
for roop in range(int(input())): h,m = list(map(int,input().split(":"))) s = 60*h + m l = 12*m if l < s: l,s = s,l arg = l - s if l - s < 180*2 else 360*2-(l-s) if arg < 30*2: print("alert") elif arg < 90*2: print("warning") else : print("safe")
[["-", 8, 196, 0, 1, 0, 662, 12, 657, 31, 612], ["+", 8, 196, 0, 1, 0, 662, 12, 657, 31, 612], ["-", 0, 7, 8, 196, 0, 57, 15, 666, 667, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 666, 667, 18], ["-", 0, 662, 12, 41, 0, 666, 0, 657, 12, 612], ["+", 0, 662, 12, 41, 0, 666, 0, 657, 12, 612], ["-", 0, 662, 12, 41, 0, 657, 31, 657, 12, 612], ["+", 0, 662, 12, 41, 0, 657, 31, 657, 12, 612], ["-", 8, 196, 0, 57, 15, 666, 0, 657, 12, 612], ["+", 8, 196, 0, 57, 15, 666, 0, 657, 12, 612], ["-", 0, 57, 75, 665, 15, 666, 0, 657, 12, 612], ["+", 0, 57, 75, 665, 15, 666, 0, 657, 12, 612]]
5
116
12
for _ in [0] * int(input()): a, b = list(map(int, input().split(':'))) b = b/60.0 x = abs((a+b)-b*12) if x>6: x=12-6 if x<1: print('alert') elif 3<=x: print('safe') else: print('warning')
for _ in [0] * int(input()): a, b = list(map(int, input().split(':'))) b = b/60.0 x = abs((a+b)-b*12) if x>6: x=12-x if x<1: print('alert') elif 3<=x: print('safe') else: print('warning')
[["-", 64, 196, 0, 1, 0, 662, 12, 657, 12, 612], ["+", 64, 196, 0, 1, 0, 662, 12, 657, 12, 22]]
5
95
2
n=int(input()) for i in range(n): t=[int(x) for x in input().split(':')] longdeg=t[1]*360/60. shortdeg=t[0]*360/12.+t[1]*12/60. (longdeg,shortdeg)=(max(longdeg,shortdeg),min(longdeg,shortdeg)) dist=min(longdeg-shortdeg,360-(longdeg-shortdeg)) if dist<30: print('alert') elif dist>=90: print('safe') else: print('warning')
n=int(input()) for i in range(n): t=[int(x) for x in input().split(':')] longdeg=t[1]*360/60. shortdeg=t[0]*360/12.+t[1]*30/60. (longdeg,shortdeg)=(max(longdeg,shortdeg),min(longdeg,shortdeg)) dist=min(longdeg-shortdeg,360-(longdeg-shortdeg)) if dist<30: print('alert') elif dist>=90: print('safe') else: print('warning')
[["-", 0, 662, 12, 657, 12, 657, 31, 657, 12, 612], ["+", 0, 662, 12, 657, 12, 657, 31, 657, 12, 612]]
5
133
2
n=int(input()) t=[[int(num)for num in input().split(':')]for i in range(n)] for i in range(n): h=t[i][0] m=t[i][1] an_s=h*30+m/60 an_l=m*6 dif=0 if abs(an_s-an_l)<180:dif=abs(an_s-an_l) else:dif=360-abs(an_s-an_l) if dif<30: print("alert") elif dif<90: print("warning") else: print("safe")
n=int(input()) t=[[int(num)for num in input().split(':')]for i in range(n)] for i in range(n): h=t[i][0] m=t[i][1] an_s=h*30+m/2 an_l=m*6 dif=0 if abs(an_s-an_l)<180:dif=abs(an_s-an_l) else:dif=360-abs(an_s-an_l) if dif<30: print("alert") elif dif<90: print("warning") else: print("safe")
[["-", 0, 1, 0, 662, 12, 657, 12, 657, 12, 612], ["+", 0, 1, 0, 662, 12, 657, 12, 657, 12, 612]]
5
141
2
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0135 WA """ import sys from sys import stdin from math import sqrt, acos, cos, sin, radians, degrees input = stdin.readline def solve(time): # 12????????????90??? short_hand_angle = time[1] * -6 + 90 x_s = cos(radians(short_hand_angle)) y_s = sin(radians(short_hand_angle)) long_hand_angle = (time[0]*60+time[1])/(12*60) * -360 + 90 x_l = cos(radians(long_hand_angle)) y_l = sin(radians(long_hand_angle)) c = (x_s * x_l + y_s * y_l) / (sqrt(x_s**2 + y_s**2) * sqrt(x_l**2 + y_l**2)) ans = degrees(acos(c)) if ans < 30: return 'alert' elif ans >= 90: return 'safe' else: return 'warning' def main(args): # n = int(input()) n = 1 for _ in range(n): time = [int(x) for x in input().split(':')] result = solve(time) print(result) if __name__ == '__main__': main(sys.argv[1:])
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0135 WA """ import sys from sys import stdin from math import sqrt, acos, cos, sin, radians, degrees input = stdin.readline def solve(time): # 12????????????90??? short_hand_angle = time[1] * -6 + 90 x_s = cos(radians(short_hand_angle)) y_s = sin(radians(short_hand_angle)) long_hand_angle = (time[0]*60+time[1])/(12*60) * -360 + 90 x_l = cos(radians(long_hand_angle)) y_l = sin(radians(long_hand_angle)) c = (x_s * x_l + y_s * y_l) / (sqrt(x_s**2 + y_s**2) * sqrt(x_l**2 + y_l**2)) ans = degrees(acos(c)) if ans < 30: return 'alert' elif ans >= 90: return 'safe' else: return 'warning' def main(args): n = int(input()) # n = 1 for _ in range(n): time = [int(x) for x in input().split(':')] result = solve(time) print(result) if __name__ == '__main__': main(sys.argv[1:])
[["-", 0, 14, 8, 196, 0, 1, 0, 662, 12, 612], ["+", 8, 196, 0, 1, 0, 662, 12, 652, 63, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["+", 0, 662, 12, 652, 3, 4, 0, 652, 63, 22], ["+", 12, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["+", 12, 652, 3, 4, 0, 652, 3, 4, 0, 25], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 25]]
5
243
7
# Clock Short Hand and Long Hand n = int(input()) for i in range(n): h, m = list(map(int, input().split(':'))) h *= 30.0 h += m * 0.5 m *= 6.0 d = abs(m - h) if d > 180: d = 360 - d print(d) if 0 <= d < 30: print("alert") elif 90 <= d <= 180: print("safe") else: print("warning")
# Clock Short Hand and Long Hand n = int(input()) for i in range(n): h, m = list(map(int, input().split(':'))) h *= 30.0 h += m * 0.5 m *= 6.0 d = abs(m - h) if d > 180: d = 360 - d if 0 <= d < 30: print("alert") elif 90 <= d <= 180: print("safe") else: print("warning")
[["-", 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, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 25]]
5
106
4
import static java.util.Arrays.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class Main { static void tr(Object... os) { System.err.println(deepToString(os)); } void solve() { int n = sc.nextInt(); int[] count = new int[6]; for (int i = 0; i < n; i++) { count[cate(sc.nextDouble())]++; } for (int i = 0; i < count.length; i++) { out.print(i + ":"); for (int j = 0; j < count[i]; j++) { out.print("*"); } out.println(); } } int cate(double x) { if (x < 165.0) return 0; if (x < 170.0) return 1; if (x < 175.0) return 2; if (x < 180.0) return 3; if (x < 185.0) return 4; return 5; } public static void main(String[] args) throws Exception { new Main().run(); } MyScanner sc = null; PrintWriter out = null; public void run() throws Exception { sc = new MyScanner(System.in); out = new PrintWriter(System.out); for (; sc.hasNext();) { solve(); out.flush(); } out.close(); } class MyScanner { String line; BufferedReader reader; StringTokenizer tokenizer; public MyScanner(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); tokenizer = null; } public void eat() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { line = reader.readLine(); if (line == null) { tokenizer = null; return; } tokenizer = new StringTokenizer(line); } catch (IOException e) { throw new RuntimeException(e); } } } public String next() { eat(); return tokenizer.nextToken(); } public String nextLine() { try { return reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } public boolean hasNext() { eat(); return (tokenizer != null && tokenizer.hasMoreElements()); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } } }
import static java.util.Arrays.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class Main { static void tr(Object... os) { System.err.println(deepToString(os)); } void solve() { int n = sc.nextInt(); int[] count = new int[6]; for (int i = 0; i < n; i++) { count[cate(sc.nextDouble())]++; } for (int i = 0; i < count.length; i++) { out.print((1 + i) + ":"); for (int j = 0; j < count[i]; j++) { out.print("*"); } out.println(); } } int cate(double x) { if (x < 165.0) return 0; if (x < 170.0) return 1; if (x < 175.0) return 2; if (x < 180.0) return 3; if (x < 185.0) return 4; return 5; } public static void main(String[] args) throws Exception { new Main().run(); } MyScanner sc = null; PrintWriter out = null; public void run() throws Exception { sc = new MyScanner(System.in); out = new PrintWriter(System.out); for (; sc.hasNext();) { solve(); out.flush(); } out.close(); } class MyScanner { String line; BufferedReader reader; StringTokenizer tokenizer; public MyScanner(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); tokenizer = null; } public void eat() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { line = reader.readLine(); if (line == null) { tokenizer = null; return; } tokenizer = new StringTokenizer(line); } catch (IOException e) { throw new RuntimeException(e); } } } public String next() { eat(); return tokenizer.nextToken(); } public String nextLine() { try { return reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } public boolean hasNext() { eat(); return (tokenizer != null && tokenizer.hasMoreElements()); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } } }
[["+", 0, 492, 3, 4, 0, 16, 31, 23, 0, 24], ["+", 3, 4, 0, 16, 31, 23, 0, 16, 31, 499], ["+", 3, 4, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 492, 3, 4, 0, 16, 31, 23, 0, 25]]
3
621
4
import java.util.*; public class Main { public static void main(String[] args) throws java.io.IOException { Scanner scan = new Scanner(System.in); // Queue<Pair> fifo = new LinkedList<Pair>(); int rank[] = {0, 0, 0, 0, 0, 0}; // ArrayList <Double> mou =new ArrayList <Double>(); int c = scan.nextInt(); while (c != 0) { double n = scan.nextDouble(); if (n >= 185.0) rank[5]++; else if (n >= 180.0) rank[4]++; else if (n >= 175.0) rank[3]++; else if (n >= 170.0) rank[2]++; else if (n >= 165.0) rank[1]++; else rank[0]++; c--; } for (int i = 0; i < 6; i++) { if (rank[i] == 0) System.out.println(i + ":"); else { String str = ""; for (int j = 0; j < rank[i]; j++) str += "*"; System.out.println(i + ":" + str); } } } }
import java.util.*; public class Main { public static void main(String[] args) throws java.io.IOException { Scanner scan = new Scanner(System.in); // Queue<Pair> fifo = new LinkedList<Pair>(); int rank[] = {0, 0, 0, 0, 0, 0}; // ArrayList <Double> mou =new ArrayList <Double>(); int c = scan.nextInt(); while (c != 0) { double n = scan.nextDouble(); if (n >= 185.0) rank[5]++; else if (n >= 180.0) rank[4]++; else if (n >= 175.0) rank[3]++; else if (n >= 170.0) rank[2]++; else if (n >= 165.0) rank[1]++; else rank[0]++; c--; } for (int i = 0; i < 6; i++) { if (rank[i] == 0) System.out.println(i + 1 + ":"); else { String str = ""; for (int j = 0; j < rank[i]; j++) str += "*"; System.out.println(i + 1 + ":" + str); } } } }
[["+", 0, 492, 3, 4, 0, 16, 31, 16, 12, 499], ["+", 64, 1, 0, 492, 3, 4, 0, 16, 17, 72], ["+", 3, 4, 0, 16, 31, 16, 31, 16, 17, 72], ["+", 3, 4, 0, 16, 31, 16, 31, 16, 12, 499]]
3
247
4
import java.util.Scanner; public class Main { void io() { Scanner s = new Scanner(System.in); int n = s.nextInt(); int[] histgram = new int[6]; for (int i = 0; i < n; ++i) { double height = s.nextDouble(); if (height < 165.0) { ++histgram[0]; } else if (height < 170.0) { ++histgram[1]; } else if (height < 175.0) { ++histgram[2]; } else if (height < 180.0) { ++histgram[3]; } else if (height < 185.0) { ++histgram[4]; } else { ++histgram[5]; } } for (int i = 0; i < 6; ++i) { System.out.print((i + 1) + ": "); for (int k = 0; k < histgram[i]; ++k) { System.out.print('*'); } System.out.println(); } s.close(); } public static void main(String[] args) { new Main().io(); } }
import java.util.Scanner; public class Main { void io() { Scanner s = new Scanner(System.in); int n = s.nextInt(); int[] histgram = new int[6]; for (int i = 0; i < n; ++i) { double height = s.nextDouble(); if (height < 165.0) { ++histgram[0]; } else if (height < 170.0) { ++histgram[1]; } else if (height < 175.0) { ++histgram[2]; } else if (height < 180.0) { ++histgram[3]; } else if (height < 185.0) { ++histgram[4]; } else { ++histgram[5]; } } for (int i = 0; i < 6; ++i) { System.out.print((i + 1) + ":"); for (int k = 0; k < histgram[i]; ++k) { System.out.print('*'); } System.out.println(); } s.close(); } public static void main(String[] args) { new Main().io(); } }
[["-", 0, 492, 3, 4, 0, 16, 12, 5, 0, 491], ["+", 0, 492, 3, 4, 0, 16, 12, 5, 0, 491]]
3
253
2
#include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <string> #include <vector> using namespace std; const int MAX = 10000100; #define loop(i, a, b) for (int i = a; i < b; i++) #define rep(i, a) loop(i, 0, a) #define all(a) (a).begin(), (a).end() #define ll long long int #define gcd(a, b) __gcd(a, b) int GCD(int a, int b) { if (!b) return a; return gcd(b, a % b); } int lcm(int a, int b) { return a * b / gcd(a, b); } #define N 15 int d[N] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1}; int main(void) { int n; while (n--) { int a, b; cin >> a >> b; if (a <= 5 && b < a) { a = 15 - a; } while (d[a] != b) { cout << d[a] << " "; a = (a + 1) % N; } cout << d[a] << endl; } }
#include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <string> #include <vector> using namespace std; const int MAX = 10000100; #define loop(i, a, b) for (int i = a; i < b; i++) #define rep(i, a) loop(i, 0, a) #define all(a) (a).begin(), (a).end() #define ll long long int #define gcd(a, b) __gcd(a, b) int GCD(int a, int b) { if (!b) return a; return gcd(b, a % b); } int lcm(int a, int b) { return a * b / gcd(a, b); } #define N 15 int d[N] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1}; int main(void) { int n; cin >> n; while (n--) { int a, b; cin >> a >> b; if (a <= 5 && b < a) { a = 15 - a; } while (d[a] != b) { cout << d[a] << " "; a = (a + 1) % N; } cout << d[a] << endl; } }
[["+", 0, 14, 8, 9, 0, 1, 0, 16, 31, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 17, 152], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 12, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35]]
1
241
4
#include <climits> #include <iostream> #include <memory> #include <vector> class Bus_stop { public: Bus_stop(const int &i) : id{i}, mins(10, INT_MAX - 1), prevs(10, nullptr) { mins.at(i) = 0; }; //?¬?????????????????¨???? void set_next(Bus_stop &other) { // this ?????? other ???????????????????????? sub_next( other); // other // ???????????????????¨???????????£???????????????????????????? } //??¨??????????????¢?´¢ void search_route() { call_sub_search( mins); // private???????????????mins???virtual??¢??°?????±??§??????????????????????????? }; std::vector<int> get_route(const int &from, const int &to) const { return move(to)->sub_route(from); } protected: // Bus_stop???ID int id; //?????????????????´??°??¨????¬??????¢?´¢???????§????????????? void sub_search(Bus_stop *next, const std::vector<int> &ms) { if (next->renew(ms, this)) { //?????????????????´??°????????£?????? next->search_route(); //?¬??????¢?´¢???????§? } } private: //???????????????????°?????????? std::vector<int> mins; //????°???????????????¨???"???????????????"?????????????????? std::vector<Bus_stop *> prevs; // mins??¨prevs?????´??°?????´??°???????????°true???????????°false bool renew(const std::vector<int> &prev, Bus_stop *from) { bool res = false; for (auto i = 0; i < prev.size(); ++i) { if (prev.at(i) + 1 < mins.at(i)) { mins.at(i) = prev.at(i) + 1; prevs.at(i) = from; res = true; } } return res; } //?????????????§???? const Bus_stop *move(const int &to) const { if (to == id) { return this; } else { return prevs.at(to)->move(to); } } std::vector<int> sub_route(const int &from) const { if (from == id) { return std::vector<int>{from}; } else { auto res = prevs.at(from)->sub_route(from); res.push_back(id); return res; } } //?¬???????????????????????????¢?´¢ virtual void call_sub_search(const std::vector<int> &) = 0; //?¬?????????????????¨???? virtual void sub_next(Bus_stop &) = 0; }; class Loop_stop : public Bus_stop { public: Loop_stop(const int &i) : Bus_stop(i), next{nullptr} {}; private: void sub_next(Bus_stop &other) override { next = &other; } void call_sub_search(const std::vector<int> &mins) override { sub_search(next, mins); } Bus_stop *next; }; class Line_stop : public Bus_stop { public: Line_stop(const int &i) : Bus_stop(i), next1{nullptr}, next2{nullptr} {}; private: void sub_next(Bus_stop &other) override { if (next1) { next2 = &other; } else { next1 = &other; } } void call_sub_search(const std::vector<int> &mins) override { sub_search(next1, mins); sub_search(next2, mins); } Bus_stop *next1, *next2; }; void show(std::vector<int> &route) { std::cout << route.at(0); for (auto i = 1; i < route.size(); ++i) { std::cout << ' ' << route.at(i); } std::cout << std::endl; } int main() { std::vector<std::shared_ptr<Bus_stop>> stops(15, nullptr); for (auto i = 0; i < 15; ++i) { stops.at(i) = std::make_shared<Loop_stop>(Loop_stop((i < 10) ? i : (15 - i))); } for (auto i = 0; i < 15; ++i) { stops.at(i)->set_next(*stops.at((i + 1) % 15)); } stops.at(0)->search_route(); int n; std::cin >> n; for (auto i = 0; i < n; ++i) { int from, to; std::cin >> from >> to; auto route1 = stops.at(to)->get_route(from, to); auto route2 = stops.at(15 - to)->get_route(from, to); if (route1.size() < route2.size()) { show(route1); } else { show(route2); } } return 0; }
#include <climits> #include <iostream> #include <memory> #include <vector> class Bus_stop { public: Bus_stop(const int &i) : id{i}, mins(10, INT_MAX - 1), prevs(10, nullptr) { mins.at(i) = 0; }; //?¬?????????????????¨???? void set_next(Bus_stop &other) { // this ?????? other ???????????????????????? sub_next( other); // other // ???????????????????¨???????????£???????????????????????????? } //??¨??????????????¢?´¢ void search_route() { call_sub_search( mins); // private???????????????mins???virtual??¢??°?????±??§??????????????????????????? }; std::vector<int> get_route(const int &from, const int &to) const { return move(to)->sub_route(from); } protected: // Bus_stop???ID int id; //?????????????????´??°??¨????¬??????¢?´¢???????§????????????? void sub_search(Bus_stop *next, const std::vector<int> &ms) { if (next->renew(ms, this)) { //?????????????????´??°????????£?????? next->search_route(); //?¬??????¢?´¢???????§? } } private: //???????????????????°?????????? std::vector<int> mins; //????°???????????????¨???"???????????????"?????????????????? std::vector<Bus_stop *> prevs; // mins??¨prevs?????´??°?????´??°???????????°true???????????°false bool renew(const std::vector<int> &prev, Bus_stop *from) { bool res = false; for (auto i = 0; i < prev.size(); ++i) { if (prev.at(i) + 1 < mins.at(i)) { mins.at(i) = prev.at(i) + 1; prevs.at(i) = from; res = true; } } return res; } //?????????????§???? const Bus_stop *move(const int &to) const { if (to == id) { return this; } else { return prevs.at(to)->move(to); } } std::vector<int> sub_route(const int &from) const { if (from == id) { return std::vector<int>{from}; } else { auto res = prevs.at(from)->sub_route(from); res.push_back(id); return res; } } //?¬???????????????????????????¢?´¢ virtual void call_sub_search(const std::vector<int> &) = 0; //?¬?????????????????¨???? virtual void sub_next(Bus_stop &) = 0; }; class Loop_stop : public Bus_stop { public: Loop_stop(const int &i) : Bus_stop(i), next{nullptr} {}; private: void sub_next(Bus_stop &other) override { next = &other; } void call_sub_search(const std::vector<int> &mins) override { sub_search(next, mins); } Bus_stop *next; }; class Line_stop : public Bus_stop { public: Line_stop(const int &i) : Bus_stop(i), next1{nullptr}, next2{nullptr} {}; private: void sub_next(Bus_stop &other) override { if (next1) { next2 = &other; } else { next1 = &other; } } void call_sub_search(const std::vector<int> &mins) override { sub_search(next1, mins); sub_search(next2, mins); } Bus_stop *next1, *next2; }; void show(std::vector<int> &route) { std::cout << route.at(0); for (auto i = 1; i < route.size(); ++i) { std::cout << ' ' << route.at(i); } std::cout << std::endl; } int main() { std::vector<std::shared_ptr<Bus_stop>> stops(15, nullptr); for (auto i = 0; i < 15; ++i) { stops.at(i) = std::make_shared<Loop_stop>(Loop_stop((i < 10) ? i : (15 - i))); } for (auto i = 0; i < 15; ++i) { stops.at(i)->set_next(*stops.at((i + 1) % 15)); } stops.at(0)->search_route(); int n; std::cin >> n; for (auto i = 0; i < n; ++i) { int from, to; std::cin >> from >> to; auto route1 = stops.at(0)->get_route(from, to); auto route2 = stops.at(9)->get_route(from, to); if (route1.size() < route2.size()) { show(route1); } else { show(route2); } } return 0; }
[["-", 51, 2, 63, 118, 28, 2, 3, 4, 0, 22], ["+", 51, 2, 63, 118, 28, 2, 3, 4, 0, 13], ["-", 63, 118, 28, 2, 3, 4, 0, 16, 31, 13], ["-", 63, 118, 28, 2, 3, 4, 0, 16, 17, 33], ["-", 63, 118, 28, 2, 3, 4, 0, 16, 12, 22]]
1
890
6
#include "bits/stdc++.h" #include <unordered_map> #include <unordered_set> #pragma warning(disable : 4996) using namespace std; using ld = long double; const ld eps = 1e-9; //// < "d:\d_download\visual studio ///2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual ///studio 2015\projects\programing_contest_c++\debug\b.txt" int main() { int N; cin >> N; for (int i = 0; i < N; ++i) { int a, b; cin >> a >> b; vector<int> anss; if (a < b) { for (int j = a; j <= b; ++j) { anss.emplace_back(j); } } else if (a == b) { anss.emplace_back(a); } else { if (a <= 5) { for (int j = a; j >= b; --j) { anss.emplace_back(j); } } else { if (b <= 5) { for (int j = a + 1; j <= 9; ++j) { anss.emplace_back(j); } for (int j = 5; j >= b; --j) { anss.emplace_back(j); } } else { for (int j = a + 1; j <= 9; ++j) { anss.emplace_back(j); } for (int j = 5; j >= 0; --j) { anss.emplace_back(j); } for (int j = 1; j <= b; ++j) { anss.emplace_back(j); } } } } for (int i = 0; i < anss.size(); ++i) { cout << anss[i]; if (i == anss.size() - 1) cout << endl; else cout << " "; } } return 0; }
#include "bits/stdc++.h" #include <unordered_map> #include <unordered_set> #pragma warning(disable : 4996) using namespace std; using ld = long double; const ld eps = 1e-9; //// < "d:\d_download\visual studio ///2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual ///studio 2015\projects\programing_contest_c++\debug\b.txt" int main() { int N; cin >> N; for (int i = 0; i < N; ++i) { int a, b; cin >> a >> b; vector<int> anss; if (a < b) { for (int j = a; j <= b; ++j) { anss.emplace_back(j); } } else if (a == b) { anss.emplace_back(a); } else { if (a <= 5) { for (int j = a; j >= b; --j) { anss.emplace_back(j); } } else { if (b <= 5) { for (int j = a; j <= 9; ++j) { anss.emplace_back(j); } for (int j = 5; j >= b; --j) { anss.emplace_back(j); } } else { for (int j = a; j <= 9; ++j) { anss.emplace_back(j); } for (int j = 5; j >= 0; --j) { anss.emplace_back(j); } for (int j = 1; j <= b; ++j) { anss.emplace_back(j); } } } } for (int i = 0; i < anss.size(); ++i) { cout << anss[i]; if (i == anss.size() - 1) cout << endl; else cout << " "; } } return 0; }
[["-", 0, 7, 10, 43, 49, 50, 51, 16, 17, 72], ["-", 0, 7, 10, 43, 49, 50, 51, 16, 12, 13]]
1
342
4
#include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <cstdlib> #include <cstring> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; int main() { const int path[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1}; // cut here before submit // freopen ("testcase.busline2", "r", stdin ); string str = ""; int n; while (getline(cin, str)) { stringstream ssn(str); ssn >> n; if (n == 0) { break; } // end if int i, j, k; for (i = 0; i < n; ++i) { getline(cin, str); if (str.empty()) { break; } // end if vector<int> res; int from, to; stringstream ss(str); ss >> from >> to; int len = sizeof(path) / sizeof(path[0]); if (from < to) { for (j = from; j != to; j = (j + 1) % len) { res.push_back(path[j]); } // end for } else if (from > to) { bool found = (from < 6 ? false : true); for (k = 0; k < len; ++k) { if (path[k] == from) { if (!found) { found = true; continue; } else { break; } // end if } // end if } // end for for (j = k; j != to || path[j] != to; j = (j + 1) % len) { res.push_back(path[j]); } // end for } // end if res.push_back(path[to]); int size = res.size(); for (j = 0; j < size; ++j) { cout << res[j]; if (j != size - 1) { cout << ' '; } // end if } // end for cout << endl; } // end for } // end loop return 0; }
#include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <cstdlib> #include <cstring> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; int main() { const int path[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1}; // cut here before submit // freopen ("testcase.busline2", "r", stdin ); string str = ""; int n; while (getline(cin, str)) { stringstream ssn(str); ssn >> n; if (n == 0) { break; } // end if int i, j, k; for (i = 0; i < n; ++i) { getline(cin, str); if (str.empty()) { break; } // end if vector<int> res; int from, to; stringstream ss(str); ss >> from >> to; int len = sizeof(path) / sizeof(path[0]); if (from < to) { for (j = from; j != to; j = (j + 1) % len) { res.push_back(path[j]); } // end for } else if (from > to) { bool found = (from < 6 ? false : true); for (k = 0; k < len; ++k) { if (path[k] == from) { if (!found) { found = true; continue; } else { break; } // end if } // end if } // end for for (j = k; j != to && path[j] != to; j = (j + 1) % len) { res.push_back(path[j]); } // end for } // end if res.push_back(path[to]); int size = res.size(); for (j = 0; j < size; ++j) { cout << res[j]; if (j != size - 1) { cout << ' '; } // end if } // end for cout << endl; } // end for } // end loop return 0; }
[["-", 0, 57, 64, 9, 0, 7, 15, 16, 17, 106], ["+", 0, 57, 64, 9, 0, 7, 15, 16, 17, 98]]
1
431
2
#include <iostream> using namespace std; int main(void) { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { int f, t; scanf("%d%d", &f, &t); printf("%d", f); if (f <= 5) { if (t > f) { while (f != t) { f++; printf(" %d", f); } } if (t < f) { while (f != t) { f--; printf(" %d", f); } } } if (f > 5) { if (f < t && t <= 9) { while (f != t) { f++; printf(" %d", f); } } else if (t == 5) { while (f != 9) { f++; printf(" %d", f); } f = 5; printf(" %d", f); } else { while (f != 9) { f++; printf(" %d", f); } f = 5; printf(" %d", f); if (t < 5) { while (f != t) { f--; printf(" %d", f); } } else { while (f != 0) { f--; printf(" %d", f); } while (f != t) { f++; printf(" %d", f); } } } } printf("\n"); } return 0; }
#include <iostream> using namespace std; int main(void) { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { int f, t; scanf("%d%d", &f, &t); printf("%d", f); if (f <= 5) { if (t > f) { while (f != t) { f++; printf(" %d", f); } } if (t < f) { while (f != t) { f--; printf(" %d", f); } } } else if (f > 5) { if (f < t && t <= 9) { while (f != t) { f++; printf(" %d", f); } } else if (t == 5) { while (f != 9) { f++; printf(" %d", f); } f = 5; printf(" %d", f); } else { while (f != 9) { f++; printf(" %d", f); } f = 5; printf(" %d", f); if (t < 5) { while (f != t) { f--; printf(" %d", f); } } else { while (f != 0) { f--; printf(" %d", f); } while (f != t) { f++; printf(" %d", f); } } } } printf("\n"); } return 0; }
[["+", 0, 7, 8, 9, 0, 57, 75, 76, 0, 95]]
1
332
1
#include <iostream> #include <string> using namespace std; string bus_stop = "012345678954321012345678954321"; void solve() { int n; cin >> n; while (n--) { char s, g; cin >> s >> g; string ans1, ans2; bool flag = false; int pos = 0; for (int i = 0; i < bus_stop.size(); ++i) { if (!flag && bus_stop[i] == s) { flag = true; pos = i; } if (flag) { ans1 += bus_stop[i]; if (bus_stop[i] == g) { break; } } } flag = false; for (int i = pos + 1; i < bus_stop.size(); ++i) { if (bus_stop[i] == s) { flag = true; } if (flag) { ans2 += bus_stop[i]; if (bus_stop[i] == g) { break; } } } if (ans1.size() < ans2.size()) { cout << ans1[0]; for (int i = 1; i < ans1.size(); ++i) { cout << " " << ans1[i]; } cout << endl; } else { cout << ans2[0]; for (int i = 1; i < ans2.size(); ++i) { cout << " " << ans2[i]; } cout << endl; } } } int main() { solve(); return (0); }
#include <iostream> #include <string> using namespace std; string bus_stop = "0123456789543210123456789543210123456789543210"; void solve() { int n; cin >> n; while (n--) { char s, g; cin >> s >> g; string ans1, ans2; bool flag = false; int pos = 0; for (int i = 0; i < bus_stop.size(); ++i) { if (!flag && bus_stop[i] == s) { flag = true; pos = i; } if (flag) { ans1 += bus_stop[i]; if (bus_stop[i] == g) { break; } } } flag = false; for (int i = pos + 1; i < bus_stop.size(); ++i) { if (bus_stop[i] == s) { flag = true; } if (flag) { ans2 += bus_stop[i]; if (bus_stop[i] == g) { break; } } } if (ans1.size() < ans2.size()) { cout << ans1[0]; for (int i = 1; i < ans1.size(); ++i) { cout << " " << ans1[i]; } cout << endl; } else { cout << ans2[0]; for (int i = 1; i < ans2.size(); ++i) { cout << " " << ans2[i]; } cout << endl; } } } int main() { solve(); return (0); }
[["-", 0, 30, 0, 43, 49, 50, 51, 5, 0, 6], ["+", 0, 30, 0, 43, 49, 50, 51, 5, 0, 6]]
1
314
2
function bomb(y, x, z) { if (yx[y][x] != "+") return; var dy = [ -1, 0, 1, 0 ]; var dx = [ 0, 1, 0, -1 ]; var Y = y + dy[z]; var X = x + dx[z]; if (Y < 0 || X < 0 || Y >= n || X >= n) { z = (z + 1) % 4; bomb(y, x, z); } else { if (yx[Y][X] == "#") { yx[Y - dy[z]][X - dx[z]] = "+"; if (z == 3) bomb(Y - 2 * dy[z] - 1, X - 2 * dx[z], 0); else if (z == 0) bomb(Y - 2 * dy[z], X - 2 * dx[z] + 1, 1); else if (z == 1) bomb(Y - 2 * dy[z] + 1, X - 2 * dx[z], 2); else if (z == 2) bomb(Y - 2 * dy[z], X - 2 * dx[z] - 1, 3); } else { yx[y][x] = "#"; last = [ y, x ]; bomb(Y, X, z); } } } var input = require('fs').readFileSync('/dev/stdin', 'utf8'); var arr = input.trim().split("\n").map(Number); var d = arr.shift(); var str = ""; for (var i = 0; i < d; i++) { if (i != 0) str += "\n\n"; var n = arr.shift(); if (n == 0) { str += ""; continue; } if (n == 1) { str += "#"; continue; } if (n == 2) { str += "##\n# "; continue; } var yx = []; for (var i = 0; i < n; i++) { yx[i] = []; for (var j = 0; j < n; j++) { yx[i][j] = "+"; } } var last = []; bomb(n - 1, 0, 0); if (n % 2 == 0) yx[last[0]][last[1]] = "+"; str += yx.join("\n").replace(/\,/g, "").replace(/\+/g, " "); } console.log(str);
function bomb(y, x, z) { if (yx[y][x] != "+") return; var dy = [ -1, 0, 1, 0 ]; var dx = [ 0, 1, 0, -1 ]; var Y = y + dy[z]; var X = x + dx[z]; if (Y < 0 || X < 0 || Y >= n || X >= n) { z = (z + 1) % 4; bomb(y, x, z); } else { if (yx[Y][X] == "#") { yx[Y - dy[z]][X - dx[z]] = "+"; if (z == 3) bomb(Y - 2 * dy[z] - 1, X - 2 * dx[z], 0); else if (z == 0) bomb(Y - 2 * dy[z], X - 2 * dx[z] + 1, 1); else if (z == 1) bomb(Y - 2 * dy[z] + 1, X - 2 * dx[z], 2); else if (z == 2) bomb(Y - 2 * dy[z], X - 2 * dx[z] - 1, 3); } else { yx[y][x] = "#"; last = [ y, x ]; bomb(Y, X, z); } } } var input = require('fs').readFileSync('/dev/stdin', 'utf8'); var arr = input.trim().split("\n").map(Number); var d = arr.shift(); var str = ""; for (var k = 0; k < d; k++) { if (k != 0) str += "\n\n"; var n = arr.shift(); if (n == 0) { str += ""; continue; } if (n == 1) { str += "#"; continue; } if (n == 2) { str += "##\n# "; continue; } var yx = []; for (var i = 0; i < n; i++) { yx[i] = []; for (var j = 0; j < n; j++) { yx[i][j] = "+"; } } var last = []; bomb(n - 1, 0, 0); if (n % 2 == 0) yx[last[0]][last[1]] = "+"; str += yx.join("\n").replace(/\,/g, "").replace(/\+/g, " "); } console.log(str);
[["-", 0, 493, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 493, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 0, 493, 0, 7, 15, 1, 0, 16, 31, 22], ["+", 0, 493, 0, 7, 15, 1, 0, 16, 31, 22], ["-", 36, 36, 0, 493, 0, 7, 567, 27, 28, 22], ["+", 36, 36, 0, 493, 0, 7, 567, 27, 28, 22], ["-", 8, 556, 0, 57, 15, 23, 0, 16, 31, 22], ["+", 8, 556, 0, 57, 15, 23, 0, 16, 31, 22]]
2
600
8
import static java.util.Arrays.deepToString; import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { new Main().run(); } void tr(Object... os) { System.err.println(deepToString(os)); } Scanner sc = new Scanner(System.in); public void run() { int t = sc.nextInt(); for (int i = 0; i < t; i++) { if (i > 0) System.out.println(); solve(sc.nextInt()); } } void solve(int n) { char[][] t = new char[n][n]; for (int i = 0; i < n; i++) Arrays.fill(t[i], '.'); int[] dr = {-1, 0, 1, 0}; int[] dc = {0, 1, 0, -1}; int r = n - 1; int c = 0; t[r][c] = '#'; int d = 0; int miss = 0; for (; miss < 4;) { int nr = r + dr[d]; int nc = c + dc[d]; int nnr = r + 2 * dr[d]; int nnc = c + 2 * dc[d]; if (isin(nr, nc, n) && t[nr][nc] != '#' && (!isin(nnr, nnc, n) || t[nnr][nnc] != '#') && t[nr + dr[(d + 1) & 3]][nc + dc[(d + 1) & 3]] != '#') { r = nr; c = nc; t[r][c] = '#'; miss = 0; } else { d = (d + 1) & 3; miss++; } } for (int i = 0; i < n; i++) { System.out.println(new String(t[i])); } } boolean isin(int r, int c, int n) { return 0 <= r && r < n && 0 <= c && c < n; } }
import static java.util.Arrays.deepToString; import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { new Main().run(); } void tr(Object... os) { System.err.println(deepToString(os)); } Scanner sc = new Scanner(System.in); public void run() { int t = sc.nextInt(); for (int i = 0; i < t; i++) { if (i > 0) System.out.println(); solve(sc.nextInt()); } } void solve(int n) { char[][] t = new char[n][n]; for (int i = 0; i < n; i++) Arrays.fill(t[i], ' '); int[] dr = {-1, 0, 1, 0}; int[] dc = {0, 1, 0, -1}; int r = n - 1; int c = 0; t[r][c] = '#'; int d = 0; int miss = 0; for (; miss < 4;) { int nr = r + dr[d]; int nc = c + dc[d]; int nnr = r + 2 * dr[d]; int nnc = c + 2 * dc[d]; if (isin(nr, nc, n) && t[nr][nc] != '#' && (!isin(nnr, nnc, n) || t[nnr][nnc] != '#') && t[nr + dr[(d + 1) & 3]][nc + dc[(d + 1) & 3]] != '#') { r = nr; c = nc; t[r][c] = '#'; miss = 0; } else { d = (d + 1) & 3; miss++; } } for (int i = 0; i < n; i++) { System.out.println(new String(t[i])); } } boolean isin(int r, int c, int n) { return 0 <= r && r < n && 0 <= c && c < n; } }
[["-", 0, 7, 8, 1, 0, 492, 3, 4, 0, 252], ["+", 0, 7, 8, 1, 0, 492, 3, 4, 0, 252]]
3
483
2
import java.util.Scanner; public class Main { char[][] makeSpiral(int n) { char[][] pattern = new char[n][n]; int dir = 0; int x = 0, y = n - n % 2; int[] dx = {0, 1, 0, -1}; int[] dy = {-1, 0, 1, 0}; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { pattern[i][j] = ' '; } } int notTurn = 2; boolean end = false; while (!end) { if (n % 2 == 0 || notTurn < 2) { x += dx[dir]; y += dy[dir]; } --notTurn; switch (dir) { case 0: if (y <= 0 || (y != 1 && pattern[x][y - 2] == '*')) { if (notTurn > 0) { end = true; } else { dir = 1; notTurn = 2; } } break; case 1: if (x >= n - 1 || (x != n - 2 && pattern[x + 2][y] == '*')) { if (notTurn > 0) { end = true; } else { dir = 2; notTurn = 2; } } break; case 2: if (y >= n - 1 || (y != n - 2 && pattern[x][y + 2] == '*')) { if (notTurn > 0) { end = true; } else { dir = 3; notTurn = 2; } } break; case 3: if (x <= 0 || (x != 1 && pattern[x - 2][y] == '*')) { if (notTurn > 0) { end = true; } else { dir = 0; notTurn = 2; } } break; } pattern[x][y] = '*'; } return pattern; } void io() { Scanner s = new Scanner(System.in); int setnum = s.nextInt(); for (int i = 0; i < setnum; ++i) { int n = s.nextInt(); char[][] pattern = makeSpiral(n); if (i > 0) System.out.println(); for (int y = 0; y < n; ++y) { for (int x = 0; x < n; ++x) { System.out.print(pattern[x][y]); } System.out.println(); } } s.close(); } public static void main(String[] args) { new Main().io(); } }
import java.util.Scanner; public class Main { char[][] makeSpiral(int n) { char[][] pattern = new char[n][n]; int dir = 0; int x = 0, y = n - n % 2; int[] dx = {0, 1, 0, -1}; int[] dy = {-1, 0, 1, 0}; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { pattern[i][j] = ' '; } } int notTurn = 2; boolean end = false; while (!end) { if (n % 2 == 0 || notTurn < 2) { x += dx[dir]; y += dy[dir]; } --notTurn; switch (dir) { case 0: if (y <= 0 || (y != 1 && pattern[x][y - 2] == '#')) { if (notTurn > 0) { end = true; } else { dir = 1; notTurn = 2; } } break; case 1: if (x >= n - 1 || (x != n - 2 && pattern[x + 2][y] == '#')) { if (notTurn > 0) { end = true; } else { dir = 2; notTurn = 2; } } break; case 2: if (y >= n - 1 || (y != n - 2 && pattern[x][y + 2] == '#')) { if (notTurn > 0) { end = true; } else { dir = 3; notTurn = 2; } } break; case 3: if (x <= 0 || (x != 1 && pattern[x - 2][y] == '#')) { if (notTurn > 0) { end = true; } else { dir = 0; notTurn = 2; } } break; } pattern[x][y] = '#'; } return pattern; } void io() { Scanner s = new Scanner(System.in); int setnum = s.nextInt(); for (int i = 0; i < setnum; ++i) { int n = s.nextInt(); char[][] pattern = makeSpiral(n); if (i > 0) System.out.println(); for (int y = 0; y < n; ++y) { for (int x = 0; x < n; ++x) { System.out.print(pattern[x][y]); } System.out.println(); } } s.close(); } public static void main(String[] args) { new Main().io(); } }
[["-", 0, 16, 12, 23, 0, 16, 12, 16, 12, 252], ["+", 0, 16, 12, 23, 0, 16, 12, 16, 12, 252], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 12, 252], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 12, 252]]
3
582
10
#include <stdio.h> int main() { int i, j, k, n, m, x, y; char b[101][101]; scanf("%d", &n); while (n--) { for (i = 0; i < 100; i++) { for (j = 0; j < 100; j++) { b[i][j] = ' '; } } scanf("%d", &m); x = m; y = 1; b[x][y] = '#'; for (i = 0, k = m - 1; i < m; i++) { for (j = 0; j < k; j++) { if (i % 4 == 0) { // puts("0"); b[--x][y] = '#'; // if(i!=0||j!=k-1)x--; } if (i % 4 == 1) { // puts("1"); b[x][++y] = '#'; // y++; } if (i % 4 == 2) { // puts("2"); b[++x][y] = '#'; // x++; } if (i % 4 == 3) { // puts("3"); b[x][--y] = '#'; // y--; } // printf("x:%d y:%d k:%d\n",x,y,k); } if (i == 0) k; else if (i % 2 == 0) { k -= 2; } } for (i = 1; i <= m; i++) { for (j = 1; j <= m; j++) { printf("%c", b[i][j]); } puts(""); } if (!n) puts(""); } return 0; }
#include <stdio.h> int main() { int i, j, k, n, m, x, y; char b[101][101]; scanf("%d", &n); while (n--) { for (i = 0; i < 101; i++) { for (j = 0; j < 101; j++) { b[i][j] = ' '; } } scanf("%d", &m); x = m; y = 1; b[x][y] = '#'; for (i = 0, k = m - 1; i < m; i++) { for (j = 0; j < k; j++) { if (i % 4 == 0) { // puts("0"); b[--x][y] = '#'; // if(i!=0||j!=k-1)x--; } if (i % 4 == 1) { // puts("1"); b[x][++y] = '#'; // y++; } if (i % 4 == 2) { // puts("2"); b[++x][y] = '#'; // x++; } if (i % 4 == 3) { // puts("3"); b[x][--y] = '#'; // y--; } // printf("x:%d y:%d k:%d\n",x,y,k); } if (i == 0) k; else if (i % 2 == 0) { k -= 2; } } for (i = 1; i <= m; i++) { for (j = 1; j <= m; j++) { printf("%c", b[i][j]); } puts(""); } if (n) puts(""); } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13], ["-", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13], ["-", 8, 9, 0, 57, 15, 23, 0, 91, 17, 111]]
0
346
5
#include <stdio.h> #include <stdlib.h> enum { UP, DOWN, LEFT, RIGHT }; int main(void) { char puttern[100][101]; int x, y; int direction; int nomove; int putternsize; int datamax, datanum; scanf("%d", &datamax); for (datanum = 0; datanum < datamax; datanum++) { if (datanum > 0) puts(""); scanf("%d", &putternsize); for (y = 0; y < putternsize; y++) { for (x = 0; x < putternsize; x++) puttern[y][x] = ' '; puttern[y][putternsize] = 0; } x = 0; y = putternsize - 1; direction = UP; nomove = 0; while (1) { puttern[y][x] = '#'; switch (direction) { case UP: if (y == 0 || (y > 1 && puttern[y - 2][x] == '#') || (y > 0 && puttern[y - 1][x] == '#') || (y > 0 && x > 0 && puttern[y - 1][x - 1] == '#') || (y > 0 && x < putternsize - 1 && puttern[y - 1][x + 1] == '#')) { direction = RIGHT; nomove++; } else { y--; nomove = 0; } break; case DOWN: if (y == putternsize - 1 || (y < putternsize - 2 && puttern[y + 2][x] == '#') || (y < putternsize - 1 && puttern[y + 1][x] == '#') || (y < putternsize - 1 && x > 0 && puttern[y + 1][x - 1] == '#') || (y < putternsize - 1 && x < putternsize - 1 && puttern[y + 1][x + 1] == '#')) { direction = LEFT; nomove++; } else { y++; nomove = 0; } break; case LEFT: if (x == 0 || (x > 1 && puttern[y][x - 2] == '#') || (x > 0 && puttern[y][x - 1] == '#') || (x > 0 && y > 0 && puttern[y - 1][x - 1] == '#') || (x > 0 && y < putternsize - 1 && puttern[y + 1][x - 1] == '#')) { direction = UP; nomove++; } else { x--; nomove = 0; } break; case RIGHT: if (x == putternsize - 1 || (x < putternsize - 2 && puttern[y][x + 2] == '#') || (x < putternsize - 1 && puttern[y][x + 1] == '#') || (x < putternsize - 1 && y > 0 && puttern[y - 1][x + 1] == '#') || (x < putternsize - 1 && y < putternsize - 1 && puttern[y + 1][x + 1] == '#')) { direction = DOWN; nomove++; } else { y++; nomove = 0; } break; } if (nomove >= 4) break; } for (y = 0; y < putternsize; y++) puts(puttern[y]); } return 0; }
#include <stdio.h> #include <stdlib.h> enum { UP, DOWN, LEFT, RIGHT }; int main(void) { char puttern[100][101]; int x, y; int direction; int nomove; int putternsize; int datamax, datanum; scanf("%d", &datamax); for (datanum = 0; datanum < datamax; datanum++) { if (datanum > 0) puts(""); scanf("%d", &putternsize); for (y = 0; y < putternsize; y++) { for (x = 0; x < putternsize; x++) puttern[y][x] = ' '; puttern[y][putternsize] = 0; } x = 0; y = putternsize - 1; direction = UP; nomove = 0; while (1) { puttern[y][x] = '#'; switch (direction) { case UP: if (y <= 0 || (y > 1 && puttern[y - 2][x] == '#') || (y > 0 && puttern[y - 1][x] == '#') || (y > 0 && x > 0 && puttern[y - 1][x - 1] == '#') || (y > 0 && x < putternsize - 1 && puttern[y - 1][x + 1] == '#')) { direction = RIGHT; nomove++; } else { y--; nomove = 0; } break; case DOWN: if (y >= putternsize - 1 || (y < putternsize - 2 && puttern[y + 2][x] == '#') || (y < putternsize - 1 && puttern[y + 1][x] == '#') || (y < putternsize - 1 && x > 0 && puttern[y + 1][x - 1] == '#') || (y < putternsize - 1 && x < putternsize - 1 && puttern[y + 1][x + 1] == '#')) { direction = LEFT; nomove++; } else { y++; nomove = 0; } break; case LEFT: if (x <= 0 || (x > 1 && puttern[y][x - 2] == '#') || (x > 0 && puttern[y][x - 1] == '#') || (x > 0 && y > 0 && puttern[y - 1][x - 1] == '#') || (x > 0 && y < putternsize - 1 && puttern[y + 1][x - 1] == '#')) { direction = UP; nomove++; } else { x--; nomove = 0; } break; case RIGHT: if (x >= putternsize - 1 || (x < putternsize - 2 && puttern[y][x + 2] == '#') || (x < putternsize - 1 && puttern[y][x + 1] == '#') || (x < putternsize - 1 && y > 0 && puttern[y - 1][x + 1] == '#') || (x < putternsize - 1 && y < putternsize - 1 && puttern[y + 1][x + 1] == '#')) { direction = DOWN; nomove++; } else { x++; nomove = 0; } break; } if (nomove >= 4) break; } for (y = 0; y < putternsize; y++) puts(puttern[y]); } return 0; }
[["-", 31, 16, 31, 16, 31, 16, 31, 16, 17, 60], ["+", 31, 16, 31, 16, 31, 16, 31, 16, 17, 19], ["+", 31, 16, 31, 16, 31, 16, 31, 16, 17, 20], ["-", 75, 76, 0, 9, 0, 1, 0, 27, 28, 22], ["+", 75, 76, 0, 9, 0, 1, 0, 27, 28, 22]]
0
737
10
#include <algorithm> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define reep(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) reep((i), 0, (n)) #define ALL(v) (v).begin(), (v).end() #define PB push_back #define EPS 1e-8 #define F first #define S second #define mkp make_pair static const double PI = 6 * asin(0.5); typedef long long ll; typedef complex<double> CP; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vint; static const int INF = 1 << 24; template <class T> void initvv(vector<vector<T>> &v, int a, int b, const T &t = T()) { v.assign(a, vector<T>(b, t)); } // v.erase(unique(v.begin(),v.end()),v.end()); int dx[] = {-1, 0, 1, 0}; int dy[] = {0, 1, 0, -1}; int main() { int n; cin >> n; rep(l, n) { if (l) cout << endl; int m; cin >> m; // cout<<m<<endl; if (m == 1) { cout << "#\n"; continue; } if (m == 2) { cout << "##\n"; cout << "# \n"; continue; } if (m == 3) { /* ### # # # # */ cout << "###\n"; cout << "# #\n"; cout << "# #\n"; // cout<<"\n"; continue; } if (m == 4) { cout << "####\n"; cout << "# #\n"; cout << "# #\n"; cout << "# ##\n"; // cout<<endl; continue; } vector<vector<char>> vv; initvv(vv, m, m); rep(i, m) { rep(j, m) vv[i][j] = ' '; } rep(i, m) { vv[0][i] = '#'; vv[m - 1][i] = '#'; vv[i][m - 1] = '#'; vv[i][0] = '#'; } vv[m - 1][1] = ' '; int x = m - 1, y = 2; int c = 0; while (1) { // cout<<x<<" "<<y<<endl; if (vv[x + dx[c] * 2][y + dy[c] * 2] == ' ') { x += dx[c]; y += dy[c]; vv[x][y] = '#'; } else if (vv[x + 2 * dx[(c + 1) % 4]][y + 2 * dy[(c + 1) % 4]] == ' ' && vv[x + dx[(c + 1) % 4 + dx[(c + 2) % 4]]] [y + dy[(c + 1) % 4] + dy[(c + 2) % 4]] == ' ') { c++; c %= 4; x += dx[c]; y += dy[c]; vv[x][y] = '#'; } else { break; } } /* ###### # # # ## # # # # # # # # #### */ rep(i, m) { rep(j, m) { cout << vv[i][j]; } cout << endl; } cout << endl; } }
#include <algorithm> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define reep(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) reep((i), 0, (n)) #define ALL(v) (v).begin(), (v).end() #define PB push_back #define EPS 1e-8 #define F first #define S second #define mkp make_pair static const double PI = 6 * asin(0.5); typedef long long ll; typedef complex<double> CP; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vint; static const int INF = 1 << 24; template <class T> void initvv(vector<vector<T>> &v, int a, int b, const T &t = T()) { v.assign(a, vector<T>(b, t)); } // v.erase(unique(v.begin(),v.end()),v.end()); int dx[] = {-1, 0, 1, 0}; int dy[] = {0, 1, 0, -1}; int main() { int n; cin >> n; rep(l, n) { if (l) cout << endl; int m; cin >> m; // cout<<m<<endl; if (m == 1) { cout << "#\n"; continue; } if (m == 2) { cout << "##\n"; cout << "# \n"; continue; } if (m == 3) { /* ### # # # # */ cout << "###\n"; cout << "# #\n"; cout << "# #\n"; // cout<<"\n"; continue; } if (m == 4) { cout << "####\n"; cout << "# #\n"; cout << "# #\n"; cout << "# ##\n"; // cout<<endl; continue; } vector<vector<char>> vv; initvv(vv, m, m); rep(i, m) { rep(j, m) vv[i][j] = ' '; } rep(i, m) { vv[0][i] = '#'; vv[m - 1][i] = '#'; vv[i][m - 1] = '#'; vv[i][0] = '#'; } vv[m - 1][1] = ' '; int x = m - 1, y = 2; int c = 0; while (1) { // cout<<x<<" "<<y<<endl; if (vv[x + dx[c] * 2][y + dy[c] * 2] == ' ') { x += dx[c]; y += dy[c]; vv[x][y] = '#'; } else if (vv[x + 2 * dx[(c + 1) % 4]][y + 2 * dy[(c + 1) % 4]] == ' ' && vv[x + dx[(c + 1) % 4 + dx[(c + 2) % 4]]] [y + dy[(c + 1) % 4] + dy[(c + 2) % 4]] == ' ') { c++; c %= 4; x += dx[c]; y += dy[c]; vv[x][y] = '#'; } else { break; } } /* ###### # # # ## # # # # # # # # #### */ rep(i, m) { rep(j, m) { cout << vv[i][j]; } cout << endl; } // cout<<endl; } }
[["-", 0, 14, 8, 9, 0, 1, 0, 16, 31, 22], ["-", 0, 14, 8, 9, 0, 1, 0, 16, 17, 151], ["-", 0, 14, 8, 9, 0, 1, 0, 16, 12, 22], ["-", 8, 9, 0, 14, 8, 9, 0, 1, 0, 35]]
1
731
4
#include <cstring> #include <iostream> #include <string> #include <vector> #define REP(i, k, n) for (int i = k; i < n; i++) #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; int main() { int n; cin >> n; int a[101][101]; int dx[4] = {0, 1, 0, -1}; int dy[4] = {-1, 0, 1, 0}; bool first = true; rep(i, n) { int r; cin >> r; int r2 = r; memset(a, 0, sizeof(a)); if (r == 1) { if (first) first = false; else cout << endl; cout << "#" << endl; } else if (r == 2) { if (first) first = false; else cout << endl; cout << "# " << endl << "# " << endl; } else { int y = r - 1; int x = 0; a[y][x] = 1; int dir = 0; rep(j, r - 1) { y += dy[dir % 4]; x += dx[dir % 4]; a[y][x] = 1; } dir++; r--; if (r % 2 == 1) { while (true) { rep(j, r) { y += dy[dir % 4]; x += dx[dir % 4]; a[y][x] = 1; } dir++; if (r == 1) break; rep(j, r) { y += dy[dir % 4]; x += dx[dir % 4]; a[y][x] = 1; } dir++; r -= 2; } } else { while (true) { rep(j, r) { y += dy[dir % 4]; x += dx[dir % 4]; a[y][x] = 1; } dir++; rep(j, r) { y += dy[dir % 4]; x += dx[dir % 4]; a[y][x] = 1; } if (r == 2) break; dir++; r -= 2; } } if (first) first = false; else cout << endl; rep(j, r2) { rep(k, r2) { if (a[j][k] == 1) cout << "#"; else cout << " "; } cout << endl; } } } return 0; }
#include <cstring> #include <iostream> #include <string> #include <vector> #define REP(i, k, n) for (int i = k; i < n; i++) #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; int main() { int n; cin >> n; int a[101][101]; int dx[4] = {0, 1, 0, -1}; int dy[4] = {-1, 0, 1, 0}; bool first = true; rep(i, n) { int r; cin >> r; int r2 = r; memset(a, 0, sizeof(a)); if (r == 1) { if (first) first = false; else cout << endl; cout << "#" << endl; } else if (r == 2) { if (first) first = false; else cout << endl; cout << "##" << endl << "# " << endl; } else { int y = r - 1; int x = 0; a[y][x] = 1; int dir = 0; rep(j, r - 1) { y += dy[dir % 4]; x += dx[dir % 4]; a[y][x] = 1; } dir++; r--; if (r % 2 == 1) { while (true) { rep(j, r) { y += dy[dir % 4]; x += dx[dir % 4]; a[y][x] = 1; } dir++; if (r == 1) break; rep(j, r) { y += dy[dir % 4]; x += dx[dir % 4]; a[y][x] = 1; } dir++; r -= 2; } } else { while (true) { rep(j, r) { y += dy[dir % 4]; x += dx[dir % 4]; a[y][x] = 1; } dir++; rep(j, r) { y += dy[dir % 4]; x += dx[dir % 4]; a[y][x] = 1; } if (r == 2) break; dir++; r -= 2; } } if (first) first = false; else cout << endl; rep(j, r2) { rep(k, r2) { if (a[j][k] == 1) cout << "#"; else cout << " "; } cout << endl; } } } return 0; }
[["-", 31, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 31, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
1
527
2
// Name: Spiral Pattern // Level: 2 // Category: シミュレーション // Note: /** * n×nの領域を用意して、左下隅から渦巻きをたどるようにして埋めていく。 * 現在の進行方向について、壁にぶつかるときか、もう1歩進むと他の線に干渉するというときには右に曲がる。 */ #include <iostream> #include <string> #include <vector> using namespace std; // ostream support for vector. template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) { os << t << endl; } return os; } template <typename T> struct Pair { T a, b; Pair() : a(T()), b(T()) {} Pair(const T &a, const T &b) : a(a), b(b) {} Pair &operator+=(const Pair &p) { a += p.a; b += p.b; return *this; } friend Pair operator+(Pair p1, const Pair &p2) { p1 += p2; return p1; } friend ostream &operator<<(ostream &os, const Pair &p) { return os << "(" << p.a << ", " << p.b << ")"; } /* vector accessor mixin {{{*/ template <typename U> auto of(U &u) const -> decltype(u[a][b]) { return u[a][b]; } template <typename U> bool valid_in(const U &u) const { return a < u.size() && b < u[0].size(); } /*}}}*/ }; static const Pair<int> DELTA[4] = {Pair<int>(-1, 0), Pair<int>(0, -1), Pair<int>(1, 0), Pair<int>(0, 1)}; bool solve(bool first) { if (!first) cout << endl; int N; cin >> N; vector<string> f(N, string(N, ' ')); Pair<int> pos(N - 1, 0); int dir = 1; bool stucked = false; while (true) { pos.of(f) = '#'; auto next = pos + DELTA[dir]; auto nn = next + DELTA[dir]; auto nl = next + DELTA[(dir + 3) % 4]; if (nl.valid_in(f) && nl.of(f) == '#') { break; } if (!next.valid_in(f) || (nn.valid_in(f) && nn.of(f) == '#')) { if (stucked) break; dir = (dir + 3) % 4; stucked = true; } else { stucked = false; pos = next; } } cout << f << endl; return true; } int main() { cin.tie(0); ios::sync_with_stdio(0); cout.setf(ios::fixed); cout.precision(2); bool first = true; int N; cin >> N; while (N-- && solve(first)) { first = false; } return 0; }
// Name: Spiral Pattern // Level: 2 // Category: シミュレーション // Note: /** * n×nの領域を用意して、左下隅から渦巻きをたどるようにして埋めていく。 * 現在の進行方向について、壁にぶつかるときか、もう1歩進むと他の線に干渉するというときには右に曲がる。 */ #include <iostream> #include <string> #include <vector> using namespace std; // ostream support for vector. template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) { os << t << endl; } return os; } template <typename T> struct Pair { T a, b; Pair() : a(T()), b(T()) {} Pair(const T &a, const T &b) : a(a), b(b) {} Pair &operator+=(const Pair &p) { a += p.a; b += p.b; return *this; } friend Pair operator+(Pair p1, const Pair &p2) { p1 += p2; return p1; } friend ostream &operator<<(ostream &os, const Pair &p) { return os << "(" << p.a << ", " << p.b << ")"; } /* vector accessor mixin {{{*/ template <typename U> auto of(U &u) const -> decltype(u[a][b]) { return u[a][b]; } template <typename U> bool valid_in(const U &u) const { return a < u.size() && b < u[0].size(); } /*}}}*/ }; static const Pair<int> DELTA[4] = {Pair<int>(-1, 0), Pair<int>(0, -1), Pair<int>(1, 0), Pair<int>(0, 1)}; bool solve(bool first) { if (!first) cout << endl; int N; cin >> N; vector<string> f(N, string(N, ' ')); Pair<int> pos(N - 1, 0); int dir = 1; bool stucked = false; while (true) { pos.of(f) = '#'; auto next = pos + DELTA[dir]; auto nn = next + DELTA[dir]; auto nl = next + DELTA[(dir + 3) % 4]; if (nl.valid_in(f) && nl.of(f) == '#') { break; } if (!next.valid_in(f) || (nn.valid_in(f) && nn.of(f) == '#')) { if (stucked) break; dir = (dir + 3) % 4; stucked = true; } else { stucked = false; pos = next; } } cout << f; return true; } int main() { cin.tie(0); ios::sync_with_stdio(0); cout.setf(ios::fixed); cout.precision(2); bool first = true; int N; cin >> N; while (N-- && solve(first)) { first = false; } return 0; }
[["-", 0, 14, 8, 9, 0, 1, 0, 16, 17, 151], ["-", 0, 14, 8, 9, 0, 1, 0, 16, 12, 22]]
1
615
2
#include <bits/stdc++.h> #define range(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, b) range(i, 0, b) #define pb(a) push_back(a) #define all(a) (a).begin(), (a).end() #define debug(x) cout << "debug " << x << endl; #define INF (1 << 30) using namespace std; void solve(char a[105][105], int inp, int d, int y, int x) { int i; for (i = 0; i < inp - 1; i++) { a[y][x] = '#'; if (d == 0) { if (a[y - 2][x] == '#') break; y--; } else if (d == 1) { if (a[y][x + 2] == '#') break; x++; } else if (d == 2) { if (a[y + 2][x] == '#') break; y++; } else { if (a[y][x - 2] == '#') break; x--; } } if (i <= 1) return; solve(a, inp, (d + 1) % 4, y, x); } int main() { int n; char a[105][105]; cin >> n; rep(i, n) { if (i) cout << endl; rep(i, 105) rep(j, 105) a[i][j] = ' '; int inp; cin >> inp; solve(a, inp, 0, 104, 0); if (inp == 1) cout << '#' << endl; else if (inp == 2) cout << "# " << endl << "# " << endl; else { for (int i = 104 - inp + 1; i <= 104; i++) { rep(j, inp) { cout << a[i][j]; } cout << endl; } } } }
#include <bits/stdc++.h> #define range(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, b) range(i, 0, b) #define pb(a) push_back(a) #define all(a) (a).begin(), (a).end() #define debug(x) cout << "debug " << x << endl; #define INF (1 << 30) using namespace std; void solve(char a[105][105], int inp, int d, int y, int x) { int i; for (i = 0; i < inp - 1; i++) { a[y][x] = '#'; if (d == 0) { if (a[y - 2][x] == '#') break; y--; } else if (d == 1) { if (a[y][x + 2] == '#') break; x++; } else if (d == 2) { if (a[y + 2][x] == '#') break; y++; } else { if (a[y][x - 2] == '#') break; x--; } } if (i <= 1) return; solve(a, inp, (d + 1) % 4, y, x); } int main() { int n; char a[105][105]; cin >> n; rep(i, n) { if (i) cout << endl; rep(i, 105) rep(j, 105) a[i][j] = ' '; int inp; cin >> inp; solve(a, inp, 0, 104, 0); if (inp == 1) cout << '#' << endl; else if (inp == 2) cout << "##" << endl << "# " << endl; else { for (int i = 104 - inp + 1; i <= 104; i++) { rep(j, inp) { cout << a[i][j]; } cout << endl; } } } }
[["-", 31, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 31, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
1
406
2
#include "bits/stdc++.h" using namespace std; const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, 1, 0, -1}; int main() { int D; cin >> D; while (D--) { int N; cin >> N; vector<vector<char>> field(N, vector<char>(N, ' ')); int way = 3; int nx = 0; int ny = N - 1; bool flag = true; while (flag) { field[ny][nx] = '#'; if (N == 1) break; for (int i = 0; i < 2; ++i) { int nextx = nx + dx[way]; int nexty = ny + dy[way]; if (nextx >= 0 && nextx < N && nexty >= 0 && nexty < N) { bool aok = true; for (int w = -1; w <= 1; ++w) { int nextway = (way + 4 + w) % 4; int next2x = nextx + dx[nextway]; int next2y = nexty + dy[nextway]; if (next2x >= 0 && next2x < N && next2y >= 0 && next2y < N) { if (field[next2y][next2x] == '#') { aok = false; } } } if (!aok) { if (i == 1) flag = false; } else { nx = nextx; ny = nexty; break; } } way = (way + 3) % 4; } } for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { cout << field[i][j]; } cout << endl; } if (N - 1) cout << endl; } return 0; }
#include "bits/stdc++.h" using namespace std; const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, 1, 0, -1}; int main() { int D; cin >> D; while (D--) { int N; cin >> N; vector<vector<char>> field(N, vector<char>(N, ' ')); int way = 3; int nx = 0; int ny = N - 1; bool flag = true; while (flag) { field[ny][nx] = '#'; if (N == 1) break; for (int i = 0; i < 2; ++i) { int nextx = nx + dx[way]; int nexty = ny + dy[way]; if (nextx >= 0 && nextx < N && nexty >= 0 && nexty < N) { bool aok = true; for (int w = -1; w <= 1; ++w) { int nextway = (way + 4 + w) % 4; int next2x = nextx + dx[nextway]; int next2y = nexty + dy[nextway]; if (next2x >= 0 && next2x < N && next2y >= 0 && next2y < N) { if (field[next2y][next2x] == '#') { aok = false; } } } if (!aok) { if (i == 1) flag = false; } else { nx = nextx; ny = nexty; break; } } way = (way + 3) % 4; } } for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { cout << field[i][j]; } cout << endl; } if (D) cout << endl; } return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 33], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 0, 52, 8, 9, 0, 57, 15, 339, 51, 22]]
1
390
4
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> i_i; typedef pair<long long, int> ll_i; #define PI 3.141592653589793238462643383279 #define mod 1000000007LL #define rep(i, n) for (i = 0; i < n; ++i) #define rep1(i, n) for (i = 1; i < n; ++i) #define per(i, n) for (i = n - 1; i > -1; --i) #define int(x) \ int x; \ scanf("%d", &x) #define int2(x, y) \ int x, y; \ scanf("%d%d", &x, &y) #define int3(x, y, z) \ int x, y, z; \ scanf("%d%d%d", &x, &y, &z) #define int4(v, x, y, z) \ int v, x, y, z; \ scanf("%d%d%d%d", &v, &x, &y, &z) #define int5(v, w, x, y, z) \ int v, w, x, y, z; \ scanf("%d%d%d%d%d", &v, &w, &x, &y, &z) #define pri(x) cout << (x) << "\n" #define pri2(x, y) cout << (x) << " " << (y) << "\n" #define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n" #define pb push_back #define mp make_pair #define all(a) (a).begin(), (a).end() #define kabe puts("---------------------------") #define kara puts("") #define debug(x) cout << " --- " << (x) << "\n" #define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n" #define debug3(x, y, z) \ cout << " --- " << (x) << " " << (y) << " " << (z) << "\n" #define X first #define Y second #define eps 0.0001 #define prid(x) printf("%.15lf\n", x) char f[100][100]; int dw[4] = {0, 1, 0, -1}; int dh[4] = {-1, 0, 1, 0}; signed main(void) { int i, j; int(d); for (int testcase = 0; testcase < d; testcase++) { if (testcase != 0) puts(""); int(n); rep(i, n) rep(j, n) f[i][j] = '.'; int noww = 0, nowh = n - 1, k = 0; bool is = false; for (;;) { // printf("%d %d %d\n", nowh, noww, k); f[nowh][noww] = '#'; if (0 > nowh + dh[k] || nowh + dh[k] >= n || 0 > noww + dw[k] || noww + dw[k] >= n) { // puts("a"); if (is) break; is = true; k = (k + 1) % 4; continue; } if (0 <= nowh + dh[k] * 2 && nowh + dh[k] * 2 < n) if (0 <= noww + dw[k] * 2 && noww + dw[k] * 2 < n) if (f[nowh + dh[k] + dh[k]][noww + dw[k] + dw[k]] == '#') { // puts("b"); if (is) break; is = true; k = (k + 1) % 4; continue; } if (0 <= nowh + dh[k] + dh[(k + 1) % 4] && nowh + dh[k] + dh[(k + 1) % 4] < n) if (0 <= noww + dw[k] + dw[(k + 1) % 4] && noww + dw[k] + dw[(k + 1) % 4] < n) if (f[nowh + dh[k] + dh[(k + 1) % 4]] [noww + dw[k] + dw[(k + 1) % 4]] == '#') { // puts("c"); if (is) break; is = true; k = (k + 1) % 4; continue; } if (0 <= nowh + dh[(k + 3) % 4] && nowh + dh[(k + 3) % 4] < n) if (0 <= noww + dw[(k + 3) % 4] && noww + dw[(k + 3) % 4] < n) if (f[nowh + dh[(k + 3) % 4]][noww + dw[(k + 3) % 4]] == '#') { // puts("d"); if (is) break; is = true; k = (k + 1) % 4; continue; } // puts("e"); is = false; nowh += dh[k]; noww += dw[k]; } rep(i, n) { rep(j, n) printf("%c", f[i][j]); puts(""); } //*/ //*/ break; } return 0; }
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> i_i; typedef pair<long long, int> ll_i; #define PI 3.141592653589793238462643383279 #define mod 1000000007LL #define rep(i, n) for (i = 0; i < n; ++i) #define rep1(i, n) for (i = 1; i < n; ++i) #define per(i, n) for (i = n - 1; i > -1; --i) #define int(x) \ int x; \ scanf("%d", &x) #define int2(x, y) \ int x, y; \ scanf("%d%d", &x, &y) #define int3(x, y, z) \ int x, y, z; \ scanf("%d%d%d", &x, &y, &z) #define int4(v, x, y, z) \ int v, x, y, z; \ scanf("%d%d%d%d", &v, &x, &y, &z) #define int5(v, w, x, y, z) \ int v, w, x, y, z; \ scanf("%d%d%d%d%d", &v, &w, &x, &y, &z) #define pri(x) cout << (x) << "\n" #define pri2(x, y) cout << (x) << " " << (y) << "\n" #define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n" #define pb push_back #define mp make_pair #define all(a) (a).begin(), (a).end() #define kabe puts("---------------------------") #define kara puts("") #define debug(x) cout << " --- " << (x) << "\n" #define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n" #define debug3(x, y, z) \ cout << " --- " << (x) << " " << (y) << " " << (z) << "\n" #define X first #define Y second #define eps 0.0001 #define prid(x) printf("%.15lf\n", x) char f[100][100]; int dw[4] = {0, 1, 0, -1}; int dh[4] = {-1, 0, 1, 0}; signed main(void) { int i, j; int(d); for (int testcase = 0; testcase < d; testcase++) { if (testcase != 0) puts(""); int(n); rep(i, n) rep(j, n) f[i][j] = ' '; int noww = 0, nowh = n - 1, k = 0; bool is = false; for (;;) { // printf("%d %d %d\n", nowh, noww, k); f[nowh][noww] = '#'; if (0 > nowh + dh[k] || nowh + dh[k] >= n || 0 > noww + dw[k] || noww + dw[k] >= n) { // puts("a"); if (is) break; is = true; k = (k + 1) % 4; continue; } if (0 <= nowh + dh[k] * 2 && nowh + dh[k] * 2 < n) if (0 <= noww + dw[k] * 2 && noww + dw[k] * 2 < n) if (f[nowh + dh[k] + dh[k]][noww + dw[k] + dw[k]] == '#') { // puts("b"); if (is) break; is = true; k = (k + 1) % 4; continue; } if (0 <= nowh + dh[k] + dh[(k + 1) % 4] && nowh + dh[k] + dh[(k + 1) % 4] < n) if (0 <= noww + dw[k] + dw[(k + 1) % 4] && noww + dw[k] + dw[(k + 1) % 4] < n) if (f[nowh + dh[k] + dh[(k + 1) % 4]] [noww + dw[k] + dw[(k + 1) % 4]] == '#') { // puts("c"); if (is) break; is = true; k = (k + 1) % 4; continue; } if (0 <= nowh + dh[(k + 3) % 4] && nowh + dh[(k + 3) % 4] < n) if (0 <= noww + dw[(k + 3) % 4] && noww + dw[(k + 3) % 4] < n) if (f[nowh + dh[(k + 3) % 4]][noww + dw[(k + 3) % 4]] == '#') { // puts("d"); if (is) break; is = true; k = (k + 1) % 4; continue; } // puts("e"); is = false; nowh += dh[k]; noww += dw[k]; } rep(i, n) { rep(j, n) printf("%c", f[i][j]); puts(""); } //*/ //*/ break; } return 0; }
[["-", 8, 9, 0, 1, 0, 11, 12, 103, 0, 125], ["+", 8, 9, 0, 1, 0, 11, 12, 103, 0, 125]]
1
896
2
#include <iostream> using namespace std; bool vis[30][30], na[30][30]; int dx[] = {0, 1, 0, -1}, dy[] = {-1, 0, 1, 0}; int ex[] = {-1, 1, 0, 0}, ey[] = {0, 0, -1, 1}; int n; void DFS(int y, int x, int k) { vis[y][x] = true; na[y][x] = true; int xx, yy; bool done = false; for (int i = 0; i < 4; i++) { xx = x + dx[k], yy = y + dy[k]; bool ok = false; if (0 <= xx && xx < n && 0 <= yy && yy < n) { if (na[yy][xx] == false) { ok = true; } } if (ok) { done = true; break; } k = (k + 1) % 4; } if (!done) return; for (int i = 0; i < 2; i++) { int r = i + (k % 2) * 2; int nx = x + ex[r], ny = y + ey[r]; if (0 <= nx && nx < n && 0 <= ny && ny < n) { na[ny][nx] = true; } } DFS(yy, xx, k); } int main() { int q; cin >> q; for (int u = 0; u < q; u++) { if (u) cout << endl; cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { vis[i][j] = false; na[i][j] = false; } } DFS(n - 1, 0, 0); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) cout << (vis[i][j] ? "#" : " "); cout << endl; } } return 0; }
#include <iostream> using namespace std; bool vis[110][110], na[110][110]; int dx[] = {0, 1, 0, -1}, dy[] = {-1, 0, 1, 0}; int ex[] = {-1, 1, 0, 0}, ey[] = {0, 0, -1, 1}; int n; void DFS(int y, int x, int k) { vis[y][x] = true; na[y][x] = true; int xx, yy; bool done = false; for (int i = 0; i < 4; i++) { xx = x + dx[k], yy = y + dy[k]; bool ok = false; if (0 <= xx && xx < n && 0 <= yy && yy < n) { if (na[yy][xx] == false) { ok = true; } } if (ok) { done = true; break; } k = (k + 1) % 4; } if (!done) return; for (int i = 0; i < 2; i++) { int r = i + (k % 2) * 2; int nx = x + ex[r], ny = y + ey[r]; if (0 <= nx && nx < n && 0 <= ny && ny < n) { na[ny][nx] = true; } } DFS(yy, xx, k); } int main() { int q; cin >> q; for (int u = 0; u < q; u++) { if (u) cout << endl; cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { vis[i][j] = false; na[i][j] = false; } } DFS(n - 1, 0, 0); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) cout << (vis[i][j] ? "#" : " "); cout << endl; } } return 0; }
[["-", 0, 30, 0, 43, 49, 80, 49, 80, 81, 13], ["+", 0, 30, 0, 43, 49, 80, 49, 80, 81, 13], ["-", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13]]
1
482
8
#include <algorithm> #include <cassert> #include <cctype> #include <complex> #include <cstdio> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; int n, dy[] = {-1, 0, 1, 0}, dx[] = {0, 1, 0, -1}; char c[100][100]; int main() { cin >> n; int f = 0; while (cin >> n) { if (f) cout << endl; if (n == 1) { cout << "#" << endl; continue; } for (int i = 0; i < n * n; i++) c[i / n][i % n] = ' '; int y = n - 1, x = 0, u = 0, d = n - 1, l = 0, r = n - 1; c[y][x] = '#'; for (int i = 0; i < n; i++) { while (1) { y += dy[i % 4]; x += dx[i % 4]; c[y][x] = '#'; if (i % 4 == 0 && y == u || i % 4 == 1 && x == r || i % 4 == 2 && y == d || i % 4 == 3 && x == l) break; } if (i % 4 == 0) l += 2; if (i % 4 == 1) u += 2; if (i % 4 == 2) r -= 2; if (i % 4 == 3) d -= 2; } for (int i = 0; i < n * n; i++) { cout << c[i / n][i % n]; if (i % n == n - 1) cout << endl; } f = 1; } }
#include <algorithm> #include <cassert> #include <cctype> #include <complex> #include <cstdio> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; int n, dy[] = {-1, 0, 1, 0}, dx[] = {0, 1, 0, -1}; char c[100][100]; int main() { cin >> n; int f = 0; while (cin >> n) { if (f) cout << endl; if (n == 1) { cout << "#" << endl; f = 1; continue; } for (int i = 0; i < n * n; i++) c[i / n][i % n] = ' '; int y = n - 1, x = 0, u = 0, d = n - 1, l = 0, r = n - 1; c[y][x] = '#'; for (int i = 0; i < n; i++) { while (1) { y += dy[i % 4]; x += dx[i % 4]; c[y][x] = '#'; if (i % 4 == 0 && y == u || i % 4 == 1 && x == r || i % 4 == 2 && y == d || i % 4 == 3 && x == l) break; } if (i % 4 == 0) l += 2; if (i % 4 == 1) u += 2; if (i % 4 == 2) r -= 2; if (i % 4 == 3) d -= 2; } for (int i = 0; i < n * n; i++) { cout << c[i / n][i % n]; if (i % n == n - 1) cout << endl; } f = 1; } }
[["+", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 57, 64, 9, 0, 1, 0, 35]]
1
388
4
// 01 #include <algorithm> #include <iostream> using namespace std; int n; char g[100][100]; bool fr(int y, int x, int py, int px) { bool f = true; for (int i = 0; i < 4; i++) { int d[] = {0, 1, 0, -1, 0}; int jy = y + d[i]; int jx = x + d[i + 1]; f &= min(jx, jy) < 0 || n <= max(jx, jy) || (px == jx && py == jy) || g[jy][jx] == ' '; } return f; } int main() { int d; cin >> d; while (d--) { cin >> n; fill(g[0], g[100], ' '); g[0][0] = '#'; int d = 0, y = 0, x = 0; int p = 0; for (;;) { int dx[] = {0, 1, 0, -1}; int dy[] = {1, 0, -1, 0}; int ny = y + dy[d]; int nx = x + dx[d]; int jy = ny + dy[d]; int jx = nx + dx[d]; if (0 <= min(nx, ny) && max(nx, ny) < n && fr(ny, nx, y, x)) { y = ny; x = nx; g[ny][nx] = '#'; p = 0; } else { p++; d = (d + 1) % 4; if (p >= 2) { break; } } } for (int y = n - 1; y >= 0; y--) { for (int x = 0; x < n; x++) { cout << g[y][x]; } cout << endl; } if (d) { cout << endl; } } return 0; }
// 01 #include <algorithm> #include <iostream> using namespace std; int n; char g[100][100]; bool fr(int y, int x, int py, int px) { bool f = true; for (int i = 0; i < 4; i++) { int d[] = {0, 1, 0, -1, 0}; int jy = y + d[i]; int jx = x + d[i + 1]; f &= min(jx, jy) < 0 || n <= max(jx, jy) || (px == jx && py == jy) || g[jy][jx] == ' '; } return f; } int main() { int ds; cin >> ds; while (ds--) { cin >> n; fill(g[0], g[100], ' '); g[0][0] = '#'; int d = 0, y = 0, x = 0; int p = 0; for (;;) { int dx[] = {0, 1, 0, -1}; int dy[] = {1, 0, -1, 0}; int ny = y + dy[d]; int nx = x + dx[d]; int jy = ny + dy[d]; int jx = nx + dx[d]; if (0 <= min(nx, ny) && max(nx, ny) < n && fr(ny, nx, y, x)) { y = ny; x = nx; g[ny][nx] = '#'; p = 0; } else { p++; d = (d + 1) % 4; if (p >= 2) { break; } } } for (int y = n - 1; y >= 0; y--) { for (int x = 0; x < n; x++) { cout << g[y][x]; } cout << endl; } if (ds) { cout << endl; } } return 0; }
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["-", 0, 14, 8, 9, 0, 1, 0, 16, 12, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 12, 22], ["-", 8, 9, 0, 52, 15, 339, 51, 27, 28, 22], ["+", 8, 9, 0, 52, 15, 339, 51, 27, 28, 22], ["-", 0, 52, 8, 9, 0, 57, 15, 339, 51, 22], ["+", 0, 52, 8, 9, 0, 57, 15, 339, 51, 22]]
1
435
8
#include <iostream> using namespace std; #define N 100 #define rep(i, n) for (int i = 0; i < n; ++i) int dx[] = {-1, 0, 1, 0}; int dy[] = {0, -1, 0, 1}; bool inRange(int x, int a, int b) { return a <= x && x <= b; } void drawSpiral(int n) { char mat[N][N]; rep(i, n) rep(j, n) mat[i][j] = ' '; int x = 0, y = n - 1, dir = 1, s = 0, mv = n; mat[y][x] = '#'; while (1) { for (int i = 0; i < mv - 1; ++i) { x += dx[dir]; y += dy[dir]; mat[y][x] = '#'; } if (mv <= 2) break; if (s > 0 && s % 2 == 0) { mv -= 2; if (mv <= 1) break; } dir = (dir + 1) % 4; ++s; } rep(i, n) { rep(j, n) cout << mat[i][j]; cout << endl; } } int main() { int d, n, count = 0; cin >> d; while (d--) { if (count++ > 0) cout << endl; cin >> n; drawSpiral(n); } return 0; }
#include <iostream> using namespace std; #define N 100 #define rep(i, n) for (int i = 0; i < n; ++i) int dx[] = {-1, 0, 1, 0}; int dy[] = {0, -1, 0, 1}; bool inRange(int x, int a, int b) { return a <= x && x <= b; } void drawSpiral(int n) { char mat[N][N]; rep(i, n) rep(j, n) mat[i][j] = ' '; int x = 0, y = n - 1, dir = 1, s = 0, mv = n; mat[y][x] = '#'; while (1) { for (int i = 0; i < mv - 1; ++i) { x += dx[dir]; y += dy[dir]; mat[y][x] = '#'; } if (mv <= 2 && s > 0) break; if (s > 0 && s % 2 == 0) { mv -= 2; if (mv <= 1) break; } dir = (dir + 1) % 4; ++s; } rep(i, n) { rep(j, n) cout << mat[i][j]; cout << endl; } } int main() { int d, n, count = 0; cin >> d; while (d--) { if (count++ > 0) cout << endl; cin >> n; drawSpiral(n); } 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, 47], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
1
321
4
puts ("1\n"..gets).map{n=gets.to_i n<2?"#\n":n<3?"# \n"*2:(a=[?#*n+?\n]+(2..n).map{?#+" "*(n-2)+"#\n"} c=i=j=n-1 d=[[1,0],[0,-1],[-1,0],[0,1]] (c=0;(x,y),_=d.rotate!;(c+=1;a[i+=x][j+=y]=?#)while a[i+x*2][j+y*2]<?#)while c>1 a*"")}*?\n
puts ("1\n"..gets).map{n=gets.to_i n<2?"#\n":n<3?"##\n# \n":(a=[?#*n+?\n]+(2..n).map{?#+" "*(n-2)+"#\n"} c=i=j=n-1 d=[[1,0],[0,-1],[-1,0],[0,1]] (c=0;(x,y),_=d.rotate!;(c+=1;a[i+=x][j+=y]=?#)while a[i+x*2][j+y*2]<?#)while c>1 a*"")}*?\n
[["+", 8, 734, 0, 754, 75, 754, 64, 557, 0, 6], ["+", 8, 734, 0, 754, 75, 754, 64, 557, 0, 44], ["-", 8, 734, 0, 754, 75, 754, 64, 738, 17, 48], ["-", 8, 734, 0, 754, 75, 754, 64, 738, 12, 612]]
4
178
4
def f(n): spiral = [list(' ' for i in range(n)) for i in range(n)] for i in range(n): spiral[i][0] = '#' for i in range(n): spiral[0][i] = '#' for i in range(n): spiral[i][-1] = '#' return spiral def draw(n, m): #down for w in range(m, n): spiral[n-1][w] = '#' if n-m == 2: return #left for h in range(m, n): spiral[h][m] = '#' if n-m == 3: return #up for w in range(m, n-2): spiral[m][w] = '#' if n-m == 4: return #right for h in range(m, n-2): spiral[h][n-3] = '#' if n-m == 5: return draw(n-2, m+2) c = 0 for i in range(eval(input())): if c != 0: print() n = eval(input()) if n == 1: spiral = [['#']] elif n == 2: spiral = [['#'],['#']] elif 3 <= n: spiral = f(n) if 4 <= n: draw(n, 2) for line in spiral: print(''.join(line)) c = 1
def f(n): spiral = [list(' ' for i in range(n)) for i in range(n)] for i in range(n): spiral[i][0] = '#' for i in range(n): spiral[0][i] = '#' for i in range(n): spiral[i][-1] = '#' return spiral def draw(n, m): #down for w in range(m, n): spiral[n-1][w] = '#' if n-m == 2: return #left for h in range(m, n): spiral[h][m] = '#' if n-m == 3: return #up for w in range(m, n-2): spiral[m][w] = '#' if n-m == 4: return #right for h in range(m, n-2): spiral[h][n-3] = '#' if n-m == 5: return draw(n-2, m+2) c = 0 for i in range(eval(input())): if c != 0: print() n = eval(input()) if n == 1: spiral = [['#']] elif n == 2: spiral = [['##'],['# ']] elif 3 <= n: spiral = f(n) if 4 <= n: draw(n, 2) for line in spiral: print(''.join(line)) c = 1
[["-", 0, 662, 12, 634, 0, 634, 0, 557, 0, 6], ["+", 0, 662, 12, 634, 0, 634, 0, 557, 0, 6]]
5
342
4
#include <stdio.h> #include <string.h> int N, c[10005], p[10005], i, j, t; int main() { for (; scanf("%d", &N), N;) { memset(c, 0, sizeof(c)); memset(p, 0, sizeof(p)); for (i = 1; i < N; i++) p[i * i % N] = 1; for (i = 1; i <= 10000; i++) for (j = 1; j <= 10000; j++) if (i != j && p[i] && p[j]) { t = i - j; if (t < 0) t += N; if (t > (N - 1) / 2) t = N - t; c[t]++; } for (i = 1; i <= (N - 1) / 2; i++) printf("%d\n", c[i]); } return 0; }
#include <stdio.h> #include <string.h> int N, c[10005], p[10005], i, j, t; int main() { for (; scanf("%d", &N), N;) { memset(c, 0, sizeof(c)); memset(p, 0, sizeof(p)); for (i = 1; i < N; i++) p[i * i % N] = 1; for (i = 0; i <= 10000; i++) for (j = 0; j <= 10000; j++) if (i != j && p[i] && p[j]) { t = i - j; if (t < 0) t += N; if (t > (N - 1) / 2) t = N - t; c[t]++; } for (i = 1; i <= (N - 1) / 2; i++) printf("%d\n", c[i]); } return 0; }
[["-", 0, 7, 8, 9, 0, 7, 10, 11, 12, 13], ["+", 0, 7, 8, 9, 0, 7, 10, 11, 12, 13], ["-", 8, 9, 0, 7, 8, 7, 10, 11, 12, 13], ["+", 8, 9, 0, 7, 8, 7, 10, 11, 12, 13]]
0
214
4
#include <bits/stdc++.h> #define R(i, n) for (int i = 0; i < n; i++) using namespace std; int main() { int n; cin >> n; while (n--) { int i, k = 1500, m2 = 10000, m1 = 0; char a[3000]; string s; cin >> s; a[k] = s[0]; for (i = 1; i < s.size(); i += 3) { if (s[i] == '-') k--; else k++; a[k] = s[i + 2]; m1 = max(m1, k); m2 = min(m2, k); } for (i = m1 + 1; i >= m2; i--) cout << a[i]; cout << endl; } }
#include <bits/stdc++.h> #define R(i, n) for (int i = 0; i < n; i++) using namespace std; int main() { int n; cin >> n; while (n--) { int i, k = 1500, m2 = 1500, m1 = 1500; char a[3000]; string s; cin >> s; a[k] = s[0]; for (i = 1; i < s.size(); i += 3) { if (s[i] == '-') k--; else k++; a[k] = s[i + 2]; m1 = max(m1, k); m2 = min(m2, k); } for (i = m1; i >= m2; i--) cout << a[i]; cout << endl; } }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["-", 8, 9, 0, 7, 10, 11, 12, 16, 17, 72], ["-", 8, 9, 0, 7, 10, 11, 12, 16, 12, 13]]
1
166
6
#include <iostream> #include <string> int main() { int n; std::cin >> n; for (int i = 0; i < n; i++) { char train[60]; for (int j = 0; j < 30; j++) train[j] = '?'; int it = 30; std::string str; std::cin >> str; train[it] = str[0]; for (int j = 1; j < str.size(); j++) { if (str[j] == '>') { it++; if (train[it] != str[j + 1]) train[it] = str[j + 1]; } else if (str[j] == '<') { it--; if (train[it] != str[j + 2]) train[it] = str[j + 2]; } } for (int j = 0; j < 30; j++) { if (train[j] != '?') std::cout << train[j]; } std::cout << std::endl; } return 0; }
#include <iostream> #include <string> int main() { int n; std::cin >> n; for (int i = 0; i < n; i++) { char train[60]; for (int j = 0; j < 60; j++) train[j] = '?'; int it = 30; std::string str; std::cin >> str; train[it] = str[0]; for (int j = 1; j < str.size(); j++) { if (str[j] == '>') { it++; if (train[it] != str[j + 1]) train[it] = str[j + 1]; } else if (str[j] == '<') { it--; if (train[it] != str[j + 2]) train[it] = str[j + 2]; } } for (int j = 0; j < 60; j++) { if (train[j] != '?') std::cout << train[j]; } std::cout << std::endl; } return 0; }
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13]]
1
242
4
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for (int i = 0; i < n; i++) { boolean[][] map = new boolean[10][10]; for (int j = 0; j < 10; j++) { for (int k = 0; k < 10; k++) { map[j][k] = (sc.nextInt() == 1) ? true : false; } } for (int j = 0; j < 1 << 10; j++) { boolean[][] cpMap = new boolean[10][10]; boolean[][] faMap = new boolean[10][10]; for (int k = 0; k < 10; k++) { cpMap[k] = Arrays.copyOf(map[k], 10); } for (int k = 0; k < 10; k++) { if ((j & 1 << k) == 1) { faMap[0][k] = true; fa(cpMap, 0, k); } } for (int k = 1; k < 10; k++) { for (int l = 0; l < 10; l++) { if (cpMap[k - 1][l]) { fa(cpMap, k, l); faMap[k][l] = true; } } } if (check(cpMap)) { show(faMap); break; } } } } public static void show(boolean[][] a) { for (int i = 0; i < 10; i++) { if (a[i][0]) { System.out.print(1); } else { System.out.print(0); } for (int j = 1; j < 10; j++) { if (a[i][j]) { System.out.print(" " + 1); } else { System.out.print(" " + 0); } } System.out.println(); } } public static boolean check(boolean[][] a) { for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { if (a[i][j]) return false; } } return true; } public static void fa(boolean[][] a, int b, int c) { a[b][c] = (a[b][c]) ? false : true; for (int i = 0; i < 4; i++) { if (fb(b + vy[i], c + vx[i])) { a[b + vy[i]][c + vx[i]] = (a[b + vy[i]][c + vx[i]]) ? false : true; } } } public static boolean fb(int b, int c) { if (b < 0 || c < 0 || b >= 10 || c >= 10) return false; return true; } static int[] vx = new int[] {1, 0, -1, 0}; static int[] vy = new int[] {0, 1, 0, -1}; }
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for (int i = 0; i < n; i++) { boolean[][] map = new boolean[10][10]; for (int j = 0; j < 10; j++) { for (int k = 0; k < 10; k++) { map[j][k] = (sc.nextInt() == 1) ? true : false; } } for (int j = 0; j < 1 << 10; j++) { boolean[][] cpMap = new boolean[10][10]; boolean[][] faMap = new boolean[10][10]; for (int k = 0; k < 10; k++) { cpMap[k] = Arrays.copyOf(map[k], 10); } for (int k = 0; k < 10; k++) { if ((j & 1 << k) != 0) { faMap[0][k] = true; fa(cpMap, 0, k); } } for (int k = 1; k < 10; k++) { for (int l = 0; l < 10; l++) { if (cpMap[k - 1][l]) { fa(cpMap, k, l); faMap[k][l] = true; } } } if (check(cpMap)) { show(faMap); break; } } } } public static void show(boolean[][] a) { for (int i = 0; i < 10; i++) { if (a[i][0]) { System.out.print(1); } else { System.out.print(0); } for (int j = 1; j < 10; j++) { if (a[i][j]) { System.out.print(" " + 1); } else { System.out.print(" " + 0); } } System.out.println(); } } public static boolean check(boolean[][] a) { for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { if (a[i][j]) return false; } } return true; } public static void fa(boolean[][] a, int b, int c) { a[b][c] = (a[b][c]) ? false : true; for (int i = 0; i < 4; i++) { if (fb(b + vy[i], c + vx[i])) { a[b + vy[i]][c + vx[i]] = (a[b + vy[i]][c + vx[i]]) ? false : true; } } } public static boolean fb(int b, int c) { if (b < 0 || c < 0 || b >= 10 || c >= 10) return false; return true; } static int[] vx = new int[] {1, 0, -1, 0}; static int[] vy = new int[] {0, 1, 0, -1}; }
[["-", 8, 196, 0, 57, 15, 15, 0, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 15, 0, 16, 12, 499], ["+", 8, 196, 0, 57, 15, 15, 0, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 15, 0, 16, 12, 499]]
3
740
4
import java.io.*; public class Main { public static void main(String args[]) { try { new Main(); } catch (IOException e) { e.printStackTrace(); } } public int[][] offset = new int[][] {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; public Main() throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String line = in.readLine(); int size = Integer.parseInt(line); for (int n = 0; n < size; n++) { int[][] data = new int[10][10]; for (int y = 0; y < 10; y++) { line = in.readLine(); String[] tmp = line.split(" "); for (int x = 0; x < 10; x++) { data[y][x] = Integer.parseInt(tmp[x]); } } int[][] button = solve(data); for (int y = 0; y < 10; y++) { for (int x = 0; x < 10; x++) { System.out.print(button[y][x]); if (x != 9) System.out.print(" "); } System.out.println(); } } } public int[][] solve(int[][] prob) { int is_break = 0; int[][] button = null; for (int i = 0; i < 1024; i++) { int[][] data = deepClone(prob); button = new int[10][10]; int[] bin = num_to_bin(i); for (int x = 0; x < 10; x++) { if (bin[x] == 1) { button[0][x] = 1; data[0][x] ^= 1; for (int d = 0; d < 3; d++) { int xx = x + offset[d][0]; int yy = offset[d][1]; if (xx >= 0 && yy >= 0 && xx < 10 && yy < 10) { data[yy][xx] ^= 1; } } } } for (int y = 1; y < 10; y++) { for (int x = 0; x < 10; x++) { if (data[y - 1][x] == 1) { button[y][x] ^= 1; data[y][x] ^= 1; for (int d = 0; d < 4; d++) { int xx = x + offset[d][0]; int yy = y + offset[d][1]; if (xx >= 0 && yy >= 0 && xx < 10 && yy < 10) { data[yy][xx] ^= 1; } } } } } is_break = 1; for (int x = 0; x < 10; x++) { if (data[9][x] == 1) { is_break = 0; break; } } if (is_break == 1) { break; } } return button; } public int[][] deepClone(int[][] data) { int[][] copy = new int[10][10]; for (int y = 0; y < 10; y++) { for (int x = 0; x < 10; x++) { copy[y][x] = data[y][x]; } } return copy; } public int[] num_to_bin(int n) { int[] bin = new int[10]; for (int i = 0; i < 10; i++) { if (n % 2 == 0) { bin[i] = 0; } else { bin[i] = 1; } n = n / 2; } return bin; } }
import java.io.*; public class Main { public static void main(String args[]) { try { new Main(); } catch (IOException e) { e.printStackTrace(); } } public int[][] offset = new int[][] {{-1, 0}, {1, 0}, {0, 1}, {0, -1}}; public Main() throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String line = in.readLine(); int size = Integer.parseInt(line); for (int n = 0; n < size; n++) { int[][] data = new int[10][10]; for (int y = 0; y < 10; y++) { line = in.readLine(); String[] tmp = line.split(" "); for (int x = 0; x < 10; x++) { data[y][x] = Integer.parseInt(tmp[x]); } } int[][] button = solve(data); for (int y = 0; y < 10; y++) { for (int x = 0; x < 10; x++) { System.out.print(button[y][x]); if (x != 9) System.out.print(" "); } System.out.println(); } } } public int[][] solve(int[][] prob) { int is_break = 0; int[][] button = null; for (int i = 0; i < 1024; i++) { int[][] data = deepClone(prob); button = new int[10][10]; int[] bin = num_to_bin(i); for (int x = 0; x < 10; x++) { if (bin[x] == 1) { button[0][x] = 1; data[0][x] ^= 1; for (int d = 0; d < 3; d++) { int xx = x + offset[d][0]; int yy = offset[d][1]; if (xx >= 0 && yy >= 0 && xx < 10 && yy < 10) { data[yy][xx] ^= 1; } } } } for (int y = 1; y < 10; y++) { for (int x = 0; x < 10; x++) { if (data[y - 1][x] == 1) { button[y][x] ^= 1; data[y][x] ^= 1; for (int d = 0; d < 4; d++) { int xx = x + offset[d][0]; int yy = y + offset[d][1]; if (xx >= 0 && yy >= 0 && xx < 10 && yy < 10) { data[yy][xx] ^= 1; } } } } } is_break = 1; for (int x = 0; x < 10; x++) { if (data[9][x] == 1) { is_break = 0; break; } } if (is_break == 1) { break; } } return button; } public int[][] deepClone(int[][] data) { int[][] copy = new int[10][10]; for (int y = 0; y < 10; y++) { for (int x = 0; x < 10; x++) { copy[y][x] = data[y][x]; } } return copy; } public int[] num_to_bin(int n) { int[] bin = new int[10]; for (int i = 0; i < 10; i++) { if (n % 2 == 0) { bin[i] = 0; } else { bin[i] = 1; } n = n / 2; } return bin; } }
[["-", 51, 227, 51, 518, 0, 518, 0, 91, 17, 33], ["+", 51, 227, 51, 518, 0, 518, 0, 91, 17, 33]]
3
865
2
/* AOJ 0131 Title: @kankichi573 */ #include <stdio.h> #include <string.h> int n; int ph[10][10]; // photon mult. int ph_org[10][10]; int r[10][10]; void inv(int i, int j) { ph[i][j] ^= 1; if (i > 0) ph[i - 1][j] ^= 1; if (i < 9) ph[i + 1][j] ^= 1; if (j > 0) ph[i][j - 1] ^= 1; if (j < 9) ph[i][j + 1] ^= 1; } void find1(int *y, int *x) { int i, j; for (i = 0; i < 10; i++) for (j = 0; j < 10; j++) if (ph[i][j]) { *y = i; *x = j; return; } *y = *x = -1; } void output() { int i, j; for (i = 0; i < 10; i++) { for (j = 0; j < 9; j++) printf("%d ", r[i][j]); printf("%d", r[i][10]); printf("\n"); } // printf("---------\n"); } void display() { int i, j; for (i = 0; i < 10; i++) { for (j = 0; j < 10; j++) printf("%d ", ph[i][j]); printf("\n"); } // printf("---------\n"); } int is_all_off() { int i, j; for (i = 0; i < 10; i++) for (j = 0; j < 10; j++) if (ph[i][j]) return (0); return (-1); } void solve() { int y, x, i, pos, bit; for (i = 0; i < 1024; i++) { memset(r, 0, sizeof(int) * 10 * 10); memcpy(ph, ph_org, sizeof(int) * 10 * 10); for (pos = 0; pos < 10; pos++) { bit = 1 << pos; if (bit & i) { r[0][pos] ^= 1; inv(0, pos); } } // display(); while (find1(&y, &x), y != -1 && y < 9) { r[y + 1][x] ^= 1; inv(y + 1, x); // display(); if (is_all_off()) return; } } } main() { int i, j, k; scanf("%d", &n); for (i = 0; i < n; i++) { for (j = 0; j < 10; j++) for (k = 0; k < 10; k++) scanf("%d", &ph_org[j][k]); solve(); output(); } return (0); }
/* AOJ 0131 Title: @kankichi573 */ #include <stdio.h> #include <string.h> int n; int ph[10][10]; // photon mult. int ph_org[10][10]; int r[10][10]; void inv(int i, int j) { ph[i][j] ^= 1; if (i > 0) ph[i - 1][j] ^= 1; if (i < 9) ph[i + 1][j] ^= 1; if (j > 0) ph[i][j - 1] ^= 1; if (j < 9) ph[i][j + 1] ^= 1; } void find1(int *y, int *x) { int i, j; for (i = 0; i < 10; i++) for (j = 0; j < 10; j++) if (ph[i][j]) { *y = i; *x = j; return; } *y = *x = -1; } void output() { int i, j; for (i = 0; i < 10; i++) { for (j = 0; j < 9; j++) printf("%d ", r[i][j]); printf("%d", r[i][9]); printf("\n"); } // printf("---------\n"); } void display() { int i, j; for (i = 0; i < 10; i++) { for (j = 0; j < 10; j++) printf("%d ", ph[i][j]); printf("\n"); } // printf("---------\n"); } int is_all_off() { int i, j; for (i = 0; i < 10; i++) for (j = 0; j < 10; j++) if (ph[i][j]) return (0); return (-1); } void solve() { int y, x, i, pos, bit; for (i = 0; i < 1024; i++) { memset(r, 0, sizeof(int) * 10 * 10); memcpy(ph, ph_org, sizeof(int) * 10 * 10); for (pos = 0; pos < 10; pos++) { bit = 1 << pos; if (bit & i) { r[0][pos] ^= 1; inv(0, pos); } } // display(); while (find1(&y, &x), y != -1 && y < 9) { r[y + 1][x] = 1; inv(y + 1, x); if (is_all_off()) return; } } } main() { int i, j, k; scanf("%d", &n); for (i = 0; i < n; i++) { for (j = 0; j < 10; j++) for (k = 0; k < 10; k++) scanf("%d", &ph_org[j][k]); solve(); output(); } return (0); }
[["-", 0, 1, 0, 2, 3, 4, 0, 69, 71, 13], ["+", 0, 1, 0, 2, 3, 4, 0, 69, 71, 13], ["-", 0, 52, 8, 9, 0, 1, 0, 11, 17, 130], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32]]
0
656
4
// Name: Doctor's Strange Particles // Level: 2 // Category: 全探索 // Note: /** * 一番上の行に対する照射方法を固定すると、それより下の行が全て一意に決まる。 * したがって、一番上の行だけを全探索してシミュレーションすればよい。 * * オーダーは O(2^W HW)。 */ #include <array> #include <iostream> using namespace std; array<int, 1 << 10> eff; bool solve(bool first) { array<int, 10> f; for (int r = 0; r < 10; ++r) { f[r] = 0; for (int c = 0; c < 10; ++c) { int v; cin >> v; f[r] |= (v << c); } } array<int, 10> ans; for (int pat = 0; pat < (1 << 10); ++pat) { int prev = f[0] ^ pat; int pmask = pat; ans[0] = pat; for (int r = 1; r < 10; ++r) { ans[r] = prev; const int tmp = f[r] ^ eff[prev] ^ pmask; pmask = prev; prev = tmp; } if (prev == 0) break; } for (int r = 0; r < 10; ++r) { for (int c = 0; c < 10; ++c) { if (c > 0) cout << ' '; cout << !!(ans[r] & (1 << c)); } cout << endl; } return true; } int main() { cin.tie(0); ios::sync_with_stdio(0); cout.setf(ios::fixed); cout.precision(10); for (int pat = 0; pat < (1 << 10); ++pat) { eff[pat] = pat; for (int c = 0; c < 10; ++c) { if (pat & (1 << c)) { if (c > 0) eff[pat] ^= (1 << (c - 1)); if (c < 9) eff[pat] ^= (1 << (c + 1)); } } } bool first = true; int N; cin >> N; while (N-- && solve(first)) { first = false; } return 0; }
// Name: Doctor's Strange Particles // Level: 2 // Category: 全探索 // Note: /** * 一番上の行に対する照射方法を固定すると、それより下の行が全て一意に決まる。 * したがって、一番上の行だけを全探索してシミュレーションすればよい。 * * オーダーは O(2^W HW)。 */ #include <array> #include <iostream> using namespace std; array<int, 1 << 10> eff; bool solve(bool first) { array<int, 10> f; for (int r = 0; r < 10; ++r) { f[r] = 0; for (int c = 0; c < 10; ++c) { int v; cin >> v; f[r] |= (v << c); } } array<int, 10> ans; for (int pat = 0; pat < (1 << 10); ++pat) { int prev = f[0] ^ eff[pat]; int pmask = pat; ans[0] = pat; for (int r = 1; r < 10; ++r) { ans[r] = prev; const int tmp = f[r] ^ eff[prev] ^ pmask; pmask = prev; prev = tmp; } if (prev == 0) break; } for (int r = 0; r < 10; ++r) { for (int c = 0; c < 10; ++c) { if (c > 0) cout << ' '; cout << !!(ans[r] & (1 << c)); } cout << endl; } return true; } int main() { cin.tie(0); ios::sync_with_stdio(0); cout.setf(ios::fixed); cout.precision(10); for (int pat = 0; pat < (1 << 10); ++pat) { eff[pat] = pat; for (int c = 0; c < 10; ++c) { if (pat & (1 << c)) { if (c > 0) eff[pat] ^= (1 << (c - 1)); if (c < 9) eff[pat] ^= (1 << (c + 1)); } } } bool first = true; int N; cin >> N; while (N-- && solve(first)) { first = false; } return 0; }
[["+", 0, 43, 49, 50, 51, 16, 12, 69, 28, 22], ["+", 49, 50, 51, 16, 12, 69, 341, 342, 0, 70], ["+", 49, 50, 51, 16, 12, 69, 341, 342, 0, 73]]
1
433
3
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> i_i; #define PI 3.141592653589793238462643383279 #define mod 1000000007LL #define rep(i, n) for (i = 0; i < n; ++i) #define rep1(i, n) for (i = 1; i < n; ++i) #define per(i, n) for (i = n - 1; i > -1; --i) #define int(x) \ int x; \ scanf("%d", &x) #define int2(x, y) \ int x, y; \ scanf("%d%d", &x, &y) #define int3(x, y, z) \ int x, y, z; \ scanf("%d%d%d", &x, &y, &z) #define int4(v, x, y, z) \ int v, x, y, z; \ scanf("%d%d%d%d", &v, &x, &y, &z) #define int5(v, w, x, y, z) \ int v, w, x, y, z; \ scanf("%d%d%d%d%d", &v, &w, &x, &y, &z) #define ll2(x, y) \ ll x, y; \ cin >> x >> y; #define scn(n, a) rep(i, n) cin >> a[i] #define sc2n(n, a, b) rep(i, n) cin >> a[i] >> b[i] #define pri(x) cout << (x) << "\n" #define pri2(x, y) cout << (x) << " " << (y) << "\n" #define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n" #define pb push_back #define mp make_pair #define all(a) (a).begin(), (a).end() #define endl "\n" #define kabe puts("---------------------------") #define kara puts("") #define debug(x) cout << " --- " << (x) << "\n" #define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n" #define debug3(x, y, z) \ cout << " --- " << (x) << " " << (y) << " " << (z) << "\n" #define X first #define Y second #define eps 0.0001 #define prid(x) printf("%.15lf\n", x) int a[12][12]; int f[12][12]; int res[12][12]; int b[20] = {1}; int dh[5] = {0, 0, 0, 1, -1}; int dw[5] = {0, 1, -1, 0, 0}; signed main(void) { int i, j, k, l; rep1(i, 20) b[i] = b[i - 1] << 1; for (int testcase = 0; testcase >= 0; testcase++) { int(n); for (; n--;) { rep(i, 10) rep(j, 10) scanf("%d", &a[i + 1][j + 1]); rep(k, b[10]) { rep(i, 12) rep(j, 12) { f[i][j] = a[i][j]; res[i][j] = 0; } for (int x = k, d = 1; x; x /= 2) { res[1][d++] = x % 2; if (x % 2 == 1) rep(l, 5) f[1 + dh[l]][d + dw[l]] ^= 1; } rep1(i, 10) rep(j, 10) if (f[i][j + 1] == 1) { res[i + 1][j + 1] = 1; rep(l, 5) f[i + 1 + dh[l]][j + 1 + dw[l]] ^= 1; } bool isok = true; rep(i, 10) rep(j, 10) if (f[i + 1][j + 1] == 1) isok = false; if (isok) { rep(i, 10) { rep(j, 9) printf("%d ", res[i + 1][j + 1]); printf("%d\n", res[i + 1][j + 1]); } break; } } } /*/ //*/ break; } return 0; }
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> i_i; #define PI 3.141592653589793238462643383279 #define mod 1000000007LL #define rep(i, n) for (i = 0; i < n; ++i) #define rep1(i, n) for (i = 1; i < n; ++i) #define per(i, n) for (i = n - 1; i > -1; --i) #define int(x) \ int x; \ scanf("%d", &x) #define int2(x, y) \ int x, y; \ scanf("%d%d", &x, &y) #define int3(x, y, z) \ int x, y, z; \ scanf("%d%d%d", &x, &y, &z) #define int4(v, x, y, z) \ int v, x, y, z; \ scanf("%d%d%d%d", &v, &x, &y, &z) #define int5(v, w, x, y, z) \ int v, w, x, y, z; \ scanf("%d%d%d%d%d", &v, &w, &x, &y, &z) #define ll2(x, y) \ ll x, y; \ cin >> x >> y; #define scn(n, a) rep(i, n) cin >> a[i] #define sc2n(n, a, b) rep(i, n) cin >> a[i] >> b[i] #define pri(x) cout << (x) << "\n" #define pri2(x, y) cout << (x) << " " << (y) << "\n" #define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n" #define pb push_back #define mp make_pair #define all(a) (a).begin(), (a).end() #define endl "\n" #define kabe puts("---------------------------") #define kara puts("") #define debug(x) cout << " --- " << (x) << "\n" #define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n" #define debug3(x, y, z) \ cout << " --- " << (x) << " " << (y) << " " << (z) << "\n" #define X first #define Y second #define eps 0.0001 #define prid(x) printf("%.15lf\n", x) int a[12][12]; int f[12][12]; int res[12][12]; int b[20] = {1}; int dh[5] = {0, 0, 0, 1, -1}; int dw[5] = {0, 1, -1, 0, 0}; signed main(void) { int i, j, k, l; rep1(i, 20) b[i] = b[i - 1] << 1; for (int testcase = 0; testcase >= 0; testcase++) { int(n); for (; n--;) { rep(i, 10) rep(j, 10) scanf("%d", &a[i + 1][j + 1]); rep(k, b[10]) { rep(i, 12) rep(j, 12) { f[i][j] = a[i][j]; res[i][j] = 0; } for (int x = k, d = 1; x; x /= 2) { res[1][d] = x % 2; if (x % 2 == 1) rep(l, 5) f[1 + dh[l]][d + dw[l]] ^= 1; ++d; } rep1(i, 10) rep(j, 10) if (f[i][j + 1] == 1) { res[i + 1][j + 1] = 1; rep(l, 5) f[i + 1 + dh[l]][j + 1 + dw[l]] ^= 1; } bool isok = true; rep(i, 10) rep(j, 10) if (f[i + 1][j + 1] == 1) isok = false; if (isok) { rep(i, 10) { rep(j, 9) printf("%d ", res[i + 1][j + 1]); printf("%d\n", res[i + 1][j + 1]); } break; } } } /*/ //*/ break; } return 0; }
[["-", 0, 11, 31, 69, 341, 342, 0, 27, 17, 29], ["+", 0, 7, 8, 9, 0, 57, 64, 1, 0, 35], ["+", 0, 7, 8, 9, 0, 1, 0, 27, 17, 29], ["+", 0, 7, 8, 9, 0, 1, 0, 27, 28, 22]]
1
719
4
#include <bits/stdc++.h> #define l(i, n) for (int i = 0; i < n; i++) using namespace std; bool m[12][12], c[12][12], d[12][12], q; int main() { int n; cin >> n; l(u, n) { l(i, 10) l(j, 10) cin >> m[i][j]; bool f[10], t[10] = {0}; for (int p = 1; p <= 1024; p++) { l(i, 10) f[i] = t[i]; l(i, 10) l(j, 10) c[i][j] = m[i][j]; l(k, 10) { l(i, 10) if (f[i]) { for (int j = max(0, i - 1); j <= min(9, i + 1); j++) c[k][j] ^= 1; c[k + 1][i] ^= 1; } l(i, 10) d[k][i] = f[i]; l(i, 10) f[i] = c[k][i]; } q = 0; l(i, 10) q |= f[i]; if (!q) { l(i, 10) l(j, 10) { if (j) cout << " "; cout << d[i][j]; } cout << endl; break; } l(i, 10) if (p % (int)pow(2, i) == 0) t[i] ^= 1; } } return 0; }
#include <bits/stdc++.h> #define l(i, n) for (int i = 0; i < n; i++) using namespace std; bool m[12][12], c[12][12], d[12][12], q; int main() { int n; cin >> n; l(u, n) { l(i, 10) l(j, 10) cin >> m[i][j]; bool f[10], t[10] = {0}; for (int p = 1; p <= 1024; p++) { l(i, 10) f[i] = t[i]; l(i, 10) l(j, 10) c[i][j] = m[i][j]; l(k, 10) { l(i, 10) if (f[i]) { for (int j = max(0, i - 1); j <= min(9, i + 1); j++) c[k][j] ^= 1; c[k + 1][i] ^= 1; } l(i, 10) d[k][i] = f[i]; l(i, 10) f[i] = c[k][i]; } q = 0; l(i, 10) q |= f[i]; if (!q) { l(i, 10) { l(j, 10) { if (j) cout << " "; cout << d[i][j]; } cout << endl; } break; } l(i, 10) if (p % (int)pow(2, i) == 0) t[i] ^= 1; } } return 0; }
[["+", 8, 9, 0, 57, 64, 9, 0, 9, 0, 45], ["+", 8, 9, 0, 57, 64, 9, 0, 9, 0, 46]]
1
369
2
#include <cstring> #include <iostream> using namespace std; int n, s, d[12][12], b[12][12], a[12][12]; int dx[] = {0, 0, 0, 1, -1}; int dy[] = {-1, 1, 0, 0, 0}; void flip(int x, int y) { a[y][x] = 1; for (int i = 0; i < 5; i++) { b[y + dy[i]][x + dx[i]] = 1 - b[y + dy[i]][x + dx[i]]; } } void func() { for (int i = 0; i <= 1024; i++) { memset(a, 0, sizeof(d)); memcpy(b, d, sizeof(d)); for (int y = 1, x = 1; x <= 10; x++) { if ((i >> (x - 1)) & 1) flip(x, y); } for (int y = 2; y <= 10; y++) for (int x = 1; x <= 10; x++) { if (b[y - 1][x]) flip(x, y); } s = 0; for (int y = 10, x = 1; x <= 10; x++) { s += a[y][x]; } if (s == 0) return; } } int main() { cin >> n; while (n--) { for (int y = 1; y <= 10; y++) for (int x = 1; x <= 10; x++) { cin >> d[y][x]; } func(); for (int y = 1; y <= 10; y++) { for (int x = 1; x <= 10; x++) { cout << a[y][x] << (x == 10 ? "" : " "); } cout << endl; } } }
#include <cstring> #include <iostream> using namespace std; int n, s, d[12][12], b[12][12], a[12][12]; int dx[] = {0, 0, 0, 1, -1}; int dy[] = {-1, 1, 0, 0, 0}; void flip(int x, int y) { a[y][x] = 1; for (int i = 0; i < 5; i++) { b[y + dy[i]][x + dx[i]] = 1 - b[y + dy[i]][x + dx[i]]; } } void func() { for (int i = 0; i < 1024; i++) { memset(a, 0, sizeof(a)); memcpy(b, d, sizeof(d)); for (int y = 1, x = 1; x <= 10; x++) { if ((i >> (x - 1)) & 1) flip(x, y); } for (int y = 2; y <= 10; y++) for (int x = 1; x <= 10; x++) { if (b[y - 1][x]) flip(x, y); } s = 0; for (int y = 10, x = 1; x <= 10; x++) { s += b[y][x]; } if (s == 0) return; } } int main() { cin >> n; while (n--) { for (int y = 1; y <= 10; y++) for (int x = 1; x <= 10; x++) { cin >> d[y][x]; } func(); for (int y = 1; y <= 10; y++) { for (int x = 1; x <= 10; x++) { cout << a[y][x] << (x == 10 ? "" : " "); } cout << endl; } } }
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["-", 0, 2, 3, 4, 0, 105, 51, 23, 0, 22], ["+", 0, 2, 3, 4, 0, 105, 51, 23, 0, 22], ["-", 0, 1, 0, 11, 12, 69, 28, 69, 28, 22], ["+", 0, 1, 0, 11, 12, 69, 28, 69, 28, 22]]
1
444
6
#include <cstdio> using namespace std; int memo[11][1024]; int main() { int sw[1024]; for (int i = 0; i < 1024; i++) { sw[i] = 0; if (i & 1) sw[i] ^= 3; for (int j = 1; j < 9; j++) if (i & (1 << j)) sw[i] ^= (7 << (j - 1)); if (i & 512) sw[i] ^= 768; } int t; scanf("%d", &t); while (t--) { int cell[10] = {}; for (int i = 0; i < 10; i++) { cell[i] = 0; for (int j = 0, tmp; j < 10; j++) scanf("%d", &tmp), cell[i] |= (tmp << (9 - j)); } for (int i = 0; i < 1024; i++) memo[0][i] = 0; for (int r = 1; r < 10; r++) { for (int i = 0; i < 1024; i++) { memo[r][i] = -1; for (int b = 0; b < 1024; b++) { if (memo[r - 1][b] == -1) continue; if ((cell[r - 1] ^ memo[r - 1][b] ^ sw[b] ^ i) == 0) memo[r][i] = b; } } } int ans[10]; for (int i = 0, j = memo[10 - i][0]; i < 10; i++, j = memo[10 - i][j]) ans[i] = j; for (int i = 9; i >= 0; i--) { printf(""); for (int k = 9; k >= 0; k--) printf("%s%d", (k == 9 ? "" : " "), (bool)(ans[i] & (1 << k))); puts(""); } } return 0; }
#include <cstdio> using namespace std; int memo[11][1024]; int main() { int sw[1024]; for (int i = 0; i < 1024; i++) { sw[i] = 0; if (i & 1) sw[i] ^= 3; for (int j = 1; j < 9; j++) if (i & (1 << j)) sw[i] ^= (7 << (j - 1)); if (i & 512) sw[i] ^= 768; } int t; scanf("%d", &t); while (t--) { int cell[10] = {}; for (int i = 0; i < 10; i++) { cell[i] = 0; for (int j = 0, tmp; j < 10; j++) scanf("%d", &tmp), cell[i] |= (tmp << (9 - j)); } for (int i = 0; i < 1024; i++) memo[0][i] = 0; for (int r = 1; r <= 10; r++) { for (int i = 0; i < 1024; i++) { memo[r][i] = -1; for (int b = 0; b < 1024; b++) { if (memo[r - 1][b] == -1) continue; if ((cell[r - 1] ^ memo[r - 1][b] ^ sw[b] ^ i) == 0) memo[r][i] = b; } } } int ans[10]; for (int i = 0, j = memo[10 - i][0]; i < 10; i++, j = memo[10 - i][j]) ans[i] = j; for (int i = 9; i >= 0; i--) { for (int k = 9; k >= 0; k--) printf("%s%d", (k == 9 ? "" : " "), (bool)(ans[i] & (1 << k))); puts(""); } } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 9, 0, 1, 0, 2, 63, 22], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 62], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["-", 8, 9, 0, 7, 8, 9, 0, 1, 0, 35]]
1
478
8
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <list> #include <string> #include <vector> using namespace std; int f(int p[][12], int q[][12], int x) { int i, j; int r[12][12], s[12][12]; if (x == 11) { for (i = 2; i < 10; i++) { for (j = 1; j < 11; j++) { if (p[j][i]) { p[j][i] = (p[j][i] + 1) % 2; p[j - 1][i + 1] = (p[j - 1][i + 1] + 1) % 2; p[j][i + 1] = (p[j][i + 1] + 1) % 2; p[j + 1][i + 1] = (p[j + 1][i + 1] + 1) % 2; p[j][i + 2] = (p[j][i + 2] + 1) % 2; q[j][i + 1] = 1; } } } for (i = 1; i < 11; i++) { if (p[i][10]) break; } if (i == 11) { for (i = 1; i < 11; i++) { for (j = 1; j < 10; j++) cout << q[j][i] << " "; cout << q[i][j] << endl; } return 1; } } else if (x == 10) { if (p[x][1]) { memcpy(r, p, sizeof(r)); memcpy(s, q, sizeof(s)); r[x][1] = (r[x][1] + 1) % 2; r[x - 1][2] = (r[x - 1][2] + 1) % 2; r[x][2] = (r[x][2] + 1) % 2; r[x + 1][2] = (r[x + 1][2] + 1) % 2; r[x][3] = (r[x][3] + 1) % 2; s[x][2] = 1; if (f(r, s, x + 1)) return 1; } else { memcpy(r, p, sizeof(r)); memcpy(s, q, sizeof(s)); if (f(r, s, x + 1)) return 1; } } else { if (p[x][1]) { memcpy(r, p, sizeof(r)); memcpy(s, q, sizeof(s)); r[x + 1][0] = (r[x + 1][0] + 1) % 2; r[x][1] = (r[x][1] + 1) % 2; r[x + 1][1] = (r[x + 1][1] + 1) % 2; r[x + 2][1] = (r[x + 2][1] + 1) % 2; r[x + 1][2] = (r[x + 1][2] + 1) % 2; s[x + 1][1] = 1; if (f(r, s, x + 1)) return 1; memcpy(r, p, sizeof(r)); memcpy(s, q, sizeof(s)); r[x][1] = (r[x][1] + 1) % 2; r[x - 1][2] = (r[x - 1][2] + 1) % 2; r[x][2] = (r[x][2] + 1) % 2; r[x + 1][2] = (r[x + 1][2] + 1) % 2; r[x][3] = (r[x][3] + 1) % 2; s[x][2] = 1; if (f(r, s, x + 1)) return 1; } else { memcpy(r, p, sizeof(r)); memcpy(s, q, sizeof(s)); if (f(r, s, x + 1)) return 1; memcpy(r, p, sizeof(r)); memcpy(s, q, sizeof(s)); r[x + 1][0] = (r[x + 1][0] + 1) % 2; r[x][1] = (r[x][1] + 1) % 2; r[x + 1][1] = (r[x + 1][1] + 1) % 2; r[x + 2][1] = (r[x + 2][1] + 1) % 2; r[x + 1][2] = (r[x + 1][2] + 1) % 2; s[x + 1][1] = 1; r[x][1] = (r[x][1] + 1) % 2; r[x - 1][2] = (r[x - 1][2] + 1) % 2; r[x][2] = (r[x][2] + 1) % 2; r[x + 1][2] = (r[x + 1][2] + 1) % 2; r[x][3] = (r[x][3] + 1) % 2; s[x][2] = 1; if (f(r, s, x + 1)) return 1; } } return 0; } int main() { int i, j, k; int q[12][12], r[12][12], n; int(*p)[12][12]; cin >> n; p = new int[n][12][12]; for (i = 0; i < n; i++) for (j = 1; j < 11; j++) for (k = 1; k < 11; k++) cin >> p[i][k][j]; for (i = 0; i < n; i++) { memcpy(r, &p[i][0][0], sizeof(r)); memset(q, 0, sizeof(q)); f(r, q, 1); memcpy(r, &p[i][0][0], sizeof(r)); memset(q, 0, sizeof(q)); r[1][0] = (r[1][0] + 1) % 2; r[0][1] = (r[0][1] + 1) % 2; r[1][1] = (r[1][1] + 1) % 2; r[2][1] = (r[2][1] + 1) % 2; r[1][2] = (r[1][2] + 1) % 2; q[1][1] = 1; f(r, q, 1); } delete[] p; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <list> #include <string> #include <vector> using namespace std; int f(int p[][12], int q[][12], int x) { int i, j; int r[12][12], s[12][12]; if (x == 11) { for (i = 2; i < 10; i++) { for (j = 1; j < 11; j++) { if (p[j][i]) { p[j][i] = (p[j][i] + 1) % 2; p[j - 1][i + 1] = (p[j - 1][i + 1] + 1) % 2; p[j][i + 1] = (p[j][i + 1] + 1) % 2; p[j + 1][i + 1] = (p[j + 1][i + 1] + 1) % 2; p[j][i + 2] = (p[j][i + 2] + 1) % 2; q[j][i + 1] = 1; } } } for (i = 1; i < 11; i++) { if (p[i][10]) break; } if (i == 11) { for (i = 1; i < 11; i++) { for (j = 1; j < 10; j++) cout << q[j][i] << " "; cout << q[j][i] << endl; } return 1; } } else if (x == 10) { if (p[x][1]) { memcpy(r, p, sizeof(r)); memcpy(s, q, sizeof(s)); r[x][1] = (r[x][1] + 1) % 2; r[x - 1][2] = (r[x - 1][2] + 1) % 2; r[x][2] = (r[x][2] + 1) % 2; r[x + 1][2] = (r[x + 1][2] + 1) % 2; r[x][3] = (r[x][3] + 1) % 2; s[x][2] = 1; if (f(r, s, x + 1)) return 1; } else { memcpy(r, p, sizeof(r)); memcpy(s, q, sizeof(s)); if (f(r, s, x + 1)) return 1; } } else { if (p[x][1]) { memcpy(r, p, sizeof(r)); memcpy(s, q, sizeof(s)); r[x + 1][0] = (r[x + 1][0] + 1) % 2; r[x][1] = (r[x][1] + 1) % 2; r[x + 1][1] = (r[x + 1][1] + 1) % 2; r[x + 2][1] = (r[x + 2][1] + 1) % 2; r[x + 1][2] = (r[x + 1][2] + 1) % 2; s[x + 1][1] = 1; if (f(r, s, x + 1)) return 1; memcpy(r, p, sizeof(r)); memcpy(s, q, sizeof(s)); r[x][1] = (r[x][1] + 1) % 2; r[x - 1][2] = (r[x - 1][2] + 1) % 2; r[x][2] = (r[x][2] + 1) % 2; r[x + 1][2] = (r[x + 1][2] + 1) % 2; r[x][3] = (r[x][3] + 1) % 2; s[x][2] = 1; if (f(r, s, x + 1)) return 1; } else { memcpy(r, p, sizeof(r)); memcpy(s, q, sizeof(s)); if (f(r, s, x + 1)) return 1; memcpy(r, p, sizeof(r)); memcpy(s, q, sizeof(s)); r[x + 1][0] = (r[x + 1][0] + 1) % 2; r[x][1] = (r[x][1] + 1) % 2; r[x + 1][1] = (r[x + 1][1] + 1) % 2; r[x + 2][1] = (r[x + 2][1] + 1) % 2; r[x + 1][2] = (r[x + 1][2] + 1) % 2; s[x + 1][1] = 1; r[x][1] = (r[x][1] + 1) % 2; r[x - 1][2] = (r[x - 1][2] + 1) % 2; r[x][2] = (r[x][2] + 1) % 2; r[x + 1][2] = (r[x + 1][2] + 1) % 2; r[x][3] = (r[x][3] + 1) % 2; s[x][2] = 1; if (f(r, s, x + 1)) return 1; } } return 0; } int main() { int i, j, k; int q[12][12], r[12][12], n; int(*p)[12][12]; cin >> n; p = new int[n][12][12]; for (i = 0; i < n; i++) for (j = 1; j < 11; j++) for (k = 1; k < 11; k++) cin >> p[i][k][j]; for (i = 0; i < n; i++) { memcpy(r, &p[i][0][0], sizeof(r)); memset(q, 0, sizeof(q)); f(r, q, 1); memcpy(r, &p[i][0][0], sizeof(r)); memset(q, 0, sizeof(q)); r[1][0] = (r[1][0] + 1) % 2; r[0][1] = (r[0][1] + 1) % 2; r[1][1] = (r[1][1] + 1) % 2; r[2][1] = (r[2][1] + 1) % 2; r[1][2] = (r[1][2] + 1) % 2; q[1][1] = 1; f(r, q, 1); } delete[] p; return 0; }
[["-", 31, 16, 12, 69, 28, 69, 341, 342, 0, 22], ["+", 31, 16, 12, 69, 28, 69, 341, 342, 0, 22], ["-", 0, 16, 31, 16, 12, 69, 341, 342, 0, 22], ["+", 0, 16, 31, 16, 12, 69, 341, 342, 0, 22]]
1
1,644
4
#!/usr/bin/ruby def lightsout(x,y) now=Time.now.to_f succ=0 a=Array.new(x*y) a.length.times{|i| a[i]=Array.new(2)} #create problem x.times {|i| y.times {|j| a[i+j*x][0]=1<<(i+j*x) a[i+j*x][1]= 0 + (1<<(i+j*x)) + (i>0 ? 1<<(i-1+j*x) : 0) + (i<x-1 ? 1<<(i+1+j*x) : 0) + (j>0 ? 1<<(i+(j-1)*x) : 0) + (j<y-1 ? 1<<(i+(j+1)*x) : 0) + =begin (i>0 && j>0 ? 1<<(i-1+(j-1)*x) : 0) + (i<x-1 && j>0 ? 1<<(i+1+(j-1)*x) : 0) + (i>0 && j<y-1 ? 1<<(i-1+(j+1)*x) : 0) + (i<x-1 && j<y-1 ? 1<<(i+1+(j+1)*x) : 0) + =end 0 } } #solve (x*y).times {|i| if a[i][1]&1<<i==0 (i+1).step(x*y-1) {|j| if a[j][1]&1<<i!=0 a[i],a[j]=a[j],a[i] succ=1 break end } if succ==0 then break end #in 6*5 succ is always 1 succ=0 end (x*y).times {|j| if i==j then next end if a[j][1]&1<<i!=0 a[j][0]^=a[i][0] a[j][1]^=a[i][1] end } #$stderr.printf("%d/%d passes\r",i+1,x*y) } #$stderr.print "\n" gets.to_i.times{ prob=[];ans=[0]*x*y y.times{prob+=gets.split.map(&:to_i)} (x*y).times{|i|if prob[i]>0 then (x*y).times{|j|ans[j]^=a[j][0][i]}end} y.times{|i|puts ans[i*x,x].map(&:to_s).join('')} } =begin #output as C print <<"EOM" #include <stdio.h> int table[#{x*y}][#{x*y}] = { EOM a.each {|b| print " {" a.length.times {|c| print "#{b[0][c]}," } print "},\n" } print <<"EOM" }; int prob[#{x*y}], ans[#{x*y}]; main(b,c,i,j){ for(scanf("%d",&c);b<=c;b++){ for(i=0;i<#{x*y};i++) scanf("%d",prob+i),ans[i]=0; for(i=0;i<#{x*y};i++) if(prob[i]) for(j=0;j<#{x*y};j++) ans[j]^=table[i][j]; for(j=0;j<#{y};printf("\\n"),j++) for(i=0;i<#{x};i++) printf(i<#{x-1}?"%d ":"%d",ans[i+j*#{x}]); } return 0; } EOM $stderr.printf("%.3f ms\n",Time.now.to_f-now) =end end lightsout(10,10)
#!/usr/bin/ruby def lightsout(x,y) now=Time.now.to_f succ=0 a=Array.new(x*y) a.length.times{|i| a[i]=Array.new(2)} #create problem x.times {|i| y.times {|j| a[i+j*x][0]=1<<(i+j*x) a[i+j*x][1]= 0 + (1<<(i+j*x)) + (i>0 ? 1<<(i-1+j*x) : 0) + (i<x-1 ? 1<<(i+1+j*x) : 0) + (j>0 ? 1<<(i+(j-1)*x) : 0) + (j<y-1 ? 1<<(i+(j+1)*x) : 0) + =begin (i>0 && j>0 ? 1<<(i-1+(j-1)*x) : 0) + (i<x-1 && j>0 ? 1<<(i+1+(j-1)*x) : 0) + (i>0 && j<y-1 ? 1<<(i-1+(j+1)*x) : 0) + (i<x-1 && j<y-1 ? 1<<(i+1+(j+1)*x) : 0) + =end 0 } } #solve (x*y).times {|i| if a[i][1]&1<<i==0 (i+1).step(x*y-1) {|j| if a[j][1]&1<<i!=0 a[i],a[j]=a[j],a[i] succ=1 break end } if succ==0 then break end #in 6*5 succ is always 1 succ=0 end (x*y).times {|j| if i==j then next end if a[j][1]&1<<i!=0 a[j][0]^=a[i][0] a[j][1]^=a[i][1] end } #$stderr.printf("%d/%d passes\r",i+1,x*y) } #$stderr.print "\n" gets.to_i.times{ prob=[];ans=[0]*x*y y.times{prob+=gets.split.map(&:to_i)} (x*y).times{|i|if prob[i]>0 then (x*y).times{|j|ans[j]^=a[j][0][i]}end} y.times{|i|puts ans[i*x,x].map(&:to_s).join(' ')} } =begin #output as C print <<"EOM" #include <stdio.h> int table[#{x*y}][#{x*y}] = { EOM a.each {|b| print " {" a.length.times {|c| print "#{b[0][c]}," } print "},\n" } print <<"EOM" }; int prob[#{x*y}], ans[#{x*y}]; main(b,c,i,j){ for(scanf("%d",&c);b<=c;b++){ for(i=0;i<#{x*y};i++) scanf("%d",prob+i),ans[i]=0; for(i=0;i<#{x*y};i++) if(prob[i]) for(j=0;j<#{x*y};j++) ans[j]^=table[i][j]; for(j=0;j<#{y};printf("\\n"),j++) for(i=0;i<#{x};i++) printf(i<#{x-1}?"%d ":"%d",ans[i+j*#{x}]); } return 0; } EOM $stderr.printf("%.3f ms\n",Time.now.to_f-now) =end end lightsout(10,10)
[["+", 3, 4, 0, 652, 3, 4, 0, 557, 0, 6]]
4
487
1
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line = ""; char[][] pattern = new char[8][8]; for (int i = 0; i < 8; i++) { line = br.readLine(); for (int j = 0; j < 8; j++) { pattern[i][j] = line.charAt(j); } } for (int i = 1; i <= 3; i++) { pattern = rotate(pattern); System.out.println(i * 90); for (int j = 0; j < 8; j++) { System.out.println(new String(pattern[i])); } } } static char[][] rotate(char[][] pattern) { char[][] rotate = new char[8][8]; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { rotate[j][7 - i] = pattern[i][j]; } } return rotate; } }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line = ""; char[][] pattern = new char[8][8]; for (int i = 0; i < 8; i++) { line = br.readLine(); for (int j = 0; j < 8; j++) { pattern[i][j] = line.charAt(j); } } for (int i = 1; i <= 3; i++) { pattern = rotate(pattern); System.out.println(i * 90); for (int j = 0; j < 8; j++) { System.out.println(new String(pattern[j])); } } } static char[][] rotate(char[][] pattern) { char[][] rotate = new char[8][8]; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { rotate[j][7 - i] = pattern[i][j]; } } return rotate; } }
[["-", 3, 4, 0, 230, 3, 4, 0, 504, 71, 22], ["+", 3, 4, 0, 230, 3, 4, 0, 504, 71, 22]]
3
284
2
#include <stdio.h> int main() { char s[8][8]; int i, j, k; for (i = 0; i < 8; i++) { fgets(s[i], 10, stdin); } printf("90\n"); for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) { printf("%c", s[7 - i][j]); } printf("\n"); } printf("180\n"); for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) { printf("%c", s[7 - i][7 - j]); } printf("\n"); } printf("270\n"); for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) { printf("%c", s[i][7 - j]); } printf("\n"); } return 0; }
#include <stdio.h> int main() { char s[8][8]; int i, j, k; for (i = 0; i < 8; i++) { fgets(s[i], 10, stdin); } printf("90\n"); for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) { printf("%c", s[7 - j][i]); } printf("\n"); } printf("180\n"); for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) { printf("%c", s[7 - i][7 - j]); } printf("\n"); } printf("270\n"); for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) { printf("%c", s[j][7 - i]); } printf("\n"); } return 0; }
[["-", 3, 4, 0, 69, 28, 69, 71, 16, 12, 22], ["+", 3, 4, 0, 69, 28, 69, 71, 16, 12, 22], ["-", 0, 1, 0, 2, 3, 4, 0, 69, 71, 22], ["+", 0, 1, 0, 2, 3, 4, 0, 69, 71, 22], ["-", 0, 2, 3, 4, 0, 69, 28, 69, 71, 22], ["+", 0, 2, 3, 4, 0, 69, 28, 69, 71, 22], ["-", 0, 2, 3, 4, 0, 69, 71, 16, 12, 22], ["+", 0, 2, 3, 4, 0, 69, 71, 16, 12, 22]]
0
242
8
#include <stdio.h> #include <stdlib.h> #include <string.h> int n, i, j, k, x, set, a[50000], b[50000], c[50000]; int main() { while (scanf("%d", &n) * n) { set++; for (i = 1; i < n; i++) if (a[(i * i) % n] != set) a[(i * i) % n] = set; for (i = 1, j = 0; i < n; i++) { if (a[i] == set) { b[j] = i; j++; } } k = j; for (i = 0; i < k - 1; i++) { for (j = i + 1; j < k; j++) { x = b[j] - b[i]; if (x > n / 2) x = n - x; c[x] += 2; } } for (i = 1; i <= n / 2; i++) { printf("%d\n", c[i]); c[i] = 0; } } return 0; }
#include <stdio.h> #include <stdlib.h> #include <string.h> int n, i, j, k, x, set, a[50000], b[50000], c[50000]; int main() { while (scanf("%d", &n) * n) { set++; for (i = 1; i < n; i++) if (a[(i * i) % n] != set) a[(i * i) % n] = set; for (i = 0, j = 0; i < n; i++) { if (a[i] == set) { b[j] = i; j++; } } k = j; for (i = 0; i < k - 1; i++) { for (j = i + 1; j < k; j++) { x = b[j] - b[i]; if (x > n / 2) x = n - x; c[x] += 2; } } for (i = 1; i <= n / 2; i++) { printf("%d\n", c[i]); c[i] = 0; } } return 0; }
[["-", 8, 9, 0, 7, 10, 34, 31, 11, 12, 13], ["+", 8, 9, 0, 7, 10, 34, 31, 11, 12, 13]]
0
251
2
#include <set> #include <stdio.h> #include <vector> using namespace std; const int N = 1e4 + 10; #define PB push_back int abs(int n) { return n > 0 ? n : -n; } int main() { int n, a[N], mid, temp; set<int> s; vector<int> v; while (scanf("%d", &n) != EOF) { if (n == 0) return 0; s.clear(); v.clear(); for (int i = 1; i < n; i++) s.insert((i * i) % n); mid = n >> 1; for (int i = 1; i <= mid; i++) a[i] = 0; for (int i : s) v.PB(i); for (int i = 0; i < v.size(); i++) for (int j = 0; j < v.size(); j++) if (i != j) { temp = abs(v[j] - v[i]); if (temp > mid) a[n - temp]++; else a[temp]++; } for (int i = 1; i <= mid; i++) printf("%d\n", a[i] * 2); } }
#include <set> #include <stdio.h> #include <vector> using namespace std; const int N = 1e4 + 10; #define PB push_back int abs(int n) { return n > 0 ? n : -n; } int main() { int n, a[N], mid, temp; set<int> s; vector<int> v; while (scanf("%d", &n) != EOF) { if (n == 0) return 0; s.clear(); v.clear(); for (int i = 1; i < n; i++) s.insert((i * i) % n); mid = n >> 1; for (int i = 1; i <= mid; i++) a[i] = 0; for (int i : s) v.PB(i); for (int i = 0; i < v.size(); i++) for (int j = 0; j < v.size(); j++) if (i != j) { temp = abs(v[j] - v[i]); if (temp > mid) a[n - temp]++; else a[temp]++; } for (int i = 1; i <= mid; i++) printf("%d\n", a[i]); } }
[["-", 8, 1, 0, 2, 3, 4, 0, 16, 17, 48], ["-", 8, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
1
283
2
#include <algorithm> #include <iostream> using namespace std; const int MAX = 10010; int main(void) { int square[MAX]; for (int i = 1; i < MAX + 1; i++) square[i - 1] = i * i; while (true) { int n, size; int raw_mod[MAX], mod[MAX], hist[MAX] = {}; cin >> n; if (n == 0) break; int m = (n - 1) / 2; for (int i = 0; i < n - 1; i++) raw_mod[i] = square[i] % n; sort(raw_mod, raw_mod + n - 1); mod[0] = raw_mod[0]; for (int i = 1, j = 1; i < n - 1; i++) { if (mod[j - 1] != raw_mod[i]) { mod[j] = raw_mod[i]; j++; } size = j; } for (int i = 0; i < size - 1; i++) for (int j = i + 1; j < size; j++) { int tmp1 = mod[i] - mod[j]; if (tmp1 < 0) tmp1 += n; if (tmp1 > m) tmp1 = n - tmp1; int tmp2 = mod[j] - mod[i]; if (tmp2 < 0) tmp2 += n; if (tmp2 > m) tmp2 = n - tmp2; hist[tmp1 - 1] += 1; hist[tmp2 - 1] += 1; } for (int i = 0; i < size; i++) cout << hist[i] << endl; } return 0; }
#include <algorithm> #include <iostream> using namespace std; const int MAX = 10010; int main(void) { int square[MAX]; for (int i = 1; i < MAX + 1; i++) square[i - 1] = i * i; while (true) { int n, size; int raw_mod[MAX], mod[MAX], hist[MAX] = {}; cin >> n; if (n == 0) break; int m = (n - 1) / 2; for (int i = 0; i < n - 1; i++) raw_mod[i] = square[i] % n; sort(raw_mod, raw_mod + n - 1); mod[0] = raw_mod[0]; for (int i = 1, j = 1; i < n - 1; i++) { if (mod[j - 1] != raw_mod[i]) { mod[j] = raw_mod[i]; j++; } size = j; } for (int i = 0; i < size - 1; i++) for (int j = i + 1; j < size; j++) { int tmp1 = mod[i] - mod[j]; if (tmp1 < 0) tmp1 += n; if (tmp1 > m) tmp1 = n - tmp1; int tmp2 = mod[j] - mod[i]; if (tmp2 < 0) tmp2 += n; if (tmp2 > m) tmp2 = n - tmp2; hist[tmp1 - 1] += 1; hist[tmp2 - 1] += 1; } for (int i = 0; i < m; i++) cout << hist[i] << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22]]
1
359
2
#include <iostream> #include <vector> using namespace std; #define rep2(x, from, to) for (int x = (from); x < (to); ++(x)) #define rep(x, to) rep2(x, 0, to) int main() { int n; while (cin >> n, n) { int a[10000] = {}; int c[5000] = {}; rep2(i, 1, n) { a[(i * i) % n]++; } vector<int> v; rep2(i, 1, n) { if (a[i] != 0) v.push_back(i); } rep(i, v.size()) { rep(j, v.size()) { if (i == j) continue; int s = v[i] - v[j]; if (s < 0) s += n; if (s > (n - 1) / 2) c[n - s]++; else c[s]++; } } rep2(i, 1, (n + 1) / 2) { cout << c[i] << endl; } } return 0; }
#include <iostream> #include <vector> using namespace std; #define rep2(x, from, to) for (int x = (from); x < (to); ++(x)) #define rep(x, to) rep2(x, 0, to) int main() { int n; while (cin >> n, n) { int a[10000] = {}; int c[5000] = {}; rep2(i, 1, n) { a[(i * i) % n]++; } vector<int> v; rep(i, n) { if (a[i] != 0) v.push_back(i); } rep(i, v.size()) { rep(j, v.size()) { if (i == j) continue; int s = v[i] - v[j]; if (s < 0) s += n; if (s > (n - 1) / 2) c[n - s]++; else c[s]++; } } rep2(i, 1, (n + 1) / 2) { cout << c[i] << endl; } } return 0; }
[["-", 0, 52, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 52, 8, 9, 0, 14, 49, 53, 49, 22], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 21], ["-", 0, 1, 0, 2, 3, 4, 0, 25, 0, 35]]
1
232
5