buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
#include <iostream> using namespace std; int main() { int n, s[1000], i; while (cin >> n && n > 0) { int sum = 0, maximum = 0, minimum = 10000; for (i = 0; i > n; i++) { cin >> s[i]; sum += s[i]; } for (i = 0; i > n; i++) { maximum = max(maximum, s[i]); minimum = min(minimum, s[i]); } cout << (sum - maximum - minimum) / (n - 2) << endl; } }
#include <iostream> using namespace std; int main() { int n, s[1000], i; while (cin >> n && n > 0) { int sum = 0, maximum = 0, minimum = 10000; for (i = 0; i < n; i++) { cin >> s[i]; sum += s[i]; } for (i = 0; i < n; i++) { maximum = max(maximum, s[i]); minimum = min(minimum, s[i]); } cout << (sum - maximum - minimum) / (n - 2) << endl; } }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 47], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18]]
1
133
#include <stdio.h> int INF = 1e9; int main() { int n; int s[100]; while (1) { scanf("%d", &n); if (n == 0) break; int sum = 0; int avg = 0; int min = INF; int max = 0; for (int i = 0; i < n; i++) { scanf("%d", &s[i]); sum += s[i]; if (max < s[i]) { max = s[i]; } else if (min > s[i]) { min = s[i]; } } sum = sum - min - max; avg = sum / (n - 2); printf("%d\n", avg); } }
#include <stdio.h> int INF = 1e9; int main() { int n; int s[100]; while (1) { scanf("%d", &n); if (n == 0) break; int sum = 0; int avg = 0; int min = INF; int max = 0; for (int i = 0; i < n; i++) { scanf("%d", &s[i]); sum += s[i]; if (max < s[i]) { max = s[i]; } if (min > s[i]) { min = s[i]; } } sum = sum - min - max; avg = sum / (n - 2); printf("%d\n", avg); } }
[["-", 0, 7, 8, 9, 0, 57, 75, 76, 0, 95]]
1
167
#include <stdio.h> int main() { int n, s; int maxm, mini, sum; while (1) { scanf("%d", &n); if (n == 0) break; sum = 0; maxm = 1000; mini = 0; for (int i = 0; i < n; i++) { scanf("%d", &s); sum = sum + s; if (maxm < s) { maxm = s; } if (mini > s) { mini = s; } } printf("%d\n", (sum - maxm - mini) / (n - 2)); } return 0; }
#include <stdio.h> int main() { int n, s; int maxm, mini, sum; while (1) { scanf("%d", &n); if (n == 0) break; sum = 0; maxm = 0; mini = 1000; for (int i = 0; i < n; i++) { scanf("%d", &s); sum = sum + s; if (maxm < s) { maxm = s; } if (mini > s) { mini = s; } } printf("%d\n", (sum - maxm - mini) / (n - 2)); } return 0; }
[["-", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13]]
1
137
#include <iostream> #include <math.h> using namespace std; int main() { while (1) { int n; int sum = 0; cin >> n; if (n == 0) { return 0; } int s; int max = -1; int min = 9999; for (int i = 0; i < n; i++) { cin >> s; sum += s; if (s > max) { max = s; } else if (s < min) { min = s; } } int ans = floor((sum - max - min) / (n - 2)); cout << ans << endl; } return 0; }
#include <iostream> #include <math.h> using namespace std; int main() { while (1) { int n; int sum = 0; cin >> n; if (n == 0) { return 0; } int s; int max = -1; int min = 9999; for (int i = 0; i < n; i++) { cin >> s; sum += s; if (s >= max) { max = s; } if (s <= min) { min = s; } } int ans = floor((sum - max - min) / (n - 2)); cout << ans << endl; } return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["-", 0, 7, 8, 9, 0, 57, 75, 76, 0, 95], ["-", 75, 76, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19]]
1
134
#include <algorithm> #include <iostream> using namespace std; int main() { int num; while (true) { int ans = 0; cin >> num; if (num != 0) { int a[num]; for (int i = 0; i < num; i++) { cin >> a[i]; } sort(a, a + num); for (int i = 1; i < num - 1; i++) { ans += a[i]; } cout << ans << endl; } else { return 0; } } }
#include <algorithm> #include <iostream> using namespace std; int main() { int num; while (true) { int ans = 0; cin >> num; if (num != 0) { int a[num]; for (int i = 0; i < num; i++) { cin >> a[i]; } sort(a, a + num); for (int i = 1; i < num - 1; i++) { ans += a[i]; } cout << ans / (num - 2) << endl; } else { return 0; } } }
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 85], ["+", 0, 16, 31, 16, 12, 16, 12, 23, 0, 24], ["+", 31, 16, 12, 16, 12, 23, 0, 16, 31, 22], ["+", 31, 16, 12, 16, 12, 23, 0, 16, 17, 33], ["+", 31, 16, 12, 16, 12, 23, 0, 16, 12, 13], ["+", 0, 16, 31, 16, 12, 16, 12, 23, 0, 25]]
1
115
#include <iostream> using namespace std; int main() { while (true) { int n; cin >> n; if (n == 0) return 0; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int max = 0; int min = 1000; int sum = 0; for (int i = 0; i <= n; i++) { if (a[i] > max) max = a[i]; if (a[i] < min) min = a[i]; sum += a[i]; } cout << (sum - max - min) / (n - 2); } }
#include <iostream> using namespace std; int main() { while (true) { int n; cin >> n; if (n == 0) return 0; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int max = 0; int min = 1000; int sum = 0; for (int i = 0; i < n; i++) { if (a[i] > max) max = a[i]; if (a[i] < min) min = a[i]; sum += a[i]; } cout << (sum - max - min) / (n - 2) << endl; } }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 52, 8, 9, 0, 1, 0, 16, 12, 22]]
1
147
#include <algorithm> #include <climits> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <numeric> #include <vector> using namespace std; int main() { int n, s[101]; while (cin >> n && n > 0) { int mean = 0; for (int i = 0; i < n; i++) cin >> s[i]; sort(s, s + n); for (int t = 1; t < n - 1; t++) mean += s[t]; cout << mean << endl; } return 0; }
#include <algorithm> #include <climits> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <numeric> #include <vector> using namespace std; int main() { int n, s[101]; while (cin >> n && n > 0) { int mean = 0; for (int i = 0; i < n; i++) cin >> s[i]; sort(s, s + n); for (int t = 1; t < n - 1; t++) mean += s[t]; cout << mean / (n - 2) << endl; } return 0; }
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 85], ["+", 0, 16, 31, 16, 12, 16, 12, 23, 0, 24], ["+", 31, 16, 12, 16, 12, 23, 0, 16, 31, 22], ["+", 31, 16, 12, 16, 12, 23, 0, 16, 17, 33], ["+", 31, 16, 12, 16, 12, 23, 0, 16, 12, 13], ["+", 0, 16, 31, 16, 12, 16, 12, 23, 0, 25]]
1
115
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <vector> using namespace std; #define ll long long int #define ld long long double #define reps(i, f, n) for (int i = f; i < n; i++) #define rep(i, n) reps(i, 0, n) #define m1 cout << "move1" << endl #define m2 cout << "move2" << endl #define m3 cout << "move3" << endl #define m4 cout << "move4" << endl int main() { ll sum = 0; int N = 0; int max_v = -1; int min_v = 10000; int a; int b; // m2; while (cin >> a) { N = a; // cout<<a<<endl; // m1; for (int i = 0; i < N; i++) { cin >> b; max_v = max(max_v, b); min_v = min(min_v, b); sum += b; // cout<<sum<<endl; } sum = sum - max_v - min_v; cout << sum / (N - 2) << endl; max_v = -1; min_v = 1000; sum = 0; } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <vector> using namespace std; #define ll long long int #define ld long long double #define reps(i, f, n) for (int i = f; i < n; i++) #define rep(i, n) reps(i, 0, n) #define m1 cout << "move1" << endl #define m2 cout << "move2" << endl #define m3 cout << "move3" << endl #define m4 cout << "move4" << endl int main() { ll sum = 0; int N = 0; int max_v = -1; int min_v = 10000; int a; int b; // m2; while (cin >> a, a != 0) { N = a; // cout<<a<<endl; // m1; for (int i = 0; i < N; i++) { cin >> b; max_v = max(max_v, b); min_v = min(min_v, b); sum += b; // cout<<sum<<endl; } sum = sum - max_v - min_v; cout << sum / (N - 2) << endl; max_v = -1; min_v = 1000; sum = 0; } return 0; }
[["+", 8, 9, 0, 52, 15, 339, 51, 34, 0, 21], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 31, 22], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 17, 79], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 12, 13]]
1
175
#include <iostream> using namespace std; int s; int n, maxn, minn, sum; int main() { while (1) { cin >> n; if (n == 0) break; minn = 1001; maxn = 0; for (int i = 0; i < n; i++) { cin >> s; sum += s; if (maxn < s) maxn = s; if (minn > s) minn = s; } sum = sum - minn - maxn; cout << sum / (n - 2) << endl; } return 0; }
#include <iostream> using namespace std; int s; int n, maxn, minn, sum; int main() { while (1) { cin >> n; if (n == 0) break; minn = 1001; maxn = 0; sum = 0; for (int i = 0; i < n; i++) { cin >> s; sum += s; if (maxn < s) maxn = s; if (minn > s) minn = s; } sum = sum - minn - maxn; cout << sum / (n - 2) << endl; } return 0; }
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
117
#include <algorithm> #include <cmath> #include <iostream> using namespace std; bool b[33000]; int main() { int n; while (cin >> n && n) { int a = 10000000, b = -100, x; long long sum = 0; for (int i = 0; i < n; i++) { cin >> x; sum += x; a = min(a, x); b = max(b, x); } sum -= a; sum -= b; double c = floor((double)sum / (double)n - 2); cout << c << endl; } }
#include <algorithm> #include <cmath> #include <iostream> using namespace std; bool b[33000]; int main() { int n; while (cin >> n && n) { int a = 10000000, b = -100, x; long long sum = 0; for (int i = 0; i < n; i++) { cin >> x; sum += x; a = min(a, x); b = max(b, x); } sum -= a; sum -= b; double c = floor((double)sum / (double)(n - 2)); cout << c << endl; } }
[["+", 3, 4, 0, 16, 12, 74, 51, 23, 0, 24], ["+", 3, 4, 0, 16, 12, 74, 51, 23, 0, 25]]
1
126
#include <iostream> #include <queue> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <vector> using namespace std; int main() { int n; while (1) { scanf("%d", &n); if (n == 0) break; int sum = 0, max = 0, min = 1000, point; for (int i = 1; i <= n; i++) { scanf("%d", &point); if (point > max) max = point; else if (point < min) min = point; sum += point; } printf("%d\n", (sum - max - min) / (n - 2)); } return 0; }
#include <iostream> #include <queue> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <vector> using namespace std; int main() { int n; while (1) { scanf("%d", &n); if (n == 0) break; int sum = 0, max = 0, min = 1000, point; for (int i = 1; i <= n; i++) { scanf("%d", &point); if (point > max) max = point; if (point < min) min = point; sum += point; } printf("%d\n", (sum - max - min) / (n - 2)); } return 0; }
[["-", 0, 7, 8, 9, 0, 57, 75, 76, 0, 95]]
1
142
#include <iostream> using namespace std; int main(void) { while (1) { int n; cin >> n; if (n == 0) { return 0; } int point[n]; for (int i = 0; i < n; i++) { cin >> point[i]; } int sum = 0; int max = -1; int min = 1001; for (int i = 0; i < n; i++) { if (max < point[i]) { max = point[i]; } if (min > point[i]) { min = point[i]; } sum += point[i]; } cout << (int)(sum - max - min) / (n - 2); } }
#include <iostream> using namespace std; int main(void) { while (1) { int n; cin >> n; if (n == 0) { return 0; } int point[n]; for (int i = 0; i < n; i++) { cin >> point[i]; } int sum = 0; int max = -1; int min = 1001; for (int i = 0; i < n; i++) { if (max < point[i]) { max = point[i]; } if (min > point[i]) { min = point[i]; } sum += point[i]; } cout << (int)(sum - max - min) / (n - 2) << endl; } }
[["+", 0, 52, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 52, 8, 9, 0, 1, 0, 16, 12, 22]]
1
159
#include <iostream> #define INF (2 << 29) using namespace std; int main() { cin.tie(0); ios_base::sync_with_stdio(false); for (;;) { int a, n, s = 0, max = 0, min = INF; cin >> n; if (n == 0) break; for (int i = 0; i < n; i++) { cin >> a; s += a; if (max < a) max = a; if (min > a) min = a; } cout << (s - max - min) / n << endl; } return 0; }
#include <iostream> #define INF (2 << 29) using namespace std; int main() { cin.tie(0); ios_base::sync_with_stdio(false); for (;;) { int a, n, s = 0, max = 0, min = INF; cin >> n; if (n == 0) break; for (int i = 0; i < n; i++) { cin >> a; s += a; if (max < a) max = a; if (min > a) min = a; } cout << (s - max - min) / (n - 2) << endl; } return 0; }
[["+", 0, 16, 31, 16, 12, 16, 12, 23, 0, 24], ["+", 31, 16, 12, 16, 12, 23, 0, 16, 17, 33], ["+", 31, 16, 12, 16, 12, 23, 0, 16, 12, 13], ["+", 0, 16, 31, 16, 12, 16, 12, 23, 0, 25]]
1
126
#include <climits> #include <iostream> using namespace std; int main(void) { int n, m, max, min, answer; while (1) { cin >> n; max = 0; min = INT_MAX; answer = 0; if (!n) break; for (int i = 0; i < n; i++) { cin >> m; if (m > max) max = m; else if (m < min) min = m; answer += m; } cout << (answer - max - min) / (n - 2) << endl; } return 0; }
#include <climits> #include <iostream> using namespace std; int main(void) { int n, m, max, min, answer; while (1) { cin >> n; max = 0; min = INT_MAX; answer = 0; if (!n) break; for (int i = 0; i < n; i++) { cin >> m; if (m > max) max = m; if (m < min) min = m; answer += m; } cout << (answer - max - min) / (n - 2) << endl; } return 0; }
[["-", 0, 7, 8, 9, 0, 57, 75, 76, 0, 95]]
1
121
#include <iostream> using namespace std; int main() { int a[101]; int b[20]; int n = 0; int i = 0; int max = 0; int min = 1000; int sum = 0; int counter = 0; while (1) { max = 0; min = 1000; sum = 0; cin >> n; if (n == 0) break; for (i = 0; i < n; i++) { cin >> a[i]; if (max <= a[i]) max = a[i]; if (min >= a[i]) min = a[i]; sum += a[i]; } b[counter] = (sum - max - min) / (n - 2); counter++; } for (i = 0; i < counter; i++) { cout << b[i]; } return 0; }
#include <iostream> using namespace std; int main() { int a[101]; int b[20]; int n = 0; int i = 0; int max = 0; int min = 1000; int sum = 0; int counter = 0; while (1) { max = 0; min = 1000; sum = 0; cin >> n; if (n == 0) break; for (i = 0; i < n; i++) { cin >> a[i]; if (max <= a[i]) max = a[i]; if (min >= a[i]) min = a[i]; sum += a[i]; } b[counter] = (sum - max - min) / (n - 2); counter++; } for (i = 0; i < counter; i++) { cout << b[i] << endl; } return 0; }
[["+", 0, 7, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 7, 8, 9, 0, 1, 0, 16, 12, 22]]
1
192
#include <iostream> using namespace std; int larger(int x, int y) { int z = 0; if (x > y) z = x; else z = y; return z; } int smaller(int x, int y) { int z = 0; if (x < y) z = x; else z = y; return z; } int main(void) { int s = 1; while (s == 1) { int sinsa, a[100], sum = 0, ave; cin >> sinsa; if (sinsa == 0) s = 2; for (int i = 0; i < sinsa; i++) { cin >> a[i]; } int n = a[0]; for (int i = 0; i < sinsa; i++) { n = larger(n, a[i]); } int m = a[0]; for (int i = 0; i < sinsa; i++) { m = smaller(m, a[i]); } for (int i = 0; i < sinsa; i++) { sum += a[i]; } sum = sum - n - m; ave = sum / (sinsa - 2); cout << ave << endl; } return 0; }
#include <iostream> using namespace std; int larger(int x, int y) { int z = 0; if (x > y) z = x; else z = y; return z; } int smaller(int x, int y) { int z = 0; if (x < y) z = x; else z = y; return z; } int main(void) { int s = 1; while (s == 1) { int sinsa, a[100], sum = 0, ave; cin >> sinsa; if (sinsa == 0) return 0; for (int i = 0; i < sinsa; i++) { cin >> a[i]; } int n = a[0]; for (int i = 0; i < sinsa; i++) { n = larger(n, a[i]); } int m = a[0]; for (int i = 0; i < sinsa; i++) { m = smaller(m, a[i]); } for (int i = 0; i < sinsa; i++) { sum += a[i]; } sum = sum - n - m; ave = sum / (sinsa - 2); cout << ave << endl; } return 0; }
[["-", 8, 9, 0, 57, 64, 1, 0, 11, 31, 22], ["-", 8, 9, 0, 57, 64, 1, 0, 11, 17, 32], ["-", 8, 9, 0, 57, 64, 1, 0, 11, 12, 13], ["+", 0, 52, 8, 9, 0, 57, 64, 37, 0, 38], ["+", 0, 52, 8, 9, 0, 57, 64, 37, 0, 13]]
1
267
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; int main() { while (true) { int n, A[100] = {0}; cin >> n; if (n == 0) break; rep(i, n) cin >> A[i]; sort(A, A + n); int sum = 0; rep(i, n - 2) sum += A[i + 1]; cout << sum / n << endl; } return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; int main() { while (true) { int n, A[100] = {0}; cin >> n; if (n == 0) break; rep(i, n) cin >> A[i]; sort(A, A + n); int sum = 0; rep(i, n - 2) sum += A[i + 1]; cout << sum / (n - 2) << endl; } return 0; }
[["+", 0, 16, 31, 16, 12, 16, 12, 23, 0, 24], ["+", 31, 16, 12, 16, 12, 23, 0, 16, 17, 33], ["+", 31, 16, 12, 16, 12, 23, 0, 16, 12, 13], ["+", 0, 16, 31, 16, 12, 16, 12, 23, 0, 25]]
1
106
#include <stdio.h> int max(int a, int b) { if (a > b) return a; return b; } int min(int a, int b) { if (a > b) return b; return a; } int main() { int n, top, bot, tot, temp; while (1) { scanf("%d", &n); if (n == 0) return 0; scanf("%d", &top); tot = bot = top; for (int i = 1; i < n; i++) { scanf("%d", &temp); tot += temp; top = max(top, temp); bot = min(bot, temp); } printf("%d\n", (tot - top - bot) / n); } }
#include <stdio.h> int max(int a, int b) { if (a > b) return a; return b; } int min(int a, int b) { if (a > b) return b; return a; } int main() { int n, top, bot, tot, temp; while (1) { scanf("%d", &n); if (n == 0) return 0; scanf("%d", &top); tot = bot = top; for (int i = 1; i < n; i++) { scanf("%d", &temp); tot += temp; top = max(top, temp); bot = min(bot, temp); } printf("%d\n", (tot - top - bot) / (n - 2)); } }
[["+", 0, 2, 3, 4, 0, 16, 12, 23, 0, 24], ["+", 3, 4, 0, 16, 12, 23, 0, 16, 17, 33], ["+", 3, 4, 0, 16, 12, 23, 0, 16, 12, 13], ["+", 0, 2, 3, 4, 0, 16, 12, 23, 0, 25]]
1
172
#include <bits/stdc++.h> using namespace std; int main() { while (1) { int n, av, max, min, sum = 0, s; cin >> n; if (n == 0) break; cin >> s; sum = s; max = s; min = s; for (int i = 1; i < n; i++) { cin >> s; sum += s; if (s > max) max = s; if (s < min) min = s; } av = (sum - max - min) / n - 2; cout << av << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { while (1) { int n, av, max, min, sum = 0, s; cin >> n; if (n == 0) break; cin >> s; sum = s; max = s; min = s; for (int i = 1; i < n; i++) { cin >> s; sum += s; if (s > max) max = s; if (s < min) min = s; } av = (sum - max - min) / (n - 2); cout << av << endl; } return 0; }
[["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25]]
1
128
#include <algorithm> #include <iostream> #define FOR(i, l, n) for (int i = (l); i < (n); i++) #define REP(i, n) FOR(i, 0, n) #define MAX_JUDGE 100 using namespace std; int main() { int n, score[MAX_JUDGE]; while (cin >> n, n) { REP(i, n) cin >> score[i]; sort(score, score + n); int sum = 0; FOR(i, 1, n - 1) sum += score[i]; cout << sum / (n - 2); } return 0; }
#include <algorithm> #include <iostream> #define FOR(i, l, n) for (int i = (l); i < (n); i++) #define REP(i, n) FOR(i, 0, n) #define MAX_JUDGE 100 using namespace std; int main() { int n, score[MAX_JUDGE]; while (cin >> n, n) { REP(i, n) cin >> score[i]; sort(score, score + n); int sum = 0; FOR(i, 1, n - 1) sum += score[i]; cout << sum / (n - 2) << endl; } return 0; }
[["+", 0, 52, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 52, 8, 9, 0, 1, 0, 16, 12, 22]]
1
110
#include <algorithm> #include <iostream> #include <numeric> #define FOR(i, l, n) for (int i = (l); i < (n); i++) #define REP(i, n) FOR(i, 0, n) #define MAX_JUDGE 100 using namespace std; int main() { int n, score[MAX_JUDGE]; while (cin >> n, n) { REP(i, n) cin >> score[i]; sort(score, score + n); int sum = accumulate(score + 1, score + n - 2, 0); cout << sum / (n - 2) << endl; } return 0; }
#include <algorithm> #include <iostream> #include <numeric> #define FOR(i, l, n) for (int i = (l); i < (n); i++) #define REP(i, n) FOR(i, 0, n) #define MAX_JUDGE 100 using namespace std; int main() { int n, score[MAX_JUDGE]; while (cin >> n, n) { REP(i, n) cin >> score[i]; sort(score, score + n); int sum = accumulate(score + 1, score + n - 1, 0); cout << sum / (n - 2) << endl; } return 0; }
[["-", 49, 50, 51, 2, 3, 4, 0, 16, 12, 13], ["+", 49, 50, 51, 2, 3, 4, 0, 16, 12, 13]]
1
110
#include <bits/stdc++.h> #define FOR(i, a, b) for (long long int i = (a); i <= (b); i++) #define RFOR(i, a, b) for (long long int i = (a); i >= (b); i--) #define MOD 1000000007 #define INF 1000000000 // 2000000000 #define LLINF 1000000000000000000 // 9000000000000000000 #define PI 3.14159265358979 using namespace std; typedef long long int ll; typedef pair<long long int, long long int> P; int main(void) { int result[100] = {}; int pos = 0; while (1) { int n; int s[101] = {}; int mini = 1001; int maxi = -1; int total = 0; cin >> n; if (n == 0) { break; } pos++; FOR(i, 1, n) { cin >> s[i]; if (maxi < s[i]) { maxi = s[i]; } else if (mini > s[i]) { mini = s[i]; } total += s[i]; } result[pos] = (total - maxi - mini) / (n - 2); } FOR(i, 1, pos) { cout << result[i] << endl; } }
#include <bits/stdc++.h> #define FOR(i, a, b) for (long long int i = (a); i <= (b); i++) #define RFOR(i, a, b) for (long long int i = (a); i >= (b); i--) #define MOD 1000000007 #define INF 1000000000 // 2000000000 #define LLINF 1000000000000000000 // 9000000000000000000 #define PI 3.14159265358979 using namespace std; typedef long long int ll; typedef pair<long long int, long long int> P; int main(void) { int result[100] = {}; int pos = 0; while (1) { int n; int s[101] = {}; int mini = 1001; int maxi = -1; int total = 0; cin >> n; if (n == 0) { break; } pos++; FOR(i, 1, n) { cin >> s[i]; if (maxi < s[i]) { maxi = s[i]; } if (mini > s[i]) { mini = s[i]; } total += s[i]; } result[pos] = (total - maxi - mini) / (n - 2); } FOR(i, 1, pos) { cout << result[i] << endl; } }
[["-", 8, 9, 0, 9, 0, 57, 75, 76, 0, 95]]
1
229
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl; #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--) #define CHMIN(a, b) (a) = min((a), (b)) #define CHMAX(a, b) (a) = max((a), (b)) int main() { int in; int num; int ans = 0; int point[105] = {}; while (1 == 1) { scanf("%d\n", &in); if (in == 0) return 0; num = in; ans = 0; REP(i, num) { scanf("%d\n", &point[i]); ans += point[i]; } sort(&point[0], &point[num]); ans -= (point[0] + point[num - 1]); printf("%d\n", ans / num - 2); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl; #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--) #define CHMIN(a, b) (a) = min((a), (b)) #define CHMAX(a, b) (a) = max((a), (b)) int main() { int in; int num; int ans = 0; int point[105] = {}; while (1 == 1) { scanf("%d\n", &in); if (in == 0) return 0; num = in; ans = 0; REP(i, num) { scanf("%d\n", &point[i]); ans += point[i]; } sort(&point[0], &point[num]); ans -= (point[0] + point[num - 1]); printf("%d\n", ans / (num - 2)); } return 0; }
[["+", 0, 2, 3, 4, 0, 16, 12, 23, 0, 24], ["+", 0, 2, 3, 4, 0, 16, 12, 23, 0, 25]]
1
200
#include <bits/stdc++.h> using namespace std; int main() { vector<int> sss(20); for (int l = 0; l < 2000; l++) { int A; cin >> A; if (A == 0) { break; } int cnt = 0; vector<int> vec(A); for (int i = 0; i < A; i++) { cin >> vec[i]; cnt += vec[i]; } sort(vec.begin(), vec.end()); cout << (cnt - (vec[0] + vec[A - 1]) / (A - 2)); } }
#include <bits/stdc++.h> using namespace std; int main() { vector<int> sss(20); for (int l = 0; l < 20; l++) { int A; cin >> A; if (A == 0) { break; } int cnt = 0; vector<int> vec(A); for (int i = 0; i < A; i++) { cin >> vec[i]; cnt += vec[i]; } sort(vec.begin(), vec.end()); cout << ((cnt - (vec[0] + vec[A - 1])) / (A - 2)) << endl; } }
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 1, 0, 16, 31, 16, 12, 23, 0, 24], ["+", 0, 16, 31, 23, 0, 16, 12, 23, 0, 25], ["+", 0, 7, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 7, 8, 9, 0, 1, 0, 16, 12, 22]]
1
139
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using P = pair<ll, ll>; #define MOD 1000000007ll #define INF 1000000000ll #define EPS 1e-10 #define FOR(i, n, m) for (ll i = n; i < (ll)m; i++) #define REP(i, n) FOR(i, 0, n) #define DUMP(a) \ REP(d, a.size()) { \ cout << a[d]; \ if (d != a.size() - 1) \ cout << " "; \ else \ cout << endl; \ } #define ALL(v) v.begin(), v.end() #define UNIQUE(v) \ sort(v.begin(), v.end()); \ v.erase(unique(v.begin(), v.end()), v.end()); #define pb push_back int main() { cin.tie(0); ios::sync_with_stdio(false); while (1) { ll n; cin >> n; if (n == 0) break; vector<ll> s(n); REP(i, n) cin >> s[i]; sort(ALL(s)); ll sum = accumulate(ALL(s), 0); sum -= s[0] + s[n - 1]; cout << sum << endl; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using P = pair<ll, ll>; #define MOD 1000000007ll #define INF 1000000000ll #define EPS 1e-10 #define FOR(i, n, m) for (ll i = n; i < (ll)m; i++) #define REP(i, n) FOR(i, 0, n) #define DUMP(a) \ REP(d, a.size()) { \ cout << a[d]; \ if (d != a.size() - 1) \ cout << " "; \ else \ cout << endl; \ } #define ALL(v) v.begin(), v.end() #define UNIQUE(v) \ sort(v.begin(), v.end()); \ v.erase(unique(v.begin(), v.end()), v.end()); #define pb push_back int main() { cin.tie(0); ios::sync_with_stdio(false); while (1) { ll n; cin >> n; if (n == 0) break; vector<ll> s(n); REP(i, n) cin >> s[i]; sort(ALL(s)); ll sum = accumulate(ALL(s), 0); sum -= s[0] + s[n - 1]; cout << sum / (n - 2) << endl; } }
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 85], ["+", 0, 16, 31, 16, 12, 16, 12, 23, 0, 24], ["+", 31, 16, 12, 16, 12, 23, 0, 16, 31, 22], ["+", 31, 16, 12, 16, 12, 23, 0, 16, 17, 33], ["+", 31, 16, 12, 16, 12, 23, 0, 16, 12, 13], ["+", 0, 16, 31, 16, 12, 16, 12, 23, 0, 25]]
1
183
#include <iostream> using namespace std; int main() { int n; int j[110]; int max, min; for (; cin >> n, n != 0;) { for (int i = 0; i < n; i++) { cin >> j[i]; } max = min = 0; int sum = 0; for (int i = 0; i < n; i++) { if (max < j[i]) max = j[i]; if (min > j[i]) min = j[i]; sum += j[i]; } sum -= max + min; cout << sum / (n - 2) << endl; } return 0; }
#include <iostream> using namespace std; int main() { int n; int j[110]; int max, min; for (; cin >> n, n != 0;) { for (int i = 0; i < n; i++) { cin >> j[i]; } max = 0; min = 2000; int sum = 0; for (int i = 0; i < n; i++) { if (max < j[i]) max = j[i]; if (min > j[i]) min = j[i]; sum += j[i]; } sum -= max + min; cout << sum / (n - 2) << endl; } return 0; }
[["+", 0, 7, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 7, 8, 9, 0, 1, 0, 35], ["-", 8, 9, 0, 1, 0, 11, 12, 11, 12, 13]]
1
150
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int n; while (cin >> n) { if (n == 0) return 0; vector<int> V; for (int i = 0; i < n; i++) { int t; cin >> t; V.push_back(t); } sort(V.begin(), V.end()); int ans = 0; for (int i = 1; i < V.size() - 1; i++) ans += V[i]; cout << ans / n << endl; } }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int n; while (cin >> n) { if (n == 0) return 0; vector<int> V; for (int i = 0; i < n; i++) { int t; cin >> t; V.push_back(t); } sort(V.begin(), V.end()); int ans = 0; for (int i = 1; i < V.size() - 1; i++) ans += V[i]; cout << ans / (n - 2) << endl; } }
[["+", 0, 16, 31, 16, 12, 16, 12, 23, 0, 24], ["+", 31, 16, 12, 16, 12, 23, 0, 16, 17, 33], ["+", 31, 16, 12, 16, 12, 23, 0, 16, 12, 13], ["+", 0, 16, 31, 16, 12, 16, 12, 23, 0, 25]]
1
127
#include <cstdlib> #include <iostream> using namespace std; int main() { int n, s, sum, maxs, mins, i; while ((cin >> n), n) { sum = maxs = 0; mins = 1000; for (i = 0; i < n; i++) { cin >> s; sum += s; maxs = max(maxs, s); mins = min(mins, s); } sum = (sum - maxs - mins) / n; cout << sum << endl; } }
#include <cstdlib> #include <iostream> using namespace std; int main() { int n, s, sum, maxs, mins, i; while ((cin >> n), n) { sum = maxs = 0; mins = 1000; for (i = 0; i < n; i++) { cin >> s; sum += s; maxs = max(maxs, s); mins = min(mins, s); } sum = (sum - maxs - mins) / (n - 2); cout << sum << endl; } }
[["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 12, 13], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25]]
1
108
#include <stdio.h> int main() { int n; while (scanf("%d", &n), n) { int max = 0, min = 1000, s; long sum = 0; for (int i = 0; i < n; i++) { scanf("%d", &s); sum += s; max = max < s ? s : max; min = s < min ? s : min; } printf("%ld", (sum - min - max) / (n - 2)); } }
#include <stdio.h> int main() { int n; while (scanf("%d", &n), n) { int max = 0, min = 1000, s; long sum = 0; for (int i = 0; i < n; i++) { scanf("%d", &s); sum += s; max = max < s ? s : max; min = s < min ? s : min; } printf("%ld\n", (sum - min - max) / (n - 2)); } }
[["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
1
114
#include <iostream> using namespace std; int main() { int n, sum, max, min; while (cin >> n && n > 0) { int S; min = 1000000000; max = 0; sum = 0; for (int i = 0; i < n; i++) { cin >> S; sum += S; if (min > S) { min = S; } if (max < S) { max = S; } } sum -= (min + max); cout << sum / n << endl; } return 0; }
#include <iostream> using namespace std; int main() { int n, sum, max, min; while (cin >> n && n > 0) { int S; min = 1000000000; max = 0; sum = 0; for (int i = 0; i < n; i++) { cin >> S; sum += S; if (min > S) { min = S; } if (max < S) { max = S; } } sum -= (min + max); cout << sum / (n - 2) << endl; } return 0; }
[["+", 0, 16, 31, 16, 12, 16, 12, 23, 0, 24], ["+", 31, 16, 12, 16, 12, 23, 0, 16, 17, 33], ["+", 31, 16, 12, 16, 12, 23, 0, 16, 12, 13], ["+", 0, 16, 31, 16, 12, 16, 12, 23, 0, 25]]
1
115
#include <iostream> using namespace std; int main() { int n, m, i; int ave[1000] = {0}; m = 0; while (1) { int point[100] = {0}; int min = 1000; int max = 0; cin >> n; if (n == 0) break; for (i = 0; i < n; i++) { cin >> point[i]; if (point[i] > max) max = point[i]; if (point[i] < min) min = point[i]; ave[m]++; } ave[m] = (ave[m] - max - min) / (n - 2); m++; } for (i = 0; i < m; i++) { cout << ave[i] << endl; } }
#include <iostream> using namespace std; int main() { int n, m, i; int ave[1000] = {0}; m = 0; while (1) { int point[100] = {0}; int min = 1000; int max = 0; cin >> n; if (n == 0) break; for (i = 0; i < n; i++) { cin >> point[i]; if (point[i] > max) max = point[i]; if (point[i] < min) min = point[i]; ave[m] += point[i]; } // cout<<"debug "<<ave[m]<<endl; // cout<<max<<" "<<min<<endl; ave[m] = (ave[m] - max - min) / (n - 2); m++; } for (i = 0; i < m; i++) { cout << ave[i] << endl; } }
[["-", 0, 7, 8, 9, 0, 1, 0, 27, 17, 29], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 17, 107], ["+", 8, 9, 0, 1, 0, 11, 12, 69, 28, 22], ["+", 0, 1, 0, 11, 12, 69, 341, 342, 0, 70], ["+", 0, 1, 0, 11, 12, 69, 341, 342, 0, 22], ["+", 0, 1, 0, 11, 12, 69, 341, 342, 0, 73]]
1
180
#include <iostream> using namespace std; int main() { int n, s, sum, max, min; while (1) { cin >> n; if (n == 0) break; sum = 0; cin >> s; sum += s; max = s; cin >> s; sum += s; if (max < s) { max = s; } else { min = s; } for (int i = 2; i < n; i++) { cin >> s; sum += s; if (max < s) { max = s; } else if (min > s) { min = s; } } sum -= max; sum -= min; int ave = sum / (n - 2); cout << ave << endl; } return 0; }
#include <iostream> using namespace std; int main() { int n, s, sum, max, min; while (1) { cin >> n; if (n == 0) break; sum = 0; cin >> s; sum += s; max = s; min = s; cin >> s; sum += s; if (max < s) { max = s; } else { min = s; } for (int i = 2; i < n; i++) { cin >> s; sum += s; if (max < s) { max = s; } else if (min > s) { min = s; } } sum -= max; sum -= min; int ave = sum / (n - 2); cout << ave << endl; } return 0; }
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 22], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
161
#include <iostream> using namespace std; int main() { int n, i, p, max, min, s; while (1) { cin >> n; if (n) { } else break; cin >> p; s = p; max = p; min = p; for (i = 0; i < n - 1; i++) { cin >> p; s += p; if (max < p) { max = p; } if (min > p) { min = p; } } s = (s - max - min) / (n - 2); cout << p << endl; } return 0; }
#include <iostream> using namespace std; int main() { int n, i, p, max, min, s; while (1) { cin >> n; if (n) { } else break; cin >> p; s = p; max = p; min = p; for (i = 0; i < n - 1; i++) { cin >> p; s += p; if (max < p) { max = p; } if (min > p) { min = p; } } s = (s - max - min) / (n - 2); cout << s << endl; } return 0; }
[["-", 8, 9, 0, 1, 0, 16, 31, 16, 12, 22], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 12, 22]]
1
134
#include <iostream> using namespace std; int N, S; int main() { while (cin >> N && N > 0) { int M, m, addup, i; M = -1; m = 1001; for (i = 0; i < N; i++) { cin >> S; addup += S; if (S > M) M = S; if (S < m) m = S; } cout << (addup - M - m) / (N - 2) << endl; } }
#include <iostream> using namespace std; int N, S; int main() { while (cin >> N && N > 0) { int M, m, addup, i; M = -1; m = 1001; addup = 0; for (i = 0; i < N; i++) { cin >> S; addup += S; if (S > M) M = S; if (S < m) m = S; } cout << (addup - M - m) / (N - 2) << endl; } }
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
107
#include <iostream> using namespace std; int main() { int n, i; cout << "test"; while (cin >> n, n) { int p; int min = 1000; int max = 0; int total = 0; for (int i = 0; i < n; i++) { cin >> p; if (p > max) max = p; if (p < min) min = p; total += p; } cout << (total - max - min) / (n - 2) << "\n"; } }
#include <iostream> using namespace std; int main() { int n, i; while (cin >> n, n) { int p; int min = 1000; int max = 0; int total = 0; for (int i = 0; i < n; i++) { cin >> p; if (p > max) max = p; if (p < min) min = p; total += p; } cout << (total - max - min) / (n - 2) << "\n"; } }
[["-", 0, 14, 8, 9, 0, 1, 0, 16, 31, 22], ["-", 0, 14, 8, 9, 0, 1, 0, 16, 17, 151], ["-", 8, 9, 0, 1, 0, 16, 12, 5, 0, 62], ["-", 8, 9, 0, 1, 0, 16, 12, 5, 0, 6], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35]]
1
115
#include <algorithm> #include <array> #include <bitset> #include <cmath> #include <cstdlib> #include <iostream> #include <list> #include <map> #include <queue> //priority_queue #include <set> #include <stack> #include <utility> #include <vector> #pragma warning(disable : 4996) /*-------マクロ定義---------*/ #define REP(i, n) for (L i = 0; i < n; i++) #define TIMES(n) REP(i, n) /*---------Typedef------------*/ // long typedef long L; typedef std::pair<L, L> IntPair; typedef std::vector<L> IntVector; typedef std::priority_queue<L> IntPriority; typedef std::queue<L> IntQueue; typedef std::stack<L> IntStack; // unsigned long typedef unsigned long ul; typedef std::pair<ul, ul> UIntPair; typedef std::vector<ul> UIntVector; typedef std::priority_queue<ul> UIntPriority; typedef std::queue<ul> UIntQueue; typedef std::stack<ul> UIntStack; // double typedef double D; typedef std::pair<D, D> DoublePair; typedef std::vector<D> DoubleVector; typedef std::priority_queue<D> DoublePriority; typedef std::queue<D> DoubleQueue; typedef std::stack<D> DoubleStack; // char typedef char Ch; typedef std::pair<Ch, Ch> CharPair; typedef std::vector<Ch> CharVector; typedef std::priority_queue<Ch> CharPriority; typedef std::queue<Ch> CharQueue; typedef std::stack<Ch> CharStack; // /* VectorArray Dp(1000,IntVector(1000)); */ typedef std::vector<std::vector<L>> VectorArray; typedef std::vector<std::vector<ul>> UVectorArray; typedef std::vector<std::vector<D>> DVectorArray; /*--------ScanOverLoad----------*/ // type long// void Scan(L &output) { scanf("%ld", &output); } void Scan(IntVector &vector) { L scan = 0; scanf("%ld", &scan); vector.push_back(scan); } void Scan(IntPriority &pri_que) { L scan = 0; scanf("%ld", &scan); pri_que.push(scan); } void Scan(IntQueue &que) { L scan = 0; scanf("%ld", &scan); que.push(scan); } void Scan(IntStack &stack) { L scan = 0; scanf("%ld", &scan); stack.push(scan); } // type unsigned long// void Scan(ul &output) { scanf("%lu", &output); } void Scan(UIntVector &vector) { ul scan = 0; scanf("%lu", &scan); vector.push_back(scan); } void Scan(UIntPriority &pri_que) { ul scan = 0; scanf("%lu", &scan); pri_que.push(scan); } void Scan(UIntQueue &que) { ul scan = 0; scanf("%lu", &scan); que.push(scan); } void Scan(UIntStack &stack) { ul scan = 0; scanf("%lu", &scan); stack.push(scan); } // type double// void Scan(D &output) { scanf("%lf", &output); } void Scan(DoubleVector &vector) { D scan = 0; scanf("lf", &scan); vector.push_back(scan); } void Scan(DoublePriority &pri_que) { D scan = 0; scanf("%lf", &scan); pri_que.push(scan); } void Scan(DoubleQueue &que) { D scan = 0; scanf("%lf", &scan); que.push(scan); } void Scan(DoubleStack &stack) { D scan = 0; scanf("%lf", &scan); stack.push(scan); } // type char// void Scan(Ch &output) { scanf("%c", &output); } void Scan(CharVector &vector) { Ch scan = 0; scanf("%c", &scan); vector.push_back(scan); } void Scan(CharPriority &pri_que) { Ch scan = 0; scanf("%c", &scan); pri_que.push(scan); } void Scan(CharQueue &que) { Ch scan = 0; scanf("%c", &scan); que.push(scan); } void Scan(CharStack &stack) { Ch scan = 0; scanf("%c", &scan); stack.push(scan); } /*----------Print----------*/ struct OPrint { void operator()(L &value) { printf("%ld", value); } void operator()(ul &value) { printf("%lu", value); } void operator()(D &value) { printf("%lf", value); } void operator()(Ch &value) { printf("%c", value); } }; template <class T> void Print(T &value) { std::for_each(value.begin(), value.end(), OPrint()); } void Print(L value) { printf("%ld", value); } void Print(ul value) { printf("%lu", value); } void Print(D value) { printf("%lf", value); } void Print(Ch value) { printf("%c", value); } /*----------Init---------*/ template <class T> struct OInit { T x; OInit(T _x) : x(_x) {} void operator()(L &value) { value = x; } void operator()(ul &value) { value = x; } void operator()(D &value) { value = x; } void operator()(Ch &value) { value = x; } }; template <class T1, class T2> void Init(T1 &value, T2 x) { std::for_each(value.begin(), value.end(), OInit<T2>(x)); } void Init(L &value, L x) { value = x; } void Init(ul &value, ul x) { value = x; } void Init(D &value, D x) { value = x; } void Init(Ch &value, Ch x) { value = x; } int main() { for (;;) { IntVector Point; L n; Scan(n); if (!n) return 0; TIMES(n) Scan(Point); std::sort(Point.begin(), Point.end()); L souwa = 0; std::for_each(Point.begin() + 1, Point.end() - 1, [&souwa](L x) { souwa += x; }); Print(souwa / (Point.size() - 2)); puts(""); puts(""); } return 0; }
#include <algorithm> #include <array> #include <bitset> #include <cmath> #include <cstdlib> #include <iostream> #include <list> #include <map> #include <queue> //priority_queue #include <set> #include <stack> #include <utility> #include <vector> #pragma warning(disable : 4996) /*-------マクロ定義---------*/ #define REP(i, n) for (L i = 0; i < n; i++) #define TIMES(n) REP(i, n) /*---------Typedef------------*/ // long typedef long L; typedef std::pair<L, L> IntPair; typedef std::vector<L> IntVector; typedef std::priority_queue<L> IntPriority; typedef std::queue<L> IntQueue; typedef std::stack<L> IntStack; // unsigned long typedef unsigned long ul; typedef std::pair<ul, ul> UIntPair; typedef std::vector<ul> UIntVector; typedef std::priority_queue<ul> UIntPriority; typedef std::queue<ul> UIntQueue; typedef std::stack<ul> UIntStack; // double typedef double D; typedef std::pair<D, D> DoublePair; typedef std::vector<D> DoubleVector; typedef std::priority_queue<D> DoublePriority; typedef std::queue<D> DoubleQueue; typedef std::stack<D> DoubleStack; // char typedef char Ch; typedef std::pair<Ch, Ch> CharPair; typedef std::vector<Ch> CharVector; typedef std::priority_queue<Ch> CharPriority; typedef std::queue<Ch> CharQueue; typedef std::stack<Ch> CharStack; // /* VectorArray Dp(1000,IntVector(1000)); */ typedef std::vector<std::vector<L>> VectorArray; typedef std::vector<std::vector<ul>> UVectorArray; typedef std::vector<std::vector<D>> DVectorArray; /*--------ScanOverLoad----------*/ // type long// void Scan(L &output) { scanf("%ld", &output); } void Scan(IntVector &vector) { L scan = 0; scanf("%ld", &scan); vector.push_back(scan); } void Scan(IntPriority &pri_que) { L scan = 0; scanf("%ld", &scan); pri_que.push(scan); } void Scan(IntQueue &que) { L scan = 0; scanf("%ld", &scan); que.push(scan); } void Scan(IntStack &stack) { L scan = 0; scanf("%ld", &scan); stack.push(scan); } // type unsigned long// void Scan(ul &output) { scanf("%lu", &output); } void Scan(UIntVector &vector) { ul scan = 0; scanf("%lu", &scan); vector.push_back(scan); } void Scan(UIntPriority &pri_que) { ul scan = 0; scanf("%lu", &scan); pri_que.push(scan); } void Scan(UIntQueue &que) { ul scan = 0; scanf("%lu", &scan); que.push(scan); } void Scan(UIntStack &stack) { ul scan = 0; scanf("%lu", &scan); stack.push(scan); } // type double// void Scan(D &output) { scanf("%lf", &output); } void Scan(DoubleVector &vector) { D scan = 0; scanf("lf", &scan); vector.push_back(scan); } void Scan(DoublePriority &pri_que) { D scan = 0; scanf("%lf", &scan); pri_que.push(scan); } void Scan(DoubleQueue &que) { D scan = 0; scanf("%lf", &scan); que.push(scan); } void Scan(DoubleStack &stack) { D scan = 0; scanf("%lf", &scan); stack.push(scan); } // type char// void Scan(Ch &output) { scanf("%c", &output); } void Scan(CharVector &vector) { Ch scan = 0; scanf("%c", &scan); vector.push_back(scan); } void Scan(CharPriority &pri_que) { Ch scan = 0; scanf("%c", &scan); pri_que.push(scan); } void Scan(CharQueue &que) { Ch scan = 0; scanf("%c", &scan); que.push(scan); } void Scan(CharStack &stack) { Ch scan = 0; scanf("%c", &scan); stack.push(scan); } /*----------Print----------*/ struct OPrint { void operator()(L &value) { printf("%ld", value); } void operator()(ul &value) { printf("%lu", value); } void operator()(D &value) { printf("%lf", value); } void operator()(Ch &value) { printf("%c", value); } }; template <class T> void Print(T &value) { std::for_each(value.begin(), value.end(), OPrint()); } void Print(L value) { printf("%ld", value); } void Print(ul value) { printf("%lu", value); } void Print(D value) { printf("%lf", value); } void Print(Ch value) { printf("%c", value); } /*----------Init---------*/ template <class T> struct OInit { T x; OInit(T _x) : x(_x) {} void operator()(L &value) { value = x; } void operator()(ul &value) { value = x; } void operator()(D &value) { value = x; } void operator()(Ch &value) { value = x; } }; template <class T1, class T2> void Init(T1 &value, T2 x) { std::for_each(value.begin(), value.end(), OInit<T2>(x)); } void Init(L &value, L x) { value = x; } void Init(ul &value, ul x) { value = x; } void Init(D &value, D x) { value = x; } void Init(Ch &value, Ch x) { value = x; } int main() { for (;;) { IntVector Point; L n; Scan(n); if (!n) return 0; TIMES(n) Scan(Point); std::sort(Point.begin(), Point.end()); L souwa = 0; std::for_each(Point.begin() + 1, Point.end() - 1, [&souwa](L x) { souwa += x; }); Print(souwa / (Point.size() - 2)); puts(""); } return 0; }
[["-", 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
1,381
while true do n = gets.to_i if n == 0 break end max = 0 min = 10000 sum = 0 n.times do i = gets.to_i if i > max max = i elsif i < min min = i end sum += i end p (sum - min - max) / (n-2) end
while true do n = gets.to_i if n == 0 break end max = 0 min = 1000 sum = 0 n.times do i = gets.to_i if i > max max = i end if i < min min = i end sum += i end p (sum - min - max) / (n-2) end
[["-", 0, 493, 0, 89, 8, 170, 0, 662, 12, 612], ["+", 0, 493, 0, 89, 8, 170, 0, 662, 12, 612], ["-", 196, 737, 8, 736, 0, 121, 75, 759, 0, 759], ["+", 0, 652, 196, 737, 8, 736, 0, 121, 0, 444], ["+", 0, 652, 196, 737, 8, 736, 0, 121, 0, 121]]
4
66
result = [] loop do input = gets.chomp!.to_i ary = [] break unless input != 0 input.times do ary << gets.chomp!.to_i end ary.sort_by!{|a, b| a<=>b} ary.delete_at(0) ary.delete_at(ary.length-1) sum = 0 ary.each do |i| sum += i end result << sum / ary.length end result.each do |r| p r end
result = [] loop do input = gets.chomp!.to_i ary = [] break unless input != 0 input.times do ary << gets.chomp!.to_i end ary.sort!{|a, b| a<=>b} ary.delete_at(0) ary.delete_at(ary.length-1) sum = 0 ary.each do |i| sum += i end result << sum / ary.length end result.each do |r| p r end
[["-", 0, 652, 196, 737, 8, 736, 0, 652, 735, 22], ["+", 0, 652, 196, 737, 8, 736, 0, 652, 735, 22]]
4
95
while(n=gets.to_i)>0 p n.times.map{gets.to_i}.sort[1..-1].reduce(:+)/(n-2)end
while(n=gets.to_i)>0 p n.times.map{gets.to_i}.sort[1..-2].reduce(:+)/(n-2)end
[["-", 31, 652, 486, 742, 0, 475, 444, 748, 439, 612], ["+", 31, 652, 486, 742, 0, 475, 444, 748, 439, 612]]
4
41
while input = gets if (input.to_i) == 0 exit else n = input.to_i score = Array.new(n, nil) sum = 0 end for roop in 0 .. (n - 1) score[roop] = gets.to_i end for roop in 1 .. (n - 2) sum += score[roop] end puts sum / (n - 2) end
while input = gets if (input.to_i) == 0 exit else n = input.to_i score = Array.new(n, nil) sum = 0 end for roop in 0 .. (n - 1) score[roop] = gets.to_i end score.sort! for roop in 1 .. (n - 2) sum += score[roop] end puts sum / (n - 2) end
[["+", 0, 493, 0, 89, 8, 170, 0, 652, 486, 22], ["+", 0, 493, 0, 89, 8, 170, 0, 652, 17, 131], ["+", 0, 493, 0, 89, 8, 170, 0, 652, 735, 22]]
4
78
averages = [] while True: amount = int(input()) if amount == 0: break scores = [int(input()) for i in range(amount)] scores.remove(max(scores)) scores.remove(min(scores)) averages.append(sum(scores) // amount) for i in range(len(averages)): print(averages[i])
averages = [] while True: amount = int(input()) if amount == 0: break scores = [int(input()) for i in range(amount)] scores.remove(max(scores)) scores.remove(min(scores)) averages.append(sum(scores) // (amount - 2)) for i in range(len(averages)): print(averages[i])
[["+", 0, 652, 3, 4, 0, 657, 12, 23, 0, 24], ["+", 3, 4, 0, 657, 12, 23, 0, 657, 17, 33], ["+", 3, 4, 0, 657, 12, 23, 0, 657, 12, 612], ["+", 0, 652, 3, 4, 0, 657, 12, 23, 0, 25]]
5
85
while True: n = int(eval(input())) if n == 0: break ma = 0 mi = 1000 s = 0 for i in range(n): x = int(eval(input())) if ma < x: ma = x elif mi > x: mi = x s += x print(((s - ma - mi) // (n - 2)))
while True: n = int(eval(input())) if n == 0: break ma = 0 mi = 1000 s = 0 for i in range(n): x = int(eval(input())) if ma < x: ma = x if mi > x: mi = x s += x print(((s - ma - mi) // (n - 2)))
[["-", 0, 7, 8, 196, 0, 57, 75, 665, 0, 683], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121]]
5
85
import statistics while True: n = int(input()) if n == 0: break s = [int(input()) for i in range(n)] ave = statistics.mean(sorted(s[1:-1])) print(int(ave))
import statistics while True: n = int(input()) if n == 0: break s = [int(input()) for i in range(n)] ave = statistics.mean(sorted(s)[1:-1]) print(int(ave))
[["+", 3, 4, 0, 206, 51, 652, 3, 4, 0, 25], ["-", 12, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
5
60
import bisect while True: n = int(input()) if n+1: break score = [] for _ in range(n): s = int(input()) bisect.insort(score, s) print(sum(score[1:-1])//(len(score)-2))
import bisect while True: n = int(input()) if n == 0: break score = [] for _ in range(n): s = int(input()) bisect.insort(score, s) print(sum(score[1:-1])//(len(score)-2))
[["-", 0, 52, 8, 196, 0, 57, 15, 657, 17, 72], ["-", 0, 52, 8, 196, 0, 57, 15, 657, 12, 612], ["+", 0, 52, 8, 196, 0, 57, 15, 666, 667, 60], ["+", 0, 52, 8, 196, 0, 57, 15, 666, 0, 612]]
5
69
#-*- encoding:utf-8 -*- import math while 1: n = int(input()) if n == 0: break max = 0 min = 9999 sum = 0 for i in range(n): s = int(input()) if max < s: max = s elif min > s: min = s sum = sum + s ans = math.floor((sum - min - max) / (n-2)) print(ans)
#-*- encoding:utf-8 -*- import math while 1: n = int(input()) if n == 0: break max = 0 min = 9999 sum = 0 for i in range(n): s = int(input()) if max < s: max = s if min > s: min = s sum = sum + s ans = math.floor((sum - min - max) / (n-2)) print(ans)
[["-", 0, 7, 8, 196, 0, 57, 75, 665, 0, 683], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121]]
5
90
while(True): n = eval(input()) if n == 0: break; sl = 1001 sh = 0 ret = 0 for i in range(n): tmp = eval(input()) sum += tmp if tmp < sl: sl = tmp if tmp > sh: sh = tmp ret -= (sl + sh) print("%d" % (ret/n))
while(True): n = eval(input()) if n == 0: break; sl = 1001 sh = 0 ret = 0 for i in range(n): tmp = eval(input()) ret += tmp if tmp < sl: sl = tmp if tmp > sh: sh = tmp ret -= (sl + sh) print("%d" % (ret/(n-2)))
[["-", 0, 7, 8, 196, 0, 1, 0, 677, 31, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 677, 31, 22], ["+", 0, 657, 12, 23, 0, 657, 12, 23, 0, 24], ["+", 12, 23, 0, 657, 12, 23, 0, 657, 17, 33], ["+", 12, 23, 0, 657, 12, 23, 0, 657, 12, 612], ["+", 0, 657, 12, 23, 0, 657, 12, 23, 0, 25]]
5
83
import static java.lang.Math.*; import static java.util.Arrays.*; import java.util.*; public class Main { int INF = 1 << 28; P[] ps; void run() { Scanner sc = new Scanner(System.in); for (;;) { int n = sc.nextInt(); if (n == 0) break; ps = new P[n]; for (int i = 0; i < n; i++) { ps[i] = new P(sc.nextDouble(), sc.nextDouble()); } int cnt_max = 0; int cnt = 0; for (int i = 0; i < n - 1; i++) for (int j = i + 1; j < n; j++) { if (sqrt(dis(ps[i], ps[j])) < 2.0) { P m = new P((ps[i].x + ps[j].x) / 2, (ps[i].y + ps[j].y) / 2); double d = sqrt(1 - dis(ps[i], m)); P dp = new P((ps[i].y - ps[j].y), -(ps[i].x - ps[j].x)); dp.nom(); dp.mult(d); P c[] = new P[2]; c[0] = m.add(dp); dp.mult(-1.0); c[1] = m.add(dp); for (int l = 0; l < 2; l++) { cnt = 0; // LinkedList<Double> //dist = new LinkedList<Double>(); LinkedList<Integer> ind = new //LinkedList<Integer>(); for (int k = 0; k < n; k++) { // debug(dis(c[l], //ps[k])); if (dis(c[l], ps[k]) < 1.0 || k == i || k == j) { // dist.add(dis(c[l], //ps[k])); ind.add(k); cnt++; } } // debug(dis( //ps[i], ps[j] ), cnt_max, cnt); cnt_max = max(cnt_max, cnt); } } } System.out.println(cnt_max); } } double dis(P p1, P p2) { return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y); } public static void main(String[] args) { new Main().run(); } void debug(Object... os) { System.err.println(Arrays.deepToString(os)); } class P { double x, y; P(double x, double y) { this.x = x; this.y = y; } void nom() { double nom = sqrt(x * x + y * y); x /= nom; y /= nom; } P add(P p) { x += p.x; y += p.y; return new P(x, y); } P mult(double d) { x *= d; y *= d; return new P(x, y); } } }
import static java.lang.Math.*; import static java.util.Arrays.*; import java.util.*; public class Main { int INF = 1 << 28; P[] ps; void run() { Scanner sc = new Scanner(System.in); for (;;) { int n = sc.nextInt(); if (n == 0) break; ps = new P[n]; for (int i = 0; i < n; i++) { ps[i] = new P(sc.nextDouble(), sc.nextDouble()); } int cnt_max = 1; int cnt = 0; for (int i = 0; i < n - 1; i++) for (int j = i + 1; j < n; j++) { if (sqrt(dis(ps[i], ps[j])) < 2.0) { P m = new P((ps[i].x + ps[j].x) / 2, (ps[i].y + ps[j].y) / 2); double d = sqrt(1 - dis(ps[i], m)); P dp = new P((ps[i].y - ps[j].y), -(ps[i].x - ps[j].x)); dp.nom(); dp.mult(d); P c[] = new P[2]; c[0] = m.add(dp); dp.mult(-1.0); c[1] = m.add(dp); for (int l = 0; l < 2; l++) { cnt = 0; // LinkedList<Double> //dist = new LinkedList<Double>(); LinkedList<Integer> ind = new //LinkedList<Integer>(); for (int k = 0; k < n; k++) { if (dis(c[l], ps[k]) < 1.0 || k == i || k == j) { // debug(dis(c[l], //ps[k])); dist.add(dis(c[l], ps[k])); ind.add(k); cnt++; } } // debug(c[l].x, //c[l].y, i, j, cnt); cnt_max = max(cnt_max, cnt); } } } System.out.println(cnt_max); } } double dis(P p1, P p2) { return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y); } public static void main(String[] args) { new Main().run(); } void debug(Object... os) { System.err.println(Arrays.deepToString(os)); } class P { double x, y; P(double x, double y) { this.x = x; this.y = y; } void nom() { double nom = sqrt(x * x + y * y); x /= nom; y /= nom; } P add(P p) { x += p.x; y += p.y; return new P(x, y); } P mult(double d) { x *= d; y *= d; return new P(x, y); } } }
[["-", 0, 7, 8, 196, 0, 503, 49, 200, 51, 499], ["+", 0, 7, 8, 196, 0, 503, 49, 200, 51, 499]]
3
655
import java.awt.geom.Point2D; import java.awt.geom.Point2D.Double; import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (true) { int n = sc.nextInt(); if (n == 0) break; Point2D.Double[] p = new Point2D.Double[n]; for (int i = 0; i < n; i++) p[i] = new Point2D.Double(sc.nextDouble(), sc.nextDouble()); Arrays.sort(p, new Comparator<Point2D.Double>() { public int compare(Point2D.Double o1, Point2D.Double o2) { if (o1.y - o2.y > 0) return 1; else return -1; } }); int max = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (p[j].y - p[i].y > 2.0001) break; if (p[j].distance(p[i]) > 2.0001) continue; double a, b, c, A, B, C; double xa = p[i].x; double ya = p[i].y; double xb = p[j].x; double yb = p[j].y; double[] x = new double[2]; double[] y = new double[2]; A = xa - xb; B = ya - yb; C = (A * xa + A * xb + B * ya + B * yb) / 2; if (A == 0) { c = (C / B - ya) * (C / B - ya) + xa * xa - 1; x[0] = xa + Math.sqrt(xa * xa - c); x[1] = xa - Math.sqrt(xa * xa - c); y[0] = C / B; y[1] = C / B; } else if (B == 0) { c = (C / A - xa) * (C / A - xa) + ya * ya - 1; y[0] = ya + Math.sqrt(ya * ya - c); y[1] = ya - Math.sqrt(ya * ya - c); x[0] = C / A; x[1] = C / A; } else { a = 1 + (A * A) / (B * B); b = (2 * A * ya * B - 2 * A * C - 2 * xa * B * B) / (B * B); c = (C / B - ya) * (C / B - ya) + xa * xa - 1; x[0] = (-b + Math.sqrt(b * b - 4 * a * c)) / (2 * a); x[1] = (-b - Math.sqrt(b * b - 4 * a * c)) / (2 * a); y[0] = (C - A * x[0]) / B; y[1] = (C - A * x[1]) / B; } for (int d = 0; d < 2; d++) { int cnt = 0; for (int e = 0; e < n; e++) { if (p[e].y - y[d] > 1.0001) break; if (p[e].distance(x[d], y[d]) < 1.0001) cnt++; } max = Math.max(max, cnt); } } } System.out.println(max); } } }
import java.awt.geom.Point2D; import java.awt.geom.Point2D.Double; import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (true) { int n = sc.nextInt(); if (n == 0) break; Point2D.Double[] p = new Point2D.Double[n]; for (int i = 0; i < n; i++) p[i] = new Point2D.Double(sc.nextDouble(), sc.nextDouble()); Arrays.sort(p, new Comparator<Point2D.Double>() { public int compare(Point2D.Double o1, Point2D.Double o2) { if (o1.y - o2.y > 0) return 1; else return -1; } }); int max = 1; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (p[j].y - p[i].y > 2.0001) break; if (p[j].distance(p[i]) > 2.0001) continue; double a, b, c, A, B, C; double xa = p[i].x; double ya = p[i].y; double xb = p[j].x; double yb = p[j].y; double[] x = new double[2]; double[] y = new double[2]; A = xa - xb; B = ya - yb; C = (A * xa + A * xb + B * ya + B * yb) / 2; if (A == 0) { c = (C / B - ya) * (C / B - ya) + xa * xa - 1; x[0] = xa + Math.sqrt(xa * xa - c); x[1] = xa - Math.sqrt(xa * xa - c); y[0] = C / B; y[1] = C / B; } else if (B == 0) { c = (C / A - xa) * (C / A - xa) + ya * ya - 1; y[0] = ya + Math.sqrt(ya * ya - c); y[1] = ya - Math.sqrt(ya * ya - c); x[0] = C / A; x[1] = C / A; } else { a = 1 + (A * A) / (B * B); b = (2 * A * ya * B - 2 * A * C - 2 * xa * B * B) / (B * B); c = (C / B - ya) * (C / B - ya) + xa * xa - 1; x[0] = (-b + Math.sqrt(b * b - 4 * a * c)) / (2 * a); x[1] = (-b - Math.sqrt(b * b - 4 * a * c)) / (2 * a); y[0] = (C - A * x[0]) / B; y[1] = (C - A * x[1]) / B; } for (int d = 0; d < 2; d++) { int cnt = 0; for (int e = 0; e < n; e++) { if (p[e].y - y[d] > 1.0001) break; if (p[e].distance(x[d], y[d]) < 1.0001) cnt++; } max = Math.max(max, cnt); } } } System.out.println(max); } } }
[["-", 0, 52, 8, 196, 0, 503, 49, 200, 51, 499], ["+", 0, 52, 8, 196, 0, 503, 49, 200, 51, 499]]
3
818
import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class Main { static Scanner sc = new Scanner(System.in); static int N; static double[] X, Y; public static void main(String[] args) { while (true) { N = sc.nextInt(); if (N == 0) break; X = new double[N]; Y = new double[N]; for (int i = 0; i < N; ++i) { X[i] = sc.nextDouble(); Y[i] = sc.nextDouble(); } System.out.println(solve()); } } static int solve() { if (N == 1) return 1; if (N == 2) { return dist(0, 1) < 2 ? 2 : 1; } int ans = 1; for (int i = 0; i < N; ++i) { for (int j = i + 1; j < N; ++j) { double d = dist(i, j); if (d > 2) continue; double dx = (X[j] - X[i]) / 2; double dy = (Y[j] - Y[i]) / 2; double len = sq(dx, dy); double ex = dx / len; double ey = dx / len; double lenC = Math.sqrt(1 - len); { double cx = X[i] + dx - ey * lenC; double cy = Y[i] + dy + ex * lenC; ans = Math.max(ans, count(cx, cy)); } { double cx = X[i] + dx + ey * lenC; double cy = Y[i] + dy - ex * lenC; ans = Math.max(ans, count(cx, cy)); } } } return ans; } static int count(double cx, double cy) { int c = 0; for (int i = 0; i < N; ++i) { double d = sq(X[i] - cx, Y[i] - cy); if (d <= 1 + 1e-8) ++c; } return c; } static double dist(int i, int j) { return sq(X[i] - X[j], Y[i] - Y[j]); } static double sq(double x, double y) { return Math.sqrt(x * x + y * y); } }
import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class Main { static Scanner sc = new Scanner(System.in); static int N; static double[] X, Y; public static void main(String[] args) { while (true) { N = sc.nextInt(); if (N == 0) break; X = new double[N]; Y = new double[N]; for (int i = 0; i < N; ++i) { X[i] = sc.nextDouble(); Y[i] = sc.nextDouble(); } System.out.println(solve()); } } static int solve() { if (N == 1) return 1; if (N == 2) { return dist(0, 1) <= 2 ? 2 : 1; } int ans = 1; for (int i = 0; i < N; ++i) { for (int j = i + 1; j < N; ++j) { double d = dist(i, j); if (d > 2) continue; double dx = (X[j] - X[i]) / 2; double dy = (Y[j] - Y[i]) / 2; double len = sq(dx, dy); double ex = dx / len; double ey = dy / len; double lenC = Math.sqrt(1 - len * len); { double cx = X[i] + dx - ey * lenC; double cy = Y[i] + dy + ex * lenC; ans = Math.max(ans, count(cx, cy)); } { double cx = X[i] + dx + ey * lenC; double cy = Y[i] + dy - ex * lenC; ans = Math.max(ans, count(cx, cy)); } } } return ans; } static int count(double cx, double cy) { int c = 0; for (int i = 0; i < N; ++i) { double d = sq(X[i] - cx, Y[i] - cy); if (d <= 1 + 1e-9) ++c; } return c; } static double dist(int i, int j) { return sq(X[i] - X[j], Y[i] - Y[j]); } static double sq(double x, double y) { return Math.sqrt(x * x + y * y); } }
[["-", 64, 196, 0, 37, 0, 510, 15, 16, 17, 18], ["+", 64, 196, 0, 37, 0, 510, 15, 16, 17, 19], ["-", 8, 196, 0, 503, 49, 200, 51, 16, 31, 22], ["+", 8, 196, 0, 503, 49, 200, 51, 16, 31, 22], ["+", 51, 492, 3, 4, 0, 16, 12, 16, 31, 22], ["+", 51, 492, 3, 4, 0, 16, 12, 16, 17, 48], ["-", 0, 57, 15, 15, 0, 16, 12, 16, 12, 515], ["+", 0, 57, 15, 15, 0, 16, 12, 16, 12, 515]]
3
538
import java.awt.geom.Point2D; import java.util.*; public class Main { Scanner in = new Scanner(System.in); public static void main(String[] args) { new Main(); } public Main() { while (in.hasNext()) new AOJ1134().doIt(); } class AOJ1134 { final double EPS = 1.0e-8; Point2D[] intersectPtCC(Circle a, Circle b) { double dis = a.p.distance(b.p); if (dis > a.r + b.r) return null; Point2D v = sub(b.p, a.p); double rc = (dis * dis + a.r * a.r - b.r * b.r) / (2 * dis); double rate = rc / dis; v = mul(rate, v); Point2D c = add(v, a.p); double disC2c = c.distance(b.p); double disqc = Math.sqrt(b.r * b.r - disC2c * disC2c); Point2D v2 = sub(b.p, c); v2 = mul(disqc / disC2c, v2); Point2D[] ret = new Point2D.Double[2]; ret[0] = add(normalVector1(v2), c); ret[1] = add(normalVector2(v2), c); return ret; } Point2D add(Point2D p1, Point2D p2) { return new Point2D.Double(p1.getX() + p2.getX(), p1.getY() + p2.getY()); } Point2D normalVector1(Point2D p) { return new Point2D.Double(-p.getY(), p.getX()); } Point2D normalVector2(Point2D p) { return new Point2D.Double(p.getY(), -p.getX()); } Point2D mul(double n, Point2D p1) { return new Point2D.Double(p1.getX() * n, p1.getY() * n); } Point2D sub(Point2D p1, Point2D p2) { return new Point2D.Double(p1.getX() - p2.getX(), p1.getY() - p2.getY()); } class Circle { Point2D p; double r; Circle(Point2D p, double r) { this.p = p; this.r = r; } Circle(double x, double y, double r) { this.p = new Point2D.Double(x, y); this.r = r; } } void doIt() { int n = in.nextInt(); if (n == 0) return; Point2D[] p = new Point2D[n]; for (int i = 0; i < n; i++) p[i] = new Point2D.Double(in.nextDouble(), in.nextDouble()); int result = 1; for (int i = 0; i < n; i++) for (int s = 0; s < n; s++) if (i != s) if (p[i].distance(p[s]) <= 2) { Point2D[] k = intersectPtCC(new Circle(p[i], 1 + EPS), new Circle(p[s], 1 + EPS)); for (int a = 0; a < k.length; a++) { int cnt = 0; for (int b = 0; b < n; b++) if (k[a].distance(p[b]) <= 1 + EPS) cnt++; result = Math.max(result, cnt); } } System.out.println(result); } } }
import java.awt.geom.Point2D; import java.util.*; public class Main { Scanner in = new Scanner(System.in); public static void main(String[] args) { new Main(); } public Main() { while (in.hasNext()) new AOJ1134().doIt(); } class AOJ1134 { final double EPS = 1.0e-8; Point2D[] intersectPtCC(Circle a, Circle b) { double dis = a.p.distance(b.p); if (dis > a.r + b.r) return null; Point2D v = sub(b.p, a.p); double rc = (dis * dis + a.r * a.r - b.r * b.r) / (2 * dis); double rate = rc / dis; v = mul(rate, v); Point2D c = add(v, a.p); double disC2c = c.distance(b.p); double disqc = Math.sqrt(b.r * b.r - disC2c * disC2c); Point2D v2 = sub(b.p, c); v2 = mul(disqc / disC2c, v2); Point2D[] ret = new Point2D.Double[2]; ret[0] = add(normalVector1(v2), c); ret[1] = add(normalVector2(v2), c); return ret; } Point2D add(Point2D p1, Point2D p2) { return new Point2D.Double(p1.getX() + p2.getX(), p1.getY() + p2.getY()); } Point2D normalVector1(Point2D p) { return new Point2D.Double(-p.getY(), p.getX()); } Point2D normalVector2(Point2D p) { return new Point2D.Double(p.getY(), -p.getX()); } Point2D mul(double n, Point2D p1) { return new Point2D.Double(p1.getX() * n, p1.getY() * n); } Point2D sub(Point2D p1, Point2D p2) { return new Point2D.Double(p1.getX() - p2.getX(), p1.getY() - p2.getY()); } class Circle { Point2D p; double r; Circle(Point2D p, double r) { this.p = p; this.r = r; } Circle(double x, double y, double r) { this.p = new Point2D.Double(x, y); this.r = r; } } void doIt() { int n = in.nextInt(); if (n == 0) return; Point2D[] p = new Point2D[n]; for (int i = 0; i < n; i++) p[i] = new Point2D.Double(in.nextDouble(), in.nextDouble()); int result = 1; for (int i = 0; i < n; i++) for (int s = 0; s < n; s++) if (i != s) if (p[i].distance(p[s]) <= 2) { Point2D[] k = intersectPtCC(new Circle(p[i], 1), new Circle(p[s], 1)); for (int a = 0; a < k.length; a++) { int cnt = 0; for (int b = 0; b < n; b++) if (k[a].distance(p[b]) <= 1 + EPS) cnt++; result = Math.max(result, cnt); } } System.out.println(result); } } }
[["-", 3, 4, 0, 230, 3, 4, 0, 16, 17, 72], ["-", 3, 4, 0, 230, 3, 4, 0, 16, 12, 22]]
3
779
#include <math.h> #include <stdio.h> #define p2(x) ((x) * (x)) #define mul(rx, ry, x1, y1, x2, y2) \ ((rx) = (x1) * (x2) - (y1) * (y2), (ry) = (x2) * (y1) + (x1) * (y2)) #define R 1 double X[300], Y[300], hyp, t, pl, dx, dy, x[2], y[2]; int main() { int N, M, m, i, j, k, z; for (; scanf("%d", &N), N; printf("%d\n", M)) { for (i = 0; i < N; i++) scanf("%lf%lf", X + i, Y + i); for (M = 1, i = 0; i < N; i++) for (j = i + 1; j < N; j++) { hyp = hypot(X[j] - X[i], Y[j] - Y[i]); if (hyp > 2 * R) continue; // t=( p2(R)-p2(R)+p2(hyp) )/( 2*hyp ); t = hyp / 2; pl = sqrt(p2(R) - p2(t)); dx = (X[j] - X[i]) / hyp; dy = (Y[j] - Y[i]) / hyp; mul(x[0], y[0], dx, dy, t, pl); mul(x[1], y[1], dx, dy, t, -pl); for (z = 0; z < 2; z++) { x[z] += X[i], y[z] += Y[i]; for (m = k = 0; k < N; k++) if (p2(X[k] - x[z]) + p2(Y[k] - y[z]) < p2(R) - 1e-9) m++; if (M < m) M = m; } } } return 0; }
#include <math.h> #include <stdio.h> #define p2(x) ((x) * (x)) #define mul(rx, ry, x1, y1, x2, y2) \ ((rx) = (x1) * (x2) - (y1) * (y2), (ry) = (x2) * (y1) + (x1) * (y2)) #define R 1 double X[300], Y[300], hyp, t, pl, dx, dy, x[2], y[2]; int main() { int N, M, m, i, j, k, z; for (; scanf("%d", &N), N; printf("%d\n", M)) { for (i = 0; i < N; i++) scanf("%lf%lf", X + i, Y + i); for (M = 1, i = 0; i < N; i++) for (j = i + 1; j < N; j++) { hyp = hypot(X[j] - X[i], Y[j] - Y[i]); if (hyp > 2 * R) continue; // t=( p2(R)-p2(R)+p2(hyp) )/( 2*hyp ); t = hyp / 2; pl = sqrt(p2(R) - p2(t)); dx = (X[j] - X[i]) / hyp; dy = (Y[j] - Y[i]) / hyp; mul(x[0], y[0], dx, dy, t, pl); mul(x[1], y[1], dx, dy, t, -pl); for (z = 0; z < 2; z++) { x[z] += X[i], y[z] += Y[i]; for (m = k = 0; k < N; k++) if (p2(X[k] - x[z]) + p2(Y[k] - y[z]) < p2(R) + 1e-9) m++; if (M < m) M = m; } } } return 0; }
[["-", 8, 57, 15, 23, 0, 16, 12, 16, 17, 33], ["+", 8, 57, 15, 23, 0, 16, 12, 16, 17, 72]]
0
404
#include <math.h> #include <stdio.h> int main() { int n, i, j, l, max, c; double x[310], y[310], k, s, t, a, b, e = 1e-6; while (scanf("%d", &n), n) { for (i = max = 0; i < n; i++) scanf("%lf %lf", &x[i], &y[i]); for (i = 0; i < n; i++) { for (j = i + 1; j < n; j++) { a = (x[i] - x[j]) / 2; b = (y[i] - y[j]) / 2; if (hypot(a, b) - e > 1) continue; k = tan(acos(hypot(a, b))); s = x[j] + a + k * b; t = y[j] + b - k * a; for (l = c = 0; l < n; l++) { if (hypot(x[l] - s, y[l] - t) - e < 1) c++; } if (max < c) max = c; s = x[j] + a - k * b; t = y[j] + b + k * a; for (l = c = 0; l < n; l++) { if (hypot(x[l] - s, y[l] - t) - e < 1) c++; } if (max < c) max = c; } } printf("%d\n", max); } return 0; }
#include <math.h> #include <stdio.h> int main() { int n, i, j, l, max, c; double x[310], y[310], k, s, t, a, b, e = 1e-6; while (scanf("%d", &n), n) { max = 1; for (i = 0; i < n; i++) scanf("%lf %lf", &x[i], &y[i]); for (i = 0; i < n; i++) { for (j = i + 1; j < n; j++) { a = (x[i] - x[j]) / 2; b = (y[i] - y[j]) / 2; if (hypot(a, b) - e > 1) continue; k = tan(acos(hypot(a, b))); s = x[j] + a + k * b; t = y[j] + b - k * a; for (l = c = 0; l < n; l++) { if (hypot(x[l] - s, y[l] - t) - e < 1) c++; } if (max < c) max = c; s = x[j] + a - k * b; t = y[j] + b + k * a; for (l = c = 0; l < n; l++) { if (hypot(x[l] - s, y[l] - t) - e < 1) c++; } if (max < c) max = c; } } printf("%d\n", max); } return 0; }
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35], ["-", 0, 52, 8, 9, 0, 7, 10, 11, 17, 32], ["-", 8, 9, 0, 7, 10, 11, 12, 11, 31, 22]]
0
363
#include <algorithm> #include <cmath> #include <deque> #include <iostream> #include <string> #include <utility> #include <vector> #define REP(i, n) FOR(i, 0, n) #define FOR(i, a, b) for (int i = int(a); i < int(b); ++i) #define RREP(i, n) RFOR(i, 0, n) #define RFOR(i, a, b) for (int i = int(b) - 1; i >= int(a); --i) constexpr double EPS = 1e-7; signed main() { while (true) { int n; std::cin >> n; if (n == 0) break; std::vector<double> x(n), y(n); REP(i, n) std::cin >> x[i] >> y[i]; int ans = 0; REP(i, n) FOR(j, i + 1, n) { double dist = std::hypot(x[i] - x[j], y[i] - y[j]); if (dist > 2 + EPS) continue; // iとjの中点m double mx = (x[i] + x[j]) / 2; double my = (y[i] + y[j]) / 2; // 線分ijから中心への距離 double r = std::sqrt(1 - (dist / 2) * (dist / 2)); // 中心c for (int sign = -1; sign <= 1; sign += 2) { // 移動のベクトルv double vx = sign * r * (y[j] - y[i]) / dist; double vy = sign * r * -(x[j] - x[i]) / dist; double cx = mx + vx; double cy = my + vy; int cnt = 0; REP(k, n) { if (std::hypot(cx - x[k], cy - y[k]) < 1 + EPS) ++cnt; } ans = std::max(ans, cnt); } } std::cout << ans << "\n"; } return 0; }
#include <algorithm> #include <cmath> #include <deque> #include <iostream> #include <string> #include <utility> #include <vector> #define REP(i, n) FOR(i, 0, n) #define FOR(i, a, b) for (int i = int(a); i < int(b); ++i) #define RREP(i, n) RFOR(i, 0, n) #define RFOR(i, a, b) for (int i = int(b) - 1; i >= int(a); --i) constexpr double EPS = 1e-7; signed main() { while (true) { int n; std::cin >> n; if (n == 0) break; std::vector<double> x(n), y(n); REP(i, n) std::cin >> x[i] >> y[i]; int ans = 1; REP(i, n) FOR(j, i + 1, n) { double dist = std::hypot(x[i] - x[j], y[i] - y[j]); if (dist > 2 + EPS) continue; // iとjの中点m double mx = (x[i] + x[j]) / 2; double my = (y[i] + y[j]) / 2; // 線分ijから中心への距離 double r = std::sqrt(1 - (dist / 2) * (dist / 2)); // 中心c for (int sign = -1; sign <= 1; sign += 2) { // 移動のベクトルv double vx = sign * r * (y[j] - y[i]) / dist; double vy = sign * r * -(x[j] - x[i]) / dist; double cx = mx + vx; double cy = my + vy; int cnt = 0; REP(k, n) { if (std::hypot(cx - x[k], cy - y[k]) < 1 + EPS) ++cnt; } ans = std::max(ans, cnt); } } std::cout << ans << "\n"; } return 0; }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
1
384
#include <algorithm> #include <cassert> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <ctime> #include <deque> #include <functional> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <string> #include <utility> #include <vector> #define REP(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define DEBUGP(val) cerr << #val << "=" << val << "\n" using namespace std; typedef long long int ll; typedef vector<int> VI; typedef vector<ll> VL; typedef pair<int, int> PI; typedef pair<double, double> PD; const double EPS = 1e-11; double sq(double x) { return x * x; } void solve(double ax, double ay, double bx, double by, int &ma, const vector<double> &x, const vector<double> &y) { double sqdist = sq(ax - bx) + sq(ay - by); if (sqdist >= 4 + EPS) return; double dist = sqrt(sqdist); double ndist = sqrt(1 - sqdist / 4); double ex = (bx - ax) / dist, ey = (by - ay) / dist; int n = x.size(); REP(i, 0, 2) { double coef = i == 0 ? 1 : -1; double cx = (ax + bx) / 2 + ey * coef * ndist; double cy = (ay + by) / 2 - ex * coef * ndist; int cnt = 0; REP(j, 0, n) { double sqdist = sq(x[j] - cx) + sq(y[j] - cy); if (sqdist <= 1 + EPS) { cnt += 1; } } ma = max(ma, cnt); } } int main(void) { int n; while (scanf("%d", &n) && n) { vector<double> x(n), y(n); REP(i, 0, n) scanf("%lf%lf", &x[i], &y[i]); int ma = 0; REP(i, 0, n) { REP(j, 0, i) { solve(x[i], y[i], x[j], y[j], ma, x, y); } } printf("%d\n", ma); } }
#include <algorithm> #include <cassert> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <ctime> #include <deque> #include <functional> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <string> #include <utility> #include <vector> #define REP(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define DEBUGP(val) cerr << #val << "=" << val << "\n" using namespace std; typedef long long int ll; typedef vector<int> VI; typedef vector<ll> VL; typedef pair<int, int> PI; typedef pair<double, double> PD; const double EPS = 1e-11; double sq(double x) { return x * x; } void solve(double ax, double ay, double bx, double by, int &ma, const vector<double> &x, const vector<double> &y) { double sqdist = sq(ax - bx) + sq(ay - by); if (sqdist >= 4 + EPS) return; double dist = sqrt(sqdist); double ndist = sqrt(1 - sqdist / 4); double ex = (bx - ax) / dist, ey = (by - ay) / dist; int n = x.size(); REP(i, 0, 2) { double coef = i == 0 ? 1 : -1; double cx = (ax + bx) / 2 + ey * coef * ndist; double cy = (ay + by) / 2 - ex * coef * ndist; int cnt = 0; REP(j, 0, n) { double sqdist = sq(x[j] - cx) + sq(y[j] - cy); if (sqdist <= 1 + EPS) { cnt += 1; } } ma = max(ma, cnt); } } int main(void) { int n; while (scanf("%d", &n) && n) { vector<double> x(n), y(n); REP(i, 0, n) scanf("%lf%lf", &x[i], &y[i]); int ma = 1; REP(i, 0, n) { REP(j, 0, i) { solve(x[i], y[i], x[j], y[j], ma, x, y); } } printf("%d\n", ma); } }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
1
477
//////////////////// /// template /// //////////////////// #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; //// MACRO //// #define REP(i, n) for (int i = 0; i < (n); i++) #define RREP(i, n) for (int i = (n)-1; i >= 0; i--) #define FOR(i, s, n) for (int i = (s); i < (n); i++) #define allof(c) c.begin(), c.end() #define partof(c, i, n) c.begin() + (i), c.begin() + (i) + (n) #define EPS 1e-10 #define INF 1000000000 #define countof(a) (sizeof(a) / sizeof(a[0])) #define PREDIACTE(t, a) [](const t &a) -> bool #define COMPARISON_T(t) bool (*)(const t &, const t &) #define COMPARISON(t, a, b) [](const t &a, const t &b) -> bool //// prime //// vector<unsigned char> isPrime; vector<int> primes; void initPrimes(int n) { isPrime = vector<unsigned char>(n + 1, true); isPrime[0] = isPrime[1] = false; FOR(i, 2, n + 1) { if (!isPrime[i]) continue; primes.push_back(i); for (int j = i * 2; j <= n; j += i) isPrime[j] = false; } } //// Probability //// // パスカルの三角形(二項定理) 2種類の並べ替えにつかう。 vector<vector<double>> makePascalTriangle(int n, bool probability = false) { typedef vector<double> VD; vector<VD> t; if (!t.size()) { t.push_back(VD(1, 1)); } FOR(i, t.size(), n + 1) { t.push_back(VD(i + 1)); REP(j, i) { double x = t[i - 1][j] * (probability ? 0.5 : 1); t[i][j] += x; t[i][j + 1] += x; } } return t; } //// iota iterator //// struct iotait { int n; iotait(int n = 0) : n(n) {} iotait &operator++() { ++n; return *this; } int operator*() { return n; } }; //// geo //// struct P3 { double x, y, z; P3(double x = 0, double y = 0, double z = 0) : x(x), y(y), z(z) {} P3 operator+() const { return *this; } P3 operator+(const P3 &_) const { return P3(x + _.x, y + _.y, z + _.z); } P3 operator-() const { return P3(-x, -y, -z); } P3 operator-(const P3 &_) const { return *this + -_; } P3 operator*(double _) const { return P3(x * _, y * _, z * _); } P3 operator/(double _) const { return P3(x / _, y / _, z / _); } double dot(const P3 &_) const { return x * _.x + y * _.y + z * _.z; } // 内積 P3 cross(const P3 &_) const { return P3(y * _.z - z * _.y, z * _.x - x * _.z, x * _.y - y * _.x); } // 外積 double sqlength() const { return x * x + y * y + z * z; } // 二乗長さ double length() const { return sqrt(sqlength()); } // 長さ P3 direction() const { return *this / length(); } // 方向ベクトル }; inline istream &operator>>(istream &in, P3 &p) { in >> p.x >> p.y >> p.z; return in; } inline double abs(P3 p) { return p.length(); } struct Sphere { P3 c; double r; Sphere(double x, double y, double z, double r) : c(x, y, z), r(r) {} Sphere(P3 c, double r) : c(c), r(r) {} bool IntersectWith(const Sphere &rhs) const { return abs(c - rhs.c) - (r + rhs.r) < EPS; } // 接してても真。 }; inline istream &operator>>(istream &in, Sphere &c) { in >> c.c >> c.r; return in; } struct P2 { double x, y; P2(double x = 0, double y = 0) : x(x), y(y) {} P2(complex<double> c) : x(c.real()), y(c.imag()) {} P2 operator+() const { return *this; } P2 operator+(const P2 &_) const { return P2(x + _.x, y + _.y); } P2 operator-() const { return P2(-x, -y); } P2 operator-(const P2 &_) const { return *this + -_; } P2 operator*(double _) const { return P2(x * _, y * _); } P2 operator/(double _) const { return P2(x / _, y / _); } double dot(const P2 &_) const { return x * _.x + y * _.y; } // 内積 double cross(const P2 &_) const { return x * _.y - y * _.x; } // 外積 double sqlength() const { return x * x + y * y; } // 二乗長さ double length() const { return sqrt(sqlength()); } // 長さ P2 orthogonal() const { return P2(y, -x); } P2 direction() const { return *this / length(); } // 方向ベクトル }; inline istream &operator>>(istream &in, P2 &p) { in >> p.x >> p.y; return in; } inline double abs(P2 p2) { return p2.length(); } inline P2 orthogonal(P2 p) { return p.orthogonal(); } inline complex<double> orthogonal(complex<double> c) { return c * complex<double>(0, 1); } // a,b から ちょうど d だけ離れた点。aとbを円周に持つ円の半径。 pair<P2, P2> get_same_distance_points(P2 a, P2 b, double d) { assert(abs(a - b) <= 2 * d + EPS); auto v = (a + b) / 2.0 - a; // a から aとbの中点 auto vl = abs(v); auto wl = sqrt(d * d - vl * vl); // 直行Vの大きさ auto w = orthogonal(v) * (wl / vl); // 直行V return make_pair(a + v + w, a + v - w); } struct Circle { P2 c; double r; Circle(double x, double y, double r) : c(x, y), r(r) {} Circle(P2 c, double r) : c(c), r(r) {} bool IntersectWith(const Circle &rhs) const { return abs(c - rhs.c) - (r + rhs.r) < EPS; } // 接してても真。 bool Contains(const P2 &p) const { return abs(p - c) - r < EPS; } // 接してても真。 }; inline istream &operator>>(istream &in, Circle &c) { in >> c.c >> c.r; return in; } //// bit //// #ifdef _MSC_VER inline unsigned __builtin_ctz(unsigned x) { unsigned long r; _BitScanForward(&r, x); return r; } #endif inline int next_bit_permutation(int x) { int t = x | (x - 1); return (t + 1) | (unsigned)((~t & -~t) - 1) >> (__builtin_ctz(x) + 1); } //// graph //// struct Path { int from; int to; double cost; Path(int from = 0, int to = 0, double cost = 0) : from(from), to(to), cost(cost) {} bool operator<(const Path &rhs) const { return cost < rhs.cost; } bool operator>(const Path &rhs) const { return cost > rhs.cost; } }; // prim // pair<double, vector<int>> prim(const vector<vector<double>> &costTable) { int N = costTable.size(); priority_queue<Path, vector<Path>, greater<Path>> q; q.push(Path(0, 0, 0)); vector<int> parent(N, -1); double totalCost = 0; while (!q.empty()) { Path cur = q.top(); q.pop(); int i = cur.to; if (parent[i] != -1) continue; parent[i] = cur.from; totalCost += cur.cost; REP(j, N) if (parent[j] == -1) q.push(Path(i, j, costTable[i][j])); } return make_pair(totalCost, parent); } // dijkstra // pair<vector<double>, vector<int>> dijkstra(const vector<vector<Path>> &routes, int start = 0, int goal = -1) { int N = routes.size(); priority_queue<Path, vector<Path>, greater<Path>> q; q.push(Path(start, start, 0)); vector<int> prev(N, -1); vector<double> cost(N, INF); while (!q.empty()) { Path cur = q.top(); q.pop(); int i = cur.to; if (prev[i] != -1) continue; prev[i] = cur.from; cost[i] = cur.cost; if (i == goal) { break; } REP(j, routes[i].size()) { Path next = Path(i, routes[i][j].to, cur.cost + routes[i][j].cost); if (prev[next.to] == -1) q.push(next); } } return make_pair(cost, prev); } //// i/o //// template <class T> class vevector : public vector<vector<T>> { public: vevector(int n = 0, int m = 0) : vector<vector<T>>(n, vector<T>(m)){}; vevector(int n, int m, const T &initial) : vector<vector<T>>(n, vector<T>(m, initial)){}; }; template <class T> T read() { T t; cin >> t; return t; } template <class T> vector<T> read(int n) { vector<T> v; REP(i, n) { v.push_back(read<T>()); } return v; } template <class T> vevector<T> read(int n, int m) { vevector<T> v; REP(i, n) v.push_back(read<T>(m)); return v; } template <class T> vevector<T> readjag(int n) { vevector<T> v; REP(i, n) v.push_back(read<T>(read<int>())); return v; } template <class T> void write(const T &t) { cout << t << endl; } template <class T> void write(const T &t, const T &t2) { cout << t << ' ' << t2 << endl; } template <class T> void write(const vector<T> &v) { ostringstream ss; for (auto x : v) ss << x << ' '; auto s = ss.str(); cout << s.substr(0, s.length() - 1) << endl; } template <class T> istream &operator>>(istream &in, complex<T> &n) { T r, i; in >> r >> i; n = complex<T>(r, i); return in; } struct _Reader { template <class T> _Reader operator,(T &rhs) { cin >> rhs; return *this; } }; #define READ(t, ...) \ t __VA_ARGS__; \ _Reader(), __VA_ARGS__ template <class InIt1, class InIt2> int partial_compare(InIt1 first1, InIt1 last1, InIt2 first2, InIt2 last2) { return lexicographical_compare(first1, last1, first2, last2) ? -1 : lexicographical_compare(first2, last2, first1, last1) ? 1 : 0; } //// start up //// void solve(); int main() { // freopen("A.in", "r", stdin); solve(); return 0; } //////////////////// /// template end /// //////////////////// void solve() { auto testcases = INF; // read<int>(); REP(testcase, testcases) { READ(int, N); if (!N) { break; } auto ps = read<P2>(N); int result = N; REP(i_, N) FOR(j_, i_ + 1, N) { const P2 i = ps[i_], j = ps[j_]; double r = 1; if (abs(i - j) - 2 * r > -EPS) { continue; } // 遠すぎて円が作れない auto c = get_same_distance_points(i, j, r); // i と j から ちょうど r 離れた点 auto c1 = Circle(c.first, r), c2 = Circle(c.second, r); result = max<int>(result, count_if(allof(ps), [c1, r](P2 p) { return c1.Contains(p); })); result = max<int>(result, count_if(allof(ps), [c2, r](P2 p) { return c2.Contains(p); })); } write(result); } }
//////////////////// /// template /// //////////////////// #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; //// MACRO //// #define REP(i, n) for (int i = 0; i < (n); i++) #define RREP(i, n) for (int i = (n)-1; i >= 0; i--) #define FOR(i, s, n) for (int i = (s); i < (n); i++) #define allof(c) c.begin(), c.end() #define partof(c, i, n) c.begin() + (i), c.begin() + (i) + (n) #define EPS 1e-10 #define INF 1000000000 #define countof(a) (sizeof(a) / sizeof(a[0])) #define PREDIACTE(t, a) [](const t &a) -> bool #define COMPARISON_T(t) bool (*)(const t &, const t &) #define COMPARISON(t, a, b) [](const t &a, const t &b) -> bool //// prime //// vector<unsigned char> isPrime; vector<int> primes; void initPrimes(int n) { isPrime = vector<unsigned char>(n + 1, true); isPrime[0] = isPrime[1] = false; FOR(i, 2, n + 1) { if (!isPrime[i]) continue; primes.push_back(i); for (int j = i * 2; j <= n; j += i) isPrime[j] = false; } } //// Probability //// // パスカルの三角形(二項定理) 2種類の並べ替えにつかう。 vector<vector<double>> makePascalTriangle(int n, bool probability = false) { typedef vector<double> VD; vector<VD> t; if (!t.size()) { t.push_back(VD(1, 1)); } FOR(i, t.size(), n + 1) { t.push_back(VD(i + 1)); REP(j, i) { double x = t[i - 1][j] * (probability ? 0.5 : 1); t[i][j] += x; t[i][j + 1] += x; } } return t; } //// iota iterator //// struct iotait { int n; iotait(int n = 0) : n(n) {} iotait &operator++() { ++n; return *this; } int operator*() { return n; } }; //// geo //// struct P3 { double x, y, z; P3(double x = 0, double y = 0, double z = 0) : x(x), y(y), z(z) {} P3 operator+() const { return *this; } P3 operator+(const P3 &_) const { return P3(x + _.x, y + _.y, z + _.z); } P3 operator-() const { return P3(-x, -y, -z); } P3 operator-(const P3 &_) const { return *this + -_; } P3 operator*(double _) const { return P3(x * _, y * _, z * _); } P3 operator/(double _) const { return P3(x / _, y / _, z / _); } double dot(const P3 &_) const { return x * _.x + y * _.y + z * _.z; } // 内積 P3 cross(const P3 &_) const { return P3(y * _.z - z * _.y, z * _.x - x * _.z, x * _.y - y * _.x); } // 外積 double sqlength() const { return x * x + y * y + z * z; } // 二乗長さ double length() const { return sqrt(sqlength()); } // 長さ P3 direction() const { return *this / length(); } // 方向ベクトル }; inline istream &operator>>(istream &in, P3 &p) { in >> p.x >> p.y >> p.z; return in; } inline double abs(P3 p) { return p.length(); } struct Sphere { P3 c; double r; Sphere(double x, double y, double z, double r) : c(x, y, z), r(r) {} Sphere(P3 c, double r) : c(c), r(r) {} bool IntersectWith(const Sphere &rhs) const { return abs(c - rhs.c) - (r + rhs.r) < EPS; } // 接してても真。 }; inline istream &operator>>(istream &in, Sphere &c) { in >> c.c >> c.r; return in; } struct P2 { double x, y; P2(double x = 0, double y = 0) : x(x), y(y) {} P2(complex<double> c) : x(c.real()), y(c.imag()) {} P2 operator+() const { return *this; } P2 operator+(const P2 &_) const { return P2(x + _.x, y + _.y); } P2 operator-() const { return P2(-x, -y); } P2 operator-(const P2 &_) const { return *this + -_; } P2 operator*(double _) const { return P2(x * _, y * _); } P2 operator/(double _) const { return P2(x / _, y / _); } double dot(const P2 &_) const { return x * _.x + y * _.y; } // 内積 double cross(const P2 &_) const { return x * _.y - y * _.x; } // 外積 double sqlength() const { return x * x + y * y; } // 二乗長さ double length() const { return sqrt(sqlength()); } // 長さ P2 orthogonal() const { return P2(y, -x); } P2 direction() const { return *this / length(); } // 方向ベクトル }; inline istream &operator>>(istream &in, P2 &p) { in >> p.x >> p.y; return in; } inline double abs(P2 p2) { return p2.length(); } inline P2 orthogonal(P2 p) { return p.orthogonal(); } inline complex<double> orthogonal(complex<double> c) { return c * complex<double>(0, 1); } // a,b から ちょうど d だけ離れた点。aとbを円周に持つ円の半径。 pair<P2, P2> get_same_distance_points(P2 a, P2 b, double d) { assert(abs(a - b) <= 2 * d + EPS); auto v = (a + b) / 2.0 - a; // a から aとbの中点 auto vl = abs(v); auto wl = sqrt(d * d - vl * vl); // 直行Vの大きさ auto w = orthogonal(v) * (wl / vl); // 直行V return make_pair(a + v + w, a + v - w); } struct Circle { P2 c; double r; Circle(double x, double y, double r) : c(x, y), r(r) {} Circle(P2 c, double r) : c(c), r(r) {} bool IntersectWith(const Circle &rhs) const { return abs(c - rhs.c) - (r + rhs.r) < EPS; } // 接してても真。 bool Contains(const P2 &p) const { return abs(p - c) - r < EPS; } // 接してても真。 }; inline istream &operator>>(istream &in, Circle &c) { in >> c.c >> c.r; return in; } //// bit //// #ifdef _MSC_VER inline unsigned __builtin_ctz(unsigned x) { unsigned long r; _BitScanForward(&r, x); return r; } #endif inline int next_bit_permutation(int x) { int t = x | (x - 1); return (t + 1) | (unsigned)((~t & -~t) - 1) >> (__builtin_ctz(x) + 1); } //// graph //// struct Path { int from; int to; double cost; Path(int from = 0, int to = 0, double cost = 0) : from(from), to(to), cost(cost) {} bool operator<(const Path &rhs) const { return cost < rhs.cost; } bool operator>(const Path &rhs) const { return cost > rhs.cost; } }; // prim // pair<double, vector<int>> prim(const vector<vector<double>> &costTable) { int N = costTable.size(); priority_queue<Path, vector<Path>, greater<Path>> q; q.push(Path(0, 0, 0)); vector<int> parent(N, -1); double totalCost = 0; while (!q.empty()) { Path cur = q.top(); q.pop(); int i = cur.to; if (parent[i] != -1) continue; parent[i] = cur.from; totalCost += cur.cost; REP(j, N) if (parent[j] == -1) q.push(Path(i, j, costTable[i][j])); } return make_pair(totalCost, parent); } // dijkstra // pair<vector<double>, vector<int>> dijkstra(const vector<vector<Path>> &routes, int start = 0, int goal = -1) { int N = routes.size(); priority_queue<Path, vector<Path>, greater<Path>> q; q.push(Path(start, start, 0)); vector<int> prev(N, -1); vector<double> cost(N, INF); while (!q.empty()) { Path cur = q.top(); q.pop(); int i = cur.to; if (prev[i] != -1) continue; prev[i] = cur.from; cost[i] = cur.cost; if (i == goal) { break; } REP(j, routes[i].size()) { Path next = Path(i, routes[i][j].to, cur.cost + routes[i][j].cost); if (prev[next.to] == -1) q.push(next); } } return make_pair(cost, prev); } //// i/o //// template <class T> class vevector : public vector<vector<T>> { public: vevector(int n = 0, int m = 0) : vector<vector<T>>(n, vector<T>(m)){}; vevector(int n, int m, const T &initial) : vector<vector<T>>(n, vector<T>(m, initial)){}; }; template <class T> T read() { T t; cin >> t; return t; } template <class T> vector<T> read(int n) { vector<T> v; REP(i, n) { v.push_back(read<T>()); } return v; } template <class T> vevector<T> read(int n, int m) { vevector<T> v; REP(i, n) v.push_back(read<T>(m)); return v; } template <class T> vevector<T> readjag(int n) { vevector<T> v; REP(i, n) v.push_back(read<T>(read<int>())); return v; } template <class T> void write(const T &t) { cout << t << endl; } template <class T> void write(const T &t, const T &t2) { cout << t << ' ' << t2 << endl; } template <class T> void write(const vector<T> &v) { ostringstream ss; for (auto x : v) ss << x << ' '; auto s = ss.str(); cout << s.substr(0, s.length() - 1) << endl; } template <class T> istream &operator>>(istream &in, complex<T> &n) { T r, i; in >> r >> i; n = complex<T>(r, i); return in; } struct _Reader { template <class T> _Reader operator,(T &rhs) { cin >> rhs; return *this; } }; #define READ(t, ...) \ t __VA_ARGS__; \ _Reader(), __VA_ARGS__ template <class InIt1, class InIt2> int partial_compare(InIt1 first1, InIt1 last1, InIt2 first2, InIt2 last2) { return lexicographical_compare(first1, last1, first2, last2) ? -1 : lexicographical_compare(first2, last2, first1, last1) ? 1 : 0; } //// start up //// void solve(); int main() { // freopen("A.in", "r", stdin); solve(); return 0; } //////////////////// /// template end /// //////////////////// void solve() { auto testcases = INF; // read<int>(); REP(testcase, testcases) { READ(int, N); if (!N) { break; } auto ps = read<P2>(N); int result = 1; REP(i_, N) FOR(j_, i_ + 1, N) { const P2 i = ps[i_], j = ps[j_]; double r = 1; if (abs(i - j) - 2 * r > -EPS) { continue; } // 遠すぎて円が作れない auto c = get_same_distance_points(i, j, r); // i と j から ちょうど r 離れた点 auto c1 = Circle(c.first, r), c2 = Circle(c.second, r); result = max<int>(result, count_if(allof(ps), [c1, r](P2 p) { return c1.Contains(p); })); result = max<int>(result, count_if(allof(ps), [c2, r](P2 p) { return c2.Contains(p); })); } write(result); } }
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 22], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13]]
1
2,904
#define _USE_MATH_DEFINES #include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <time.h> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> i_i; typedef pair<ll, int> ll_i; typedef pair<double, int> d_i; typedef pair<ll, ll> ll_ll; typedef pair<double, double> d_d; struct edge { int u, v; ll w; }; ll MOD = 1000000007; ll _MOD = 1000000009; double EPS = 1e-8; int main() { for (;;) { int N; cin >> N; if (N == 0) break; vector<double> x(N), y(N); for (int i = 0; i < N; i++) cin >> x[i] >> y[i]; int maxi = 1; for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) { if (i == j) continue; double dx = x[j] - x[i], dy = y[j] - y[i]; double d = sqrt(dx * dx + dy * dy); if (d > 2) continue; double h = sqrt(1 - d * d / 4); double ox = x[i] + dx / 2 - dy / d * h; double oy = y[i] + dy / 2 + dx / d * h; int cnt = 0; for (int k = 0; k < N; k++) { double dx = x[k] - ox, dy = y[k] - oy; double d2 = dx * dx + dy * dy; if (d <= 1 + EPS) cnt++; } maxi = max(maxi, cnt); } cout << maxi << endl; } }
#define _USE_MATH_DEFINES #include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <time.h> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> i_i; typedef pair<ll, int> ll_i; typedef pair<double, int> d_i; typedef pair<ll, ll> ll_ll; typedef pair<double, double> d_d; struct edge { int u, v; ll w; }; ll MOD = 1000000007; ll _MOD = 1000000009; double EPS = 1e-5; int main() { for (;;) { int N; cin >> N; if (N == 0) break; vector<double> x(N), y(N); for (int i = 0; i < N; i++) cin >> x[i] >> y[i]; int maxi = 1; for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) { if (i == j) continue; double dx = x[j] - x[i], dy = y[j] - y[i]; double d = sqrt(dx * dx + dy * dy); if (d > 2) continue; double h = sqrt(1 - d * d / 4); double ox = x[i] + dx / 2 - dy / d * h; double oy = y[i] + dy / 2 + dx / d * h; int cnt = 0; for (int k = 0; k < N; k++) { double dx = x[k] - ox, dy = y[k] - oy; double d2 = dx * dx + dy * dy; if (d2 <= 1 + EPS) cnt++; } maxi = max(maxi, cnt); } cout << maxi << endl; } }
[["-", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22]]
1
407
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pair<int, int>> vii; #define rrep(i, m, n) for (int(i) = (m); (i) < (n); (i)++) #define erep(i, m, n) for (int(i) = (m); (i) <= (n); (i)++) #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define rrev(i, m, n) for (int(i) = (n)-1; (i) >= (m); (i)--) #define erev(i, m, n) for (int(i) = (n); (i) >= (m); (i)--) #define rev(i, n) for (int(i) = (n)-1; (i) >= 0; (i)--) #define vrep(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++) #define ALL(v) (v).begin(), (v).end() #define mp make_pair #define pb push_back template <class T, class S> inline bool minup(T &m, S x) { return m > (T)x ? (m = (T)x, true) : false; } template <class T, class S> inline bool maxup(T &m, S x) { return m < (T)x ? (m = (T)x, true) : false; } const int INF = 1000000000; const ll MOD = 1000000007LL; const double EPS = 1E-12; template <typename T> T add(T x, T y) { if (abs(x + y) < EPS * (abs(x) + abs(y))) return 0; return x + y; } template <typename T> inline bool semieq(T x, T y) { return abs(x - y) < EPS; } template <typename T> inline bool semige(T x, T y) { return y - x < -EPS; } template <typename T> inline bool semile(T x, T y) { return x - y < -EPS; } struct Point : public complex<double> { public: Point() { this->real(0); this->imag(0); } Point(const double &x, const double &y) { this->real(x); this->imag(y); } Point(const complex<double> w) { this->real(w.real()); this->imag(w.imag()); } inline double dot(Point p) { return (conj(*this) * p).real(); } // 内積 inline double det(Point p) { return (conj(*this) * p).imag(); } // 外積 }; namespace std { inline bool operator<(const Point &a, const Point &b) { return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b); } } // namespace std typedef vector<Point> Polygon; inline Point currPoint(vector<Point> P, int i) { return P[i]; } inline Point nextPoint(vector<Point> P, int i) { return P[(i + 1) % P.size()]; } inline Point diffPoint(vector<Point> P, int i) { return nextPoint(P, i) - currPoint(P, i); } struct Circle : Point { private: Point p; double r; public: Circle(Point p, double r) : p(p), r(r) {} Circle(double x, double y, double r) : p(Point(x, y)), r(r) {} inline Point center() { return this->p; } inline double radius() { return this->r; } }; int intersectionDeterminationOfCC(Circle A, Circle B) { double d = abs(A.center() - B.center()); if (semile(d, A.radius() - B.radius())) return 1; // B in A if (semile(d, B.radius() - A.radius())) return -1; // A in B if (semieq(d, A.radius() - B.radius())) return 2; // B in A(内接) if (semieq(d, B.radius() - A.radius())) return -2; // A in B(内接) if (semige(d, A.radius() + B.radius())) return 3; // 交わらない if (semieq(d, A.radius() + B.radius())) return -3; // 外接 return 4; // 交わっている } // 交点を重複を許して丁度二つ返す。0個のときは事前に計算しておく。 vector<Point> intersectionOfCC(Circle A, Circle B) { vector<Point> ret; Point p = B.center() + A.center(); Point d = B.center() - A.center(); double m = (B.radius() + A.radius()) / abs(B.center() - A.center()); double n = (B.radius() - A.radius()) / abs(B.center() - A.center()); double s = m * n; double t = sqrt((m * m - 1.0) * (1.0 - n * n)); ret.pb((p + Point(s, -t) * d) / 2.0); ret.pb((p + Point(s, t) * d) / 2.0); return ret; } const double r = 1.0; int N; double x, y; int main() { while ((cin >> N) && N) { vector<Point> P; rep(i, N) { cin >> x >> y; P.pb(Point(x, y)); } int res = 0; rep(i, N) rep(j, i) if (!semige(abs(P[i] - P[j]), 2.0 * r)) { Circle A = Circle(P[i], r); Circle B = Circle(P[j], r); vector<Point> PP = intersectionOfCC(A, B); vrep(v, PP) { int cnt = 0; vrep(w, P) if (!semige(abs(*w - *v), r)) cnt += 1; maxup(res, cnt); } } cout << res << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pair<int, int>> vii; #define rrep(i, m, n) for (int(i) = (m); (i) < (n); (i)++) #define erep(i, m, n) for (int(i) = (m); (i) <= (n); (i)++) #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define rrev(i, m, n) for (int(i) = (n)-1; (i) >= (m); (i)--) #define erev(i, m, n) for (int(i) = (n); (i) >= (m); (i)--) #define rev(i, n) for (int(i) = (n)-1; (i) >= 0; (i)--) #define vrep(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++) #define ALL(v) (v).begin(), (v).end() #define mp make_pair #define pb push_back template <class T, class S> inline bool minup(T &m, S x) { return m > (T)x ? (m = (T)x, true) : false; } template <class T, class S> inline bool maxup(T &m, S x) { return m < (T)x ? (m = (T)x, true) : false; } const int INF = 1000000000; const ll MOD = 1000000007LL; const double EPS = 1E-12; template <typename T> T add(T x, T y) { if (abs(x + y) < EPS * (abs(x) + abs(y))) return 0; return x + y; } template <typename T> inline bool semieq(T x, T y) { return abs(x - y) < EPS; } template <typename T> inline bool semige(T x, T y) { return y - x < -EPS; } template <typename T> inline bool semile(T x, T y) { return x - y < -EPS; } struct Point : public complex<double> { public: Point() { this->real(0); this->imag(0); } Point(const double &x, const double &y) { this->real(x); this->imag(y); } Point(const complex<double> w) { this->real(w.real()); this->imag(w.imag()); } inline double dot(Point p) { return (conj(*this) * p).real(); } // 内積 inline double det(Point p) { return (conj(*this) * p).imag(); } // 外積 }; namespace std { inline bool operator<(const Point &a, const Point &b) { return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b); } } // namespace std typedef vector<Point> Polygon; inline Point currPoint(vector<Point> P, int i) { return P[i]; } inline Point nextPoint(vector<Point> P, int i) { return P[(i + 1) % P.size()]; } inline Point diffPoint(vector<Point> P, int i) { return nextPoint(P, i) - currPoint(P, i); } struct Circle : Point { private: Point p; double r; public: Circle(Point p, double r) : p(p), r(r) {} Circle(double x, double y, double r) : p(Point(x, y)), r(r) {} inline Point center() { return this->p; } inline double radius() { return this->r; } }; int intersectionDeterminationOfCC(Circle A, Circle B) { double d = abs(A.center() - B.center()); if (semile(d, A.radius() - B.radius())) return 1; // B in A if (semile(d, B.radius() - A.radius())) return -1; // A in B if (semieq(d, A.radius() - B.radius())) return 2; // B in A(内接) if (semieq(d, B.radius() - A.radius())) return -2; // A in B(内接) if (semige(d, A.radius() + B.radius())) return 3; // 交わらない if (semieq(d, A.radius() + B.radius())) return -3; // 外接 return 4; // 交わっている } // 交点を重複を許して丁度二つ返す。0個のときは事前に計算しておく。 vector<Point> intersectionOfCC(Circle A, Circle B) { vector<Point> ret; Point p = B.center() + A.center(); Point d = B.center() - A.center(); double m = (B.radius() + A.radius()) / abs(B.center() - A.center()); double n = (B.radius() - A.radius()) / abs(B.center() - A.center()); double s = m * n; double t = sqrt((m * m - 1.0) * (1.0 - n * n)); ret.pb((p + Point(s, -t) * d) / 2.0); ret.pb((p + Point(s, t) * d) / 2.0); return ret; } const double r = 1.0; int N; double x, y; int main() { while ((cin >> N) && N) { vector<Point> P; rep(i, N) { cin >> x >> y; P.pb(Point(x, y)); } int res = 1; rep(i, N) rep(j, i) if (!semige(abs(P[i] - P[j]), 2.0 * r)) { Circle A = Circle(P[i], r); Circle B = Circle(P[j], r); vector<Point> PP = intersectionOfCC(A, B); vrep(v, PP) { int cnt = 0; vrep(w, P) if (!semige(abs(*w - *v), r)) cnt += 1; maxup(res, cnt); } } cout << res << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
1
1,280
#include <algorithm> #include <array> #include <complex> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <tuple> #include <vector> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--) #define REP(i, n) for (int i = 0; i < (n); i++) #define RREP(i, n) for (int i = (n)-1; i >= 0; i--) #define ALL(u) begin(u), end(u) #define PB push_back #define LE(n, m) ((n) < (m) + EPS) #define GE(n, m) ((n) + EPS > (m)) #define EQ(n, m) (abs((n) - (m)) < EPS) typedef long long int ll; const int INF = (1 << 30) - 1; const double EPS = 1e-9; const int MOD = 1000000007; typedef double D; // ??§?¨?????????????double???long double????????? typedef complex<D> P; // Point typedef pair<P, P> L; // Line typedef vector<P> VP; #define X real() #define Y imag() // ???a??¨???b?????????????????????r???????????????????????? VP circlesPointsRadius(P a, P b, D r) { VP cs; P abH = (b - a) * 0.5; D d = abs(abH); if (d == 0 || d > r) return cs; // ???????????? !LE(d,r) ??¨?????????1??????????????´???????????? D dN = sqrt(r * r - d * d); // ???????????? max(r*r - d*d, 0) ??¨?????? P n = abH * P(0, 1) * (dN / d); cs.push_back(a + abH + n); if (dN > 0) cs.push_back(a + abH - n); return cs; } int N; // g++ -std=c++0x -msse4.2 -O3 //#include <bits/stdc++.h> int main() { ios::sync_with_stdio(false); cin.tie(0); // cout.precision(16); // cout.setf(ios::fixed); while (cin >> N, N) { vector<P> points(N); for (int i = 0; i < N; i++) { D x, y; cin >> x >> y; points[i] = P(x, y); } int ans = 0; for (int i = 0; i < N; i++) for (int j = i + 1; j < N; j++) { VP vs = circlesPointsRadius(points[i], points[j], 1); for (auto v : vs) { int tans = 0; for (auto p : points) if (LE(abs(p - v), 1)) tans++; ans = max(ans, tans); } } cout << ans << endl; } return 0; }
#include <algorithm> #include <array> #include <complex> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <tuple> #include <vector> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--) #define REP(i, n) for (int i = 0; i < (n); i++) #define RREP(i, n) for (int i = (n)-1; i >= 0; i--) #define ALL(u) begin(u), end(u) #define PB push_back #define LE(n, m) ((n) < (m) + EPS) #define GE(n, m) ((n) + EPS > (m)) #define EQ(n, m) (abs((n) - (m)) < EPS) typedef long long int ll; const int INF = (1 << 30) - 1; const double EPS = 1e-9; const int MOD = 1000000007; typedef double D; // ??§?¨?????????????double???long double????????? typedef complex<D> P; // Point typedef pair<P, P> L; // Line typedef vector<P> VP; #define X real() #define Y imag() // ???a??¨???b?????????????????????r???????????????????????? VP circlesPointsRadius(P a, P b, D r) { VP cs; P abH = (b - a) * 0.5; D d = abs(abH); if (d == 0 || d > r) return cs; // ???????????? !LE(d,r) ??¨?????????1??????????????´???????????? D dN = sqrt(r * r - d * d); // ???????????? max(r*r - d*d, 0) ??¨?????? P n = abH * P(0, 1) * (dN / d); cs.push_back(a + abH + n); if (dN > 0) cs.push_back(a + abH - n); return cs; } int N; // g++ -std=c++0x -msse4.2 -O3 //#include <bits/stdc++.h> int main() { ios::sync_with_stdio(false); cin.tie(0); // cout.precision(16); // cout.setf(ios::fixed); while (cin >> N, N) { vector<P> points(N); for (int i = 0; i < N; i++) { D x, y; cin >> x >> y; points[i] = P(x, y); } int ans = 1; for (int i = 0; i < N; i++) for (int j = i + 1; j < N; j++) { VP vs = circlesPointsRadius(points[i], points[j], 1); for (auto v : vs) { int tans = 0; for (auto p : points) if (LE(abs(p - v), 1)) tans++; ans = max(ans, tans); } } cout << ans << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
1
480
#include <algorithm> #include <array> #include <cassert> #include <climits> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define ALL(v) (v).begin(), (v).end() #define REP(i, p, n) for (int i = p; i < (int)(n); ++i) #define rep(i, n) REP(i, 0, n) #define DUMP(list) \ cout << "{ "; \ for (auto nth : list) { \ cout << nth << " "; \ } \ cout << "}" << endl #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) \ ; using namespace std; typedef double Real; const Real EPS = 1e-8; int sign(Real d) { return d > EPS ? 1 : d < -EPS ? -1 : 0; } struct Point { Real x, y; explicit Point(Real x_ = 0, Real y_ = 0) : x(x_), y(y_) {} Point operator+(const Point &p) const { return Point(x + p.x, y + p.y); } Point operator-(const Point &p) const { return Point(x - p.x, y - p.y); } Point operator*(Real s) const { return Point(x * s, y * s); } Point operator/(Real s) const { return Point(x / s, y / s); } bool operator<(const Point &p) const { return sign(x - p.x) == -1 || (sign(x - p.x) == 0 && sign(y - p.y) == -1); } bool operator==(const Point &p) const { return sign(x - p.x) == 0 && sign(y - p.y) == 0; } }; istream &operator>>(istream &is, Point &p) { return is >> p.x >> p.y; } //??\???????°??????? ostream &operator<<(ostream &os, const Point &p) { return os << '(' << p.x << ", " << p.y << ')'; } //??????????°??????? struct Segment : public array<Point, 2> { Segment(const Point &a, const Point &b) { at(0) = a; at(1) = b; } }; struct Line : public array<Point, 2> { Line(const Point &a, const Point &b) { at(0) = a; at(1) = b; } }; struct Circle { Point c; Real r; Circle(const Point &c_, Real r_) : c(c_), r(r_) {} }; typedef vector<Point> Polygon; Point rotate90(const Point &p) { return Point(-p.y, p.x); } Point rotate(const Point &p, Real theta) { const Real s = sin(theta), c = cos(theta); return Point(c * p.x - s * p.y, s * p.x + c * p.y); } Real angle(const Point &p) { return atan2(p.y, p.x); } Real dot(const Point &a, const Point &b) { //?????????????????? return a.x * b.x + a.y * b.y; } Real cross(const Point &a, const Point &b) { //?????????????????? return a.x * b.y - a.y * b.x; } Real norm(const Point &p) { return p.x * p.x + p.y * p.y; } Real abs(const Point &p) { return sqrt(norm(p)); } enum { CCW = 1, CW = -1, BACK = 2, FRONT = -2, ON = 0 }; int ccw(const Point &a, const Point &b, const Point &c) { const Point p = b - a; const Point q = c - a; const int sgn = sign(cross(p, q)); if (sgn == 1) return CCW; if (sgn == -1) return CW; if (sign(dot(p, q)) == -1) return BACK; if (sign(norm(p) - norm(q)) == -1) return FRONT; return ON; } Point project(const Line &l, const Point &p) { //?°???± Real t = dot(p - l[0], l[1] - l[0]) / norm(l[0] - l[1]); return l[0] + (l[1] - l[0]) * t; } Point refrect(const Line &l, const Point &p) { //????°? const Point c = project(l, p); return c + (c - p); } bool intersect(const Segment &a, const Segment &b) { return ccw(a[0], a[1], b[0]) * ccw(a[0], a[1], b[1]) <= 0 && ccw(b[0], b[1], a[0]) * ccw(b[0], b[1], a[1]) <= 0; } bool intersect(const Segment &s, const Point &p) { return ccw(s[0], s[1], p) == ON; } bool intersect(const Line &l, const Segment &s) { return sign(cross(l[1] - l[0], s[0] - l[0])) * cross(l[1] - l[0], s[1] - l[0]) <= 0; } bool intersect(const Line &l, const Point &p) { return abs(ccw(l[0], l[1], p)) != 1; } bool intersect(const Line &a, const Line &b) { //???????????? return sign(cross(a[1] - a[0], b[1] - b[0])) != 0 || sign(cross(a[1] - a[0], b[1] - a[0]) == 0); } Real dist(const Point &a, const Point &b) { return abs(a - b); } Real dist(const Line &l, const Point &p) { const Point a = l[1] - l[0]; const Point b = p - l[0]; return abs(cross(a, b)) / abs(a); } Real dist(const Line &l, const Segment &s) { if (intersect(l, s)) return 0; return min(dist(l, s[0]), dist(l, s[1])); } Real dist(const Line &a, const Line &b) { if (intersect(a, b)) return 0; return dist(a, b[0]); } Real dist(const Segment &s, const Point &p) { if (sign(dot(s[1] - s[0], p - s[0])) == -1) return dist(s[0], p); if (sign(dot(s[0] - s[1], p - s[1])) == -1) return dist(s[1], p); return dist(Line(s[0], s[1]), p); } Real dist(const Segment &a, const Segment &b) { if (intersect(a, b)) return 0; return min({dist(a, b[0]), dist(a, b[1]), dist(b, a[0]), dist(b, a[1])}); } bool intersect(const Circle &a, const Circle &b) { return sign(dist(a.c, b.c) - (a.r + b.r)) <= 0 && sign(dist(a.c, b.c) - abs(a.r - b.r)) >= 0; } bool intersect(const Circle &c, const Segment &s) { return sign(dist(s, c.c) - c.r) <= 0; } bool intersect(const Circle &c, const Line &l) { return sign(dist(l, c.c) - c.r) <= 0; } bool contain(const Circle &c, const Point &p) { return sign(dist(c.c, p) - c.r) <= 0; } bool contain(const Polygon &P, const Point &p) { bool res = false; for (int i = 0; i < P.size(); ++i) { Point v1 = P[i] - p; Point v2 = P[(i + 1) % P.size()] - p; if (v1.y > v2.y) swap(v1, v2); if (sign(cross(v1, v2)) == 0 && sign(dot(v1, v2)) <= 0) { return true; // on edge } if (sign(v1.y) <= 0 && sign(v2.y) == 1 && sign(cross(v1, v2)) == 1) { res = !res; } } return res; } Point crosspoint(const Line &a, const Line &b) { assert(intersect(a, b)); const Real crs = cross(a[1] - a[0], b[1] - b[0]); if (sign(crs) == 0) return a[0]; return b[0] + (b[1] - b[0]) * (cross(a[1] - a[0], a[1] - b[0]) / crs); } //??¬??¢?????????????????¨?????°?????????????????????Intersect????????? Point crosspoint(const Segment &a, const Segment &b) { assert(intersect(a, b)); const Real crs = cross(a[1] - a[0], b[1] - b[0]); if (sign(crs) == 0) { if (intersect(a, b[0])) return b[0]; if (intersect(a, b[1])) return b[1]; if (intersect(b, a[0])) return a[0]; return a[1]; } return b[0] + (b[1] - b[0]) * (cross(a[1] - a[0], a[1] - b[0]) / crs); } vector<Point> crosspoint(const Circle &c, const Line &l) { const Point p = project(l, c.c); const Real h = dist(p, c.c); vector<Point> res; if (sign(h - c.r) == 1) { // nothing } else if (sign(h - c.r) == 0) { res.emplace_back(p); } else { const Real b = sqrt(c.r * c.r - h * h); const Point e = (l[1] - l[0]) / abs(l[1] - l[0]); res.emplace_back(p + e * b); res.emplace_back(p - e * b); } return res; } vector<Point> crosspoint(const Circle &a, const Circle &b) { if (!intersect(a, b)) return vector<Point>(); vector<Point> res; const Real d = dist(a.c, b.c); if (sign(d - (a.r + b.r)) == 0) { const Point v = b.c - a.c; res.emplace_back(a.c + (v * (a.r / abs(v)))); } else { const Real theta = acos((a.r * a.r + d * d - b.r * b.r) / (2 * a.r * d)); const Real phi = angle(b.c - a.c); res.emplace_back(a.c + rotate(Point(a.r, 0), phi + theta)); res.emplace_back(a.c + rotate(Point(a.r, 0), phi - theta)); } return res; } Real area(const Polygon &P) { Real res = 0.0; for (int i = 0; i < P.size(); ++i) { res += cross(P[i], P[(i + 1) % P.size()]); } return abs(res) * 0.5; } int main() { while (1) { int n; cin >> n; if (n == 0) break; vector<Circle> circles; vector<Circle> ccircles; rep(i, n) { Point p; cin >> p; circles.push_back(Circle(p, 1.0)); } //??????????±??????? rep(i, n) for (int j = i + 1; j < n; j++) { vector<Point> points = crosspoint(circles[i], circles[j]); rep(k, points.size()) { ccircles.push_back(Circle(points[k], 1.0)); } } int ans = 0; vector<Point> points; //??????????????§??°???????????§???????????? rep(i, ccircles.size()) { int cnt = 0; rep(j, n) { if (contain(ccircles[i], circles[j].c)) { cnt++; } } ans = max(cnt, ans); } cout << ans << endl; } return 0; }
#include <algorithm> #include <array> #include <cassert> #include <climits> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define ALL(v) (v).begin(), (v).end() #define REP(i, p, n) for (int i = p; i < (int)(n); ++i) #define rep(i, n) REP(i, 0, n) #define DUMP(list) \ cout << "{ "; \ for (auto nth : list) { \ cout << nth << " "; \ } \ cout << "}" << endl #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) \ ; using namespace std; typedef double Real; const Real EPS = 1e-8; int sign(Real d) { return d > EPS ? 1 : d < -EPS ? -1 : 0; } struct Point { Real x, y; explicit Point(Real x_ = 0, Real y_ = 0) : x(x_), y(y_) {} Point operator+(const Point &p) const { return Point(x + p.x, y + p.y); } Point operator-(const Point &p) const { return Point(x - p.x, y - p.y); } Point operator*(Real s) const { return Point(x * s, y * s); } Point operator/(Real s) const { return Point(x / s, y / s); } bool operator<(const Point &p) const { return sign(x - p.x) == -1 || (sign(x - p.x) == 0 && sign(y - p.y) == -1); } bool operator==(const Point &p) const { return sign(x - p.x) == 0 && sign(y - p.y) == 0; } }; istream &operator>>(istream &is, Point &p) { return is >> p.x >> p.y; } //??\???????°??????? ostream &operator<<(ostream &os, const Point &p) { return os << '(' << p.x << ", " << p.y << ')'; } //??????????°??????? struct Segment : public array<Point, 2> { Segment(const Point &a, const Point &b) { at(0) = a; at(1) = b; } }; struct Line : public array<Point, 2> { Line(const Point &a, const Point &b) { at(0) = a; at(1) = b; } }; struct Circle { Point c; Real r; Circle(const Point &c_, Real r_) : c(c_), r(r_) {} }; typedef vector<Point> Polygon; Point rotate90(const Point &p) { return Point(-p.y, p.x); } Point rotate(const Point &p, Real theta) { const Real s = sin(theta), c = cos(theta); return Point(c * p.x - s * p.y, s * p.x + c * p.y); } Real angle(const Point &p) { return atan2(p.y, p.x); } Real dot(const Point &a, const Point &b) { //?????????????????? return a.x * b.x + a.y * b.y; } Real cross(const Point &a, const Point &b) { //?????????????????? return a.x * b.y - a.y * b.x; } Real norm(const Point &p) { return p.x * p.x + p.y * p.y; } Real abs(const Point &p) { return sqrt(norm(p)); } enum { CCW = 1, CW = -1, BACK = 2, FRONT = -2, ON = 0 }; int ccw(const Point &a, const Point &b, const Point &c) { const Point p = b - a; const Point q = c - a; const int sgn = sign(cross(p, q)); if (sgn == 1) return CCW; if (sgn == -1) return CW; if (sign(dot(p, q)) == -1) return BACK; if (sign(norm(p) - norm(q)) == -1) return FRONT; return ON; } Point project(const Line &l, const Point &p) { //?°???± Real t = dot(p - l[0], l[1] - l[0]) / norm(l[0] - l[1]); return l[0] + (l[1] - l[0]) * t; } Point refrect(const Line &l, const Point &p) { //????°? const Point c = project(l, p); return c + (c - p); } bool intersect(const Segment &a, const Segment &b) { return ccw(a[0], a[1], b[0]) * ccw(a[0], a[1], b[1]) <= 0 && ccw(b[0], b[1], a[0]) * ccw(b[0], b[1], a[1]) <= 0; } bool intersect(const Segment &s, const Point &p) { return ccw(s[0], s[1], p) == ON; } bool intersect(const Line &l, const Segment &s) { return sign(cross(l[1] - l[0], s[0] - l[0])) * cross(l[1] - l[0], s[1] - l[0]) <= 0; } bool intersect(const Line &l, const Point &p) { return abs(ccw(l[0], l[1], p)) != 1; } bool intersect(const Line &a, const Line &b) { //???????????? return sign(cross(a[1] - a[0], b[1] - b[0])) != 0 || sign(cross(a[1] - a[0], b[1] - a[0]) == 0); } Real dist(const Point &a, const Point &b) { return abs(a - b); } Real dist(const Line &l, const Point &p) { const Point a = l[1] - l[0]; const Point b = p - l[0]; return abs(cross(a, b)) / abs(a); } Real dist(const Line &l, const Segment &s) { if (intersect(l, s)) return 0; return min(dist(l, s[0]), dist(l, s[1])); } Real dist(const Line &a, const Line &b) { if (intersect(a, b)) return 0; return dist(a, b[0]); } Real dist(const Segment &s, const Point &p) { if (sign(dot(s[1] - s[0], p - s[0])) == -1) return dist(s[0], p); if (sign(dot(s[0] - s[1], p - s[1])) == -1) return dist(s[1], p); return dist(Line(s[0], s[1]), p); } Real dist(const Segment &a, const Segment &b) { if (intersect(a, b)) return 0; return min({dist(a, b[0]), dist(a, b[1]), dist(b, a[0]), dist(b, a[1])}); } bool intersect(const Circle &a, const Circle &b) { return sign(dist(a.c, b.c) - (a.r + b.r)) <= 0 && sign(dist(a.c, b.c) - abs(a.r - b.r)) >= 0; } bool intersect(const Circle &c, const Segment &s) { return sign(dist(s, c.c) - c.r) <= 0; } bool intersect(const Circle &c, const Line &l) { return sign(dist(l, c.c) - c.r) <= 0; } bool contain(const Circle &c, const Point &p) { return sign(dist(c.c, p) - c.r) <= 0; } bool contain(const Polygon &P, const Point &p) { bool res = false; for (int i = 0; i < P.size(); ++i) { Point v1 = P[i] - p; Point v2 = P[(i + 1) % P.size()] - p; if (v1.y > v2.y) swap(v1, v2); if (sign(cross(v1, v2)) == 0 && sign(dot(v1, v2)) <= 0) { return true; // on edge } if (sign(v1.y) <= 0 && sign(v2.y) == 1 && sign(cross(v1, v2)) == 1) { res = !res; } } return res; } Point crosspoint(const Line &a, const Line &b) { assert(intersect(a, b)); const Real crs = cross(a[1] - a[0], b[1] - b[0]); if (sign(crs) == 0) return a[0]; return b[0] + (b[1] - b[0]) * (cross(a[1] - a[0], a[1] - b[0]) / crs); } //??¬??¢?????????????????¨?????°?????????????????????Intersect????????? Point crosspoint(const Segment &a, const Segment &b) { assert(intersect(a, b)); const Real crs = cross(a[1] - a[0], b[1] - b[0]); if (sign(crs) == 0) { if (intersect(a, b[0])) return b[0]; if (intersect(a, b[1])) return b[1]; if (intersect(b, a[0])) return a[0]; return a[1]; } return b[0] + (b[1] - b[0]) * (cross(a[1] - a[0], a[1] - b[0]) / crs); } vector<Point> crosspoint(const Circle &c, const Line &l) { const Point p = project(l, c.c); const Real h = dist(p, c.c); vector<Point> res; if (sign(h - c.r) == 1) { // nothing } else if (sign(h - c.r) == 0) { res.emplace_back(p); } else { const Real b = sqrt(c.r * c.r - h * h); const Point e = (l[1] - l[0]) / abs(l[1] - l[0]); res.emplace_back(p + e * b); res.emplace_back(p - e * b); } return res; } vector<Point> crosspoint(const Circle &a, const Circle &b) { if (!intersect(a, b)) return vector<Point>(); vector<Point> res; const Real d = dist(a.c, b.c); if (sign(d - (a.r + b.r)) == 0) { const Point v = b.c - a.c; res.emplace_back(a.c + (v * (a.r / abs(v)))); } else { const Real theta = acos((a.r * a.r + d * d - b.r * b.r) / (2 * a.r * d)); const Real phi = angle(b.c - a.c); res.emplace_back(a.c + rotate(Point(a.r, 0), phi + theta)); res.emplace_back(a.c + rotate(Point(a.r, 0), phi - theta)); } return res; } Real area(const Polygon &P) { Real res = 0.0; for (int i = 0; i < P.size(); ++i) { res += cross(P[i], P[(i + 1) % P.size()]); } return abs(res) * 0.5; } int main() { while (1) { int n; cin >> n; if (n == 0) break; vector<Circle> circles; vector<Circle> ccircles; rep(i, n) { Point p; cin >> p; circles.push_back(Circle(p, 1.0)); } //??????????±??????? rep(i, n) for (int j = i + 1; j < n; j++) { vector<Point> points = crosspoint(circles[i], circles[j]); rep(k, points.size()) { ccircles.push_back(Circle(points[k], 1.0)); } } int ans = 1; vector<Point> points; //??????????????§??°???????????§???????????? rep(i, ccircles.size()) { int cnt = 0; rep(j, n) { if (contain(ccircles[i], circles[j].c)) { cnt++; } } ans = max(cnt, ans); } cout << ans << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
1
2,907
#include <algorithm> #include <array> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <unordered_map> #include <unordered_set> #include <valarray> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double R; typedef complex<R> P; const R EPS = 1e-10; const R PI = acos((R)(-1)); R radNorP(R x) { return fmod(fmod(x, 2 * PI) + 2 * PI, 2 * PI); } const int MN = 330; P p[MN]; typedef pair<R, int> Pi; bool solve() { int n; cin >> n; if (!n) return false; for (int i = 0; i < n; i++) { R x, y; cin >> x >> y; p[i] = P(x, y); } int res = 0; for (int i = 0; i < n; i++) { vector<Pi> v; for (int j = 0; j < n; j++) { if (i == j) continue; if (2.0 < abs(p[j] - p[i])) continue; R th = acos(abs(p[j] - p[i]) / 2.0); R l = radNorP(arg(p[j] - p[i]) - th); R r = radNorP(arg(p[j] - p[i]) + th); if (r < l) { v.push_back(Pi(l - EPS, 1)); v.push_back(Pi(2 * PI + EPS, -1)); v.push_back(Pi(0 - EPS, 1)); v.push_back(Pi(r + EPS, -1)); } else { v.push_back(Pi(l - EPS, 1)); v.push_back(Pi(r + EPS, -1)); } } sort(v.begin(), v.end()); int sm = 1; for (Pi p : v) { sm += p.second; res = max(res, sm); } } cout << res << endl; return true; } int main() { while (solve()) { } return 0; }
#include <algorithm> #include <array> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <unordered_map> #include <unordered_set> #include <valarray> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double R; typedef complex<R> P; const R EPS = 1e-10; const R PI = acos((R)(-1)); R radNorP(R x) { return fmod(fmod(x, 2 * PI) + 2 * PI, 2 * PI); } const int MN = 330; P p[MN]; typedef pair<R, int> Pi; bool solve() { int n; cin >> n; if (!n) return false; for (int i = 0; i < n; i++) { R x, y; cin >> x >> y; p[i] = P(x, y); } int res = 1; for (int i = 0; i < n; i++) { vector<Pi> v; for (int j = 0; j < n; j++) { if (i == j) continue; if (2.0 < abs(p[j] - p[i])) continue; R th = acos(abs(p[j] - p[i]) / 2.0); R l = radNorP(arg(p[j] - p[i]) - th - EPS); R r = radNorP(arg(p[j] - p[i]) + th + EPS); if (r < l) { v.push_back(Pi(l - EPS, 1)); v.push_back(Pi(2 * PI + EPS, -1)); v.push_back(Pi(0 - EPS, 1)); v.push_back(Pi(r + EPS, -1)); } else { v.push_back(Pi(l - EPS, 1)); v.push_back(Pi(r + EPS, -1)); } } sort(v.begin(), v.end()); int sm = 1; for (Pi p : v) { sm += p.second; res = max(res, sm); } } cout << res << endl; return true; } int main() { while (solve()) { } return 0; }
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 49, 50, 51, 2, 3, 4, 0, 16, 17, 33], ["+", 49, 50, 51, 2, 3, 4, 0, 16, 12, 22], ["+", 49, 50, 51, 2, 3, 4, 0, 16, 17, 72]]
1
489
#include <algorithm> #include <cmath> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <utility> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) typedef long long ll; typedef pair<int, int> pii; const double EPS = 1e-6; int main() { int n; while (cin >> n, n) { double x[n], y[n]; rep(i, n) { cin >> x[i] >> y[i]; } int maxi = 0; rep(i, n) { for (int j = i + 1; j < n; j++) { if (((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j])) > 4.0) continue; double mx = (x[i] + x[j]) / 2.0; double my = (y[i] + y[j]) / 2.0; double px0, py0, px1, py1; if (fabs(y[i] - y[j]) < EPS) { px0 = px1 = mx; py0 = my + sqrt(1.0 - (x[i] - mx) * (x[i] - mx)); py1 = my - sqrt(1.0 - (x[i] - mx) * (x[i] - mx)); } else if (fabs(x[i] - x[j]) < EPS) { py0 = py1 = my; px0 = mx + sqrt(1.0 - (y[i] - my) * (y[i] - my)); px1 = mx - sqrt(1.0 - (y[i] - my) * (y[i] - my)); } else { double m = -(x[i] - x[j]) / (y[i] - y[j]); double l = sqrt( 1.0 - ((x[i] - mx) * (x[i] - mx) + (y[i] - my) * (y[i] - my))); px0 = mx + sqrt(l * l / (1.0 + m * m)); px1 = mx - sqrt(l * l / (1.0 + m * m)); py0 = my + m * (px0 - mx); py1 = my + m * (px1 - mx); } int cnt0 = 0, cnt1 = 0; rep(k, n) { double d0 = (px0 - x[k]) * (px0 - x[k]) + (py0 - y[k]) * (py0 - y[k]); if (d0 <= 1.0 + EPS) { cnt0++; } } rep(k, n) { double d1 = (px1 - x[k]) * (px1 - x[k]) + (py1 - y[k]) * (py1 - y[k]); if (d1 <= 1.0 + EPS) { cnt1++; } } maxi = max(maxi, cnt0); maxi = max(maxi, cnt1); } } cout << maxi << endl; } return 0; }
#include <algorithm> #include <cmath> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <utility> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) typedef long long ll; typedef pair<int, int> pii; const double EPS = 1e-6; int main() { int n; while (cin >> n, n) { double x[n], y[n]; rep(i, n) { cin >> x[i] >> y[i]; } int maxi = 1; rep(i, n) { for (int j = i + 1; j < n; j++) { if (((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j])) > 4.0) continue; double mx = (x[i] + x[j]) / 2.0; double my = (y[i] + y[j]) / 2.0; double px0, py0, px1, py1; if (fabs(y[i] - y[j]) < EPS) { px0 = px1 = mx; py0 = my + sqrt(1.0 - (x[i] - mx) * (x[i] - mx)); py1 = my - sqrt(1.0 - (x[i] - mx) * (x[i] - mx)); } else if (fabs(x[i] - x[j]) < EPS) { py0 = py1 = my; px0 = mx + sqrt(1.0 - (y[i] - my) * (y[i] - my)); px1 = mx - sqrt(1.0 - (y[i] - my) * (y[i] - my)); } else { double m = -(x[i] - x[j]) / (y[i] - y[j]); double l = sqrt( 1.0 - ((x[i] - mx) * (x[i] - mx) + (y[i] - my) * (y[i] - my))); px0 = mx + sqrt(l * l / (1.0 + m * m)); px1 = mx - sqrt(l * l / (1.0 + m * m)); py0 = my + m * (px0 - mx); py1 = my + m * (px1 - mx); } int cnt0 = 0, cnt1 = 0; rep(k, n) { double d0 = (px0 - x[k]) * (px0 - x[k]) + (py0 - y[k]) * (py0 - y[k]); if (d0 <= 1.0 + EPS) { cnt0++; } } rep(k, n) { double d1 = (px1 - x[k]) * (px1 - x[k]) + (py1 - y[k]) * (py1 - y[k]); if (d1 <= 1.0 + EPS) { cnt1++; } } maxi = max(maxi, cnt0); maxi = max(maxi, cnt1); } } cout << maxi << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
1
686
#include <bits/stdc++.h> #define _ \ ios_base::sync_with_stdio(0); \ cin.tie(0); #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define REPP(i, j, n) for (int i = (j); i < (int)(n); i++) using namespace std; typedef long double ld; typedef complex<ld> Point; const ld eps = 1e-5, pi = acos(-1.0); ld dot(Point a, Point b) { return real(conj(a) * b); } ld cross(Point a, Point b) { return imag(conj(a) * b); } Point p[310]; int n; void solve() { int result = 1; REP(i, n) { REPP(j, i + 1, n) { Point ab = p[j] - p[i]; if (norm(ab) > 4) continue; Point q = (p[i] + p[j]) / 2.L; Point aq = q - p[j]; Point normal = Point{imag(aq), -real(aq)} * sqrt(1 - norm(aq)) / abs(aq); Point c = q + normal; Point d = q - normal; int cntc = 0, cntd = 0; REP(k, n) { if (norm(p[k] - c) <= 1.L) cntc++; if (norm(p[k] - d) <= 1.L) cntd++; } result = max({result, 2, cntc, cntd}); } } cout << result << endl; } int main() { _; ld r, i; while (cin >> n, n != 0) { REP(j, n) { cin >> r >> i; p[j] = Point{r, i}; } solve(); } }
#include <bits/stdc++.h> #define _ \ ios_base::sync_with_stdio(0); \ cin.tie(0); #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define REPP(i, j, n) for (int i = (j); i < (int)(n); i++) using namespace std; typedef long double ld; typedef complex<ld> Point; const ld eps = 1e-5, pi = acos(-1.0); ld dot(Point a, Point b) { return real(conj(a) * b); } ld cross(Point a, Point b) { return imag(conj(a) * b); } Point p[310]; int n; void solve() { int result = 1; REP(i, n) { REPP(j, i + 1, n) { Point ab = p[j] - p[i]; if (norm(ab) > 4) continue; Point q = (p[i] + p[j]) / 2.L; Point aq = q - p[j]; Point normal = Point{imag(aq), -real(aq)} * sqrt(1 - norm(aq)) / abs(aq); Point c = q + normal; Point d = q - normal; int cntc = 0, cntd = 0; REP(k, n) { if (norm(p[k] - c) <= 1.0001L) cntc++; if (norm(p[k] - d) <= 1.0001L) cntd++; } result = max({result, 2, cntc, cntd}); } } cout << result << endl; } int main() { _; ld r, i; while (cin >> n, n != 0) { REP(j, n) { cin >> r >> i; p[j] = Point{r, i}; } solve(); } }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
1
362
#include <algorithm> #include <array> #include <assert.h> #include <bitset> #include <complex> #include <cstdlib> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <stdio.h> #include <string.h> #include <string> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(x) (x).begin(), (x).end() /* 幾何の基本 */ typedef long double ld; typedef complex<ld> Point; const ld eps = 1e-9, pi = acos(-1.0); namespace std { bool operator<(const Point &lhs, const Point &rhs) { if (lhs.real() < rhs.real() - eps) return true; if (lhs.real() > rhs.real() + eps) return false; return lhs.imag() < rhs.imag(); } } // namespace std // 点の入力 Point input_point() { ld x, y; cin >> x >> y; return Point(x, y); } // 誤差つき等号判定 bool eq(ld a, ld b) { return (abs(a - b) < eps); } // 内積 ld dot(Point a, Point b) { return real(conj(a) * b); } // 外積 ld cross(Point a, Point b) { return imag(conj(a) * b); } // 直線の定義 class Line { public: Point a, b; Line() : a(Point(0, 0)), b(Point(0, 0)) {} Line(Point a, Point b) : a(a), b(b) {} Point operator[](const int _num) { if (_num == 0) return a; else if (_num == 1) return b; else assert(false); } }; // 円の定義 class Circle { public: Point p; ld r; Circle() : p(Point(0, 0)), r(0) {} Circle(Point p, ld r) : p(p), r(r) {} }; // CCW int ccw(Point a, Point b, Point c) { b -= a; c -= a; if (cross(b, c) > eps) return 1; // a,b,cが反時計周りの順に並ぶ if (cross(b, c) < -eps) return -1; // a,b,cが時計周りの順に並ぶ if (dot(b, c) < 0) return 2; // c,a,bの順に直線に並ぶ if (norm(b) < norm(c)) return -2; // a,b,cの順に直線に並ぶ return 0; // a,c,bの順に直線に並ぶ } /* 交差判定 */ // 直線と直線の交差判定 bool isis_ll(Line l, Line m) { return !eq(cross(l.b - l.a, m.b - m.a), 0); } // 直線と線分の交差判定 bool isis_ls(Line l, Line s) { return isis_ll(l, s) && (cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) < eps); } // 線分と線分の交差判定 bool isis_ss(Line s, Line t) { return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0 && ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0; } // 点の直線上判定 bool isis_lp(Line l, Point p) { return (abs(cross(l.b - p, l.a - p)) < eps); } // 点の線分上判定 bool isis_sp(Line s, Point p) { return (abs(s.a - p) + abs(s.b - p) - abs(s.b - s.a) < eps); } // 垂線の足 Point proj(Line l, Point p) { ld t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b); return l.a + t * (l.a - l.b); } // 直線と直線の交点 Point is_ll(Line s, Line t) { Point sv = s.b - s.a, tv = t.b - t.a; assert(cross(sv, tv) != 0); return s.a + sv * cross(tv, t.a - s.a) / cross(tv, sv); } // 直線と点の距離 ld dist_lp(Line l, Point p) { return abs(p - proj(l, p)); } // 直線と直線の距離 ld dist_ll(Line l, Line m) { return isis_ll(l, m) ? 0 : dist_lp(l, m.a); } // 直線と線分の距離 ld dist_ls(Line l, Line s) { return isis_ls(l, s) ? 0 : min(dist_lp(l, s.a), dist_lp(l, s.b)); } // 線分と点の距離 ld dist_sp(Line s, Point p) { Point r = proj(s, p); return isis_sp(s, r) ? abs(r - p) : min(abs(s.a - p), abs(s.b - p)); } // 線分と線分の距離 ld dist_ss(Line s, Line t) { if (isis_ss(s, t)) return 0; return min( {dist_sp(s, t.a), dist_sp(s, t.b), dist_sp(t, s.a), dist_sp(t, s.b)}); } /* 円 */ // 円と円の交点 vector<Point> is_cc(Circle c1, Circle c2) { vector<Point> res; ld d = abs(c1.p - c2.p); ld rc = (d * d + c1.r * c1.r - c2.r * c2.r) / (2 * d); ld dfr = c1.r * c1.r - rc * rc; if (abs(dfr) < eps) dfr = 0.0; else if (dfr < 0.0) return res; // no intersection ld rs = sqrt(dfr); Point diff = (c2.p - c1.p) / d; res.push_back(c1.p + diff * Point(rc, rs)); if (dfr != 0.0) res.push_back(c1.p + diff * Point(rc, -rs)); return res; } // 円と直線の交点 vector<Point> is_lc(Circle c, Line l) { vector<Point> res; ld d = dist_lp(l, c.p); if (d < c.r + eps) { ld len = (d > c.r) ? 0.0 : sqrt(c.r * c.r - d * d); // safety; Point nor = (l.a - l.b) / abs(l.a - l.b); res.push_back(proj(l, c.p) + len * nor); res.push_back(proj(l, c.p) - len * nor); } return res; } // 円と線分の距離 vector<Point> is_sc(Circle c, Line l) { vector<Point> v = is_lc(c, l), res; for (Point p : v) if (isis_sp(l, p)) res.push_back(p); return res; } // 円と点の接線 vector<Line> tangent_cp(Circle c, Point p) { vector<Line> ret; Point v = c.p - p; ld d = abs(v); ld l = sqrt(norm(v) - c.r * c.r); if (isnan(l)) { return ret; } Point v1 = v * Point(l / d, c.r / d); Point v2 = v * Point(l / d, -c.r / d); ret.push_back(Line(p, p + v1)); if (l < eps) return ret; ret.push_back(Line(p, p + v2)); return ret; } // 円と円の接線 vector<Line> tangent_cc(Circle c1, Circle c2) { vector<Line> ret; if (abs(c1.p - c2.p) - (c1.r + c2.r) > -eps) { Point center = (c1.p * c2.r + c2.p * c1.r) / (c1.r + c2.r); ret = tangent_cp(c1, center); } if (abs(c1.r - c2.r) > eps) { Point out = (-c1.p * c2.r + c2.p * c1.r) / (c1.r - c2.r); vector<Line> nret = tangent_cp(c1, out); ret.insert(ret.end(), ALL(nret)); } else { Point v = c2.p - c1.p; v /= abs(v); Point q1 = c1.p + v * Point(0, 1) * c1.r; Point q2 = c1.p + v * Point(0, -1) * c1.r; ret.push_back(Line(q1, q1 + v)); ret.push_back(Line(q2, q2 + v)); } return ret; } /* 多角形 */ typedef vector<Point> Polygon; // 面積 ld area(const Polygon &p) { ld res = 0; int n = p.size(); REP(j, n) res += cross(p[j], p[(j + 1) % n]); return res / 2; } // 多角形の回転方向 bool is_counter_clockwise(const Polygon &poly) { ld angle = 0; int n = poly.size(); REP(i, n) { Point a = poly[i], b = poly[(i + 1) % n], c = poly[(i + 2) % n]; angle += arg((c - b) / (b - a)); } return angle > eps; } // 円の内外判定 // -1 => out // 0 => on // 1 => in int is_in_polygon(const Polygon &poly, Point p) { ld angle = 0; int n = poly.size(); REP(i, n) { Point a = poly[i], b = poly[(i + 1) % n]; if (isis_sp(Line(a, b), p)) return 1; angle += arg((b - p) / (a - p)); } return eq(angle, 0) ? 0 : 2; } // 凸包 Polygon convex_hull(vector<Point> ps) { int n = ps.size(); int k = 0; sort(ps.begin(), ps.end()); Polygon ch(2 * n); for (int i = 0; i < n; ch[k++] = ps[i++]) while (k >= 2 && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k; for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = ps[i--]) while (k >= t && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k; ch.resize(k - 1); return ch; } // 凸カット Polygon convex_cut(const Polygon &ps, Line l) { int n = ps.size(); Polygon Q; REP(i, n) { Point A = ps[i], B = ps[(i + 1) % n]; Line m = Line(A, B); if (ccw(l.a, l.b, A) != -1) Q.push_back(A); if (ccw(l.a, l.b, A) * ccw(l.a, l.b, B) < 0 && isis_ll(l, m)) Q.push_back(is_ll(l, m)); } return Q; } /* アレンジメント */ void add_point(vector<Point> &ps, Point p) { for (Point q : ps) if (abs(q - p) < eps) return; ps.push_back(p); } typedef int Weight; struct Edge { int from, to; Weight weight; }; typedef vector<Edge> Edges; typedef vector<Edges> Graph; void add_edge(Graph &g, int from, int to, Weight weight) { g[from].push_back(Edge{from, to, weight}); } Graph segment_arrangement(const vector<Line> &s, const vector<Point> &p) { int n = p.size(), m = s.size(); Graph g(n); REP(i, m) { vector<pair<ld, int>> vec; REP(j, n) if (isis_sp(s[i], p[j])) vec.emplace_back(abs(s[i].a - p[j]), j); sort(ALL(vec)); REP(j, vec.size() - 1) { int from = vec[j].second, to = vec[j + 1].second; add_edge(g, from, to, abs(p[from] - p[to])); } } return g; } Graph circle_arrangement(const vector<Circle> &c, const vector<Point> &p) { int n = p.size(), m = c.size(); Graph g(n); REP(i, m) { vector<pair<ld, int>> vec; REP(j, n) if (abs(abs(c[i].p - p[j]) - c[i].r) < eps) vec.emplace_back(arg(c[i].p - p[j]), j); sort(ALL(vec)); REP(j, vec.size() - 1) { int from = vec[j].second, to = vec[j + 1].second; ld angle = vec[j + 1].first - vec[j].first; add_edge(g, from, to, angle * c[i].r); } if (vec.size() >= 2) { int from = vec.back().second, to = vec.front().first; ld angle = vec.front().first - vec.back().first; add_edge(g, from, to, angle * c[i].r); } } return g; } /* 双対グラフ */ // 線分集合は既にアレンジメントされていなければならない. // 内側の円は時計回りで,外側の円は反時計回りで得られる. // 変数 polygon は,vector<int> で表される多角形の集合であり, // vector<int> で表される // 多角形のi番目は,その頂点の頂点集合pにおける番号である. vector<vector<int>> polygon; vector<int> seg2p[1024][1024]; Graph dual_graph(const vector<Line> &s, const vector<Point> &p) { int N = p.size(); polygon.clear(); REP(i, 1024) REP(j, 1024) seg2p[i][j].clear(); vector<vector<tuple<ld, int, bool>>> tup(N); REP(i, s.size()) { int a = -1, b = -1; REP(j, N) if (abs(s[i].a - p[j]) < eps) a = j; REP(j, N) if (abs(s[i].b - p[j]) < eps) b = j; assert(a >= 0 && b >= 0); tup[a].emplace_back(arg(s[i].b - s[i].a), b, false); tup[b].emplace_back(arg(s[i].a - s[i].b), a, false); } REP(i, N) sort(ALL(tup[i])); REP(i, N) { REP(j, tup[i].size()) { ld angle; int pos = j, from = i, to; bool flag; tie(angle, to, flag) = tup[i][j]; if (flag) continue; vector<int> ps; while (!flag) { ps.push_back(from); get<2>(tup[from][pos]) = true; seg2p[from][to].push_back(polygon.size()); seg2p[to][from].push_back(polygon.size()); angle += pi + eps; if (angle > pi) angle -= 2 * pi; auto it = lower_bound(ALL(tup[to]), make_tuple(angle, 0, false)); if (it == tup[to].end()) it = tup[to].begin(); from = to; tie(angle, to, flag) = *it; pos = it - tup[from].begin(); } polygon.push_back(ps); } } Graph g(polygon.size()); REP(i, N) REP(j, i) { if (seg2p[i][j].size() == 2) { int from = seg2p[i][j][0], to = seg2p[i][j][1]; g[from].push_back(Edge{from, to}); g[to].push_back(Edge{to, from}); } } return g; } /* ビジュアライザ */ const ld zoom = 25; const ld centerX = 6; const ld centerY = 5; void change_color(int r, int g, int b) { fprintf(stderr, "c.strokeStyle = 'rgb(%d, %d, %d)';\n", r, g, b); } int cordx(Point p) { return 400 + zoom * (p.real() - centerX); } int cordy(Point p) { return 400 - zoom * (p.imag() - centerY); } #define cord(p) cordx(p), cordy(p) void draw_point(Point p) { fprintf(stderr, "circle(%d, %d, %d)\n", cord(p), 2); } void draw_segment(Line l) { fprintf(stderr, "line(%d, %d, %d, %d)\n", cord(l.a), cord(l.b)); } void draw_line(Line l) { Point v = l.b - l.a; Line m(l.a - v * Point(1e4, 0), l.b + v * Point(1e4, 0)); fprintf(stderr, "line(%d, %d, %d, %d)\n", cord(m.a), cord(m.b)); } void draw_polygon(const Polygon &p) { int n = p.size(); REP(i, n) draw_segment(Line(p[i], p[(i + 1) % n])); } void draw_circle(Circle c) { fprintf(stderr, "circle(%d, %d, %d)\n", cord(c.p), (int)(zoom * c.r)); } vector<Point> ps; int check(Point &center) { int num = 0; for (int i = 0; i < ps.size(); ++i) { if (abs(ps[i] - center) <= 1) { num++; } } return num; } int main() { while (1) { int N; cin >> N; if (!N) break; ps.clear(); for (int i = 0; i < N; ++i) { long double x, y; cin >> x >> y; ps.push_back({x, y}); } int ans = 0; for (int i = 0; i < N; ++i) { for (int j = i + 1; j < N; ++j) { if (abs(ps[i] - ps[j]) > 2) continue; Line l(ps[i], ps[j]); Point center = (ps[i] + ps[j]) * 0.5l; Point vec(imag(ps[i] - ps[j]), -real(ps[i] - ps[j])); long double nl = sqrt(0.9999999 - norm(center - ps[i])); long double oldl = abs(vec); vec *= nl / oldl; Point checkcenter = center + vec; ans = max(ans, check(checkcenter)); checkcenter = center - vec; ans = max(ans, check(checkcenter)); } } cout << ans << endl; } return 0; }
#include <algorithm> #include <array> #include <assert.h> #include <bitset> #include <complex> #include <cstdlib> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <stdio.h> #include <string.h> #include <string> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(x) (x).begin(), (x).end() /* 幾何の基本 */ typedef long double ld; typedef complex<ld> Point; const ld eps = 1e-9, pi = acos(-1.0); namespace std { bool operator<(const Point &lhs, const Point &rhs) { if (lhs.real() < rhs.real() - eps) return true; if (lhs.real() > rhs.real() + eps) return false; return lhs.imag() < rhs.imag(); } } // namespace std // 点の入力 Point input_point() { ld x, y; cin >> x >> y; return Point(x, y); } // 誤差つき等号判定 bool eq(ld a, ld b) { return (abs(a - b) < eps); } // 内積 ld dot(Point a, Point b) { return real(conj(a) * b); } // 外積 ld cross(Point a, Point b) { return imag(conj(a) * b); } // 直線の定義 class Line { public: Point a, b; Line() : a(Point(0, 0)), b(Point(0, 0)) {} Line(Point a, Point b) : a(a), b(b) {} Point operator[](const int _num) { if (_num == 0) return a; else if (_num == 1) return b; else assert(false); } }; // 円の定義 class Circle { public: Point p; ld r; Circle() : p(Point(0, 0)), r(0) {} Circle(Point p, ld r) : p(p), r(r) {} }; // CCW int ccw(Point a, Point b, Point c) { b -= a; c -= a; if (cross(b, c) > eps) return 1; // a,b,cが反時計周りの順に並ぶ if (cross(b, c) < -eps) return -1; // a,b,cが時計周りの順に並ぶ if (dot(b, c) < 0) return 2; // c,a,bの順に直線に並ぶ if (norm(b) < norm(c)) return -2; // a,b,cの順に直線に並ぶ return 0; // a,c,bの順に直線に並ぶ } /* 交差判定 */ // 直線と直線の交差判定 bool isis_ll(Line l, Line m) { return !eq(cross(l.b - l.a, m.b - m.a), 0); } // 直線と線分の交差判定 bool isis_ls(Line l, Line s) { return isis_ll(l, s) && (cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) < eps); } // 線分と線分の交差判定 bool isis_ss(Line s, Line t) { return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0 && ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0; } // 点の直線上判定 bool isis_lp(Line l, Point p) { return (abs(cross(l.b - p, l.a - p)) < eps); } // 点の線分上判定 bool isis_sp(Line s, Point p) { return (abs(s.a - p) + abs(s.b - p) - abs(s.b - s.a) < eps); } // 垂線の足 Point proj(Line l, Point p) { ld t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b); return l.a + t * (l.a - l.b); } // 直線と直線の交点 Point is_ll(Line s, Line t) { Point sv = s.b - s.a, tv = t.b - t.a; assert(cross(sv, tv) != 0); return s.a + sv * cross(tv, t.a - s.a) / cross(tv, sv); } // 直線と点の距離 ld dist_lp(Line l, Point p) { return abs(p - proj(l, p)); } // 直線と直線の距離 ld dist_ll(Line l, Line m) { return isis_ll(l, m) ? 0 : dist_lp(l, m.a); } // 直線と線分の距離 ld dist_ls(Line l, Line s) { return isis_ls(l, s) ? 0 : min(dist_lp(l, s.a), dist_lp(l, s.b)); } // 線分と点の距離 ld dist_sp(Line s, Point p) { Point r = proj(s, p); return isis_sp(s, r) ? abs(r - p) : min(abs(s.a - p), abs(s.b - p)); } // 線分と線分の距離 ld dist_ss(Line s, Line t) { if (isis_ss(s, t)) return 0; return min( {dist_sp(s, t.a), dist_sp(s, t.b), dist_sp(t, s.a), dist_sp(t, s.b)}); } /* 円 */ // 円と円の交点 vector<Point> is_cc(Circle c1, Circle c2) { vector<Point> res; ld d = abs(c1.p - c2.p); ld rc = (d * d + c1.r * c1.r - c2.r * c2.r) / (2 * d); ld dfr = c1.r * c1.r - rc * rc; if (abs(dfr) < eps) dfr = 0.0; else if (dfr < 0.0) return res; // no intersection ld rs = sqrt(dfr); Point diff = (c2.p - c1.p) / d; res.push_back(c1.p + diff * Point(rc, rs)); if (dfr != 0.0) res.push_back(c1.p + diff * Point(rc, -rs)); return res; } // 円と直線の交点 vector<Point> is_lc(Circle c, Line l) { vector<Point> res; ld d = dist_lp(l, c.p); if (d < c.r + eps) { ld len = (d > c.r) ? 0.0 : sqrt(c.r * c.r - d * d); // safety; Point nor = (l.a - l.b) / abs(l.a - l.b); res.push_back(proj(l, c.p) + len * nor); res.push_back(proj(l, c.p) - len * nor); } return res; } // 円と線分の距離 vector<Point> is_sc(Circle c, Line l) { vector<Point> v = is_lc(c, l), res; for (Point p : v) if (isis_sp(l, p)) res.push_back(p); return res; } // 円と点の接線 vector<Line> tangent_cp(Circle c, Point p) { vector<Line> ret; Point v = c.p - p; ld d = abs(v); ld l = sqrt(norm(v) - c.r * c.r); if (isnan(l)) { return ret; } Point v1 = v * Point(l / d, c.r / d); Point v2 = v * Point(l / d, -c.r / d); ret.push_back(Line(p, p + v1)); if (l < eps) return ret; ret.push_back(Line(p, p + v2)); return ret; } // 円と円の接線 vector<Line> tangent_cc(Circle c1, Circle c2) { vector<Line> ret; if (abs(c1.p - c2.p) - (c1.r + c2.r) > -eps) { Point center = (c1.p * c2.r + c2.p * c1.r) / (c1.r + c2.r); ret = tangent_cp(c1, center); } if (abs(c1.r - c2.r) > eps) { Point out = (-c1.p * c2.r + c2.p * c1.r) / (c1.r - c2.r); vector<Line> nret = tangent_cp(c1, out); ret.insert(ret.end(), ALL(nret)); } else { Point v = c2.p - c1.p; v /= abs(v); Point q1 = c1.p + v * Point(0, 1) * c1.r; Point q2 = c1.p + v * Point(0, -1) * c1.r; ret.push_back(Line(q1, q1 + v)); ret.push_back(Line(q2, q2 + v)); } return ret; } /* 多角形 */ typedef vector<Point> Polygon; // 面積 ld area(const Polygon &p) { ld res = 0; int n = p.size(); REP(j, n) res += cross(p[j], p[(j + 1) % n]); return res / 2; } // 多角形の回転方向 bool is_counter_clockwise(const Polygon &poly) { ld angle = 0; int n = poly.size(); REP(i, n) { Point a = poly[i], b = poly[(i + 1) % n], c = poly[(i + 2) % n]; angle += arg((c - b) / (b - a)); } return angle > eps; } // 円の内外判定 // -1 => out // 0 => on // 1 => in int is_in_polygon(const Polygon &poly, Point p) { ld angle = 0; int n = poly.size(); REP(i, n) { Point a = poly[i], b = poly[(i + 1) % n]; if (isis_sp(Line(a, b), p)) return 1; angle += arg((b - p) / (a - p)); } return eq(angle, 0) ? 0 : 2; } // 凸包 Polygon convex_hull(vector<Point> ps) { int n = ps.size(); int k = 0; sort(ps.begin(), ps.end()); Polygon ch(2 * n); for (int i = 0; i < n; ch[k++] = ps[i++]) while (k >= 2 && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k; for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = ps[i--]) while (k >= t && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k; ch.resize(k - 1); return ch; } // 凸カット Polygon convex_cut(const Polygon &ps, Line l) { int n = ps.size(); Polygon Q; REP(i, n) { Point A = ps[i], B = ps[(i + 1) % n]; Line m = Line(A, B); if (ccw(l.a, l.b, A) != -1) Q.push_back(A); if (ccw(l.a, l.b, A) * ccw(l.a, l.b, B) < 0 && isis_ll(l, m)) Q.push_back(is_ll(l, m)); } return Q; } /* アレンジメント */ void add_point(vector<Point> &ps, Point p) { for (Point q : ps) if (abs(q - p) < eps) return; ps.push_back(p); } typedef int Weight; struct Edge { int from, to; Weight weight; }; typedef vector<Edge> Edges; typedef vector<Edges> Graph; void add_edge(Graph &g, int from, int to, Weight weight) { g[from].push_back(Edge{from, to, weight}); } Graph segment_arrangement(const vector<Line> &s, const vector<Point> &p) { int n = p.size(), m = s.size(); Graph g(n); REP(i, m) { vector<pair<ld, int>> vec; REP(j, n) if (isis_sp(s[i], p[j])) vec.emplace_back(abs(s[i].a - p[j]), j); sort(ALL(vec)); REP(j, vec.size() - 1) { int from = vec[j].second, to = vec[j + 1].second; add_edge(g, from, to, abs(p[from] - p[to])); } } return g; } Graph circle_arrangement(const vector<Circle> &c, const vector<Point> &p) { int n = p.size(), m = c.size(); Graph g(n); REP(i, m) { vector<pair<ld, int>> vec; REP(j, n) if (abs(abs(c[i].p - p[j]) - c[i].r) < eps) vec.emplace_back(arg(c[i].p - p[j]), j); sort(ALL(vec)); REP(j, vec.size() - 1) { int from = vec[j].second, to = vec[j + 1].second; ld angle = vec[j + 1].first - vec[j].first; add_edge(g, from, to, angle * c[i].r); } if (vec.size() >= 2) { int from = vec.back().second, to = vec.front().first; ld angle = vec.front().first - vec.back().first; add_edge(g, from, to, angle * c[i].r); } } return g; } /* 双対グラフ */ // 線分集合は既にアレンジメントされていなければならない. // 内側の円は時計回りで,外側の円は反時計回りで得られる. // 変数 polygon は,vector<int> で表される多角形の集合であり, // vector<int> で表される // 多角形のi番目は,その頂点の頂点集合pにおける番号である. vector<vector<int>> polygon; vector<int> seg2p[1024][1024]; Graph dual_graph(const vector<Line> &s, const vector<Point> &p) { int N = p.size(); polygon.clear(); REP(i, 1024) REP(j, 1024) seg2p[i][j].clear(); vector<vector<tuple<ld, int, bool>>> tup(N); REP(i, s.size()) { int a = -1, b = -1; REP(j, N) if (abs(s[i].a - p[j]) < eps) a = j; REP(j, N) if (abs(s[i].b - p[j]) < eps) b = j; assert(a >= 0 && b >= 0); tup[a].emplace_back(arg(s[i].b - s[i].a), b, false); tup[b].emplace_back(arg(s[i].a - s[i].b), a, false); } REP(i, N) sort(ALL(tup[i])); REP(i, N) { REP(j, tup[i].size()) { ld angle; int pos = j, from = i, to; bool flag; tie(angle, to, flag) = tup[i][j]; if (flag) continue; vector<int> ps; while (!flag) { ps.push_back(from); get<2>(tup[from][pos]) = true; seg2p[from][to].push_back(polygon.size()); seg2p[to][from].push_back(polygon.size()); angle += pi + eps; if (angle > pi) angle -= 2 * pi; auto it = lower_bound(ALL(tup[to]), make_tuple(angle, 0, false)); if (it == tup[to].end()) it = tup[to].begin(); from = to; tie(angle, to, flag) = *it; pos = it - tup[from].begin(); } polygon.push_back(ps); } } Graph g(polygon.size()); REP(i, N) REP(j, i) { if (seg2p[i][j].size() == 2) { int from = seg2p[i][j][0], to = seg2p[i][j][1]; g[from].push_back(Edge{from, to}); g[to].push_back(Edge{to, from}); } } return g; } /* ビジュアライザ */ const ld zoom = 25; const ld centerX = 6; const ld centerY = 5; void change_color(int r, int g, int b) { fprintf(stderr, "c.strokeStyle = 'rgb(%d, %d, %d)';\n", r, g, b); } int cordx(Point p) { return 400 + zoom * (p.real() - centerX); } int cordy(Point p) { return 400 - zoom * (p.imag() - centerY); } #define cord(p) cordx(p), cordy(p) void draw_point(Point p) { fprintf(stderr, "circle(%d, %d, %d)\n", cord(p), 2); } void draw_segment(Line l) { fprintf(stderr, "line(%d, %d, %d, %d)\n", cord(l.a), cord(l.b)); } void draw_line(Line l) { Point v = l.b - l.a; Line m(l.a - v * Point(1e4, 0), l.b + v * Point(1e4, 0)); fprintf(stderr, "line(%d, %d, %d, %d)\n", cord(m.a), cord(m.b)); } void draw_polygon(const Polygon &p) { int n = p.size(); REP(i, n) draw_segment(Line(p[i], p[(i + 1) % n])); } void draw_circle(Circle c) { fprintf(stderr, "circle(%d, %d, %d)\n", cord(c.p), (int)(zoom * c.r)); } vector<Point> ps; int check(Point &center) { int num = 0; for (int i = 0; i < ps.size(); ++i) { if (abs(ps[i] - center) <= 1) { num++; } } return num; } int main() { while (1) { int N; cin >> N; if (!N) break; ps.clear(); for (int i = 0; i < N; ++i) { long double x, y; cin >> x >> y; ps.push_back({x, y}); } int ans = 1; for (int i = 0; i < N; ++i) { for (int j = i + 1; j < N; ++j) { if (abs(ps[i] - ps[j]) > 2) continue; Line l(ps[i], ps[j]); Point center = (ps[i] + ps[j]) * 0.5l; Point vec(imag(ps[i] - ps[j]), -real(ps[i] - ps[j])); long double nl = sqrt(0.9999999 - norm(center - ps[i])); long double oldl = abs(vec); vec *= nl / oldl; Point checkcenter = center + vec; ans = max(ans, check(checkcenter)); checkcenter = center - vec; ans = max(ans, check(checkcenter)); } } cout << ans << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
1
4,282
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-8; using P = complex<double>; int n; P p[300]; int main() { while (cin >> n, n) { for (int i = 0; i < n; i++) { double x, y; cin >> x >> y; p[i] = P(x, y); } vector<P> ps; for (int i = 0; i < n; i++) { for (int j = 0; j < i; j++) { if (abs(p[i] - p[j]) >= 2.0) continue; P v = p[j] - p[i]; P u = v * P(0.0, 1.0); u *= sqrt(1.0 - abs(v) / 2.0) / abs(u); ps.push_back(p[i] + v / 2.0 + u); ps.push_back(p[i] + v / 2.0 - u); } } int res = 1; for (P c : ps) { int s = 0; for (int i = 0; i < n; i++) { s += abs(c - p[i]) <= 1.0 + EPS; } res = max(res, s); } cout << res << endl; } }
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-8; using P = complex<double>; int n; P p[300]; int main() { while (cin >> n, n) { for (int i = 0; i < n; i++) { double x, y; cin >> x >> y; p[i] = P(x, y); } vector<P> ps; for (int i = 0; i < n; i++) { for (int j = 0; j < i; j++) { if (abs(p[i] - p[j]) >= 2.0) continue; P v = p[j] - p[i]; P u = v * P(0.0, 1.0); u *= sqrt(1.0 - abs(v) * abs(v) / 4.0) / abs(u); ps.push_back(p[i] + v / 2.0 + u); ps.push_back(p[i] + v / 2.0 - u); } } int res = 1; for (P c : ps) { int s = 0; for (int i = 0; i < n; i++) { s += abs(c - p[i]) <= 1.0 + EPS; } res = max(res, s); } cout << res << endl; } }
[["+", 3, 4, 0, 16, 12, 16, 31, 16, 17, 48], ["+", 0, 16, 12, 16, 31, 16, 12, 2, 63, 22], ["+", 12, 16, 31, 16, 12, 2, 3, 4, 0, 24], ["+", 12, 16, 31, 16, 12, 2, 3, 4, 0, 22], ["+", 12, 16, 31, 16, 12, 2, 3, 4, 0, 25], ["-", 31, 2, 3, 4, 0, 16, 12, 16, 12, 13], ["+", 31, 2, 3, 4, 0, 16, 12, 16, 12, 13]]
1
283
#include <bits/stdc++.h> using namespace std; #define rep(i, x, y) for (int i = (x); i < (y); ++i) #define debug(x) #x << "=" << (x) #ifdef DEBUG #define _GLIBCXX_DEBUG #define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl #else #define dump(x) #endif typedef long long int ll; typedef pair<int, int> pii; // template<typename T> using vec=std::vector<T>; const int inf = 1 << 30; const long long int infll = 1LL << 58; const double eps = 1e-9; const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "["; for (const auto &v : vec) { os << v << ","; } os << "]"; return os; } void solve() { while (true) { int n; cin >> n; if (n == 0) break; vector<long double> xs(n), ys(n); rep(i, 0, n) cin >> xs[i] >> ys[i]; auto count = [&](const long double x, const long double y) { int res = 0; rep(i, 0, n) if ((xs[i] - x) * (xs[i] - x) + (ys[i] - y) * (ys[i] - y) <= 1 + eps)++ res; return res; }; int ans = 0; rep(i, 0, 201) { const long double y = 10. * i / 200; rep(j, 0, n) { const long double tmp = 1 - (ys[j] - y) * (ys[j] - y); if (tmp < 0) continue; const long double x1 = xs[j] - sqrtl(tmp), x2 = xs[j] + sqrt(tmp); ans = max({ans, count(x1, y), count(x2, y)}); } } cout << ans << endl; } } int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); cout << fixed << setprecision(8); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, x, y) for (int i = (x); i < (y); ++i) #define debug(x) #x << "=" << (x) #ifdef DEBUG #define _GLIBCXX_DEBUG #define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl #else #define dump(x) #endif typedef long long int ll; typedef pair<int, int> pii; // template<typename T> using vec=std::vector<T>; const int inf = 1 << 30; const long long int infll = 1LL << 58; const long double eps = 1e-3; const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "["; for (const auto &v : vec) { os << v << ","; } os << "]"; return os; } void solve() { while (true) { int n; cin >> n; if (n == 0) break; vector<long double> xs(n), ys(n); rep(i, 0, n) cin >> xs[i] >> ys[i]; auto count = [&](const long double x, const long double y) { int res = 0; rep(i, 0, n) if ((xs[i] - x) * (xs[i] - x) + (ys[i] - y) * (ys[i] - y) <= 1 + eps)++ res; return res; }; int ans = 0; rep(i, 0, 2401) { const long double y = 10. * i / 2400; rep(j, 0, n) { const long double tmp = 1 - (ys[j] - y) * (ys[j] - y); if (tmp < 0) continue; const long double x1 = xs[j] - sqrtl(tmp), x2 = xs[j] + sqrt(tmp); ans = max({ans, count(x1, y), count(x2, y)}); } } cout << ans << endl; } } int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); cout << fixed << setprecision(8); solve(); return 0; }
[["+", 36, 36, 0, 30, 0, 43, 39, 86, 0, 96], ["-", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["-", 0, 9, 0, 43, 49, 50, 51, 16, 12, 13], ["+", 0, 9, 0, 43, 49, 50, 51, 16, 12, 13]]
1
479
#include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> //#include<cctype> #include <climits> #include <iostream> #include <map> #include <string> #include <vector> //#include<list> #include <algorithm> #include <deque> #include <queue> //#include<numeric> #include <utility> //#include<memory> #include <cassert> #include <functional> #include <random> #include <set> #include <stack> const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int, int> pii; typedef long double Real; Real eps = 1e-9; Real add(Real a, Real b) { if (abs(a + b) < eps * (abs(a) + abs(b))) return 0; return a + b; } bool equal(Real a, Real b) { return add(a, -b) == 0; } struct P { Real x, y; P() {} P(Real x, Real y) : x(x), y(y) {} P operator+(P p) const { return P(add(x, p.x), add(y, p.y)); } P operator-(P p) const { return P(add(x, -p.x), add(y, -p.y)); } P operator*(Real d) const { return P(x * d, y * d); } Real dot(P p) const { return add(x * p.x, y * p.y); } // ?????? Real det(P p) const { return add(x * p.y, -y * p.x); } // ?????? Real dist(P p) const { return sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y)); } // ?????¢ void normalize() { Real d = sqrt(x * x + y * y); x /= d; y /= d; } // ??£?????? bool operator<(const P &rhs) const { if (x != rhs.x) return x < rhs.x; return y < rhs.y; } bool operator==(const P &rhs) const { return equal(x, rhs.x) && equal(y, rhs.y); } }; const int MAXN = 333; P pnt[MAXN]; int N; int calc(P center) { int ret = 0; for (int i = 0; i < N; i++) { P vec = pnt[i] - center; if (vec.dot(vec) < 1 + eps) { ret++; } } return ret; } int main() { cin.tie(0); ios::sync_with_stdio(false); while (cin >> N) { if (N == 0) break; for (int i = 0; i < N; i++) cin >> pnt[i].x >> pnt[i].y; int ans = min(2, N); for (int i = 0; i < N; i++) for (int j = i + 1; j < N; j++) { if (pnt[i].dist(pnt[j]) > 2) continue; // diff ????????? P vec = pnt[j] - pnt[i]; // vec ????????´???????????????????????? P n = P(vec.y, -vec.x); n.normalize(); vec = vec * 0.5; Real len = sqrt(1 - vec.dot(vec)); P cand1 = pnt[i] + vec + n * len; P cand2 = pnt[i] + vec - n * len; ans = max(ans, calc(cand1)); ans = max(ans, calc(cand2)); } cout << ans << endl; } return 0; }
#include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> //#include<cctype> #include <climits> #include <iostream> #include <map> #include <string> #include <vector> //#include<list> #include <algorithm> #include <deque> #include <queue> //#include<numeric> #include <utility> //#include<memory> #include <cassert> #include <functional> #include <random> #include <set> #include <stack> const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int, int> pii; typedef long double Real; Real eps = 1e-9; Real add(Real a, Real b) { if (abs(a + b) < eps * (abs(a) + abs(b))) return 0; return a + b; } bool equal(Real a, Real b) { return add(a, -b) == 0; } struct P { Real x, y; P() {} P(Real x, Real y) : x(x), y(y) {} P operator+(P p) const { return P(add(x, p.x), add(y, p.y)); } P operator-(P p) const { return P(add(x, -p.x), add(y, -p.y)); } P operator*(Real d) const { return P(x * d, y * d); } Real dot(P p) const { return add(x * p.x, y * p.y); } // ?????? Real det(P p) const { return add(x * p.y, -y * p.x); } // ?????? Real dist(P p) const { return sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y)); } // ?????¢ void normalize() { Real d = sqrt(x * x + y * y); x /= d; y /= d; } // ??£?????? bool operator<(const P &rhs) const { if (x != rhs.x) return x < rhs.x; return y < rhs.y; } bool operator==(const P &rhs) const { return equal(x, rhs.x) && equal(y, rhs.y); } }; const int MAXN = 333; P pnt[MAXN]; int N; int calc(P center) { int ret = 0; for (int i = 0; i < N; i++) { P vec = pnt[i] - center; if (vec.dot(vec) < 1 + eps) { ret++; } } return ret; } int main() { cin.tie(0); ios::sync_with_stdio(false); while (cin >> N) { if (N == 0) break; for (int i = 0; i < N; i++) cin >> pnt[i].x >> pnt[i].y; int ans = 1; for (int i = 0; i < N; i++) for (int j = i + 1; j < N; j++) { if (pnt[i].dist(pnt[j]) > 2) continue; // diff ????????? P vec = pnt[j] - pnt[i]; // vec ????????´???????????????????????? P n = P(vec.y, -vec.x); n.normalize(); vec = vec * 0.5; Real len = sqrt(1 - vec.dot(vec)); P cand1 = pnt[i] + vec + n * len; P cand2 = pnt[i] + vec - n * len; ans = max(ans, calc(cand1)); ans = max(ans, calc(cand2)); } cout << ans << 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, 13], ["-", 0, 43, 49, 50, 51, 2, 3, 4, 0, 21], ["-", 0, 43, 49, 50, 51, 2, 3, 4, 0, 22], ["-", 0, 43, 49, 50, 51, 2, 3, 4, 0, 25], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
1
820
#include "bits/stdc++.h" #include <cassert> using namespace std; typedef long long ll; typedef pair<int, int> pii; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define all(a) (a).begin(), (a).end() #define vi vector<int> #define pb push_back #define INF 999999999 //#define INF (1LL<<59) #define OUT 0 #define ON 1 #define IN 2 #define EPS 0.00009 //#define EPS (1e-10) class P { //テァツつケ public: double x, y; P(double _x = 0, double _y = 0) : x(_x), y(_y){}; P operator+(const P &p) const { return P(x + p.x, y + p.y); } //テ・ツ環?ァツョツ? P operator-(const P &p) const { return P(x - p.x, y - p.y); } //テヲツクツ崚ァツョツ? P operator*(const double k) const { return P(x * k, y * k); } //テ、ツケツ療ァツョツ? P operator/(const double k) const { return P(x / k, y / k); } //テゥツ卍、テァツョツ? bool operator==(const P &p) { return (fabs(x - p.x) < EPS && fabs(y - p.y) < EPS); } bool operator<(const P &p) const { return (x != p.x ? x < p.x : y < p.y); } double norm() { return x * x + y * y; } //テ」ツδ偲」ツδォテ」ツδ? double abs() { return sqrt(norm()); } //テ・ツ、ツァテ」ツ?催」ツ?? }; struct C { P p; double r; }; //テ・ツ?? struct S { P p1, p2; }; //テァツキツ堙・ツ按? typedef vector<P> Polygon; //テ・ツ、ツ堙ィツァツ津・ツスツ「 typedef P Vector; //テ」ツδ凖」ツつッテ」ツδ暗」ツδォ typedef S L; //テァツ崢エテァツキツ? double norm(P p) { return p.norm(); } double abs(P p) { return p.abs(); } double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; } double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; } double sqDist(P a, P b) { return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); } double dist(P a, P b) { return sqrt(sqDist(a, b)); } Vector vec(S a) { return P(a.p2.x - a.p1.x, a.p2.y - a.p1.y); } int ccw(P p0, P p1, P p2) { // AOJ_BOOK_P386 verified Vector a = p1 - p0; Vector b = p2 - p0; if (cross(a, b) > EPS) return 1; // COUNTER_CLOCKWISE if (cross(a, b) < -EPS) return -1; // CLOCKWISE if (dot(a, b) < -EPS) return 2; // ONLINE_BACK if (a.norm() < b.norm()) return -2; // ONLINE_FRONT return 0; // ON_SEGMENT; } //テァツ崢エテァツキツ堙ァツ崢エティツ。ツ古・ツ按、テ・ツョツ?verified AOJ0058 bool orthogonal(P p1, P p2, P p3, P p4) { return abs(dot(p1 - p2, p3 - p4)) < EPS; } //テァツキツ堙・ツ按?、ツコツ、テ・ツキツョテ・ツ按、テ・ツョツ? bool intersect(P p1, P p2, P p3, P p4) { return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 && ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0); } //テァツキツ堙・ツ按?」ツ?ィテァツつケテ」ツ?ョティツキツ敕ゥツ崢「 verified //ARC042-B double dLP(S l, P p) { return abs(cross(l.p2 - l.p1, p - l.p1)) / (l.p2 - l.p1).abs(); } //テァツキツ堙・ツ按?」ツ?ォテ・ツッツセテ」ツ?凖」ツつ凝ァツつケテ」ツ?ョテ・ツーツ?・ツスツア //verified AOJ CGL_1_A P project(S s, P p) { Vector base = s.p2 - s.p1; double r = dot(p - s.p1, base) / norm(base); return (base * r) + s.p1; } //テァツキツ堙・ツ按?」ツ?ォテ・ツッツセテ」ツ?凖」ツつ凝ァツつケテ」ツ?ョテ・ツ渉催・ツーツ?verified //AOJ CGL_1_B P reflect(S s, P p) { return p + (project(s, p) - p) * 2.0; } //テァツ崢エテァツキツ堙」ツ?ィテァツ崢エテァツキツ堙」ツ?ョテゥツ鳴「テ、ツソツ?verified //AOJ CGL_2 int rLL(L a, L b) { if (cross(vec(a), vec(b)) == 0) return 2; //テ、ツクツヲティツ。ツ? if (dot(vec(a), vec(b)) == 0) return 1; //テ・ツ楪づァツ崢エ return 0; } // テ・ツ??」ツ?ィテァツつケテ」ツ?ョテ・ツ??・ツ、ツ姪・ツ按、テ・ツョツ? int contains(C c, P p) { double d = (c.p - p).abs(); if (d - c.r > EPS) return OUT; if (abs(d - c.r) < EPS) return ON; return IN; } //テァツ崢エテァツキツ堙」ツ?ィテ・ツ??」ツ?ョテ、ツコツ、テ・ツキツョテ・ツ按、テ・ツョツ?テゥツ?催」ツ?ェテ」ツ?」テ」ツ?ヲテ」ツ??」ツつ凝・ツ?エテ・ツ青暗」ツ?ッテ、ツコツ、テ・ツキツョテヲツ可アテ」ツ?? bool intersect_circle_(P center, double r, L line) { if (dLP(line, center) <= r + EPS) return true; return false; } //テァツキツ堙・ツ按?」ツ?ィテ・ツコツ療」ツ?ョティツキツ敕ゥツ崢「 verified //QUPC-G double dSP(S s, P p) { if (dot((s.p2 - s.p1), p - s.p1) <= EPS) return (p - s.p1).abs(); if (dot((s.p2 - s.p1) * -1, p - s.p2) <= EPS) return (p - s.p2).abs(); return dLP(s, p); } //テァツキツ堙・ツ按?」ツ?ィテ・ツ??」ツ?ョテ、ツコツ、テ・ツキツョテ・ツ按、テ・ツョツ?テゥツ?催」ツ?ェテ」ツ?」テ」ツ?ヲテ」ツ??」ツつ凝・ツ?エテ・ツ青暗」ツ?ッテ、ツコツ、テ・ツキツョテヲツ可アテ」ツ?? //verified QUPC-G bool iCS(C c, S l) { int c1 = contains(c, l.p1); int c2 = contains(c, l.p2); if (c1 > c2) swap(c1, c2); // (OUT, OUT) (OUT, ON) (OUT, IN) (ON, ON) (ON, IN) (IN, IN) // テ」ツ?ョ6テゥツ?堙」ツつ? if (c1 == OUT && c2 == IN) return true; if (c1 == IN && c2 == IN) return false; if (c1 == ON) return true; // (テヲツ篠・テ」ツ?凖」ツつ凝」ツ?ィテ」ツ?? double d = dSP(l, c.p); if (d - c.r < -EPS) return true; if (d - c.r > EPS) return false; return true; // (テヲツ篠・テ」ツ?凖」ツつ凝」ツ?ィテ」ツ?? } //テ・ツ債佚ァツエツ氾・ツ、ツ堙ィツァツ津・ツスツ「テ・ツ按、テ・ツョツ? bool isSimple(Polygon pol) { //テ・ツ按敕」ツつ?」ツ?ョテァツつケテ」ツつ津ゥツ?催ィツ、ツ?」ツ?療」ツ?ヲpolテ」ツ?ォテ・ツ?・テ」ツつ古」ツ?ヲテ」ツ?甘」ツ?? size_t pol_size = pol.size() - 1; rep(i, pol_size) { for (int j = i + 2; j < pol_size; j++) { if (i == j || i == (j - 1 + pol_size) % pol_size || i == (j + 1 + pol_size) % pol_size) continue; if (intersect(pol[i], pol[i + 1], pol[j], pol[j + 1])) return false; } } return true; } //テァツつケテ」ツ?古・ツ?クテ・ツ、ツ堙ィツァツ津・ツスツ「テ」ツ?ョテ・ツ??・ツ?エテ」ツ?ォテ」ツ?づ」ツつ凝」ツ?凝」ツ?ゥテ」ツ??」ツ?凝」ツつ津ヲツアツづ」ツつ?」ツつ?trueテ」ツ?ェテ」ツつ嘉・ツ??・ツ?エ //verified AOJ0012 int isPointInsidePolygon(vector<P> pol, P p) { int c = 0; rep(i, pol.size()) { if (cross(pol[i] - pol[(i + 1) % pol.size()], p - pol[(i + 1) % pol.size()]) == 0) return ON; if (cross(pol[i] - pol[(i + 1) % pol.size()], p - pol[(i + 1) % pol.size()]) > 0) c++; } if (c % pol.size()) return OUT; return IN; } //テ・ツ??」ツ?ィテ・ツ?クテ・ツ、ツ堙ィツァツ津・ツスツ「テ」ツ?ョテ、ツコツ、テ・ツキツョテァツ環カテヲツ?凝」ツつ津ィツェツソテ」ツ?ケテ」ツつ? int CPOLarea(C c, Polygon pol) { vector<L> lines; vector<int> res(pol.size()); bool POLinC = true, isFar = true; rep(i, pol.size()) { if (contains(c, pol[i]) == OUT) POLinC = false; res[i] = contains(c, pol[i]); lines.pb(L{pol[i], pol[(i + 1) % pol.size()]}); if (sqDist(c.p, pol[i]) < c.r * c.r) isFar = false; } if (POLinC) return 2; //テ・ツ、ツ堙ィツァツ津・ツスツ「テ」ツ?ッテ・ツ??」ツ?ョテ・ツ??ゥツδィb if (isPointInsidePolygon(pol, c.p) == IN && isFar) return 3; //テ・ツ、ツ堙ィツァツ津・ツスツ「テ」ツ?ョテ・ツ??ゥツδィテ」ツ?ォテ・ツ?? rep(i, lines.size()) if ( iCS(c, lines [i])) return 1; //テ・ツ、ツ堙ィツァツ津・ツスツ「テ」ツ?ィテ・ツ??」ツ?ッテ、ツコツ、テ・ツキツョc return 0; } //テ・ツ?クテ・ツ個?verified AOJ0068,QUPC-G //ティツセツ榲ヲツ崢クテゥツ??」ツ?ァテヲツッツ氾ィツシツ? bool cmp_x(const P &p, const P &q) { if (p.x != q.x) return p.x < q.x; return p.y < q.y; } //テ・ツ?クテ・ツ個?」ツつ津ヲツアツづ」ツつ?」ツつ? vector<P> convex_hull(vector<P> ps) { int n = ps.size(); sort(all(ps), cmp_x); int k = 0; //テ・ツ?クテ・ツ個?」ツ?ョテゥツ?づァツつケテヲツ閉ー vector<P> qs(n * 2); //テヲツァツ凝ヲツ按静、ツクツュテ」ツ?ョテ・ツ?クテ・ツ個? //テ、ツクツ凝・ツ?エテ・ツ?クテ・ツ個?」ツ?ョテ、ツスツ愿ヲツ按? rep(i, n) { while (k > 1 && cross((qs[k - 1] - qs[k - 2]), (ps[i] - qs[k - 1])) <= 0) k--; qs[k++] = ps[i]; } //テ、ツクツ甘・ツ?エテ・ツ?クテ・ツ個?」ツ?ョテ、ツスツ愿ヲツ按? for (int i = n - 2, t = k; i >= 0; i--) { while (k > t && cross((qs[k - 1] - qs[k - 2]), (ps[i] - qs[k - 1])) <= 0) k--; qs[k++] = ps[i]; } qs.resize(k - 1); return qs; } // 2テァツつケテ」ツつ津ゥツ?堙」ツつ凝・ツ債甘・ツセツвテ」ツ?ョテ・ツ??」ツ?ョテ、ツクツュテ・ツソツε・ツコツァテヲツィツ凖」ツつ津ヲツアツづ」ツつ?」ツつ? pair<P, P> geoGetCircleOf2pAndR(P p1, P p2, double r) { P pc1 = P(-INF, -INF), pc2(-INF, -INF), p3; double d, l, dx, dy; p3 = (p1 + p2) / 2.0; l = sqDist(p2, p3); if (r * r >= l) { d = sqrt(r * r / l - 1.0); dx = d * (p2.y - p3.y); dy = d * (p2.x - p3.x); pc1.x = p3.x + dx; pc1.y = p3.y - dy; pc2.x = p3.x - dx; pc2.y = p3.y + dy; } return pair<P, P>(pc1, pc2); } int main() { int n; while (cin >> n && n) { int ans = 0; vector<P> ps(n); rep(i, n) cin >> ps[i].x >> ps[i].y; rep(i, n) { for (int j = i + 1; j < n; j++) { if (dist(ps[i], ps[j]) > 2 + EPS) continue; pair<P, P> res = geoGetCircleOf2pAndR(ps[i], ps[j], 1); int suma = 0, sumb = 0; rep(k, n) { if (sqDist(ps[k], res.first) < 1 + EPS) suma++; if (sqDist(ps[k], res.second) < 1 + EPS) sumb++; } ans = max(ans, max(suma, sumb)); } } cout << ans << endl; } }
#include "bits/stdc++.h" #include <cassert> using namespace std; typedef long long ll; typedef pair<int, int> pii; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define all(a) (a).begin(), (a).end() #define vi vector<int> #define pb push_back #define INF 999999999 //#define INF (1LL<<59) #define OUT 0 #define ON 1 #define IN 2 #define EPS 0.00009 //#define EPS (1e-10) class P { //テァツつケ public: double x, y; P(double _x = 0, double _y = 0) : x(_x), y(_y){}; P operator+(const P &p) const { return P(x + p.x, y + p.y); } //テ・ツ環?ァツョツ? P operator-(const P &p) const { return P(x - p.x, y - p.y); } //テヲツクツ崚ァツョツ? P operator*(const double k) const { return P(x * k, y * k); } //テ、ツケツ療ァツョツ? P operator/(const double k) const { return P(x / k, y / k); } //テゥツ卍、テァツョツ? bool operator==(const P &p) { return (fabs(x - p.x) < EPS && fabs(y - p.y) < EPS); } bool operator<(const P &p) const { return (x != p.x ? x < p.x : y < p.y); } double norm() { return x * x + y * y; } //テ」ツδ偲」ツδォテ」ツδ? double abs() { return sqrt(norm()); } //テ・ツ、ツァテ」ツ?催」ツ?? }; struct C { P p; double r; }; //テ・ツ?? struct S { P p1, p2; }; //テァツキツ堙・ツ按? typedef vector<P> Polygon; //テ・ツ、ツ堙ィツァツ津・ツスツ「 typedef P Vector; //テ」ツδ凖」ツつッテ」ツδ暗」ツδォ typedef S L; //テァツ崢エテァツキツ? double norm(P p) { return p.norm(); } double abs(P p) { return p.abs(); } double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; } double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; } double sqDist(P a, P b) { return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); } double dist(P a, P b) { return sqrt(sqDist(a, b)); } Vector vec(S a) { return P(a.p2.x - a.p1.x, a.p2.y - a.p1.y); } int ccw(P p0, P p1, P p2) { // AOJ_BOOK_P386 verified Vector a = p1 - p0; Vector b = p2 - p0; if (cross(a, b) > EPS) return 1; // COUNTER_CLOCKWISE if (cross(a, b) < -EPS) return -1; // CLOCKWISE if (dot(a, b) < -EPS) return 2; // ONLINE_BACK if (a.norm() < b.norm()) return -2; // ONLINE_FRONT return 0; // ON_SEGMENT; } //テァツ崢エテァツキツ堙ァツ崢エティツ。ツ古・ツ按、テ・ツョツ?verified AOJ0058 bool orthogonal(P p1, P p2, P p3, P p4) { return abs(dot(p1 - p2, p3 - p4)) < EPS; } //テァツキツ堙・ツ按?、ツコツ、テ・ツキツョテ・ツ按、テ・ツョツ? bool intersect(P p1, P p2, P p3, P p4) { return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 && ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0); } //テァツキツ堙・ツ按?」ツ?ィテァツつケテ」ツ?ョティツキツ敕ゥツ崢「 verified //ARC042-B double dLP(S l, P p) { return abs(cross(l.p2 - l.p1, p - l.p1)) / (l.p2 - l.p1).abs(); } //テァツキツ堙・ツ按?」ツ?ォテ・ツッツセテ」ツ?凖」ツつ凝ァツつケテ」ツ?ョテ・ツーツ?・ツスツア //verified AOJ CGL_1_A P project(S s, P p) { Vector base = s.p2 - s.p1; double r = dot(p - s.p1, base) / norm(base); return (base * r) + s.p1; } //テァツキツ堙・ツ按?」ツ?ォテ・ツッツセテ」ツ?凖」ツつ凝ァツつケテ」ツ?ョテ・ツ渉催・ツーツ?verified //AOJ CGL_1_B P reflect(S s, P p) { return p + (project(s, p) - p) * 2.0; } //テァツ崢エテァツキツ堙」ツ?ィテァツ崢エテァツキツ堙」ツ?ョテゥツ鳴「テ、ツソツ?verified //AOJ CGL_2 int rLL(L a, L b) { if (cross(vec(a), vec(b)) == 0) return 2; //テ、ツクツヲティツ。ツ? if (dot(vec(a), vec(b)) == 0) return 1; //テ・ツ楪づァツ崢エ return 0; } // テ・ツ??」ツ?ィテァツつケテ」ツ?ョテ・ツ??・ツ、ツ姪・ツ按、テ・ツョツ? int contains(C c, P p) { double d = (c.p - p).abs(); if (d - c.r > EPS) return OUT; if (abs(d - c.r) < EPS) return ON; return IN; } //テァツ崢エテァツキツ堙」ツ?ィテ・ツ??」ツ?ョテ、ツコツ、テ・ツキツョテ・ツ按、テ・ツョツ?テゥツ?催」ツ?ェテ」ツ?」テ」ツ?ヲテ」ツ??」ツつ凝・ツ?エテ・ツ青暗」ツ?ッテ、ツコツ、テ・ツキツョテヲツ可アテ」ツ?? bool intersect_circle_(P center, double r, L line) { if (dLP(line, center) <= r + EPS) return true; return false; } //テァツキツ堙・ツ按?」ツ?ィテ・ツコツ療」ツ?ョティツキツ敕ゥツ崢「 verified //QUPC-G double dSP(S s, P p) { if (dot((s.p2 - s.p1), p - s.p1) <= EPS) return (p - s.p1).abs(); if (dot((s.p2 - s.p1) * -1, p - s.p2) <= EPS) return (p - s.p2).abs(); return dLP(s, p); } //テァツキツ堙・ツ按?」ツ?ィテ・ツ??」ツ?ョテ、ツコツ、テ・ツキツョテ・ツ按、テ・ツョツ?テゥツ?催」ツ?ェテ」ツ?」テ」ツ?ヲテ」ツ??」ツつ凝・ツ?エテ・ツ青暗」ツ?ッテ、ツコツ、テ・ツキツョテヲツ可アテ」ツ?? //verified QUPC-G bool iCS(C c, S l) { int c1 = contains(c, l.p1); int c2 = contains(c, l.p2); if (c1 > c2) swap(c1, c2); // (OUT, OUT) (OUT, ON) (OUT, IN) (ON, ON) (ON, IN) (IN, IN) // テ」ツ?ョ6テゥツ?堙」ツつ? if (c1 == OUT && c2 == IN) return true; if (c1 == IN && c2 == IN) return false; if (c1 == ON) return true; // (テヲツ篠・テ」ツ?凖」ツつ凝」ツ?ィテ」ツ?? double d = dSP(l, c.p); if (d - c.r < -EPS) return true; if (d - c.r > EPS) return false; return true; // (テヲツ篠・テ」ツ?凖」ツつ凝」ツ?ィテ」ツ?? } //テ・ツ債佚ァツエツ氾・ツ、ツ堙ィツァツ津・ツスツ「テ・ツ按、テ・ツョツ? bool isSimple(Polygon pol) { //テ・ツ按敕」ツつ?」ツ?ョテァツつケテ」ツつ津ゥツ?催ィツ、ツ?」ツ?療」ツ?ヲpolテ」ツ?ォテ・ツ?・テ」ツつ古」ツ?ヲテ」ツ?甘」ツ?? size_t pol_size = pol.size() - 1; rep(i, pol_size) { for (int j = i + 2; j < pol_size; j++) { if (i == j || i == (j - 1 + pol_size) % pol_size || i == (j + 1 + pol_size) % pol_size) continue; if (intersect(pol[i], pol[i + 1], pol[j], pol[j + 1])) return false; } } return true; } //テァツつケテ」ツ?古・ツ?クテ・ツ、ツ堙ィツァツ津・ツスツ「テ」ツ?ョテ・ツ??・ツ?エテ」ツ?ォテ」ツ?づ」ツつ凝」ツ?凝」ツ?ゥテ」ツ??」ツ?凝」ツつ津ヲツアツづ」ツつ?」ツつ?trueテ」ツ?ェテ」ツつ嘉・ツ??・ツ?エ //verified AOJ0012 int isPointInsidePolygon(vector<P> pol, P p) { int c = 0; rep(i, pol.size()) { if (cross(pol[i] - pol[(i + 1) % pol.size()], p - pol[(i + 1) % pol.size()]) == 0) return ON; if (cross(pol[i] - pol[(i + 1) % pol.size()], p - pol[(i + 1) % pol.size()]) > 0) c++; } if (c % pol.size()) return OUT; return IN; } //テ・ツ??」ツ?ィテ・ツ?クテ・ツ、ツ堙ィツァツ津・ツスツ「テ」ツ?ョテ、ツコツ、テ・ツキツョテァツ環カテヲツ?凝」ツつ津ィツェツソテ」ツ?ケテ」ツつ? int CPOLarea(C c, Polygon pol) { vector<L> lines; vector<int> res(pol.size()); bool POLinC = true, isFar = true; rep(i, pol.size()) { if (contains(c, pol[i]) == OUT) POLinC = false; res[i] = contains(c, pol[i]); lines.pb(L{pol[i], pol[(i + 1) % pol.size()]}); if (sqDist(c.p, pol[i]) < c.r * c.r) isFar = false; } if (POLinC) return 2; //テ・ツ、ツ堙ィツァツ津・ツスツ「テ」ツ?ッテ・ツ??」ツ?ョテ・ツ??ゥツδィb if (isPointInsidePolygon(pol, c.p) == IN && isFar) return 3; //テ・ツ、ツ堙ィツァツ津・ツスツ「テ」ツ?ョテ・ツ??ゥツδィテ」ツ?ォテ・ツ?? rep(i, lines.size()) if ( iCS(c, lines [i])) return 1; //テ・ツ、ツ堙ィツァツ津・ツスツ「テ」ツ?ィテ・ツ??」ツ?ッテ、ツコツ、テ・ツキツョc return 0; } //テ・ツ?クテ・ツ個?verified AOJ0068,QUPC-G //ティツセツ榲ヲツ崢クテゥツ??」ツ?ァテヲツッツ氾ィツシツ? bool cmp_x(const P &p, const P &q) { if (p.x != q.x) return p.x < q.x; return p.y < q.y; } //テ・ツ?クテ・ツ個?」ツつ津ヲツアツづ」ツつ?」ツつ? vector<P> convex_hull(vector<P> ps) { int n = ps.size(); sort(all(ps), cmp_x); int k = 0; //テ・ツ?クテ・ツ個?」ツ?ョテゥツ?づァツつケテヲツ閉ー vector<P> qs(n * 2); //テヲツァツ凝ヲツ按静、ツクツュテ」ツ?ョテ・ツ?クテ・ツ個? //テ、ツクツ凝・ツ?エテ・ツ?クテ・ツ個?」ツ?ョテ、ツスツ愿ヲツ按? rep(i, n) { while (k > 1 && cross((qs[k - 1] - qs[k - 2]), (ps[i] - qs[k - 1])) <= 0) k--; qs[k++] = ps[i]; } //テ、ツクツ甘・ツ?エテ・ツ?クテ・ツ個?」ツ?ョテ、ツスツ愿ヲツ按? for (int i = n - 2, t = k; i >= 0; i--) { while (k > t && cross((qs[k - 1] - qs[k - 2]), (ps[i] - qs[k - 1])) <= 0) k--; qs[k++] = ps[i]; } qs.resize(k - 1); return qs; } // 2テァツつケテ」ツつ津ゥツ?堙」ツつ凝・ツ債甘・ツセツвテ」ツ?ョテ・ツ??」ツ?ョテ、ツクツュテ・ツソツε・ツコツァテヲツィツ凖」ツつ津ヲツアツづ」ツつ?」ツつ? pair<P, P> geoGetCircleOf2pAndR(P p1, P p2, double r) { P pc1 = P(-INF, -INF), pc2(-INF, -INF), p3; double d, l, dx, dy; p3 = (p1 + p2) / 2.0; l = sqDist(p2, p3); if (r * r >= l) { d = sqrt(r * r / l - 1.0); dx = d * (p2.y - p3.y); dy = d * (p2.x - p3.x); pc1.x = p3.x + dx; pc1.y = p3.y - dy; pc2.x = p3.x - dx; pc2.y = p3.y + dy; } return pair<P, P>(pc1, pc2); } int main() { int n; while (cin >> n && n) { int ans = 1; vector<P> ps(n); rep(i, n) cin >> ps[i].x >> ps[i].y; rep(i, n) { for (int j = i + 1; j < n; j++) { if (dist(ps[i], ps[j]) > 2 + EPS) continue; pair<P, P> res = geoGetCircleOf2pAndR(ps[i], ps[j], 1); int suma = 0, sumb = 0; rep(k, n) { if (sqDist(ps[k], res.first) < 1 + EPS) suma++; if (sqDist(ps[k], res.second) < 1 + EPS) sumb++; } ans = max(ans, max(suma, sumb)); } } cout << ans << endl; } }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
1
2,330
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (N); i++) using namespace std; namespace geom { #define at(i) ((*this)[i]) #define pb push_back #define X real() #define Y imag() #define SELF (*this) typedef long double R; typedef complex<R> P; const R EPS = 1e-8; const R PI = 3.14159265358979323846264338327950288; enum { TURE = 1, FALSE = 0, BORDER = -1 }; inline int sig(const R &x) { return (abs(x) < EPS ? 0 : x > 0 ? 1 : -1); } inline int less(const R &x, const R &y) { return sig(x - y) ? x < y : BORDER; } inline R inp(const P &a, const P &b) { return (conj(a) * b).X; } inline R outp(const P &a, const P &b) { return (conj(a) * b).Y; } inline R norm(const P &p) { return p.X * p.X + p.Y * p.Y; } inline P unit(const P &p) { return p / abs(p); } inline P proj(const P &s, const P &t) { return t * inp(s, t) / norm(t); } struct L : public vector<P> { L(const P &p1, const P &p2) { this->pb(p1); this->pb(p2); } L() {} P dir() const { return at(1) - at(0); } int online(const P &p) const { return !sig(outp(p - at(0), dir())); } }; struct S : public L { S(const P &p1, const P &p2) : L(p1, p2) {} S() {} int online(const P &p) const { if (!sig(norm(p - at(0))) || !sig(norm(p - at(1)))) return BORDER; return !sig(outp(p - at(0), dir())) && inp(p - at(0), dir()) > EPS && inp(p - at(1), -dir()) > -EPS; } }; struct C : public P { C() {} C(const P &p, const R r) : P(p), r(r) {} R r; int inside(const P &p) const { return less(norm(p - SELF), r * r); } }; // inline P proj(const P &s,const L &t){return t[0] + proj(s-t[0], t[1]-t[0]);} inline int intersect(const C &a, const C &b) { return less((a.r - b.r) * (a.r - b.r), norm(a - b)) + less(norm(a - b), (a.r + b.r) * (a.r + b.r)) - 1; } inline S crosspoint(const C &c1, const C &c2) { if (!intersect(c1, c2)) return S(); R d = abs(c1 - c2); R x = (c1.r * c1.r - c2.r * c2.r + d * d) / (2 * d); R h = sqrt(max<R>(0., c1.r * c1.r - x * x)); P u = unit(c2 - c1); return S(c1 + u * x + u * P(0, -1) * h, c1 + u * x + u * P(0, 1) * h); } // inline S crosspoint(const C &c,const L &l){ // R d2=dist2(l,c); // if(c.r*c.r+EPS < d2) return S(); // P m= proj(c,l); // P u = unit(l[1]-l[0]); // R d=sqrt(max<R>(.0,c.r*c.r-d2)); // return S(m+u*d,m-u*d); // } S circlePPR(const P &a, const P &b, R r) { return crosspoint(C(a, r), C(b, r)); } } // namespace geom using namespace geom; int main() { int N; while (cin >> N, N) { int ans = 0; P po[305]; rep(i, N) { R x, y; cin >> x >> y; po[i] = P(x, y); } rep(i, N) rep(j, i) { // if( i==j ) continue; S s = circlePPR(po[i], po[j], 1.0); // if( s.empty() ) continue; // for(auto t: s) cout << t << " "; cout << endl; for (auto k : s) { int count = 0; rep(h, N) { if (abs(k - po[h]) < 1.0 + EPS) { count++; } } ans = max(ans, count); } } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (N); i++) using namespace std; namespace geom { #define at(i) ((*this)[i]) #define pb push_back #define X real() #define Y imag() #define SELF (*this) typedef long double R; typedef complex<R> P; const R EPS = 1e-8; const R PI = 3.14159265358979323846264338327950288; enum { TURE = 1, FALSE = 0, BORDER = -1 }; inline int sig(const R &x) { return (abs(x) < EPS ? 0 : x > 0 ? 1 : -1); } inline int less(const R &x, const R &y) { return sig(x - y) ? x < y : BORDER; } inline R inp(const P &a, const P &b) { return (conj(a) * b).X; } inline R outp(const P &a, const P &b) { return (conj(a) * b).Y; } inline R norm(const P &p) { return p.X * p.X + p.Y * p.Y; } inline P unit(const P &p) { return p / abs(p); } inline P proj(const P &s, const P &t) { return t * inp(s, t) / norm(t); } struct L : public vector<P> { L(const P &p1, const P &p2) { this->pb(p1); this->pb(p2); } L() {} P dir() const { return at(1) - at(0); } int online(const P &p) const { return !sig(outp(p - at(0), dir())); } }; struct S : public L { S(const P &p1, const P &p2) : L(p1, p2) {} S() {} int online(const P &p) const { if (!sig(norm(p - at(0))) || !sig(norm(p - at(1)))) return BORDER; return !sig(outp(p - at(0), dir())) && inp(p - at(0), dir()) > EPS && inp(p - at(1), -dir()) > -EPS; } }; struct C : public P { C() {} C(const P &p, const R r) : P(p), r(r) {} R r; int inside(const P &p) const { return less(norm(p - SELF), r * r); } }; // inline P proj(const P &s,const L &t){return t[0] + proj(s-t[0], t[1]-t[0]);} inline int intersect(const C &a, const C &b) { return less((a.r - b.r) * (a.r - b.r), norm(a - b)) + less(norm(a - b), (a.r + b.r) * (a.r + b.r)) - 1; } inline S crosspoint(const C &c1, const C &c2) { if (!intersect(c1, c2)) return S(); R d = abs(c1 - c2); R x = (c1.r * c1.r - c2.r * c2.r + d * d) / (2 * d); R h = sqrt(max<R>(0., c1.r * c1.r - x * x)); P u = unit(c2 - c1); return S(c1 + u * x + u * P(0, -1) * h, c1 + u * x + u * P(0, 1) * h); } // inline S crosspoint(const C &c,const L &l){ // R d2=dist2(l,c); // if(c.r*c.r+EPS < d2) return S(); // P m= proj(c,l); // P u = unit(l[1]-l[0]); // R d=sqrt(max<R>(.0,c.r*c.r-d2)); // return S(m+u*d,m-u*d); // } S circlePPR(const P &a, const P &b, R r) { return crosspoint(C(a, r), C(b, r)); } } // namespace geom using namespace geom; int main() { int N; while (cin >> N, N) { int ans = 1; P po[305]; rep(i, N) { R x, y; cin >> x >> y; po[i] = P(x, y); } rep(i, N) rep(j, i) { // if( i==j ) continue; S s = circlePPR(po[i], po[j], 1.0); // if( s.empty() ) continue; // for(auto t: s) cout << t << " "; cout << endl; for (auto k : s) { int count = 0; rep(h, N) { if (abs(k - po[h]) < 1.0 + EPS) { count++; } } ans = max(ans, count); } } cout << ans << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
1
991
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; ++i) struct Point { double x, y; }; double dist(Point a, Point b) { return sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2)); } #define eps 0.0001 int main(void) { int N; while (cin >> N, N) { vector<Point> p(N); int maxcnt = 0; rep(i, N) cin >> p[i].x >> p[i].y; rep(i, N) { for (int j = i + 1; j < N; j++) { double d = dist(p[i], p[j]); if (d > 2.0) continue; Point C1, C2; C1.x = p[i].x + cos(atan2(p[j].y - p[i].y, p[j].x - p[i].x) + acos(d / 2.0)); C1.y = p[i].y + sin(atan2(p[j].y - p[i].y, p[j].x - p[i].x) + acos(d / 2.0)); C2.x = p[i].x + cos(atan2(p[j].y - p[i].y, p[j].x - p[i].x) - acos(d / 2.0)); C2.y = p[i].y + sin(atan2(p[j].y - p[i].y, p[j].x - p[i].x) - acos(d / 2.0)); int cnt = 0; rep(k, N) { if (pow(C1.x - p[k].x, 2) + pow(C1.y - p[k].y, 2) <= 1.0 + eps) cnt++; } if (maxcnt < cnt) maxcnt = cnt; cnt = 0; rep(k, N) { if (pow(C2.x - p[k].x, 2) + pow(C2.y - p[k].y, 2) <= 1.0 + eps) cnt++; } if (maxcnt < cnt) maxcnt = cnt; } } cout << maxcnt << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; ++i) struct Point { double x, y; }; double dist(Point a, Point b) { return sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2)); } #define eps 0.0001 int main(void) { int N; while (cin >> N, N) { vector<Point> p(N); int maxcnt = 1; rep(i, N) cin >> p[i].x >> p[i].y; rep(i, N) { for (int j = i + 1; j < N; j++) { double d = dist(p[i], p[j]); if (d > 2.0) continue; Point C1, C2; C1.x = p[i].x + cos(atan2(p[j].y - p[i].y, p[j].x - p[i].x) + acos(d / 2.0)); C1.y = p[i].y + sin(atan2(p[j].y - p[i].y, p[j].x - p[i].x) + acos(d / 2.0)); C2.x = p[i].x + cos(atan2(p[j].y - p[i].y, p[j].x - p[i].x) - acos(d / 2.0)); C2.y = p[i].y + sin(atan2(p[j].y - p[i].y, p[j].x - p[i].x) - acos(d / 2.0)); int cnt = 0; rep(k, N) { if (pow(C1.x - p[k].x, 2) + pow(C1.y - p[k].y, 2) <= 1.0 + eps) cnt++; } if (maxcnt < cnt) maxcnt = cnt; cnt = 0; rep(k, N) { if (pow(C2.x - p[k].x, 2) + pow(C2.y - p[k].y, 2) <= 1.0 + eps) cnt++; } if (maxcnt < cnt) maxcnt = cnt; } } cout << maxcnt << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
1
524
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; ++i) struct Point { double x, y; }; double dist(Point a, Point b) { return sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2)); } int main(void) { int N; while (cin >> N, N) { vector<Point> p(N); int maxcnt = 1; rep(i, N) cin >> p[i].x >> p[i].y; rep(i, N) { for (int j = i + 1; j < N; j++) { double d = dist(p[i], p[j]); if (d > 2.0) continue; int sign[] = {-1, 1}; rep(s, 2) { Point C; C.x = p[i].x + cos(atan2(p[j].y - p[i].y, p[j].x - p[i].x) + sign[s] * acos(d / 2.0)); C.y = p[i].y + sin(atan2(p[j].y - p[i].y, p[j].x - p[i].x) + sign[s] * acos(d / 2.0)); int cnt = 0; rep(k, N) cnt += (pow(C.x - p[k].x, 2) + pow(C.y - p[k].y, 2) <= 1.0); if (maxcnt < cnt) maxcnt = cnt; } } } cout << maxcnt << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; ++i) struct Point { double x, y; }; double dist(Point a, Point b) { return sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2)); } int main(void) { int N; while (cin >> N, N) { vector<Point> p(N); int maxcnt = 1; rep(i, N) cin >> p[i].x >> p[i].y; rep(i, N) { for (int j = i + 1; j < N; j++) { double d = dist(p[i], p[j]); if (d > 2.0) continue; int sign[] = {-1, 1}; rep(s, 2) { Point C; C.x = p[i].x + cos(atan2(p[j].y - p[i].y, p[j].x - p[i].x) + sign[s] * acos(d / 2.0)); C.y = p[i].y + sin(atan2(p[j].y - p[i].y, p[j].x - p[i].x) + sign[s] * acos(d / 2.0)); int cnt = 0; rep(k, N) cnt += (pow(C.x - p[k].x, 2) + pow(C.y - p[k].y, 2) <= 1.0001); if (maxcnt < cnt) maxcnt = cnt; } } } cout << maxcnt << endl; } return 0; }
[["-", 0, 1, 0, 11, 12, 23, 0, 16, 12, 13], ["+", 0, 1, 0, 11, 12, 23, 0, 16, 12, 13]]
1
377
#include <bits/stdc++.h> using namespace std; #define rep(i, n) REP(i, 0, n) #define REP(i, s, e) for (int i = (int)(s); i < (int)(e); ++i) #define X() real() #define Y() imag() #define x(p) (p).X() #define y(p) (p).Y() #define SZ(P) (int)(P.size()) #define curr(P, i) P[(i) % SZ(P)] #define next(P, i) P[(i + 1) % SZ(P)] #define prev(P, i) P[(i + SZ(P) - 1) % SZ(P)] ? ´ using D = double; using P = complex<D>; namespace std { bool operator<(const P &a, const P &b) { return x(a) != x(b) ? x(a) < x(b) : y(a) < y(b); } } // namespace std D dot(const P &a, const P &b) { return x(conj(a) * b); } D cross(const P &a, const P &b) { return y(conj(a) * b); } int ccw(P a, P b, P c) { b -= a; c -= a; if (cross(b, c) > 0) return +1; if (cross(b, c) < 0) return -1; if (dot(b, c) < 0) return +2; if (norm(b) < norm(c)) return -2; return 0; } const D EPS = 1e-8; const D PI = acos(-1); struct C { P p; D r; }; P makeP(D arg, D r = 1.0) { return r * P{cos(arg), sin(arg)}; } P rotP(const P &p, D arg) { return p * makeP(arg); } vector<P> getNorm(const P &p) { return {rotP(p, PI / 2.0) / abs(p), rotP(p, -PI / 2.0) / abs(p)}; } vector<C> makeC(const P &a, const P &b, D r = 1.0) { P m = (a + b) / 2.0; D d = sqrt(r * r - abs(m - a) * abs(m - a)); auto ps = getNorm(b - a); rep(i, 2) ps[i] = d * ps[i] + m; vector<C> ret; rep(i, 2) ret.push_back(C{ps[i], r}); return ret; } bool include(const C &c, const P &p) { return abs(c.p - p) < c.r + EPS; } int main() { int n; while (cin >> n && n) { vector<P> ps(n); rep(i, n) { D x, y; cin >> x >> y; ps[i] = P{x, y}; } int ans = 0; rep(i, n) rep(j, i) { auto cs = makeC(ps[i], ps[j]); for (auto &c : cs) { int tmp = 0; rep(k, n) if (include(c, ps[k])) tmp++; ans = max(ans, tmp); } } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) REP(i, 0, n) #define REP(i, s, e) for (int i = (int)(s); i < (int)(e); ++i) #define X() real() #define Y() imag() #define x(p) (p).X() #define y(p) (p).Y() #define SZ(P) (int)(P.size()) #define curr(P, i) P[(i) % SZ(P)] #define next(P, i) P[(i + 1) % SZ(P)] #define prev(P, i) P[(i + SZ(P) - 1) % SZ(P)] ? ´ using D = double; using P = complex<D>; namespace std { bool operator<(const P &a, const P &b) { return x(a) != x(b) ? x(a) < x(b) : y(a) < y(b); } } // namespace std D dot(const P &a, const P &b) { return x(conj(a) * b); } D cross(const P &a, const P &b) { return y(conj(a) * b); } int ccw(P a, P b, P c) { b -= a; c -= a; if (cross(b, c) > 0) return +1; if (cross(b, c) < 0) return -1; if (dot(b, c) < 0) return +2; if (norm(b) < norm(c)) return -2; return 0; } const D EPS = 1e-8; const D PI = acos(-1); struct C { P p; D r; }; P makeP(D arg, D r = 1.0) { return r * P{cos(arg), sin(arg)}; } P rotP(const P &p, D arg) { return p * makeP(arg); } vector<P> getNorm(const P &p) { return {rotP(p, PI / 2.0) / abs(p), rotP(p, -PI / 2.0) / abs(p)}; } vector<C> makeC(const P &a, const P &b, D r = 1.0) { P m = (a + b) / 2.0; D d = sqrt(r * r - abs(m - a) * abs(m - a)); auto ps = getNorm(b - a); rep(i, 2) ps[i] = d * ps[i] + m; vector<C> ret; rep(i, 2) ret.push_back(C{ps[i], r}); return ret; } bool include(const C &c, const P &p) { return abs(c.p - p) < c.r + EPS; } int main() { int n; while (cin >> n && n) { vector<P> ps(n); rep(i, n) { D x, y; cin >> x >> y; ps[i] = P{x, y}; } int ans = 1; rep(i, n) rep(j, i) { auto cs = makeC(ps[i], ps[j]); for (auto &c : cs) { int tmp = 0; rep(k, n) if (include(c, ps[k])) tmp++; ans = max(ans, tmp); } } cout << ans << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
1
696
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef complex<double> P; typedef pair<int, int> pii; #define REP(i, n) for (ll i = 0; i < n; ++i) #define REPR(i, n) for (ll i = 1; i < n; ++i) #define FOR(i, a, b) for (ll i = a; i < b; ++i) #define DEBUG(x) cout << #x << ": " << x << endl #define DEBUG_VEC(v) \ cout << #v << ":"; \ REP(i, v.size()) cout << " " << v[i]; \ cout << endl #define ALL(a) (a).begin(), (a).end() #define MOD (ll)(1e9 + 7) #define ADD(a, b) a = ((a) + (b)) % MOD #define FIX(a) ((a) % MOD + MOD) % MOD int n; P pts[353]; int check(P c) { int ret = 0; REP(i, n) { if (abs(c - pts[i]) <= 1.00001) ret++; } return ret; } int main() { while (true) { scanf("%d", &n); if (n == 0) break; REP(i, n) { double x, y; scanf("%lf%lf", &x, &y); pts[i] = P(x, y); } int ans = 0; REP(i, n) REP(j, i) { P a, b; a = pts[i]; b = pts[j]; double l = abs(b - a); if (l > 2.0) continue; double h = sqrt(1.0 - l * l / 4.0); P c; c = a + (b - a) / 2.0 + (b - a) * P(0, 1) * h / l; ans = max(ans, check(c)); c = a + (b - a) / 2.0 + (b - a) * P(0, -1) * h / l; ans = max(ans, check(c)); } printf("%d\n", ans); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef complex<double> P; typedef pair<int, int> pii; #define REP(i, n) for (ll i = 0; i < n; ++i) #define REPR(i, n) for (ll i = 1; i < n; ++i) #define FOR(i, a, b) for (ll i = a; i < b; ++i) #define DEBUG(x) cout << #x << ": " << x << endl #define DEBUG_VEC(v) \ cout << #v << ":"; \ REP(i, v.size()) cout << " " << v[i]; \ cout << endl #define ALL(a) (a).begin(), (a).end() #define MOD (ll)(1e9 + 7) #define ADD(a, b) a = ((a) + (b)) % MOD #define FIX(a) ((a) % MOD + MOD) % MOD int n; P pts[353]; int check(P c) { int ret = 0; REP(i, n) { if (abs(c - pts[i]) <= 1.00001) ret++; } return ret; } int main() { while (true) { scanf("%d", &n); if (n == 0) break; REP(i, n) { double x, y; scanf("%lf%lf", &x, &y); pts[i] = P(x, y); } int ans = 1; REP(i, n) REP(j, i) { P a, b; a = pts[i]; b = pts[j]; double l = abs(b - a); if (l > 2.0) continue; double h = sqrt(1.0 - l * l / 4.0); P c; c = a + (b - a) / 2.0 + (b - a) * P(0, 1) * h / l; ans = max(ans, check(c)); c = a + (b - a) / 2.0 + (b - a) * P(0, -1) * h / l; ans = max(ans, check(c)); } printf("%d\n", ans); } return 0; }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
1
390
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a); i < int(b); ++i) #define REP(i, n) FOR(i, 0, n) int main() { cin.tie(0); ios_base::sync_with_stdio(false); int N; while (cin >> N, N) { static const complex<double> I = complex<double>(0, -1); using Point = complex<double>; vector<Point> points(N); REP(i, N) { double x, y; cin >> x >> y; points[i] = Point(x, y); } int ans = 0; REP(i, N) FOR(j, i + 1, N) { auto x = points[i]; auto y = points[j]; double l_sq = norm(x - y); if (l_sq > 4) continue; for (double d : {-1, 1}) { Point middle = 0.5 * (x + y); Point dir = (x - y) * I; dir /= abs(dir); Point center = middle + d * sqrt(1 - l_sq / 4) * dir; int count = 0; REP(k, N) { if (norm(center - points[k]) <= 1 + 1e-10) ++count; } ans = max(ans, count); } } cout << ans << '\n'; } }
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a); i < int(b); ++i) #define REP(i, n) FOR(i, 0, n) int main() { cin.tie(0); ios_base::sync_with_stdio(false); int N; while (cin >> N, N) { static const complex<double> I = complex<double>(0, -1); using Point = complex<double>; vector<Point> points(N); REP(i, N) { double x, y; cin >> x >> y; points[i] = Point(x, y); } int ans = 1; REP(i, N) FOR(j, i + 1, N) { auto x = points[i]; auto y = points[j]; double l_sq = norm(x - y); if (l_sq > 4) continue; for (double d : {-1, 1}) { Point middle = 0.5 * (x + y); Point dir = (x - y) * I; dir /= abs(dir); Point center = middle + d * sqrt(1 - l_sq / 4) * dir; int count = 0; REP(k, N) { if (norm(center - points[k]) <= 1 + 1e-10) ++count; } ans = max(ans, count); } } cout << ans << '\n'; } }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
1
291
#include <algorithm> #include <cmath> #include <cstdio> #include <ctime> #include <functional> #include <iostream> #include <queue> #include <set> #include <vector> using namespace std; #define fst first #define snd second #define all(c) ((c).begin()), ((c).end()) #define TEST(x, a) \ { \ auto y = (x); \ if (sign(y - a)) { \ cout << "line " << __LINE__ << #x << " = " << y << " != " << a << endl; \ exit(-1); \ } \ } double urand() { return rand() / (1.0 + RAND_MAX); } const double PI = acos(-1.0); // implementation note: use EPS only this function // usage note: check sign(x) < 0, sign(x) > 0, or sign(x) == 0 // notice: should be normalize to O(1) const double EPS = 1e-8; int sign(double x) { if (x < -EPS) return -1; if (x > +EPS) return +1; return 0; } struct point { typedef double T; T x, y; point &operator+=(point p) { x += p.x; y += p.y; return *this; } point &operator-=(point p) { x -= p.x; y -= p.y; return *this; } point &operator*=(T a) { x *= a; y *= a; return *this; } point &operator/=(T a) { return *this *= (1.0 / a); } point operator-() const { return {-x, -y}; } bool operator==(point p) const { return !sign(x - p.x) && !sign(y - p.y); } bool operator!=(point p) const { return !operator==(p); } bool operator<(point p) const { return x != p.x ? x < p.x : y < p.y; } // for sort }; point operator+(point p, point q) { return p += q; } point operator-(point p, point q) { return p -= q; } point operator*(point::T a, point p) { return p *= a; } point operator*(point p, point::T a) { return p *= a; } point operator/(point p, point::T a) { return p /= a; } point::T dot(point p, point q) { return p.x * q.x + p.y * q.y; } point::T cross(point p, point q) { return p.x * q.y - p.y * q.x; } // left turn > 0 point::T norm2(point p) { return dot(p, p); } point::T norm(point p) { return sqrt(dot(p, p)); } point::T dist(point p, point q) { return norm(p - q); } point orth(point p) { return {-p.y, p.x}; } istream &operator>>(istream &is, point &p) { is >> p.x >> p.y; return is; } ostream &operator<<(ostream &os, const point &p) { os << "(" << p.x << "," << p.y << ")"; return os; } int maximum_circle_cover(vector<point> ps, double r) { struct range { point p; // center double w; // width int hi; bool operator<(range r) const { return hi < r.hi; } }; double w = 0; for (point p : ps) w = max({w, abs(p.x), abs(p.y)}); priority_queue<range> que; que.push({{0, 0}, w, (int)ps.size()}); point best_p; int best = 0; while (!que.empty()) { range R = que.top(); que.pop(); if (R.hi <= best) continue; // cout << "processing " << R.p << " " << R.w << " " << R.hi << "/" << best // << endl; double dx[] = {1, -1, -1, 1}, dy[] = {1, 1, -1, -1}; for (int i = 0; i < 4; ++i) { range S = {R.p, R.w / 2, 0}; S.p += S.w * point({dx[i], dy[i]}); int lo = 0; for (point q : ps) { auto d = dist(S.p, q); if (sign(d - r) <= 0) ++lo; if (sign(d - S.w * sqrt(2) - r) <= 0) ++S.hi; } if (lo > best) { best = lo; best_p = S.p; } best = max(lo, best); if (S.hi > best) que.push(S); } } return best; // best_p; } int maximum_circle_cover3(vector<point> ps, double r) { point best_p; int best = 0; function<void(point, double, vector<point> &)> rec = [&](point p, double w, vector<point> &ps) { w /= 2; const double dx[] = {1, -1, -1, 1}, dy[] = {1, 1, -1, -1}; point qs[4]; vector<point> pss[4]; for (int i = 0; i < 4; ++i) { qs[i] = p + w * point({dx[i], dy[i]}); int lo = 0; for (point q : ps) { auto d = dist(qs[i], q); if (sign(d - r) <= 0) ++lo; if (sign(d - w * sqrt(2) - r) <= 0) pss[i].push_back(q); } if (lo > best) { best = lo; best_p = qs[i]; } } int a = 0, b = 1, c = 2, d = 3; auto SW = [&](int &a, int &b) { if (pss[a].size() > pss[b].size()) swap(a, b); }; SW(a, b); SW(c, d); SW(b, d); SW(a, c); SW(b, c); if (pss[d].size() > best) rec(qs[d], w, pss[d]); if (pss[b].size() > best) rec(qs[b], w, pss[b]); if (pss[c].size() > best) rec(qs[c], w, pss[c]); if (pss[a].size() > best) rec(qs[a], w, pss[a]); }; double w = 0; for (point p : ps) w = max({w, abs(p.x), abs(p.y)}); rec({0, 0}, w, ps); return best; // best_p; } int maximum_circle_cover2(vector<point> ps, double r) { int best = 0; for (point p : ps) { int count = 0; vector<pair<double, int>> aux; for (point q : ps) { auto d = dist(p, q); if (sign(d) == 0) ++count; else if (sign(d - 2 * r) <= 0) { double theta = atan2(q.y - p.y, q.x - p.x); double phi = acos(min(1., d / (2 * r))); aux.push_back({theta - phi, -1}); aux.push_back({theta + phi, +1}); } } sort(all(aux)); /* cout << "for point " << p << endl; for (auto a: aux) cout << "(" << a.fst << "," << a.snd << ") "; cout << endl; */ for (auto a : aux) best = max(best, count -= a.snd); } return best; } void verify_maximum_circle_cover2() { for (int n; scanf("%d", &n) && n;) { vector<point> ps(n); for (int i = 0; i < n; ++i) scanf("%lf %lf", &ps[i].x, &ps[i].y); printf("%d\n", maximum_circle_cover2(ps, 1.0)); } } int main() { // verify_maximum_circle_cover(); verify_maximum_circle_cover2(); }
#include <algorithm> #include <cmath> #include <cstdio> #include <ctime> #include <functional> #include <iostream> #include <queue> #include <set> #include <vector> using namespace std; #define fst first #define snd second #define all(c) ((c).begin()), ((c).end()) #define TEST(x, a) \ { \ auto y = (x); \ if (sign(y - a)) { \ cout << "line " << __LINE__ << #x << " = " << y << " != " << a << endl; \ exit(-1); \ } \ } double urand() { return rand() / (1.0 + RAND_MAX); } const double PI = acos(-1.0); // implementation note: use EPS only this function // usage note: check sign(x) < 0, sign(x) > 0, or sign(x) == 0 // notice: should be normalize to O(1) const double EPS = 1e-8; int sign(double x) { if (x < -EPS) return -1; if (x > +EPS) return +1; return 0; } struct point { typedef double T; T x, y; point &operator+=(point p) { x += p.x; y += p.y; return *this; } point &operator-=(point p) { x -= p.x; y -= p.y; return *this; } point &operator*=(T a) { x *= a; y *= a; return *this; } point &operator/=(T a) { return *this *= (1.0 / a); } point operator-() const { return {-x, -y}; } bool operator==(point p) const { return !sign(x - p.x) && !sign(y - p.y); } bool operator!=(point p) const { return !operator==(p); } bool operator<(point p) const { return x != p.x ? x < p.x : y < p.y; } // for sort }; point operator+(point p, point q) { return p += q; } point operator-(point p, point q) { return p -= q; } point operator*(point::T a, point p) { return p *= a; } point operator*(point p, point::T a) { return p *= a; } point operator/(point p, point::T a) { return p /= a; } point::T dot(point p, point q) { return p.x * q.x + p.y * q.y; } point::T cross(point p, point q) { return p.x * q.y - p.y * q.x; } // left turn > 0 point::T norm2(point p) { return dot(p, p); } point::T norm(point p) { return sqrt(dot(p, p)); } point::T dist(point p, point q) { return norm(p - q); } point orth(point p) { return {-p.y, p.x}; } istream &operator>>(istream &is, point &p) { is >> p.x >> p.y; return is; } ostream &operator<<(ostream &os, const point &p) { os << "(" << p.x << "," << p.y << ")"; return os; } int maximum_circle_cover(vector<point> ps, double r) { struct range { point p; // center double w; // width int hi; bool operator<(range r) const { return hi < r.hi; } }; double w = 0; for (point p : ps) w = max({w, abs(p.x), abs(p.y)}); priority_queue<range> que; que.push({{0, 0}, w, (int)ps.size()}); point best_p; int best = 0; while (!que.empty()) { range R = que.top(); que.pop(); if (R.hi <= best) continue; // cout << "processing " << R.p << " " << R.w << " " << R.hi << "/" << best // << endl; double dx[] = {1, -1, -1, 1}, dy[] = {1, 1, -1, -1}; for (int i = 0; i < 4; ++i) { range S = {R.p, R.w / 2, 0}; S.p += S.w * point({dx[i], dy[i]}); int lo = 0; for (point q : ps) { auto d = dist(S.p, q); if (sign(d - r) <= 0) ++lo; if (sign(d - S.w * sqrt(2) - r) <= 0) ++S.hi; } if (lo > best) { best = lo; best_p = S.p; } best = max(lo, best); if (S.hi > best) que.push(S); } } return best; // best_p; } int maximum_circle_cover3(vector<point> ps, double r) { point best_p; int best = 0; function<void(point, double, vector<point> &)> rec = [&](point p, double w, vector<point> &ps) { w /= 2; const double dx[] = {1, -1, -1, 1}, dy[] = {1, 1, -1, -1}; point qs[4]; vector<point> pss[4]; for (int i = 0; i < 4; ++i) { qs[i] = p + w * point({dx[i], dy[i]}); int lo = 0; for (point q : ps) { auto d = dist(qs[i], q); if (sign(d - r) <= 0) ++lo; if (sign(d - w * sqrt(2) - r) <= 0) pss[i].push_back(q); } if (lo > best) { best = lo; best_p = qs[i]; } } int a = 0, b = 1, c = 2, d = 3; auto SW = [&](int &a, int &b) { if (pss[a].size() > pss[b].size()) swap(a, b); }; SW(a, b); SW(c, d); SW(b, d); SW(a, c); SW(b, c); if (pss[d].size() > best) rec(qs[d], w, pss[d]); if (pss[b].size() > best) rec(qs[b], w, pss[b]); if (pss[c].size() > best) rec(qs[c], w, pss[c]); if (pss[a].size() > best) rec(qs[a], w, pss[a]); }; double w = 0; for (point p : ps) w = max({w, abs(p.x), abs(p.y)}); rec({0, 0}, w, ps); return best; // best_p; } int maximum_circle_cover2(vector<point> ps, double r) { int best = 0; for (point p : ps) { int count = 0; vector<pair<double, int>> aux; for (point q : ps) { auto d = dist(p, q); if (sign(d) == 0) ++count; else if (sign(d - 2 * r) <= 0) { double theta = atan2(q.y - p.y, q.x - p.x); double phi = acos(min(1., d / (2 * r))); aux.push_back({theta - phi, -1}); aux.push_back({theta + phi, +1}); } } sort(all(aux)); /* cout << "for point " << p << endl; for (auto a: aux) cout << "(" << a.fst << "," << a.snd << ") "; cout << endl; */ for (auto a : aux) best = max(best, count -= a.snd); } return best; } void verify_maximum_circle_cover2() { for (int n; scanf("%d", &n) && n;) { vector<point> ps(n); for (int i = 0; i < n; ++i) scanf("%lf %lf", &ps[i].x, &ps[i].y); printf("%d\n", maximum_circle_cover(ps, 1.0)); } } int main() { // verify_maximum_circle_cover(); verify_maximum_circle_cover2(); }
[["-", 0, 1, 0, 2, 3, 4, 0, 2, 63, 22], ["+", 0, 1, 0, 2, 3, 4, 0, 2, 63, 22]]
1
1,753
/*include*/ #include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <set> #include <string> #include <utility> #include <vector> #define loop(i, a, b) for (int i = a; i < b; i++) #define rep(i, a) loop(i, 0, a) #define rp(a) while (a--) #define pb push_back #define mp make_pair #define it ::iterator #define all(in) in.begin(), in.end() #define shosu(x) fixed << setprecision(x) const double PI = acos(-1); const double EPS = 1e-10; const double inf = 1e8; using namespace std; #define shosu(x) fixed << setprecision(x) typedef complex<double> P; typedef vector<P> G; typedef vector<int> vi; typedef vector<vi> vvi; struct L : public vector<P> { L(const P &a, const P &b) { push_back(a); push_back(b); } }; struct C { P c; double r; C(const P &c, double r) : c(c), r(r) {} }; #define curr(P, i) P[i] #define next(P, i) P[(i + 1) % P.size()] #define diff(P, i) (next(P, i) - curr(P, i)) namespace std { bool operator<(const P &a, const P &b) { return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b); // return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b); } bool operator==(const P &a, const P &b) { return a.real() == b.real() && a.imag() == b.imag(); } } // namespace std P pin() { double x, y; char d; cin >> x >> y; P p(x, y); return p; } void PIN(P *a, int n) { rep(i, n) a[i] = pin(); } double dot(P a, P b) { return real(conj(a) * b); } double cross(P a, P b) { return imag(conj(a) * b); } int ccw(P a, P b, P c) { b -= a; c -= a; if (cross(b, c) > 0) return +1; // counter clockwise if (cross(b, c) < 0) return -1; // clockwise if (dot(b, c) < 0) return +2; // c--a--b on line if (norm(b) < norm(c)) return -2; // a--b--c on line return 0; } P projection(L a, P p) { double t = dot(p - a[0], a[0] - a[1]) / norm(a[0] - a[1]); return a[0] + t * (a[0] - a[1]); } P reflection(L a, P p) { return p + 2.0 * (projection(a, p) - p); } bool intersectLL(const L &l, const L &m) { return abs(cross(l[1] - l[0], m[1] - m[0])) > EPS || // non-parallel abs(cross(l[1] - l[0], m[0] - l[0])) < EPS; // same line } bool intersectLS(const L &l, const L &s) { return cross(l[1] - l[0], s[0] - l[0]) * // s[0] is left of l cross(l[1] - l[0], s[1] - l[0]) < EPS; // s[1] is right of l } bool intersectLP(const L &l, const P &p) { return abs(cross(l[1] - p, l[0] - p)) < EPS; } bool intersectSS(const L &s, const L &t) { return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 && ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0; } bool intersectSP(const L &s, const P &p) { return abs(s[0] - p) + abs(s[1] - p) - abs(s[1] - s[0]) < EPS; // triangle inequality } double distanceLP(const L &l, const P &p) { return abs(p - projection(l, p)); } double distanceLL(const L &l, const L &m) { return intersectLL(l, m) ? 0 : distanceLP(l, m[0]); } double distanceLS(const L &l, const L &s) { if (intersectLS(l, s)) return 0; return min(distanceLP(l, s[0]), distanceLP(l, s[1])); } double distanceSP(const L &s, const P &p) { const P r = projection(s, p); if (intersectSP(s, r)) return abs(r - p); return min(abs(s[0] - p), abs(s[1] - p)); } double distanceSS(const L &s, const L &t) { if (intersectSS(s, t)) return 0; return min(min(distanceSP(s, t[0]), distanceSP(s, t[1])), min(distanceSP(t, s[0]), distanceSP(t, s[1]))); } /*bool intersectCS(C c,const L &l){ return (distanceLP(l,c.c) < c.r+EPS && (c.r < abs(c.c-l[0]) + EPS || c.r < abs(c.c-l[1]) + EPS)); }*/ int intersectCS(C c, L l) { if (norm(projection(l, c.c) - c.c) - c.r * c.r > EPS) return 0; const double d1 = abs(c.c - l[0]), d2 = abs(c.c - l[1]); if (d1 < c.r + EPS && d2 < c.r + EPS) return 0; if (d1 < c.r - EPS && d2 > c.r + EPS || d1 > c.r + EPS && d2 < c.r - EPS) return 1; const P h = projection(l, c.c); if (dot(l[0] - h, l[1] - h) < 0) return 2; return 0; } P crosspointSS(L a, L b) { double t1 = abs(cross(a[1] - a[0], b[0] - a[0])); double t2 = abs(cross(a[1] - a[0], b[1] - a[0])); return b[0] + (b[1] - b[0]) * t1 / (t1 + t2); } L crosspointCL(C c, L l) { P pr = projection(l, c.c); P e = (l[1] - l[0]) / abs(l[1] - l[0]); double t = sqrt(c.r * c.r - norm(pr - c.c)); P a = pr + t * e; P b = pr - t * e; if (b < a) swap(a, b); return L(a, b); } L crosspointCS(C c, L l) { if (intersectCS(c, l) == 2) return crosspointCL(c, l); L ret = crosspointCL(c, l); if (dot(l[0] - ret[0], l[1] - ret[0]) < 0) ret[1] = ret[0]; else ret[0] = ret[1]; return ret; } L crosspointCC(C a, C b) { P tmp = b.c - a.c; double d = abs(tmp); double q = acos((a.r * a.r + d * d - b.r * b.r) / (2 * a.r * d)); double t = arg(tmp); // atan(tmp.imag()/tmp.real()); P p1 = a.c + polar(a.r, t + q); P p2 = a.c + polar(a.r, t - q); if (p2 < p1) swap(p1, p2); return L(p1, p2); } P crosspointLL(const L &l, const L &m) { double A = cross(l[1] - l[0], m[1] - m[0]); double B = cross(l[1] - l[0], l[1] - m[0]); if (abs(A) < EPS && abs(B) < EPS) return m[0]; // same line return m[0] + B / A * (m[1] - m[0]); } double area(const G &g) { double S = 0; for (int i = 0; i < g.size(); i++) { S += (cross(g[i], g[(i + 1) % g.size()])); } return abs(S / 2.0); } bool isconvex(const G &g) { int n = g.size(); rep(i, n) if (ccw(g[(i + n - 1) % n], g[i % n], g[(i + 1) % n]) == -1) return false; return true; } int inconvex(const G &g, const P &p) { bool in = false; int n = g.size(); rep(i, n) { P a = g[i % n] - p; P b = g[(i + 1) % n] - p; if (imag(a) > imag(b)) swap(a, b); if (imag(a) < EPS && 0 < imag(b)) if (cross(a, b) < 0) in = !in; if (abs(cross(a, b)) < EPS && dot(a, b) < EPS) return 1; // ON } return in ? 2 : 0; // IN : OUT; } G convex_hull(G &ps) { int n = ps.size(), k = 0; sort(ps.begin(), ps.end()); G ch(2 * n); for (int i = 0; i < n; ch[k++] = ps[i++]) // lower-hull while (k >= 2 && ccw(ch[k - 2], ch[k - 1], ps[i]) == -1) --k; //<=0 -> ==-1 for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = ps[i--]) // upper-hull while (k >= t && ccw(ch[k - 2], ch[k - 1], ps[i]) == -1) --k; // ch.resize(k - 1); return ch; } double convex_diameter(const G &pt) { const int n = pt.size(); int is = 0, js = 0; for (int i = 1; i < n; ++i) { if (imag(pt[i]) > imag(pt[is])) is = i; if (imag(pt[i]) < imag(pt[js])) js = i; } double maxd = norm(pt[is] - pt[js]); int i, maxi, j, maxj; i = maxi = is; j = maxj = js; do { if (cross(diff(pt, i), diff(pt, j)) >= 0) j = (j + 1) % n; else i = (i + 1) % n; if (norm(pt[i] - pt[j]) > maxd) { maxd = norm(pt[i] - pt[j]); maxi = i; maxj = j; } } while (i != is || j != js); return sqrt(maxd); /* farthest pair is (maxi, maxj). */ } // convex_diameter(g) G convex_cut(const G &g, const L &l) { G Q; for (int i = 0; i < g.size(); ++i) { P a = curr(g, i), b = next(g, i); if (ccw(l[0], l[1], a) != -1) Q.push_back(a); if (ccw(l[0], l[1], a) * ccw(l[0], l[1], b) < 0) Q.push_back(crosspointLL(L(a, b), l)); } return Q; } P turn(P p, double t) { return p * exp(P(.0, t * PI / 180.0)); } P turn2(P p, double t) { return p * exp(P(.0, t)); } vector<L> tangentCC(C a, C b) { if (a.r < b.r) swap(a, b); double d = abs(a.c - b.c); vector<L> l; if (d < EPS) return l; if (a.r + b.r < d - EPS) { // hanareteiru double t = acos((a.r + b.r) / d); t = t * 180 / PI; l.pb(L(a.c + turn(a.r / d * (b.c - a.c), t), b.c + turn(b.r / d * (a.c - b.c), t))); l.pb(L(a.c + turn(a.r / d * (b.c - a.c), -t), b.c + turn(b.r / d * (a.c - b.c), -t))); } else if (a.r + b.r < d + EPS) { // kuttuiteiru soto P p = a.c + a.r / d * (b.c - a.c); l.pb(L(p, p + turn(b.c - a.c, 90))); } if (abs(a.r - b.r) < d - EPS) { // majiwatteiru double t1 = acos((a.r - b.r) / d); t1 = t1 * 180 / PI; double t2 = 180 - t1; l.pb(L(a.c + turn(a.r / d * (b.c - a.c), t1), b.c + turn(b.r / d * (a.c - b.c), -t2))); l.pb(L(a.c + turn(a.r / d * (b.c - a.c), -t1), b.c + turn(b.r / d * (a.c - b.c), t2))); } else if (abs(a.r - b.r) < d + EPS) { // kuttuiteiru uti P p = a.c + a.r / d * (b.c - a.c); l.pb(L(p, p + turn(b.c - a.c, 90))); } return l; } void printL(const L &out) { printf("%.9f %.9f %.9f %.9f\n", out[0].real(), out[0].imag(), out[1].real(), out[1].imag()); } C CIN() { P p = pin(); double r; cin >> r; return C(p, r); } bool para(L a, L b) { return (abs(cross(a[1] - a[0], b[1] - b[0])) < EPS); } double min(double a, double b) { return a < b ? a : b; } double max(double a, double b) { return a > b ? a : b; } int main() { int n; while (cin >> n, n) { G g(n); rep(i, n) g[i] = pin(); int out = 0; rep(i, n) rep(j, i) if (abs(g[i] - g[j]) < 2 + EPS) { double dis = abs(g[i] - g[j]); double c = atan(sqrt(4 / dis / dis - 1)); P tur = g[j] - g[i]; tur /= abs(tur); P p = g[i] + turn2(tur, c); int co = 0; rep(k, n) if (abs(p - g[k]) < 1 + EPS) co++; out = max(out, co); co = 0; p = g[i] + turn2(tur, -c); rep(k, n) if (abs(p - g[k]) < 1 + EPS) co++; out = max(out, co); } cout << out << endl; } }
/*include*/ #include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <set> #include <string> #include <utility> #include <vector> #define loop(i, a, b) for (int i = a; i < b; i++) #define rep(i, a) loop(i, 0, a) #define rp(a) while (a--) #define pb push_back #define mp make_pair #define it ::iterator #define all(in) in.begin(), in.end() #define shosu(x) fixed << setprecision(x) const double PI = acos(-1); const double EPS = 1e-10; const double inf = 1e8; using namespace std; #define shosu(x) fixed << setprecision(x) typedef complex<double> P; typedef vector<P> G; typedef vector<int> vi; typedef vector<vi> vvi; struct L : public vector<P> { L(const P &a, const P &b) { push_back(a); push_back(b); } }; struct C { P c; double r; C(const P &c, double r) : c(c), r(r) {} }; #define curr(P, i) P[i] #define next(P, i) P[(i + 1) % P.size()] #define diff(P, i) (next(P, i) - curr(P, i)) namespace std { bool operator<(const P &a, const P &b) { return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b); // return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b); } bool operator==(const P &a, const P &b) { return a.real() == b.real() && a.imag() == b.imag(); } } // namespace std P pin() { double x, y; char d; cin >> x >> y; P p(x, y); return p; } void PIN(P *a, int n) { rep(i, n) a[i] = pin(); } double dot(P a, P b) { return real(conj(a) * b); } double cross(P a, P b) { return imag(conj(a) * b); } int ccw(P a, P b, P c) { b -= a; c -= a; if (cross(b, c) > 0) return +1; // counter clockwise if (cross(b, c) < 0) return -1; // clockwise if (dot(b, c) < 0) return +2; // c--a--b on line if (norm(b) < norm(c)) return -2; // a--b--c on line return 0; } P projection(L a, P p) { double t = dot(p - a[0], a[0] - a[1]) / norm(a[0] - a[1]); return a[0] + t * (a[0] - a[1]); } P reflection(L a, P p) { return p + 2.0 * (projection(a, p) - p); } bool intersectLL(const L &l, const L &m) { return abs(cross(l[1] - l[0], m[1] - m[0])) > EPS || // non-parallel abs(cross(l[1] - l[0], m[0] - l[0])) < EPS; // same line } bool intersectLS(const L &l, const L &s) { return cross(l[1] - l[0], s[0] - l[0]) * // s[0] is left of l cross(l[1] - l[0], s[1] - l[0]) < EPS; // s[1] is right of l } bool intersectLP(const L &l, const P &p) { return abs(cross(l[1] - p, l[0] - p)) < EPS; } bool intersectSS(const L &s, const L &t) { return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 && ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0; } bool intersectSP(const L &s, const P &p) { return abs(s[0] - p) + abs(s[1] - p) - abs(s[1] - s[0]) < EPS; // triangle inequality } double distanceLP(const L &l, const P &p) { return abs(p - projection(l, p)); } double distanceLL(const L &l, const L &m) { return intersectLL(l, m) ? 0 : distanceLP(l, m[0]); } double distanceLS(const L &l, const L &s) { if (intersectLS(l, s)) return 0; return min(distanceLP(l, s[0]), distanceLP(l, s[1])); } double distanceSP(const L &s, const P &p) { const P r = projection(s, p); if (intersectSP(s, r)) return abs(r - p); return min(abs(s[0] - p), abs(s[1] - p)); } double distanceSS(const L &s, const L &t) { if (intersectSS(s, t)) return 0; return min(min(distanceSP(s, t[0]), distanceSP(s, t[1])), min(distanceSP(t, s[0]), distanceSP(t, s[1]))); } /*bool intersectCS(C c,const L &l){ return (distanceLP(l,c.c) < c.r+EPS && (c.r < abs(c.c-l[0]) + EPS || c.r < abs(c.c-l[1]) + EPS)); }*/ int intersectCS(C c, L l) { if (norm(projection(l, c.c) - c.c) - c.r * c.r > EPS) return 0; const double d1 = abs(c.c - l[0]), d2 = abs(c.c - l[1]); if (d1 < c.r + EPS && d2 < c.r + EPS) return 0; if (d1 < c.r - EPS && d2 > c.r + EPS || d1 > c.r + EPS && d2 < c.r - EPS) return 1; const P h = projection(l, c.c); if (dot(l[0] - h, l[1] - h) < 0) return 2; return 0; } P crosspointSS(L a, L b) { double t1 = abs(cross(a[1] - a[0], b[0] - a[0])); double t2 = abs(cross(a[1] - a[0], b[1] - a[0])); return b[0] + (b[1] - b[0]) * t1 / (t1 + t2); } L crosspointCL(C c, L l) { P pr = projection(l, c.c); P e = (l[1] - l[0]) / abs(l[1] - l[0]); double t = sqrt(c.r * c.r - norm(pr - c.c)); P a = pr + t * e; P b = pr - t * e; if (b < a) swap(a, b); return L(a, b); } L crosspointCS(C c, L l) { if (intersectCS(c, l) == 2) return crosspointCL(c, l); L ret = crosspointCL(c, l); if (dot(l[0] - ret[0], l[1] - ret[0]) < 0) ret[1] = ret[0]; else ret[0] = ret[1]; return ret; } L crosspointCC(C a, C b) { P tmp = b.c - a.c; double d = abs(tmp); double q = acos((a.r * a.r + d * d - b.r * b.r) / (2 * a.r * d)); double t = arg(tmp); // atan(tmp.imag()/tmp.real()); P p1 = a.c + polar(a.r, t + q); P p2 = a.c + polar(a.r, t - q); if (p2 < p1) swap(p1, p2); return L(p1, p2); } P crosspointLL(const L &l, const L &m) { double A = cross(l[1] - l[0], m[1] - m[0]); double B = cross(l[1] - l[0], l[1] - m[0]); if (abs(A) < EPS && abs(B) < EPS) return m[0]; // same line return m[0] + B / A * (m[1] - m[0]); } double area(const G &g) { double S = 0; for (int i = 0; i < g.size(); i++) { S += (cross(g[i], g[(i + 1) % g.size()])); } return abs(S / 2.0); } bool isconvex(const G &g) { int n = g.size(); rep(i, n) if (ccw(g[(i + n - 1) % n], g[i % n], g[(i + 1) % n]) == -1) return false; return true; } int inconvex(const G &g, const P &p) { bool in = false; int n = g.size(); rep(i, n) { P a = g[i % n] - p; P b = g[(i + 1) % n] - p; if (imag(a) > imag(b)) swap(a, b); if (imag(a) < EPS && 0 < imag(b)) if (cross(a, b) < 0) in = !in; if (abs(cross(a, b)) < EPS && dot(a, b) < EPS) return 1; // ON } return in ? 2 : 0; // IN : OUT; } G convex_hull(G &ps) { int n = ps.size(), k = 0; sort(ps.begin(), ps.end()); G ch(2 * n); for (int i = 0; i < n; ch[k++] = ps[i++]) // lower-hull while (k >= 2 && ccw(ch[k - 2], ch[k - 1], ps[i]) == -1) --k; //<=0 -> ==-1 for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = ps[i--]) // upper-hull while (k >= t && ccw(ch[k - 2], ch[k - 1], ps[i]) == -1) --k; // ch.resize(k - 1); return ch; } double convex_diameter(const G &pt) { const int n = pt.size(); int is = 0, js = 0; for (int i = 1; i < n; ++i) { if (imag(pt[i]) > imag(pt[is])) is = i; if (imag(pt[i]) < imag(pt[js])) js = i; } double maxd = norm(pt[is] - pt[js]); int i, maxi, j, maxj; i = maxi = is; j = maxj = js; do { if (cross(diff(pt, i), diff(pt, j)) >= 0) j = (j + 1) % n; else i = (i + 1) % n; if (norm(pt[i] - pt[j]) > maxd) { maxd = norm(pt[i] - pt[j]); maxi = i; maxj = j; } } while (i != is || j != js); return sqrt(maxd); /* farthest pair is (maxi, maxj). */ } // convex_diameter(g) G convex_cut(const G &g, const L &l) { G Q; for (int i = 0; i < g.size(); ++i) { P a = curr(g, i), b = next(g, i); if (ccw(l[0], l[1], a) != -1) Q.push_back(a); if (ccw(l[0], l[1], a) * ccw(l[0], l[1], b) < 0) Q.push_back(crosspointLL(L(a, b), l)); } return Q; } P turn(P p, double t) { return p * exp(P(.0, t * PI / 180.0)); } P turn2(P p, double t) { return p * exp(P(.0, t)); } vector<L> tangentCC(C a, C b) { if (a.r < b.r) swap(a, b); double d = abs(a.c - b.c); vector<L> l; if (d < EPS) return l; if (a.r + b.r < d - EPS) { // hanareteiru double t = acos((a.r + b.r) / d); t = t * 180 / PI; l.pb(L(a.c + turn(a.r / d * (b.c - a.c), t), b.c + turn(b.r / d * (a.c - b.c), t))); l.pb(L(a.c + turn(a.r / d * (b.c - a.c), -t), b.c + turn(b.r / d * (a.c - b.c), -t))); } else if (a.r + b.r < d + EPS) { // kuttuiteiru soto P p = a.c + a.r / d * (b.c - a.c); l.pb(L(p, p + turn(b.c - a.c, 90))); } if (abs(a.r - b.r) < d - EPS) { // majiwatteiru double t1 = acos((a.r - b.r) / d); t1 = t1 * 180 / PI; double t2 = 180 - t1; l.pb(L(a.c + turn(a.r / d * (b.c - a.c), t1), b.c + turn(b.r / d * (a.c - b.c), -t2))); l.pb(L(a.c + turn(a.r / d * (b.c - a.c), -t1), b.c + turn(b.r / d * (a.c - b.c), t2))); } else if (abs(a.r - b.r) < d + EPS) { // kuttuiteiru uti P p = a.c + a.r / d * (b.c - a.c); l.pb(L(p, p + turn(b.c - a.c, 90))); } return l; } void printL(const L &out) { printf("%.9f %.9f %.9f %.9f\n", out[0].real(), out[0].imag(), out[1].real(), out[1].imag()); } C CIN() { P p = pin(); double r; cin >> r; return C(p, r); } bool para(L a, L b) { return (abs(cross(a[1] - a[0], b[1] - b[0])) < EPS); } double min(double a, double b) { return a < b ? a : b; } double max(double a, double b) { return a > b ? a : b; } int main() { int n; while (cin >> n, n) { G g(n); rep(i, n) g[i] = pin(); int out = 1; rep(i, n) rep(j, i) if (abs(g[i] - g[j]) < 2 + EPS) { double dis = abs(g[i] - g[j]); double c = atan(sqrt(4 / dis / dis - 1)); P tur = g[j] - g[i]; tur /= abs(tur); P p = g[i] + turn2(tur, c); int co = 0; rep(k, n) if (abs(p - g[k]) < 1 + EPS) co++; out = max(out, co); co = 0; p = g[i] + turn2(tur, -c); rep(k, n) if (abs(p - g[k]) < 1 + EPS) co++; out = max(out, co); } cout << out << endl; } }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
1
3,726
#include <bits/stdc++.h> using namespace std; #define int long long #define F first #define S second #define all(v) (v).begin(), (v).end() #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define reps(i, f, n) for (int i = (int)(f); i < (int)(n); i++) #define each(a, b) for (auto &a : b) const int inf = 1LL << 55; #define EPS (1e-10) #define equals(a, b) (fabs((a) - (b)) < EPS) // ???/???????????? struct Point { double x, y; Point(double x = 0.0, double y = 0.0) : x(x), y(y) {} Point operator+(Point p) { return Point(x + p.x, y + p.y); } Point operator-(Point p) { return Point(x - p.x, y - p.y); } Point operator*(double a) { return Point(x * a, y * a); } Point operator/(double a) { return Point(x / a, y / a); } double abs() { return sqrt(norm()); } double norm() { return x * x + y * y; } bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; } bool operator==(const Point &p) const { return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS; } }; typedef Point Vector; // ??? struct Circle { Point c; double r; Circle(Point c = Point(), double r = 0.0) : c(c), r(r) {} }; // ????§???¢ typedef vector<Point> Polygon; // ??????/??´??? struct Segment { Point p1, p2; }; typedef Segment Line; // ???????????????????????? double norm(Vector v) { return v.x * v.x + v.y * v.y; } // ?????????????????§?????? double abs(Vector v) { return sqrt(norm(v)); } // ????????????????????? double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; } // ??????????????????????????§?????? double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; } // ??´????????? bool isOrthogonal(Vector a, Vector b) { return equals(dot(a, b), 0.0); } bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) { return isOrthogonal(a1 - a2, b1 - b2); } bool isOrthogonal(Segment s1, Segment s2) { return equals(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0); } // ???????????? bool isParallel(Vector a, Vector b) { return equals(cross(a, b), 0.0); } bool isParallel(Point a1, Point a2, Point b1, Point b2) { return isParallel(a1 - a2, b1 - b2); } bool isParallel(Segment s1, Segment s2) { return equals(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0); } // ?°???± Point project(Segment s, Point p) { Vector base = s.p2 - s.p1; double r = dot(p - s.p1, base) / norm(base); return s.p1 + base * r; } // ????°? Point reflect(Segment s, Point p) { return p + (project(s, p) - p) * 2.0; } static const int COUNTER_CLOCKWISE = 1; static const int CLOCKWISE = -1; static const int ONLINE_BACK = 2; static const int ONLINE_FRONT = -2; static const int ON_SEGMENT = 0; // ???????¨??????? int ccw(Point p0, Point p1, Point p2) { Vector a = p1 - p0; Vector b = p2 - p0; if (cross(a, b) > EPS) return COUNTER_CLOCKWISE; if (cross(a, b) < -EPS) return CLOCKWISE; if (dot(a, b) < -EPS) return ONLINE_BACK; if (a.norm() < b.norm()) return ONLINE_FRONT; return ON_SEGMENT; } // ???????????? bool intersect(Point p1, Point p2, Point p3, Point p4) { return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 && ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0); } bool intersect(Segment s1, Segment s2) { return intersect(s1.p1, s1.p2, s2.p1, s2.p2); } // ?????????????????¢ double getDistance(Point a, Point b) { return abs(a - b); } // ??´?????¨?????¨????????¢ double getDistanceLP(Line l, Point p) { return abs(cross(l.p2 - l.p1, p - l.p1) / abs(l.p2 - l.p1)); } // ????????¨?????¨????????¢ double getDistanceSP(Segment s, Point p) { if (dot(s.p2 - s.p1, p - s.p1) < 0.0) return abs(p - s.p1); if (dot(s.p1 - s.p2, p - s.p2) < 0.0) return abs(p - s.p2); return getDistanceLP(s, p); } // ????????????????????¢ double getDistance(Segment s1, Segment s2) { if (intersect(s1, s2)) return 0.0; return min(min(getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2)), min(getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2))); } // ??????????????? Point getCrossPoint(Segment s1, Segment s2) { Vector base = s2.p2 - s2.p1; double d1 = abs(cross(base, s1.p1 - s2.p1)); double d2 = abs(cross(base, s1.p2 - s2.p1)); double t = d1 / (d1 + d2); return s1.p1 + (s1.p2 - s1.p1) * t; } // ???c??¨??????l????????? pair<Point, Point> getCrossPoints(Circle c, Line l) { // assert(intersect(c, l)); Vector pr = project(l, c.c); Vector e = (l.p2 - l.p1) / abs(l.p2 - l.p1); double base = sqrt(c.r * c.r - norm(pr - c.c)); return make_pair(pr + e * base, pr - e * base); } // ???c1??¨???c2????????? double arg(Vector p) { return atan2(p.y, p.x); } Vector polar(double a, double r) { return Point(cos(r) * a, sin(r) * a); } pair<Point, Point> getCrossPoints(Circle c1, Circle c2) { // assert(intersect(c1, c2)); double d = abs(c1.c - c2.c); double a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d)); double t = arg(c2.c - c1.c); return make_pair(c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a)); } // ???????????? static const int IN_POLYGON = 2; static const int ON_POLYGON = 1; static const int OUT_POLYGON = 0; int contains(Polygon g, Point p) { int n = g.size(); bool x = false; for (int i = 0; i < n; i++) { Point a = g[i] - p, b = g[(i + 1) % n] - p; if (abs(cross(a, b)) < EPS && dot(a, b) < EPS) return ON_POLYGON; if (a.y > b.y) swap(a, b); if (a.y < EPS && EPS < b.y && cross(a, b) > EPS) x = !x; } return (x ? IN_POLYGON : OUT_POLYGON); } signed main() { int N; while (cin >> N, N) { vector<Point> p(N); rep(i, N) cin >> p[i].x >> p[i].y; int ans = 0; rep(i, N) reps(j, i + 1, N) { if (getDistance(p[i], p[j]) < 2.0 + EPS) { Circle c1(p[i], 1.0), c2(p[j], 1.0); auto cp = getCrossPoints(c1, c2); int cnt = 0; rep(k, N) if (getDistance(cp.first, p[k]) < 1.0 + EPS) cnt++; ans = max(ans, cnt); cnt = 0; rep(k, N) if (getDistance(cp.second, p[k]) < 1.0 + EPS) cnt++; ans = max(ans, cnt); } } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define F first #define S second #define all(v) (v).begin(), (v).end() #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define reps(i, f, n) for (int i = (int)(f); i < (int)(n); i++) #define each(a, b) for (auto &a : b) const int inf = 1LL << 55; #define EPS (1e-10) #define equals(a, b) (fabs((a) - (b)) < EPS) // ???/???????????? struct Point { double x, y; Point(double x = 0.0, double y = 0.0) : x(x), y(y) {} Point operator+(Point p) { return Point(x + p.x, y + p.y); } Point operator-(Point p) { return Point(x - p.x, y - p.y); } Point operator*(double a) { return Point(x * a, y * a); } Point operator/(double a) { return Point(x / a, y / a); } double abs() { return sqrt(norm()); } double norm() { return x * x + y * y; } bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; } bool operator==(const Point &p) const { return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS; } }; typedef Point Vector; // ??? struct Circle { Point c; double r; Circle(Point c = Point(), double r = 0.0) : c(c), r(r) {} }; // ????§???¢ typedef vector<Point> Polygon; // ??????/??´??? struct Segment { Point p1, p2; }; typedef Segment Line; // ???????????????????????? double norm(Vector v) { return v.x * v.x + v.y * v.y; } // ?????????????????§?????? double abs(Vector v) { return sqrt(norm(v)); } // ????????????????????? double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; } // ??????????????????????????§?????? double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; } // ??´????????? bool isOrthogonal(Vector a, Vector b) { return equals(dot(a, b), 0.0); } bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) { return isOrthogonal(a1 - a2, b1 - b2); } bool isOrthogonal(Segment s1, Segment s2) { return equals(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0); } // ???????????? bool isParallel(Vector a, Vector b) { return equals(cross(a, b), 0.0); } bool isParallel(Point a1, Point a2, Point b1, Point b2) { return isParallel(a1 - a2, b1 - b2); } bool isParallel(Segment s1, Segment s2) { return equals(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0); } // ?°???± Point project(Segment s, Point p) { Vector base = s.p2 - s.p1; double r = dot(p - s.p1, base) / norm(base); return s.p1 + base * r; } // ????°? Point reflect(Segment s, Point p) { return p + (project(s, p) - p) * 2.0; } static const int COUNTER_CLOCKWISE = 1; static const int CLOCKWISE = -1; static const int ONLINE_BACK = 2; static const int ONLINE_FRONT = -2; static const int ON_SEGMENT = 0; // ???????¨??????? int ccw(Point p0, Point p1, Point p2) { Vector a = p1 - p0; Vector b = p2 - p0; if (cross(a, b) > EPS) return COUNTER_CLOCKWISE; if (cross(a, b) < -EPS) return CLOCKWISE; if (dot(a, b) < -EPS) return ONLINE_BACK; if (a.norm() < b.norm()) return ONLINE_FRONT; return ON_SEGMENT; } // ???????????? bool intersect(Point p1, Point p2, Point p3, Point p4) { return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 && ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0); } bool intersect(Segment s1, Segment s2) { return intersect(s1.p1, s1.p2, s2.p1, s2.p2); } // ?????????????????¢ double getDistance(Point a, Point b) { return abs(a - b); } // ??´?????¨?????¨????????¢ double getDistanceLP(Line l, Point p) { return abs(cross(l.p2 - l.p1, p - l.p1) / abs(l.p2 - l.p1)); } // ????????¨?????¨????????¢ double getDistanceSP(Segment s, Point p) { if (dot(s.p2 - s.p1, p - s.p1) < 0.0) return abs(p - s.p1); if (dot(s.p1 - s.p2, p - s.p2) < 0.0) return abs(p - s.p2); return getDistanceLP(s, p); } // ????????????????????¢ double getDistance(Segment s1, Segment s2) { if (intersect(s1, s2)) return 0.0; return min(min(getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2)), min(getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2))); } // ??????????????? Point getCrossPoint(Segment s1, Segment s2) { Vector base = s2.p2 - s2.p1; double d1 = abs(cross(base, s1.p1 - s2.p1)); double d2 = abs(cross(base, s1.p2 - s2.p1)); double t = d1 / (d1 + d2); return s1.p1 + (s1.p2 - s1.p1) * t; } // ???c??¨??????l????????? pair<Point, Point> getCrossPoints(Circle c, Line l) { // assert(intersect(c, l)); Vector pr = project(l, c.c); Vector e = (l.p2 - l.p1) / abs(l.p2 - l.p1); double base = sqrt(c.r * c.r - norm(pr - c.c)); return make_pair(pr + e * base, pr - e * base); } // ???c1??¨???c2????????? double arg(Vector p) { return atan2(p.y, p.x); } Vector polar(double a, double r) { return Point(cos(r) * a, sin(r) * a); } pair<Point, Point> getCrossPoints(Circle c1, Circle c2) { // assert(intersect(c1, c2)); double d = abs(c1.c - c2.c); double a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d)); double t = arg(c2.c - c1.c); return make_pair(c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a)); } // ???????????? static const int IN_POLYGON = 2; static const int ON_POLYGON = 1; static const int OUT_POLYGON = 0; int contains(Polygon g, Point p) { int n = g.size(); bool x = false; for (int i = 0; i < n; i++) { Point a = g[i] - p, b = g[(i + 1) % n] - p; if (abs(cross(a, b)) < EPS && dot(a, b) < EPS) return ON_POLYGON; if (a.y > b.y) swap(a, b); if (a.y < EPS && EPS < b.y && cross(a, b) > EPS) x = !x; } return (x ? IN_POLYGON : OUT_POLYGON); } signed main() { int N; while (cin >> N, N) { vector<Point> p(N); rep(i, N) cin >> p[i].x >> p[i].y; int ans = 1; rep(i, N) reps(j, i + 1, N) { if (getDistance(p[i], p[j]) < 2.0 + EPS) { Circle c1(p[i], 1.0), c2(p[j], 1.0); auto cp = getCrossPoints(c1, c2); int cnt = 0; rep(k, N) if (getDistance(cp.first, p[k]) < 1.0 + EPS) cnt++; ans = max(ans, cnt); cnt = 0; rep(k, N) if (getDistance(cp.second, p[k]) < 1.0 + EPS) cnt++; ans = max(ans, cnt); } } cout << ans << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
1
1,887
#include <bits/stdc++.h> #define r(i, n) for (int i = 0; i < n; i++) using namespace std; #define EPS (1e-10) #define equals(a, b) (fabs((a) - (b)) < EPS) // CCW??¨/////////////////////////////////// static const int COUNTER_CLOCKWISE = 1; static const int CLOCKWISE = -1; static const int ONLINE_BACK = 2; static const int ONLINE_FRONT = -2; static const int ON_SEGMENT = 0; ///////////////////////////////////////// class Point { public: double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} Point operator+(Point p) { return Point(x + p.x, y + p.y); } Point operator-(Point p) { return Point(x - p.x, y - p.y); } Point operator*(double a) { return Point(a * x, a * y); } Point operator/(double a) { return Point(x / a, y / a); } bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; } bool operator==(const Point &p) const { return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS; } }; struct Circle { Point c; double r; }; typedef Point vect; struct seg { Point p1, p2; }; //????????´???????????? double norm(Point p) { return p.x * p.x + p.y * p.y; } //??¶???????????????absolute ?????????????????¶????????? double abs(Point p) { return sqrt(norm(p)); } //????????????????????????????????? double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; } //?????? ???????????????????????? double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; } //??´?????????????????¨?????\????????????????????? bool C90(seg s1, seg s2) { return equals(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0); } //????????????????????¨?????\?????????????????????????????????????????? bool C0(seg s1, seg s2) { return equals(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0); } //?°???± ??????????????´??????????????? Point project(seg s, Point p) { Point base = s.p2 - s.p1; double r = dot(p - s.p1, base) / norm(base); return s.p1 + base * r; } //????°?????????????????????? Point reflection(seg s, Point p) { return p + (project(s, p) - p) * 2.0; } // 2???????????¢ ??????????????? double getDistancePP(Point a, Point b) { return abs(a - b); } //??´??????????????¢(????°?)??????????????? double getDistanceLP(seg l, Point p) { return abs(cross(l.p2 - l.p1, p - l.p1) / abs(l.p2 - l.p1)); } //?????????????????¢?????????????????? double getDistanceSP(seg s, Point p) { if (dot(s.p2 - s.p1, p - s.p1) < 0.0) return abs(p - s.p1); if (dot(s.p1 - s.p2, p - s.p2) < 0.0) return abs(p - s.p2); return getDistanceLP(s, p); } //????¨?????????????????¨?????????????????????????????????? int CCW(Point p0, Point p1, Point p2) { Point a = p1 - p0; Point b = p2 - p0; if (cross(a, b) > EPS) return COUNTER_CLOCKWISE; if (cross(a, b) < -EPS) return CLOCKWISE; if (dot(a, b) < -EPS) return ONLINE_BACK; if (norm(a) < norm(b)) return ONLINE_FRONT; return ON_SEGMENT; } //????????????????????????????????????????????§?\???? bool intersect(Point p1, Point p2, Point p3, Point p4) { return (CCW(p1, p2, p3) * CCW(p1, p2, p4) <= 0 && CCW(p3, p4, p1) * CCW(p3, p4, p2) <= 0); } bool intersect(seg s1, seg s2) { return intersect(s1.p1, s1.p2, s2.p1, s2.p2); } // 2??????????§???¢?????\??????????????????...???????????????????????? bool squareintersect(seg s1, seg s2) { if (s1.p2.x < s2.p1.x || s2.p2.x < s1.p1.x) return 0; if (s1.p2.y < s2.p1.y || s2.p2.y < s1.p1.y) return 0; return 1; } //??????????????¢?????????????????????????????§??¨??????????????? double getDistance(seg s1, seg s2) { if (intersect(s1, s2)) return 0.0; return min(min(getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2)), min(getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2))); } //??????????????????????????????(?´????????`) Point getCrossPoint(seg s1, seg s2) { Point base = s2.p2 - s2.p1; double d1 = abs(cross(base, s1.p1 - s2.p1)); double d2 = abs(cross(base, s1.p2 - s2.p1)); double t = d1 / (d1 + d2); return s1.p1 + (s1.p2 - s1.p1) * t; } //???????£????????????¢??????????????¢??????????????????????????\????????????????????§???????????£???????????????????????????????????§????????????????????? int intersectCC(Circle a, Circle b) { double dist = abs(a.c - b.c); if (dist > a.r + b.r + EPS) return 4; if (dist > a.r + b.r - EPS) return 3; if (dist > abs(a.r - b.r) + EPS) return 2; if (dist > abs(a.r - b.r) - EPS) return 1; return 0; } //?????¨??´???????????????2?????? (LINE) seg getCrossPoint(Circle c, seg l) { // assert(intersect(cc,l)); Point pr = project(l, c.c); Point e = (l.p2 - l.p1) / abs(l.p2 - l.p1); double base = sqrt(c.r * c.r - norm(pr - c.c)); seg pp; pp.p1 = (pr + e * base); pp.p2 = (pr - e * base); return pp; } //?????¨??´??????Line??????????????° int getCircleLine(Circle c, seg l) { seg a = getCrossPoint(c, l); if (isnan(a.p1.x) && isnan(a.p2.y)) return 0; else if (a.p1.x == a.p2.x && a.p1.y == a.p2.y) return 1; else return 2; } //??´?????¨????????\??????????????? bool intersectCirclesen(seg s, Circle t) { double a, b, c; a = getDistancePP(s.p1, t.c); b = getDistancePP(s.p2, t.c); c = getDistanceSP(s, t.c); if (a < t.r && b > t.r) return 1; if (b < t.r && a > t.r) return 1; if (a >= t.r && b >= t.r && c <= t.r) return 1; return 0; } //?????? Point gaishin(Point a, Point b, Point c) { double a1, a2, b1, b2, c1, c2; a1 = 2 * (b.x - a.x); b1 = 2 * (b.y - a.y); c1 = a.x * a.x - b.x * b.x + a.y * a.y - b.y * b.y; a2 = 2 * (c.x - a.x); b2 = 2 * (c.y - a.y); c2 = a.x * a.x - c.x * c.x + a.y * a.y - c.y * c.y; Point p; p.x = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1); p.y = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1); return p; } // 2?????????????????? double arg(Point p) { return atan2(p.y, p.x); } Point polar(double a, double r) { return Point(cos(r) * a, sin(r) * a); } seg getCrossPoints(Circle c1, Circle c2) { // assert(intersect(c1,c2)); double d = abs(c1.c - c2.c); double a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d)); double t = arg(c2.c - c1.c); seg s; s.p2 = c1.c + polar(c1.r, t + a); s.p1 = c1.c + polar(c1.r, t - a); return s; } //???????????? ????????????->2 ??????->1 ????????\???->0 typedef vector<Point> Polygon; int contains(Polygon g, Point p) { int n = g.size(); bool x = false; for (int i = 0; i < n; i++) { Point a = g[i] - p, b = g[(i + 1) % n] - p; if (abs(cross(a, b)) < EPS && dot(a, b) < EPS) return 1; if (a.y > b.y) swap(a, b); if (a.y < EPS && EPS < b.y && cross(a, b) > EPS) x = !x; } return x ? 2 : 0; } double Area(Polygon p) { double a = 0; for (int i = 0; i < p.size(); i++) a += cross(p[i], p[(i + 1) % p.size()]); return a / 2; } //???????§???¢?????? bool isConvex(Polygon p) { for (int i = 0; i < p.size(); i++) { if (CCW(p[(i + 1) % p.size()], p[i % p.size()], p[(i + 2) % p.size()]) == 1) return false; } return true; } //?????¢???????????¢???(?????´)=ans Polygon convex_cut(Polygon p, seg l) { Polygon ans; for (int i = 0; i < p.size(); i++) { Point A = p[i], B = p[(i + 1) % p.size()]; if (CCW(l.p1, l.p2, A) != -1) ans.push_back(A); if (CCW(l.p1, l.p2, A) * CCW(l.p1, l.p2, B) < 0) { seg s; s.p1 = A; s.p2 = B; ans.push_back(getCrossPoint(l, s)); } } return ans; } double convex_diameter(Polygon p) { int n = p.size(); int i = 0, j = 0; for (int k = 0; k < n; k++) { if (p[i] < p[k]) i = k; if (p[k] < p[j]) j = k; } int si = i, sj = j; double ans = 0.0; while (i != sj || j != si) { ans = max(ans, abs(p[i] - p[j])); if (cross((p[(i + 1) % n] - p[i]), (p[(j + 1) % n] - p[j])) < 0) i = (i + 1) % n; else j = (j + 1) % n; } return ans; } //?????? //??´??????????????????????????????????????¨?????????191,197?????????&&CCW(u[n-2],u[n-1],s[i])!=ONLINE_FRONT??????????????? Polygon andrewScan(Polygon s) { Polygon l, u; if (s.size() < 3) return s; sort(s.begin(), s.end()); u.push_back(s[0]); u.push_back(s[1]); l.push_back(s[s.size() - 1]); l.push_back(s[s.size() - 2]); for (int i = 2; i < s.size(); i++) { for (int n = u.size(); n >= 2 && CCW(u[n - 2], u[n - 1], s[i]) != -1 && CCW(u[n - 2], u[n - 1], s[i]) != ONLINE_FRONT; n--) { u.pop_back(); } u.push_back(s[i]); } for (int i = s.size() - 3; i >= 0; i--) { for (int n = l.size(); n >= 2 && CCW(l[n - 2], l[n - 1], s[i]) != -1 && CCW(l[n - 2], l[n - 1], s[i]) != ONLINE_FRONT; n--) { l.pop_back(); } l.push_back(s[i]); } reverse(l.begin(), l.end()); for (int i = u.size() - 2; i >= 1; i--) l.push_back(u[i]); return l; } //???a??¨???b??????d??¢??????2??? seg identifyPoint(Point a, Point b, double d) { Circle c1, c2; c1.c = a; c1.r = d; c2.c = b; c2.r = d; return getCrossPoints(c1, c2); } // ???????????°??¨?????? seg scan() { seg a; scanf("%lf%lf%lf%lf", &a.p1.x, &a.p1.y, &a.p2.x, &a.p2.y); return a; } void prin(seg a) { printf("%.10f %.10f %.10f %.10f\n", a.p1.x, a.p1.y, a.p2.x, a.p2.y); } // /////------Library END-------////////////////////////////////////// // exp????????? // //////a=x??§?¨????b=y??§?¨????c=?§?????????????d=????????????????????¢ // p[i][j].x=a-d*sin(M_PI/180*(72*j+c)); // p[i][j].y=b+d*cos(M_PI/180*(72*j+c)); ///////////////////////////////////////////////// int main() { int n; while (cin >> n, n) { Point p[n]; int ans = 1; r(i, n) cin >> p[i].x >> p[i].y; r(i, n) for (int j = i + 1; j < n; j++) { if (getDistancePP(p[i], p[j]) < 2.0) { seg s = identifyPoint(p[i], p[j], 1); int a1 = 0, a2 = 0; Point p3, p4; p3 = s.p1; p4 = s.p2; r(k, n) if (abs(getDistancePP(p3, p[k])) <= 1) a1++; r(k, n) if (abs(getDistancePP(p4, p[k])) <= 1) a2++; ans = max(ans, max(a1, a2)); } } cout << ans << endl; } }
#include <bits/stdc++.h> #define r(i, n) for (int i = 0; i < n; i++) using namespace std; #define EPS (1e-10) #define equals(a, b) (fabs((a) - (b)) < EPS) // CCW??¨/////////////////////////////////// static const int COUNTER_CLOCKWISE = 1; static const int CLOCKWISE = -1; static const int ONLINE_BACK = 2; static const int ONLINE_FRONT = -2; static const int ON_SEGMENT = 0; ///////////////////////////////////////// class Point { public: double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} Point operator+(Point p) { return Point(x + p.x, y + p.y); } Point operator-(Point p) { return Point(x - p.x, y - p.y); } Point operator*(double a) { return Point(a * x, a * y); } Point operator/(double a) { return Point(x / a, y / a); } bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; } bool operator==(const Point &p) const { return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS; } }; struct Circle { Point c; double r; }; typedef Point vect; struct seg { Point p1, p2; }; //????????´???????????? double norm(Point p) { return p.x * p.x + p.y * p.y; } //??¶???????????????absolute ?????????????????¶????????? double abs(Point p) { return sqrt(norm(p)); } //????????????????????????????????? double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; } //?????? ???????????????????????? double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; } //??´?????????????????¨?????\????????????????????? bool C90(seg s1, seg s2) { return equals(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0); } //????????????????????¨?????\?????????????????????????????????????????? bool C0(seg s1, seg s2) { return equals(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0); } //?°???± ??????????????´??????????????? Point project(seg s, Point p) { Point base = s.p2 - s.p1; double r = dot(p - s.p1, base) / norm(base); return s.p1 + base * r; } //????°?????????????????????? Point reflection(seg s, Point p) { return p + (project(s, p) - p) * 2.0; } // 2???????????¢ ??????????????? double getDistancePP(Point a, Point b) { return abs(a - b); } //??´??????????????¢(????°?)??????????????? double getDistanceLP(seg l, Point p) { return abs(cross(l.p2 - l.p1, p - l.p1) / abs(l.p2 - l.p1)); } //?????????????????¢?????????????????? double getDistanceSP(seg s, Point p) { if (dot(s.p2 - s.p1, p - s.p1) < 0.0) return abs(p - s.p1); if (dot(s.p1 - s.p2, p - s.p2) < 0.0) return abs(p - s.p2); return getDistanceLP(s, p); } //????¨?????????????????¨?????????????????????????????????? int CCW(Point p0, Point p1, Point p2) { Point a = p1 - p0; Point b = p2 - p0; if (cross(a, b) > EPS) return COUNTER_CLOCKWISE; if (cross(a, b) < -EPS) return CLOCKWISE; if (dot(a, b) < -EPS) return ONLINE_BACK; if (norm(a) < norm(b)) return ONLINE_FRONT; return ON_SEGMENT; } //????????????????????????????????????????????§?\???? bool intersect(Point p1, Point p2, Point p3, Point p4) { return (CCW(p1, p2, p3) * CCW(p1, p2, p4) <= 0 && CCW(p3, p4, p1) * CCW(p3, p4, p2) <= 0); } bool intersect(seg s1, seg s2) { return intersect(s1.p1, s1.p2, s2.p1, s2.p2); } // 2??????????§???¢?????\??????????????????...???????????????????????? bool squareintersect(seg s1, seg s2) { if (s1.p2.x < s2.p1.x || s2.p2.x < s1.p1.x) return 0; if (s1.p2.y < s2.p1.y || s2.p2.y < s1.p1.y) return 0; return 1; } //??????????????¢?????????????????????????????§??¨??????????????? double getDistance(seg s1, seg s2) { if (intersect(s1, s2)) return 0.0; return min(min(getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2)), min(getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2))); } //??????????????????????????????(?´????????`) Point getCrossPoint(seg s1, seg s2) { Point base = s2.p2 - s2.p1; double d1 = abs(cross(base, s1.p1 - s2.p1)); double d2 = abs(cross(base, s1.p2 - s2.p1)); double t = d1 / (d1 + d2); return s1.p1 + (s1.p2 - s1.p1) * t; } //???????£????????????¢??????????????¢??????????????????????????\????????????????????§???????????£???????????????????????????????????§????????????????????? int intersectCC(Circle a, Circle b) { double dist = abs(a.c - b.c); if (dist > a.r + b.r + EPS) return 4; if (dist > a.r + b.r - EPS) return 3; if (dist > abs(a.r - b.r) + EPS) return 2; if (dist > abs(a.r - b.r) - EPS) return 1; return 0; } //?????¨??´???????????????2?????? (LINE) seg getCrossPoint(Circle c, seg l) { // assert(intersect(cc,l)); Point pr = project(l, c.c); Point e = (l.p2 - l.p1) / abs(l.p2 - l.p1); double base = sqrt(c.r * c.r - norm(pr - c.c)); seg pp; pp.p1 = (pr + e * base); pp.p2 = (pr - e * base); return pp; } //?????¨??´??????Line??????????????° int getCircleLine(Circle c, seg l) { seg a = getCrossPoint(c, l); if (isnan(a.p1.x) && isnan(a.p2.y)) return 0; else if (a.p1.x == a.p2.x && a.p1.y == a.p2.y) return 1; else return 2; } //??´?????¨????????\??????????????? bool intersectCirclesen(seg s, Circle t) { double a, b, c; a = getDistancePP(s.p1, t.c); b = getDistancePP(s.p2, t.c); c = getDistanceSP(s, t.c); if (a < t.r && b > t.r) return 1; if (b < t.r && a > t.r) return 1; if (a >= t.r && b >= t.r && c <= t.r) return 1; return 0; } //?????? Point gaishin(Point a, Point b, Point c) { double a1, a2, b1, b2, c1, c2; a1 = 2 * (b.x - a.x); b1 = 2 * (b.y - a.y); c1 = a.x * a.x - b.x * b.x + a.y * a.y - b.y * b.y; a2 = 2 * (c.x - a.x); b2 = 2 * (c.y - a.y); c2 = a.x * a.x - c.x * c.x + a.y * a.y - c.y * c.y; Point p; p.x = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1); p.y = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1); return p; } // 2?????????????????? double arg(Point p) { return atan2(p.y, p.x); } Point polar(double a, double r) { return Point(cos(r) * a, sin(r) * a); } seg getCrossPoints(Circle c1, Circle c2) { // assert(intersect(c1,c2)); double d = abs(c1.c - c2.c); double a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d)); double t = arg(c2.c - c1.c); seg s; s.p2 = c1.c + polar(c1.r, t + a); s.p1 = c1.c + polar(c1.r, t - a); return s; } //???????????? ????????????->2 ??????->1 ????????\???->0 typedef vector<Point> Polygon; int contains(Polygon g, Point p) { int n = g.size(); bool x = false; for (int i = 0; i < n; i++) { Point a = g[i] - p, b = g[(i + 1) % n] - p; if (abs(cross(a, b)) < EPS && dot(a, b) < EPS) return 1; if (a.y > b.y) swap(a, b); if (a.y < EPS && EPS < b.y && cross(a, b) > EPS) x = !x; } return x ? 2 : 0; } double Area(Polygon p) { double a = 0; for (int i = 0; i < p.size(); i++) a += cross(p[i], p[(i + 1) % p.size()]); return a / 2; } //???????§???¢?????? bool isConvex(Polygon p) { for (int i = 0; i < p.size(); i++) { if (CCW(p[(i + 1) % p.size()], p[i % p.size()], p[(i + 2) % p.size()]) == 1) return false; } return true; } //?????¢???????????¢???(?????´)=ans Polygon convex_cut(Polygon p, seg l) { Polygon ans; for (int i = 0; i < p.size(); i++) { Point A = p[i], B = p[(i + 1) % p.size()]; if (CCW(l.p1, l.p2, A) != -1) ans.push_back(A); if (CCW(l.p1, l.p2, A) * CCW(l.p1, l.p2, B) < 0) { seg s; s.p1 = A; s.p2 = B; ans.push_back(getCrossPoint(l, s)); } } return ans; } double convex_diameter(Polygon p) { int n = p.size(); int i = 0, j = 0; for (int k = 0; k < n; k++) { if (p[i] < p[k]) i = k; if (p[k] < p[j]) j = k; } int si = i, sj = j; double ans = 0.0; while (i != sj || j != si) { ans = max(ans, abs(p[i] - p[j])); if (cross((p[(i + 1) % n] - p[i]), (p[(j + 1) % n] - p[j])) < 0) i = (i + 1) % n; else j = (j + 1) % n; } return ans; } //?????? //??´??????????????????????????????????????¨?????????191,197?????????&&CCW(u[n-2],u[n-1],s[i])!=ONLINE_FRONT??????????????? Polygon andrewScan(Polygon s) { Polygon l, u; if (s.size() < 3) return s; sort(s.begin(), s.end()); u.push_back(s[0]); u.push_back(s[1]); l.push_back(s[s.size() - 1]); l.push_back(s[s.size() - 2]); for (int i = 2; i < s.size(); i++) { for (int n = u.size(); n >= 2 && CCW(u[n - 2], u[n - 1], s[i]) != -1 && CCW(u[n - 2], u[n - 1], s[i]) != ONLINE_FRONT; n--) { u.pop_back(); } u.push_back(s[i]); } for (int i = s.size() - 3; i >= 0; i--) { for (int n = l.size(); n >= 2 && CCW(l[n - 2], l[n - 1], s[i]) != -1 && CCW(l[n - 2], l[n - 1], s[i]) != ONLINE_FRONT; n--) { l.pop_back(); } l.push_back(s[i]); } reverse(l.begin(), l.end()); for (int i = u.size() - 2; i >= 1; i--) l.push_back(u[i]); return l; } //???a??¨???b??????d??¢??????2??? seg identifyPoint(Point a, Point b, double d) { Circle c1, c2; c1.c = a; c1.r = d; c2.c = b; c2.r = d; return getCrossPoints(c1, c2); } // ???????????°??¨?????? seg scan() { seg a; scanf("%lf%lf%lf%lf", &a.p1.x, &a.p1.y, &a.p2.x, &a.p2.y); return a; } void prin(seg a) { printf("%.10f %.10f %.10f %.10f\n", a.p1.x, a.p1.y, a.p2.x, a.p2.y); } // /////------Library END-------////////////////////////////////////// // exp????????? // //////a=x??§?¨????b=y??§?¨????c=?§?????????????d=????????????????????¢ // p[i][j].x=a-d*sin(M_PI/180*(72*j+c)); // p[i][j].y=b+d*cos(M_PI/180*(72*j+c)); ///////////////////////////////////////////////// int main() { int n; while (cin >> n, n) { Point p[n]; int ans = 1; r(i, n) cin >> p[i].x >> p[i].y; r(i, n) for (int j = i + 1; j < n; j++) { if (getDistancePP(p[i], p[j]) <= 2.0) { seg s = identifyPoint(p[i], p[j], 1); int a1 = 0, a2 = 0; Point p3, p4; p3 = s.p1; p4 = s.p2; r(k, n) if (abs(getDistancePP(p3, p[k])) <= 1.000001) a1++; r(k, n) if (abs(getDistancePP(p4, p[k])) <= 1.000001) a2++; ans = max(ans, max(a1, a2)); } } cout << ans << endl; } }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["-", 64, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 64, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
1
3,219
#include <bits/stdc++.h> using namespace std; /*{{{*/ // template #define rep(i, n) for (int i = 0; i < n; i++) #define INF 1 << 29 #define LINF LLONG_MAX / 3 #define mp make_pair #define pb push_back #define EB emplace_back #define fi first #define se second #define all(v) ALL(v) #define sz(x) (int)(x).size() #define debug(x) cerr << #x << ":" << x << endl #define debug2(x, y) cerr << #x << "," << #y ":" << x << "," << y << endl // struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_; struct Double { double d; explicit Double(double x) : d(x) {} }; ostream &operator<<(ostream &os, const Double x) { os << fixed << setprecision(20) << x.d; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "["; for (const auto &v : vec) { os << v << ","; } os << "]"; return os; } template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << "(" << p.first << "," << p.second << ")"; return os; } typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vi> vvi; ll gcd(ll a, ll b) { if (b == 0) return a; else return gcd(b, a % b); } constexpr double eps = 1e-14; constexpr ll mod = 1e9 + 7; const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; /*}}}*/ int N; void solve() { vector<double> x(N), y(N); rep(i, N) { cin >> x[i] >> y[i]; } int ans = 1; rep(i, N) rep(j, N) if (i != j) { double vx = x[i] - x[j]; double vy = y[i] - y[j]; double d = sqrt(vx * vx + vy * vy); if (d > 2) continue; double r = sqrt(1 - (d / 2) * (d / 2)); double rx = -vy * r / d; double ry = vx * r / d; double cx = (x[i] + x[j]) / 2 + rx; double cy = (y[i] + y[j]) / 2 + ry; int cnt = 0; rep(k, N) { double tx = cx - x[k]; double ty = cy - y[k]; double dd = sqrt(tx * tx + ty * ty); if (dd <= 1) cnt++; } ans = max(ans, cnt); } cout << ans << endl; } int main() { while (cin >> N) { if (N == 0) break; solve(); } }
#include <bits/stdc++.h> using namespace std; /*{{{*/ // template #define rep(i, n) for (int i = 0; i < n; i++) #define INF 1 << 29 #define LINF LLONG_MAX / 3 #define mp make_pair #define pb push_back #define EB emplace_back #define fi first #define se second #define all(v) ALL(v) #define sz(x) (int)(x).size() #define debug(x) cerr << #x << ":" << x << endl #define debug2(x, y) cerr << #x << "," << #y ":" << x << "," << y << endl // struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_; struct Double { double d; explicit Double(double x) : d(x) {} }; ostream &operator<<(ostream &os, const Double x) { os << fixed << setprecision(20) << x.d; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "["; for (const auto &v : vec) { os << v << ","; } os << "]"; return os; } template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << "(" << p.first << "," << p.second << ")"; return os; } typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vi> vvi; ll gcd(ll a, ll b) { if (b == 0) return a; else return gcd(b, a % b); } constexpr double eps = 1e-14; constexpr ll mod = 1e9 + 7; const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; /*}}}*/ int N; void solve() { vector<double> x(N), y(N); rep(i, N) { cin >> x[i] >> y[i]; } int ans = 1; rep(i, N) rep(j, N) if (i != j) { // cout << "i,j = " << i << "," << j << endl; double vx = x[i] - x[j]; double vy = y[i] - y[j]; double d = sqrt(vx * vx + vy * vy); if (d + eps > 2) continue; double r = sqrt(1 - (d / 2) * (d / 2)); double rx = -vy * r / d; double ry = vx * r / d; double cx = (x[i] + x[j]) / 2 + rx; double cy = (y[i] + y[j]) / 2 + ry; int cnt = 0; rep(k, N) { double tx = cx - x[k]; double ty = cy - y[k]; double dd = sqrt(tx * tx + ty * ty); // cout << "dd=" << dd << endl; if (dd <= 1 + eps) cnt++; } // cout << "cnt : " << cnt << endl; ans = max(ans, cnt); } cout << ans << endl; } int main() { while (cin >> N) { if (N == 0) break; solve(); } }
[["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 72], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 12, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 72], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22]]
1
630
#include <bits/stdc++.h> using namespace std; using ld = long double; using P = complex<ld>; const ld eps = 1e-6; int main() { int N; while (cin >> N, N) { vector<ld> x(N), y(N); vector<P> p(N); for (int i = 0; i < N; i++) { cin >> x[i] >> y[i]; p[i] = P(x[i], y[i]); } vector<P> ko; for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { if (norm(p[i] - p[j]) < 4.0 + eps) { auto d = p[i] - p[j]; ko.push_back(p[j] + (d * (ld)0.5) + d * P(0, 1) / abs(d) * sqrtl(1 - norm(d * (ld)0.5))); ko.push_back(p[j] + (d * (ld)0.5) - d * P(0, 1) / abs(d) * sqrtl(1 - norm(d * (ld)0.5))); } } } int res = 0; for (auto c : ko) { int cnt = 0; for (int i = 0; i < N; i++) { if (norm(c - p[i]) < 1.0001) { cnt++; } } res = max(res, cnt); } cout << res << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using ld = long double; using P = complex<ld>; const ld eps = 1e-6; int main() { int N; while (cin >> N, N) { vector<ld> x(N), y(N); vector<P> p(N); for (int i = 0; i < N; i++) { cin >> x[i] >> y[i]; p[i] = P(x[i], y[i]); } vector<P> ko; for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { if (norm(p[i] - p[j]) < 4.0 + eps) { auto d = p[i] - p[j]; ko.push_back(p[j] + (d * (ld)0.5) + d * P(0, 1) / abs(d) * sqrtl(1 - norm(d * (ld)0.5))); ko.push_back(p[j] + (d * (ld)0.5) - d * P(0, 1) / abs(d) * sqrtl(1 - norm(d * (ld)0.5))); } } } int res = 1; for (auto c : ko) { int cnt = 0; for (int i = 0; i < N; i++) { if (norm(c - p[i]) < 1.0001) { cnt++; } } res = max(res, cnt); } cout << res << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
1
356
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define repr(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define rep(i, n) repl(i, 0, n) #define each(itr, v) for (auto itr : v) #define pb(s) push_back(s) #define all(x) (x).begin(), (x).end() #define dbg(x) cout << #x " = " << x << endl #define print(x) cout << x << endl #define maxch(x, y) x = max(x, y) #define minch(x, y) x = min(x, y) #define uni(x) x.erase(unique(all(x)), x.end()) #define exist(x, y) (find(all(x), y) != x.end()) #define bcnt(x) bitset<32>(x).count() typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; typedef pair<double, double> PD; typedef pair<P, int> PPI; typedef pair<int, P> PIP; typedef pair<ll, ll> PL; typedef pair<P, ll> PPL; typedef set<int> S; #define INF INT_MAX / 3 #define MAX_N 1000000001 vector<PD> cli(double a, double b, double c, PD c1) { double l = a * a + b * b, k = a * c1.fi + b * c1.se + c, d = l - k * k; vector<PD> v; if (d > 0) { double ds = sqrt(d), apl = a / l, bpl = b / l; double xc = c1.fi - apl * k, xd = bpl * ds, yc = c1.se - bpl * k, yd = apl * ds; v.pb(PD(xc - xd, yc + yd)), v.pb(PD(xc + xd, yc - yd)); } else if (d == 0) { v.pb(PD(c1.fi - a * k / l, c1.se - b * k / l)); } return v; } vector<PD> cci(PD c1, PD c2) { double a = c1.fi - c2.fi, b = c1.se - c2.se; return cli(2.0 * a, 2.0 * b, 0 - a * (c1.fi + c2.fi) - b * (c1.se + c2.se), c1); } bool dist(PD p1, PD p2) { return (pow(p1.fi - p2.fi, 2.0) + pow(p1.se - p2.se, 2.0)) <= 1.0 + 1e-7; } int main() { cin.sync_with_stdio(false); int n; while (cin >> n, n) { vector<PD> v(n); rep(i, n) cin >> v[i].fi >> v[i].se; int maxi = 0; rep(i, n - 1) repl(j, i + 1, n) { vector<PD> p = cci(v[i], v[j]); rep(k, p.size()) { int cnt = 0; rep(l, n) { if (dist(p[k], v[l])) cnt++; } maxch(maxi, cnt); } } cout << maxi << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define repr(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define rep(i, n) repl(i, 0, n) #define each(itr, v) for (auto itr : v) #define pb(s) push_back(s) #define all(x) (x).begin(), (x).end() #define dbg(x) cout << #x " = " << x << endl #define print(x) cout << x << endl #define maxch(x, y) x = max(x, y) #define minch(x, y) x = min(x, y) #define uni(x) x.erase(unique(all(x)), x.end()) #define exist(x, y) (find(all(x), y) != x.end()) #define bcnt(x) bitset<32>(x).count() typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; typedef pair<double, double> PD; typedef pair<P, int> PPI; typedef pair<int, P> PIP; typedef pair<ll, ll> PL; typedef pair<P, ll> PPL; typedef set<int> S; #define INF INT_MAX / 3 #define MAX_N 1000000001 vector<PD> cli(double a, double b, double c, PD c1) { double l = a * a + b * b, k = a * c1.fi + b * c1.se + c, d = l - k * k; vector<PD> v; if (d > 0) { double ds = sqrt(d), apl = a / l, bpl = b / l; double xc = c1.fi - apl * k, xd = bpl * ds, yc = c1.se - bpl * k, yd = apl * ds; v.pb(PD(xc - xd, yc + yd)), v.pb(PD(xc + xd, yc - yd)); } else if (d == 0) { v.pb(PD(c1.fi - a * k / l, c1.se - b * k / l)); } return v; } vector<PD> cci(PD c1, PD c2) { double a = c1.fi - c2.fi, b = c1.se - c2.se; return cli(2.0 * a, 2.0 * b, 0 - a * (c1.fi + c2.fi) - b * (c1.se + c2.se), c1); } bool dist(PD p1, PD p2) { return (pow(p1.fi - p2.fi, 2.0) + pow(p1.se - p2.se, 2.0)) <= 1.0 + 1e-7; } int main() { cin.sync_with_stdio(false); int n; while (cin >> n, n) { vector<PD> v(n); rep(i, n) cin >> v[i].fi >> v[i].se; int maxi = 1; rep(i, n - 1) repl(j, i + 1, n) { vector<PD> p = cci(v[i], v[j]); rep(k, p.size()) { int cnt = 0; rep(l, n) { if (dist(p[k], v[l])) cnt++; } maxch(maxi, cnt); } } cout << maxi << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
1
661
/* ??????????????????????????????3??\??????3???????????¨?????????????????????????????????????????¨???????????? */ #include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <utility> #include <vector> using namespace std; typedef long double ld; typedef long long ll; typedef vector<int> vint; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; typedef complex<double> comd; #define rep(i, n) for (int i = 0; i < n; i++) #define srep(i, a, n) for (int i = a; i < n; i++) #define REP(i, n) for (int i = 0; i <= n; i++) #define SREP(i, a, n) for (int i = a; i <= n; i++) #define rrep(i, n) for (int i = n - 1; i >= 0; i--) #define RREP(i, n) for (int i = n; i >= 0; i--) #define all(a) (a).begin(), (a).end() #define mp(a, b) make_pair(a, b) #define mt make_tuple #define fst first #define scn second #define bucnt(x) __buildin__popcount(x) #define debug(x) cout << "debug: " << x << endl const ll inf = (ll)1e9; const ll mod = (ll)1e9 + 7; const ld eps = 1e-9; const int dx[] = {0, 1, 0, -1}; const int dy[] = {1, 0, -1, 0}; double Dist2(pdd a, pdd b) { return (a.fst - b.fst) * (a.fst - b.fst) + (a.scn - b.scn) * (a.scn - b.scn); } vector<pdd> getCenter(pdd a, pdd b) { vector<pdd> ret; pdd c = mp((a.fst + b.fst) / 2.0, (a.scn + b.scn) / 2.0); pdd v = mp(a.scn - b.scn, b.fst - a.fst); double D = sqrt(v.fst * v.fst + v.scn * v.scn); v.fst /= D; v.scn /= D; D = sqrt(1 - Dist2(a, b) / 4.0); v.fst *= D; v.scn *= D; ret.push_back(mp(c.fst + v.fst, c.scn + v.scn)); ret.push_back(mp(c.fst - v.fst, c.scn - v.scn)); return ret; } int main() { while (true) { int n; cin >> n; if (n == 0) break; vector<pdd> p(n, mp(0, 0)); rep(i, n) cin >> p[i].fst >> p[i].scn; int ret = 0; rep(i, n) { rep(j, i) { if (Dist2(p[i], p[j]) <= 4.0) { vector<pdd> c = getCenter(p[i], p[j]); int tmp = 0; rep(k, n) { if (Dist2(c[0], p[k]) <= 1.0 + eps) tmp++; } ret = max(ret, tmp); tmp = 0; rep(k, n) { if (Dist2(c[1], p[k]) <= 1.0 + eps) tmp++; } ret = max(ret, tmp); } } } cout << ret << endl; } return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <utility> #include <vector> using namespace std; typedef long double ld; typedef long long ll; typedef vector<int> vint; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; typedef complex<double> comd; #define rep(i, n) for (int i = 0; i < n; i++) #define srep(i, a, n) for (int i = a; i < n; i++) #define REP(i, n) for (int i = 0; i <= n; i++) #define SREP(i, a, n) for (int i = a; i <= n; i++) #define rrep(i, n) for (int i = n - 1; i >= 0; i--) #define RREP(i, n) for (int i = n; i >= 0; i--) #define all(a) (a).begin(), (a).end() #define mp(a, b) make_pair(a, b) #define mt make_tuple #define fst first #define scn second #define bucnt(x) __buildin__popcount(x) #define debug(x) cout << "debug: " << x << endl const ll inf = (ll)1e9; const ll mod = (ll)1e9 + 7; const ld eps = 1e-9; const int dx[] = {0, 1, 0, -1}; const int dy[] = {1, 0, -1, 0}; double Dist2(pdd a, pdd b) { return (a.fst - b.fst) * (a.fst - b.fst) + (a.scn - b.scn) * (a.scn - b.scn); } vector<pdd> getCenter(pdd a, pdd b) { vector<pdd> ret; pdd c = mp((a.fst + b.fst) / 2.0, (a.scn + b.scn) / 2.0); pdd v = mp(a.scn - b.scn, b.fst - a.fst); double D = sqrt(v.fst * v.fst + v.scn * v.scn); v.fst /= D; v.scn /= D; D = sqrt(1 - Dist2(a, b) / 4.0); v.fst *= D; v.scn *= D; ret.push_back(mp(c.fst + v.fst, c.scn + v.scn)); ret.push_back(mp(c.fst - v.fst, c.scn - v.scn)); return ret; } int main() { while (true) { int n; cin >> n; if (n == 0) break; vector<pdd> p(n, mp(0, 0)); rep(i, n) cin >> p[i].fst >> p[i].scn; int ret = 1; rep(i, n) { rep(j, i) { if (Dist2(p[i], p[j]) <= 4.0) { vector<pdd> c = getCenter(p[i], p[j]); int tmp = 0; rep(k, n) { if (Dist2(c[0], p[k]) <= 1.0 + eps) tmp++; } ret = max(ret, tmp); tmp = 0; rep(k, n) { if (Dist2(c[1], p[k]) <= 1.0 + eps) tmp++; } ret = max(ret, tmp); } } } cout << ret << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
1
693
#include "bits/stdc++.h" #define REP(i, n) for (ll i = 0; i < n; ++i) #define RREP(i, n) for (ll i = n - 1; i >= 0; --i) #define FOR(i, m, n) for (ll i = m; i < n; ++i) #define RFOR(i, m, n) for (ll i = n - 1; i >= m; --i) #define ALL(v) (v).begin(), (v).end() #define UNIQUE(v) v.erase(unique(ALL(v)), v.end()); #define DUMP(v) \ REP(aa, (v).size()) { \ cout << v[aa]; \ if (aa != v.size() - 1) \ cout << " "; \ else \ cout << endl; \ } #define INF 1000000001ll #define MOD 1000000007ll #define EPS 1e-9 const int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; const int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vi> vvi; typedef vector<vl> vvl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; ll max(ll a, int b) { return max(a, ll(b)); } ll max(int a, ll b) { return max(ll(a), b); } ll min(ll a, int b) { return min(a, ll(b)); } ll min(int a, ll b) { return min(ll(a), b); } ///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)/// int main() { cin.tie(0); ios::sync_with_stdio(false); int n; while (cin >> n, n) { vector<double> x(n), y(n); int ans = -1; REP(i, n) cin >> x[i] >> y[i]; REP(i, n) { REP(j, n) { if (i == j) continue; double ax = x[j] - x[i], ay = y[j] - y[i]; if (ax * ax + ay * ay + EPS > 4) continue; double px = x[i] + ax / 2 + sqrt((4 - (ax * ax + ay * ay)) / (4 * (ax * ax + ay * ay))) * ay, py = y[i] + ay / 2 - sqrt((4 - (ax * ax + ay * ay)) / (4 * (ax * ax + ay * ay))) * ax; int cnt = 0; REP(k, n) { if ((x[k] - px) * (x[k] - px) + (y[k] - py) * (y[k] - py) < 1 + EPS) cnt++; } ans = max(ans, cnt); } } REP(i, n) { REP(j, n) { if (i == j) continue; double ax = x[j] - x[i], ay = y[j] - y[i]; if (ax * ax + ay * ay + EPS > 4) continue; double px = x[i] + ax / 2 - sqrt((4 - (ax * ax + ay * ay)) / (4 * (ax * ax + ay * ay))) * ay, py = y[i] + ay / 2 + sqrt((4 - (ax * ax + ay * ay)) / (4 * (ax * ax + ay * ay))) * ax; int cnt = 0; REP(k, n) { if ((x[k] - px) * (x[k] - px) + (y[k] - py) * (y[k] - py) < 1 + EPS) cnt++; } ans = max(ans, cnt); } } cout << ans << endl; } }
#include "bits/stdc++.h" #define REP(i, n) for (ll i = 0; i < n; ++i) #define RREP(i, n) for (ll i = n - 1; i >= 0; --i) #define FOR(i, m, n) for (ll i = m; i < n; ++i) #define RFOR(i, m, n) for (ll i = n - 1; i >= m; --i) #define ALL(v) (v).begin(), (v).end() #define UNIQUE(v) v.erase(unique(ALL(v)), v.end()); #define DUMP(v) \ REP(aa, (v).size()) { \ cout << v[aa]; \ if (aa != v.size() - 1) \ cout << " "; \ else \ cout << endl; \ } #define INF 1000000001ll #define MOD 1000000007ll #define EPS 1e-9 const int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; const int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vi> vvi; typedef vector<vl> vvl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; ll max(ll a, int b) { return max(a, ll(b)); } ll max(int a, ll b) { return max(ll(a), b); } ll min(ll a, int b) { return min(a, ll(b)); } ll min(int a, ll b) { return min(ll(a), b); } ///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)/// int main() { cin.tie(0); ios::sync_with_stdio(false); int n; while (cin >> n, n) { vector<double> x(n), y(n); int ans = 1; REP(i, n) cin >> x[i] >> y[i]; REP(i, n) { REP(j, n) { if (i == j) continue; double ax = x[j] - x[i], ay = y[j] - y[i]; if (ax * ax + ay * ay + EPS > 4) continue; double px = x[i] + ax / 2 + sqrt((4 - (ax * ax + ay * ay)) / (4 * (ax * ax + ay * ay))) * ay, py = y[i] + ay / 2 - sqrt((4 - (ax * ax + ay * ay)) / (4 * (ax * ax + ay * ay))) * ax; int cnt = 0; REP(k, n) { if ((x[k] - px) * (x[k] - px) + (y[k] - py) * (y[k] - py) < 1 + EPS) cnt++; } ans = max(ans, cnt); } } REP(i, n) { REP(j, n) { if (i == j) continue; double ax = x[j] - x[i], ay = y[j] - y[i]; if (ax * ax + ay * ay + EPS > 4) continue; double px = x[i] + ax / 2 - sqrt((4 - (ax * ax + ay * ay)) / (4 * (ax * ax + ay * ay))) * ay, py = y[i] + ay / 2 + sqrt((4 - (ax * ax + ay * ay)) / (4 * (ax * ax + ay * ay))) * ax; int cnt = 0; REP(k, n) { if ((x[k] - px) * (x[k] - px) + (y[k] - py) * (y[k] - py) < 1 + EPS) cnt++; } ans = max(ans, cnt); } } cout << ans << endl; } }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
1
781
#include <algorithm> #include <cassert> #include <cctype> #include <cmath> #include <cstdio> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <time.h> #include <typeinfo> #include <vector> #define syosu(x) fixed << setprecision(x) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; typedef pair<double, double> pdd; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<char> vc; typedef vector<vc> vvc; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<P> vp; typedef vector<vp> vvp; typedef vector<pll> vpll; typedef pair<P, int> pip; typedef vector<pip> vip; const int inf = 1 << 28; const ll INF = 1ll << 60; const double pi = acos(-1); const double eps = 1e-8; const ll mod = 1e9 + 7; const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; struct point { double x, y; point operator+(point p) { return point{x + p.x, y + p.y}; } point operator-(point p) { return point{x - p.x, y - p.y}; } point operator*(double p) { return point{x * p, y * p}; } point operator/(double p) { if (!p) return point{0, 0}; return point{x / p, y / p}; } bool operator==(point p) { return fabs(x - p.x) < eps && fabs(y - p.y) < eps; } bool operator<(point p) { if (fabs(x - p.x) > eps) return x < p.x; return y < p.y; } }; typedef pair<point, point> pp; typedef vector<point> VP; const point O{0, 0}; double Length(point x, point y) { point z = y - x; return sqrt(z.x * z.x + z.y * z.y); } point Normal(point p) { return point{p.y, -p.x}; } int n; VP p; int f(point q) { int res = 0; for (int i = 0; i < n; i++) if (Length(p[i], q) < 1 + eps) res++; return res; } int main() { while (1) { cin >> n; if (!n) break; p = VP(n); for (int i = 0; i < n; i++) cin >> p[i].x >> p[i].y; int res = 0; for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) { point c = (p[i] + p[j]) / 2, e = Normal(p[i] - p[j]); double l = Length(c, p[i]); e = e / Length(O, e) * sqrt(1.0 - l * l); res = max(res, max(f(c + e), f(c - e))); } cout << res << endl; } }
#include <algorithm> #include <cassert> #include <cctype> #include <cmath> #include <cstdio> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <time.h> #include <typeinfo> #include <vector> #define syosu(x) fixed << setprecision(x) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; typedef pair<double, double> pdd; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<char> vc; typedef vector<vc> vvc; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<P> vp; typedef vector<vp> vvp; typedef vector<pll> vpll; typedef pair<P, int> pip; typedef vector<pip> vip; const int inf = 1 << 28; const ll INF = 1ll << 60; const double pi = acos(-1); const double eps = 1e-8; const ll mod = 1e9 + 7; const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; struct point { double x, y; point operator+(point p) { return point{x + p.x, y + p.y}; } point operator-(point p) { return point{x - p.x, y - p.y}; } point operator*(double p) { return point{x * p, y * p}; } point operator/(double p) { if (!p) return point{0, 0}; return point{x / p, y / p}; } bool operator==(point p) { return fabs(x - p.x) < eps && fabs(y - p.y) < eps; } bool operator<(point p) { if (fabs(x - p.x) > eps) return x < p.x; return y < p.y; } }; typedef pair<point, point> pp; typedef vector<point> VP; const point O{0, 0}; double Length(point x, point y) { point z = y - x; return sqrt(z.x * z.x + z.y * z.y); } point Normal(point p) { return point{p.y, -p.x}; } int n; VP p; int f(point q) { int res = 0; for (int i = 0; i < n; i++) if (Length(p[i], q) < 1 + eps) res++; return res; } int main() { while (1) { cin >> n; if (!n) break; p = VP(n); for (int i = 0; i < n; i++) cin >> p[i].x >> p[i].y; int res = 1; for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) { point c = (p[i] + p[j]) / 2, e = Normal(p[i] - p[j]); double l = Length(c, p[i]); e = e / Length(O, e) * sqrt(1.0 - l * l); res = max(res, max(f(c + e), f(c - e))); } cout << res << endl; } }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
1
781
#include <iostream> #include <math.h> using namespace std; #define REP(i, n) for (int i = 0; i < n; i++) double p[300][2]; int n; double dis(double x1, double y1, double x2, double y2) { return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2)); } int circle(double x, double y, int i, int j) { int count = 2; REP(k, n) { if (k != i && k != j) { if (dis(x, y, p[k][0], p[k][1]) < 1) { count += 1; } } } return count; } int main() { while (1) { cin >> n; if (n == 0) break; REP(i, n) { cin >> p[i][0]; cin >> p[i][1]; } int output = 0; REP(i, n) { for (int j = i + 1; j < n; j++) { double cx = (p[i][0] + p[j][0]) / 2; double cy = (p[i][1] + p[j][1]) / 2; double d = dis(p[i][0], p[i][1], p[j][0], p[j][1]); if (d > 2) { continue; } else if (d == 2) { output = max(output, circle(cx, cy, i, j)); } else { double a1 = acos(d / 2); double a2 = atan2((p[j][1] - p[i][1]), p[j][0] - p[i][0]); double x1 = p[i][0] + cos(a2 + a1); double y1 = p[i][1] + sin(a2 + a1); double x2 = p[i][0] + cos(a2 - a1); double y2 = p[i][1] + sin(a2 - a1); output = max(output, circle(x1, y1, i, j)); output = max(output, circle(x2, y2, i, j)); } } } cout << output << endl; } }
#include <iostream> #include <math.h> using namespace std; #define REP(i, n) for (int i = 0; i < n; i++) double p[300][2]; int n; double dis(double x1, double y1, double x2, double y2) { return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2)); } int circle(double x, double y, int i, int j) { int count = 2; REP(k, n) { if (k != i && k != j) { if (dis(x, y, p[k][0], p[k][1]) < 1) { count += 1; } } } return count; } int main() { while (1) { cin >> n; if (n == 0) break; REP(i, n) { cin >> p[i][0]; cin >> p[i][1]; } int output = 1; REP(i, n) { for (int j = i + 1; j < n; j++) { double cx = (p[i][0] + p[j][0]) / 2; double cy = (p[i][1] + p[j][1]) / 2; double d = dis(p[i][0], p[i][1], p[j][0], p[j][1]); if (d > 2) { continue; } else if (d == 2) { output = max(output, circle(cx, cy, i, j)); } else { double a1 = acos(d / 2); double a2 = atan2((p[j][1] - p[i][1]), p[j][0] - p[i][0]); double x1 = p[i][0] + cos(a2 + a1); double y1 = p[i][1] + sin(a2 + a1); double x2 = p[i][0] + cos(a2 - a1); double y2 = p[i][1] + sin(a2 - a1); output = max(output, circle(x1, y1, i, j)); output = max(output, circle(x2, y2, i, j)); } } } cout << output << endl; } }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
1
516
#include "bits/stdc++.h" using namespace std; typedef complex<double> Point; const double eps = 1e-9; int main(void) { cin.tie(0); ios::sync_with_stdio(false); int N; while (cin >> N, N) { vector<Point> P(N); for (int i = 0; i < N; i++) { double x, y; cin >> x >> y; P[i] = Point(x, y); } if (N == 1) { cout << 1 << endl; return 0; } int ans = 0; for (int i = 0; i < N; i++) for (int j = i + 1; j < N; j++) { double dist = abs(P[i] - P[j]); if (dist > 2) continue; double r = sqrt(1 - dist * dist / 4); double difx = -(P[i] - P[j]).imag() * r / dist; double dify = (P[i] - P[j]).real() * r / dist; Point new_P(difx, dify); Point check_P(new_P + (P[i] + P[j]) / 2.0); int cnt = 0; for (int k = 0; k < N; k++) { if (abs(check_P - P[k]) < 1.0 + eps) cnt++; } ans = max(ans, cnt); } cout << ans << endl; } return 0; }
#include "bits/stdc++.h" using namespace std; typedef complex<double> Point; const double eps = 1e-9; int main(void) { cin.tie(0); ios::sync_with_stdio(false); int N; while (cin >> N, N) { vector<Point> P(N); for (int i = 0; i < N; i++) { double x, y; cin >> x >> y; P[i] = Point(x, y); } if (N == 1) { cout << 1 << endl; continue; } int ans = 1; for (int i = 0; i < N; i++) for (int j = i + 1; j < N; j++) { double dist = abs(P[i] - P[j]); if (dist > 2) continue; double r = sqrt(1 - dist * dist / 4); double difx = -(P[i] - P[j]).imag() * r / dist; double dify = (P[i] - P[j]).real() * r / dist; Point new_P(difx, dify); Point check_P(new_P + (P[i] + P[j]) / 2.0); int cnt = 0; for (int k = 0; k < N; k++) { if (abs(check_P - P[k]) < 1.0 + eps) cnt++; } ans = max(ans, cnt); } cout << ans << endl; } return 0; }
[["-", 8, 9, 0, 57, 64, 9, 0, 37, 0, 38], ["-", 8, 9, 0, 57, 64, 9, 0, 37, 0, 13], ["+", 8, 9, 0, 57, 64, 9, 0, 116, 0, 117], ["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
1
328
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int INF = 1e9; const ll LINF = 1e18; template <class S, class T> ostream &operator<<(ostream &out, const pair<S, T> &o) { out << "(" << o.first << "," << o.second << ")"; return out; } template <class T> ostream &operator<<(ostream &out, const vector<T> V) { for (int i = 0; i < V.size(); i++) { out << V[i]; if (i != V.size() - 1) out << " "; } return out; } template <class T> ostream &operator<<(ostream &out, const vector<vector<T>> Mat) { for (int i = 0; i < Mat.size(); i++) { if (i != 0) out << endl; out << Mat[i]; } return out; } template <class S, class T> ostream &operator<<(ostream &out, const map<S, T> mp) { out << "{ "; for (auto it = mp.begin(); it != mp.end(); it++) { out << it->first << ":" << it->second; if (mp.size() - 1 != distance(mp.begin(), it)) out << ", "; } out << " }"; return out; } /* <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1132> 問題文============================================================ ================================================================= 解説============================================================= ================================================================ */ typedef complex<double> Point; int n; int solve() { int res = 1; vector<Point> ps(n); for (int i = 0; i < n; i++) { double x, y; cin >> x >> y; ps[i] = Point(x, y); } for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { double dist = abs(ps[i] - ps[j]); if (dist > 2) continue; Point mp = (ps[i] + ps[j]) / 2.; Point dp = ps[i] - ps[j]; double x = sqrt(1 - dist * dist / 4); Point cp = Point(-dp.imag() * x / dist + mp.real(), dp.real() * x / dist + mp.imag()); int cnt = 0; for (int k = 0; k < n; k++) { if (abs(cp - ps[k]) <= 1.0) cnt++; } res = max(res, cnt); } } return res; } int main(void) { cin.tie(0); ios_base::sync_with_stdio(false); while (cin >> n, n) { cout << solve() << endl; } return 0; }
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int INF = 1e9; const ll LINF = 1e18; template <class S, class T> ostream &operator<<(ostream &out, const pair<S, T> &o) { out << "(" << o.first << "," << o.second << ")"; return out; } template <class T> ostream &operator<<(ostream &out, const vector<T> V) { for (int i = 0; i < V.size(); i++) { out << V[i]; if (i != V.size() - 1) out << " "; } return out; } template <class T> ostream &operator<<(ostream &out, const vector<vector<T>> Mat) { for (int i = 0; i < Mat.size(); i++) { if (i != 0) out << endl; out << Mat[i]; } return out; } template <class S, class T> ostream &operator<<(ostream &out, const map<S, T> mp) { out << "{ "; for (auto it = mp.begin(); it != mp.end(); it++) { out << it->first << ":" << it->second; if (mp.size() - 1 != distance(mp.begin(), it)) out << ", "; } out << " }"; return out; } /* <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1132> 問題文============================================================ ================================================================= 解説============================================================= ================================================================ */ typedef complex<double> Point; int n; int solve() { int res = 1; vector<Point> ps(n); for (int i = 0; i < n; i++) { double x, y; cin >> x >> y; ps[i] = Point(x, y); } for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { double dist = abs(ps[i] - ps[j]); if (dist > 2) continue; Point mp = (ps[i] + ps[j]) / 2.; Point dp = ps[i] - ps[j]; double x = sqrt(1 - dist * dist / 4); Point cp = Point(-dp.imag() * x / dist + mp.real(), dp.real() * x / dist + mp.imag()); int cnt = 0; for (int k = 0; k < n; k++) { if (abs(cp - ps[k]) < 1.0 + 1e-9) cnt++; } res = max(res, cnt); } } return res; } int main(void) { cin.tie(0); ios_base::sync_with_stdio(false); while (cin >> n, n) { cout << solve() << endl; } return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 72], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
1
645
#include <cmath> #include <iostream> #define eps 1.0e-9 using namespace std; int N; double x[305], y[305]; int count(double cx, double cy) { int ret = 0; for (int i = 0; i < N; i++) { if ((cx - x[i]) * (cx - x[i]) + (cy - y[i]) * (cy - y[i]) <= 1 + eps) ret++; } return ret; } int main(void) { while (1) { cin >> N; if (N == 0) break; for (int i = 0; i < N; i++) cin >> x[i] >> y[i]; int ans = -1; double cx, cy; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (i >= j) continue; double px = x[j] - x[i]; double py = y[j] - y[i]; double pnorm = sqrt(px * px + py * py); px /= pnorm; py /= pnorm; double mx = (x[i] + x[j]) / 2.0; double my = (y[i] + y[j]) / 2.0; double qnorm = 1 - pnorm * pnorm / 4.0; if (qnorm < eps) continue; qnorm = sqrt(qnorm); double qx = qnorm * py; double qy = qnorm * -px; ans = max(ans, count(mx + qx, my + qy)); ans = max(ans, count(mx - qx, my - qy)); } } cout << ans << endl; } return 0; }
#include <cmath> #include <iostream> #define eps 1.0e-9 using namespace std; int N; double x[305], y[305]; int count(double cx, double cy) { int ret = 0; for (int i = 0; i < N; i++) { if ((cx - x[i]) * (cx - x[i]) + (cy - y[i]) * (cy - y[i]) <= 1 + eps) ret++; } return ret; } int main(void) { while (1) { cin >> N; if (N == 0) break; for (int i = 0; i < N; i++) cin >> x[i] >> y[i]; int ans = 1; double cx, cy; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (i >= j) continue; double px = x[j] - x[i]; double py = y[j] - y[i]; double pnorm = sqrt(px * px + py * py); px /= pnorm; py /= pnorm; double mx = (x[i] + x[j]) / 2.0; double my = (y[i] + y[j]) / 2.0; double qnorm = 1 - pnorm * pnorm / 4.0; if (qnorm < eps) continue; qnorm = sqrt(qnorm); double qx = qnorm * py; double qy = qnorm * -px; ans = max(ans, count(mx + qx, my + qy)); ans = max(ans, count(mx - qx, my - qy)); } } cout << ans << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
1
374
//#define __USE_MINGW_ANSI_STDIO 0 #include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<ll> VL; typedef vector<VL> VVL; typedef pair<int, int> PII; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() #define IN(a, b, x) (a <= x && x < b) #define MP make_pair #define PB push_back #ifdef int const ll INF = (1LL << 60); #else const int INF = (1LL << 30); #endif const double PI = 3.14159265359; const double EPS = 1e-12; const int MOD = 1000000007; template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); } template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); } int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // y???real(), x???imag() // point typedef complex<double> P; namespace std { bool operator<(const P &a, const P &b) { return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b); } bool cmp_y(const P &a, const P &b) { return a.imag() != b.imag() ? a.imag() < b.imag() : a.real() < b.real(); } } // namespace std // circle struct C { P p; double r; C(const P &p, double r) : p(p), r(r) {} }; // 2???p1, p2?????????????????????r?????????2????????? vector<C> calcCircle(P p1, P p2, double r) { if (abs(p1 - p2) > 2 * r) return {}; P p3 = {(p1.real() + p2.real()) / 2, (p1.imag() + p2.imag()) / 2}; // cout << p3.real() << " " << p3.imag() << endl; double l = abs(p1 - p3); // cout << "l:" << l << endl; // ????????????p_1p_2 P p1p2 = p2 - p1; double a = p1p2.real(), b = p1p2.imag(); double dx = b * sqrt((r * r - l * l) / (a * a + b * b)), dy = a * sqrt((r * r - l * l) / (a * a + b * b)); // cout << "dx:" << dx << " dy:" << dy << endl; return {{{p3.real() + dx, p3.imag() - dy}, r}, {{p3.real() - dx, p3.imag() + dy}, r}}; } // ???p??????c????????¨????????¨?????????????????? bool intersectCP(C c, P p) { return abs(p - c.p) <= c.r + EPS; } P po[305]; signed main(void) { while (true) { int n; cin >> n; if (!n) break; REP(i, n) { double x, y; cin >> x >> y; po[i] = {x, y}; } int ans = 0; REP(i, n) FOR(j, i + 1, n) { vector<C> ret = calcCircle(po[i], po[j], 1); if (ret.size() == 0) continue; // cout << "i:" << i << " j:" << j << endl; // cout << ret[0].p.real() << " " << ret[0].p.imag() << " " << ret[0].r << // endl; cout << ret[1].p.real() << " " << ret[1].p.imag() << " " << // ret[1].r << endl; int num = 0; REP(k, n) { num += intersectCP(ret[0], po[k]) ? 1 : 0; // if(intersectCP(ret[0], po[k])) cout << k << " "; } chmax(ans, num); // cout << "num:" << num << endl; num = 0; REP(k, n) { num += intersectCP(ret[1], po[k]) ? 1 : 0; // if(intersectCP(ret[1], po[k])) cout << k << " "; } // cout << "num:" << num << endl; chmax(ans, num); } cout << ans << endl; } return 0; }
//#define __USE_MINGW_ANSI_STDIO 0 #include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<ll> VL; typedef vector<VL> VVL; typedef pair<int, int> PII; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() #define IN(a, b, x) (a <= x && x < b) #define MP make_pair #define PB push_back #ifdef int const ll INF = (1LL << 60); #else const int INF = (1LL << 30); #endif const double PI = 3.14159265359; const double EPS = 1e-12; const int MOD = 1000000007; template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); } template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); } int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // y???real(), x???imag() // point typedef complex<double> P; namespace std { bool operator<(const P &a, const P &b) { return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b); } bool cmp_y(const P &a, const P &b) { return a.imag() != b.imag() ? a.imag() < b.imag() : a.real() < b.real(); } } // namespace std // circle struct C { P p; double r; C(const P &p, double r) : p(p), r(r) {} }; // 2???p1, p2?????????????????????r?????????2????????? vector<C> calcCircle(P p1, P p2, double r) { if (abs(p1 - p2) > 2 * r) return {}; P p3 = {(p1.real() + p2.real()) / 2, (p1.imag() + p2.imag()) / 2}; // cout << p3.real() << " " << p3.imag() << endl; double l = abs(p1 - p3); // cout << "l:" << l << endl; // ????????????p_1p_2 P p1p2 = p2 - p1; double a = p1p2.real(), b = p1p2.imag(); double dx = b * sqrt((r * r - l * l) / (a * a + b * b)), dy = a * sqrt((r * r - l * l) / (a * a + b * b)); // cout << "dx:" << dx << " dy:" << dy << endl; return {{{p3.real() + dx, p3.imag() - dy}, r}, {{p3.real() - dx, p3.imag() + dy}, r}}; } // ???p??????c????????¨????????¨?????????????????? bool intersectCP(C c, P p) { return abs(p - c.p) <= c.r + EPS; } P po[305]; signed main(void) { while (true) { int n; cin >> n; if (!n) break; REP(i, n) { double x, y; cin >> x >> y; po[i] = {x, y}; } int ans = 1; REP(i, n) FOR(j, i + 1, n) { vector<C> ret = calcCircle(po[i], po[j], 1); if (ret.size() == 0) continue; // cout << "i:" << i << " j:" << j << endl; // cout << ret[0].p.real() << " " << ret[0].p.imag() << " " << ret[0].r << // endl; cout << ret[1].p.real() << " " << ret[1].p.imag() << " " << // ret[1].r << endl; int num = 0; REP(k, n) { num += intersectCP(ret[0], po[k]) ? 1 : 0; // if(intersectCP(ret[0], po[k])) cout << k << " "; } chmax(ans, num); // cout << "num:" << num << endl; num = 0; REP(k, n) { num += intersectCP(ret[1], po[k]) ? 1 : 0; // if(intersectCP(ret[1], po[k])) cout << k << " "; } // cout << "num:" << num << endl; chmax(ans, num); } cout << ans << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
1
825
#include <algorithm> #include <cmath> #include <iostream> #include <utility> using namespace std; const double eps = 1e-8; struct point { double x, y; } P[310]; int x, y, N; int ans = 1; double cal_distance(point a, point b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } point cal_center(point a, point b) { point mid, center; mid.x = (a.x + b.x) / 2.0; mid.y = (a.y + b.y) / 2.0; double angle = atan2(a.x - b.x, b.y - a.y); double line = sqrt(1 - (cal_distance(a, mid) * cal_distance(a, mid))); center.x = mid.x + line * cos(angle); center.y = mid.y + line * sin(angle); return center; } int main() { while (cin >> N && N > 0) { for (int i = 0; i < N; i++) { cin >> P[i].x >> P[i].y; } for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { if (cal_distance(P[i], P[j]) > 2.0) continue; point center = cal_center(P[i], P[j]); int count = 0; for (int k = 0; k < N; k++) { if (cal_distance(P[k], center) < (1.0 + eps)) count++; } ans = max(ans, count); } } cout << ans << endl; } }
#include <algorithm> #include <cmath> #include <iostream> #include <utility> using namespace std; const double eps = 1e-8; struct point { double x, y; } P[310]; int x, y, N; int ans = 1; double cal_distance(point a, point b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } point cal_center(point a, point b) { point mid, center; mid.x = (a.x + b.x) / 2.0; mid.y = (a.y + b.y) / 2.0; double angle = atan2(a.x - b.x, b.y - a.y); double line = sqrt(1 - (cal_distance(a, mid) * cal_distance(a, mid))); center.x = mid.x + line * cos(angle); center.y = mid.y + line * sin(angle); return center; } int main() { while (cin >> N && N > 0) { ans = 1; for (int i = 0; i < N; i++) { cin >> P[i].x >> P[i].y; } for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { if (cal_distance(P[i], P[j]) > 2.0) continue; point center = cal_center(P[i], P[j]); int count = 0; for (int k = 0; k < N; k++) { if (cal_distance(P[k], center) < (1.0 + eps)) count++; } ans = max(ans, count); } } cout << ans << endl; } }
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
402
#include "bits/stdc++.h" using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef pair<int, int> P; const LL MOD = 1000000007LL; const double EPS = 1e-10; struct Point { double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} Point operator+(const Point &p) const { return Point(x + p.x, y + p.y); } Point operator-(const Point &p) const { return Point(x - p.x, y - p.y); } Point operator*(const double a) const { return Point(x * a, y * a); } Point operator/(double a) const { return Point(x / a, y / a); } double abs() const { return sqrt(norm()); } double norm() const { return x * x + y * y; } bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; } bool operator==(const Point &p) const { return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS; } }; typedef Point Vector; struct Segment { Point p1, p2; }; typedef Segment Line; struct Circle { Point c; double r; Circle(Point c = Point(), double r = 0.0) : c(c), r(r) {} }; typedef vector<Point> Polygon; double norm(Vector a); double abs(Vector a); double dot(Vector a, Vector b); double cross(Vector a, Vector b); bool equals(double a, double b); bool isOrthogonal(Vector a, Vector b); bool isOrthogonal(Point a1, Point a2, Point b1, Point b2); bool isOrthogonal(Segment s1, Segment s2); bool isParallel(Vector a, Vector b); bool isParallel(Point a1, Point a2, Point b1, Point b2); bool isParallel(Segment s1, Segment s2); Point project(Segment s, Point p); Point reflect(Segment s, Point p); int ccw(Point p0, Point p1, Point p2); double getDistance(Point a, Point b); double getDistanceLP(Line l, Point p); double getDistanceSP(Segment s, Point p); double getDistance(Segment s1, Segment s2); bool intersect(Point p1, Point p2, Point p3, Point p4); bool intersect(Segment s1, Segment s2); bool intersect(Circle c, Line l); bool intersect(Circle c1, Circle c2); Point getCrossPoint(Segment s1, Segment s2); pair<Point, Point> getCrossPoints(Circle c, Line l); double arg(Vector p); Vector polar(double a, double r); pair<Point, Point> getCrossPoints(Circle c1, Circle c2); double norm(Vector a) { return a.x * a.x + a.y * a.y; } double abs(Vector a) { return sqrt(norm(a)); } double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; } double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; } bool equals(double a, double b) { return fabs(a - b) < EPS; } bool isOrthogonal(Vector a, Vector b) { return equals(dot(a, b), 0.0); } bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) { return isOrthogonal(a1 - a2, b1 - b2); } bool isOrthogonal(Segment s1, Segment s2) { return equals(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0); } bool isParallel(Vector a, Vector b) { return equals(cross(a, b), 0.0); } bool isParallel(Point a1, Point a2, Point b1, Point b2) { return isParallel(a1 - a2, b1 - b2); } bool isParallel(Segment s1, Segment s2) { return equals(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0); } Point project(Segment s, Point p) { Vector base = s.p2 - s.p1; double r = dot(p - s.p1, base) / norm(base); return s.p1 + base * r; } Point reflect(Segment s, Point p) { return p + (project(s, p) - p) * 2.0; } static const int COUNTER_CLOCKWISE = 1; static const int CLOCKWISE = -1; static const int ONLINE_BACK = 2; static const int ONLINE_FRONT = -2; static const int ON_SEGMENT = 0; int ccw(Point p0, Point p1, Point p2) { Vector a = p1 - p0; Vector b = p2 - p0; if (cross(a, b) > EPS) return COUNTER_CLOCKWISE; if (cross(a, b) < -EPS) return CLOCKWISE; if (dot(a, b) < -EPS) return ONLINE_BACK; if (a.norm() < b.norm()) return ONLINE_FRONT; return ON_SEGMENT; } double getDistance(Point a, Point b) { return abs(a - b); } double getDistanceLP(Line l, Point p) { return abs(cross(l.p2 - l.p1, p - l.p1) / abs(l.p2 - l.p1)); } double getDistanceSP(Segment s, Point p) { if (dot(s.p2 - s.p1, p - s.p1) < 0.0) return abs(p - s.p1); if (dot(s.p1 - s.p2, p - s.p2) < 0.0) return abs(p - s.p2); return getDistanceLP(s, p); } double getDistance(Segment s1, Segment s2) { if (intersect(s1, s2)) return 0.0; return min(min(getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2)), min(getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2))); } bool intersect(Point p1, Point p2, Point p3, Point p4) { return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 && ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0); } bool intersect(Segment s1, Segment s2) { return intersect(s1.p1, s1.p2, s2.p1, s2.p2); } bool intersect(Circle c, Line l) { return getDistanceLP(l, c.c) <= c.r; } bool intersect(Circle c1, Circle c2) { return getDistance(c1.c, c2.c) <= c1.r + c2.r; } Point getCrossPoint(Segment s1, Segment s2) { Vector base = s2.p2 - s2.p1; double d1 = abs(cross(base, s1.p1 - s2.p1)); double d2 = abs(cross(base, s1.p2 - s2.p1)); double t = d1 / (d1 + d2); return s1.p1 + (s1.p2 - s1.p1) * t; } pair<Point, Point> getCrossPoints(Circle c, Line l) { assert(intersect(c, l)); Vector pr = project(l, c.c); Vector e = (l.p2 - l.p1) / abs(l.p2 - l.p1); double base = sqrt(c.r * c.r - norm(pr - c.c)); return make_pair(pr + e * base, pr - e * base); } double arg(Vector p) { return atan2(p.y, p.x); } Vector polar(double a, double r) { return Vector(cos(r) * a, sin(r) * a); } pair<Point, Point> getCrossPoints(Circle c1, Circle c2) { assert(intersect(c1, c2)); double d = abs(c1.c - c2.c); double a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d)); double t = arg(c2.c - c1.c); return make_pair(c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a)); } int main() { int N; while (cin >> N, N) { Point p[300]; for (int i = 0; i < N; i++) { double x, y; cin >> x >> y; p[i] = Point(x, y); } int ans = 1; for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { Vector d = p[j] - p[i]; if (d.abs() > 2.0) continue; Point m = p[i] + d / 2.0; Vector r = Vector(-d.y, d.x); r = r / r.abs() * sqrt(1 - pow(d.abs() / 2.0, 2)); Point p1 = m + r; Point p2 = m - r; int cnt1 = 0; int cnt2 = 0; for (int k = 0; k < N; k++) { if ((p[k] - p1).abs() <= 1) cnt1++; if ((p[k] - p2).abs() <= 1) cnt2++; } ans = max(ans, max(cnt1, cnt2)); } } cout << ans << endl; } }
#include "bits/stdc++.h" using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef pair<int, int> P; const LL MOD = 1000000007LL; const double EPS = 1e-10; struct Point { double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} Point operator+(const Point &p) const { return Point(x + p.x, y + p.y); } Point operator-(const Point &p) const { return Point(x - p.x, y - p.y); } Point operator*(const double a) const { return Point(x * a, y * a); } Point operator/(double a) const { return Point(x / a, y / a); } double abs() const { return sqrt(norm()); } double norm() const { return x * x + y * y; } bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; } bool operator==(const Point &p) const { return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS; } }; typedef Point Vector; struct Segment { Point p1, p2; }; typedef Segment Line; struct Circle { Point c; double r; Circle(Point c = Point(), double r = 0.0) : c(c), r(r) {} }; typedef vector<Point> Polygon; double norm(Vector a); double abs(Vector a); double dot(Vector a, Vector b); double cross(Vector a, Vector b); bool equals(double a, double b); bool isOrthogonal(Vector a, Vector b); bool isOrthogonal(Point a1, Point a2, Point b1, Point b2); bool isOrthogonal(Segment s1, Segment s2); bool isParallel(Vector a, Vector b); bool isParallel(Point a1, Point a2, Point b1, Point b2); bool isParallel(Segment s1, Segment s2); Point project(Segment s, Point p); Point reflect(Segment s, Point p); int ccw(Point p0, Point p1, Point p2); double getDistance(Point a, Point b); double getDistanceLP(Line l, Point p); double getDistanceSP(Segment s, Point p); double getDistance(Segment s1, Segment s2); bool intersect(Point p1, Point p2, Point p3, Point p4); bool intersect(Segment s1, Segment s2); bool intersect(Circle c, Line l); bool intersect(Circle c1, Circle c2); Point getCrossPoint(Segment s1, Segment s2); pair<Point, Point> getCrossPoints(Circle c, Line l); double arg(Vector p); Vector polar(double a, double r); pair<Point, Point> getCrossPoints(Circle c1, Circle c2); double norm(Vector a) { return a.x * a.x + a.y * a.y; } double abs(Vector a) { return sqrt(norm(a)); } double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; } double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; } bool equals(double a, double b) { return fabs(a - b) < EPS; } bool isOrthogonal(Vector a, Vector b) { return equals(dot(a, b), 0.0); } bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) { return isOrthogonal(a1 - a2, b1 - b2); } bool isOrthogonal(Segment s1, Segment s2) { return equals(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0); } bool isParallel(Vector a, Vector b) { return equals(cross(a, b), 0.0); } bool isParallel(Point a1, Point a2, Point b1, Point b2) { return isParallel(a1 - a2, b1 - b2); } bool isParallel(Segment s1, Segment s2) { return equals(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0); } Point project(Segment s, Point p) { Vector base = s.p2 - s.p1; double r = dot(p - s.p1, base) / norm(base); return s.p1 + base * r; } Point reflect(Segment s, Point p) { return p + (project(s, p) - p) * 2.0; } static const int COUNTER_CLOCKWISE = 1; static const int CLOCKWISE = -1; static const int ONLINE_BACK = 2; static const int ONLINE_FRONT = -2; static const int ON_SEGMENT = 0; int ccw(Point p0, Point p1, Point p2) { Vector a = p1 - p0; Vector b = p2 - p0; if (cross(a, b) > EPS) return COUNTER_CLOCKWISE; if (cross(a, b) < -EPS) return CLOCKWISE; if (dot(a, b) < -EPS) return ONLINE_BACK; if (a.norm() < b.norm()) return ONLINE_FRONT; return ON_SEGMENT; } double getDistance(Point a, Point b) { return abs(a - b); } double getDistanceLP(Line l, Point p) { return abs(cross(l.p2 - l.p1, p - l.p1) / abs(l.p2 - l.p1)); } double getDistanceSP(Segment s, Point p) { if (dot(s.p2 - s.p1, p - s.p1) < 0.0) return abs(p - s.p1); if (dot(s.p1 - s.p2, p - s.p2) < 0.0) return abs(p - s.p2); return getDistanceLP(s, p); } double getDistance(Segment s1, Segment s2) { if (intersect(s1, s2)) return 0.0; return min(min(getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2)), min(getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2))); } bool intersect(Point p1, Point p2, Point p3, Point p4) { return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 && ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0); } bool intersect(Segment s1, Segment s2) { return intersect(s1.p1, s1.p2, s2.p1, s2.p2); } bool intersect(Circle c, Line l) { return getDistanceLP(l, c.c) <= c.r; } bool intersect(Circle c1, Circle c2) { return getDistance(c1.c, c2.c) <= c1.r + c2.r; } Point getCrossPoint(Segment s1, Segment s2) { Vector base = s2.p2 - s2.p1; double d1 = abs(cross(base, s1.p1 - s2.p1)); double d2 = abs(cross(base, s1.p2 - s2.p1)); double t = d1 / (d1 + d2); return s1.p1 + (s1.p2 - s1.p1) * t; } pair<Point, Point> getCrossPoints(Circle c, Line l) { assert(intersect(c, l)); Vector pr = project(l, c.c); Vector e = (l.p2 - l.p1) / abs(l.p2 - l.p1); double base = sqrt(c.r * c.r - norm(pr - c.c)); return make_pair(pr + e * base, pr - e * base); } double arg(Vector p) { return atan2(p.y, p.x); } Vector polar(double a, double r) { return Vector(cos(r) * a, sin(r) * a); } pair<Point, Point> getCrossPoints(Circle c1, Circle c2) { assert(intersect(c1, c2)); double d = abs(c1.c - c2.c); double a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d)); double t = arg(c2.c - c1.c); return make_pair(c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a)); } int main() { int N; while (cin >> N, N) { Point p[300]; for (int i = 0; i < N; i++) { double x, y; cin >> x >> y; p[i] = Point(x, y); } int ans = 1; for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { Vector d = p[j] - p[i]; if (d.abs() > 2.0) continue; Point m = p[i] + d / 2.0; Vector r = Vector(-d.y, d.x); r = r / r.abs() * sqrt(1 - pow(d.abs() / 2.0, 2)); Point p1 = m + r; Point p2 = m - r; int cnt1 = 0; int cnt2 = 0; for (int k = 0; k < N; k++) { if ((p[k] - p1).abs() <= 1 + EPS) cnt1++; if ((p[k] - p2).abs() <= 1 + EPS) cnt2++; } ans = max(ans, max(cnt1, cnt2)); } } cout << ans << endl; } }
[["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 72], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22]]
1
2,133
#include <cmath> #include <complex> #include <iostream> #define EPS 1e-9 using namespace std; typedef complex<double> xy_t; int n; xy_t points[301]; int count_in(xy_t center) { int ans = 0; for (int i = 0; i < n; i++) { if (abs(center - points[i]) < 1.0 + EPS) ans++; } return ans; } /*xy_t ppdcl(xy_t a) { return xy_t(a.imag(),-a.real()); } xy_t delta_v(xy_t C1,xy_t C2) { xy_t half=(C1-C2)*0.5; double l=abs(half); return ppdcl(half)*sqrt(1-l*l)*(1.0/l); }*/ int main() { while (1) { cin >> n; if (n == 0) break; double x, y; for (int i = 0; i < n; i++) { cin >> x >> y; points[i] = xy_t(x, y); } int maxn = -1; for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { /*if(abs(points[i]-points[j])<2.0) { xy_t mid_p=(points[i]+points[j])*0.5; maxn=max(maxn,count_in(mid_p+delta_v(points[i],points[j]))); maxn=max(maxn,count_in(mid_p-delta_v(points[i],points[j]))); }*/ double d = abs(points[j] - points[i]) / 2; xy_t v = (points[j] - points[i]) / (2 * d); if (d < 1) { maxn = max(maxn, count_in(points[i] + d * v + sqrt(1 - d * d) * v * xy_t(0, +1))); maxn = max(maxn, count_in(points[i] + d * v + sqrt(1 - d * d) * v * xy_t(0, -1))); } } } cout << maxn << endl; } }
#include <cmath> #include <complex> #include <iostream> #define EPS 1e-9 using namespace std; typedef complex<double> xy_t; int n; xy_t points[301]; int count_in(xy_t center) { int ans = 0; for (int i = 0; i < n; i++) { if (abs(center - points[i]) < 1.0 + EPS) ans++; } return ans; } /*xy_t ppdcl(xy_t a) { return xy_t(a.imag(),-a.real()); } xy_t delta_v(xy_t C1,xy_t C2) { xy_t half=(C1-C2)*0.5; double l=abs(half); return ppdcl(half)*sqrt(1-l*l)*(1.0/l); }*/ int main() { while (1) { cin >> n; if (n == 0) break; double x, y; for (int i = 0; i < n; i++) { cin >> x >> y; points[i] = xy_t(x, y); } int maxn = 1; for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { /*if(abs(points[i]-points[j])<2.0) { xy_t mid_p=(points[i]+points[j])*0.5; maxn=max(maxn,count_in(mid_p+delta_v(points[i],points[j]))); maxn=max(maxn,count_in(mid_p-delta_v(points[i],points[j]))); }*/ double d = abs(points[j] - points[i]) / 2; xy_t v = (points[j] - points[i]) / (2 * d); if (d < 1) { maxn = max(maxn, count_in(points[i] + d * v + sqrt(1 - d * d) * v * xy_t(0, +1))); maxn = max(maxn, count_in(points[i] + d * v + sqrt(1 - d * d) * v * xy_t(0, -1))); } } } cout << maxn << endl; } }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
1
309
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)n; i++) #define cd complex<double> complex<double> ci = complex<double>(0.0, 1.0); complex<double> mci = complex<double>(0.0, -1.0); int main() { while (1) { int n; cin >> n; if (n == 0) break; vector<complex<double>> p(n); rep(i, n) { double real, imag; cin >> real >> imag; p[i] = complex<double>(real, imag); } int summax = 0; rep(i, n) { rep(j, n) { if (i == j) continue; if (abs(p[i] - p[j]) > 2) continue; complex<double> mid = (p[i] + p[j]) / 2.0; double l = abs(p[i] - mid); double h = sqrt(1 - l * l); complex<double> c1 = mid + (mid - p[i]) * ci * h / l; complex<double> c2 = mid + (mid - p[i]) * mci * h / l; int sum1 = 2, sum2 = 2; rep(k, n) { if (k == i || k == j) continue; if (abs(p[k] - c1) < 1.0) sum1++; if (abs(p[k] - c2) < 1.0) sum2++; } if (max(sum1, sum2) > summax) summax = max(sum1, sum2); } } cout << summax << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)n; i++) #define cd complex<double> complex<double> ci = complex<double>(0.0, 1.0); complex<double> mci = complex<double>(0.0, -1.0); int main() { while (1) { int n; cin >> n; if (n == 0) break; vector<complex<double>> p(n); rep(i, n) { double real, imag; cin >> real >> imag; p[i] = complex<double>(real, imag); } int summax = 1; rep(i, n) { rep(j, n) { if (i == j) continue; if (abs(p[i] - p[j]) > 2) continue; complex<double> mid = (p[i] + p[j]) / 2.0; double l = abs(p[i] - mid); double h = sqrt(1 - l * l); complex<double> c1 = mid + (mid - p[i]) * ci * h / l; complex<double> c2 = mid + (mid - p[i]) * mci * h / l; int sum1 = 2, sum2 = 2; rep(k, n) { if (k == i || k == j) continue; if (abs(p[k] - c1) < 1.0) sum1++; if (abs(p[k] - c2) < 1.0) sum2++; } if (max(sum1, sum2) > summax) summax = max(sum1, sum2); } } cout << summax << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
1
353
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) FOR(i, 0, n) #define pb emplace_back typedef long long ll; typedef pair<int, int> pint; #define eps (1e-10) struct Point { double x, y; Point() {} Point(double x, double y) : x(x), y(y) {} Point operator+(Point p) { return Point(x + p.x, y + p.y); } Point operator-(Point p) { return Point(x - p.x, y - p.y); } Point operator*(Point p) { return Point(x * p.x - y * p.y, x * p.y + y * p.x); } Point operator*(double k) { return Point(x * k, y * k); } double norm() { return x * x + y * y; } double abs() { return sqrt(norm()); } bool operator==(const Point &p) const { return fabs(x - p.x) < eps && fabs(y - p.y) < eps; } double arg() { return atan2(y, x); } double dot(Point p) { return x * p.x + y * p.y; } double det(Point p) { return x * p.y - y * p.x; } }; bool cmp_x(const Point &p, const Point &q) { if (p.x != q.x) return p.x < q.x; return p.y < q.y; } struct Circle { double r; Point p; Circle() {} Circle(Point p, double r) : p(p), r(r) {} }; bool isIntersectCC(Circle c1, Circle c2) { return (c1.p - c2.p).abs() <= c1.r + c2.r + eps; } pair<Point, Point> CrossPointsCC(Circle c1, Circle c2) { assert(isIntersectCC(c1, c2)); double d = (c1.p - c2.p).abs(); double k = acos((d * d + c1.r * c1.r - c2.r * c2.r) / (c1.r * d * 2)); return make_pair(c1.p + (c2.p - c1.p) * Point(cos(k), sin(k)) * (c1.r / d), c1.p + (c2.p - c1.p) * Point(cos(-k), sin(-k)) * (c1.r / d)); } Point p[301]; int main() { int n; double x, y; while (cin >> n, n) { rep(i, n) { cin >> x >> y; p[i] = Point(x, y); } int mx = 1; rep(i, n) FOR(j, i + 1, n) { if ((p[i] - p[j]).abs() > 2) continue; pair<Point, Point> pp = CrossPointsCC(Circle(p[i], 1.0), Circle(p[j], 1.0)); int cnt = 0, cnt2 = 0; rep(k, n) { if ((pp.first - p[k]).abs() <= 1.0) ++cnt; if ((pp.second - p[k]).abs() <= 1.0) ++cnt2; } mx = max(mx, max(cnt, cnt2)); } cout << mx << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) FOR(i, 0, n) #define pb emplace_back typedef long long ll; typedef pair<int, int> pint; #define eps (1e-10) struct Point { double x, y; Point() {} Point(double x, double y) : x(x), y(y) {} Point operator+(Point p) { return Point(x + p.x, y + p.y); } Point operator-(Point p) { return Point(x - p.x, y - p.y); } Point operator*(Point p) { return Point(x * p.x - y * p.y, x * p.y + y * p.x); } Point operator*(double k) { return Point(x * k, y * k); } double norm() { return x * x + y * y; } double abs() { return sqrt(norm()); } bool operator==(const Point &p) const { return fabs(x - p.x) < eps && fabs(y - p.y) < eps; } double arg() { return atan2(y, x); } double dot(Point p) { return x * p.x + y * p.y; } double det(Point p) { return x * p.y - y * p.x; } }; bool cmp_x(const Point &p, const Point &q) { if (p.x != q.x) return p.x < q.x; return p.y < q.y; } struct Circle { double r; Point p; Circle() {} Circle(Point p, double r) : p(p), r(r) {} }; bool isIntersectCC(Circle c1, Circle c2) { return (c1.p - c2.p).abs() <= c1.r + c2.r + eps; } pair<Point, Point> CrossPointsCC(Circle c1, Circle c2) { assert(isIntersectCC(c1, c2)); double d = (c1.p - c2.p).abs(); double k = acos((d * d + c1.r * c1.r - c2.r * c2.r) / (c1.r * d * 2)); return make_pair(c1.p + (c2.p - c1.p) * Point(cos(k), sin(k)) * (c1.r / d), c1.p + (c2.p - c1.p) * Point(cos(-k), sin(-k)) * (c1.r / d)); } Point p[301]; int main() { int n; double x, y; while (cin >> n, n) { rep(i, n) { cin >> x >> y; p[i] = Point(x, y); } int mx = 1; rep(i, n) FOR(j, i + 1, n) { if ((p[i] - p[j]).abs() > 2) continue; pair<Point, Point> pp = CrossPointsCC(Circle(p[i], 1.0), Circle(p[j], 1.0)); int cnt = 0, cnt2 = 0; rep(k, n) { if ((pp.first - p[k]).abs() <= 1.0 + eps) ++cnt; if ((pp.second - p[k]).abs() <= 1.0 + eps) ++cnt2; } mx = max(mx, max(cnt, cnt2)); } cout << mx << endl; } return 0; }
[["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 72], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22]]
1
797
#include <cmath> #include <iostream> using namespace std; int n; double x[300]; double y[300]; double dist(double x1, double y1, double x2, double y2) { double dx = abs(x1 - x2); double dy = abs(y1 - y2); return sqrt(dx * dx + dy * dy); } int count(double cx, double cy, int i, int j) { int ans = 0; for (int k = 0; k < n; ++k) { if (k == i || k == j || dist(cx, cy, x[k], y[k]) < 1) ans++; } return ans; } void solve() { for (int i = 0; i < n; ++i) { cin >> x[i] >> y[i]; } int ans = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if (i == j) continue; double d = dist(x[i], y[i], x[j], y[j]); if (d > 2.) continue; double dx = x[j] - x[i]; double dy = y[j] - y[i]; double r = sqrt(1 - (d * d / 4)); // cout << r << endl; double cx = x[i] + dx / 2 - dy * r / d; double cy = y[i] + dy / 2 + dx * r / d; // cout << x[i] << ", " << y[i] << " - " << x[j] << ", " << y[j] << " : " // << cx << ", "<< cy << endl; ans = max(ans, count(cx, cy, i, j)); } } cout << ans << endl; } int main() { while (1) { cin >> n; if (n == 0) break; solve(); } }
#include <cmath> #include <iostream> using namespace std; int n; double x[300]; double y[300]; double dist(double x1, double y1, double x2, double y2) { double dx = abs(x1 - x2); double dy = abs(y1 - y2); return sqrt(dx * dx + dy * dy); } int count(double cx, double cy, int i, int j) { int ans = 0; for (int k = 0; k < n; ++k) { if (k == i || k == j || dist(cx, cy, x[k], y[k]) < 1) ans++; } return ans; } void solve() { for (int i = 0; i < n; ++i) { cin >> x[i] >> y[i]; } int ans = 1; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if (i == j) continue; double d = dist(x[i], y[i], x[j], y[j]); if (d > 2.) continue; double dx = x[j] - x[i]; double dy = y[j] - y[i]; double r = sqrt(1 - (d * d / 4)); // cout << r << endl; double cx = x[i] + dx / 2 - dy * r / d; // cout << d << endl; double cy = y[i] + dy / 2 + dx * r / d; // cout << x[i] << ", " << y[i] << " - " << x[j] << ", " << y[j] << " : " // << cx << ", "<< cy << endl; ans = max(ans, count(cx, cy, i, j)); } } cout << ans << endl; } int main() { while (1) { cin >> n; if (n == 0) break; solve(); } }
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13]]
1
391
#include <bits/stdc++.h> using namespace std; using ld = long double; using Point = complex<ld>; struct Line { Point a, b; Line(Point a, Point b) : a(a), b(b) {} Line() : Line(Point(), Point()) {} }; struct Circle { Point p; ld r; Circle(Point p, ld r) : p(p), r(r) {} Circle() : Circle(Point(), 0.0) {} }; constexpr ld eps = 1e-9, pi = acos(-1.0); namespace std { bool operator<(const Point &lhs, const Point &rhs) { if (lhs.real() < rhs.real() - eps) return true; if (lhs.real() > rhs.real() + eps) return false; return lhs.imag() < rhs.imag(); } } // namespace std namespace Geometry { bool eq(ld a, ld b) { return abs(a - b) < eps; } //内積 ld dot(Point a, Point b) { return real(conj(a) * b); } //外積 ld cross(Point a, Point b) { return imag(conj(a) * b); } // 3点の位置関係 int ccw(Point a, Point b, Point c) { b -= a; c -= a; if (cross(b, c) > eps) return 1; // a,b,cで反時計周り if (cross(b, c) < -eps) return -1; // a,b,cで時計周り if (dot(b, c) < 0) return 2; // c,a,bで直線 if (norm(b) < norm(c)) return -2; // a,b,cで直線 return 0; // a,c,bで直線 } //==================================================== Point inputPoint() { ld x, y; cin >> x >> y; return Point(x, y); } // 2直線の交差判定 bool isCrossed_ll(Line l, Line m) { return !eq(cross(l.b - l.a, m.b - m.a), 0); } //直線と線分の交差判定 bool isCrossed_ls(Line l, Line s) { return isCrossed_ll(l, s) && cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) < eps; } //線分と線分の交差判定 bool isCrossed_ss(Line s, Line t) { return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0 && ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0; } //点が直線上にあるか bool isON_l(Line l, Point p) { return abs(cross(l.b - p, l.a - p)) < eps; } //点が線分上にあるか bool isON_s(Line s, Point p) { return abs(s.a - p) + abs(s.b - p) - abs(s.b - s.a) < eps; } //点から直線への垂線の足 Point foot(Line l, Point p) { ld t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b); return l.a + t * (l.a - l.b); } //直線と直線の交点 Point intersection_ll(Line l, Line m) { Point lv = l.b - l.a, mv = m.b - m.a; assert(cross(lv, mv) != 0); //平行 return l.a + lv * cross(mv, m.a - l.a) / cross(mv, lv); } //線分と線分の交点 Point intersection_ss(Line s, Line t) { assert(isCrossed_ll(s, t)); return intersection_ll(s, t); } //点と点の距離 ld dist_pp(Point p, Point q) { ld x = p.real() - q.real(), y = p.imag() - q.imag(); return sqrt(x * x + y * y); } //点と直線の距離 ld dist_lp(Line l, Point p) { return abs(p - foot(l, p)); } //直線と直線の距離 ld dist_ll(Line l, Line m) { return isCrossed_ll(l, m) ? 0 : dist_lp(l, m.a); } //直線と線分の距離 ld dist_ls(Line l, Line s) { return isCrossed_ls(l, s) ? 0 : min(dist_lp(l, s.a), dist_lp(l, s.b)); } //線分と点の距離 ld dist_sp(Line s, Point p) { Point r = foot(s, p); return isON_s(s, r) ? abs(r - p) : min(abs(s.a - p), abs(s.b - p)); } //線分と線分の距離 ld dist_ss(Line s, Line t) { if (isCrossed_ss(s, t)) return 0; return min( {dist_sp(s, t.a), dist_sp(s, t.b), dist_sp(t, s.a), dist_sp(t, s.b)}); } //円と円の交点 vector<Point> intersection_cc(Circle c1, Circle c2) { vector<Point> res; ld d = abs(c1.p - c2.p); ld rc = (d * d + c1.r * c1.r - c2.r * c2.r) / (2 * d); ld dfr = c1.r * c1.r - rc * rc; if (abs(dfr) < eps) dfr = 0.0; else if (dfr < 0.0) return res; ld rs = sqrt(dfr); Point diff = (c2.p - c1.p) / d; res.push_back(c1.p + diff * Point(rc, rs)); if (dfr != 0.0) res.push_back(c1.p + diff * Point(rc, -rs)); return res; } }; // namespace Geometry int main() { int n; using namespace Geometry; while (cin >> n, n) { vector<Point> g(n); vector<Circle> Cs(n); for (int i = 0; i < n; ++i) { g[i] = inputPoint(); Cs[i] = {g[i], 1.0}; } int ans = 0; for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { vector<Point> intersections(intersection_cc(Cs[i], Cs[j])); for (auto intersection : intersections) { int ret = 0; for (int k = 0; k < n; ++k) { if (dist_pp(intersection, g[k]) < 1.0) { if (i == k || j == k) continue; ++ret; } } ans = max(ans, ret + 2); } } } cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; using ld = long double; using Point = complex<ld>; struct Line { Point a, b; Line(Point a, Point b) : a(a), b(b) {} Line() : Line(Point(), Point()) {} }; struct Circle { Point p; ld r; Circle(Point p, ld r) : p(p), r(r) {} Circle() : Circle(Point(), 0.0) {} }; constexpr ld eps = 1e-9, pi = acos(-1.0); namespace std { bool operator<(const Point &lhs, const Point &rhs) { if (lhs.real() < rhs.real() - eps) return true; if (lhs.real() > rhs.real() + eps) return false; return lhs.imag() < rhs.imag(); } } // namespace std namespace Geometry { bool eq(ld a, ld b) { return abs(a - b) < eps; } //内積 ld dot(Point a, Point b) { return real(conj(a) * b); } //外積 ld cross(Point a, Point b) { return imag(conj(a) * b); } // 3点の位置関係 int ccw(Point a, Point b, Point c) { b -= a; c -= a; if (cross(b, c) > eps) return 1; // a,b,cで反時計周り if (cross(b, c) < -eps) return -1; // a,b,cで時計周り if (dot(b, c) < 0) return 2; // c,a,bで直線 if (norm(b) < norm(c)) return -2; // a,b,cで直線 return 0; // a,c,bで直線 } //==================================================== Point inputPoint() { ld x, y; cin >> x >> y; return Point(x, y); } // 2直線の交差判定 bool isCrossed_ll(Line l, Line m) { return !eq(cross(l.b - l.a, m.b - m.a), 0); } //直線と線分の交差判定 bool isCrossed_ls(Line l, Line s) { return isCrossed_ll(l, s) && cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) < eps; } //線分と線分の交差判定 bool isCrossed_ss(Line s, Line t) { return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0 && ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0; } //点が直線上にあるか bool isON_l(Line l, Point p) { return abs(cross(l.b - p, l.a - p)) < eps; } //点が線分上にあるか bool isON_s(Line s, Point p) { return abs(s.a - p) + abs(s.b - p) - abs(s.b - s.a) < eps; } //点から直線への垂線の足 Point foot(Line l, Point p) { ld t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b); return l.a + t * (l.a - l.b); } //直線と直線の交点 Point intersection_ll(Line l, Line m) { Point lv = l.b - l.a, mv = m.b - m.a; assert(cross(lv, mv) != 0); //平行 return l.a + lv * cross(mv, m.a - l.a) / cross(mv, lv); } //線分と線分の交点 Point intersection_ss(Line s, Line t) { assert(isCrossed_ll(s, t)); return intersection_ll(s, t); } //点と点の距離 ld dist_pp(Point p, Point q) { ld x = p.real() - q.real(), y = p.imag() - q.imag(); return sqrt(x * x + y * y); } //点と直線の距離 ld dist_lp(Line l, Point p) { return abs(p - foot(l, p)); } //直線と直線の距離 ld dist_ll(Line l, Line m) { return isCrossed_ll(l, m) ? 0 : dist_lp(l, m.a); } //直線と線分の距離 ld dist_ls(Line l, Line s) { return isCrossed_ls(l, s) ? 0 : min(dist_lp(l, s.a), dist_lp(l, s.b)); } //線分と点の距離 ld dist_sp(Line s, Point p) { Point r = foot(s, p); return isON_s(s, r) ? abs(r - p) : min(abs(s.a - p), abs(s.b - p)); } //線分と線分の距離 ld dist_ss(Line s, Line t) { if (isCrossed_ss(s, t)) return 0; return min( {dist_sp(s, t.a), dist_sp(s, t.b), dist_sp(t, s.a), dist_sp(t, s.b)}); } //円と円の交点 vector<Point> intersection_cc(Circle c1, Circle c2) { vector<Point> res; ld d = abs(c1.p - c2.p); ld rc = (d * d + c1.r * c1.r - c2.r * c2.r) / (2 * d); ld dfr = c1.r * c1.r - rc * rc; if (abs(dfr) < eps) dfr = 0.0; else if (dfr < 0.0) return res; ld rs = sqrt(dfr); Point diff = (c2.p - c1.p) / d; res.push_back(c1.p + diff * Point(rc, rs)); if (dfr != 0.0) res.push_back(c1.p + diff * Point(rc, -rs)); return res; } }; // namespace Geometry int main() { int n; using namespace Geometry; while (cin >> n, n) { vector<Point> g(n); vector<Circle> Cs(n); for (int i = 0; i < n; ++i) { g[i] = inputPoint(); Cs[i] = {g[i], 1.0}; } int ans = 1; for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { vector<Point> intersections(intersection_cc(Cs[i], Cs[j])); for (auto intersection : intersections) { int ret = 0; for (int k = 0; k < n; ++k) { if (dist_pp(intersection, g[k]) < 1.0) { if (i == k || j == k) continue; ++ret; } } ans = max(ans, ret + 2); } } } cout << ans << endl; } }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
1
1,465
#include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <complex> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #include <cassert> #include <functional> typedef long long ll; using namespace std; #define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl; #define mod 1000000007 // 1e9+7(prime number) #define INF 1000000000 // 1e9 #define LLINF 2000000000000000000LL // 2e18 #define SIZE 300 typedef double P_type; typedef complex<P_type> P; const P_type P_eps = 1e-8; //整数の時はゼロ namespace std { template <class T> bool operator<(const complex<T> &a, const complex<T> &b) { return a.real() == b.real() ? a.imag() < b.imag() : a.real() < b.real(); } }; // namespace std /* 円の点包含判定 */ double isContainedCP(P c, double r, P p) { // return abs(c-p) < r - P_eps; //円周上を含まない return abs(c - p) < r + P_eps; //円周上を含む } int solve() { int n; double x[SIZE], y[SIZE]; scanf("%d", &n); if (n == 0) return false; for (int i = 0; i < n; i++) { scanf("%lf%lf", x + i, y + i); } int ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) continue; P vec = P(x[i] - x[j], y[i] - y[j]); if (abs(vec) > 2.0 + P_eps) continue; P p = P(-vec.imag(), vec.real()); p = p / abs(p) * sqrt(1 - norm(vec) / 4); // debug(p); p += vec / 2.0 + P(x[j], y[j]); int counter = 0; // debug(abs(p - P(x[i], y[i]))); for (int k = 0; k < n; k++) { counter += isContainedCP(p, 1, P(x[k], y[k])); } ans = max(ans, counter); } } printf("%d\n", ans); return true; } int main() { while (solve()) ; return 0; }
#include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <complex> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #include <cassert> #include <functional> typedef long long ll; using namespace std; #define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl; #define mod 1000000007 // 1e9+7(prime number) #define INF 1000000000 // 1e9 #define LLINF 2000000000000000000LL // 2e18 #define SIZE 300 typedef double P_type; typedef complex<P_type> P; const P_type P_eps = 1e-8; //整数の時はゼロ namespace std { template <class T> bool operator<(const complex<T> &a, const complex<T> &b) { return a.real() == b.real() ? a.imag() < b.imag() : a.real() < b.real(); } }; // namespace std /* 円の点包含判定 */ double isContainedCP(P c, double r, P p) { // return abs(c-p) < r - P_eps; //円周上を含まない return abs(c - p) < r + P_eps; //円周上を含む } int solve() { int n; double x[SIZE], y[SIZE]; scanf("%d", &n); if (n == 0) return false; for (int i = 0; i < n; i++) { scanf("%lf%lf", x + i, y + i); } int ans = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) continue; P vec = P(x[i] - x[j], y[i] - y[j]); if (abs(vec) > 2.0 + P_eps) continue; P p = P(-vec.imag(), vec.real()); p = p / abs(p) * sqrt(1 - norm(vec) / 4); // debug(p); p += vec / 2.0 + P(x[j], y[j]); int counter = 0; // debug(abs(p - P(x[i], y[i]))); for (int k = 0; k < n; k++) { counter += isContainedCP(p, 1, P(x[k], y[k])); } ans = max(ans, counter); } } printf("%d\n", ans); return true; } int main() { while (solve()) ; return 0; }
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13]]
1
475
#include <cmath> #include <iostream> #include <vector> using namespace std; const double EPS = 1e-8; typedef pair<double, double> pt; #define x first #define y second pt operator-(pt a, pt b) { return pt(a.x - b.x, a.y - b.y); } bool zero(double x) { return fabs(x) <= EPS; } double sq(double a) { return a * a; } double dist(pt p, pt q) { return sqrt(sq(p.x - q.x) + sq(p.y - q.y)); } pt midpoint(pt p1, pt p2) { double midx = (p1.x + p2.x) / 2; double midy = (p1.y + p2.y) / 2; return make_pair(midx, midy); } int get_max_points(pt centre, vector<pt> points) { int count = 0; for (int i = 0; i < points.size(); i++) { pt current = points[i]; double num = sq(current.x - centre.x) + sq(current.y - centre.y); // cout << num << endl; // cout << fabs(num - 1) << endl; if (sqrt(num) < 1 + EPS) { count++; } } return count; } int find_max_points(vector<pt> points) { // for every pair of two points, create a cricle and check num points in // circle int max_points = 0; for (int i = 0; i < points.size(); ++i) { pt p1 = points[i]; for (int j = i + 1; j < points.size(); ++j) { pt p2 = points[j]; pt mid = midpoint(p1, p2); double q = dist(p1, p2); double x1 = mid.x + sqrt(1 - sq(q / 2)) * (p1.y - p2.y) / q; double y1 = mid.y + sqrt(1 - sq(q / 2)) * (p2.x - p1.x) / q; pt c1(x1, y1); int m = get_max_points(c1, points); max_points = max(m, max_points); // cout << mid.x << " " << mid.y << endl; // int m = get_max_points(mid, points); double x2 = mid.x - sqrt(1 - sq(q / 2)) * (p1.y - p2.y) / q; double y2 = mid.y - sqrt(1 - sq(q / 2)) * (p2.x - p1.x) / q; pt c2(x1, x2); m = get_max_points(c2, points); max_points = max(max_points, m); } } // cout << max_points return max_points; } int main() { int n; while (1) { cin >> n; if (n == 0) break; vector<pt> points; for (int i = 0; i < n; ++i) { double x, y; cin >> x >> y; points.push_back(make_pair(x, y)); } cout << find_max_points(points) << endl; } return 0; }
#include <cmath> #include <iostream> #include <vector> using namespace std; const double EPS = 1e-8; typedef pair<double, double> pt; #define x first #define y second pt operator-(pt a, pt b) { return pt(a.x - b.x, a.y - b.y); } bool zero(double x) { return fabs(x) <= EPS; } double sq(double a) { return a * a; } double dist(pt p, pt q) { return sqrt(sq(p.x - q.x) + sq(p.y - q.y)); } pt midpoint(pt p1, pt p2) { double midx = (p1.x + p2.x) / 2; double midy = (p1.y + p2.y) / 2; return make_pair(midx, midy); } int get_max_points(pt centre, vector<pt> points) { int count = 0; for (int i = 0; i < points.size(); i++) { pt current = points[i]; double num = sq(current.x - centre.x) + sq(current.y - centre.y); // cout << num << endl; // cout << fabs(num - 1) << endl; if (sqrt(num) < 1 + EPS) { count++; } } return count; } int find_max_points(vector<pt> points) { // for every pair of two points, create a cricle and check num points in // circle int max_points = 1; for (int i = 0; i < points.size(); ++i) { pt p1 = points[i]; for (int j = i + 1; j < points.size(); ++j) { pt p2 = points[j]; pt mid = midpoint(p1, p2); double q = dist(p1, p2); double x1 = mid.x + sqrt(1 - sq(q / 2)) * (p1.y - p2.y) / q; double y1 = mid.y + sqrt(1 - sq(q / 2)) * (p2.x - p1.x) / q; pt c1(x1, y1); int m = get_max_points(c1, points); max_points = max(m, max_points); // cout << mid.x << " " << mid.y << endl; // int m = get_max_points(mid, points); double x2 = mid.x - sqrt(1 - sq(q / 2)) * (p1.y - p2.y) / q; double y2 = mid.y - sqrt(1 - sq(q / 2)) * (p2.x - p1.x) / q; pt c2(x1, x2); m = get_max_points(c2, points); max_points = max(max_points, m); } } // cout << max_points return max_points; } int main() { int n; while (1) { cin >> n; if (n == 0) break; vector<pt> points; for (int i = 0; i < n; ++i) { double x, y; cin >> x >> y; points.push_back(make_pair(x, y)); } cout << find_max_points(points) << endl; } return 0; }
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13]]
1
634
#include <algorithm> #include <cmath> #include <complex> #include <iostream> #include <vector> using namespace std; // xy平面上の点(ベクトル)を表現するには、complex型を利用するとよい typedef complex<double> P; // 辺の表現 (座標を2つ pair でもつ) typedef pair<P, P> L; // 円の表現 (座標 P と 半径 d で表現する) typedef pair<P, double> C; // 成分を取り出すのを簡単にする #define X real() #define Y imag() // 誤差(epsilon)の定義 #define EPS (1e-10) // 2つの要素が等しいかどうか #define EQ(a, b) (abs((a) - (b)) < EPS) // 2つのベクトルが等しいかどうか #define EQV(a, b) (EQ((a).X, (b).X) && EQ((a).Y, (b).Y)) // m は n より大きい(以上)かどうか #define LE(n, m) ((n) < (m) + EPS) #define LEQ(n, m) ((n) <= (m) + EPS) // m は n より小さい(以下)かどうか #define GE(n, m) ((n) + EPS > (m)) #define GEQ(n, m) ((n) + EPS >= (m)) // 2つのベクトルの内積を求める double dot(P a, P b) { return (a.X * b.X + a.Y * b.Y); } // 2つのベクトルの外積を求める double cross(P a, P b) { return (a.X * b.Y - a.Y * b.X); } // 点 a と 点 b を通り、半径が r の円の中心を返す vector<P> circlesPointsRadius(P a, P b, double r) { vector<P> cs; P abH = (b - a) * 0.5; double d = abs(abH); if (d == 0 || d > r) return cs; // 必要なら !LE(d,r) として円1つになる側へ丸める double dN = sqrt(r * r - d * d); // 必要なら max(r*r - d*d, 0) とする P n = abH * P(0, 1) * (dN / d); cs.push_back(a + abH + n); if (dN > 0) cs.push_back(a + abH - n); return cs; } int main() { int N; while (cin >> N, N) { vector<P> ps; for (int i = 0; i < N; i++) { double x, y; cin >> x >> y; ps.push_back(P(x, y)); } if (N == 1) cout << 1 << endl; else if (N == 2) { cout << (abs(ps[0] - ps[1]) < 2 + EPS) << endl; } else { int ans = 0; for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { // printf("i = %d, j = %d, abs = %f\n", i, j, abs(ps[i] - ps[j])); if (abs(ps[i] - ps[j]) > 2 - EPS) continue; vector<P> centers = circlesPointsRadius(ps[i], ps[j], 1); for (auto c : centers) { int sum = 2; for (int k = 0; k < N; k++) { if (i == k || j == k) continue; sum += (abs(c - ps[k]) < 1 + EPS); } ans = max(ans, sum); } } } cout << ans << endl; } } return 0; }
#include <algorithm> #include <cmath> #include <complex> #include <iostream> #include <vector> using namespace std; // xy平面上の点(ベクトル)を表現するには、complex型を利用するとよい typedef complex<double> P; // 辺の表現 (座標を2つ pair でもつ) typedef pair<P, P> L; // 円の表現 (座標 P と 半径 d で表現する) typedef pair<P, double> C; // 成分を取り出すのを簡単にする #define X real() #define Y imag() // 誤差(epsilon)の定義 #define EPS (1e-10) // 2つの要素が等しいかどうか #define EQ(a, b) (abs((a) - (b)) < EPS) // 2つのベクトルが等しいかどうか #define EQV(a, b) (EQ((a).X, (b).X) && EQ((a).Y, (b).Y)) // m は n より大きい(以上)かどうか #define LE(n, m) ((n) < (m) + EPS) #define LEQ(n, m) ((n) <= (m) + EPS) // m は n より小さい(以下)かどうか #define GE(n, m) ((n) + EPS > (m)) #define GEQ(n, m) ((n) + EPS >= (m)) // 2つのベクトルの内積を求める double dot(P a, P b) { return (a.X * b.X + a.Y * b.Y); } // 2つのベクトルの外積を求める double cross(P a, P b) { return (a.X * b.Y - a.Y * b.X); } // 点 a と 点 b を通り、半径が r の円の中心を返す vector<P> circlesPointsRadius(P a, P b, double r) { vector<P> cs; P abH = (b - a) * 0.5; double d = abs(abH); if (d == 0 || d > r) return cs; // 必要なら !LE(d,r) として円1つになる側へ丸める double dN = sqrt(r * r - d * d); // 必要なら max(r*r - d*d, 0) とする P n = abH * P(0, 1) * (dN / d); cs.push_back(a + abH + n); if (dN > 0) cs.push_back(a + abH - n); return cs; } int main() { int N; while (cin >> N, N) { vector<P> ps; for (int i = 0; i < N; i++) { double x, y; cin >> x >> y; ps.push_back(P(x, y)); } if (N == 1) cout << 1 << endl; else if (N == 2) { cout << 1 + (abs(ps[0] - ps[1]) < 2 + EPS) << endl; } else { int ans = 1; for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { // printf("i = %d, j = %d, abs = %f\n", i, j, abs(ps[i] - ps[j])); if (abs(ps[i] - ps[j]) > 2 + EPS) continue; // printf("valid\n"); vector<P> centers = circlesPointsRadius(ps[i], ps[j], 1); for (auto c : centers) { int sum = 2; for (int k = 0; k < N; k++) { if (i == k || j == k) continue; sum += (abs(c - ps[k]) < 1 + EPS); } ans = max(ans, sum); } } } cout << ans << endl; } } return 0; }
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 31, 13], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["-", 75, 76, 0, 9, 0, 43, 49, 50, 51, 13], ["+", 75, 76, 0, 9, 0, 43, 49, 50, 51, 13], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 33], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 72]]
1
559
#include <algorithm> #include <cstdio> #include <math.h> using namespace std; typedef pair<double, double> P; int N; double X[300], Y[300]; P d[300]; P add(P p1, P p2) { return P(p1.first + p2.first, p1.second + p2.second); } P minas(P p1, P p2) { return P(p1.first - p2.first, p1.second - p2.second); } P mul(P p, double c) { return P(p.first * c, p.second * c); } P ave(P p1, P p2) { return P((p1.first + p2.first) / 2, (p1.second + p2.second) / 2); } void printP(P p) { printf("P:(%f, %f)\n", p.first, p.second); } double square(P p) { return p.first * p.first + p.second * p.second; } double size(P p) { return sqrt(square(p)); } int count(P p) { // printP(p); int counter = 0; for (int i = 0; i < N; i++) { if (square(minas(p, d[i])) <= 1.0001) counter++; } // printf("%d\n",counter); return counter; } int check(int i, int j) { if (square(minas(d[i], d[j])) > 4.0) return 0; int ans = 0; P average = ave(d[i], d[j]); P dir = mul(minas(d[i], d[j]), 0.5); // printP(average); double s = sqrt(1.0 - square(dir)); // printf("!!!!!!%f\n",s); P dir1 = P((Y[i] - Y[j]), -(X[i] - X[j])); // printf("!!!!!!%f\n",size(dir1)); double r = s / size(dir1); P d1 = add(average, mul(dir1, r)); P d2 = add(average, mul(dir1, -r)); return max(count(d1), count(d2)); } int main() { while (1) { scanf("%d", &N); if (N == 0) break; for (int i = 0; i < N; i++) scanf("%lf%lf", &X[i], &Y[i]), d[i] = P(X[i], Y[i]); int ans = 0; for (int i = 0; i < N; i++) for (int j = 0; j < i; j++) ans = max(ans, check(i, j)); printf("%d\n", ans); } }
#include <algorithm> #include <cstdio> #include <math.h> using namespace std; typedef pair<double, double> P; int N; double X[300], Y[300]; P d[300]; P add(P p1, P p2) { return P(p1.first + p2.first, p1.second + p2.second); } P minas(P p1, P p2) { return P(p1.first - p2.first, p1.second - p2.second); } P mul(P p, double c) { return P(p.first * c, p.second * c); } P ave(P p1, P p2) { return P((p1.first + p2.first) / 2, (p1.second + p2.second) / 2); } void printP(P p) { printf("P:(%f, %f)\n", p.first, p.second); } double square(P p) { return p.first * p.first + p.second * p.second; } double size(P p) { return sqrt(square(p)); } int count(P p) { // printP(p); int counter = 0; for (int i = 0; i < N; i++) { if (square(minas(p, d[i])) <= 1.0001) counter++; } // printf("%d\n",counter); return counter; } int check(int i, int j) { if (square(minas(d[i], d[j])) > 4.0) return 0; int ans = 0; P average = ave(d[i], d[j]); P dir = mul(minas(d[i], d[j]), 0.5); // printP(average); double s = sqrt(1.0 - square(dir)); // printf("!!!!!!%f\n",s); P dir1 = P((Y[i] - Y[j]), -(X[i] - X[j])); // printf("!!!!!!%f\n",size(dir1)); double r = s / size(dir1); P d1 = add(average, mul(dir1, r)); P d2 = add(average, mul(dir1, -r)); return max(count(d1), count(d2)); } int main() { while (1) { scanf("%d", &N); if (N == 0) break; for (int i = 0; i < N; i++) scanf("%lf%lf", &X[i], &Y[i]), d[i] = P(X[i], Y[i]); int ans = 1; for (int i = 0; i < N; i++) for (int j = 0; j < i; j++) ans = max(ans, check(i, j)); printf("%d\n", ans); } }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
1
603
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int, int> P; const double EPS = 1e-12; const int INF = numeric_limits<int>::max() / 2; const int MOD = 1e9 + 7; typedef long double ld; typedef complex<ld> Point; const ld eps = 1e-9, pi = acos(-1.0); namespace std { bool operator<(const Point &lhs, const Point &rhs) { if (lhs.real() < rhs.real() - eps) return true; if (lhs.real() > rhs.real() + eps) return false; return lhs.imag() < rhs.imag(); } } // namespace std Point input_point() { ld x, y; cin >> x >> y; return Point(x, y); } bool eq(ld a, ld b) { return (abs(a - b) < eps); } class Circle { public: Point p; ld r; Circle() : p(Point(0, 0)), r(0) {} Circle(Point p, ld r) : p(p), r(r) {} }; vector<Point> is_cc(Circle c1, Circle c2) { vector<Point> res; ld d = abs(c1.p - c2.p); ld rc = (d * d + c1.r * c1.r - c2.r * c2.r) / (2 * d); ld dfr = c1.r * c1.r - rc * rc; if (abs(dfr) < eps) dfr = 0.0; else if (dfr < 0.0) return res; // no intersection ld rs = sqrt(dfr); Point diff = (c2.p - c1.p) / d; res.push_back(c1.p + diff * Point(rc, rs)); if (dfr != 0.0) res.push_back(c1.p + diff * Point(rc, -rs)); return res; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n; while (cin >> n, n) { vector<Point> ps(n); for (int i = 0; i < n; i++) { ps[i] = input_point(); } if (n <= 2) { cout << n << endl; continue; } int res = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { Circle c1 = Circle(ps[i], 1.0), c2 = Circle(ps[j], 1.0); vector<Point> vs = is_cc(c1, c2); int sz = vs.size(); if (sz == 0) continue; for (int k = 0; k < sz; k++) { Point p = vs[k]; int tmp = 0; for (int idx = 0; idx < n; idx++) { if (abs(ps[idx] - p) <= 1 + eps) tmp++; } res = max(res, tmp); } } } cout << res << endl; } }
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int, int> P; const double EPS = 1e-12; const int INF = numeric_limits<int>::max() / 2; const int MOD = 1e9 + 7; typedef long double ld; typedef complex<ld> Point; const ld eps = 1e-9, pi = acos(-1.0); namespace std { bool operator<(const Point &lhs, const Point &rhs) { if (lhs.real() < rhs.real() - eps) return true; if (lhs.real() > rhs.real() + eps) return false; return lhs.imag() < rhs.imag(); } } // namespace std Point input_point() { ld x, y; cin >> x >> y; return Point(x, y); } bool eq(ld a, ld b) { return (abs(a - b) < eps); } class Circle { public: Point p; ld r; Circle() : p(Point(0, 0)), r(0) {} Circle(Point p, ld r) : p(p), r(r) {} }; vector<Point> is_cc(Circle c1, Circle c2) { vector<Point> res; ld d = abs(c1.p - c2.p); ld rc = (d * d + c1.r * c1.r - c2.r * c2.r) / (2 * d); ld dfr = c1.r * c1.r - rc * rc; if (abs(dfr) < eps) dfr = 0.0; else if (dfr < 0.0) return res; // no intersection ld rs = sqrt(dfr); Point diff = (c2.p - c1.p) / d; res.push_back(c1.p + diff * Point(rc, rs)); if (dfr != 0.0) res.push_back(c1.p + diff * Point(rc, -rs)); return res; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n; while (cin >> n, n) { vector<Point> ps(n); for (int i = 0; i < n; i++) { ps[i] = input_point(); } if (n == 1) { cout << n << endl; continue; } int res = 1; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { Circle c1 = Circle(ps[i], 1.0), c2 = Circle(ps[j], 1.0); vector<Point> vs = is_cc(c1, c2); int sz = vs.size(); if (sz == 0) continue; for (int k = 0; k < sz; k++) { Point p = vs[k]; int tmp = 0; for (int idx = 0; idx < n; idx++) { if (abs(ps[idx] - p) <= 1 + eps) tmp++; } res = max(res, tmp); } } } cout << res << endl; } }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
1
678