buggy_code
stringlengths 11
625k
| fixed_code
stringlengths 17
625k
| bug_type
stringlengths 2
4.45k
| language
int64 0
8
| token_count
int64 5
200k
| change_count
int64 0
100
|
|---|---|---|---|---|---|
// Name: Maximum Sum Sequence II
// Level: 2
// Category: データ構造,累積和
// Note:
/**
* 行列要素の累積和を求めておけば、任意の矩形に対して和をO(1)で計算できる。
*
* オーダーは O(N^4)。
*/
#include <iostream>
#include <vector>
using namespace std;
bool solve() {
int N;
if (!(cin >> N))
return false;
if (!N)
return false;
vector<vector<long long>> v(N, vector<long long>(N));
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
cin >> v[i][j];
}
}
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
if (i > 0)
v[i][j] += v[i - 1][j];
if (j > 0)
v[i][j] += v[i][j - 1];
if (i > 0 && j > 0)
v[i][j] -= v[i - 1][j - 1];
}
}
long long ans = -100000;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
for (int k = 0; k < N; ++k) {
for (int l = 0; l < N; ++l) {
long long sum = v[k][l];
if (i > 0)
sum -= v[i - 1][l];
if (j > 0)
sum -= v[k][j - 1];
if (i > 0 && j > 0)
sum += v[i - 1][j - 1];
ans = max(ans, sum);
}
}
}
}
cout << ans << endl;
return true;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
cout.setf(ios::fixed);
cout.precision(10);
while (solve())
;
return 0;
}
|
// Name: Maximum Sum Sequence II
// Level: 2
// Category: データ構造,累積和
// Note:
/**
* 行列要素の累積和を求めておけば、任意の矩形に対して和をO(1)で計算できる。
*
* オーダーは O(N^4)。
*/
#include <iostream>
#include <vector>
using namespace std;
bool solve() {
int N;
if (!(cin >> N))
return false;
if (!N)
return false;
vector<vector<long long>> v(N, vector<long long>(N));
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
cin >> v[i][j];
}
}
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
if (i > 0)
v[i][j] += v[i - 1][j];
if (j > 0)
v[i][j] += v[i][j - 1];
if (i > 0 && j > 0)
v[i][j] -= v[i - 1][j - 1];
}
}
long long ans = -100000;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
for (int k = i; k < N; ++k) {
for (int l = j; l < N; ++l) {
long long sum = v[k][l];
if (i > 0)
sum -= v[i - 1][l];
if (j > 0)
sum -= v[k][j - 1];
if (i > 0 && j > 0)
sum += v[i - 1][j - 1];
ans = max(ans, sum);
}
}
}
}
cout << ans << endl;
return true;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
cout.setf(ios::fixed);
cout.precision(10);
while (solve())
;
return 0;
}
|
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 22]]
| 1
| 422
| 4
|
// Name: Maximum Sum Sequence II
// Level: 2
// Category: データ構造,累積和
// Note:
/**
* 行列要素の累積和を求めておけば、任意の矩形に対して和をO(1)で計算できる。
*
* オーダーは O(N^4)。
*/
#include <iostream>
#include <vector>
using namespace std;
template <typename T> struct Accumulate2D {
vector<vector<T>> v;
Accumulate2D(int R, int C) { v.resize(R, vector<T>(C)); }
void set(int r, int c, const T &val) { v[r][c] = val; }
T &setter(int r, int c) { return v[r][c]; }
void freeze() {
const int R = v.size();
const int C = v[0].size();
for (int r = 0; r < R; ++r) {
for (int c = 0; c < C; ++c) {
if (r > 0)
v[r][c] += v[r - 1][c];
if (c > 0)
v[r][c] += v[r][c - 1];
if (r > 0 && c > 0)
v[r][c] -= v[r - 1][c - 1];
}
}
}
// Returns cumulative sum of ([r1, r2), [c1, c2))
T &&operator()(int r1, int c1, int r2, int c2) const {
T res = v[r2 - 1][c2 - 1];
if (r1 > 0)
res -= v[r1 - 1][c2 - 1];
if (c1 > 0)
res -= v[r2 - 1][c1 - 1];
if (r1 > 0 && c1 > 0)
res += v[r1 - 1][c1 - 1];
return std::move(res);
}
};
bool solve() {
int N;
if (!(cin >> N))
return false;
if (!N)
return false;
Accumulate2D<long long> acc(N, N);
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
cin >> acc.setter(i, j);
}
}
acc.freeze();
long long ans = -100000;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
for (int k = i + 1; k <= N; ++k) {
for (int l = j + 1; l <= N; ++l) {
ans = max(ans, acc(i, j, k, l));
}
}
}
}
cout << ans << endl;
return true;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
cout.setf(ios::fixed);
cout.precision(10);
while (solve())
;
return 0;
}
|
// Name: Maximum Sum Sequence II
// Level: 2
// Category: データ構造,累積和
// Note:
/**
* 行列要素の累積和を求めておけば、任意の矩形に対して和をO(1)で計算できる。
*
* オーダーは O(N^4)。
*/
#include <iostream>
#include <vector>
using namespace std;
template <typename T> struct Accumulate2D {
vector<vector<T>> v;
Accumulate2D(int R, int C) { v.resize(R, vector<T>(C)); }
void set(int r, int c, const T &val) { v[r][c] = val; }
T &setter(int r, int c) { return v[r][c]; }
void freeze() {
const int R = v.size();
const int C = v[0].size();
for (int r = 0; r < R; ++r) {
for (int c = 0; c < C; ++c) {
if (r > 0)
v[r][c] += v[r - 1][c];
if (c > 0)
v[r][c] += v[r][c - 1];
if (r > 0 && c > 0)
v[r][c] -= v[r - 1][c - 1];
}
}
}
// Returns cumulative sum of ([r1, r2), [c1, c2))
T operator()(int r1, int c1, int r2, int c2) const {
T res = v[r2 - 1][c2 - 1];
if (r1 > 0)
res -= v[r1 - 1][c2 - 1];
if (c1 > 0)
res -= v[r2 - 1][c1 - 1];
if (r1 > 0 && c1 > 0)
res += v[r1 - 1][c1 - 1];
return res;
}
};
bool solve() {
int N;
if (!(cin >> N))
return false;
if (!N)
return false;
Accumulate2D<long long> acc(N, N);
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
cin >> acc.setter(i, j);
}
}
acc.freeze();
long long ans = -100000;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
for (int k = i + 1; k <= N; ++k) {
for (int l = j + 1; l <= N; ++l) {
ans = max(ans, acc(i, j, k, l));
}
}
}
}
cout << ans << endl;
return true;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
cout.setf(ios::fixed);
cout.precision(10);
while (solve())
;
return 0;
}
|
[["-", 0, 122, 8, 123, 0, 14, 49, 352, 0, 98], ["-", 8, 9, 0, 37, 0, 2, 63, 343, 345, 348], ["-", 8, 9, 0, 37, 0, 2, 63, 343, 0, 349], ["-", 8, 9, 0, 37, 0, 2, 63, 343, 141, 22], ["-", 8, 9, 0, 37, 0, 2, 3, 4, 0, 24], ["-", 8, 9, 0, 37, 0, 2, 3, 4, 0, 25]]
| 1
| 588
| 6
|
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<vector<int>> V(n + 1, vector<int>(n + 1, 0));
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
cin >> V[i][j];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n - 1; j++) {
V[i][j + 1] += V[i][j];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j < n - 1; j++) {
V[j + 1][i] += V[j][i];
}
}
int res = -100000000;
for (int i = 0; i < n; i++) {
for (int l = 0; l < n; l++) {
for (int j = i + 1; j <= n; j++) {
for (int k = l + 1; k <= n; k++) {
if ((V[j][k] - V[i][k]) - (V[j][l] - V[i][l]) > res)
res = (V[j][k] - V[i][k]) - (V[j][l] - V[i][l]);
}
}
}
}
cout << res << endl;
return 0;
}
|
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<vector<int>> V(n + 1, vector<int>(n + 1, 0));
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
cin >> V[i][j];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n - 1; j++) {
V[i][j + 1] += V[i][j];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j < n; j++) {
V[j + 1][i] += V[j][i];
}
}
int res = -100000000;
for (int i = 0; i < n; i++) {
for (int l = 0; l < n; l++) {
for (int j = i + 1; j <= n; j++) {
for (int k = l + 1; k <= n; k++) {
if ((V[j][k] - V[i][k]) - (V[j][l] - V[i][l]) > res)
res = (V[j][k] - V[i][k]) - (V[j][l] - V[i][l]);
}
}
}
}
cout << res << endl;
return 0;
}
|
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13]]
| 1
| 349
| 4
|
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int mat[110][110];
long long sum[110][110];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
cin >> mat[i][j];
}
}
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= n; ++j) {
if (i == 0 || j == 0) {
sum[i][j] = 0;
} else {
sum[i][j] =
sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + mat[i][j];
}
}
}
long long mx = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
for (int k = 1; k <= n; ++k) {
for (int l = 1; l <= n; ++l) {
long long area =
sum[k][l] - sum[i - 1][l] - sum[k][j - 1] + sum[i - 1][j - 1];
mx = max(mx, area);
}
}
}
}
cout << mx << endl;
return 0;
}
|
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int mat[110][110];
long long sum[110][110];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
cin >> mat[i][j];
}
}
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= n; ++j) {
if (i == 0 || j == 0) {
sum[i][j] = 0;
} else {
sum[i][j] =
sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + mat[i][j];
}
}
}
long long mx = -1000001;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
for (int k = i; k <= n; ++k) {
for (int l = j; l <= n; ++l) {
long long area =
sum[k][l] - sum[i - 1][l] - sum[k][j - 1] + sum[i - 1][j - 1];
mx = max(mx, area);
}
}
}
}
cout << mx << endl;
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 22]]
| 1
| 321
| 6
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<vector<int>> mat(n + 1, vector<int>(n + 1, 0));
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) {
int k;
cin >> k;
mat[i][j] = k + mat[i - 1][j] + mat[i][j - 1] - mat[i - 1][j - 1];
}
int ret = 0x80000000;
for (int x1 = 0; x1 < n; x1++)
for (int y1 = 0; y1 < n; y1++)
for (int x2 = 1; x2 <= n; x2++)
for (int y2 = 1; y2 <= n; y2++) {
int t = mat[y2][x2] - mat[y2][x1] - mat[y1][x2] + mat[y1][x1];
ret = max(ret, t);
}
cout << ret << endl;
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<vector<int>> mat(n + 1, vector<int>(n + 1, 0));
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) {
int k;
cin >> k;
mat[i][j] = k + mat[i - 1][j] + mat[i][j - 1] - mat[i - 1][j - 1];
}
int ret = 0x80000000;
for (int x1 = 0; x1 < n; x1++)
for (int y1 = 0; y1 < n; y1++)
for (int x2 = x1 + 1; x2 <= n; x2++)
for (int y2 = y1 + 1; y2 <= n; y2++) {
int t = mat[y2][x2] - mat[y2][x1] - mat[y1][x2] + mat[y1][x1];
ret = max(ret, t);
}
cout << ret << endl;
return 0;
}
|
[["+", 8, 7, 10, 43, 49, 50, 51, 16, 31, 22], ["+", 8, 7, 10, 43, 49, 50, 51, 16, 17, 72]]
| 1
| 244
| 4
|
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
int main() {
int n;
int imos[101][101];
fill_n(*imos, 101 * 101, 0);
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
int val;
scanf("%d", &val);
imos[i][j] = imos[i - 1][j] + imos[i][j - 1] - imos[i - 1][j - 1] + val;
}
}
int ans = -1000000000;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int y = 1; y < i; y++) {
for (int x = 1; x < j; x++) {
ans = max(ans, imos[i][j] - imos[y - 1][j] - imos[i][x - 1] +
imos[y - 1][x - 1]);
}
}
}
}
printf("%d\n", ans);
}
|
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
int main() {
int n;
int imos[101][101];
fill_n(*imos, 101 * 101, 0);
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
int val;
scanf("%d", &val);
imos[i][j] = imos[i - 1][j] + imos[i][j - 1] - imos[i - 1][j - 1] + val;
}
}
int ans = -1000000000;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int y = 1; y <= i; y++) {
for (int x = 1; x <= j; x++) {
ans = max(ans, imos[i][j] - imos[y - 1][j] - imos[i][x - 1] +
imos[y - 1][x - 1]);
}
}
}
}
printf("%d\n", ans);
}
|
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19]]
| 1
| 263
| 4
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<vector<int>> data(N + 1, vector<int>(N + 1));
for (size_t i = 1; i < N + 1; i++) {
for (size_t j = 1; j < N + 1; j++) {
cin >> data[i][j];
}
}
for (size_t i = 1; i < N + 1; i++) {
for (size_t j = 1; j < N + 1; j++) {
data[i][j] += data[i][j - 1];
}
}
for (size_t i = 1; i < N + 1; i++) {
for (size_t j = 1; j < N + 1; j++) {
data[i][j] += data[i - 1][j];
}
}
long long int ans = INT_MIN;
for (size_t i = 0; i < N; i++) {
for (size_t j = 0; j < N; j++) {
for (size_t k = 1; k < N + 1; k++) {
for (size_t l = 1; l < N + 1; l++) {
long long int num = data[k][l] + data[i][j] - data[k][j] - data[i][l];
if (num > ans) {
ans = num;
}
}
}
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<vector<int>> data(N + 1, vector<int>(N + 1));
for (size_t i = 1; i < N + 1; i++) {
for (size_t j = 1; j < N + 1; j++) {
cin >> data[i][j];
}
}
for (size_t i = 1; i < N + 1; i++) {
for (size_t j = 1; j < N + 1; j++) {
data[i][j] += data[i][j - 1];
}
}
for (size_t i = 1; i < N + 1; i++) {
for (size_t j = 1; j < N + 1; j++) {
data[i][j] += data[i - 1][j];
}
}
long long int ans = INT_MIN;
for (size_t i = 0; i < N; i++) {
for (size_t j = 0; j < N; j++) {
for (size_t k = i + 1; k < N + 1; k++) {
for (size_t l = j + 1; l < N + 1; l++) {
long long int num = data[k][l] + data[i][j] - data[k][j] - data[i][l];
if (num > ans) {
ans = num;
}
}
}
}
}
cout << ans << endl;
}
|
[["+", 0, 7, 10, 43, 49, 50, 51, 16, 31, 22], ["+", 0, 7, 10, 43, 49, 50, 51, 16, 17, 72]]
| 1
| 327
| 4
|
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define INF 1000000001
#define MOD 10000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const ull B = 100000007;
int main() {
ll sum[100][100];
int n, a;
cin >> n;
memset(sum, 0, sizeof(sum));
REP(i, n) {
REP(j, n) { cin >> sum[j][i]; }
}
REP(i, n) {
REP(j, n) {
if (i == 0 && j == 0)
continue;
if (i != 0)
sum[j][i] += sum[j][i - 1];
if (j != 0)
sum[j][i] += sum[j - 1][i];
if (i != 0 && j != 0)
sum[j][i] -= sum[j - 1][i - 1];
}
}
ll ans = sum[0][0];
REP(i, n) REP(j, n) REP(k, n) REP(l, n) {
if (k < i || l < j)
continue;
ll res = sum[l][k];
if (i != 0)
res -= sum[l][i - 1];
if (j != 0)
res -= sum[j - 1][k];
if (i != 0 && j != 0)
res += sum[i - 1][j - 1];
ans = max(res, ans);
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define INF 1000000001
#define MOD 10000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const ull B = 100000007;
int main() {
ll sum[100][100];
int n, a;
cin >> n;
memset(sum, 0, sizeof(sum));
REP(i, n) {
REP(j, n) { cin >> sum[j][i]; }
}
REP(i, n) {
REP(j, n) {
if (i == 0 && j == 0)
continue;
if (i != 0)
sum[j][i] += sum[j][i - 1];
if (j != 0)
sum[j][i] += sum[j - 1][i];
if (i != 0 && j != 0)
sum[j][i] -= sum[j - 1][i - 1];
}
}
ll ans = sum[0][0];
REP(i, n) REP(j, n) REP(k, n) REP(l, n) {
if (k < i || l < j)
continue;
ll res = sum[l][k];
if (i != 0)
res -= sum[l][i - 1];
if (j != 0)
res -= sum[j - 1][k];
if (i != 0 && j != 0)
res += sum[j - 1][i - 1];
ans = max(res, ans);
}
cout << ans << endl;
}
|
[["-", 12, 69, 28, 69, 341, 342, 0, 16, 31, 22], ["+", 12, 69, 28, 69, 341, 342, 0, 16, 31, 22], ["-", 0, 11, 12, 69, 341, 342, 0, 16, 31, 22], ["+", 0, 11, 12, 69, 341, 342, 0, 16, 31, 22]]
| 1
| 364
| 4
|
#include <iostream>
using namespace std;
int S[110][110] = {0}, a[110][110];
int main() {
int n, max = -50000, t;
cin >> n;
for (int i = 0; i <= n; i++) {
S[0][i] = 0;
S[i][0] = 0;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> a[i][j];
S[i + 1][j + 1] = S[i][j + 1] + S[i + 1][j] - S[i][j] + a[i][j];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 0; k < i; k++) {
for (int h = 0; h < j; h++) {
t = S[i][j] - S[k][j] - S[i][h] + S[k][h];
if (max < t)
max = t;
}
}
}
}
cout << t << endl;
}
|
#include <iostream>
using namespace std;
int S[110][110] = {0}, a[110][110];
int main() {
int n, max = -50000, t;
cin >> n;
for (int i = 0; i <= n; i++) {
S[0][i] = 0;
S[i][0] = 0;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> a[i][j];
S[i + 1][j + 1] = S[i][j + 1] + S[i + 1][j] - S[i][j] + a[i][j];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 0; k < i; k++) {
for (int h = 0; h < j; h++) {
t = S[i][j] - S[k][j] - S[i][h] + S[k][h];
if (max < t)
max = t;
}
}
}
}
cout << max << endl;
}
|
[["-", 8, 9, 0, 1, 0, 16, 31, 16, 12, 22], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 12, 22]]
| 1
| 286
| 2
|
#include <iostream>
using namespace std;
int main() {
int n, s;
int m[100][100];
cin >> n;
int a = -10001;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cin >> m[i][j];
a = max(a, m[i][j]);
}
}
for (int i = 0; i < n; ++i) {
int p[100] = {0};
for (int j = i; j < n; ++j) {
s = 0;
for (int k = 0; k < n; ++k) {
p[k] += m[j][k];
s = max(s + p[k], 0);
if (s > 0)
a = s;
}
}
}
cout << a << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int n, s;
int m[100][100];
cin >> n;
int a = -10001;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cin >> m[i][j];
a = max(a, m[i][j]);
}
}
for (int i = 0; i < n; ++i) {
int p[100] = {0};
for (int j = i; j < n; ++j) {
s = 0;
for (int k = 0; k < n; ++k) {
p[k] += m[j][k];
s = max(s + p[k], 0);
if (s > 0)
a = max(a, s);
}
}
}
cout << a << endl;
return 0;
}
|
[["+", 0, 57, 64, 1, 0, 11, 12, 2, 63, 22], ["+", 64, 1, 0, 11, 12, 2, 3, 4, 0, 24], ["+", 64, 1, 0, 11, 12, 2, 3, 4, 0, 22], ["+", 64, 1, 0, 11, 12, 2, 3, 4, 0, 21], ["+", 64, 1, 0, 11, 12, 2, 3, 4, 0, 25]]
| 1
| 200
| 5
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll b[100][100];
ll sum[110][110];
ll S(int x1, int y1, int x2, int y2) {
return sum[y2 + 1][x2 + 1] - sum[y2 + 1][x1] - sum[y1][x2 + 1] + sum[y1][x1];
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> b[i][j];
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
sum[i + 1][j + 1] = sum[i + 1][j] + b[i][j];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
sum[i + 1][j] += sum[i][j];
}
}
ll ans = -1e18;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = i; k < n; k++) {
for (int l = j; l < n; l++) {
ans = max(ans, S(j, i, k, l));
}
}
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll b[100][100];
ll sum[110][110];
ll S(int x1, int y1, int x2, int y2) {
return sum[y2 + 1][x2 + 1] - sum[y2 + 1][x1] - sum[y1][x2 + 1] + sum[y1][x1];
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> b[i][j];
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
sum[i + 1][j + 1] = sum[i + 1][j] + b[i][j];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
sum[i + 1][j] += sum[i][j];
}
}
ll ans = -1e18;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = i; k < n; k++) {
for (int l = j; l < n; l++) {
ans = max(ans, S(j, i, l, k));
}
}
}
}
cout << ans << endl;
}
|
[["-", 12, 2, 3, 4, 0, 2, 3, 4, 0, 22], ["-", 12, 2, 3, 4, 0, 2, 3, 4, 0, 21], ["+", 12, 2, 3, 4, 0, 2, 3, 4, 0, 21], ["+", 12, 2, 3, 4, 0, 2, 3, 4, 0, 22]]
| 1
| 361
| 4
|
#include <stdio.h>
int main(void) {
int i, j, k, l;
int h, w;
char map[1000][1000];
int n;
int max, min;
while (1) {
scanf(" %d ", &n);
if (!n)
break;
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
scanf(" %c ", &map[i][j]);
}
}
max = 0;
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
h = 0;
w = 0;
while (map[i + h][j] == '.' && i + h < n)
h++;
while (map[i][j + w] == '.' && j + w < n)
w++;
if (h < w)
min = h;
else
min = w;
for (k = 1; k < min; k++) {
for (l = 1; l < min; l++) {
if (map[i + k][j + l] == '*') {
min = k;
break;
}
}
}
if (min > max)
max = min;
}
}
printf("%d\n", max);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int i, j, k, l;
int h, w;
char map[1000][1000];
int n;
int max, min;
while (1) {
scanf(" %d ", &n);
if (!n)
break;
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
scanf(" %c ", &map[i][j]);
}
}
max = 0;
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
h = 0;
w = 0;
while (map[i + h][j] == '.' && i + h < n)
h++;
while (map[i][j + w] == '.' && j + w < n)
w++;
if (h < w)
min = h;
else
min = w;
for (k = 1; k < min; k++) {
for (l = 1; l < min; l++) {
if (map[i + k][j + l] == '*') {
min = l;
break;
}
}
}
if (min > max)
max = min;
}
}
printf("%d\n", max);
}
return 0;
}
|
[["-", 0, 57, 64, 9, 0, 1, 0, 11, 12, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 22]]
| 0
| 295
| 2
|
#include <stdio.h>
int min(int a, int b, int c) {
int min = a;
if (min > b)
min = b;
if (min > c)
min = c;
return min;
}
int main(void) {
char masu[1000][1000];
int space[1000][1000];
int n;
int max;
int i, j;
while (1) {
scanf("%d", &n);
if (n == 0)
break;
for (i = 0; i < n; i++)
scanf("%s", masu[i]);
for (i = 0; i < n; i++) {
if (masu[i][0] = '*')
space[i][0] = 0;
else
space[i][0] = 1;
if (masu[0][i] = '*')
space[0][i] = 0;
else
space[0][i] = 1;
}
max = 0;
for (i = 1; i < n; i++) {
for (j = 1; j < n; j++) {
if (masu[i][j] == '*')
space[i][j] = 0;
else
space[i][j] =
min(space[i - 1][j - 1], space[i - 1][j], space[i][j - 1]);
if (max < space[i][j])
max = space[i][j];
}
}
printf("%d\n", max);
}
return 0;
}
|
#include <stdio.h>
int min(int a, int b, int c) {
int min = a;
if (min > b)
min = b;
if (min > c)
min = c;
return min;
}
int main(void) {
char masu[1000][1000];
int space[1000][1000];
int n;
int max;
int i, j;
while (1) {
scanf("%d", &n);
if (n == 0)
break;
for (i = 0; i < n; i++)
scanf("%s", masu[i]);
for (i = 0; i < n; i++) {
if (masu[i][0] == '*')
space[i][0] = 0;
else
space[i][0] = 1;
if (masu[0][i] == '*')
space[0][i] = 0;
else
space[0][i] = 1;
}
max = 0;
for (i = 1; i < n; i++) {
for (j = 1; j < n; j++) {
if (masu[i][j] == '*')
space[i][j] = 0;
else
space[i][j] =
min(space[i - 1][j - 1], space[i - 1][j], space[i][j - 1]) + 1;
if (max < space[i][j])
max = space[i][j];
}
}
printf("%d\n", max);
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 23, 0, 11, 17, 32], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 17, 60], ["+", 75, 76, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 75, 76, 0, 1, 0, 11, 12, 16, 12, 13]]
| 0
| 351
| 6
|
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int dp[3000][3000], n, x[3000][3000], maxn;
char a;
int main() {
while (true) {
memset(dp, 0, sizeof(dp));
cin >> n;
if (!n) {
break;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> a;
if (a == '*') {
x[i][j] = 1;
} else {
x[i][j] = 0;
}
}
}
maxn = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (x[i][j] == 1) {
dp[i][j] = 0;
} else {
dp[i][j] = max(dp[i - 1][j - 1], min(dp[i - 1][j], dp[i][j - 1]) + 1);
}
maxn = max(maxn, dp[i][j]);
}
}
cout << maxn << endl;
}
}
|
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int dp[3000][3000], n, x[3000][3000], maxn;
char a;
int main() {
while (true) {
memset(dp, 0, sizeof(dp));
cin >> n;
if (!n) {
break;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> a;
if (a == '*') {
x[i][j] = 1;
} else {
x[i][j] = 0;
}
}
}
maxn = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (x[i][j] == 1) {
dp[i][j] = 0;
} else {
dp[i][j] = min(dp[i - 1][j - 1], min(dp[i - 1][j], dp[i][j - 1])) + 1;
}
maxn = max(maxn, dp[i][j]);
}
}
cout << maxn << endl;
}
}
|
[["-", 0, 9, 0, 1, 0, 11, 12, 2, 63, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 2, 63, 22], ["+", 31, 2, 3, 4, 0, 2, 3, 4, 0, 25], ["-", 0, 1, 0, 11, 12, 2, 3, 4, 0, 25]]
| 1
| 272
| 4
|
#include <iostream>
using namespace std;
int main() {
int n;
char m[1000][1001];
while (cin >> n && n) {
int a = 0;
for (int i = 0; i < n; ++i)
cin >> m[i];
for (int i = 0; i <= n - a; ++i) {
for (int j = 0; j <= n - a; ++j) {
if (m[i][j] == '.') {
bool f = true;
for (int k = 1; f; ++k) {
for (int l = k; l >= 0; ++l) {
if (m[i + l][j + k] != '.') {
a = max(a, k);
j += k;
f = false;
break;
}
if (m[i + k][j + l] != '.') {
a = max(a, k);
j += l;
f = false;
break;
}
}
}
}
}
}
cout << a << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int n;
char m[1000][1001];
while (cin >> n && n) {
int a = 0;
for (int i = 0; i < n; ++i)
cin >> m[i];
for (int i = 0; i < n - a; ++i) {
for (int j = 0; j < n - a; ++j) {
if (m[i][j] == '.') {
bool f = true;
for (int k = 1; f; ++k) {
for (int l = k; l >= 0; --l) {
if (m[i + l][j + k] != '.') {
a = max(a, k);
j += k;
f = false;
break;
}
if (m[i + k][j + l] != '.') {
a = max(a, k);
j += l;
f = false;
break;
}
}
}
}
}
}
cout << a << endl;
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18], ["-", 0, 7, 8, 9, 0, 7, 26, 27, 17, 29], ["+", 0, 7, 8, 9, 0, 7, 26, 27, 17, 68]]
| 1
| 234
| 6
|
#include <iostream>
#include <string>
using namespace std;
int n;
char field[1000][1000];
int dp[1000][1000];
void solve() {
fill(dp[0], dp[1000], 0);
for (int i = 0; i < n; i++) {
if (field[0][i] == '.')
dp[0][i] = 1;
if (field[i][0] == '.')
dp[i][0] = 1;
}
int max = 0;
for (int y = 1; y < n; y++)
for (int x = 1; x < n; x++) {
if (field[y][x] = '*') {
dp[y][x] = 0;
continue;
}
int min = dp[y - 1][x - 1];
if (min > dp[y][x - 1])
min = dp[y][x - 1];
if (min > dp[y - 1][x])
min = dp[y - 1][x];
dp[y][x] = min + 1;
if (dp[y][x] > max)
max = dp[y][x];
}
cout << max << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
while (cin >> n, n) {
for (int y = 0; y < n; y++)
for (int x = 0; x < n; x++)
cin >> field[y][x];
solve();
}
}
|
#include <iostream>
#include <string>
using namespace std;
int n;
char field[1000][1000];
int dp[1000][1000];
void solve() {
fill(dp[0], dp[1000], 0);
for (int i = 0; i < n; i++) {
if (field[0][i] == '.')
dp[0][i] = 1;
if (field[i][0] == '.')
dp[i][0] = 1;
}
int max = 0;
for (int y = 1; y < n; y++)
for (int x = 1; x < n; x++) {
if (field[y][x] == '*') {
dp[y][x] = 0;
continue;
}
int min = dp[y - 1][x - 1];
if (min > dp[y][x - 1])
min = dp[y][x - 1];
if (min > dp[y - 1][x])
min = dp[y - 1][x];
dp[y][x] = min + 1;
if (dp[y][x] > max)
max = dp[y][x];
}
cout << max << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
while (cin >> n, n) {
for (int y = 0; y < n; y++)
for (int x = 0; x < n; x++)
cin >> field[y][x];
solve();
}
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 11, 17, 32], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60]]
| 1
| 356
| 2
|
#include <iostream>
#include <string>
using namespace std;
int checkSquare(char *data, int x0, int y0, int n) {
int d = 1;
while ((x0 + d) < n && (y0 + d) < n) {
for (int y = y0; y < (y0 + d); y++) {
for (int x = x0; x < (x0 + d); x++) {
if (data[y * n + x] == '*') {
return d - 1;
}
}
}
d++;
}
return d;
}
int main() {
int n;
char *data;
string line;
while (1) {
int max = 0;
getline(cin, line);
sscanf(line.c_str(), "%d", &n);
if (n == 0)
break;
data = new char[n * n + 1];
for (int i = 0; i < n; i++) {
getline(cin, line);
for (int j = 0; j < n; j++) {
data[i * n + j] = line[j];
}
}
for (int y = 0; y < n; y++) {
for (int x = 0; x < n; x++) {
if (data[y * n + x] == '.') {
int l = checkSquare(data, x, y, n);
max = (max < l) ? l : max;
}
}
}
cout << max << endl;
delete[] data;
data = 0;
}
return 0;
}
|
#include <iostream>
#include <string>
using namespace std;
int checkSquare(char *data, int x0, int y0, int n) {
int d = 1;
while ((x0 + d) <= n && (y0 + d) <= n) {
for (int y = y0; y < (y0 + d); y++) {
for (int x = x0; x < (x0 + d); x++) {
if (data[y * n + x] == '*') {
return d - 1;
}
}
}
d++;
}
return d - 1;
}
int main() {
int n;
char *data;
string line;
while (1) {
int max = 0;
getline(cin, line);
sscanf(line.c_str(), "%d", &n);
if (n == 0)
break;
data = new char[n * n + 1];
for (int i = 0; i < n; i++) {
getline(cin, line);
for (int j = 0; j < n; j++) {
data[i * n + j] = line[j];
}
}
for (int y = 0; y < n; y++) {
for (int x = 0; x < n; x++) {
if (data[y * n + x] == '.') {
int l = checkSquare(data, x, y, n);
max = (max < l) ? l : max;
}
}
}
cout << max << endl;
delete[] data;
data = 0;
}
return 0;
}
|
[["-", 0, 52, 15, 339, 51, 16, 31, 16, 17, 18], ["+", 0, 52, 15, 339, 51, 16, 31, 16, 17, 19], ["-", 0, 52, 15, 339, 51, 16, 12, 16, 17, 18], ["+", 0, 52, 15, 339, 51, 16, 12, 16, 17, 19], ["+", 0, 14, 8, 9, 0, 37, 0, 16, 17, 33], ["+", 0, 14, 8, 9, 0, 37, 0, 16, 12, 13]]
| 1
| 335
| 6
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
char fie[1111][1111];
int rui[1111][1111];
main() {
int N;
while (1) {
cin >> N;
if (N == 0)
break;
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++)
cin >> fie[j][i];
}
memset(rui, 0, sizeof(rui));
for (int i = 1; i <= N; i++) {
if (fie[1][i] == '.')
rui[1][i] = 1;
for (int j = 2; j <= N; j++) {
rui[j][i] = rui[j - 1][i];
if (fie[j][i] == '.')
rui[j][i]++;
}
}
for (int j = 1; j <= N; j++) {
for (int i = 2; i <= N; i++) {
rui[j][i] += rui[j][i - 1];
}
}
/*
for(int i=1;i<=N;i++){
for(int j=1;j<=N;j++) printf("%2d ",rui[j][i]);
puts("");
}
*/
int res = 0;
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
if (fie[j][i] == '*')
continue;
int st = 0, ed = min(N - j, N - i);
int ret = 0;
// cout << j << ":" << i << endl;
while (st <= ed) {
int h = (st + ed) / 2;
int r = rui[j + h][i + h] - rui[j + h][i - 1] - rui[j - 1][i + h] +
rui[i - 1][j - 1];
// cout << r << " " <<rui[j+h][i+h]<<" "<<rui[j+h][i-1]<<"
//"<<rui[j-1][i+h]<<" "<<rui[i-1][j-1]<<" "<< h << endl;
if (r == (h + 1) * (h + 1)) {
st = h + 1;
ret = h + 1;
} else
ed = h - 1;
}
res = max(res, ret);
}
}
cout << res << endl;
}
}
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
char fie[1111][1111];
int rui[1111][1111];
main() {
int N;
while (1) {
cin >> N;
if (N == 0)
break;
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++)
cin >> fie[j][i];
}
memset(rui, 0, sizeof(rui));
for (int i = 1; i <= N; i++) {
if (fie[1][i] == '.')
rui[1][i] = 1;
for (int j = 2; j <= N; j++) {
rui[j][i] = rui[j - 1][i];
if (fie[j][i] == '.')
rui[j][i]++;
}
}
for (int j = 1; j <= N; j++) {
for (int i = 2; i <= N; i++) {
rui[j][i] += rui[j][i - 1];
}
}
/*
for(int i=1;i<=N;i++){
for(int j=1;j<=N;j++) printf("%2d ",rui[j][i]);
puts("");
}
*/
int res = 0;
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
if (fie[j][i] == '*')
continue;
int st = 0, ed = min(N - j, N - i);
int ret = 0;
// cout << j << ":" << i << endl;
while (st <= ed) {
int h = (st + ed) / 2;
int r = rui[j + h][i + h] - rui[j + h][i - 1] - rui[j - 1][i + h] +
rui[j - 1][i - 1];
// cout << r << " " <<rui[j+h][i+h]<<" "<<rui[j+h][i-1]<<"
//"<<rui[j-1][i+h]<<" "<<rui[i-1][j-1]<<" "<< h << endl;
if (r >= (h + 1) * (h + 1)) {
st = h + 1;
ret = h + 1;
} else
ed = h - 1;
}
res = max(res, ret);
}
}
cout << res << endl;
}
}
|
[["-", 12, 69, 28, 69, 341, 342, 0, 16, 31, 22], ["+", 12, 69, 28, 69, 341, 342, 0, 16, 31, 22], ["-", 51, 16, 12, 69, 341, 342, 0, 16, 31, 22], ["+", 51, 16, 12, 69, 341, 342, 0, 16, 31, 22], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20]]
| 1
| 459
| 6
|
#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int main() {
int n;
string s[10000];
int w[1001][1001];
while (cin >> n, n) {
memset(w, 0, sizeof(0));
int ans = 0;
for (int i = 0; i < n; i++)
cin >> s[i];
for (int i = 0; i < n; i++) {
if (s[0][i] == '.')
w[0][i] = 1;
if (s[i][0] == '.')
w[i][0] = 1;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (s[i][j] == '*')
w[i][j] = 0;
else {
w[i][j] = min(w[i - 1][j - 1], min(w[i][j - 1], w[i - 1][j])) + 1;
ans = max(ans, w[i][j]);
}
}
}
cout << ans << endl;
}
}
|
#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int main() {
int n;
string s[10000];
int w[1001][1001];
while (cin >> n, n) {
memset(w, 0, sizeof(0));
int ans = 0;
for (int i = 0; i < n; i++)
cin >> s[i];
for (int i = 0; i < n; i++) {
if (s[0][i] == '.')
w[0][i] = 1;
if (s[i][0] == '.')
w[i][0] = 1;
}
for (int i = 1; i < n; i++) {
for (int j = 1; j < n; j++) {
if (s[i][j] == '*')
w[i][j] = 0;
else {
w[i][j] = min(w[i - 1][j - 1], min(w[i][j - 1], w[i - 1][j])) + 1;
ans = max(ans, w[i][j]);
}
}
}
cout << ans << endl;
}
}
|
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13]]
| 1
| 276
| 4
|
while True:
n=int(input())
if n==0:
break
field=[input() for i in range(n)]
large=[[0]*(n+1) for i in range(n+1)]
for i in range(n):
for j in range(n):
if field[i][j]=='.':
large[i][j]=min(large[i][j-1],large[i-1][j],large[i-1][i-1])+1
print(max(list(map(max,large))))
|
while True:
n=int(input())
if n==0:
break
field=[input() for i in range(n)]
large=[[0]*(n+1) for i in range(n+1)]
for i in range(n):
for j in range(n):
if field[i][j]=='.':
large[i][j]=min(large[i][j-1],large[i-1][j],large[i-1][j-1])+1
print(max(list(map(max,large))))
|
[["-", 31, 652, 3, 4, 0, 206, 206, 657, 31, 22], ["+", 31, 652, 3, 4, 0, 206, 206, 657, 31, 22]]
| 5
| 141
| 2
|
#include <iostream>
using namespace std;
typedef long long ll;
int a[101][101];
ll dp[101][101];
int N;
int main() {
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
cin >> a[i][j];
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1] - dp[i][j] + a[i][j];
ll res = -(1 << 30);
for (int miny = 0; miny < N; miny++) {
for (int minx = 0; minx < N; minx++) {
for (int maxy = miny; maxy < N; maxy++) {
for (int maxx = minx; maxx < N; maxx++) {
res = max(res, dp[maxy + 1][maxx + 1] - dp[miny][maxx + 1] -
dp[maxy + 1][minx] + dp[miny][minx]);
}
}
}
}
cout << res << endl;
return 0;
}
|
#include <iostream>
using namespace std;
typedef long long ll;
int a[101][101];
ll dp[101][101];
int N;
int main() {
cin >> N;
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
cin >> a[i][j];
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1] - dp[i][j] + a[i][j];
ll res = -(1LL << 30);
for (int miny = 0; miny < N; miny++) {
for (int minx = 0; minx < N; minx++) {
for (int maxy = miny; maxy < N; maxy++) {
for (int maxx = minx; maxx < N; maxx++) {
res = max(res, dp[maxy + 1][maxx + 1] - dp[miny][maxx + 1] -
dp[maxy + 1][minx] + dp[miny][minx]);
}
}
}
}
cout << res << endl;
return 0;
}
|
[["+", 0, 14, 8, 9, 0, 1, 0, 16, 31, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 17, 152], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 12, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["-", 49, 50, 51, 91, 28, 23, 0, 16, 31, 13], ["+", 49, 50, 51, 91, 28, 23, 0, 16, 31, 13]]
| 1
| 282
| 6
|
#include <algorithm>
#include <iostream>
#include <limits>
using namespace std;
int a[101][101];
int dp[101][101];
int main() {
int n;
cin >> n;
int ans = numeric_limits<int>::min();
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
cin >> a[i][j];
dp[i][j] = a[i][j] + dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
}
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
for (int x = 1; x <= i; ++x) {
for (int y = 1; y <= j; ++y) {
ans = max(ans,
dp[i][j] - dp[i][x - 1] - dp[y - 1][j] + dp[y - 1][x - 1]);
}
}
}
}
cout << ans << endl;
}
|
#include <algorithm>
#include <iostream>
#include <limits>
using namespace std;
int a[101][101];
int dp[101][101];
int main() {
int n;
cin >> n;
int ans = numeric_limits<int>::min();
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
cin >> a[i][j];
dp[i][j] = a[i][j] + dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
}
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
for (int x = 1; x <= j; ++x) {
for (int y = 1; y <= i; ++y) {
ans = max(ans,
dp[i][j] - dp[i][x - 1] - dp[y - 1][j] + dp[y - 1][x - 1]);
}
}
}
}
cout << ans << endl;
}
|
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 12, 22]]
| 1
| 260
| 4
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <istream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define vci vector<int>
#define vcs vector<string>
#define pb push_back
#define sz size()
#define mapii map<int, int>
#define mapci map<char, int>
#define mapsi map<string, int>
#define all(x) x.begin(), x.end()
#define minit(a, i) memset(a, i, sizeof(a));
#define for_(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define for_d(i, a, b) for (int i = (int)a - 1; i >= b; i--)
#define for_r(i, a, b, c) for (int i = (int)a; i < (int)b; i += c)
#define for_dr(i, a, b, c) for (int i = (int)a - 1; i >= b; i -= c)
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
template <class T> int __builtin_popcount(T n) {
return n ? 1 + __builtin_popcount(n & (n - 1)) : 0;
}
typedef long long ll;
typedef double D;
const int iINF = 2147483647;
const ll lINF = 9223372036854775807;
template <class T> inline void dbg(T t) { cout << t << endl; }
int main() {
int n;
cin >> n;
int v[110];
int b[110][110];
minit(b, -1);
int ans = -1000000000;
for_(i, 0, n) {
for_(j, 0, n) cin >> v[j];
for_(j, 0, n) {
int s = 0;
for_(k, 0, n) {
s += v[k];
b[j][k] = max(b[j][k], 0) + s;
ans = max(ans, b[j][k]);
}
}
}
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <istream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define vci vector<int>
#define vcs vector<string>
#define pb push_back
#define sz size()
#define mapii map<int, int>
#define mapci map<char, int>
#define mapsi map<string, int>
#define all(x) x.begin(), x.end()
#define minit(a, i) memset(a, i, sizeof(a));
#define for_(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define for_d(i, a, b) for (int i = (int)a - 1; i >= b; i--)
#define for_r(i, a, b, c) for (int i = (int)a; i < (int)b; i += c)
#define for_dr(i, a, b, c) for (int i = (int)a - 1; i >= b; i -= c)
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
template <class T> int __builtin_popcount(T n) {
return n ? 1 + __builtin_popcount(n & (n - 1)) : 0;
}
typedef long long ll;
typedef double D;
const int iINF = 2147483647;
const ll lINF = 9223372036854775807;
template <class T> inline void dbg(T t) { cout << t << endl; }
int main() {
int n;
cin >> n;
int v[110];
int b[110][110];
minit(b, -1);
int ans = -1000000000;
for_(i, 0, n) {
for_(j, 0, n) cin >> v[j];
for_(j, 0, n) {
int s = 0;
for_(k, j, n) {
s += v[k];
b[j][k] = max(b[j][k], 0) + s;
ans = max(ans, b[j][k]);
}
}
}
cout << ans << endl;
return 0;
}
|
[["-", 0, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["+", 0, 14, 49, 53, 54, 55, 0, 56, 39, 78], ["-", 0, 1, 0, 2, 3, 4, 0, 25, 0, 35]]
| 1
| 346
| 3
|
#include <stdio.h>
int s[1000000];
int main() {
int n, q, a, v, i, j, maxa, maxv;
scanf("%d %d", &n, &q);
for (i = 0; i < q; i++) {
scanf("%d %d", &a, &v);
s[a - 1] += v;
if (i == 0) {
maxa = a - 1;
maxv = s[a - 1];
printf("%d %d\n", maxa + 1, maxv);
continue;
}
if (v > 0) {
if ((maxv < s[a - 1]) || ((maxv == s[a - 1]) && (maxa > a))) {
maxa = a;
maxv = s[a - 1];
}
} else {
if (maxa == a) {
maxa = n + 1;
maxv = 0;
for (j = 0; j < n; j++) {
if ((maxv < s[j]) || ((maxv == s[j]) && (maxa > a))) {
maxa = j + 1;
maxv = s[j];
}
}
}
}
printf("%d %d\n", maxa, maxv);
}
return 0;
}
|
#include <stdio.h>
int s[1000000];
int main() {
int n, q, a, v, i, j, maxa, maxv;
scanf("%d %d", &n, &q);
for (i = 0; i < q; i++) {
scanf("%d %d", &a, &v);
s[a - 1] += v;
if (i == 0) {
maxa = a;
maxv = s[a - 1];
printf("%d %d\n", maxa, maxv);
continue;
}
if (v > 0) {
if ((maxv < s[a - 1]) || ((maxv == s[a - 1]) && (maxa > a))) {
maxa = a;
maxv = s[a - 1];
}
} else {
if (maxa == a) {
maxa = n + 1;
maxv = 0;
for (j = 0; j < n; j++) {
if ((maxv < s[j]) || ((maxv == s[j]) && (maxa > a))) {
maxa = j + 1;
maxv = s[j];
}
}
}
}
printf("%d %d\n", maxa, maxv);
}
return 0;
}
|
[["-", 64, 9, 0, 1, 0, 11, 12, 16, 17, 33], ["-", 64, 9, 0, 1, 0, 11, 12, 16, 12, 13], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 17, 72], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
| 0
| 269
| 4
|
#include <stdio.h>
int main(void) {
int n, q, num, fish, i, j, vic = 0, max = 0, get[100];
scanf("%d %d", &n, &q);
for (i = 1; i <= n; i++) {
get[i] = 0;
}
for (i = 0; i < q; i++) {
scanf("%d %d", &num, &fish);
get[num] += fish;
if (fish < 0 && num == vic) {
max = 0;
for (j = n; j > 0; j--) {
if (max <= get[j]) {
max = get[j];
vic = j;
}
}
} else if (get[num] > max || (get[num] == max && vic > num)) {
max = get[num];
vic = num;
}
printf("%d %d\n", vic, get[vic]);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int n, q, num, fish, i, j, vic = 0, max = 0, get[1000000];
scanf("%d %d", &n, &q);
for (i = 1; i <= n; i++) {
get[i] = 0;
}
for (i = 0; i < q; i++) {
scanf("%d %d", &num, &fish);
get[num] += fish;
if (fish < 0 && num == vic) {
max = 0;
for (j = n; j > 0; j--) {
if (max <= get[j]) {
max = get[j];
vic = j;
}
}
} else if (get[num] > max || (get[num] == max && vic > num)) {
max = get[num];
vic = num;
}
printf("%d %d\n", vic, get[vic]);
}
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13]]
| 0
| 212
| 2
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q;
cin >> n >> q;
vector<int> A(n, 0);
priority_queue<pair<int, int>> Q;
for (int i = 0; i < n; i++) {
Q.push(make_pair(0, i));
}
for (int i = 0; i < q; i++) {
int a, v;
cin >> a >> v;
a--;
A[a] += v;
Q.push(make_pair(A[a], a));
pair<int, int> ans;
while (1) {
ans = Q.top();
if (ans.first == A[ans.second]) {
break;
} else {
Q.pop();
}
}
cout << ans.second + 1 << ' ' << ans.first << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q;
cin >> n >> q;
vector<int> A(n, 0);
priority_queue<pair<int, int>> Q;
for (int i = 0; i < n; i++) {
Q.push(make_pair(0, -i));
}
for (int i = 0; i < q; i++) {
int a, v;
cin >> a >> v;
a--;
A[a] += v;
Q.push(make_pair(A[a], -a));
pair<int, int> ans;
while (1) {
ans = Q.top();
if (ans.first == A[-ans.second]) {
break;
} else {
Q.pop();
}
}
cout << -ans.second + 1 << ' ' << ans.first << endl;
}
return 0;
}
|
[["+", 3, 4, 0, 2, 3, 4, 0, 91, 17, 33], ["+", 51, 16, 12, 69, 341, 342, 0, 91, 17, 33], ["+", 31, 16, 31, 16, 12, 16, 31, 91, 17, 33]]
| 1
| 194
| 4
|
#include <algorithm>
#include <cstdio>
#include <queue>
using namespace std;
priority_queue<pair<int, int>> q;
int n, m, d[1000001], a, b;
main() {
scanf("%d%d", &n, &n);
q.push(make_pair(0, -1));
for (int i = 0; i < m; i++) {
scanf("%d%d", &a, &b);
d[a] += b;
q.push(make_pair(d[a], -a));
while (1) {
pair<int, int> p = q.top();
if (p.first == d[-p.second]) {
printf("%d %d\n", -p.second, p.first);
break;
}
q.pop();
}
}
}
|
#include <algorithm>
#include <cstdio>
#include <queue>
using namespace std;
priority_queue<pair<int, int>> q;
int n, m, d[1000001], a, b;
main() {
scanf("%d%d", &n, &m);
q.push(make_pair(0, -1));
for (int i = 0; i < m; i++) {
scanf("%d%d", &a, &b);
d[a] += b;
q.push(make_pair(d[a], -a));
while (1) {
pair<int, int> p = q.top();
if (p.first == d[-p.second]) {
printf("%d %d\n", -p.second, p.first);
break;
}
q.pop();
}
}
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 66, 28, 22], ["+", 0, 1, 0, 2, 3, 4, 0, 66, 28, 22]]
| 1
| 178
| 2
|
#include <iostream>
#include <set>
#include <vector>
using namespace std;
typedef pair<int, int> Pii;
int main() {
int N, Q;
cin >> N >> Q;
vector<int> memo(N + 1);
set<Pii> st;
for (int q = 0; q < Q; q++) {
int a, v;
cin >> a >> v;
st.erase(Pii(-v, a));
memo[a] += v;
st.insert(Pii(-memo[a], a));
cout << st.begin()->second << ' ' << -st.begin()->first << endl;
}
return 0;
}
|
#include <iostream>
#include <set>
#include <vector>
using namespace std;
typedef pair<int, int> Pii;
int main() {
int N, Q;
cin >> N >> Q;
vector<int> memo(N + 1);
set<Pii> st;
for (int q = 0; q < Q; q++) {
int a, v;
cin >> a >> v;
st.erase(Pii(-memo[a], a));
memo[a] += v;
st.insert(Pii(-memo[a], a));
cout << st.begin()->second << ' ' << -st.begin()->first << endl;
}
return 0;
}
|
[["-", 3, 4, 0, 2, 3, 4, 0, 91, 28, 22], ["+", 0, 2, 3, 4, 0, 91, 28, 69, 28, 22], ["+", 3, 4, 0, 91, 28, 69, 341, 342, 0, 70], ["+", 3, 4, 0, 91, 28, 69, 341, 342, 0, 22], ["+", 3, 4, 0, 91, 28, 69, 341, 342, 0, 73]]
| 1
| 144
| 19
|
hash = Hash.new(0)
min_a, max_v = Float::INFINITY, 0
n, q = gets.chomp.split.map(&:to_i)
q.times do
a, v = gets.chomp.split.map(&:to_i)
hash[a] += v
if v > 0
if hash[a] > max_v
max_v = hash[a]
min_a = a
elsif hash[a] == max_v
max_a = [a, min_a].min
end
else
if a == min_a
order = hash.sort do |(k1, v1), (k2, v2)|
if v1 == v2
k1 <=> k2
else
v2 <=> v1
end
end
min_a, max_v = order.first[0], order.first[1]
end
end
puts [min_a, max_v].join(' ')
end
|
hash = Hash.new(0)
min_a, max_v = Float::INFINITY, -Float::INFINITY
n, q = gets.chomp.split.map(&:to_i)
q.times do
a, v = gets.chomp.split.map(&:to_i)
hash[a] += v
if v > 0
if hash[a] > max_v
max_v = hash[a]
min_a = a
elsif hash[a] == max_v
min_a = [a, min_a].min
end
else
if a == min_a
order = hash.sort do |(k1, v1), (k2, v2)|
if v1 == v2
k1 <=> k2
else
v2 <=> v1
end
end
min_a, max_v = order.first[0], order.first[1]
end
end
puts [min_a, max_v].join(' ')
end
|
[["-", 36, 36, 0, 493, 0, 662, 12, 762, 0, 612], ["+", 0, 493, 0, 662, 12, 762, 0, 748, 17, 33], ["+", 0, 662, 12, 762, 0, 748, 439, 760, 345, 743], ["+", 0, 662, 12, 762, 0, 748, 439, 760, 0, 349], ["+", 0, 662, 12, 762, 0, 748, 439, 760, 141, 743], ["-", 0, 121, 75, 759, 64, 749, 0, 662, 31, 22], ["+", 0, 121, 75, 759, 64, 749, 0, 662, 31, 22]]
| 4
| 164
| 7
|
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
result, index = 0, 1
for _ in range(q):
a, v = [int(el) for el in input().split(' ')]
data[a-1] += v
if v > 0:
if result < data[a-1]:
result, index = data[a-1], a
elif result == data[a-1]:
index = min(index, a-1)
else:
if index == a:
result = max(data)
index = data.index(result) + 1
print(index, result)
|
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
result, index = 0, 1
for _ in range(q):
a, v = [int(el) for el in input().split(' ')]
data[a-1] += v
if v > 0:
if result < data[a-1]:
result, index = data[a-1], a
elif result == data[a-1]:
index = min(index, a)
else:
if index == a:
result = max(data)
index = data.index(result) + 1
print(index, result)
|
[["-", 0, 662, 12, 652, 3, 4, 0, 657, 17, 33], ["-", 0, 662, 12, 652, 3, 4, 0, 657, 12, 612]]
| 5
| 152
| 2
|
n,q=map(int,input().split())
s=[0]*-~n
w=m=0
for _ in[0]*q:
a,v=map(int,input().split())
s[a]+=v
if v<0 and a==w:m=max(s);w=s.index(m)
elif s[a]>maxv:w,m=a,s[a]
elif s[a]==maxv:w=min(w,a)
print(w,m)
|
n,q=map(int,input().split())
s=[0]*-~n
w=m=0
for _ in[0]*q:
a,v=map(int,input().split())
s[a]+=v
if v<0 and a==w:m=max(s);w=s.index(m)
elif s[a]>m:w,m=a,s[a]
elif s[a]==m:w=min(w,a)
print(w,m)
|
[["-", 8, 196, 0, 57, 75, 665, 15, 666, 0, 22], ["+", 8, 196, 0, 57, 75, 665, 15, 666, 0, 22]]
| 5
| 125
| 13
|
"""
セグメント木
"""
INF = 10 ** 20
def main():
n, q = map(int, input().split())
size = 1
while size < n:
size *= 2
size = size * 2 - 1
seg_tree = [(INF, 0) for _ in range(size)]
def update(a, v):
ind = (size - 1) // 2 + a
prea, prev = seg_tree[ind]
seg_tree[ind] = (a + 1, prev + v)
while ind > 0:
ind = (ind - 1) // 2
ca1, cv1 = seg_tree[ind * 2 + 1]
ca2, cv2 = seg_tree[ind * 2 + 2]
if cv1 >= cv2:
if seg_tree[ind] == (ca1, cv2): break
seg_tree[ind] = (ca1, cv1)
else:
if seg_tree[ind] == (ca2, cv2): break
seg_tree[ind] = (ca2, cv2)
for i in range(q):
a, v = map(int, input().split())
update(a - 1, v)
print(seg_tree[0][0], seg_tree[0][1])
main()
|
"""
セグメント木
"""
INF = 10 ** 20
def main():
n, q = map(int, input().split())
size = 1
while size < n:
size *= 2
size = size * 2 - 1
seg_tree = [(INF, 0) for _ in range(size)]
def update(a, v):
ind = (size - 1) // 2 + a
prea, prev = seg_tree[ind]
seg_tree[ind] = (a + 1, prev + v)
while ind > 0:
ind = (ind - 1) // 2
ca1, cv1 = seg_tree[ind * 2 + 1]
ca2, cv2 = seg_tree[ind * 2 + 2]
if cv1 >= cv2:
if seg_tree[ind] == (ca1, cv1): break
seg_tree[ind] = (ca1, cv1)
else:
if seg_tree[ind] == (ca2, cv2): break
seg_tree[ind] = (ca2, cv2)
for i in range(q):
a, v = map(int, input().split())
update(a - 1, v)
print(seg_tree[0][0], seg_tree[0][1])
main()
|
[["-", 64, 196, 0, 57, 15, 666, 0, 660, 0, 22], ["+", 64, 196, 0, 57, 15, 666, 0, 660, 0, 22]]
| 5
| 248
| 2
|
var print = console.log;
function read_input(_input) {
var lines = _input.split("\n");
return function() { return lines.shift(); };
}
String.prototype.dot = function dot(x) {
var res = "";
for (var i = 0; i < x; i++) {
res += this.toString();
}
return res;
};
function IL(line, min1Flg) {
var s = line.split(' ');
var offset = min1Flg ? -1 : 0;
var res = [];
for (var i = 0; i < s.length; i++) {
res.push(parseInt(s[i]));
}
return res;
}
function range(i, n) {
var res = [];
for (; i < n; i++) {
res.push(i);
}
return res;
}
function IMAX(x, y) { return x > y ? x : y; }
function IMIN(x, y) { return x < y ? x : y; }
function item_getter_key(x) {
return function(a, b) {
if (a[x] < b[x])
return -1;
else if (a[x] > b[x])
return 1;
return 0;
};
}
var Counter = function Counter() {
this.dic = {};
var that = this;
this.add = function(key, val) {
if (that.dic.hasOwnProperty(key)) {
that.dic[key] += val;
} else {
that.dic[key] = val;
}
};
this.get = function(key) {
if (that.dic.hasOwnProperty(key)) {
return that.dic[key];
}
return 0;
};
// this.values = function(){
// var keys = Object.keys(that.dic);
// var res = [];
// for(var i =0;i<keys.length;i++){
// res.push([])
// }
//}
};
/**
* @return {number}
*/
Array.prototype.SUM = function SUM() {
var sum = 0;
this.forEach(function(elm) { sum += elm; });
return sum;
};
Array.prototype.Print = function Print(split) {
if (split === undefined) {
split = " ";
}
console.log(this.join(split));
};
/*
(((???????????)???
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
*/
// input?????\??????????????¨????????\???
function Main(_input) {
var input = read_input(_input);
var N = parseInt(input());
while (N !== 0) {
var keys = [];
var counter = new Counter();
for (var i = 0; i < N; i++) {
var tmp = IL(input());
counter.add(tmp[0], tmp[1] * tmp[2]);
if (keys.indexOf(tmp[0]) < 0) {
keys.push(tmp[0]);
}
}
var flg = false;
for (var i = 0; i < keys.length; i++) {
if (counter.get(keys[i]) >= 1000000) {
print(keys[i]);
flg = true;
}
}
if (!flg) {
print('NA');
}
N = parseInt(input());
}
}
//*???????????\????????¨??????????????§????????????????¨??????\????????????????????????????????????Main????????????????????????
// Main(require("fs").readFileSync("/dev/stdin", "utf8"));
Main(require("fs").readFileSync("input.txt", "utf8"));
|
var print = console.log;
function read_input(_input) {
var lines = _input.split("\n");
return function() { return lines.shift(); };
}
String.prototype.dot = function dot(x) {
var res = "";
for (var i = 0; i < x; i++) {
res += this.toString();
}
return res;
};
function IL(line, min1Flg) {
var s = line.split(' ');
var offset = min1Flg ? -1 : 0;
var res = [];
for (var i = 0; i < s.length; i++) {
res.push(parseInt(s[i]));
}
return res;
}
function range(i, n) {
var res = [];
for (; i < n; i++) {
res.push(i);
}
return res;
}
function IMAX(x, y) { return x > y ? x : y; }
function IMIN(x, y) { return x < y ? x : y; }
function item_getter_key(x) {
return function(a, b) {
if (a[x] < b[x])
return -1;
else if (a[x] > b[x])
return 1;
return 0;
};
}
var Counter = function Counter() {
this.dic = {};
var that = this;
this.add = function(key, val) {
if (that.dic.hasOwnProperty(key)) {
that.dic[key] += val;
} else {
that.dic[key] = val;
}
};
this.get = function(key) {
if (that.dic.hasOwnProperty(key)) {
return that.dic[key];
}
return 0;
};
// this.values = function(){
// var keys = Object.keys(that.dic);
// var res = [];
// for(var i =0;i<keys.length;i++){
// res.push([])
// }
//}
};
/**
* @return {number}
*/
Array.prototype.SUM = function SUM() {
var sum = 0;
this.forEach(function(elm) { sum += elm; });
return sum;
};
Array.prototype.Print = function Print(split) {
if (split === undefined) {
split = " ";
}
console.log(this.join(split));
};
/*
(((???????????)???
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
*/
// input?????\??????????????¨????????\???
function Main(_input) {
var input = read_input(_input);
var N = parseInt(input());
while (N !== 0) {
var keys = [];
var counter = new Counter();
for (var i = 0; i < N; i++) {
var tmp = IL(input());
counter.add(tmp[0], tmp[1] * tmp[2]);
if (keys.indexOf(tmp[0]) < 0) {
keys.push(tmp[0]);
}
}
var flg = false;
for (var i = 0; i < keys.length; i++) {
if (counter.get(keys[i]) >= 1000000) {
print(keys[i]);
flg = true;
}
}
if (!flg) {
print('NA');
}
N = parseInt(input());
}
}
//*???????????\????????¨??????????????§????????????????¨??????\????????????????????????????????????Main????????????????????????
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// Main(require("fs").readFileSync("input.txt", "utf8"));
|
[["-", 3, 3, 0, 2, 3, 3, 0, 557, 0, 491], ["+", 3, 3, 0, 2, 3, 3, 0, 557, 0, 491]]
| 2
| 690
| 2
|
import java.util.*;
class Main {
public static void main(String[] args) {
Solve s = new Solve();
s.solve();
}
}
class Solve {
Solve() {}
Scanner in = new Scanner(System.in);
void solve() {
while (in.hasNext()) {
int n = in.nextInt();
if (n == 0)
return;
Map<Integer, Long> m = new HashMap<Integer, Long>();
for (int i = 0; i < n; i++) {
int k = in.nextInt();
long p = in.nextInt(), l = in.nextInt();
if (m.get(k) == null)
m.put(k, p * l);
else
m.put(k, m.get(k) + p * l);
}
boolean f = true;
for (Map.Entry<Integer, Long> entry : m.entrySet()) {
if (entry.getValue() >= 1000000l) {
System.out.println(entry.getKey());
f = false;
}
}
if (f)
System.out.println("NA");
}
}
}
|
import java.util.*;
class Main {
public static void main(String[] args) {
Solve s = new Solve();
s.solve();
}
}
class Solve {
Solve() {}
Scanner in = new Scanner(System.in);
void solve() {
while (in.hasNext()) {
int n = in.nextInt();
if (n == 0)
return;
Map<Integer, Long> m = new LinkedHashMap<Integer, Long>();
for (int i = 0; i < n; i++) {
int k = in.nextInt();
long p = in.nextInt(), l = in.nextInt();
if (m.get(k) == null)
m.put(k, p * l);
else
m.put(k, m.get(k) + p * l);
}
boolean f = true;
for (Map.Entry<Integer, Long> entry : m.entrySet()) {
if (entry.getValue() >= 1000000l) {
System.out.println(entry.getKey());
f = false;
}
}
if (f)
System.out.println("NA");
}
}
}
|
[["-", 0, 503, 49, 200, 51, 230, 39, 513, 0, 78], ["+", 0, 503, 49, 200, 51, 230, 39, 513, 0, 78]]
| 3
| 260
| 2
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (true) {
final int times = Integer.parseInt(br.readLine());
if (times == 0) {
break;
}
Map<String, Long> data = new LinkedHashMap<>();
for (int i = 1; i <= times; i++) {
String[] e = br.readLine().split(" ");
data.merge(e[0], Long.parseLong(e[1]) * Long.parseLong(e[2]),
Long::sum);
}
int count = 0;
for (Map.Entry<String, Long> e : data.entrySet()) {
if (e.getValue() >= 1_000_000) {
System.out.println(e.getKey());
}
count++;
}
if (count == 0) {
System.out.println("NA");
}
}
}
}
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (true) {
final int times = Integer.parseInt(br.readLine());
if (times == 0) {
break;
}
Map<String, Long> data = new LinkedHashMap<>();
for (int i = 1; i <= times; i++) {
String[] e = br.readLine().split(" ");
data.merge(e[0], Long.parseLong(e[1]) * Long.parseLong(e[2]),
Long::sum);
}
int count = 0;
for (Map.Entry<String, Long> e : data.entrySet()) {
if (e.getValue() >= 1_000_000) {
System.out.println(e.getKey());
count++;
}
}
if (count == 0) {
System.out.println("NA");
}
}
}
}
|
[["-", 0, 514, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 514, 8, 196, 0, 57, 64, 196, 0, 46]]
| 3
| 248
| 2
|
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (true) {
final int times = Integer.parseInt(br.readLine());
if (times == 0) {
break;
}
Map<String, Long> data = new HashMap<>();
for (int i = 1; i <= times; i++) {
String[] e = br.readLine().split(" ");
data.merge(e[0], Long.parseLong(e[1]) * Long.parseLong(e[2]),
Long::sum);
}
long count = data.entrySet()
.stream()
.filter(e -> e.getValue() >= 1_000_000)
.peek(e -> System.out.println(e.getKey()))
.count();
if (count == 0) {
System.out.println("NA");
}
}
}
}
|
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (true) {
final int times = Integer.parseInt(br.readLine());
if (times == 0) {
break;
}
Map<String, Long> data = new LinkedHashMap<>();
for (int i = 1; i <= times; i++) {
String[] e = br.readLine().split(" ");
data.merge(e[0], Long.parseLong(e[1]) * Long.parseLong(e[2]),
Long::sum);
}
long count = data.entrySet()
.stream()
.filter(e -> e.getValue() >= 1_000_000L)
.peek(e -> System.out.println(e.getKey()))
.count();
if (count == 0L) {
System.out.println("NA");
}
}
}
}
|
[["-", 0, 503, 49, 200, 51, 230, 39, 513, 0, 78], ["+", 0, 503, 49, 200, 51, 230, 39, 513, 0, 78], ["-", 500, 492, 3, 4, 0, 218, 8, 16, 12, 499], ["+", 500, 492, 3, 4, 0, 218, 8, 16, 12, 499], ["-", 8, 196, 0, 57, 15, 15, 0, 16, 12, 499], ["+", 8, 196, 0, 57, 15, 15, 0, 16, 12, 499]]
| 3
| 229
| 6
|
import java.util.HashMap;
import java.util.Scanner;
public class Main {
private Scanner sc;
public static void main(String[] args) { new Main(); }
public Main() {
sc = new Scanner(System.in);
int lines = Integer.parseInt(sc.nextLine());
while (lines != 0) {
HashMap<String, Integer> nico = new HashMap<String, Integer>();
for (int i = 0; i < lines; i++) {
String line = sc.nextLine();
String[] data = line.split(" ");
int sales = Integer.parseInt(data[1]) * Integer.parseInt(data[2]);
if (nico.containsKey(data[0]) == true) {
nico.put(data[0], nico.get(data[0]) + sales);
} else {
nico.put(data[0], sales);
}
}
boolean na = true;
for (String key : nico.keySet()) {
if (nico.get(key) >= 1000000) {
System.out.println(key);
na = false;
}
}
if (na == true)
System.out.println("NA");
lines = Integer.parseInt(sc.nextLine());
}
}
}
|
import java.util.LinkedHashMap;
import java.util.Scanner;
public class Main {
private Scanner sc;
public static void main(String[] args) { new Main(); }
public Main() {
sc = new Scanner(System.in);
int lines = Integer.parseInt(sc.nextLine());
while (lines != 0) {
LinkedHashMap<String, Integer> nico =
new LinkedHashMap<String, Integer>();
for (int i = 0; i < lines; i++) {
String line = sc.nextLine();
String[] data = line.split(" ");
int sales = Integer.parseInt(data[1]) * Integer.parseInt(data[2]);
if (nico.containsKey(data[0]) == true) {
nico.put(data[0], nico.get(data[0]) + sales);
} else {
nico.put(data[0], sales);
}
}
boolean na = true;
for (String key : nico.keySet()) {
if (nico.get(key) >= 1000000) {
System.out.println(key);
na = false;
}
}
if (na == true)
System.out.println("NA");
lines = Integer.parseInt(sc.nextLine());
}
}
}
|
[["-", 36, 36, 0, 493, 0, 454, 0, 522, 141, 22], ["+", 36, 36, 0, 493, 0, 454, 0, 522, 141, 22], ["-", 0, 52, 8, 196, 0, 503, 39, 513, 0, 78], ["+", 0, 52, 8, 196, 0, 503, 39, 513, 0, 78], ["-", 0, 503, 49, 200, 51, 230, 39, 513, 0, 78], ["+", 0, 503, 49, 200, 51, 230, 39, 513, 0, 78]]
| 3
| 285
| 6
|
#include <stdio.h>
int main(int argc, char *argv[]) {
int n, f, i;
long long int ID, price, num;
long long int sum[4001];
int ln, list[4000];
while (1) {
scanf("%d ", &n);
if (!n)
break;
f = 0;
ln = 0;
for (i = 1; i < 4001; i++)
sum[i] = 0;
while (n--) {
scanf("%lld %lld %lld ", &ID, &price, &num);
sum[ID] += price * num;
list[ln++] = ID;
}
for (i = 0; i < ln; i++)
if (1000000 <= sum[list[i]]) {
printf("%dn", list[i]);
f = 1;
sum[list[i]] = 0;
}
if (!f)
printf("NAn");
}
return 0;
}
|
#include <stdio.h>
int main(int argc, char *argv[]) {
int n, f, i;
long long int ID, price, num;
long long int sum[4001];
int ln, list[4000];
while (1) {
scanf("%d ", &n);
if (!n)
break;
f = 0;
ln = 0;
for (i = 1; i < 4001; i++)
sum[i] = 0;
while (n--) {
scanf("%lld %lld %lld ", &ID, &price, &num);
sum[ID] += price * num;
list[ln++] = ID;
}
for (i = 0; i < ln; i++)
if (1000000 <= sum[list[i]]) {
printf("%d\n", list[i]);
f = 1;
sum[list[i]] = 0;
}
if (!f)
printf("NA\n");
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44], ["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 207
| 6
|
////#include <stdio.h>
////long long int n,a,b[100001],c[100001],num[100001]={},d[4001]={};
//// int i,j,x=0;
//// int sum=0;
//// int main(){
//// while(1){
//// scanf("%lld",&n);
//// if(n==0) break;
//// for(i=0;i<n;i++){
//// scanf("%lld %lld %lld",&a,&b[i],&c[i]);
//// d[a] += b[i]*c[i];
//// num[i]=a;
//// }
//// for(i=0;i<n;i++){
//// if(d[num[i]]>=1000000){
//// for(j=1;j<i;j++){
//// if(num[j]==num[i]){
//// x=1;
//// break;
//// }} if(x==0){
//// printf("%lld\n",a);
//// sum++;
//// }
//// }
//// }
//// if(sum==0){
//// printf("NA\n");
//// }
//// sum = 0;
//// for(i=1;i<=4000;i++){
//// d[i]=0;
//// }
//// }
//// return 0;
//// }
////
//#include <stdio.h>
// int main(void){
// int n,i,j,x,y,z,f,a[4000];
// long long t,b[4000];
// for(;scanf("%d",&n),n;f||puts("NA"))
// for(f=i=0;n--;){
// scanf("%d%d%d",&x,&y,&z);
// t=z;
// for(j=i;--j>=0&&a[j]-x;);
// if(j<0){a[j=i]=x;b[i++]=y*t;}
// else if(b[j]>=0)b[j]+=y*t;
// if(b[j]>=1000000)
// b[j]=f=-printf("%d\n",a[j]);
// }
// return 0;
//}
#include <stdio.h>
int main() {
int n, m, i;
long long int x, y, z;
long long int sum[4001];
int q, a[4000];
while (1) {
scanf("%d ", &n);
if (n == 0)
break;
m = 0;
q = 0;
for (i = 1; i < 4001; i++) {
sum[i] = 0;
}
while (n--) {
scanf("%lld %lld %lld ", &x, &y, &z);
sum[x] += y * z;
a[q] = x;
q++;
}
for (i = 0; i < n; i++)
if (1000000 <= sum[a[i]]) {
printf("%d\n", a[i]);
m = 1;
sum[a[i]] = 0;
}
if (m == 0)
printf("NA\n");
}
return 0;
}
|
////#include <stdio.h>
////long long int n,a,b[100001],c[100001],num[100001]={},d[4001]={};
//// int i,j,x=0;
//// int sum=0;
//// int main(){
//// while(1){
//// scanf("%lld",&n);
//// if(n==0) break;
//// for(i=0;i<n;i++){
//// scanf("%lld %lld %lld",&a,&b[i],&c[i]);
//// d[a] += b[i]*c[i];
//// num[i]=a;
//// }
//// for(i=0;i<n;i++){
//// if(d[num[i]]>=1000000){
//// for(j=1;j<i;j++){
//// if(num[j]==num[i]){
//// x=1;
//// break;
//// }} if(x==0){
//// printf("%lld\n",a);
//// sum++;
//// }
//// }
//// }
//// if(sum==0){
//// printf("NA\n");
//// }
//// sum = 0;
//// for(i=1;i<=4000;i++){
//// d[i]=0;
//// }
//// }
//// return 0;
//// }
////
//#include <stdio.h>
// int main(void){
// int n,i,j,x,y,z,f,a[4000];
// long long t,b[4000];
// for(;scanf("%d",&n),n;f||puts("NA"))
// for(f=i=0;n--;){
// scanf("%d%d%d",&x,&y,&z);
// t=z;
// for(j=i;--j>=0&&a[j]-x;);
// if(j<0){a[j=i]=x;b[i++]=y*t;}
// else if(b[j]>=0)b[j]+=y*t;
// if(b[j]>=1000000)
// b[j]=f=-printf("%d\n",a[j]);
// }
// return 0;
//}
#include <stdio.h>
int main() {
int n, m, i;
long long int x, y, z;
long long int sum[4001];
int q, a[4000];
while (1) {
scanf("%d ", &n);
if (n == 0)
break;
m = 0;
q = 0;
for (i = 1; i < 4001; i++) {
sum[i] = 0;
}
while (n--) {
scanf("%lld %lld %lld ", &x, &y, &z);
sum[x] += y * z;
a[q] = x;
q++;
}
for (i = 0; i < q; i++)
if (1000000 <= sum[a[i]]) {
printf("%d\n", a[i]);
m = 1;
sum[a[i]] = 0;
}
if (m == 0)
printf("NA\n");
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22]]
| 0
| 259
| 2
|
#include <iostream>
#include <map>
int main() {
int n;
while (std::cin >> n) {
if (n == 0)
break;
bool na = true;
std::map<int, long long> id_sales_map;
for (int i = 0; i < n; ++i) {
int ID;
long long price, number;
std::cin >> ID >> price >> number;
if (id_sales_map[ID] < 1000000) {
id_sales_map[ID] += price * number;
if (id_sales_map[ID] >= 1000000) {
std::cout << ID << std::endl;
na = true;
}
}
}
if (na) {
std::cout << "NA" << std::endl;
}
}
return 0;
}
|
#include <iostream>
#include <map>
int main() {
int n;
while (std::cin >> n) {
if (n == 0)
break;
bool na = true;
std::map<int, long long> id_sales_map;
for (int i = 0; i < n; ++i) {
int ID;
long long price, number;
std::cin >> ID >> price >> number;
if (id_sales_map[ID] < 1000000) {
id_sales_map[ID] += price * number;
if (id_sales_map[ID] >= 1000000) {
std::cout << ID << std::endl;
na = false;
}
}
}
if (na) {
std::cout << "NA" << std::endl;
}
}
return 0;
}
|
[["-", 0, 57, 64, 9, 0, 1, 0, 11, 12, 146], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 147]]
| 1
| 148
| 2
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, id, val, num, cnt;
int member[4000];
int index[4000];
while (cin >> n) {
if (!n)
break;
cnt = 0;
memset(member, -1, sizeof(member));
memset(index, -1, sizeof(index));
for (int i = 0; i < n; ++i) {
cin >> id >> val >> num;
if (member[id - 1] == -1) {
index[cnt] = id - 1;
++cnt;
member[id - 1] += 1 + val * num;
} else {
member[id - 1] += val * num;
}
}
bool flag = false;
for (int i = 0; i < cnt; ++i) {
if (member[index[i]] >= 1000000) {
cout << index[i] + 1 << endl;
flag = true;
}
}
if (!flag)
cout << "NA" << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, id, val, num, cnt;
long long member[4000];
int index[4000];
while (cin >> n) {
if (!n)
break;
cnt = 0;
memset(member, -1, sizeof(member));
memset(index, -1, sizeof(index));
for (int i = 0; i < n; ++i) {
cin >> id >> val >> num;
if (member[id - 1] == -1) {
index[cnt] = id - 1;
++cnt;
member[id - 1] += 1 + val * num;
} else {
member[id - 1] += val * num;
}
}
bool flag = false;
for (int i = 0; i < cnt; ++i) {
if (member[index[i]] >= 1000000) {
cout << index[i] + 1 << endl;
flag = true;
}
}
if (!flag)
cout << "NA" << endl;
}
}
|
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96]]
| 1
| 217
| 6
|
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int main(void) {
int n;
while (1) {
cin >> n;
if (n == 0)
break;
int c[4001] = {}, id[10000000];
for (int i = 0; i < n; i++) {
int p, q;
cin >> id[i] >> p >> q;
c[id[i]] += p * q;
}
bool f = 1;
for (int i = 0; i < n; i++) {
if (c[id[i]] >= 1000000) {
cout << id[i] << endl;
c[id[i]] = 0;
f = 0;
}
}
if (f)
cout << "NA" << endl;
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int main(void) {
int n;
while (1) {
cin >> n;
if (n == 0)
break;
long int c[4001] = {};
int id[100000];
for (int i = 0; i < n; i++) {
long int p, q;
cin >> id[i] >> p >> q;
c[id[i]] += p * q;
}
bool f = 1;
for (int i = 0; i < n; i++) {
if (c[id[i]] >= 1000000) {
cout << id[i] << endl;
c[id[i]] = 0;
f = 0;
}
}
if (f)
cout << "NA" << endl;
}
return 0;
}
|
[["+", 0, 52, 8, 9, 0, 43, 39, 86, 0, 96], ["-", 8, 9, 0, 52, 8, 9, 0, 43, 0, 21], ["+", 8, 9, 0, 52, 8, 9, 0, 43, 0, 35], ["+", 8, 9, 0, 52, 8, 9, 0, 43, 39, 40], ["-", 0, 52, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 7, 8, 9, 0, 43, 39, 86, 0, 96]]
| 1
| 169
| 7
|
#include <iostream>
#include <string>
using namespace std;
long long a[5000];
bool check[5000];
int main() {
int n;
while (true) {
cin >> n;
if (n == 0)
break;
for (int i = 0; i < 5000; i++) {
a[i] = 0;
check[i] = true;
}
bool na = true;
long long b, c, d;
for (int i = 0; i < n; i++) {
cin >> b >> c >> d;
a[b] += c * d;
if (a[b] >= 1000000 && check[b] == true) {
check[b - 1] = false;
na = false;
cout << b << endl;
}
}
if (na == true)
cout << "NA" << endl;
}
return 0;
}
|
#include <iostream>
#include <string>
using namespace std;
long long a[5000];
bool check[5000];
int main() {
int n;
while (true) {
cin >> n;
if (n == 0)
break;
for (int i = 0; i < 5000; i++) {
a[i] = 0;
check[i] = true;
}
bool na = true;
long long b, c, d;
for (int i = 0; i < n; i++) {
cin >> b >> c >> d;
a[b] += c * d;
if (a[b] >= 1000000 && check[b] == true) {
check[b] = false;
na = false;
cout << b << endl;
}
}
if (na == true)
cout << "NA" << endl;
}
return 0;
}
|
[["-", 0, 11, 31, 69, 341, 342, 0, 16, 17, 33], ["-", 0, 11, 31, 69, 341, 342, 0, 16, 12, 13]]
| 1
| 178
| 2
|
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
int n;
while (cin >> n && n) {
map<int, int> mp;
vector<int> v;
for (int i = 0; i < n; i++) {
int e, p, q;
cin >> e >> p >> q;
if (!mp[e])
v.push_back(e);
mp[e] += p * q;
}
bool flg = false;
for (int i = 0; i < v.size(); i++) {
if (mp[v[i]] >= 1000000) {
flg = true;
cout << v[i] << endl;
} else if (!flg) {
cout << "NA" << endl;
}
}
}
return 0;
}
|
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
int n;
while (cin >> n && n) {
map<int, int> mp;
vector<int> v;
for (int i = 0; i < n; i++) {
int e, p, q;
cin >> e >> p >> q;
if (!mp[e])
v.push_back(e);
mp[e] += p * q;
}
bool flg = false;
for (int i = 0; i < v.size(); i++) {
if (mp[v[i]] >= 1000000) {
flg = true;
cout << v[i] << endl;
}
}
if (!flg) {
cout << "NA" << endl;
}
}
return 0;
}
|
[["-", 0, 7, 8, 9, 0, 57, 75, 76, 0, 95], ["+", 0, 52, 8, 9, 0, 7, 8, 9, 0, 46], ["-", 0, 57, 75, 76, 0, 57, 64, 9, 0, 46]]
| 1
| 169
| 3
|
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int H;
int W[100];
int G[100][100];
int dp[100][100];
int solve() {
dp[0][0] = G[0][0];
for (int i = 1; i < H; ++i) {
for (int j = 0; j < W[i]; ++j) {
if (i <= H / 2 + 1) {
dp[i][j] = dp[i - 1][j] + G[i][j];
if (j - 1 >= 0)
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + G[i][j]);
} else {
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j + 1]) + G[i][j];
}
}
}
return dp[H - 1][0];
}
int main() {
H = 0;
string line;
while (getline(cin, line)) {
W[H] = 0;
replace(line.begin(), line.end(), ',', ' ');
stringstream ss;
ss << line;
while (ss >> G[H][W[H]])
++W[H];
++H;
}
cout << solve() << endl;
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int H;
int W[100];
int G[100][100];
int dp[100][100];
int solve() {
dp[0][0] = G[0][0];
for (int i = 1; i < H; ++i) {
for (int j = 0; j < W[i]; ++j) {
if (i <= H / 2) {
dp[i][j] = dp[i - 1][j] + G[i][j];
if (j - 1 >= 0)
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + G[i][j]);
} else {
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j + 1]) + G[i][j];
}
}
}
return dp[H - 1][0];
}
int main() {
H = 0;
string line;
while (getline(cin, line)) {
W[H] = 0;
replace(line.begin(), line.end(), ',', ' ');
stringstream ss;
ss << line;
while (ss >> G[H][W[H]])
++W[H];
++H;
}
cout << solve() << endl;
return 0;
}
|
[["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 72], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
| 1
| 332
| 2
|
import sys
s=[list(map(int,e.split(',')))for e in sys.stdin]
for i in range(1,len(s)):
for j in range(len(s[i])):
t=j-len(s[i])>len(s[i-1])
s[i][j]+=max(s[i-1][t*(j>0):t+2])
print(*s[-1])
|
import sys
s=[list(map(int,e.split(',')))for e in sys.stdin]
for i in range(1,len(s)):
for j in range(len(s[i])):
t=j-(len(s[i])>len(s[i-1]))
s[i][j]+=max(s[i-1][t*(j>0):t+2])
print(*s[-1])
|
[["+", 0, 1, 0, 662, 12, 657, 12, 23, 0, 24], ["+", 12, 23, 0, 666, 0, 652, 3, 4, 0, 25]]
| 5
| 115
| 21
|
def mx(p,w,h,l):
if h <= c/2:
if w == 0: p[h][w] += p[h-1][w]
elif w == l-1: p[h][w] += p[h-1][w-1]
else: p[h][w] += max(p[h-1][w],p[h-1][w-1])
else:
p[h][w] += max(p[h-1][w],p[h-1][w+1])
return p
c = 0
p = []
while True:
try:
p.append(list(map(int, raw_put().split(","))))
c += 1
except:
break
for h in range(1,c):
l = len(p[h])
for w in range(l):
p = mx(p,w,h,l)
print(p[c-1][0])
|
def mx(p,w,h,l):
if h <= c/2:
if w == 0: p[h][w] += p[h-1][w]
elif w == l-1: p[h][w] += p[h-1][w-1]
else: p[h][w] += max(p[h-1][w],p[h-1][w-1])
else:
p[h][w] += max(p[h-1][w],p[h-1][w+1])
return p
c = 0
p = []
while True:
try:
p.append(list(map(int, input().split(","))))
c += 1
except:
break
for h in range(1,c):
l = len(p[h])
for w in range(l):
p = mx(p,w,h,l)
print(p[c-1][0])
|
[["-", 3, 4, 0, 652, 63, 319, 500, 652, 63, 22], ["+", 3, 4, 0, 652, 63, 319, 500, 652, 63, 22]]
| 5
| 229
| 2
|
import java.io.IOException;
import java.util.InputMismatchException;
public class Main {
double EPS = 1e-10;
int n;
Circle[] c;
class Point {
double x, y;
Point(double x, double y) {
this.x = x;
this.y = y;
}
}
class Circle {
Point c;
double r;
Circle(Point c, double r) {
this.c = c;
this.r = r;
}
}
double norm(Point a) { return Math.hypot(a.x, a.y); }
Point sub(Point a, Point b) { return new Point(a.x - b.x, a.y - b.y); }
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; }
double abs(double a) { return 0 < a ? a : -a; }
Point[] crossPoint(Circle c1, Circle c2) {
double d = norm(sub(c1.c, c2.c));
if (d < EPS && abs(c1.r - c2.r) < EPS) {
return null;
} else if (c1.r + c2.r < d - EPS || d + EPS < abs(c1.r - c2.r)) {
return null;
} else {
double a = (c1.r * c1.r - c2.r * c2.r + d * d) / (2 * d);
double h = Math.sqrt(Math.max(c1.r * c1.r - a * a, 0));
Point p1 = new Point(c1.c.x + a / d * (c2.c.x - c1.c.x),
c1.c.y + a / d * (c2.c.y - c1.c.y));
Point p2 =
new Point(h / d * (c2.c.x - c1.c.x), h / d * (c2.c.y - c1.c.y));
if (norm(p2) < EPS) {
return new Point[] {p1};
} else {
return new Point[] {new Point(p1.x - p2.y, p1.y + p2.x),
new Point(p1.x + p2.y, p1.y - p2.x)};
}
}
}
boolean isCover(Circle c, Point p) { return norm(sub(c.c, p)) <= c.r; }
void run() {
MyScanner sc = new MyScanner();
while (true) {
n = sc.nextInt();
if (n == 0) {
break;
}
c = new Circle[n];
for (int i = 0; i < n; i++) {
String[] s = sc.next().split(",");
double x = Double.parseDouble(s[0]);
double y = Double.parseDouble(s[1]);
c[i] = new Circle(new Point(x, y), 1.);
}
int max = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
Point[] cp = crossPoint(c[i], c[j]);
if (cp == null)
continue;
for (int k = 0; k < cp.length; k++) {
int cnt = 0;
for (int l = 0; l < n; l++) {
if (isCover(c[l], cp[k])) {
cnt++;
}
}
max = Math.max(max, cnt);
}
}
}
System.out.println(max);
}
}
public static void main(String[] args) { new Main().run(); }
public void mapDebug(int[][] a) {
System.out.println("--------map display---------");
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[i].length; j++) {
System.out.printf("%3d ", a[i][j]);
}
System.out.println();
}
System.out.println("----------------------------" + '\n');
}
class MyScanner {
int read() {
try {
return System.in.read();
} catch (IOException e) {
throw new InputMismatchException();
}
}
boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
boolean isEndline(int c) { return c == '\n' || c == '\r' || c == -1; }
int nextInt() { return Integer.parseInt(next()); }
int[] nextIntArray(int n) {
int[] array = new int[n];
for (int i = 0; i < n; i++)
array[i] = nextInt();
return array;
}
long nextLong() { return Long.parseLong(next()); }
long[] nextLongArray(int n) {
long[] array = new long[n];
for (int i = 0; i < n; i++)
array[i] = nextLong();
return array;
}
double nextDouble() { return Double.parseDouble(next()); }
double[] nextDoubleArray(int n) {
double[] array = new double[n];
for (int i = 0; i < n; i++)
array[i] = nextDouble();
return array;
}
String next() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
String[] nextStringArray(int n) {
String[] array = new String[n];
for (int i = 0; i < n; i++)
array[i] = next();
return array;
}
String nextLine() {
int c = read();
while (isEndline(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndline(c));
return res.toString();
}
}
}
|
import java.io.IOException;
import java.util.InputMismatchException;
public class Main {
double EPS = 1e-10;
int n;
Circle[] c;
class Point {
double x, y;
Point(double x, double y) {
this.x = x;
this.y = y;
}
}
class Circle {
Point c;
double r;
Circle(Point c, double r) {
this.c = c;
this.r = r;
}
}
double norm(Point a) { return Math.hypot(a.x, a.y); }
Point sub(Point a, Point b) { return new Point(a.x - b.x, a.y - b.y); }
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; }
double abs(double a) { return 0 < a ? a : -a; }
Point[] crossPoint(Circle c1, Circle c2) {
double d = norm(sub(c1.c, c2.c));
if (d < EPS && abs(c1.r - c2.r) < EPS) {
return null;
} else if (c1.r + c2.r < d - EPS || d + EPS < abs(c1.r - c2.r)) {
return null;
} else {
double a = (c1.r * c1.r - c2.r * c2.r + d * d) / (2 * d);
double h = Math.sqrt(Math.max(c1.r * c1.r - a * a, 0));
Point p1 = new Point(c1.c.x + a / d * (c2.c.x - c1.c.x),
c1.c.y + a / d * (c2.c.y - c1.c.y));
Point p2 =
new Point(h / d * (c2.c.x - c1.c.x), h / d * (c2.c.y - c1.c.y));
if (norm(p2) < EPS) {
return new Point[] {p1};
} else {
return new Point[] {new Point(p1.x - p2.y, p1.y + p2.x),
new Point(p1.x + p2.y, p1.y - p2.x)};
}
}
}
boolean isCover(Circle c, Point p) { return norm(sub(c.c, p)) <= c.r + EPS; }
void run() {
MyScanner sc = new MyScanner();
while (true) {
n = sc.nextInt();
if (n == 0) {
break;
}
c = new Circle[n];
for (int i = 0; i < n; i++) {
String[] s = sc.next().split(",");
double x = Double.parseDouble(s[0]);
double y = Double.parseDouble(s[1]);
c[i] = new Circle(new Point(x, y), 1.);
}
int max = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
Point[] cp = crossPoint(c[i], c[j]);
if (cp == null)
continue;
for (int k = 0; k < cp.length; k++) {
int cnt = 0;
for (int l = 0; l < n; l++) {
if (isCover(c[l], cp[k])) {
cnt++;
}
}
max = Math.max(max, cnt);
}
}
}
System.out.println(max);
}
}
public static void main(String[] args) { new Main().run(); }
public void mapDebug(int[][] a) {
System.out.println("--------map display---------");
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[i].length; j++) {
System.out.printf("%3d ", a[i][j]);
}
System.out.println();
}
System.out.println("----------------------------" + '\n');
}
class MyScanner {
int read() {
try {
return System.in.read();
} catch (IOException e) {
throw new InputMismatchException();
}
}
boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
boolean isEndline(int c) { return c == '\n' || c == '\r' || c == -1; }
int nextInt() { return Integer.parseInt(next()); }
int[] nextIntArray(int n) {
int[] array = new int[n];
for (int i = 0; i < n; i++)
array[i] = nextInt();
return array;
}
long nextLong() { return Long.parseLong(next()); }
long[] nextLongArray(int n) {
long[] array = new long[n];
for (int i = 0; i < n; i++)
array[i] = nextLong();
return array;
}
double nextDouble() { return Double.parseDouble(next()); }
double[] nextDoubleArray(int n) {
double[] array = new double[n];
for (int i = 0; i < n; i++)
array[i] = nextDouble();
return array;
}
String next() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
String[] nextStringArray(int n) {
String[] array = new String[n];
for (int i = 0; i < n; i++)
array[i] = next();
return array;
}
String nextLine() {
int c = read();
while (isEndline(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndline(c));
return res.toString();
}
}
}
|
[["+", 8, 196, 0, 37, 0, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 37, 0, 16, 12, 16, 12, 22], ["-", 0, 52, 8, 196, 0, 503, 49, 200, 51, 499], ["+", 0, 52, 8, 196, 0, 503, 49, 200, 51, 499]]
| 3
| 1,415
| 4
|
import java.awt.geom.Point2D;
import java.io.*;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
FastScanner sc = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
while (true) {
int n = sc.nextInt();
if (n == 0)
break;
Point2D.Double[] list = new Point2D.Double[n];
for (int i = 0; i < n; i++) {
String tmp[] = sc.next().split(",");
list[i] = new Point2D.Double(Double.parseDouble(tmp[0]),
Double.parseDouble(tmp[1]));
}
int max = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
Point2D.Double[] tmp = CircleCross.getCross(list[i], list[j]);
if (tmp != null)
for (int k = 0; k < tmp.length; k++) {
int count = 0;
for (int l = 0; l < n; l++) {
if (Point2D.Double.distance(tmp[k].getX(), tmp[k].getY(),
list[l].getX(), list[l].getY()) -
1.0 <=
10e-6) {
count++;
}
}
if (count > max) {
max = count;
}
}
}
}
out.println(max);
}
out.flush();
}
}
//------------------------------//
//-----------//
class FastScanner {
private final InputStream in = System.in;
private final byte[] buffer = new byte[1024];
private int ptr = 0;
private int buflen = 0;
private boolean hasNextByte() {
if (ptr < buflen) {
return true;
} else {
ptr = 0;
try {
buflen = in.read(buffer);
} catch (IOException e) {
e.printStackTrace();
}
if (buflen <= 0) {
return false;
}
}
return true;
}
private int readByte() {
if (hasNextByte())
return buffer[ptr++];
else
return -1;
}
private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126; }
private void skipUnprintable() {
while (hasNextByte() && !isPrintableChar(buffer[ptr]))
ptr++;
}
public boolean hasNext() {
skipUnprintable();
return hasNextByte();
}
public String next() {
if (!hasNext())
throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = readByte();
while (isPrintableChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public long nextLong() {
if (!hasNext())
throw new NoSuchElementException();
long n = 0;
boolean minus = false;
int b = readByte();
if (b == '-') {
minus = true;
b = readByte();
}
if (b < '0' || '9' < b) {
throw new NumberFormatException();
}
while (true) {
if ('0' <= b && b <= '9') {
n *= 10;
n += b - '0';
} else if (b == -1 || !isPrintableChar(b)) {
return minus ? -n : n;
} else {
throw new NumberFormatException();
}
b = readByte();
}
}
public int nextInt() { return (int)nextLong(); }
public double nextDouble() { return Double.parseDouble(next()); }
}
class CircleCross {
static double DIF = 10e-6;
public static Point2D.Double[] getCross(Point2D.Double p1,
Point2D.Double p2) {
Point2D.Double[] cRet = null;
if (p1 != null && p2 != null) {
double length = p1.distance(p2);
if (length <= DIF) {
cRet = new Point2D.Double[1];
cRet[0] = new Point2D.Double(p1.x, p1.y);
} else if (length <= 2.0 + DIF) {
double theta = Math.atan2(p2.y - p1.y, p2.x - p1.x);
double alpha = Math.acos(length / 2.0);
cRet = new Point2D.Double[2];
cRet[0] = new Point2D.Double(p1.x + Math.cos(theta + alpha),
p1.y + Math.sin(theta + alpha));
cRet[1] = new Point2D.Double(p1.x + Math.cos(theta - alpha),
p1.y + Math.sin(theta - alpha));
}
}
return cRet;
}
}
|
import java.awt.geom.Point2D;
import java.io.*;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
FastScanner sc = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
while (true) {
int n = sc.nextInt();
if (n == 0)
break;
Point2D.Double[] list = new Point2D.Double[n];
for (int i = 0; i < n; i++) {
String tmp[] = sc.next().split(",");
list[i] = new Point2D.Double(Double.parseDouble(tmp[0]),
Double.parseDouble(tmp[1]));
}
int max = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
Point2D.Double[] tmp = CircleCross.getCross(list[i], list[j]);
if (tmp != null)
for (int k = 0; k < tmp.length; k++) {
int count = 0;
for (int l = 0; l < n; l++) {
if (Point2D.Double.distance(tmp[k].getX(), tmp[k].getY(),
list[l].getX(), list[l].getY()) -
1.0 <=
10e-6) {
count++;
}
}
if (count > max) {
max = count;
}
}
}
}
out.println(max);
}
out.flush();
}
}
//------------------------------//
//-----------//
class FastScanner {
private final InputStream in = System.in;
private final byte[] buffer = new byte[1024];
private int ptr = 0;
private int buflen = 0;
private boolean hasNextByte() {
if (ptr < buflen) {
return true;
} else {
ptr = 0;
try {
buflen = in.read(buffer);
} catch (IOException e) {
e.printStackTrace();
}
if (buflen <= 0) {
return false;
}
}
return true;
}
private int readByte() {
if (hasNextByte())
return buffer[ptr++];
else
return -1;
}
private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126; }
private void skipUnprintable() {
while (hasNextByte() && !isPrintableChar(buffer[ptr]))
ptr++;
}
public boolean hasNext() {
skipUnprintable();
return hasNextByte();
}
public String next() {
if (!hasNext())
throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = readByte();
while (isPrintableChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public long nextLong() {
if (!hasNext())
throw new NoSuchElementException();
long n = 0;
boolean minus = false;
int b = readByte();
if (b == '-') {
minus = true;
b = readByte();
}
if (b < '0' || '9' < b) {
throw new NumberFormatException();
}
while (true) {
if ('0' <= b && b <= '9') {
n *= 10;
n += b - '0';
} else if (b == -1 || !isPrintableChar(b)) {
return minus ? -n : n;
} else {
throw new NumberFormatException();
}
b = readByte();
}
}
public int nextInt() { return (int)nextLong(); }
public double nextDouble() { return Double.parseDouble(next()); }
}
class CircleCross {
static double DIF = 10e-6;
public static Point2D.Double[] getCross(Point2D.Double p1,
Point2D.Double p2) {
Point2D.Double[] cRet = null;
if (p1 != null && p2 != null) {
double length = p1.distance(p2);
if (length <= DIF) {
cRet = new Point2D.Double[1];
cRet[0] = new Point2D.Double(p1.x, p1.y);
} else if (length <= 2.0 + DIF) {
double theta = Math.atan2(p2.y - p1.y, p2.x - p1.x);
double alpha = Math.acos(length / 2.0);
cRet = new Point2D.Double[2];
cRet[0] = new Point2D.Double(p1.x + Math.cos(theta + alpha),
p1.y + Math.sin(theta + alpha));
cRet[1] = new Point2D.Double(p1.x + Math.cos(theta - alpha),
p1.y + Math.sin(theta - alpha));
}
}
return cRet;
}
}
|
[["-", 0, 7, 502, 503, 49, 200, 51, 16, 31, 22], ["-", 0, 7, 502, 503, 49, 200, 51, 16, 17, 72], ["-", 0, 7, 502, 503, 49, 200, 51, 16, 12, 499], ["+", 8, 196, 0, 7, 502, 503, 49, 200, 51, 499]]
| 3
| 1,075
| 4
|
import java.util.Scanner;
public class Main {
private Scanner sc;
public static void main(String[] args) { new Main(); }
public Main() {
sc = new Scanner(System.in);
while (sc.hasNextLine()) {
int lines = Integer.parseInt(sc.nextLine());
if (lines == 0)
break;
double[] x = new double[lines];
double[] y = new double[lines];
for (int i = 0; i < lines; i++) {
String[] nico = sc.nextLine().split(",");
x[i] = Double.parseDouble(nico[0]);
y[i] = Double.parseDouble(nico[1]);
}
int max = 1;
for (int i = 0; i < lines; i++) {
for (int j = (i + 1); j < lines; j++) {
double d = calc(x[i], x[j], y[i], y[j]);
if (d > 4.0)
continue;
double[] px = new double[1];
double[] py = new double[1];
if ((x[i] == x[j]) && (y[i] == y[j])) {
px[0] = x[i];
py[0] = y[i];
} else {
double cr = Math.atan2(-(y[j] - y[i]), (x[j] - x[i]));
double dr = Math.atan2(Math.sqrt(1 - (d / (2.0 * 2.0))),
(Math.sqrt(d) / 2.0));
px = new double[2];
py = new double[2];
px[0] = x[i] + Math.cos(cr - dr);
py[0] = y[i] - Math.sin(cr - dr);
px[1] = x[i] + Math.cos(cr + dr);
py[1] = y[i] - Math.sin(cr + dr);
}
for (int p = 0; p < px.length; p++) {
int tmp = 0;
for (int k = 0; k < lines; k++) {
if (calc(px[p], x[k], py[p], y[k]) <= 1.0)
tmp++;
}
if (max < tmp)
max = tmp;
}
}
}
System.out.println(max);
}
}
public double calc(double x0, double x1, double y0, double y1) {
return ((x0 - x1) * (x0 - x1) + (y0 - y1) * (y0 - y1));
}
}
|
import java.util.Scanner;
public class Main {
private Scanner sc;
public static void main(String[] args) { new Main(); }
public Main() {
sc = new Scanner(System.in);
while (sc.hasNextLine()) {
int lines = Integer.parseInt(sc.nextLine());
if (lines == 0)
break;
double[] x = new double[lines];
double[] y = new double[lines];
for (int i = 0; i < lines; i++) {
String[] nico = sc.nextLine().split(",");
x[i] = Double.parseDouble(nico[0]);
y[i] = Double.parseDouble(nico[1]);
}
int max = 1;
for (int i = 0; i < lines; i++) {
for (int j = (i + 1); j < lines; j++) {
double d = calc(x[i], x[j], y[i], y[j]);
if (d > 4.0)
continue;
double[] px = new double[1];
double[] py = new double[1];
if ((x[i] == x[j]) && (y[i] == y[j])) {
px[0] = x[i];
py[0] = y[i];
} else {
double cr = Math.atan2(-(y[j] - y[i]), (x[j] - x[i]));
double dr = Math.atan2(Math.sqrt(1.0 - (d / (2.0 * 2.0))),
(Math.sqrt(d) / 2.0));
px = new double[2];
py = new double[2];
px[0] = x[i] + Math.cos(cr - dr);
py[0] = y[i] - Math.sin(cr - dr);
px[1] = x[i] + Math.cos(cr + dr);
py[1] = y[i] - Math.sin(cr + dr);
}
for (int p = 0; p < px.length; p++) {
int tmp = 0;
for (int k = 0; k < lines; k++) {
if (calc(px[p], x[k], py[p], y[k]) < 1.1)
tmp++;
}
if (max < tmp)
max = tmp;
}
}
}
System.out.println(max);
}
}
public double calc(double x0, double x1, double y0, double y1) {
return ((x0 - x1) * (x0 - x1) + (y0 - y1) * (y0 - y1));
}
}
|
[["-", 3, 4, 0, 492, 3, 4, 0, 16, 31, 499], ["+", 3, 4, 0, 492, 3, 4, 0, 16, 31, 515], ["-", 8, 196, 0, 57, 15, 15, 0, 16, 17, 19], ["-", 8, 196, 0, 57, 15, 15, 0, 16, 12, 515], ["+", 8, 196, 0, 57, 15, 15, 0, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 15, 0, 16, 12, 515]]
| 3
| 609
| 6
|
import java.util.Arrays;
import java.util.Scanner;
// Overlaps of Seals
public class Main {
static class P {
public double x, y;
public P(double x, double y) {
this.x = x;
this.y = y;
}
}
static class R implements Comparable<R> {
public double minx, maxx, miny, maxy;
public P[] p;
public int prob;
boolean[] mark;
public R(boolean[] u, double minx, double maxx, double miny, double maxy) {
this.minx = minx;
this.maxx = maxx;
this.miny = miny;
this.maxy = maxy;
p = new P[4];
p[0] = new P(minx, miny);
p[1] = new P(minx, maxy);
p[2] = new P(maxx, miny);
p[3] = new P(maxx, maxy);
mark = new boolean[n];
prob = 0;
for (int i = 0; i < n; i++) {
// if(u[i]){
if (minx <= seal[i].x && seal[i].x <= max && miny - 1 <= seal[i].y &&
seal[i].y <= maxy + 1) {
mark[i] = true;
prob++;
} else if (minx - 1 <= seal[i].x && seal[i].x <= maxx + 1 &&
miny <= seal[i].y && seal[i].y <= maxy) {
mark[i] = true;
prob++;
} else {
boolean f = false;
for (int j = 0; j < 4; j++) {
if (Math.hypot(seal[i].x - p[j].x, seal[i].y - p[j].y) <= 1) {
f = true;
break;
}
}
if (f) {
mark[i] = true;
prob++;
}
}
// }
}
}
public void find() {
// System.out.println("FIND MAX: " + max);
// if(minx<=2.3 && 2.3<=maxx &&
//miny<=4.6&&4.6<=maxy) System.out.println("PROB FIND:" + prob + " MAX: "
//+ max);
if (prob <= max)
return;
if (maxx - minx < 0.000001) {
// System.out.println("PROB:" + prob);
max = Math.max(max, prob);
return;
}
R[] r = new R[4];
double midx = (minx + maxx) / 2;
double midy = (miny + maxy) / 2;
r[0] = new R(mark, minx, midx, miny, midy);
r[1] = new R(mark, midx, maxx, miny, midy);
r[2] = new R(mark, minx, midx, midy, maxy);
r[3] = new R(mark, midx, maxx, midy, maxy);
Arrays.sort(r);
for (int i = 0; i < 4; i++)
r[i].find();
}
public int compareTo(R o) { return o.prob - prob; }
}
static int n;
static int max;
static P[] seal;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true) {
n = sc.nextInt();
if (n == 0)
break;
seal = new P[n];
for (int i = 0; i < n; i++) {
String[] s = sc.next().split(",");
seal[i] = new P(Double.parseDouble(s[0]), Double.parseDouble(s[1]));
}
boolean[] u = new boolean[n];
Arrays.fill(u, true);
max = 0;
R r = new R(u, 0, 10, 0, 10);
r.find();
System.out.println(max);
}
}
}
|
import java.util.Arrays;
import java.util.Scanner;
// Overlaps of Seals
public class Main {
static class P {
public double x, y;
public P(double x, double y) {
this.x = x;
this.y = y;
}
}
static class R implements Comparable<R> {
public double minx, maxx, miny, maxy;
public P[] p;
public int prob;
boolean[] mark;
public R(boolean[] u, double minx, double maxx, double miny, double maxy) {
this.minx = minx;
this.maxx = maxx;
this.miny = miny;
this.maxy = maxy;
p = new P[4];
p[0] = new P(minx, miny);
p[1] = new P(minx, maxy);
p[2] = new P(maxx, miny);
p[3] = new P(maxx, maxy);
mark = new boolean[n];
prob = 0;
for (int i = 0; i < n; i++) {
// if(u[i]){
if (minx <= seal[i].x && seal[i].x <= maxx && miny - 1 <= seal[i].y &&
seal[i].y <= maxy + 1) {
mark[i] = true;
prob++;
} else if (minx - 1 <= seal[i].x && seal[i].x <= maxx + 1 &&
miny <= seal[i].y && seal[i].y <= maxy) {
mark[i] = true;
prob++;
} else {
boolean f = false;
for (int j = 0; j < 4; j++) {
if (Math.hypot(seal[i].x - p[j].x, seal[i].y - p[j].y) <= 1) {
f = true;
break;
}
}
if (f) {
mark[i] = true;
prob++;
}
}
// }
}
}
public void find() {
// System.out.println("FIND MAX: " + max);
// if(minx<=2.3 && 2.3<=maxx &&
//miny<=4.6&&4.6<=maxy) System.out.println("PROB FIND:" + prob + " MAX: "
//+ max);
if (prob <= max)
return;
if (maxx - minx < 0.000001) {
// System.out.println("PROB:" + prob);
max = Math.max(max, prob);
return;
}
R[] r = new R[4];
double midx = (minx + maxx) / 2;
double midy = (miny + maxy) / 2;
r[0] = new R(mark, minx, midx, miny, midy);
r[1] = new R(mark, midx, maxx, miny, midy);
r[2] = new R(mark, minx, midx, midy, maxy);
r[3] = new R(mark, midx, maxx, midy, maxy);
Arrays.sort(r);
for (int i = 0; i < 4; i++)
r[i].find();
}
public int compareTo(R o) { return o.prob - prob; }
}
static int n;
static int max;
static P[] seal;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true) {
n = sc.nextInt();
if (n == 0)
break;
seal = new P[n];
for (int i = 0; i < n; i++) {
String[] s = sc.next().split(",");
seal[i] = new P(Double.parseDouble(s[0]), Double.parseDouble(s[1]));
}
boolean[] u = new boolean[n];
Arrays.fill(u, true);
max = 0;
R r = new R(u, 0, 10, 0, 10);
r.find();
System.out.println(max);
}
}
}
|
[["-", 0, 16, 31, 16, 31, 16, 12, 16, 12, 22], ["+", 0, 16, 31, 16, 31, 16, 12, 16, 12, 22]]
| 3
| 803
| 2
|
import java.awt.geom.Point2D;
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++) {
String[] s = sc.next().split(",");
double u = Double.valueOf(s[0]);
double v = Double.valueOf(s[1]);
p[i] = new Point2D.Double(u, v);
}
int max = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (p[i].distance(p[j]) <= 2.00001) {
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 s = 0; s < 2; s++) {
int cnt = 0;
for (int t = 0; t < n; t++) {
if (p[t].distance(x[s], y[s]) <= 1.00001)
cnt++;
}
max = Math.max(max, cnt);
}
}
}
}
System.out.println(max);
}
}
}
|
import java.awt.geom.Point2D;
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++) {
String[] s = sc.next().split(",");
double u = Double.valueOf(s[0]);
double v = Double.valueOf(s[1]);
p[i] = new Point2D.Double(u, v);
}
int max = 1;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (p[i].distance(p[j]) <= 2.00001) {
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 s = 0; s < 2; s++) {
int cnt = 0;
for (int t = 0; t < n; t++) {
if (p[t].distance(x[s], y[s]) <= 1.00001)
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
| 752
| 2
|
#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
| 6
|
#include <math.h>
#include <stdio.h>
int main() {
double x[100], y[100];
double A, h, c, X, Y;
int n, i, j, k, m, M;
while (scanf("%d", &n), n) {
M = 0;
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 = hypot(x[i] - x[j], y[i] - y[j]) / 2;
if (A <= 1) {
c = atan2(y[i] - y[j], x[i] - x[j]);
h = sqrt(1 - A * A);
X = x[j] + A * cos(c) - h * sin(c);
Y = y[j] + A * sin(c) + h * cos(c);
for (m = 0, k = 0; k < n; k++) {
if (k != i && k != j)
if (hypot(X - x[k], Y - y[k]) <= 1)
m++;
}
if (m > M)
M = m;
X = x[j] + A * cos(c) + h * sin(c);
Y = y[j] + A * sin(c) - h * cos(c);
for (m = 0, k = 0; k < n; k++) {
if (k != i && k != j)
if (hypot(X - x[k], Y - y[k]) <= 1)
m++;
}
if (m > M)
M = m;
}
}
}
printf("%d\n", M + 2);
}
return 0;
}
|
#include <math.h>
#include <stdio.h>
int main() {
double x[100], y[100];
double A, h, c, X, Y;
int n, i, j, k, m, M;
while (scanf("%d", &n), n) {
M = -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 = hypot(x[i] - x[j], y[i] - y[j]) / 2;
if (A <= 1) {
c = atan2(y[i] - y[j], x[i] - x[j]);
h = sqrt(1 - A * A);
X = x[j] + A * cos(c) - h * sin(c);
Y = y[j] + A * sin(c) + h * cos(c);
for (m = 0, k = 0; k < n; k++) {
if (k != i && k != j)
if (hypot(X - x[k], Y - y[k]) <= 1)
m++;
}
if (m > M)
M = m;
X = x[j] + A * cos(c) + h * sin(c);
Y = y[j] + A * sin(c) - h * cos(c);
for (m = 0, k = 0; k < n; k++) {
if (k != i && k != j)
if (hypot(X - x[k], Y - y[k]) <= 1)
m++;
}
if (m > M)
M = m;
}
}
}
printf("%d\n", M + 2);
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13]]
| 0
| 421
| 2
|
#include <math.h>
#include <stdio.h>
#define SQ(x) ((x) * (x))
#define EPS 1e-4
typedef struct {
double x;
double y;
} POINT;
int dist(POINT a, POINT b, double d) {
if (SQ(a.x - b.x) + SQ(a.y - b.y) - d > EPS) {
return (0);
}
return (1);
}
int max(int a, int b) {
if (a > b) {
return (a);
}
return (b);
}
int main(void) {
POINT seal[100], v;
static POINT l[300000];
int s;
double a, a0, d, t;
int n;
int count, ans;
int i, j, k;
while (1) {
scanf("%d", &n);
if (!n) {
break;
}
for (i = 0; i < n; i++) {
scanf("%lf%*c%lf", &seal[i].x, &seal[i].y);
}
s = 0;
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if (dist(seal[i], seal[j], 4) && i != j) {
d = sqrt(SQ(seal[i].x - seal[j].x) + SQ(seal[i].y - seal[j].y));
a = atan2(seal[j].y - seal[i].y, seal[j].x - seal[i].x);
a0 = acos(0.5 * d);
l[s].x = seal[i].x + cos(a0 + a);
l[s].y = seal[i].y + sin(a0 + a);
s++;
l[s].x = seal[i].x + cos(a0 - a);
l[s].y = seal[i].y + sin(a0 - a);
s++;
}
}
}
ans = 0;
for (i = 0; i < s; i++) {
count = 0;
for (j = 0; j < n; j++) {
if (dist(seal[j], l[i], 1)) {
count++;
}
}
ans = max(ans, count);
}
printf("%d\n", ans);
}
return (0);
}
|
#include <math.h>
#include <stdio.h>
#define SQ(x) ((x) * (x))
#define EPS 1e-5
typedef struct {
double x;
double y;
} POINT;
int dist(POINT a, POINT b, double d) {
if (sqrt(SQ(a.x - b.x) + SQ(a.y - b.y)) - d > EPS) {
return (0);
}
return (1);
}
int max(int a, int b) {
if (a > b) {
return (a);
}
return (b);
}
int main(void) {
POINT seal[100], v;
static POINT l[300000];
int s;
double a, a0, d, t;
int n;
int count, ans;
int i, j, k;
while (1) {
scanf("%d", &n);
if (!n) {
break;
}
for (i = 0; i < n; i++) {
scanf("%lf%*c%lf", &seal[i].x, &seal[i].y);
}
s = 0;
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if (dist(seal[i], seal[j], 2) && i != j) {
d = sqrt(SQ(seal[i].x - seal[j].x) + SQ(seal[i].y - seal[j].y));
a = atan2(seal[j].y - seal[i].y, seal[j].x - seal[i].x);
a0 = acos(0.5 * d);
l[s].x = seal[i].x + cos(a0 + a);
l[s].y = seal[i].y + sin(a0 + a);
s++;
l[s].x = seal[i].x + cos(a0 - a);
l[s].y = seal[i].y + sin(a0 - a);
s++;
}
}
}
ans = 1;
for (i = 0; i < s; i++) {
count = 0;
for (j = 0; j < n; j++) {
if (dist(seal[j], l[i], 1)) {
count++;
}
}
ans = max(ans, count);
}
printf("%d\n", ans);
}
return (0);
}
|
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 0, 14, 8, 9, 0, 57, 15, 23, 0, 24], ["+", 15, 23, 0, 16, 31, 16, 31, 2, 63, 22], ["+", 0, 16, 31, 16, 31, 2, 3, 4, 0, 25], ["-", 15, 23, 0, 16, 31, 2, 3, 4, 0, 13], ["+", 15, 23, 0, 16, 31, 2, 3, 4, 0, 13], ["-", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13]]
| 0
| 532
| 9
|
#include <math.h>
#include <stdio.h>
double pot[100][3], xp, yp, xq, yq, d, a, ans;
int i, j, n;
void check(double x, double y) {
int i;
double px, py, a = 2.0;
for (i = 0; i < n; i++) {
px = pot[i][0];
py = pot[i][1];
if ((px - x) * (px - x) + (py - y) * (py - y) <= 1.000000000000005) {
a += pot[i][2];
}
}
if (a > ans)
ans = a;
}
int main(void) {
while (scanf("%d", &n) * n) {
ans = 1;
i = 0;
for (; n > 0; n--) {
scanf("%lf,%lf", &xp, &yp);
pot[i][2] = 0;
for (j = 0; j < i; j++) {
if (xp == pot[j][0] && yp == pot[j][1])
break;
}
pot[j][2]++;
if (pot[j][2] > ans)
ans = pot[j][2];
if (i == j) {
i++;
pot[j][0] = xp;
pot[j][1] = yp;
}
}
n = i;
for (i = 0; i < n - 1; i++) {
xp = pot[i][0];
yp = pot[i][1];
for (j = i + 1; j < n; j++) {
xq = pot[j][0];
yq = pot[j][1];
d = (xp - xq) * (xp - xq) + (yp - yq) * (yp - yq);
if (d == 4)
check((xp + xq) / 2, (yp + yq) / 2);
else if (d < 4) {
d = sqrt(1 - d / 4);
a = atan2(xq - xp, yp - yq);
check((xp + xq) / 2 + d * cos(a), (yp + yq) / 2 + d * sin(a));
check((xp + xq) / 2 - d * cos(a), (yp + yq) / 2 - d * sin(a));
}
}
}
printf("%d\n", (int)ans);
}
return 0;
}
|
#include <math.h>
#include <stdio.h>
double pot[100][3], xp, yp, xq, yq, d, a, ans;
int i, j, n;
void check(double x, double y) {
int i;
double px, py, a = 0.0;
for (i = 0; i < n; i++) {
px = pot[i][0];
py = pot[i][1];
if ((px - x) * (px - x) + (py - y) * (py - y) <= 1.000000000000005) {
a += pot[i][2];
}
}
if (a > ans)
ans = a;
}
int main(void) {
while (scanf("%d", &n) * n) {
ans = 1;
i = 0;
for (; n > 0; n--) {
scanf("%lf,%lf", &xp, &yp);
pot[i][2] = 0;
for (j = 0; j < i; j++) {
if (xp == pot[j][0] && yp == pot[j][1])
break;
}
pot[j][2]++;
if (pot[j][2] > ans)
ans = pot[j][2];
if (i == j) {
i++;
pot[j][0] = xp;
pot[j][1] = yp;
}
}
n = i;
for (i = 0; i < n - 1; i++) {
xp = pot[i][0];
yp = pot[i][1];
for (j = i + 1; j < n; j++) {
xq = pot[j][0];
yq = pot[j][1];
d = (xp - xq) * (xp - xq) + (yp - yq) * (yp - yq);
if (d == 4)
check((xp + xq) / 2, (yp + yq) / 2);
else if (d < 4) {
d = sqrt(1 - d / 4);
a = atan2(xq - xp, yp - yq);
check((xp + xq) / 2 + d * cos(a), (yp + yq) / 2 + d * sin(a));
check((xp + xq) / 2 - d * cos(a), (yp + yq) / 2 - d * sin(a));
}
}
}
printf("%d\n", (int)ans);
}
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13]]
| 0
| 553
| 2
|
M = 9;
main(n, i, j, k, a, b, c) {
float p = atan(1) * 4, X[100], Y[100], x, y;
for (; scanf("%d", &n), n; printf("%d\n", a)) {
for (i = 0; i < n; i++)
scanf("%f,%f", X + i, Y + i);
for (a = i = 0; i < n; i++) {
for (b = k = 0; k < M; k++) {
x = X[i] + cos(p * k / M), y = Y[i] + sin(p * k / M);
for (c = 0, j = i; j < n; j++) {
if ((X[j] - x) * (X[j] - x) + (Y[j] - y) * (Y[j] - y) < 1 + 1e-3)
c++;
}
if (b < c)
b = c;
}
if (a < b)
a = b;
}
}
exit(0);
}
|
M = 99;
main(n, i, j, k, a, b, c) {
float p = atan(1) * 4, X[100], Y[100], x, y;
for (; scanf("%d", &n), n; printf("%d\n", a)) {
for (i = 0; i < n; i++)
scanf("%f,%f", X + i, Y + i);
for (a = i = 0; i < n; i++) {
for (b = k = 0; k < M; k++) {
x = X[i] + cos(p * k / M), y = Y[i] + sin(p * k / M);
for (c = 0, j = 0; j < n; j++) {
if ((X[j] - x) * (X[j] - x) + (Y[j] - y) * (Y[j] - y) < 1 + 1e-3)
c++;
}
if (b < c)
b = c;
}
if (a < b)
a = b;
}
}
exit(0);
}
|
[["-", 36, 36, 0, 30, 0, 1, 0, 11, 12, 13], ["+", 36, 36, 0, 30, 0, 1, 0, 11, 12, 13], ["-", 8, 9, 0, 7, 10, 34, 12, 11, 12, 22], ["+", 8, 9, 0, 7, 10, 34, 12, 11, 12, 13]]
| 0
| 257
| 4
|
#include <bits/stdc++.h>
using namespace std;
const int dx[] = {0, 1, 0, -1, 1, -1, -1, 1};
const int dy[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int INF = 1 << 30;
const double EPS = 1e-15;
#define PB push_back
#define mk make_pair
#define fi first
#define se second
#define ll long long
#define reps(i, j, k) for (int i = (j); i < (k); i++)
#define rep(i, j) reps(i, 0, j)
#define MOD 1000000007
typedef pair<int, int> Pii;
typedef pair<int, Pii> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
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*(double k) { return Point(k * x, k * y); }
Point operator*(Point p) {
return Point(p.x * x - p.y * y, p.x * y + p.y * x);
}
Point operator/(double k) { return Point(x / k, y / k); }
Point operator=(Point p) {
x = p.x;
y = p.y;
return *this;
}
bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }
};
double dot(Point p, Point q) { return p.x * q.x + p.y * q.y; }
double cross(Point p, Point q) { return p.x * q.y - q.x * p.y; }
double norm(Point p) {
//ベクトルの大きさの2乗
return p.x * p.x + p.y * p.y;
}
double pabs(Point p) {
//ベクトルの大きさ
return sqrt(norm(p));
}
Point UnitVector(Point a) {
//単位ベクトル
return a / pabs(a);
}
typedef vector<Point> Polygon;
struct Line : Polygon {
Line() {}
Line(Point p, Point q) {
PB(p);
PB(q);
}
};
struct Circle {
Point p; //中心点
double r; //半径
Circle() {}
Circle(Point _p, double _r) {
p = _p;
r = _r;
}
};
int ccw(Point a, Point b, Point c) {
b = b - a;
c = c - a;
if (cross(b, c) > 0)
return +1; // a→b で反時計に折れてc ccw
if (cross(b, c) < 0)
return -1; // a→b で時計に折れてc ccw
if (dot(b, c) < 0)
return +2; // c--a--b;
if (pabs(b) < pabs(c))
return -2; // a--b--c
return 0; // a--c--b
}
bool intersectSS(Line l, Line m) {
// lとmが交差してるかどうか
return (ccw(l[0], l[1], m[0]) * ccw(l[0], l[1], m[1]) < EPS) &&
(ccw(m[0], m[1], l[0]) * ccw(m[0], m[1], l[1]) < EPS);
}
bool intersectSP(Line l, Point p) {
//線分lと点pが交差してるか
return !ccw(l[0], l[1], p);
}
bool intersectLL(Line l, Line m) {
return fabs(cross(l[1] - l[0], m[1] - m[0])) > EPS || //平行でない
fabs(cross(l[1] - l[0], m[0] - l[0])) < EPS; //同一の線
}
int intercectCC(Circle a, Circle b, Point *p, Point *q) {
double dist = pabs(a.p - b.p);
if (dist < fabs(a.r - b.r) || dist > a.r + b.r) {
//円の中心が一致しているとき
//円の交点が存在しないとき
*p = Point(1e15, 1e15);
*q = Point(1e15, 1e15);
return 0;
} else if (fabs(dist - a.r - b.r) < EPS) {
//円が1点で交わっているとき
Point way;
way = b.p - a.p;
*p = a.p + UnitVector(way) * a.r;
*q = *p;
return 1;
} else {
//円が2点で交わっているとき
if (a.r < b.r) {
swap(a.r, b.r);
swap(a.p, b.p);
}
double s = (a.r + b.r + dist) / 2.0;
double area = sqrt(s * (s - a.r) * (s - b.r) * (s - dist));
double h = 2.0 * area / dist;
Point v = b.p - a.p;
v = UnitVector(v);
Point m = a.p + (v * sqrt(a.r * a.r - h * h));
Point n = v * Point(0.0, 1.0);
*p = m + (n * h);
*q = m - (n * h);
return 2;
}
}
double TriangleArea(Point a, Point b, Point c) {
b = b - a;
c = c - a;
return cross(b, c) * 0.5; //負になることもあるので注意
}
double VertexArea(Polygon v) {
double subArea = 0.0;
rep(i, v.size() - 1) { subArea += TriangleArea(v[0], v[i], v[i + 1]); }
return subArea; //負になることもあるので注意
}
Point crosspoint(Line l, Line m) {
//線分lと線分mの交点
if (intersectSS(l, m) == false)
return Point(INF, INF);
return m[0] + (m[1] - m[0]) * cross(l[1] - l[0], l[1] - m[0]) /
cross(l[1] - l[0], m[1] - m[0]);
}
Polygon ConvexHull(Polygon v) {
int n = v.size();
int k = 0;
sort(v.begin(), v.end());
Polygon e(2 * n);
for (int i = 0; i < n; e[k++] = v[i++])
while (k >= 2 && ccw(e[k - 2], e[k - 1], v[i]) <= 0)
k--;
for (int i = n - 2, t = k + 1; i >= 0; e[k++] = v[i--])
while (k >= t && ccw(e[k - 2], e[k - 1], v[i]) <= 0)
k--;
e.resize(k - 1);
return e;
}
int main() {
int N;
while (scanf("%d", &N), N) {
Circle C[128];
vector<Point> points;
rep(i, N) {
double x, y;
scanf("%lf,%lf", &x, &y);
C[i] = Circle(Point(x, y), 1.);
}
int len = 0;
rep(i, N) {
reps(j, i + 1, N) {
Point p, q;
int tmp = 0;
tmp = intercectCC(C[i], C[j], &p, &q);
if (tmp > 0) {
points.PB(p);
points.PB(q);
}
}
}
int ans = -INF;
rep(i, points.size()) {
Point tar = points[i];
int cnt = 0;
rep(j, N) {
Point base = C[j].p;
if (pabs(base - tar) - 1 < EPS) {
cnt++;
}
}
ans = max(ans, cnt);
}
printf("%d\n", ans);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int dx[] = {0, 1, 0, -1, 1, -1, -1, 1};
const int dy[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int INF = 1 << 30;
const double EPS = 1e-15;
#define PB push_back
#define mk make_pair
#define fi first
#define se second
#define ll long long
#define reps(i, j, k) for (int i = (j); i < (k); i++)
#define rep(i, j) reps(i, 0, j)
#define MOD 1000000007
typedef pair<int, int> Pii;
typedef pair<int, Pii> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
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*(double k) { return Point(k * x, k * y); }
Point operator*(Point p) {
return Point(p.x * x - p.y * y, p.x * y + p.y * x);
}
Point operator/(double k) { return Point(x / k, y / k); }
Point operator=(Point p) {
x = p.x;
y = p.y;
return *this;
}
bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }
};
double dot(Point p, Point q) { return p.x * q.x + p.y * q.y; }
double cross(Point p, Point q) { return p.x * q.y - q.x * p.y; }
double norm(Point p) {
//ベクトルの大きさの2乗
return p.x * p.x + p.y * p.y;
}
double pabs(Point p) {
//ベクトルの大きさ
return sqrt(norm(p));
}
Point UnitVector(Point a) {
//単位ベクトル
return a / pabs(a);
}
typedef vector<Point> Polygon;
struct Line : Polygon {
Line() {}
Line(Point p, Point q) {
PB(p);
PB(q);
}
};
struct Circle {
Point p; //中心点
double r; //半径
Circle() {}
Circle(Point _p, double _r) {
p = _p;
r = _r;
}
};
int ccw(Point a, Point b, Point c) {
b = b - a;
c = c - a;
if (cross(b, c) > 0)
return +1; // a→b で反時計に折れてc ccw
if (cross(b, c) < 0)
return -1; // a→b で時計に折れてc ccw
if (dot(b, c) < 0)
return +2; // c--a--b;
if (pabs(b) < pabs(c))
return -2; // a--b--c
return 0; // a--c--b
}
bool intersectSS(Line l, Line m) {
// lとmが交差してるかどうか
return (ccw(l[0], l[1], m[0]) * ccw(l[0], l[1], m[1]) < EPS) &&
(ccw(m[0], m[1], l[0]) * ccw(m[0], m[1], l[1]) < EPS);
}
bool intersectSP(Line l, Point p) {
//線分lと点pが交差してるか
return !ccw(l[0], l[1], p);
}
bool intersectLL(Line l, Line m) {
return fabs(cross(l[1] - l[0], m[1] - m[0])) > EPS || //平行でない
fabs(cross(l[1] - l[0], m[0] - l[0])) < EPS; //同一の線
}
int intercectCC(Circle a, Circle b, Point *p, Point *q) {
double dist = pabs(a.p - b.p);
if (dist < fabs(a.r - b.r) || dist > a.r + b.r) {
//円の中心が一致しているとき
//円の交点が存在しないとき
*p = Point(1e15, 1e15);
*q = Point(1e15, 1e15);
return 0;
} else if (fabs(dist - a.r - b.r) < EPS) {
//円が1点で交わっているとき
Point way;
way = b.p - a.p;
*p = a.p + UnitVector(way) * a.r;
*q = *p;
return 1;
} else {
//円が2点で交わっているとき
if (a.r < b.r) {
swap(a.r, b.r);
swap(a.p, b.p);
}
double s = (a.r + b.r + dist) / 2.0;
double area = sqrt(s * (s - a.r) * (s - b.r) * (s - dist));
double h = 2.0 * area / dist;
Point v = b.p - a.p;
v = UnitVector(v);
Point m = a.p + (v * sqrt(a.r * a.r - h * h));
Point n = v * Point(0.0, 1.0);
*p = m + (n * h);
*q = m - (n * h);
return 2;
}
}
double TriangleArea(Point a, Point b, Point c) {
b = b - a;
c = c - a;
return cross(b, c) * 0.5; //負になることもあるので注意
}
double VertexArea(Polygon v) {
double subArea = 0.0;
rep(i, v.size() - 1) { subArea += TriangleArea(v[0], v[i], v[i + 1]); }
return subArea; //負になることもあるので注意
}
Point crosspoint(Line l, Line m) {
//線分lと線分mの交点
if (intersectSS(l, m) == false)
return Point(INF, INF);
return m[0] + (m[1] - m[0]) * cross(l[1] - l[0], l[1] - m[0]) /
cross(l[1] - l[0], m[1] - m[0]);
}
Polygon ConvexHull(Polygon v) {
int n = v.size();
int k = 0;
sort(v.begin(), v.end());
Polygon e(2 * n);
for (int i = 0; i < n; e[k++] = v[i++])
while (k >= 2 && ccw(e[k - 2], e[k - 1], v[i]) <= 0)
k--;
for (int i = n - 2, t = k + 1; i >= 0; e[k++] = v[i--])
while (k >= t && ccw(e[k - 2], e[k - 1], v[i]) <= 0)
k--;
e.resize(k - 1);
return e;
}
int main() {
int N;
while (scanf("%d", &N), N) {
Circle C[328];
vector<Point> points;
rep(i, N) {
double x, y;
scanf("%lf,%lf", &x, &y);
C[i] = Circle(Point(x, y), 1.);
}
int len = 0;
rep(i, N) {
reps(j, i + 1, N) {
Point p, q;
int tmp = 0;
tmp = intercectCC(C[i], C[j], &p, &q);
if (tmp > 0) {
points.PB(p);
points.PB(q);
/*
cout << i << " " << j << "->\n";
cout << "1:"<< p.x << " " << p.y << "\n";
cout << "2:"<< q.x << " " << q.y << "\n";
*/
}
}
}
int ans = 1;
rep(i, points.size()) {
Point tar = points[i];
int cnt = 0;
rep(j, N) {
Point base = C[j].p;
// cout << pabs(base-tar) << " ";
if (pabs(base - tar) - 1. < EPS) {
cnt++;
}
}
ans = max(ans, cnt);
}
printf("%d\n", ans);
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 80, 81, 13], ["-", 8, 9, 0, 43, 49, 50, 51, 91, 17, 33], ["-", 8, 9, 0, 43, 49, 50, 51, 91, 28, 22], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["-", 0, 57, 15, 339, 51, 16, 31, 16, 12, 13], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 12, 13]]
| 1
| 1,760
| 7
|
#define _USE_MATH_DEFINES
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define EPS 1e-8
#define INF 1000000
struct Point {
double x, y;
Point() {}
Point(double _x, double _y) {
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 d) const { return Point(x * d, y * d); }
bool operator<(const Point &p) const {
if (x == p.x)
return y < p.y;
return x < p.x;
}
bool operator==(const Point &p) const {
return abs(x - p.x) < EPS && abs(y - p.y) < EPS;
}
double norm() { return x * x + y * y; }
bool input() {
if (cin >> x >> y)
return true;
return false;
}
};
struct Line {
Point a, b;
Line() {}
Line(Point _a, Point _b) {
a = _a;
b = _b;
}
bool input() {
if (a.input() && b.input())
return true;
return false;
}
};
struct Circle {
Point c;
double r;
Circle() {}
Circle(Point _c, double _r) {
c = _c;
r = _r;
}
};
typedef Point Vector;
typedef vector<Point> Polygon;
typedef Line Segment;
double dot(Point p, Point q) { return p.x * q.x + p.y * q.y; }
double cross(Point p, Point q) { return p.x * q.y - q.x * p.y; }
int ccw(Point a, Point b, Point c) {
Vector v1 = b - a;
Vector v2 = c - a;
if (cross(v1, v2) > EPS)
return +1;
if (cross(v1, v2) < -EPS)
return -1;
if (dot(v1, v2) < -EPS)
return +2;
if (v2.norm() - v1.norm() > EPS)
return -2;
return 0;
}
Point project(Segment s, Point p) {
Vector v1 = s.b - s.a;
Vector v2 = p - s.a;
double r = dot(v1, v2) / v1.norm();
return s.a + v1 * r;
}
Point reflect(Segment s, Point p) { return p + (project(s, p) - p) * 2.0; }
bool intersect_ll(Line l, Line m) {
return ccw(l.a, l.b, m.a) * ccw(l.a, l.b, m.b) <= 0 &&
ccw(m.a, m.b, l.a) * ccw(m.a, m.b, l.b) <= 0;
}
bool crosspoint_ss(Segment s, Segment t, Point &p) {
Vector a1, a2, b1, b2;
a1 = s.b - s.a;
a2 = t.b - t.a;
b1 = t.a - s.a;
b2 = s.a - t.b;
double s1, s2;
s1 = cross(a1, b1) / 2;
s2 = cross(a1, b2) / 2;
if (s1 + s2 < EPS)
return false;
p = Point(t.a.x + a2.x * s1 / (s1 + s2), t.a.y + a2.y * s1 / (s1 + s2));
return true;
}
int crosspoint_ll(Line l, Line m, Point &p) {
if (intersect_ll(l, m) == false)
return 0;
if (crosspoint_ss(l, m, p) == true)
return 1;
return -1;
}
int crosspoint_cc(Circle c1, Circle c2, Point &p1, Point &p2) {
double d, a, t;
d = sqrt((c2.c - c1.c).norm());
if (abs(c1.c.x - c2.c.x) < EPS && abs(c1.c.y - c2.c.y) < EPS &&
abs(c1.r - c2.r) < EPS)
return -1;
if (d < abs(c1.r - c2.r) || c1.r + c2.r < d)
return 0;
a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d));
t = atan2(c2.c.y - c1.c.y, c2.c.x - c1.c.x);
p1 = Point(c1.c.x + c1.r * cos(t + a), c1.c.y + c1.r * sin(t + a));
p2 = Point(c1.c.x + c1.r * cos(t - a), c1.c.y + c1.r * sin(t - a));
if (abs(p1.x - p2.x) < EPS && abs(p1.y - p2.y) < EPS)
return 1;
return 2;
}
int contain_gp(Polygon g, Point p) {
Line l = Line(p, Point(INF, p.y));
int cnt = 0, n = g.size();
for (int i = 0; i < n; i++) {
Vector a = g[i] - p;
Vector b = g[(i + 1) % n] - p;
if (ccw(g[i], g[(i + 1) % n], p) == 0)
return 1;
if (a.y > b.y)
swap(a, b);
if (a.y <= EPS && EPS < b.y && cross(a, b) > EPS)
cnt++;
}
if ((cnt & 1) == 1)
return 2;
return 0;
}
Polygon andrewScan(Polygon s) {
if (s.size() <= 2)
return s;
sort(s.begin(), s.end());
Polygon g;
for (int i = 0; i < s.size(); i++) {
for (int n = g.size(); n >= 2 && ccw(g[n - 2], g[n - 1], s[i]) != -1; n--) {
g.pop_back();
}
g.push_back(s[i]);
}
int upper_n = g.size();
for (int i = s.size() - 2; i >= 0; i--) {
for (int n = g.size(); n > upper_n && ccw(g[n - 2], g[n - 1], s[i]) != -1;
n--) {
g.pop_back();
}
g.push_back(s[i]);
}
reverse(g.begin(), g.end());
g.pop_back();
return g;
}
struct Data {
int n;
double dist;
Data() {}
Data(int _n, double _dist) {
n = _n;
dist = _dist;
}
bool operator<(const Data &a) const { return dist > a.dist; }
};
struct Edge {
int to;
double dist;
Edge() {}
Edge(int _to, double _dist) {
to = _to;
dist = _dist;
}
};
int main() {
int N;
Circle C[100];
while (cin >> N, N) {
for (int i = 0; i < N; i++) {
scanf("%lf,%lf", &C[i].c.x, &C[i].c.y);
C[i].r = 1;
}
int ans = 0;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
Point p[2];
if (crosspoint_cc(C[i], C[j], p[0], p[1]) > 0) {
for (int k = 0; k < 2; k++) {
int cnt = 0;
for (int l = 0; l < N; l++) {
if ((C[l].c - p[k]).norm() <= 1 + EPS)
cnt++;
}
ans = max(ans, cnt);
}
}
}
}
printf("%d\n", ans);
}
}
|
#define _USE_MATH_DEFINES
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define EPS 1e-8
#define INF 1000000
struct Point {
double x, y;
Point() {}
Point(double _x, double _y) {
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 d) const { return Point(x * d, y * d); }
bool operator<(const Point &p) const {
if (x == p.x)
return y < p.y;
return x < p.x;
}
bool operator==(const Point &p) const {
return abs(x - p.x) < EPS && abs(y - p.y) < EPS;
}
double norm() { return x * x + y * y; }
bool input() {
if (cin >> x >> y)
return true;
return false;
}
};
struct Line {
Point a, b;
Line() {}
Line(Point _a, Point _b) {
a = _a;
b = _b;
}
bool input() {
if (a.input() && b.input())
return true;
return false;
}
};
struct Circle {
Point c;
double r;
Circle() {}
Circle(Point _c, double _r) {
c = _c;
r = _r;
}
};
typedef Point Vector;
typedef vector<Point> Polygon;
typedef Line Segment;
double dot(Point p, Point q) { return p.x * q.x + p.y * q.y; }
double cross(Point p, Point q) { return p.x * q.y - q.x * p.y; }
int ccw(Point a, Point b, Point c) {
Vector v1 = b - a;
Vector v2 = c - a;
if (cross(v1, v2) > EPS)
return +1;
if (cross(v1, v2) < -EPS)
return -1;
if (dot(v1, v2) < -EPS)
return +2;
if (v2.norm() - v1.norm() > EPS)
return -2;
return 0;
}
Point project(Segment s, Point p) {
Vector v1 = s.b - s.a;
Vector v2 = p - s.a;
double r = dot(v1, v2) / v1.norm();
return s.a + v1 * r;
}
Point reflect(Segment s, Point p) { return p + (project(s, p) - p) * 2.0; }
bool intersect_ll(Line l, Line m) {
return ccw(l.a, l.b, m.a) * ccw(l.a, l.b, m.b) <= 0 &&
ccw(m.a, m.b, l.a) * ccw(m.a, m.b, l.b) <= 0;
}
bool crosspoint_ss(Segment s, Segment t, Point &p) {
Vector a1, a2, b1, b2;
a1 = s.b - s.a;
a2 = t.b - t.a;
b1 = t.a - s.a;
b2 = s.a - t.b;
double s1, s2;
s1 = cross(a1, b1) / 2;
s2 = cross(a1, b2) / 2;
if (s1 + s2 < EPS)
return false;
p = Point(t.a.x + a2.x * s1 / (s1 + s2), t.a.y + a2.y * s1 / (s1 + s2));
return true;
}
int crosspoint_ll(Line l, Line m, Point &p) {
if (intersect_ll(l, m) == false)
return 0;
if (crosspoint_ss(l, m, p) == true)
return 1;
return -1;
}
int crosspoint_cc(Circle c1, Circle c2, Point &p1, Point &p2) {
double d, a, t;
d = sqrt((c2.c - c1.c).norm());
if (abs(c1.c.x - c2.c.x) < EPS && abs(c1.c.y - c2.c.y) < EPS &&
abs(c1.r - c2.r) < EPS)
return -1;
if (d < abs(c1.r - c2.r) || c1.r + c2.r < d)
return 0;
a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d));
t = atan2(c2.c.y - c1.c.y, c2.c.x - c1.c.x);
p1 = Point(c1.c.x + c1.r * cos(t + a), c1.c.y + c1.r * sin(t + a));
p2 = Point(c1.c.x + c1.r * cos(t - a), c1.c.y + c1.r * sin(t - a));
if (abs(p1.x - p2.x) < EPS && abs(p1.y - p2.y) < EPS)
return 1;
return 2;
}
int contain_gp(Polygon g, Point p) {
Line l = Line(p, Point(INF, p.y));
int cnt = 0, n = g.size();
for (int i = 0; i < n; i++) {
Vector a = g[i] - p;
Vector b = g[(i + 1) % n] - p;
if (ccw(g[i], g[(i + 1) % n], p) == 0)
return 1;
if (a.y > b.y)
swap(a, b);
if (a.y <= EPS && EPS < b.y && cross(a, b) > EPS)
cnt++;
}
if ((cnt & 1) == 1)
return 2;
return 0;
}
Polygon andrewScan(Polygon s) {
if (s.size() <= 2)
return s;
sort(s.begin(), s.end());
Polygon g;
for (int i = 0; i < s.size(); i++) {
for (int n = g.size(); n >= 2 && ccw(g[n - 2], g[n - 1], s[i]) != -1; n--) {
g.pop_back();
}
g.push_back(s[i]);
}
int upper_n = g.size();
for (int i = s.size() - 2; i >= 0; i--) {
for (int n = g.size(); n > upper_n && ccw(g[n - 2], g[n - 1], s[i]) != -1;
n--) {
g.pop_back();
}
g.push_back(s[i]);
}
reverse(g.begin(), g.end());
g.pop_back();
return g;
}
struct Data {
int n;
double dist;
Data() {}
Data(int _n, double _dist) {
n = _n;
dist = _dist;
}
bool operator<(const Data &a) const { return dist > a.dist; }
};
struct Edge {
int to;
double dist;
Edge() {}
Edge(int _to, double _dist) {
to = _to;
dist = _dist;
}
};
int main() {
int N;
Circle C[100];
while (cin >> N, N) {
for (int i = 0; i < N; i++) {
scanf("%lf,%lf", &C[i].c.x, &C[i].c.y);
C[i].r = 1;
}
int ans = 1;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
Point p[2];
if (crosspoint_cc(C[i], C[j], p[0], p[1]) > 0) {
for (int k = 0; k < 2; k++) {
int cnt = 0;
for (int l = 0; l < N; l++) {
if ((C[l].c - p[k]).norm() <= 1 + EPS)
cnt++;
}
ans = max(ans, cnt);
}
}
}
}
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
| 1,891
| 2
|
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
typedef pair<double, double> pd;
double EPS = 1e-9;
double sq(double a) { return a * a; }
double dis(pd p1, pd p2) {
return sqrt(sq(p1.first - p2.first) + sq(p1.second - p2.second));
}
pd add(pd p1, pd p2) {
return make_pair(p1.first + p2.first, p1.second + p2.second);
}
pd minu(pd p1, pd p2) {
return make_pair(p1.first - p2.first, p1.second - p2.second);
}
double inter(pd p1, pd p2) {
return sqrt(sq(p1.first - p2.first) + sq(p1.second - p2.second));
}
int main() {
double n;
while (cin >> n, n) {
double x, y, ans = 0;
char c;
vector<pd> vec;
for (int i = 0; i < n; i++) {
cin >> x >> c >> y;
vec.push_back(make_pair(x, y));
}
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (dis(vec[i], vec[j]) <= 2) {
double pm = sqrt(1 - sq(dis(vec[i], vec[j]) / 2));
double lam = pm / dis(vec[i], vec[j]);
pd m = add(vec[i], vec[j]);
m.first /= 2;
m.second /= 2;
pd pt = make_pair(lam * (vec[i].second - vec[j].second),
lam * (vec[j].first - vec[i].first));
pd p1 = add(m, pt);
pd p2 = minu(m, pt);
int cou = 0;
if (p1.first >= 0 - EPS && p1.second >= 0 - EPS &&
p1.first <= 10 + EPS && p1.second <= 10 + EPS)
for (int a = 0; a < n; a++) {
if (dis(vec[a], p1) <= 1 + EPS) {
cou++;
}
}
if (ans < cou)
ans = cou;
cou = 0;
if (p2.first >= 0 - EPS && p2.second >= 0 - EPS &&
p2.first <= 10 + EPS && p2.second <= 10 + EPS)
for (int a = 0; a < n; a++) {
if (dis(vec[a], p2) <= 1 + EPS)
cou++;
}
if (ans < cou)
ans = cou;
}
}
}
cout << ans << endl;
}
}
|
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
typedef pair<double, double> pd;
double EPS = 1e-5;
double sq(double a) { return a * a; }
double dis(pd p1, pd p2) {
return sqrt(sq(p1.first - p2.first) + sq(p1.second - p2.second));
}
pd add(pd p1, pd p2) {
return make_pair(p1.first + p2.first, p1.second + p2.second);
}
pd minu(pd p1, pd p2) {
return make_pair(p1.first - p2.first, p1.second - p2.second);
}
double inter(pd p1, pd p2) {
return sqrt(sq(p1.first - p2.first) + sq(p1.second - p2.second));
}
int main() {
double n;
while (cin >> n, n) {
double x, y;
int ans = 1;
char c;
vector<pd> vec;
for (int i = 0; i < n; i++) {
cin >> x >> c >> y;
vec.push_back(make_pair(x, y));
}
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (dis(vec[i], vec[j]) <= 2) {
double pm = sqrt(1 - sq(dis(vec[i], vec[j]) / 2));
double lam = pm / dis(vec[i], vec[j]);
pd m = add(vec[i], vec[j]);
m.first /= 2;
m.second /= 2;
pd pt = make_pair(lam * (vec[i].second - vec[j].second),
lam * (vec[j].first - vec[i].first));
pd p1 = add(m, pt);
pd p2 = minu(m, pt);
int cou = 0;
if (p1.first >= 0 - EPS && p1.second >= 0 - EPS &&
p1.first <= 10 + EPS && p1.second <= 10 + EPS)
for (int a = 0; a < n; a++) {
if (dis(vec[a], p1) <= 1 + EPS) {
cou++;
}
}
if (ans < cou)
ans = cou;
cou = 0;
if (p2.first >= 0 - EPS && p2.second >= 0 - EPS &&
p2.first <= 10 + EPS && p2.second <= 10 + EPS)
for (int a = 0; a < n; a++) {
if (dis(vec[a], p2) <= 1 + EPS)
cou++;
}
if (ans < cou)
ans = cou;
}
}
}
cout << ans << endl;
}
}
|
[["-", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["-", 8, 9, 0, 52, 8, 9, 0, 43, 0, 21], ["+", 8, 9, 0, 52, 8, 9, 0, 43, 0, 35], ["+", 8, 9, 0, 52, 8, 9, 0, 43, 39, 40], ["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
| 1
| 610
| 7
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
// ------ Classes ------ //
class Point {
public:
long double px, py;
Point() : px(0), py(0){};
Point(long double px_, long double py_) : px(px_), py(py_){};
bool operator==(const Point &p) const { return px == p.px && py == p.py; }
bool operator!=(const Point &p) const { return px != p.px || py != p.py; }
bool operator<(const Point &p) const {
return px < p.px ? true : (px == p.px && py < p.py);
}
bool operator>(const Point &p) const {
return px > p.px ? true : (px == p.px && py > p.py);
}
bool operator<=(const Point &p) const { return !(Point(px, py) > p); }
bool operator>=(const Point &p) const { return !(Point(px, py) < p); }
Point operator+(const Point &p) const { return Point(px + p.px, py + p.py); }
Point operator-(const Point &p) const { return Point(px - p.px, py - p.py); }
Point operator/(long double d) const { return Point(px / d, py / d); }
friend Point operator*(const Point p, long double d) {
return Point(p.px * d, p.py * d);
}
friend Point operator*(long double d, const Point &p) { return p * d; }
Point &operator+=(const Point &p1) {
px += p1.px, py += p1.py;
return *this;
}
Point &operator-=(const Point &p1) {
px -= p1.px, py -= p1.py;
return *this;
}
Point &operator*=(long double d) {
px *= d, py *= d;
return *this;
}
Point &operator/=(long double d) {
px /= d, py /= d;
return *this;
}
};
class Circle {
public:
Point p;
long double r;
Circle() : p(Point()), r(0.0L){};
Circle(Point p_) : p(p_), r(0.0L){};
Circle(Point p_, long double r_) : p(p_), r(r_){};
Circle(long double x_, long double y_) : p(Point(x_, y_)), r(0.0L){};
Circle(long double x_, long double y_, long double r_)
: p(Point(x_, y_)), r(r_){};
bool operator==(const Circle &c) const { return p == c.p && r == c.r; }
bool operator!=(const Circle &c) const { return !(Circle(p, r) == c); }
};
// ------ Functions ------ //
long double norm(const Point &a) { return a.px * a.px + a.py * a.py; }
long double abs(const Point &a) { return sqrtl(norm(a)); }
long double arg(const Point &a) { return atan2l(a.py, a.px); }
long double dot(const Point &a, const Point &b) {
return a.px * b.px + a.py * b.py;
}
long double crs(const Point &a, const Point &b) {
return a.px * b.py - a.py * b.px;
}
Point pol(long double r, long double d) {
return Point(cosl(d) * r, sinl(d) * r);
}
int ccw(const Point &p0, const Point &p1, const Point &p2) {
Point a = p1 - p0, b = p2 - p0;
if (crs(a, b) > 1e-10)
return 1;
if (crs(a, b) < -1e-10)
return -1;
if (dot(a, b) < -1e-10)
return 2;
if (norm(a) < norm(b))
return -2;
return 0;
}
bool its(const Point &p1, const Point &p2, const Point &p3, const Point &p4) {
return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}
long double dst(const Point &a, const Point &b) { return abs(b - a); }
vector<Point> crp(Circle c1, Circle c2) {
double d = abs(c1.p - c2.p);
double a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d));
double t = arg(c2.p - c1.p);
return {c1.p + pol(c1.r, t + a), c1.p + pol(c1.r, t - a)};
}
// ------ Main ------ //
int n;
char c;
vector<Circle> v;
int main() {
while (cin >> n, n) {
v.resize(n);
for (int i = 0; i < n; i++)
cin >> v[i].p.px >> c >> v[i].p.py, v[i].r = 1;
int ret = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (dst(v[i].p, v[j].p) > 2.0L + 1e-10)
continue;
vector<Point> w = crp(v[i], v[j]);
for (int k = 0; k < 2; k++) {
int s = 0;
for (int l = 0; l < n; l++) {
if (dst(w[k], v[l].p) <= 1.0L + 1e-10)
s++;
}
ret = max(ret, s);
}
}
}
cout << ret << endl;
}
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
// ------ Classes ------ //
class Point {
public:
long double px, py;
Point() : px(0), py(0){};
Point(long double px_, long double py_) : px(px_), py(py_){};
bool operator==(const Point &p) const { return px == p.px && py == p.py; }
bool operator!=(const Point &p) const { return px != p.px || py != p.py; }
bool operator<(const Point &p) const {
return px < p.px ? true : (px == p.px && py < p.py);
}
bool operator>(const Point &p) const {
return px > p.px ? true : (px == p.px && py > p.py);
}
bool operator<=(const Point &p) const { return !(Point(px, py) > p); }
bool operator>=(const Point &p) const { return !(Point(px, py) < p); }
Point operator+(const Point &p) const { return Point(px + p.px, py + p.py); }
Point operator-(const Point &p) const { return Point(px - p.px, py - p.py); }
Point operator/(long double d) const { return Point(px / d, py / d); }
friend Point operator*(const Point p, long double d) {
return Point(p.px * d, p.py * d);
}
friend Point operator*(long double d, const Point &p) { return p * d; }
Point &operator+=(const Point &p1) {
px += p1.px, py += p1.py;
return *this;
}
Point &operator-=(const Point &p1) {
px -= p1.px, py -= p1.py;
return *this;
}
Point &operator*=(long double d) {
px *= d, py *= d;
return *this;
}
Point &operator/=(long double d) {
px /= d, py /= d;
return *this;
}
};
class Circle {
public:
Point p;
long double r;
Circle() : p(Point()), r(0.0L){};
Circle(Point p_) : p(p_), r(0.0L){};
Circle(Point p_, long double r_) : p(p_), r(r_){};
Circle(long double x_, long double y_) : p(Point(x_, y_)), r(0.0L){};
Circle(long double x_, long double y_, long double r_)
: p(Point(x_, y_)), r(r_){};
bool operator==(const Circle &c) const { return p == c.p && r == c.r; }
bool operator!=(const Circle &c) const { return !(Circle(p, r) == c); }
};
// ------ Functions ------ //
long double norm(const Point &a) { return a.px * a.px + a.py * a.py; }
long double abs(const Point &a) { return sqrtl(norm(a)); }
long double arg(const Point &a) { return atan2l(a.py, a.px); }
long double dot(const Point &a, const Point &b) {
return a.px * b.px + a.py * b.py;
}
long double crs(const Point &a, const Point &b) {
return a.px * b.py - a.py * b.px;
}
Point pol(long double r, long double d) {
return Point(cosl(d) * r, sinl(d) * r);
}
int ccw(const Point &p0, const Point &p1, const Point &p2) {
Point a = p1 - p0, b = p2 - p0;
if (crs(a, b) > 1e-10)
return 1;
if (crs(a, b) < -1e-10)
return -1;
if (dot(a, b) < -1e-10)
return 2;
if (norm(a) < norm(b))
return -2;
return 0;
}
bool its(const Point &p1, const Point &p2, const Point &p3, const Point &p4) {
return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}
long double dst(const Point &a, const Point &b) { return abs(b - a); }
vector<Point> crp(Circle c1, Circle c2) {
double d = abs(c1.p - c2.p);
double a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d));
double t = arg(c2.p - c1.p);
return {c1.p + pol(c1.r, t + a), c1.p + pol(c1.r, t - a)};
}
// ------ Main ------ //
int n;
char c;
vector<Circle> v;
int main() {
while (cin >> n, n) {
v.resize(n);
for (int i = 0; i < n; i++)
cin >> v[i].p.px >> c >> v[i].p.py, v[i].r = 1;
int ret = 1;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (dst(v[i].p, v[j].p) > 2.0L + 1e-10)
continue;
vector<Point> w = crp(v[i], v[j]);
for (int k = 0; k < 2; k++) {
int s = 0;
for (int l = 0; l < n; l++) {
if (dst(w[k], v[l].p) <= 1.0L + 1e-10)
s++;
}
ret = max(ret, s);
}
}
}
cout << ret << endl;
}
}
|
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
| 1
| 1,357
| 2
|
#include <bits/stdc++.h>
using namespace std;
#define pb(n) push_back(n)
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second
#define np string::npos
#define X real()
#define Y imag()
#define value(x, y, w, h) (x >= 0 && x < w && y >= 0 && y < h)
#define all(r) (r).begin(), (r).end()
#define gsort(st, en) sort((st), (en), greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout << #x << ": " << x << endl
#define fcout(n) cout << fixed << setprecision((n))
#define scout(n) cout << setw(n)
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define repi(it, array) \
for (auto it = array.begin(), end = array.end(); it != end; ++it)
#define repa(n, array) for (auto &n : (array))
typedef long long ll;
typedef deque<int> di;
typedef deque<ll> dl;
typedef map<string, int> dict;
typedef complex<double> comd;
typedef pair<int, int> pii;
constexpr int imax = ((1 << 30) - 1) * 2 + 1;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0);
double eps = 1e-10;
const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, -1, 0, 1};
const double EPS = 1e-10;
const double INF = 1e12;
typedef complex<double> P; //????´???°????????¢?????????????????¨?§£???
namespace std {
bool operator<(const P &a, const P &b) { // x????????????
return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
bool sorty(const P &a, const P &b) { // y????????????
return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b);
}
} // namespace std
double cross(const P &a, const P &b) { //??????
return imag(conj(a) * b);
}
double dot(const P &a, const P &b) { //??????
return real(conj(a) * b);
}
struct L : public vector<P> { //??´???
L(){};
L(const P &a, const P &b) {
push_back(a);
push_back(b);
}
};
typedef vector<P> G;
struct C { //???
P p;
double r;
C(){};
C(const P &p, double r) : p(p), r(r) {}
};
// L:line,S:segment,P:point
bool in_field(double x, double y, double x1, double y1, P p) {
return x <= real(p) && real(p) <= x1 && y <= imag(p) && imag(p) <= y1;
}
double distancePP(const P &p, const P &q) { return abs(p - q); }
P crosspoint(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
if (abs(A) < EPS)
assert(false); // !!!PRECONDITION NOT SATISFIED!!!
return m[0] + B / A * (m[1] - m[0]);
}
P verticalvector(const P &a,
const P &b) { // 2???????????????????????????????????????
if (a.real() == b.real()) {
return {1.0, 0};
}
if (a.imag() == b.imag()) {
return {0, 1.0};
}
P p = a - b;
P res = {-p.imag(), p.real()};
return res / abs(p);
}
pair<P, P> crosspointCircle(const C &a, const C &b) {
P m = (a.p + b.p) / 2.0;
P vv = verticalvector(a.p, b.p);
double u = sqrt(a.r * a.r - norm(a.p - b.p) / 2.0);
P A = m + u * vv, B = m - u * vv;
return mp(A, B);
}
int n;
C ps[100];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
char c;
while (1) {
cin >> n;
if (n == 0) {
break;
}
double x, y;
rep(i, n) {
cin >> x >> c >> y;
ps[i] = {P(x, y), 1.0};
}
int ans = 1, resa = 0, resb = 0;
rep(i, n) {
REP(j, i + 1, n) {
if (distancePP(ps[i].p, ps[j].p) >= 2.0) {
continue;
} else {
auto ab = crosspointCircle(ps[i], ps[j]);
P a = ab.first, b = ab.second;
resa = 0;
resb = 0;
rep(k, n) {
if (distancePP(ps[k].p, a) <= 1.0 + EPS) {
++resa;
}
}
rep(k, n) {
if (distancePP(ps[k].p, b) <= 1.0 + EPS) {
++resb;
}
}
}
ans = max(ans, max(resa, resb));
}
}
std::cout << ans << std::endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define pb(n) push_back(n)
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second
#define np string::npos
#define X real()
#define Y imag()
#define value(x, y, w, h) (x >= 0 && x < w && y >= 0 && y < h)
#define all(r) (r).begin(), (r).end()
#define gsort(st, en) sort((st), (en), greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout << #x << ": " << x << endl
#define fcout(n) cout << fixed << setprecision((n))
#define scout(n) cout << setw(n)
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define repi(it, array) \
for (auto it = array.begin(), end = array.end(); it != end; ++it)
#define repa(n, array) for (auto &n : (array))
typedef long long ll;
typedef deque<int> di;
typedef deque<ll> dl;
typedef map<string, int> dict;
typedef complex<double> comd;
typedef pair<int, int> pii;
constexpr int imax = ((1 << 30) - 1) * 2 + 1;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0);
double eps = 1e-10;
const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, -1, 0, 1};
const double EPS = 1e-10;
const double INF = 1e12;
typedef complex<double> P; //????´???°????????¢?????????????????¨?§£???
namespace std {
bool operator<(const P &a, const P &b) { // x????????????
return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
bool sorty(const P &a, const P &b) { // y????????????
return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b);
}
} // namespace std
double cross(const P &a, const P &b) { //??????
return imag(conj(a) * b);
}
double dot(const P &a, const P &b) { //??????
return real(conj(a) * b);
}
struct L : public vector<P> { //??´???
L(){};
L(const P &a, const P &b) {
push_back(a);
push_back(b);
}
};
typedef vector<P> G;
struct C { //???
P p;
double r;
C(){};
C(const P &p, double r) : p(p), r(r) {}
};
// L:line,S:segment,P:point
bool in_field(double x, double y, double x1, double y1, P p) {
return x <= real(p) && real(p) <= x1 && y <= imag(p) && imag(p) <= y1;
}
double distancePP(const P &p, const P &q) { return abs(p - q); }
P crosspoint(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
if (abs(A) < EPS)
assert(false); // !!!PRECONDITION NOT SATISFIED!!!
return m[0] + B / A * (m[1] - m[0]);
}
P verticalvector(const P &a,
const P &b) { // 2???????????????????????????????????????
if (a.real() == b.real()) {
return {1.0, 0};
}
if (a.imag() == b.imag()) {
return {0, 1.0};
}
P p = a - b;
P res = {-p.imag(), p.real()};
return res / abs(p);
}
pair<P, P> crosspointCircle(const C &a, const C &b) {
P m = (a.p + b.p) / 2.0;
P vv = verticalvector(a.p, b.p);
double u = sqrt(a.r * a.r - norm(a.p - b.p) / 4.0);
P A = m + u * vv, B = m - u * vv;
return mp(A, B);
}
int n;
C ps[100];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
char c;
while (1) {
cin >> n;
if (n == 0) {
break;
}
double x, y;
rep(i, n) {
cin >> x >> c >> y;
ps[i] = {P(x, y), 1.0};
}
int ans = 1, resa = 0, resb = 0;
rep(i, n) {
REP(j, i + 1, n) {
if (distancePP(ps[i].p, ps[j].p) >= 2.0) {
continue;
} else {
auto ab = crosspointCircle(ps[i], ps[j]);
P a = ab.first, b = ab.second;
resa = 0;
resb = 0;
rep(k, n) {
if (distancePP(ps[k].p, a) <= 1.0 + EPS) {
++resa;
}
}
rep(k, n) {
if (distancePP(ps[k].p, b) <= 1.0 + EPS) {
++resb;
}
}
}
ans = max(ans, max(resa, resb));
}
}
std::cout << ans << std::endl;
}
return 0;
}
|
[["-", 51, 2, 3, 4, 0, 16, 12, 16, 12, 13], ["+", 51, 2, 3, 4, 0, 16, 12, 16, 12, 13]]
| 1
| 1,176
| 2
|
#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 EPS (1e-8)
typedef complex<double> P;
vector<P> intersection(P a, P b) {
vector<P> res;
if (abs(abs(b - a) - 2.0) < EPS) {
//????????\????????????
P c = a + b;
res.push_back(P(c.real() / 2.0, c.imag() / 2.0));
} else if (abs(b - a) < 2.0) {
//??????????????£?????????
P ab = b - a;
P nv1 =
(ab * P(0, +1)) / abs(ab); // ab????¨??????????????????????????????????
P nv2 = (ab * P(0. - 1)) / abs(ab); //??????????????????????????????
P c = a +
P(ab.real() / 2.0, ab.imag() / 2.0); // ab???????????????????????????
double d =
sqrt(1 - pow(abs(ab) / 2.0, 2)); //????????¨ab???????????¨????????¢
res.push_back(c + nv1 * d);
res.push_back(c + nv2 * d);
}
return res;
}
int main() {
while (true) {
int n;
cin >> n;
if (!n)
break;
P p[100];
REP(i, n) {
double a, b;
scanf("%lf,%lf", &a, &b);
p[i] = P(a, b);
}
int ans = 1;
REP(i, n) {
FOR(j, i + 1, n) {
vector<P> v = intersection(p[i], p[j]);
if (v.empty())
continue;
int cnt1 = 2, cnt2 = 2;
REP(k, n) if (i != k && j != k) {
if (abs(v[0] - p[k]) - 1.0 < EPS)
cnt1++;
if (v.size() == 2 && abs(v[1] - p[k]) - 1.0 < EPS)
cnt2++;
}
ans = max(ans, max(cnt1, cnt2));
}
}
cout << ans << 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 EPS (1e-8)
typedef complex<double> P;
vector<P> intersection(P a, P b) {
vector<P> res;
if (abs(abs(b - a) - 2.0) < EPS) {
//????????\????????????
P c = a + b;
res.push_back(P(c.real() / 2.0, c.imag() / 2.0));
} else if (abs(b - a) < 2.0) {
//??????????????£?????????
P ab = b - a;
P nv1 =
(ab * P(0, +1)) / abs(ab); // ab????¨??????????????????????????????????
P nv2 = (ab * P(0, -1)) / abs(ab); //??????????????????????????????
P c = a +
P(ab.real() / 2.0, ab.imag() / 2.0); // ab???????????????????????????
double d =
sqrt(1 - pow(abs(ab) / 2.0, 2)); //????????¨ab???????????¨????????¢
res.push_back(c + nv1 * d);
res.push_back(c + nv2 * d);
}
return res;
}
int main() {
while (true) {
int n;
cin >> n;
if (!n)
break;
P p[100];
REP(i, n) {
double a, b;
scanf("%lf,%lf", &a, &b);
p[i] = P(a, b);
}
int ans = 1;
REP(i, n) {
FOR(j, i + 1, n) {
vector<P> v = intersection(p[i], p[j]);
if (v.empty())
continue;
int cnt1 = 2, cnt2 = 2;
REP(k, n) if (i != k && j != k) {
if (abs(v[0] - p[k]) - 1.0 < EPS)
cnt1++;
if (v.size() == 2 && abs(v[1] - p[k]) - 1.0 < EPS)
cnt2++;
}
ans = max(ans, max(cnt1, cnt2));
}
}
cout << ans << endl;
}
return 0;
}
|
[["-", 0, 16, 12, 2, 3, 4, 0, 16, 31, 13], ["-", 0, 16, 12, 2, 3, 4, 0, 16, 17, 33], ["-", 0, 16, 12, 2, 3, 4, 0, 16, 12, 13], ["+", 31, 23, 0, 16, 12, 2, 3, 4, 0, 13], ["+", 31, 23, 0, 16, 12, 2, 3, 4, 0, 21]]
| 1
| 465
| 6
|
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#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 << #x << " = " << (x) << endl;
#define mod 1000000007 // 1e9+7(prime number)
#define INF 1000000000 // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 100010
const double eps = 1e-9;
bool solve() {
int n;
double x[100], y[100];
vector<pair<double, double>> vec;
scanf("%d", &n);
if (n == 0)
return false;
for (int i = 0; i < n; i++) {
scanf("%lf,%lf", x + i, y + i);
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
double dx = x[j] - x[i];
double dy = y[j] - y[i];
if (dx * dx + dy * dy <= 4 + eps) {
double a = (dx * dx + dy * dy + 1 - 1) / 2;
double cx1 = (a * dx + dy * sqrt((dx * dx + dy * dy) - a * a)) /
(dx * dx + dy * dy);
double cy1 = (a * dy - dx * sqrt((dx * dx + dy * dy) - a * a)) /
(dx * dx + dy * dy);
double cx2 = (a * dx - dy * sqrt((dx * dx + dy * dy) - a * a)) /
(dx * dx + dy * dy);
double cy2 = (a * dy + dx * sqrt((dx * dx + dy * dy) - a * a)) /
(dx * dx + dy * dy);
vec.push_back({cx1 + x[i], cy1 + y[i]});
vec.push_back({cx2 + x[i], cy2 + y[i]});
}
}
}
int ans = 0;
for (int i = 0; i < vec.size(); i++) {
int counter = 0;
for (int j = 0; j < n; j++) {
double dx = x[j] - vec[i].first;
double dy = y[j] - vec[i].second;
if (dx * dx + dy * dy <= 1 + eps) {
counter++;
}
}
ans = max(ans, counter);
}
printf("%d\n", ans);
return 0;
}
int main() {
while (solve())
;
}
|
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#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 << #x << " = " << (x) << endl;
#define mod 1000000007 // 1e9+7(prime number)
#define INF 1000000000 // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 100010
const double eps = 1e-10;
bool solve() {
int n;
double x[100], y[100];
vector<pair<double, double>> vec;
scanf("%d", &n);
if (n == 0)
return false;
for (int i = 0; i < n; i++) {
scanf("%lf,%lf", x + i, y + i);
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
double dx = x[j] - x[i];
double dy = y[j] - y[i];
if (dx * dx + dy * dy <= 4 + eps) {
double a = (dx * dx + dy * dy + 1 - 1) / 2;
double cx1 = (a * dx + dy * sqrt((dx * dx + dy * dy) - a * a)) /
(dx * dx + dy * dy);
double cy1 = (a * dy - dx * sqrt((dx * dx + dy * dy) - a * a)) /
(dx * dx + dy * dy);
double cx2 = (a * dx - dy * sqrt((dx * dx + dy * dy) - a * a)) /
(dx * dx + dy * dy);
double cy2 = (a * dy + dx * sqrt((dx * dx + dy * dy) - a * a)) /
(dx * dx + dy * dy);
vec.push_back({cx1 + x[i], cy1 + y[i]});
vec.push_back({cx2 + x[i], cy2 + y[i]});
}
}
}
int ans = 1;
for (int i = 0; i < vec.size(); i++) {
int counter = 0;
for (int j = 0; j < n; j++) {
double dx = x[j] - vec[i].first;
double dy = y[j] - vec[i].second;
if (dx * dx + dy * dy <= 1 + eps) {
counter++;
}
}
ans = max(ans, counter);
}
printf("%d\n", ans);
return true;
}
int main() {
while (solve())
;
}
|
[["-", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["-", 0, 30, 0, 14, 8, 9, 0, 37, 0, 13], ["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 146]]
| 1
| 565
| 6
|
#include <cmath>
#include <iostream>
#include <vector>
#define ESP 1.0e-12
using namespace std;
struct CPoint {
CPoint() : x(-1), y(-1) {}
CPoint(double x, double y) : x(x), y(y) {}
double x, y;
};
struct CSeal {
CSeal() : r(0) {}
CSeal(double x, double y) : p(x, y), r(1.0) {}
CPoint p;
double r;
};
double Distance(const CPoint &a, const CPoint &b) {
return sqrt(pow(b.x - a.x, 2.0) + pow(b.y - a.y, 2.0));
}
double Distance(const CSeal &a, const CSeal &b) { return Distance(a.p, b.p); }
pair<CPoint, CPoint> CrossPoints(const CSeal &a, const CSeal &b) {
pair<CPoint, CPoint> ans;
if (Distance(a, b) > 2) {
ans.first.x = -1;
ans.first.y = -1;
ans.second.x = -1;
ans.second.y = -1;
return ans;
}
if (a.p.x == b.p.x) {
double D = Distance(a, b);
double off = sqrt(1 - pow((D / 2), 2));
ans.first.x = a.p.x - off;
ans.second.x = a.p.x + off;
if (a.p.y >= b.p.y)
ans.first.y = a.p.y - D / 2;
else
ans.first.y = b.p.y - D / 2;
ans.second.y = ans.first.y;
} else {
double xa = a.p.x;
double xb = b.p.x;
double ya = a.p.y;
double yb = b.p.y;
double A = (xa + xb) / 2 - ((pow(yb, 2) - pow(ya, 2)) / (2 * (xa - xb)));
double m = (yb - ya) / (xa - xb);
double aVal = 1 + pow(m, 2);
double bVal = m * (A - xb) - yb;
double cVal = pow(A, 2) + pow(xb, 2) + pow(yb, 2) - 2 * xb * A - 1;
// cout << "b=" << bVal << "\ta=" << aVal << "\tc=" << cVal << "\tD=" <<
// pow(bVal,2) - aVal * cVal << endl;
ans.first.y = (-bVal + sqrt(pow(bVal, 2) - aVal * cVal)) / aVal;
ans.second.y = (-bVal - sqrt(pow(bVal, 2) - aVal * cVal)) / aVal;
ans.first.x = A + m * ans.first.y;
ans.second.x = A + m * ans.second.y;
}
if (Distance(a, b) == 2) {
ans.second.x = -1;
ans.second.y = -1;
}
return ans;
}
inline bool inPaper(const CPoint &p) {
return p.x >= 0 && p.y >= 0 && p.x <= 10 && p.y <= 10;
}
int main(void) {
/*CSeal sa(0,0),sb(0,2);
pair<CPoint,CPoint> tmp = CrossPoints(sa,sb);
cout << tmp.first.x << " " << tmp.first.y << "," << tmp.second.x << " " <<
tmp.second.y << endl;*/
while (true) {
int n;
unsigned int maxOverlapped = 0;
vector<CSeal> vSeals;
vector<CPoint> vCrossPoints;
cin >> n;
if (n == 0)
break;
for (int i = 0; i < n; ++i) {
double x, y;
cin >> x;
cin.ignore(1);
cin >> y;
CSeal tmp(x, y);
vSeals.push_back(tmp);
}
for (unsigned int i = 0; i < vSeals.size(); ++i) {
for (unsigned int j = i; j < vSeals.size(); ++j) {
if (i != j) {
pair<CPoint, CPoint> cp;
cp = CrossPoints(vSeals[i], vSeals[j]);
if (inPaper(cp.first)) {
vCrossPoints.push_back(cp.first);
}
if (inPaper(cp.second)) {
vCrossPoints.push_back(cp.second);
}
}
}
}
for (unsigned int i = 0; i < vCrossPoints.size(); ++i) {
unsigned int overlapped = 0;
for (unsigned int j = 0; j < vSeals.size(); ++j) {
if (Distance(vCrossPoints[i], vSeals[j].p) <= 1 + ESP) {
++overlapped;
}
}
maxOverlapped = max(maxOverlapped, overlapped);
}
cout << maxOverlapped << endl;
}
return 0;
}
|
#include <cmath>
#include <iostream>
#include <vector>
#define EPS 1.0e-12
using namespace std;
struct CPoint {
CPoint() : x(-1), y(-1) {}
CPoint(double x, double y) : x(x), y(y) {}
double x, y;
};
struct CSeal {
CSeal() : r(0) {}
CSeal(double x, double y) : p(x, y), r(1.0) {}
CPoint p;
double r;
};
inline double Distance(const CPoint &a, const CPoint &b) {
return sqrt(pow(b.x - a.x, 2.0) + pow(b.y - a.y, 2.0));
}
inline double Distance(const CSeal &a, const CSeal &b) {
return Distance(a.p, b.p);
}
pair<CPoint, CPoint> CrossPoints(const CSeal &a, const CSeal &b) {
pair<CPoint, CPoint> ans;
if (Distance(a, b) > 2) {
ans.first.x = -1;
ans.first.y = -1;
ans.second.x = -1;
ans.second.y = -1;
return ans;
}
if (a.p.x == b.p.x) {
double D = Distance(a, b);
double off = sqrt(1 - pow((D / 2), 2));
ans.first.x = a.p.x - off;
ans.second.x = a.p.x + off;
if (a.p.y >= b.p.y)
ans.first.y = a.p.y - D / 2;
else
ans.first.y = b.p.y - D / 2;
ans.second.y = ans.first.y;
} else {
double xa = a.p.x;
double xb = b.p.x;
double ya = a.p.y;
double yb = b.p.y;
double A = (xa + xb) / 2 - ((pow(yb, 2) - pow(ya, 2)) / (2 * (xa - xb)));
double m = (yb - ya) / (xa - xb);
double aVal = 1 + pow(m, 2);
double bVal = m * (A - xb) - yb;
double cVal = pow(A, 2) + pow(xb, 2) + pow(yb, 2) - 2 * xb * A - 1;
// cout << "b=" << bVal << "\ta=" << aVal << "\tc=" << cVal << "\tD=" <<
// pow(bVal,2) - aVal * cVal << endl;
ans.first.y = (-bVal + sqrt(pow(bVal, 2) - aVal * cVal)) / aVal;
ans.second.y = (-bVal - sqrt(pow(bVal, 2) - aVal * cVal)) / aVal;
ans.first.x = A + m * ans.first.y;
ans.second.x = A + m * ans.second.y;
}
if (Distance(a, b) == 2) {
ans.second.x = -1;
ans.second.y = -1;
}
return ans;
}
inline bool inPaper(const CPoint &p) {
return p.x >= 0 && p.y >= 0 && p.x <= 10 && p.y <= 10;
}
int main(void) {
/*CSeal sa(0,0),sb(0,2);
pair<CPoint,CPoint> tmp = CrossPoints(sa,sb);
cout << tmp.first.x << " " << tmp.first.y << "," << tmp.second.x << " " <<
tmp.second.y << endl;*/
while (true) {
int n;
unsigned int maxOverlapped = 1;
vector<CSeal> vSeals;
vector<CPoint> vCrossPoints;
cin >> n;
if (n == 0)
break;
for (int i = 0; i < n; ++i) {
double x, y;
cin >> x;
cin.ignore(1);
cin >> y;
CSeal tmp(x, y);
vSeals.push_back(tmp);
}
for (unsigned int i = 0; i < vSeals.size(); ++i) {
for (unsigned int j = i; j < vSeals.size(); ++j) {
if (i != j) {
pair<CPoint, CPoint> cp;
cp = CrossPoints(vSeals[i], vSeals[j]);
if (inPaper(cp.first)) {
vCrossPoints.push_back(cp.first);
}
if (inPaper(cp.second)) {
vCrossPoints.push_back(cp.second);
}
}
}
}
for (unsigned int i = 0; i < vCrossPoints.size(); ++i) {
unsigned int overlapped = 0;
for (unsigned int j = 0; j < vSeals.size(); ++j) {
if (Distance(vCrossPoints[i], vSeals[j].p) <= 1 + EPS) {
++overlapped;
}
}
maxOverlapped = max(maxOverlapped, overlapped);
}
cout << maxOverlapped << endl;
}
return 0;
}
|
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 141, 22], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 141, 22], ["+", 36, 36, 0, 30, 0, 14, 0, 114, 0, 174], ["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22]]
| 1
| 990
| 8
|
#include <algorithm>
#include <assert.h>
#include <complex>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) \
for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef complex<double> Point;
int n;
Point point[200];
pair<double, int> radian[1000];
bool used[1000];
int calc(int index) {
int m = 0;
REP(i, n) {
double d = abs(point[index] - point[i]) / 2.0;
if (i == index || d - 1.0 > EPS) {
continue;
}
Point center = (point[index] - point[i]) / 2.0;
Point vect = (point[i] - point[index]) * Point(0, -1);
vect /= abs(vect);
double l = sqrt(1 - d * d);
if (isnan(l)) {
l = EPS;
}
Point c1 = center + vect * l;
Point c2 = center - vect * l;
double arg1 = arg(c1 - point[index]) - EPS;
double arg2 = arg(c2 - point[index]) + EPS;
radian[m++] = make_pair(arg1, (i + 1));
radian[m++] = make_pair(arg2, -(i + 1));
}
sort(radian, radian + m);
MEMSET(used, false);
int lsum = 1;
int ret = 1;
REP(iter, 2) {
REP(i, m) {
int p = abs(radian[i].second) - 1;
bool start = radian[i].second > 0 ? true : false;
if (start) {
used[p] = true;
lsum++;
} else if (used[p]) {
used[p] = false;
lsum--;
}
ret = max(ret, lsum);
}
}
return ret;
}
int main() {
while (scanf("%d", &n), n) {
REP(i, n) {
double x, y;
scanf("%lf,%lf", &x, &y);
point[i] = Point(x, y);
}
int ans = 1;
REP(i, n) { ans = max(ans, calc(i)); }
printf("%d\n", ans);
}
}
|
#include <algorithm>
#include <assert.h>
#include <complex>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) \
for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef complex<double> Point;
int n;
Point point[200];
pair<double, int> radian[1000];
bool used[1000];
int calc(int index) {
int m = 0;
REP(i, n) {
double d = abs(point[index] - point[i]) / 2.0;
if (i == index || d - 1.0 > EPS) {
continue;
}
Point center = (point[index] + point[i]) / 2.0;
Point vect = (point[i] - point[index]) * Point(0, -1);
vect /= abs(vect);
double l = sqrt(1 - d * d);
if (isnan(l)) {
l = EPS;
}
Point c1 = center + vect * l;
Point c2 = center - vect * l;
double arg1 = arg(c1 - point[index]) - EPS;
double arg2 = arg(c2 - point[index]) + EPS;
radian[m++] = make_pair(arg1, (i + 1));
radian[m++] = make_pair(arg2, -(i + 1));
}
sort(radian, radian + m);
MEMSET(used, false);
int lsum = 1;
int ret = 1;
REP(iter, 2) {
REP(i, m) {
int p = abs(radian[i].second) - 1;
bool start = radian[i].second > 0 ? true : false;
if (start) {
used[p] = true;
lsum++;
} else if (used[p]) {
used[p] = false;
lsum--;
}
ret = max(ret, lsum);
}
}
return ret;
}
int main() {
while (scanf("%d", &n), n) {
REP(i, n) {
double x, y;
scanf("%lf,%lf", &x, &y);
point[i] = Point(x, y);
}
int ans = 1;
REP(i, n) { ans = max(ans, calc(i)); }
printf("%d\n", ans);
}
}
|
[["-", 49, 50, 51, 16, 31, 23, 0, 16, 17, 33], ["+", 49, 50, 51, 16, 31, 23, 0, 16, 17, 72]]
| 1
| 557
| 2
|
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int, int> PI;
typedef vector<int> vi;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define F first
#define S second
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
main() {
int n;
while (cin >> n, n) {
long double x[n], y[n];
rep(i, n) {
cin >> x[i];
cin.get();
cin >> y[i];
}
int ans = 1;
rep(i, n - 1) {
for (int j = i + 1; j < n; j++) {
long double dx = x[j] - x[i], dy = y[j] - y[i];
if (dx * dx + dy * dy > 4)
continue;
int tans = 0;
long double xm = (x[j] + x[i]) / 2, ym = (y[j] + y[i]) / 2;
long double arufa = atan2(dy, dx),
beta = acos(sqrt((dx * dx + dy * dy)) / 2.0);
long double kx = x[i] + cos(arufa + beta),
ky = y[i] + sin(arufa + beta);
rep(j, n) {
if (kx < 0 || kx > 10 || ky < 0 || ky > 10)
continue;
dx = kx - x[j], dy = ky - y[j];
if (dx * dx + dy * dy <= 4)
++tans;
}
ans = max(ans, tans);
tans = 0;
kx = x[i] + cos(arufa - beta), ky = y[i] + sin(arufa - beta);
rep(j, n) {
if (kx < 0 || kx > 10 || ky < 0 || ky > 10)
continue;
dx = kx - x[j], dy = ky - y[j];
if (dx * dx + dy * dy <= 1)
++tans;
}
ans = max(ans, tans);
}
}
cout << ans << endl;
}
}
|
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int, int> PI;
typedef vector<int> vi;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define F first
#define S second
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
main() {
int n;
while (cin >> n, n) {
long double x[n], y[n];
rep(i, n) {
cin >> x[i];
cin.get();
cin >> y[i];
}
int ans = 1;
rep(i, n - 1) {
for (int j = i + 1; j < n; j++) {
long double dx = x[j] - x[i], dy = y[j] - y[i];
if (dx * dx + dy * dy > 4)
continue;
int tans = 0;
long double xm = (x[j] + x[i]) / 2, ym = (y[j] + y[i]) / 2;
long double arufa = atan2(dy, dx),
beta = acos(sqrt((dx * dx + dy * dy)) / 2.0);
long double kx = x[i] + cos(arufa + beta),
ky = y[i] + sin(arufa + beta);
rep(j, n) {
if (kx < 0 || kx > 10 || ky < 0 || ky > 10)
continue;
dx = kx - x[j], dy = ky - y[j];
if (dx * dx + dy * dy <= 1 + EPS)
++tans;
}
ans = max(ans, tans);
tans = 0;
kx = x[i] + cos(arufa - beta), ky = y[i] + sin(arufa - beta);
rep(j, n) {
if (kx < 0 || kx > 10 || ky < 0 || ky > 10)
continue;
dx = kx - x[j], dy = ky - y[j];
if (dx * dx + dy * dy <= 1 + EPS)
++tans;
}
ans = max(ans, tans);
}
}
cout << ans << endl;
}
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 31, 13], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 72], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22]]
| 1
| 546
| 6
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>
#define EPS (1e-5)
using namespace std;
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); }
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;
}
};
Point p[100];
int n;
vector<Point> cross(Point a, Point b) {
vector<Point> res;
if (fabs((b - a).abs() - 2.0) < EPS) {
Point c = a + b;
res.push_back(Point(c.x / 2.0, c.y / 2.0));
} else if ((b - a).abs() < 2.0) {
Point ab = b - a;
Point center = a + Point(ab.x / 2.0, ab.y / 2.0);
Point un1 = Point(-ab.y / ab.abs(), ab.x / ab.abs());
Point un2 = Point(ab.y / ab.abs(), -ab.x / ab.abs());
double dist = sqrt(1.0 - pow(ab.abs() / 2.0, 2.0));
Point c1 = center + un1 * dist;
Point c2 = center + un2 * dist;
res.push_back(c1);
res.push_back(c2);
}
return res;
}
int solve() {
int ans = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
vector<Point> c = cross(p[i], p[j]);
if (c.empty())
continue;
int cnt1 = 2, cnt2 = 2;
for (int k = 0; k < n; k++) {
if (i == k || j == k)
continue;
if ((c[0] - p[k]).abs() - 1.0 < EPS)
cnt1++;
if (c.size() == 2 && (c[1] - p[k]).abs() - 1.0 < EPS)
cnt2++;
}
ans = max(ans, max(cnt1, cnt2));
}
}
return ans;
}
main() {
while (1) {
cin >> n;
if (n == 0)
break;
for (int i = 0; i < n; i++) {
cin >> p[i].x;
getchar();
cin >> p[i].y;
}
cout << solve() << endl;
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>
#define EPS (1e-5)
using namespace std;
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); }
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;
}
};
Point p[100];
int n;
vector<Point> cross(Point a, Point b) {
vector<Point> res;
if (fabs((b - a).abs() - 2.0) < EPS) {
Point c = a + b;
res.push_back(Point(c.x / 2.0, c.y / 2.0));
} else if ((b - a).abs() < 2.0) {
Point ab = b - a;
Point center = a + Point(ab.x / 2.0, ab.y / 2.0);
Point un1 = Point(-ab.y / ab.abs(), ab.x / ab.abs());
Point un2 = Point(ab.y / ab.abs(), -ab.x / ab.abs());
double dist = sqrt(1.0 - pow(ab.abs() / 2.0, 2.0));
Point c1 = center + un1 * dist;
Point c2 = center + un2 * dist;
res.push_back(c1);
res.push_back(c2);
}
return res;
}
int solve() {
int ans = 1;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
vector<Point> c = cross(p[i], p[j]);
if (c.empty())
continue;
int cnt1 = 2, cnt2 = 2;
for (int k = 0; k < n; k++) {
if (i == k || j == k)
continue;
if ((c[0] - p[k]).abs() - 1.0 < EPS)
cnt1++;
if (c.size() == 2 && (c[1] - p[k]).abs() - 1.0 < EPS)
cnt2++;
}
ans = max(ans, max(cnt1, cnt2));
}
}
return ans;
}
main() {
while (1) {
cin >> n;
if (n == 0)
break;
for (int i = 0; i < n; i++) {
cin >> p[i].x;
getchar();
cin >> p[i].y;
}
cout << solve() << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 0, 7, 10, 43, 49, 50, 51, 16, 31, 22], ["+", 0, 7, 10, 43, 49, 50, 51, 16, 17, 72], ["+", 0, 7, 10, 43, 49, 50, 51, 16, 12, 13]]
| 1
| 708
| 4
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long Int;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define mp make_pair
template <class T> void pv(T a, T b) {
for (T i = a; i != b; ++i)
cout << *i << " ";
cout << endl;
}
template <class T> void chmin(T &t, T f) {
if (t > f)
t = f;
}
template <class T> void chmax(T &t, T f) {
if (t < f)
t = f;
}
int in() {
int x;
scanf("%d", &x);
return x;
}
const double EPS = 1e-10;
const double INF = 1e+10;
const double PI = acos(-1.0);
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
struct Pt {
double x, y;
Pt() {}
Pt(double x, double y) : x(x), y(y) {}
Pt operator+(const Pt &a) const { return Pt(x + a.x, y + a.y); }
Pt operator-(const Pt &a) const { return Pt(x - a.x, y - a.y); }
Pt operator*(const Pt &a) const {
return Pt(x * a.x - y * a.y, x * a.y + y * a.x);
}
Pt operator-() const { return Pt(-x, -y); }
Pt operator*(const double &k) const { return Pt(x * k, y * k); }
Pt operator/(const double &k) const { return Pt(x / k, y / k); }
double abs() const { return sqrt(x * x + y * y); }
double abs2() const { return x * x + y * y; }
double arg() const { return atan2(y, x); }
double dot(const Pt &a) const { return x * a.x + y * a.y; }
double det(const Pt &a) const { return x * a.y - y * a.x; }
bool operator<(const Pt &a) const {
return (x != a.x) ? (x < a.x) : (y < a.y);
}
bool operator==(const Pt &a) const {
return (sig(x - a.x) == 0 && sig(y - a.y) == 0);
}
};
ostream &operator<<(ostream &os, const Pt &a) {
os << "(" << a.x << ", " << a.y << ")";
return os;
}
double tri(Pt a, Pt b, Pt c) { return (b - a).det(c - a); }
pair<Pt, Pt> pCC(Pt a, double r, Pt b, double s) {
double d = (b - a).abs();
double x = (d * d + r * r - s * s) / (d * 2);
Pt e = (b - a) / d, w = e * Pt(0, 1) * sqrt(max(r * r - x * x, 0.0));
return mp(a + e * x - w, a + e * x + w);
}
int main() {
int n;
vector<Pt> vp;
while (n = in()) {
vp.clear();
int i;
Pt p;
for (i = 0; i < n; i++) {
scanf("%lf,%lf", &p.x, &p.y);
vp.push_back(p);
}
int j;
pair<Pt, Pt> pp;
Pt pt;
int max = 1;
for (i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
if ((vp[i] - vp[j]).abs() > 1)
continue;
pp = pCC(vp[i], 1, vp[j], 1);
pt = pp.first;
if (-EPS <= pt.x && pt.x <= 10 + EPS && -EPS <= pt.y &&
pt.y <= 10 + EPS) {
int k, s = 0;
for (k = 0; k < n; k++) {
if ((pt - vp[k]).abs() <= 1 + EPS) {
s++;
}
}
// cout<<"i "<<i<<endl;
// cout<<"j "<<j<<endl;
// cout<<pt<<endl;
// cout<<s<<endl;
chmax(max, s);
}
pt = pp.second;
if (-EPS <= pt.x && pt.x <= 10 + EPS && -EPS <= pt.y &&
pt.y <= 10 + EPS) {
int k, s = 0;
for (k = 0; k < n; k++) {
if ((pt - vp[k]).abs() <= 1 + EPS) {
s++;
}
}
// cout<<"i "<<i<<endl;
// cout<<"j "<<j<<endl;
// cout<<pt<<endl;
// cout<<s<<endl;
chmax(max, s);
}
}
}
cout << max << endl;
}
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long Int;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define mp make_pair
template <class T> void pv(T a, T b) {
for (T i = a; i != b; ++i)
cout << *i << " ";
cout << endl;
}
template <class T> void chmin(T &t, T f) {
if (t > f)
t = f;
}
template <class T> void chmax(T &t, T f) {
if (t < f)
t = f;
}
int in() {
int x;
scanf("%d", &x);
return x;
}
const double EPS = 1e-10;
const double INF = 1e+10;
const double PI = acos(-1.0);
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
struct Pt {
double x, y;
Pt() {}
Pt(double x, double y) : x(x), y(y) {}
Pt operator+(const Pt &a) const { return Pt(x + a.x, y + a.y); }
Pt operator-(const Pt &a) const { return Pt(x - a.x, y - a.y); }
Pt operator*(const Pt &a) const {
return Pt(x * a.x - y * a.y, x * a.y + y * a.x);
}
Pt operator-() const { return Pt(-x, -y); }
Pt operator*(const double &k) const { return Pt(x * k, y * k); }
Pt operator/(const double &k) const { return Pt(x / k, y / k); }
double abs() const { return sqrt(x * x + y * y); }
double abs2() const { return x * x + y * y; }
double arg() const { return atan2(y, x); }
double dot(const Pt &a) const { return x * a.x + y * a.y; }
double det(const Pt &a) const { return x * a.y - y * a.x; }
bool operator<(const Pt &a) const {
return (x != a.x) ? (x < a.x) : (y < a.y);
}
bool operator==(const Pt &a) const {
return (sig(x - a.x) == 0 && sig(y - a.y) == 0);
}
};
ostream &operator<<(ostream &os, const Pt &a) {
os << "(" << a.x << ", " << a.y << ")";
return os;
}
double tri(Pt a, Pt b, Pt c) { return (b - a).det(c - a); }
pair<Pt, Pt> pCC(Pt a, double r, Pt b, double s) {
double d = (b - a).abs();
double x = (d * d + r * r - s * s) / (d * 2);
Pt e = (b - a) / d, w = e * Pt(0, 1) * sqrt(max(r * r - x * x, 0.0));
return mp(a + e * x - w, a + e * x + w);
}
int main() {
int n;
vector<Pt> vp;
while (n = in()) {
vp.clear();
int i;
Pt p;
for (i = 0; i < n; i++) {
scanf("%lf,%lf", &p.x, &p.y);
vp.push_back(p);
}
int j;
pair<Pt, Pt> pp;
Pt pt;
int max = 1;
for (i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
if ((vp[i] - vp[j]).abs() > 2)
continue;
pp = pCC(vp[i], 1, vp[j], 1);
pt = pp.first;
if (-EPS <= pt.x && pt.x <= 10 + EPS && -EPS <= pt.y &&
pt.y <= 10 + EPS) {
int k, s = 0;
for (k = 0; k < n; k++) {
if ((pt - vp[k]).abs() <= 1 + EPS) {
s++;
}
}
// cout<<"i "<<i<<endl;
// cout<<"j "<<j<<endl;
// cout<<pt<<endl;
// cout<<s<<endl;
chmax(max, s);
}
pt = pp.second;
if (-EPS <= pt.x && pt.x <= 10 + EPS && -EPS <= pt.y &&
pt.y <= 10 + EPS) {
int k, s = 0;
for (k = 0; k < n; k++) {
if ((pt - vp[k]).abs() <= 1 + EPS) {
s++;
}
}
// cout<<"i "<<i<<endl;
// cout<<"j "<<j<<endl;
// cout<<pt<<endl;
// cout<<s<<endl;
chmax(max, s);
}
}
}
cout << max << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
| 1
| 1,156
| 2
|
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
class Point {
public:
double y, x;
Point() { y = x = 0.0; }
Point(double y0, double x0) {
y = y0;
x = x0;
}
double dot(const Point &p) const {
return y * p.y + x * p.x; // |a|*|b|*cosÆ
}
double cross(const Point &p) const {
return x * p.y - y * p.x; // |a|*|b|*sinÆ
}
Point operator+(const Point &p) const { return Point(y + p.y, x + p.x); }
Point operator-(const Point &p) const { return Point(y - p.y, x - p.x); }
Point operator*(double a) const { return Point(y * a, x * a); }
Point operator/(double a) const { return Point(y / a, x * a); }
};
const double EPS = 1.0e-10;
vector<Point> circlesIntersection(const Point &p1, double r1, const Point &p2,
double r2) {
double y = p2.y - p1.y;
double x = p2.x - p1.x;
double a = (y * y + x * x + r1 * r1 - r2 * r2) / 2;
double b = (y * y + x * x) * r1 * r1 - a * a;
if (y * y + x * x < EPS || b < -EPS)
return vector<Point>(0);
if (b < EPS)
return vector<Point>(1, Point(y, x) * (a / (y * y + x * x)) + p1);
vector<Point> ret(2, Point(x * sqrt(b), -y * sqrt(b)));
ret[1] = ret[1] * -1;
for (int i = 0; i < 2; ++i)
ret[i] = (ret[i] + Point(y, x) * a) / (y * y + x * x) + p1;
return ret;
}
int main() {
for (;;) {
int n;
cin >> n;
if (n == 0)
return 0;
vector<Point> p(n);
for (int i = 0; i < n; ++i) {
char c;
cin >> p[i].x >> c >> p[i].y;
}
int ret = 1;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
vector<Point> p2 = circlesIntersection(p[i], 1, p[j], 1);
for (unsigned k = 0; k < p2.size(); ++k) {
int tmp = 0;
for (int l = 0; l < n; ++l) {
if (pow(p[l].y - p2[k].y, 2) + pow(p[l].x - p2[k].x, 2) <= 2 + EPS)
++tmp;
}
ret = max(ret, tmp);
}
}
}
cout << ret << endl;
}
}
|
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
class Point {
public:
double y, x;
Point() { y = x = 0.0; }
Point(double y0, double x0) {
y = y0;
x = x0;
}
double dot(const Point &p) const {
return y * p.y + x * p.x; // |a|*|b|*cosÆ
}
double cross(const Point &p) const {
return x * p.y - y * p.x; // |a|*|b|*sinÆ
}
Point operator+(const Point &p) const { return Point(y + p.y, x + p.x); }
Point operator-(const Point &p) const { return Point(y - p.y, x - p.x); }
Point operator*(double a) const { return Point(y * a, x * a); }
Point operator/(double a) const { return Point(y / a, x / a); }
};
const double EPS = 1.0e-10;
vector<Point> circlesIntersection(const Point &p1, double r1, const Point &p2,
double r2) {
double y = p2.y - p1.y;
double x = p2.x - p1.x;
double a = (y * y + x * x + r1 * r1 - r2 * r2) / 2;
double b = (y * y + x * x) * r1 * r1 - a * a;
if (y * y + x * x < EPS || b < -EPS)
return vector<Point>(0);
if (b < EPS)
return vector<Point>(1, Point(y, x) * (a / (y * y + x * x)) + p1);
vector<Point> ret(2, Point(x * sqrt(b), -y * sqrt(b)));
ret[1] = ret[1] * -1;
for (int i = 0; i < 2; ++i)
ret[i] = (ret[i] + Point(y, x) * a) / (y * y + x * x) + p1;
return ret;
}
int main() {
for (;;) {
int n;
cin >> n;
if (n == 0)
return 0;
vector<Point> p(n);
for (int i = 0; i < n; ++i) {
char c;
cin >> p[i].x >> c >> p[i].y;
}
int ret = 1;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
vector<Point> p2 = circlesIntersection(p[i], 1, p[j], 1);
for (unsigned k = 0; k < p2.size(); ++k) {
int tmp = 0;
for (int l = 0; l < n; ++l) {
if (pow(p[l].y - p2[k].y, 2) + pow(p[l].x - p2[k].x, 2) <= 1 + EPS)
++tmp;
}
ret = max(ret, tmp);
}
}
}
cout << ret << endl;
}
}
|
[["-", 0, 37, 0, 2, 3, 4, 0, 16, 17, 48], ["+", 0, 37, 0, 2, 3, 4, 0, 16, 17, 85], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 31, 13], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 31, 13]]
| 1
| 716
| 4
|
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
double x[100], y[100];
double px[10000], py[10000];
int main() {
int a;
while (scanf("%d", &a), a) {
for (int i = 0; i < a; i++)
scanf("%lf,%lf", x + i, y + i);
int now = 0;
for (int i = 0; i < a; i++) {
for (int j = i + 1; j < a; j++) {
if ((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]) <
4.0000001) {
double d = sqrt((x[i] - x[j]) * (x[i] - x[j]) +
(y[i] - y[j]) * (y[i] - y[j]));
double mx = (x[i] + x[j]) / 2;
double my = (y[i] + y[j]) / 2;
double s = sqrt(1 - d * d / 4);
double theta = atan((y[i] - y[j]) / (x[i] - x[j]));
px[now] = mx - sin(theta) * s;
py[now++] = my + cos(theta) * s;
px[now] = mx + sin(theta) * s;
py[now++] = my - cos(theta) * s;
}
}
}
int ret = 0;
for (int i = 0; i < now; i++) {
int k = 0;
for (int j = 0; j < a; j++)
if ((px[i] - x[j]) * (px[i] - x[j]) + (py[i] - y[j]) * (py[i] - y[j]) <
1.0000001)
k++;
ret = max(ret, k);
}
printf("%d\n", ret);
}
}
|
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
double x[100], y[100];
double px[10000], py[10000];
int main() {
int a;
while (scanf("%d", &a), a) {
for (int i = 0; i < a; i++)
scanf("%lf,%lf", x + i, y + i);
int now = 0;
for (int i = 0; i < a; i++) {
for (int j = i + 1; j < a; j++) {
if ((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]) <
4.0000001) {
double d = sqrt((x[i] - x[j]) * (x[i] - x[j]) +
(y[i] - y[j]) * (y[i] - y[j]));
double mx = (x[i] + x[j]) / 2;
double my = (y[i] + y[j]) / 2;
double s = sqrt(1 - d * d / 4);
double theta = atan((y[i] - y[j]) / (x[i] - x[j]));
px[now] = mx - sin(theta) * s;
py[now++] = my + cos(theta) * s;
px[now] = mx + sin(theta) * s;
py[now++] = my - cos(theta) * s;
}
}
}
int ret = 1;
for (int i = 0; i < now; i++) {
int k = 0;
for (int j = 0; j < a; j++)
if ((px[i] - x[j]) * (px[i] - x[j]) + (py[i] - y[j]) * (py[i] - y[j]) <
1.0000001)
k++;
ret = max(ret, k);
}
printf("%d\n", ret);
}
}
|
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
| 1
| 483
| 2
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
using namespace std;
#define EPS 1e-5
typedef pair<double, double> point, circle;
void intrsc(const circle &c1, const circle &c2, vector<point> &v) {
double a, b, c, d, e, f, g, D;
double x1, x2, y1, y2, ix1, ix2, iy1, iy2;
x1 = c1.first;
x2 = c2.first;
y1 = c1.second;
y2 = c2.second;
a = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2;
b = 2.0 * (y1 - y2);
c = 2.0 * (x1 - x2);
d = b * b + c * c;
e = b * c * y1 - a * c - b * b * x1;
f = b * b * (x1 * x1 + y1 * y1 - 1.0) + a * a - 2 * a * b * y1;
D = e * e - d * f;
if (D >= 0) {
if (abs(d) < EPS) {
v.push_back(point(x1 + 1.0, y1));
return;
}
g = sqrt(D);
ix1 = (-e + g) / d;
ix2 = (-e - g) / d;
if (abs(b) < EPS) {
iy1 = sqrt(1.0 - (ix1 - x1) * (ix1 - x1));
iy2 = y1 - iy1;
iy1 += y1;
} else {
iy1 = (a - c * ix1) / b;
iy2 = (a - c * ix2) / b;
}
v.push_back(point(ix1, iy1));
v.push_back(point(ix2, iy2));
}
}
inline bool in(const point &p, const circle &c) {
return (p.first - c.first) * (p.first - c.first) +
(p.second - c.second) * (p.second - c.second) <=
1.0 + EPS;
}
int main() {
int n;
double x, y;
for (; scanf("%d", &n), n;) {
vector<point> v;
vector<circle> crcl(n);
for (int i = 0; i < n; i++) {
scanf("%lf,%lf", &x, &y);
crcl[i] = circle(x, y);
}
for (int i = 0; i < n - 1; i++)
for (int j = i + 1; j < n; j++)
intrsc(crcl[i], crcl[j], v);
/*for(vector<point>::iterator it=v.begin();it!=v.end();++it){
printf("\t%f\t%f\n",it->first,it->second);
}*/
int m = 0;
for (vector<point>::iterator p_it = v.begin(); p_it != v.end(); ++p_it) {
int cnt = 0;
for (vector<circle>::iterator it = crcl.begin(); it != crcl.end(); ++it) {
if (in(*p_it, *it))
cnt++;
}
m = max(m, cnt);
}
printf("%d\n", m);
}
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
using namespace std;
#define EPS 1e-7
typedef pair<double, double> point, circle;
void intrsc(const circle &c1, const circle &c2, vector<point> &v) {
double a, b, c, d, e, f, g, D;
double x1, x2, y1, y2, ix1, ix2, iy1, iy2;
x1 = c1.first;
x2 = c2.first;
y1 = c1.second;
y2 = c2.second;
a = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2;
b = 2.0 * (y1 - y2);
c = 2.0 * (x1 - x2);
d = b * b + c * c;
e = b * c * y1 - a * c - b * b * x1;
f = b * b * (x1 * x1 + y1 * y1 - 1.0) + a * a - 2 * a * b * y1;
D = e * e - d * f;
if (D >= 0) {
if (abs(d) < EPS) {
v.push_back(point(x1 + 1.0, y1));
return;
}
g = sqrt(D);
ix1 = (-e + g) / d;
ix2 = (-e - g) / d;
if (abs(b) < EPS) {
iy1 = sqrt(1.0 - (ix1 - x1) * (ix1 - x1));
iy2 = y1 - iy1;
iy1 += y1;
} else {
iy1 = (a - c * ix1) / b;
iy2 = (a - c * ix2) / b;
}
v.push_back(point(ix1, iy1));
v.push_back(point(ix2, iy2));
}
}
inline bool in(const point &p, const circle &c) {
return (p.first - c.first) * (p.first - c.first) +
(p.second - c.second) * (p.second - c.second) <=
1.0 + EPS;
}
int main() {
int n;
double x, y;
for (; scanf("%d", &n), n;) {
vector<point> v;
vector<circle> crcl(n);
for (int i = 0; i < n; i++) {
scanf("%lf,%lf", &x, &y);
crcl[i] = circle(x, y);
}
for (int i = 0; i < n - 1; i++)
for (int j = i + 1; j < n; j++)
intrsc(crcl[i], crcl[j], v);
/*for(vector<point>::iterator it=v.begin();it!=v.end();++it){
printf("\t%f\t%f\n",it->first,it->second);
}*/
int m = 1;
for (vector<point>::iterator p_it = v.begin(); p_it != v.end(); ++p_it) {
int cnt = 0;
for (vector<circle>::iterator it = crcl.begin(); it != crcl.end(); ++it) {
if (in(*p_it, *it))
cnt++;
}
m = max(m, cnt);
}
printf("%d\n", m);
}
}
|
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["-", 0, 7, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 7, 8, 9, 0, 43, 49, 50, 51, 13]]
| 1
| 665
| 4
|
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
typedef pair<double, double> P;
double EPS = 1e-10;
double add(double a, double b) {
if (abs(a + b) < EPS * (abs(a) + abs(b)))
return 0;
return a + b;
}
struct point {
double x, y;
point() {}
point(double x, double y) : x(x), y(y) {}
point operator+(point p) { return point(add(x, p.x), add(y, p.y)); }
point operator-(point p) { return point(add(x, -p.x), add(y, -p.y)); }
point operator*(double d) { return point(x * d, y * d); }
point operator/(double d) { return point(x / d, y / d); }
};
struct circle {
point p;
double r;
};
vector<point> circles_cross(circle a, circle b) {
vector<point> ret;
double x = a.p.x - b.p.x, y = a.p.y - b.p.y;
double L = x * x + y * y;
if (L > pow(a.r + b.r, 2))
return ret;
L = sqrt(L);
double C = atan2(b.p.y - a.p.y, b.p.x - a.p.x);
double alpha = acos((L * L + a.r * a.r - b.r * b.r) / (2 * L * a.r));
point r1, r2;
r1.x = a.p.x + cos(C + alpha), r1.y = a.p.y + sin(C + alpha);
r2.x = a.p.x + cos(C - alpha), r2.y = a.p.y + sin(C - alpha);
ret.push_back(r1), ret.push_back(r2);
return ret;
}
int main(void) {
int n;
circle a[100];
while (cin >> n, n) {
vector<P> d;
for (int i = 0; i < n; i++) {
scanf("%lf,%lf", &a[i].p.x, &a[i].p.y);
a[i].r = 1;
}
/*
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
double L=sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2));
if(L>2.0000)continue;
double theta=atan2(y[j]-y[i],x[j]-x[i]);
double a=acos(L/2);
d.push_back(make_pair(x[i]+cos(theta+a),y[i]+sin(theta+a)));
d.push_back(make_pair(x[i]+cos(theta-a),y[i]+sin(theta-a)));
}
}
*/
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
vector<point> p = circles_cross(a[i], a[j]);
for (int k = 0; k < p.size(); k++) {
d.push_back(make_pair(p[k].x, p[k].y));
}
}
}
/*
for(int i=0;i<d.size();i++){
cout << d[i].first << " " <<d[i].second << endl;
}
*/
int count, ans = 1;
for (int i = 0; i < d.size(); i++) {
count = 0;
for (int j = 0; j < n; j++) {
if (pow(d[i].first - a[j].p.x, 2) + pow(d[i].second - a[j].p.y, 2) <=
1.0)
count++;
}
ans = max(ans, count);
}
cout << ans << endl;
}
return 0;
}
|
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
typedef pair<double, double> P;
double EPS = 1e-10;
double add(double a, double b) {
if (abs(a + b) < EPS * (abs(a) + abs(b)))
return 0;
return a + b;
}
struct point {
double x, y;
point() {}
point(double x, double y) : x(x), y(y) {}
point operator+(point p) { return point(add(x, p.x), add(y, p.y)); }
point operator-(point p) { return point(add(x, -p.x), add(y, -p.y)); }
point operator*(double d) { return point(x * d, y * d); }
point operator/(double d) { return point(x / d, y / d); }
};
struct circle {
point p;
double r;
};
vector<point> circles_cross(circle a, circle b) {
vector<point> ret;
double x = a.p.x - b.p.x, y = a.p.y - b.p.y;
double L = x * x + y * y;
if (L > pow(a.r + b.r, 2))
return ret;
L = sqrt(L);
double C = atan2(b.p.y - a.p.y, b.p.x - a.p.x);
double alpha = acos((L * L + a.r * a.r - b.r * b.r) / (2 * L * a.r));
point r1, r2;
r1.x = a.p.x + cos(C + alpha), r1.y = a.p.y + sin(C + alpha);
r2.x = a.p.x + cos(C - alpha), r2.y = a.p.y + sin(C - alpha);
ret.push_back(r1), ret.push_back(r2);
return ret;
}
int main(void) {
int n;
circle a[100];
while (cin >> n, n) {
vector<P> d;
for (int i = 0; i < n; i++) {
scanf("%lf,%lf", &a[i].p.x, &a[i].p.y);
a[i].r = 1;
}
/*
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
double L=sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2));
if(L>2.0000)continue;
double theta=atan2(y[j]-y[i],x[j]-x[i]);
double a=acos(L/2);
d.push_back(make_pair(x[i]+cos(theta+a),y[i]+sin(theta+a)));
d.push_back(make_pair(x[i]+cos(theta-a),y[i]+sin(theta-a)));
}
}
*/
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
vector<point> p = circles_cross(a[i], a[j]);
for (int k = 0; k < p.size(); k++) {
d.push_back(make_pair(p[k].x, p[k].y));
}
}
}
/*
for(int i=0;i<d.size();i++){
cout << d[i].first << " " <<d[i].second << endl;
}
*/
int count, ans = 1;
for (int i = 0; i < d.size(); i++) {
count = 0;
for (int j = 0; j < n; j++) {
if (pow(d[i].first - a[j].p.x, 2) + pow(d[i].second - a[j].p.y, 2) <=
1.0 + EPS)
count++;
}
ans = max(ans, count);
}
cout << ans << endl;
}
return 0;
}
|
[["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 72], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22]]
| 1
| 760
| 2
|
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <vector>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define EPS (1e-10)
#define COUNTER_CLOCKWISE 1
#define CLOCKWISE -1
#define ONLINE_BACK 2
#define ONLINE_FRONT -2
#define ON_SEGMENT 0
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef pair<double, double> BB;
class Point {
public:
double x, y;
Point(double x = -1, double y = -1) : 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 Segment {
Point p1, p2;
Segment(Point p1 = Point(-1, -1), Point p2 = Point(-1, -1))
: p1(p1), p2(p2) {}
};
typedef Point Vector;
typedef Segment Line;
typedef vector<Point> Polygon;
struct Circle {
Point p;
double r;
Circle(Point p = Point(0, 0), double r = 0) : p(p), r(r) {}
bool operator<(const Circle &a) const {
if (p.x != a.p.x)
return p.x < a.p.x;
if (p.y != a.p.y)
return p.y < a.p.y;
return r < a.r;
}
};
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; }
double norm(Point a) { return a.x * a.x + a.y * a.y; }
int ccw(Point p0, Point p1, Point p2) {
Point a = p1 - p0;
Point b = p2 - p0;
if (cross(a, b) > 0)
return COUNTER_CLOCKWISE;
if (cross(a, b) < 0)
return CLOCKWISE;
if (dot(a, b) < 0)
return ONLINE_BACK;
if (norm(a) < norm(b))
return ONLINE_FRONT;
return ON_SEGMENT;
}
bool isIntersectCC(Circle a, Circle b) {
double d = sqrt(norm(a.p - b.p));
double r1 = max(a.r, b.r);
double r2 = min(a.r, b.r);
if (d > r1 + r2)
return false;
if (d < r1 - r2)
return false;
return true;
}
pair<Point, Point> getPointsCC(Circle a, Circle b) {
// assert(isIntersectCC(a,b));
complex<double> c1, c2;
c1 = complex<double>(a.p.x, a.p.y);
c2 = complex<double>(b.p.x, b.p.y);
double r1 = a.r;
double r2 = b.r;
complex<double> nf[2];
nf[0] = complex<double>(a.p.x, a.p.y);
nf[1] = complex<double>(b.p.x, b.p.y);
double MD = sqrt(1 - 0.25 * norm(nf[1] - nf[0]));
complex<double> mid = (nf[0] + nf[1]) * 0.5;
complex<double> p1 =
mid + (nf[0] - nf[1]) / abs(nf[0] - nf[1]) * polar(MD, M_PI / 2);
complex<double> p2 =
mid + (nf[0] - nf[1]) / abs(nf[0] - nf[1]) * polar(MD, -M_PI / 2);
return pair<Point, Point>(Point(p1.real(), p1.imag()),
Point(p2.real(), p2.imag()));
complex<double> A = conj(c2 - c1),
B = (r2 * r2 - r1 * r1 - (c2 - c1) * conj(c2 - c1)),
C = r1 * r1 * (c2 - c1);
complex<double> D = B * B - 4.0 * A * C;
complex<double> z1 = (-B + sqrt(D)) / (2.0 * A) + c1,
z2 = (-B - sqrt(D)) / (2.0 * A) + c1;
Point R1, R2;
R1 = Point(z1.real(), z1.imag());
R2 = Point(z2.real(), z2.imag());
return pair<Point, Point>(R1, R2);
}
int main() {
int n;
while (cin >> n, n) {
vector<Circle> c(n);
rep(i, n) {
scanf("%lf,%lf", &c[i].p.x, &c[i].p.y);
c[i].r = 1.0;
}
int ans = 0;
rep(i, n) {
REP(j, i + 1, n) {
if (sqrt(norm(c[i].p - c[j].p)) >= 2.0 + EPS)
continue;
pair<Point, Point> pp = getPointsCC(c[i], c[j]);
int cnt = 0;
Point p1 = pp.first;
Point p2 = pp.second;
rep(k, n) if (sqrt(norm(p1 - c[k].p)) < EPS + 1.0) cnt++;
ans = (ans < cnt ? cnt : ans);
cnt = 0;
rep(k, n) if (sqrt(norm(p2 - c[k].p)) < EPS + 1.0) cnt++;
ans = (ans < cnt ? cnt : ans);
}
}
cout << ans << endl;
}
return 0;
}
|
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <vector>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define EPS (1e-10)
#define COUNTER_CLOCKWISE 1
#define CLOCKWISE -1
#define ONLINE_BACK 2
#define ONLINE_FRONT -2
#define ON_SEGMENT 0
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef pair<double, double> BB;
class Point {
public:
double x, y;
Point(double x = -1, double y = -1) : 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 Segment {
Point p1, p2;
Segment(Point p1 = Point(-1, -1), Point p2 = Point(-1, -1))
: p1(p1), p2(p2) {}
};
typedef Point Vector;
typedef Segment Line;
typedef vector<Point> Polygon;
struct Circle {
Point p;
double r;
Circle(Point p = Point(0, 0), double r = 0) : p(p), r(r) {}
bool operator<(const Circle &a) const {
if (p.x != a.p.x)
return p.x < a.p.x;
if (p.y != a.p.y)
return p.y < a.p.y;
return r < a.r;
}
};
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; }
double norm(Point a) { return a.x * a.x + a.y * a.y; }
int ccw(Point p0, Point p1, Point p2) {
Point a = p1 - p0;
Point b = p2 - p0;
if (cross(a, b) > 0)
return COUNTER_CLOCKWISE;
if (cross(a, b) < 0)
return CLOCKWISE;
if (dot(a, b) < 0)
return ONLINE_BACK;
if (norm(a) < norm(b))
return ONLINE_FRONT;
return ON_SEGMENT;
}
bool isIntersectCC(Circle a, Circle b) {
double d = sqrt(norm(a.p - b.p));
double r1 = max(a.r, b.r);
double r2 = min(a.r, b.r);
if (d > r1 + r2)
return false;
if (d < r1 - r2)
return false;
return true;
}
pair<Point, Point> getPointsCC(Circle a, Circle b) {
// assert(isIntersectCC(a,b));
complex<double> c1, c2;
c1 = complex<double>(a.p.x, a.p.y);
c2 = complex<double>(b.p.x, b.p.y);
double r1 = a.r;
double r2 = b.r;
complex<double> nf[2];
nf[0] = complex<double>(a.p.x, a.p.y);
nf[1] = complex<double>(b.p.x, b.p.y);
double MD = sqrt(1 - 0.25 * norm(nf[1] - nf[0]));
complex<double> mid = (nf[0] + nf[1]) * 0.5;
complex<double> p1 =
mid + (nf[0] - nf[1]) / abs(nf[0] - nf[1]) * polar(MD, M_PI / 2);
complex<double> p2 =
mid + (nf[0] - nf[1]) / abs(nf[0] - nf[1]) * polar(MD, -M_PI / 2);
return pair<Point, Point>(Point(p1.real(), p1.imag()),
Point(p2.real(), p2.imag()));
complex<double> A = conj(c2 - c1),
B = (r2 * r2 - r1 * r1 - (c2 - c1) * conj(c2 - c1)),
C = r1 * r1 * (c2 - c1);
complex<double> D = B * B - 4.0 * A * C;
complex<double> z1 = (-B + sqrt(D)) / (2.0 * A) + c1,
z2 = (-B - sqrt(D)) / (2.0 * A) + c1;
Point R1, R2;
R1 = Point(z1.real(), z1.imag());
R2 = Point(z2.real(), z2.imag());
return pair<Point, Point>(R1, R2);
}
int main() {
int n;
while (cin >> n, n) {
vector<Circle> c(n);
rep(i, n) {
scanf("%lf,%lf", &c[i].p.x, &c[i].p.y);
c[i].r = 1.0;
}
int ans = 1;
rep(i, n) {
REP(j, i + 1, n) {
if (sqrt(norm(c[i].p - c[j].p)) >= 2.0 + EPS)
continue;
pair<Point, Point> pp = getPointsCC(c[i], c[j]);
int cnt = 0;
Point p1 = pp.first;
Point p2 = pp.second;
rep(k, n) if (sqrt(norm(p1 - c[k].p)) < EPS + 1.0) cnt++;
ans = (ans < cnt ? cnt : ans);
cnt = 0;
rep(k, n) if (sqrt(norm(p2 - c[k].p)) < EPS + 1.0) cnt++;
ans = (ans < cnt ? 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
| 1,410
| 2
|
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <vector>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define EPS (1e-10)
#define COUNTER_CLOCKWISE 1
#define CLOCKWISE -1
#define ONLINE_BACK 2
#define ONLINE_FRONT -2
#define ON_SEGMENT 0
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef pair<double, double> BB;
class Point {
public:
double x, y;
Point(double x = -1, double y = -1) : 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 Segment {
Point p1, p2;
Segment(Point p1 = Point(-1, -1), Point p2 = Point(-1, -1))
: p1(p1), p2(p2) {}
};
typedef Point Vector;
typedef Segment Line;
typedef vector<Point> Polygon;
struct Circle {
Point p;
double r;
Circle(Point p = Point(0, 0), double r = 0) : p(p), r(r) {}
bool operator<(const Circle &a) const {
if (p.x != a.p.x)
return p.x < a.p.x;
if (p.y != a.p.y)
return p.y < a.p.y;
return r < a.r;
}
};
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; }
double norm(Point a) { return a.x * a.x + a.y * a.y; }
int ccw(Point p0, Point p1, Point p2) {
Point a = p1 - p0;
Point b = p2 - p0;
if (cross(a, b) > 0)
return COUNTER_CLOCKWISE;
if (cross(a, b) < 0)
return CLOCKWISE;
if (dot(a, b) < 0)
return ONLINE_BACK;
if (norm(a) < norm(b))
return ONLINE_FRONT;
return ON_SEGMENT;
}
bool isIntersectCC(Circle a, Circle b) {
double d = sqrt(norm(a.p - b.p));
double r1 = max(a.r, b.r);
double r2 = min(a.r, b.r);
if (d > r1 + r2)
return false;
if (d < r1 - r2)
return false;
return true;
}
pair<Point, Point> getPointsCC(Circle a, Circle b) {
// assert(isIntersectCC(a,b));
complex<double> c1, c2;
c1 = complex<double>(a.p.x, a.p.y);
c2 = complex<double>(b.p.x, b.p.y);
double r1 = a.r;
double r2 = b.r;
complex<double> A = conj(c2 - c1),
B = (r2 * r2 - r1 * r1 - (c2 - c1) * conj(c2 - c1)),
C = r1 * r1 * (c2 - c1);
complex<double> D = B * B - 4.0 * A * C;
complex<double> z1 = (-B + sqrt(D)) / (2.0 * A) + c1,
z2 = (-B - sqrt(D)) / (2.0 * A) + c1;
Point R1, R2;
R1 = Point(z1.real(), z1.imag());
R2 = Point(z2.real(), z2.imag());
return pair<Point, Point>(R1, R2);
}
int main() {
int n;
while (cin >> n, n) {
vector<Circle> c(n);
rep(i, n) {
scanf("%lf,%lf", &c[i].p.x, &c[i].p.y);
c[i].r = 1.0;
}
int ans = 0;
rep(i, n) {
REP(j, i + 1, n) {
if (sqrt(norm(c[i].p - c[j].p)) >= 2.0 + EPS)
continue;
pair<Point, Point> pp = getPointsCC(c[i], c[j]);
int cnt = 0;
Point p1 = pp.first;
Point p2 = pp.second;
rep(k, n) if (sqrt(norm(p1 - c[k].p)) < EPS + 1.0) cnt++;
ans = (ans < cnt ? cnt : ans);
cnt = 0;
rep(k, n) if (sqrt(norm(p2 - c[k].p)) < EPS + 1.0) cnt++;
ans = (ans < cnt ? cnt : ans);
}
}
cout << ans << endl;
}
return 0;
}
|
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <vector>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define EPS (1e-10)
#define COUNTER_CLOCKWISE 1
#define CLOCKWISE -1
#define ONLINE_BACK 2
#define ONLINE_FRONT -2
#define ON_SEGMENT 0
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef pair<double, double> BB;
class Point {
public:
double x, y;
Point(double x = -1, double y = -1) : 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 Segment {
Point p1, p2;
Segment(Point p1 = Point(-1, -1), Point p2 = Point(-1, -1))
: p1(p1), p2(p2) {}
};
typedef Point Vector;
typedef Segment Line;
typedef vector<Point> Polygon;
struct Circle {
Point p;
double r;
Circle(Point p = Point(0, 0), double r = 0) : p(p), r(r) {}
bool operator<(const Circle &a) const {
if (p.x != a.p.x)
return p.x < a.p.x;
if (p.y != a.p.y)
return p.y < a.p.y;
return r < a.r;
}
};
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; }
double norm(Point a) { return a.x * a.x + a.y * a.y; }
int ccw(Point p0, Point p1, Point p2) {
Point a = p1 - p0;
Point b = p2 - p0;
if (cross(a, b) > 0)
return COUNTER_CLOCKWISE;
if (cross(a, b) < 0)
return CLOCKWISE;
if (dot(a, b) < 0)
return ONLINE_BACK;
if (norm(a) < norm(b))
return ONLINE_FRONT;
return ON_SEGMENT;
}
bool isIntersectCC(Circle a, Circle b) {
double d = sqrt(norm(a.p - b.p));
double r1 = max(a.r, b.r);
double r2 = min(a.r, b.r);
if (d > r1 + r2)
return false;
if (d < r1 - r2)
return false;
return true;
}
pair<Point, Point> getPointsCC(Circle a, Circle b) {
// assert(isIntersectCC(a,b));
complex<double> c1, c2;
c1 = complex<double>(a.p.x, a.p.y);
c2 = complex<double>(b.p.x, b.p.y);
double r1 = a.r;
double r2 = b.r;
/*
complex<double> nf[2];
nf[0] = complex<double>(a.p.x,a.p.y);
nf[1] = complex<double>(b.p.x,b.p.y);
double MD = sqrt(1-0.25*norm(nf[1]-nf[0]));
complex<double> mid = (nf[0]+nf[1])*0.5;
complex<double> p1 = mid + (nf[0]-nf[1])/abs(nf[0]-nf[1])*polar(MD,M_PI/2);
complex<double> p2 = mid + (nf[0]-nf[1])/abs(nf[0]-nf[1])*polar(MD,-M_PI/2);
return
pair<Point,Point>(Point(p1.real(),p1.imag()),Point(p2.real(),p2.imag()));
*/
complex<double> A = conj(c2 - c1),
B = (r2 * r2 - r1 * r1 - (c2 - c1) * conj(c2 - c1)),
C = r1 * r1 * (c2 - c1);
complex<double> D = B * B - 4.0 * A * C;
complex<double> z1 = (-B + sqrt(D)) / (2.0 * A) + c1,
z2 = (-B - sqrt(D)) / (2.0 * A) + c1;
Point R1, R2;
R1 = Point(z1.real(), z1.imag());
R2 = Point(z2.real(), z2.imag());
return pair<Point, Point>(R1, R2);
}
int main() {
int n;
while (cin >> n, n) {
vector<Circle> c(n);
rep(i, n) {
scanf("%lf,%lf", &c[i].p.x, &c[i].p.y);
c[i].r = 1.0;
}
int ans = 1;
rep(i, n) {
REP(j, i + 1, n) {
if (sqrt(norm(c[i].p - c[j].p)) >= 2.0 + EPS)
continue;
pair<Point, Point> pp = getPointsCC(c[i], c[j]);
int cnt = 0;
Point p1 = pp.first;
Point p2 = pp.second;
rep(k, n) if (sqrt(norm(p1 - c[k].p)) < EPS + 1.0) cnt++;
ans = (ans < cnt ? cnt : ans);
cnt = 0;
rep(k, n) if (sqrt(norm(p2 - c[k].p)) < EPS + 1.0) cnt++;
ans = (ans < cnt ? 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
| 1,188
| 2
|
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
typedef complex<double> Vector;
struct Circle {
Vector center;
double r;
pair<Vector, Vector> intersection(const Circle &c) const {
const double d = abs(c.center - center);
const double cos_ = (d * d + r * r - c.r * c.r) / (2 * d);
const double sin_ = sqrt(r * r - cos_ * cos_);
const Vector e = (c.center - center) / d;
return make_pair(center + e * Vector(cos_, sin_),
center + e * Vector(cos_, -sin_));
}
inline bool intersects(const Circle &c) const {
return norm(center - c.center) <= pow(r + c.r, 2);
}
inline bool contains(const Circle &c) const {
return abs(center - c.center) + c.r <= r;
}
inline bool contains(const Vector &v) const { return abs(center - v) <= r; }
};
int main() {
while (true) {
int N;
cin >> N;
if (!N)
break;
vector<Circle> circles(N);
for (int i = 0; i < N; ++i) {
double x, y;
scanf("%lf,%lf", &x, &y);
circles[i].center = Vector(x, y);
circles[i].r = 1;
}
int ans = 0;
for (int i = 0; i < N; ++i) {
const Circle c1 = circles[i];
for (int j = 0; j < i; ++j) {
const Circle c2 = circles[j];
if (!c1.intersects(c2))
continue;
pair<Vector, Vector> vs = c1.intersection(c2);
int cnt1 = 0, cnt2 = 0;
for (int k = 0; k < N; ++k) {
if (i == k || j == k)
continue;
if (circles[k].contains(vs.first))
++cnt1;
if (circles[k].contains(vs.second))
++cnt2;
}
ans = max(ans, max(cnt1, cnt2) + 2);
}
}
cout << ans << endl;
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
typedef complex<double> Vector;
struct Circle {
Vector center;
double r;
pair<Vector, Vector> intersection(const Circle &c) const {
const double d = abs(c.center - center);
const double cos_ = (d * d + r * r - c.r * c.r) / (2 * d);
const double sin_ = sqrt(r * r - cos_ * cos_);
const Vector e = (c.center - center) / d;
return make_pair(center + e * Vector(cos_, sin_),
center + e * Vector(cos_, -sin_));
}
inline bool intersects(const Circle &c) const {
return norm(center - c.center) <= pow(r + c.r, 2);
}
inline bool contains(const Circle &c) const {
return abs(center - c.center) + c.r <= r;
}
inline bool contains(const Vector &v) const { return abs(center - v) <= r; }
};
int main() {
while (true) {
int N;
cin >> N;
if (!N)
break;
vector<Circle> circles(N);
for (int i = 0; i < N; ++i) {
double x, y;
scanf("%lf,%lf", &x, &y);
circles[i].center = Vector(x, y);
circles[i].r = 1;
}
int ans = 1;
for (int i = 0; i < N; ++i) {
const Circle c1 = circles[i];
for (int j = 0; j < i; ++j) {
const Circle c2 = circles[j];
if (!c1.intersects(c2))
continue;
pair<Vector, Vector> vs = c1.intersection(c2);
int cnt1 = 0, cnt2 = 0;
for (int k = 0; k < N; ++k) {
if (i == k || j == k)
continue;
if (circles[k].contains(vs.first))
++cnt1;
if (circles[k].contains(vs.second))
++cnt2;
}
ans = max(ans, max(cnt1, cnt2) + 2);
}
}
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
| 500
| 2
|
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
double cx[2], cy[2], x[100], y[100];
int cirxy(double x1, double y1, double x2, double y2) {
double x3, y3, x4, y4, k, r;
x3 = (x1 + x2) / 2;
y3 = (y1 + y2) / 2;
k = sqrt((x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1));
if ((1 - k * k) < 0)
return 1;
r = sqrt(1 - k * k);
if (x1 == x2) {
cx[0] = x3 + r;
cy[0] = cy[1] = y3;
cx[1] = x3 - r;
return 0;
}
if (y1 == y2) {
cx[0] = cx[1] = x3;
cy[0] = y3 + r;
cy[1] = y3 - r;
return 0;
}
x4 = fabs((y1 - y2)) * (r / (2 * k));
y4 = fabs((x1 - x2)) * (r / (2 * k));
if ((y1 - y2) / (x1 - x2) < 0) {
cx[0] = x3 + x4;
cy[0] = y3 + y4;
cx[1] = x3 - x4;
cy[1] = y3 - y4;
} else {
cx[0] = x3 + x4;
cy[0] = y3 - y4;
cx[1] = x3 - x4;
cy[1] = y3 + y4;
}
return 0;
}
int main() {
int n, i, j, k, h, c, mx;
while (true) {
cin >> n;
mx = 1;
if (n == 0)
break;
for (k = 0; k < n; k++)
scanf("%lf,%lf", &x[k], &y[k]);
for (i = 0; i < n - 1; i++) {
for (j = i + 1; j < n; j++) {
if (cirxy(x[i], y[i], x[j], y[j]) == 1)
continue;
for (h = 0; h < 2; h++) {
c = 0;
for (k = 0; k < n; k++)
if (sqrt((cx[h] - x[k]) * (cx[h] - x[k]) +
(cy[h] - y[k]) * (cy[h] - y[k])) <= 1)
c++;
mx = max(c, mx);
}
}
}
cout << mx << endl;
}
return 0;
}
|
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
double cx[2], cy[2], x[100], y[100];
int cirxy(double x1, double y1, double x2, double y2) {
double x3, y3, x4, y4, k, r;
x3 = (x1 + x2) / 2;
y3 = (y1 + y2) / 2;
k = sqrt((x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1));
if ((1 - k * k) < 0)
return 1;
r = sqrt(1 - k * k);
if (x1 == x2) {
cx[0] = x3 + r;
cy[0] = cy[1] = y3;
cx[1] = x3 - r;
return 0;
}
if (y1 == y2) {
cx[0] = cx[1] = x3;
cy[0] = y3 + r;
cy[1] = y3 - r;
return 0;
}
x4 = fabs((y1 - y2)) * (r / (2 * k));
y4 = fabs((x1 - x2)) * (r / (2 * k));
if ((y1 - y2) / (x1 - x2) < 0) {
cx[0] = x3 + x4;
cy[0] = y3 + y4;
cx[1] = x3 - x4;
cy[1] = y3 - y4;
} else {
cx[0] = x3 + x4;
cy[0] = y3 - y4;
cx[1] = x3 - x4;
cy[1] = y3 + y4;
}
return 0;
}
int main() {
int n, i, j, k, h, c, mx;
while (true) {
cin >> n;
mx = 1;
if (n == 0)
break;
for (k = 0; k < n; k++)
scanf("%lf,%lf", &x[k], &y[k]);
for (i = 0; i < n - 1; i++) {
for (j = i + 1; j < n; j++) {
if (cirxy(x[i], y[i], x[j], y[j]) == 1)
continue;
for (h = 0; h < 2; h++) {
c = 0;
for (k = 0; k < n; k++)
if (sqrt((cx[h] - x[k]) * (cx[h] - x[k]) +
(cy[h] - y[k]) * (cy[h] - y[k])) <= 1.000001)
c++;
mx = max(c, mx);
}
}
}
cout << mx << endl;
}
return 0;
}
|
[["-", 0, 7, 8, 57, 15, 339, 51, 16, 12, 13], ["+", 0, 7, 8, 57, 15, 339, 51, 16, 12, 13]]
| 1
| 602
| 2
|
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>
#include <algorithm>
#include <bitset>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#ifdef _MSC_VER
#define __typeof__ decltype
#define strtok_r strtok_s
#endif
#define ITER(c) __typeof__((c).begin())
#define FOREACH(it, c) for (ITER(c) it = (c).begin(); it != (c).end(); ++it)
#define RITER(c) __typeof__((c).rbegin())
#define RFOREACH(it, c) for (RITER(c) it = (c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n) REPEAT(i, 0, n)
#define RREP(i, n) RREPEAT(i, 0, n);
#define REPEAT(i, k, n) for (int i = (k); i < (k + n); ++i)
#define RREPEAT(i, k, n) for (int i = (k) + (n)-1; i >= (k); ++i)
#define ALL(c) (c).begin(), (c).end()
#define LLPOW(p1, p2) ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A) (sizeof(A) / sizeof((A)[0]))
#define CIN_NO_SYNC \
do { \
cin.tie(0); \
ios_base::sync_with_stdio(false); \
} while (0)
#define GETSTR(p) fgets((p), sizeof(p), stdin)
#define CHOMP(p) \
do { \
char *_q = (p) + strlen(p) - 1; \
if (*_q == '\n' || *_q == '\r') \
*_q = 0; \
} while (0)
#define mp make_pair
#define pb push_back
template <class _T> _T MAX(_T p1, _T p2) { return (p1 > p2) ? p1 : p2; }
template <class _T> _T MIN(_T p1, _T p2) { return (p1 < p2) ? p1 : p2; }
typedef long long ll;
typedef unsigned long long ull;
#define X real()
#define Y imag()
typedef double D;
typedef complex<D> P;
#define EPS (1e-9)
#ifdef _DEBUG
#define pf printf
#define pr(n) \
do { \
cout << #n " = " << (n) << endl; \
} while (0)
#define prfe(n) \
do { \
cout << #n " ="; \
FOREACH(_it, n) cout << " " << *_it; \
cout << endl; \
} while (0)
#else
#define pf(...) /* */
#define pr(...) /* */
#define prfe(...) /* */
#endif
bool circle_cross(P p1, P p2, D r, P &cp1, P &cp2) {
D rd, rd2;
P pd = p2 - p1;
rd = abs(pd);
if (rd == 0 || rd > r * 2)
return false;
rd2 = rd / 2;
P pl(rd2, sqrt(r * r - rd2 * rd2));
cp1 = p1 + pl * polar(1.0, arg(pd));
cp2 = p1 + conj(pl) * polar(1.0, arg(pd));
return true;
}
void solve(vector<P> &v) {
int n = v.size();
vector<P> vc;
REP(i, n) vc.pb(v[i]);
REP(i, n - 1) {
for (int j = i + 1; j < n; j++) {
pf("P%d(%f,%f), P%d(%f,%f)\n", i + 1, v[i].X, v[i].Y, j + 1, v[j].X,
v[j].Y);
P cp1, cp2;
if (circle_cross(v[i], v[j], 1, cp1, cp2)) {
vc.pb(cp1);
vc.pb(cp2);
}
}
}
int max = 1;
FOREACH(it, vc) {
int count = 0;
P &pc = *it;
pr(pc);
REP(i, n) {
if (norm(v[i] - pc) <= 1.0 * 1.0)
count++;
}
max = MAX(max, count);
}
cout << max << endl;
return;
}
int main() {
int n;
double x, y;
char c;
while (cin >> n, n) {
vector<P> v;
REP(i, n) {
cin >> x >> c >> y;
v.pb(P(x, y));
}
solve(v);
}
return 0;
}
|
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>
#include <algorithm>
#include <bitset>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#ifdef _MSC_VER
#define __typeof__ decltype
#define strtok_r strtok_s
#endif
#define ITER(c) __typeof__((c).begin())
#define FOREACH(it, c) for (ITER(c) it = (c).begin(); it != (c).end(); ++it)
#define RITER(c) __typeof__((c).rbegin())
#define RFOREACH(it, c) for (RITER(c) it = (c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n) REPEAT(i, 0, n)
#define RREP(i, n) RREPEAT(i, 0, n);
#define REPEAT(i, k, n) for (int i = (k); i < (k + n); ++i)
#define RREPEAT(i, k, n) for (int i = (k) + (n)-1; i >= (k); ++i)
#define ALL(c) (c).begin(), (c).end()
#define LLPOW(p1, p2) ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A) (sizeof(A) / sizeof((A)[0]))
#define CIN_NO_SYNC \
do { \
cin.tie(0); \
ios_base::sync_with_stdio(false); \
} while (0)
#define GETSTR(p) fgets((p), sizeof(p), stdin)
#define CHOMP(p) \
do { \
char *_q = (p) + strlen(p) - 1; \
if (*_q == '\n' || *_q == '\r') \
*_q = 0; \
} while (0)
#define mp make_pair
#define pb push_back
template <class _T> _T MAX(_T p1, _T p2) { return (p1 > p2) ? p1 : p2; }
template <class _T> _T MIN(_T p1, _T p2) { return (p1 < p2) ? p1 : p2; }
typedef long long ll;
typedef unsigned long long ull;
#define X real()
#define Y imag()
typedef double D;
typedef complex<D> P;
#define EPS (1e-9)
#ifdef _DEBUG
#define pf printf
#define pr(n) \
do { \
cout << #n " = " << (n) << endl; \
} while (0)
#define prfe(n) \
do { \
cout << #n " ="; \
FOREACH(_it, n) cout << " " << *_it; \
cout << endl; \
} while (0)
#else
#define pf(...) /* */
#define pr(...) /* */
#define prfe(...) /* */
#endif
bool circle_cross(P p1, P p2, D r, P &cp1, P &cp2) {
D rd, rd2;
P pd = p2 - p1;
rd = abs(pd);
if (rd == 0 || rd > r * 2)
return false;
rd2 = rd / 2;
P pl(rd2, sqrt(r * r - rd2 * rd2));
cp1 = p1 + pl * polar(1.0, arg(pd));
cp2 = p1 + conj(pl) * polar(1.0, arg(pd));
return true;
}
void solve(vector<P> &v) {
int n = v.size();
vector<P> vc;
REP(i, n) vc.pb(v[i]);
REP(i, n - 1) {
for (int j = i + 1; j < n; j++) {
pf("P%d(%f,%f), P%d(%f,%f)\n", i + 1, v[i].X, v[i].Y, j + 1, v[j].X,
v[j].Y);
P cp1, cp2;
if (circle_cross(v[i], v[j], 1, cp1, cp2)) {
vc.pb(cp1);
vc.pb(cp2);
}
}
}
int max = 1;
FOREACH(it, vc) {
int count = 0;
P &pc = *it;
pr(pc);
REP(i, n) {
if (norm(v[i] - pc) <= 1.0 * 1.0 + EPS)
count++;
}
max = MAX(max, count);
}
cout << max << endl;
return;
}
int main() {
int n;
double x, y;
char c;
while (cin >> n, n) {
vector<P> v;
REP(i, n) {
cin >> x >> c >> y;
v.pb(P(x, y));
}
solve(v);
}
return 0;
}
|
[["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 72], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22]]
| 1
| 707
| 2
|
#include <math.h>
#include <stdio.h>
struct pnt {
double x, y;
pnt(){};
pnt(double a, double b) { x = a, y = b; }
};
double h;
struct line {
double A, B, C;
line(){};
line(pnt a, pnt b) { A = a.y - b.y, B = b.x - a.x, C = -A * a.x - B * a.y; }
};
pnt kramer(pnt x1, pnt x2, double t) {
line a = line(x1, x2);
double g = (x2.x * x2.x - x1.x * x1.x + x2.y * x2.y - x1.y * x1.y), delta;
delta = t * 2.0 * (a.A * a.A + a.B * a.B);
return pnt((2.0 * a.A * (h - t * a.C) + t * a.B * g) / delta,
(2.0 * a.B * (h - t * a.C) - t * a.A * g) / delta);
}
int dist(pnt a, pnt b, double val) {
return (((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)) <= val);
}
int main() {
int N, i, j, k, cnt, f;
double a, b;
pnt RB[105];
while (scanf("%d", &N) != EOF && N) {
for (i = 0; i < N; i++)
scanf("%lf,%lf", &a, &b), RB[i] = pnt(a, b);
cnt = 1;
for (i = 0; i < N; i++)
for (j = i + 1; j < N; j++)
if (dist(RB[i], RB[j], 4.0)) {
line q = line(RB[i], RB[j]);
h = q.A * q.A + q.B * q.B,
h = cos(0.5 * acos((2.0 - h) / 2.0)) * sqrt(h);
RB[104] = kramer(RB[i], RB[j], 1.0);
for (k = f = 0; k < N; k++)
f += dist(RB[104], RB[k], 1.0);
if (cnt < f)
cnt = f;
RB[104] = kramer(RB[i], RB[j], -1.0);
for (k = f = 0; k < N; k++)
f += dist(RB[104], RB[k], 1.0);
if (cnt < f)
cnt = f;
}
printf("%d\n", cnt);
}
return 0;
}
|
#include <math.h>
#include <stdio.h>
struct pnt {
double x, y;
pnt(){};
pnt(double a, double b) { x = a, y = b; }
};
double h;
struct line {
double A, B, C;
line(){};
line(pnt a, pnt b) { A = a.y - b.y, B = b.x - a.x, C = -A * a.x - B * a.y; }
};
pnt kramer(pnt x1, pnt x2, double t) {
line a = line(x1, x2);
double g = (x2.x * x2.x - x1.x * x1.x + x2.y * x2.y - x1.y * x1.y), delta;
delta = t * 2.0 * (a.A * a.A + a.B * a.B);
return pnt((2.0 * a.A * (h - t * a.C) + t * a.B * g) / delta,
(2.0 * a.B * (h - t * a.C) - t * a.A * g) / delta);
}
int dist(pnt a, pnt b, double val) {
return (((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)) <=
val + 1e-6);
}
int main() {
int N, i, j, k, cnt, f;
double a, b;
pnt RB[105];
while (scanf("%d", &N) != EOF && N) {
for (i = 0; i < N; i++)
scanf("%lf,%lf", &a, &b), RB[i] = pnt(a, b);
cnt = 1;
for (i = 0; i < N; i++)
for (j = i + 1; j < N; j++)
if (dist(RB[i], RB[j], 4.0)) {
line q = line(RB[i], RB[j]);
h = q.A * q.A + q.B * q.B,
h = cos(0.5 * acos((2.0 - h) / 2.0)) * sqrt(h);
RB[104] = kramer(RB[i], RB[j], 1.0);
for (k = f = 0; k < N; k++)
f += dist(RB[104], RB[k], 1.0);
if (cnt < f)
cnt = f;
RB[104] = kramer(RB[i], RB[j], -1.0);
for (k = f = 0; k < N; k++)
f += dist(RB[104], RB[k], 1.0);
if (cnt < f)
cnt = f;
}
printf("%d\n", cnt);
}
return 0;
}
|
[["+", 0, 37, 0, 23, 0, 16, 12, 16, 17, 72], ["+", 0, 37, 0, 23, 0, 16, 12, 16, 12, 13]]
| 1
| 643
| 2
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define dump(a) (cerr << (#a) << " = " << (a) << endl)
#define FOR(it, c) \
for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define RFOR(it, c) \
for (__typeof((c).rbegin()) it = (c).rbegin(); it != (c).rend(); ++it)
#define exist(c, v) (find((c).begin(), (c).end(), (v)) != (c).end())
template <class T> inline void chmax(T &a, const T &b) {
if (b > a)
a = b;
}
template <class T> inline void chmin(T &a, const T &b) {
if (b < a)
a = b;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << '(' << p.first << ", " << p.second << ')';
return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
copy(v.begin(), v.end(), ostream_iterator<T>(os, " "));
return os;
}
const double EPS = 1e-9;
struct point {
double x, y;
point(double x = 0.0, double y = 0.0) : x(x), y(y) {}
point(const point &p) : x(p.x), y(p.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 s) const { return point(x * s, y * s); }
point operator*(const point &p) const {
return point(x * p.x - y * p.y, x * p.y + y * p.x);
}
point operator/(const double s) const { return point(x / s, y / s); }
bool operator<(const point &p) const {
return x + EPS < p.x || abs(x - p.x) < EPS && y + EPS < p.y;
}
bool operator==(const point &p) const {
return abs(x - p.x) < EPS && abs(y - p.y) < EPS;
}
};
inline point rotate90(const point &p) { return point(-p.y, p.x); }
inline point rotate(const point &p, const double theta) {
const double s = sin(theta), c = cos(theta);
return point(c * p.x - s * p.y, s * p.x + c * p.y);
}
inline double angle(const point &p) { return atan2(p.y, p.x); }
inline double abs(const point &p) { return sqrt(p.x * p.x + p.y * p.y); }
inline double norm(const point &p) { return p.x * p.x + p.y * p.y; }
inline double dot(const point &l, const point &r) {
return l.x * r.x + l.y * r.y;
}
inline double cross(const point &l, const point &r) {
return l.x * r.y - l.y * r.x;
}
struct line {
point a, b;
line(point a, point b) : a(a), b(b) {}
};
struct segment {
point a, b;
segment(point a, point b) : a(a), b(b) {}
};
struct circle {
point c;
double r;
circle(point c, double r) : c(c), r(r) {}
};
typedef vector<point> polygon;
inline int ccw(const point &a, point b, point c) {
b = b - a;
c = c - a;
const double tmp = cross(b, c);
if (tmp > EPS)
return 1; // ccw
if (tmp < -EPS)
return -1; // cw
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 順で一直線上
}
inline point projection(const line &l, const point &p) {
const point dif = l.b - l.a;
const double tmp = dot(p - l.a, dif) / norm(dif);
return l.a + dif * tmp;
}
inline bool intersect(const line &l, const line &m) {
return abs(cross(l.b - l.a, m.b - m.a)) > EPS ||
abs(cross(l.b - l.a, m.b - l.a)) < EPS;
}
inline bool intersect(const line &l, const segment &s) {
return cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) < EPS;
}
inline bool intersect(const line &l, const point &p) {
return abs(ccw(l.a, l.b, p)) != -1;
}
inline bool intersect(const segment &s, const segment &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;
}
inline bool intersect(const segment &s, const point &p) {
return ccw(s.a, s.b, p) == 0;
}
inline bool intersect(const circle &c, const point &p) {
return abs(c.c - p) <= c.r + EPS;
}
inline bool intersect(const circle &c, const circle &d) {
return abs(c.c - d.c) <= c.r + d.r && abs(c.c - d.c) >= abs(c.r - d.r);
}
inline double dist(const line &l, const point &p) {
return abs(cross((l.b - l.a), (p - l.a))) / abs(l.b - l.a);
}
inline double dist(const line &l, const line &m) {
return intersect(l, m) ? 0 : dist(l, m.a);
}
inline double dist(const line &l, const segment &s) {
return intersect(l, s) ? 0 : min(dist(l, s.a), dist(l, s.b));
}
inline double dist(const segment &s, const point &p) {
if (dot((s.b - s.a), (p - s.a)) < 0)
return abs(p - s.a);
if (dot((s.a - s.b), (p - s.b)) < 0)
return abs(p - s.b);
return dist(line(s.a, s.b), p);
}
inline double dist(const segment &s, const segment &t) {
if (intersect(s, t))
return 0;
return min(min(dist(s, t.a), dist(s, t.b)), min(dist(t, s.a), dist(t, s.b)));
}
inline double dist(const point &a, const point &b) { return abs(a - b); }
inline bool intersect(const circle &c, const segment &s) {
return dist(s, c.c) < c.r + EPS;
}
inline point crosspoint(const line &l, const line &m) {
const double tmp = cross(l.b - l.a, m.b - m.a);
if (abs(tmp) < EPS) // 平行
return l.a;
return m.a + (m.b - m.a) * cross(l.b - l.a, l.a - m.a) * (1.0 / tmp);
}
inline point crosspoint(const segment &s, const segment &t) {
if (!intersect(s, t)) // 交点を持たない
return s.a; // 用改善
const double tmp = cross(s.b - s.a, t.b - t.a);
if (abs(tmp) < EPS) { // 一直線上
if (intersect(s, t.a))
return t.a;
if (intersect(s, t.b))
return t.b;
if (intersect(t, s.a))
return s.a;
return s.b;
}
return t.a + (t.b - t.a) * cross(s.b - s.a, s.b - t.a) * (1.0 / tmp);
}
//先に,intersectを用いて交差判定を行うこと
inline vector<point> crosspoint(const circle &c, const circle &d) {
vector<point> res;
if (abs(c.c - d.c) < EPS) // 中心の座標が同じ
return res;
const double tmp = abs(c.c - d.c);
const double rc = (tmp * tmp + c.r * c.r - d.r * d.r) / (tmp + tmp);
const double rs = sqrt(c.r * c.r - rc * rc);
const point diff = (d.c - c.c) / tmp;
res.push_back(point(c.c + diff * point(rc, rs)));
res.push_back(point(c.c + diff * point(rc, -rs)));
return res;
}
inline vector<point> crosspoint(const circle &c, const line &l) {
vector<point> res;
const point h = projection(l, c.c);
const double d = abs(h - c.c);
if (d > c.r - EPS) {
res.push_back(h);
} else if (d <= c.r - EPS) {
point v = l.b - l.a;
v = v * sqrt(c.r * c.r - d * d) / abs(v);
res.push_back(h + v);
res.push_back(h - v);
}
return res;
}
inline vector<point> crosspoint(const circle &c, const segment &s) {
vector<point> res;
vector<point> tmp = crosspoint(c, line(s.a, s.b));
for (int i = 0; i < tmp.size(); ++i)
if (intersect(s, tmp[i]))
res.push_back(tmp[i]);
return res;
}
inline double areaTriangle(point a, point b, const point &c) {
a = a - c;
b = b - c;
return fabs(a.x * b.y - b.x * a.y) / 2.0;
}
inline double area(const polygon &p) {
const int num = p.size();
if (num < 3)
return 0;
if (num == 3)
return areaTriangle(p[0], p[1], p[2]);
double res = cross(p[num - 1], p[0]);
for (int i = 1; i < num; ++i)
res += cross(p[i - 1], p[i]);
return abs(res) * 0.5;
}
// L.aからL.bの方向を見た場合に,点aが左側に来る.
inline line bisector(const point &a, const point &b) {
return line(
point((a.x - a.y + b.x + b.y) / 2.0, (a.y + a.x + b.y - b.x) / 2.0),
point((a.x + a.y + b.x - b.y) / 2.0, (a.y - a.x + b.y + b.x) / 2.0));
}
// 点集合 pointsの凸包を求める.
inline polygon convex_hull(vector<point> points) {
const int n = points.size();
if (n <= 3)
return points;
sort(points.begin(), points.end());
int k = 0;
polygon res;
res.resize(2 * n);
for (int i = 0; i < n; res[k++] = points[i++])
while (k >= 2 && ccw(res[k - 2], res[k - 1], points[i]) <= 0)
--k;
const int t = k + 1;
for (int i = n - 2; i >= 0; res[k++] = points[i--])
while (k >= t && ccw(res[k - 2], res[k - 1], points[i]) <= 0)
--k;
res.resize(k - 1);
return res;
}
// L.aからL.bを向いた時の左側を残して切断する.
inline polygon convex_cut(const polygon &p, const line &l) {
const int num = p.size();
polygon res;
for (int i = 0; i < num; ++i) {
const int next = (i + 1) % num;
const int tmp = ccw(l.a, l.b, p[i]);
if (tmp != -1)
res.push_back(p[i]);
if (tmp * ccw(l.a, l.b, p[next]) < 0)
res.push_back(crosspoint(l, line(p[i], p[next])));
}
return res;
}
vector<point> tangent(const circle &c, const point &p) {
const double x = norm(p - c.c);
double d = x - c.r * c.r;
if (d < -EPS)
return vector<point>();
d = max(d, 0.0);
const point q1 = (p - c.c) * (c.r * c.r / x);
const point q2 = rotate90((p - c.c) * (-c.r * sqrt(d) / x));
vector<point> res;
res.push_back(c.c + q1 - q2);
res.push_back(c.c + q1 + q2);
return res;
}
vector<line> tangent(const circle &a, const circle &b) {
vector<line> res;
if (abs(a.r - b.r) < EPS) {
point dir = b.c - a.c;
dir = rotate90(dir * (a.r / abs(dir)));
res.push_back(line(a.c + dir, b.c + dir));
res.push_back(line(a.c - dir, b.c - dir));
} else {
point p = a.c * (-b.r) + b.c * a.r;
p = p * (1.0 / (a.r - b.r));
vector<point> ps = tangent(a, p), qs = tangent(b, p);
for (int i = 0; i < min<int>(ps.size(), qs.size()); ++i)
res.push_back(line(ps[i], qs[i]));
}
point p = a.c * b.r + b.c * a.r;
p = p * (1.0 / (a.r + b.r));
vector<point> ps = tangent(a, p), qs = tangent(b, p);
for (int i = 0; i < min<int>(ps.size(), qs.size()); ++i)
res.push_back(line(ps[i], qs[i]));
return res;
}
// 三角形と点の包含関係,境界は含まない.
// 含める場合は == -1を <= 0とする.
bool contain_triangle(const polygon &triangle, const point &p) {
const int d1 = ccw(p, triangle[0], triangle[1]),
d2 = ccw(p, triangle[1], triangle[2]),
d3 = ccw(p, triangle[2], triangle[0]);
return !(d1 * d2 == -1 || d2 * d3 == -1 || d3 * d1 == -1);
}
// 多角形と点の包含関係.境界を含む.
bool contain(const polygon &P, const point &p) {
const int n = P.size();
bool res = false;
for (int i = 0; i < n; ++i) {
point v1 = P[i] - p, v2 = P[(i + 1) % n] - p;
if (v1.y > v2.y)
swap(v1, v2);
if (v1.y < EPS && EPS < v2.y && cross(v1, v2) > EPS)
res = !res;
if (abs(cross(v1, v2)) < EPS && dot(v1, v2) < EPS)
return true; // 境界を含まないなら,falseにする.
}
return res;
}
int main() {
for (int n; scanf("%d", &n), n;) {
vector<circle> seals;
seals.reserve(n);
for (int i = 0; i < n; ++i) {
double x, y;
scanf("%lf,%lf", &x, &y);
seals.push_back(circle(point(x, y), 1.0));
}
int ans = 0;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
vector<point> candidates = crosspoint(seals[i], seals[j]);
for (int k = 0; k < (int)candidates.size(); ++k) {
int cnt = 0;
for (int l = 0; l < n; ++l) {
if (abs(candidates[k] - seals[l].c) < 1.0 + EPS)
++cnt;
}
chmax(ans, cnt);
}
}
}
printf("%d\n", ans);
}
return EXIT_SUCCESS;
}
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define dump(a) (cerr << (#a) << " = " << (a) << endl)
#define FOR(it, c) \
for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define RFOR(it, c) \
for (__typeof((c).rbegin()) it = (c).rbegin(); it != (c).rend(); ++it)
#define exist(c, v) (find((c).begin(), (c).end(), (v)) != (c).end())
template <class T> inline void chmax(T &a, const T &b) {
if (b > a)
a = b;
}
template <class T> inline void chmin(T &a, const T &b) {
if (b < a)
a = b;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << '(' << p.first << ", " << p.second << ')';
return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
copy(v.begin(), v.end(), ostream_iterator<T>(os, " "));
return os;
}
const double EPS = 1e-9;
struct point {
double x, y;
point(double x = 0.0, double y = 0.0) : x(x), y(y) {}
point(const point &p) : x(p.x), y(p.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 s) const { return point(x * s, y * s); }
point operator*(const point &p) const {
return point(x * p.x - y * p.y, x * p.y + y * p.x);
}
point operator/(const double s) const { return point(x / s, y / s); }
bool operator<(const point &p) const {
return x + EPS < p.x || abs(x - p.x) < EPS && y + EPS < p.y;
}
bool operator==(const point &p) const {
return abs(x - p.x) < EPS && abs(y - p.y) < EPS;
}
};
inline point rotate90(const point &p) { return point(-p.y, p.x); }
inline point rotate(const point &p, const double theta) {
const double s = sin(theta), c = cos(theta);
return point(c * p.x - s * p.y, s * p.x + c * p.y);
}
inline double angle(const point &p) { return atan2(p.y, p.x); }
inline double abs(const point &p) { return sqrt(p.x * p.x + p.y * p.y); }
inline double norm(const point &p) { return p.x * p.x + p.y * p.y; }
inline double dot(const point &l, const point &r) {
return l.x * r.x + l.y * r.y;
}
inline double cross(const point &l, const point &r) {
return l.x * r.y - l.y * r.x;
}
struct line {
point a, b;
line(point a, point b) : a(a), b(b) {}
};
struct segment {
point a, b;
segment(point a, point b) : a(a), b(b) {}
};
struct circle {
point c;
double r;
circle(point c, double r) : c(c), r(r) {}
};
typedef vector<point> polygon;
inline int ccw(const point &a, point b, point c) {
b = b - a;
c = c - a;
const double tmp = cross(b, c);
if (tmp > EPS)
return 1; // ccw
if (tmp < -EPS)
return -1; // cw
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 順で一直線上
}
inline point projection(const line &l, const point &p) {
const point dif = l.b - l.a;
const double tmp = dot(p - l.a, dif) / norm(dif);
return l.a + dif * tmp;
}
inline bool intersect(const line &l, const line &m) {
return abs(cross(l.b - l.a, m.b - m.a)) > EPS ||
abs(cross(l.b - l.a, m.b - l.a)) < EPS;
}
inline bool intersect(const line &l, const segment &s) {
return cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) < EPS;
}
inline bool intersect(const line &l, const point &p) {
return abs(ccw(l.a, l.b, p)) != -1;
}
inline bool intersect(const segment &s, const segment &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;
}
inline bool intersect(const segment &s, const point &p) {
return ccw(s.a, s.b, p) == 0;
}
inline bool intersect(const circle &c, const point &p) {
return abs(c.c - p) <= c.r + EPS;
}
inline bool intersect(const circle &c, const circle &d) {
return abs(c.c - d.c) <= c.r + d.r && abs(c.c - d.c) >= abs(c.r - d.r);
}
inline double dist(const line &l, const point &p) {
return abs(cross((l.b - l.a), (p - l.a))) / abs(l.b - l.a);
}
inline double dist(const line &l, const line &m) {
return intersect(l, m) ? 0 : dist(l, m.a);
}
inline double dist(const line &l, const segment &s) {
return intersect(l, s) ? 0 : min(dist(l, s.a), dist(l, s.b));
}
inline double dist(const segment &s, const point &p) {
if (dot((s.b - s.a), (p - s.a)) < 0)
return abs(p - s.a);
if (dot((s.a - s.b), (p - s.b)) < 0)
return abs(p - s.b);
return dist(line(s.a, s.b), p);
}
inline double dist(const segment &s, const segment &t) {
if (intersect(s, t))
return 0;
return min(min(dist(s, t.a), dist(s, t.b)), min(dist(t, s.a), dist(t, s.b)));
}
inline double dist(const point &a, const point &b) { return abs(a - b); }
inline bool intersect(const circle &c, const segment &s) {
return dist(s, c.c) < c.r + EPS;
}
inline point crosspoint(const line &l, const line &m) {
const double tmp = cross(l.b - l.a, m.b - m.a);
if (abs(tmp) < EPS) // 平行
return l.a;
return m.a + (m.b - m.a) * cross(l.b - l.a, l.a - m.a) * (1.0 / tmp);
}
inline point crosspoint(const segment &s, const segment &t) {
if (!intersect(s, t)) // 交点を持たない
return s.a; // 用改善
const double tmp = cross(s.b - s.a, t.b - t.a);
if (abs(tmp) < EPS) { // 一直線上
if (intersect(s, t.a))
return t.a;
if (intersect(s, t.b))
return t.b;
if (intersect(t, s.a))
return s.a;
return s.b;
}
return t.a + (t.b - t.a) * cross(s.b - s.a, s.b - t.a) * (1.0 / tmp);
}
//先に,intersectを用いて交差判定を行うこと
inline vector<point> crosspoint(const circle &c, const circle &d) {
vector<point> res;
if (abs(c.c - d.c) < EPS) // 中心の座標が同じ
return res;
const double tmp = abs(c.c - d.c);
const double rc = (tmp * tmp + c.r * c.r - d.r * d.r) / (tmp + tmp);
const double rs = sqrt(c.r * c.r - rc * rc);
const point diff = (d.c - c.c) / tmp;
res.push_back(point(c.c + diff * point(rc, rs)));
res.push_back(point(c.c + diff * point(rc, -rs)));
return res;
}
inline vector<point> crosspoint(const circle &c, const line &l) {
vector<point> res;
const point h = projection(l, c.c);
const double d = abs(h - c.c);
if (d > c.r - EPS) {
res.push_back(h);
} else if (d <= c.r - EPS) {
point v = l.b - l.a;
v = v * sqrt(c.r * c.r - d * d) / abs(v);
res.push_back(h + v);
res.push_back(h - v);
}
return res;
}
inline vector<point> crosspoint(const circle &c, const segment &s) {
vector<point> res;
vector<point> tmp = crosspoint(c, line(s.a, s.b));
for (int i = 0; i < tmp.size(); ++i)
if (intersect(s, tmp[i]))
res.push_back(tmp[i]);
return res;
}
inline double areaTriangle(point a, point b, const point &c) {
a = a - c;
b = b - c;
return fabs(a.x * b.y - b.x * a.y) / 2.0;
}
inline double area(const polygon &p) {
const int num = p.size();
if (num < 3)
return 0;
if (num == 3)
return areaTriangle(p[0], p[1], p[2]);
double res = cross(p[num - 1], p[0]);
for (int i = 1; i < num; ++i)
res += cross(p[i - 1], p[i]);
return abs(res) * 0.5;
}
// L.aからL.bの方向を見た場合に,点aが左側に来る.
inline line bisector(const point &a, const point &b) {
return line(
point((a.x - a.y + b.x + b.y) / 2.0, (a.y + a.x + b.y - b.x) / 2.0),
point((a.x + a.y + b.x - b.y) / 2.0, (a.y - a.x + b.y + b.x) / 2.0));
}
// 点集合 pointsの凸包を求める.
inline polygon convex_hull(vector<point> points) {
const int n = points.size();
if (n <= 3)
return points;
sort(points.begin(), points.end());
int k = 0;
polygon res;
res.resize(2 * n);
for (int i = 0; i < n; res[k++] = points[i++])
while (k >= 2 && ccw(res[k - 2], res[k - 1], points[i]) <= 0)
--k;
const int t = k + 1;
for (int i = n - 2; i >= 0; res[k++] = points[i--])
while (k >= t && ccw(res[k - 2], res[k - 1], points[i]) <= 0)
--k;
res.resize(k - 1);
return res;
}
// L.aからL.bを向いた時の左側を残して切断する.
inline polygon convex_cut(const polygon &p, const line &l) {
const int num = p.size();
polygon res;
for (int i = 0; i < num; ++i) {
const int next = (i + 1) % num;
const int tmp = ccw(l.a, l.b, p[i]);
if (tmp != -1)
res.push_back(p[i]);
if (tmp * ccw(l.a, l.b, p[next]) < 0)
res.push_back(crosspoint(l, line(p[i], p[next])));
}
return res;
}
vector<point> tangent(const circle &c, const point &p) {
const double x = norm(p - c.c);
double d = x - c.r * c.r;
if (d < -EPS)
return vector<point>();
d = max(d, 0.0);
const point q1 = (p - c.c) * (c.r * c.r / x);
const point q2 = rotate90((p - c.c) * (-c.r * sqrt(d) / x));
vector<point> res;
res.push_back(c.c + q1 - q2);
res.push_back(c.c + q1 + q2);
return res;
}
vector<line> tangent(const circle &a, const circle &b) {
vector<line> res;
if (abs(a.r - b.r) < EPS) {
point dir = b.c - a.c;
dir = rotate90(dir * (a.r / abs(dir)));
res.push_back(line(a.c + dir, b.c + dir));
res.push_back(line(a.c - dir, b.c - dir));
} else {
point p = a.c * (-b.r) + b.c * a.r;
p = p * (1.0 / (a.r - b.r));
vector<point> ps = tangent(a, p), qs = tangent(b, p);
for (int i = 0; i < min<int>(ps.size(), qs.size()); ++i)
res.push_back(line(ps[i], qs[i]));
}
point p = a.c * b.r + b.c * a.r;
p = p * (1.0 / (a.r + b.r));
vector<point> ps = tangent(a, p), qs = tangent(b, p);
for (int i = 0; i < min<int>(ps.size(), qs.size()); ++i)
res.push_back(line(ps[i], qs[i]));
return res;
}
// 三角形と点の包含関係,境界は含まない.
// 含める場合は == -1を <= 0とする.
bool contain_triangle(const polygon &triangle, const point &p) {
const int d1 = ccw(p, triangle[0], triangle[1]),
d2 = ccw(p, triangle[1], triangle[2]),
d3 = ccw(p, triangle[2], triangle[0]);
return !(d1 * d2 == -1 || d2 * d3 == -1 || d3 * d1 == -1);
}
// 多角形と点の包含関係.境界を含む.
bool contain(const polygon &P, const point &p) {
const int n = P.size();
bool res = false;
for (int i = 0; i < n; ++i) {
point v1 = P[i] - p, v2 = P[(i + 1) % n] - p;
if (v1.y > v2.y)
swap(v1, v2);
if (v1.y < EPS && EPS < v2.y && cross(v1, v2) > EPS)
res = !res;
if (abs(cross(v1, v2)) < EPS && dot(v1, v2) < EPS)
return true; // 境界を含まないなら,falseにする.
}
return res;
}
int main() {
for (int n; scanf("%d", &n), n;) {
vector<circle> seals;
seals.reserve(n);
for (int i = 0; i < n; ++i) {
double x, y;
scanf("%lf,%lf", &x, &y);
seals.push_back(circle(point(x, y), 1.0));
}
int ans = 1;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
vector<point> candidates = crosspoint(seals[i], seals[j]);
for (int k = 0; k < (int)candidates.size(); ++k) {
int cnt = 0;
for (int l = 0; l < n; ++l) {
if (abs(candidates[k] - seals[l].c) < 1.0 + EPS)
++cnt;
}
chmax(ans, cnt);
}
}
}
printf("%d\n", ans);
}
return EXIT_SUCCESS;
}
|
[["-", 0, 7, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 7, 8, 9, 0, 43, 49, 50, 51, 13]]
| 1
| 3,974
| 2
|
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <vector>
#define PI 3.141592654
#define RADIUS 1.0
#define EPS 1e-10
struct POINT {
double x;
double y;
POINT &operator+=(const POINT &p) {
x += p.x;
y += p.y;
return *this;
}
POINT &operator-=(const POINT &p) {
x -= p.x;
y -= p.y;
return *this;
}
POINT &operator*=(double factor) {
x *= factor;
y *= factor;
return *this;
}
POINT &operator/=(double factor) {
x /= factor;
y /= factor;
return *this;
}
};
POINT operator+(const POINT &a, const POINT &b) {
POINT p(a);
p += b;
return p;
}
POINT operator-(const POINT &a, const POINT &b) {
POINT p(a);
p -= b;
return p;
}
POINT operator*(const POINT &a, double factor) {
POINT p(a);
p *= factor;
return p;
}
POINT operator/(const POINT &a, double factor) {
POINT p(a);
p /= factor;
return p;
}
typedef POINT VECTOR;
std::istream &operator>>(std::istream &s, POINT &p) {
char c;
return s >> p.x >> c >> p.y;
}
double getDistance(const POINT &a, const POINT &b) {
return sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2));
}
double getSizeofVector(const VECTOR &vec) {
return sqrt(pow(vec.x, 2) + pow(vec.y, 2));
}
void getCrossPoint(const POINT &a, const POINT &b, POINT *p1, POINT *p2) {
POINT mid = (a + b) / 2;
if (fabs(getDistance(a, b) - 1.0) < EPS) {
*p1 = mid;
*p2 = mid;
return;
} else {
VECTOR ab = b - a;
double theta = atan(ab.y / ab.x);
double h = sqrt(pow(RADIUS, 2) - pow(getSizeofVector(ab) / 2, 2));
p1->x = mid.x + h * cos(theta + PI / 2);
p1->y = mid.y + h * sin(theta + PI / 2);
p2->x = mid.x + h * cos(theta - PI / 2);
p2->y = mid.y + h * sin(theta - PI / 2);
return;
}
}
int getMax(int a, int b) { return a > b ? a : b; }
int main(void) {
while (1) {
int n;
std::cin >> n;
if (n == 0) {
break;
}
std::vector<POINT> o;
for (int i = 0; i < n; i++) {
POINT p;
std::cin >> p;
o.push_back(p);
}
int overlap = 1;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
int cnt1, cnt2;
if (getDistance(o[i], o[j]) <= 1.0 + EPS) {
POINT p1, p2;
getCrossPoint(o[i], o[j], &p1, &p2);
cnt1 = 2;
cnt2 = 2;
for (int k = 0; k < n; k++) {
if (k == i || k == j) {
continue;
}
if (getDistance(o[k], p1) <= 1.0 + EPS) {
cnt1++;
}
if (getDistance(o[k], p2) <= 1.0 + EPS) {
cnt2++;
}
}
} else {
cnt1 = 0;
cnt2 = 0;
}
if (overlap < getMax(cnt1, cnt2)) {
overlap = getMax(cnt1, cnt2);
}
}
}
std::cout << overlap << std::endl;
}
return 0;
}
|
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <vector>
#define PI 3.141592654
#define RADIUS 1.0
#define EPS 1e-10
struct POINT {
double x;
double y;
POINT &operator+=(const POINT &p) {
x += p.x;
y += p.y;
return *this;
}
POINT &operator-=(const POINT &p) {
x -= p.x;
y -= p.y;
return *this;
}
POINT &operator*=(double factor) {
x *= factor;
y *= factor;
return *this;
}
POINT &operator/=(double factor) {
x /= factor;
y /= factor;
return *this;
}
};
POINT operator+(const POINT &a, const POINT &b) {
POINT p(a);
p += b;
return p;
}
POINT operator-(const POINT &a, const POINT &b) {
POINT p(a);
p -= b;
return p;
}
POINT operator*(const POINT &a, double factor) {
POINT p(a);
p *= factor;
return p;
}
POINT operator/(const POINT &a, double factor) {
POINT p(a);
p /= factor;
return p;
}
typedef POINT VECTOR;
std::istream &operator>>(std::istream &s, POINT &p) {
char c;
return s >> p.x >> c >> p.y;
}
double getDistance(const POINT &a, const POINT &b) {
return sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2));
}
double getSizeofVector(const VECTOR &vec) {
return sqrt(pow(vec.x, 2) + pow(vec.y, 2));
}
void getCrossPoint(const POINT &a, const POINT &b, POINT *p1, POINT *p2) {
POINT mid = (a + b) / 2;
if (fabs(getDistance(a, b) - 2.0) < EPS) {
*p1 = mid;
*p2 = mid;
return;
} else {
VECTOR ab = b - a;
double theta = atan(ab.y / ab.x);
double h = sqrt(pow(RADIUS, 2) - pow(getSizeofVector(ab) / 2, 2));
p1->x = mid.x + h * cos(theta + PI / 2);
p1->y = mid.y + h * sin(theta + PI / 2);
p2->x = mid.x + h * cos(theta - PI / 2);
p2->y = mid.y + h * sin(theta - PI / 2);
return;
}
}
int getMax(int a, int b) { return a > b ? a : b; }
int main(void) {
while (1) {
int n;
std::cin >> n;
if (n == 0) {
break;
}
std::vector<POINT> o;
for (int i = 0; i < n; i++) {
POINT p;
std::cin >> p;
o.push_back(p);
}
int overlap = 1;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
int cnt1, cnt2;
if (getDistance(o[i], o[j]) <= 2.0 + EPS) {
POINT p1, p2;
getCrossPoint(o[i], o[j], &p1, &p2);
cnt1 = 2;
cnt2 = 2;
for (int k = 0; k < n; k++) {
if (k == i || k == j) {
continue;
}
if (getDistance(o[k], p1) <= 1.0 + EPS) {
cnt1++;
}
if (getDistance(o[k], p2) <= 1.0 + EPS) {
cnt2++;
}
}
} else {
cnt1 = 0;
cnt2 = 0;
}
if (overlap < getMax(cnt1, cnt2)) {
overlap = getMax(cnt1, cnt2);
}
}
}
std::cout << overlap << std::endl;
}
return 0;
}
|
[["-", 51, 16, 31, 2, 3, 4, 0, 16, 12, 13], ["+", 51, 16, 31, 2, 3, 4, 0, 16, 12, 13], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 31, 13], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 31, 13]]
| 1
| 856
| 4
|
#include <complex>
#include <iostream>
#include <vector>
using namespace std;
typedef complex<double> P;
P A[100], j = sqrt(-1), p, p0;
double a, b, d;
int n;
int f(int m) {
int i, s1 = 2, s2 = 2;
d = acos(a / 2);
P p3 = polar(1.0, b + d) + p, p4 = polar(1.0, b - d) + p;
for (i = 0; i < n; i++) {
P q = A[i];
if (q == p || q == p0)
continue;
if (abs(q - p3) - 1 < 1e-6)
s1++;
if (abs(q - p4) - 1 < 1e-6)
s2++;
}
if (m < s1)
m = s1;
if (m < s2)
m = s2;
return m;
}
int main() {
int m, i, i1;
char c;
while (cin >> n, n != 0) {
for (i = 0; i < n; i++) {
cin >> a >> c >> b;
A[i] = P(a, b);
}
m = 1;
for (i = 0; i < n; i++) {
P p = A[i], p0;
for (i1 = i + 1; i1 < n; i1++) {
p0 = A[i1];
a = abs(p0 - p);
b = arg(p0 - p);
if (a <= 2)
m = f(m);
}
}
cout << m << endl;
}
}
|
#include <complex>
#include <iostream>
#include <vector>
using namespace std;
typedef complex<double> P;
P A[100], j = sqrt(-1), p, p0;
double a, b, d;
int n;
int f(int m) {
int i, s1 = 2, s2 = 2;
d = acos(a / 2);
P p3 = polar(1.0, b + d) + p, p4 = polar(1.0, b - d) + p;
for (i = 0; i < n; i++) {
P q = A[i];
if (q == p || q == p0)
continue;
if (abs(q - p3) - 1 < 1e-6)
s1++;
if (abs(q - p4) - 1 < 1e-6)
s2++;
}
if (m < s1)
m = s1;
if (m < s2)
m = s2;
return m;
}
int main() {
int m, i, i1;
char c;
while (cin >> n, n != 0) {
for (i = 0; i < n; i++) {
cin >> a >> c >> b;
A[i] = P(a, b);
}
m = 1;
for (i = 0; i < n; i++) {
p = A[i];
for (i1 = i + 1; i1 < n; i1++) {
p0 = A[i1];
a = abs(p0 - p);
b = arg(p0 - p);
if (a <= 2)
m = f(m);
}
}
cout << m << endl;
}
}
|
[["-", 8, 9, 0, 7, 8, 9, 0, 43, 39, 78], ["-", 8, 9, 0, 7, 8, 9, 0, 43, 0, 21], ["-", 8, 9, 0, 7, 8, 9, 0, 43, 49, 22]]
| 1
| 342
| 27
|
epsilon = 0
while n = gets.to_i
break if n == 0
cross = []
circle = []
n.times{|i|
x, y = gets.split(",").map(&:to_f)
circle.each_with_index{|it, j|
if (it[0]-x)**2 + (it[1]-y)**2 <= 4.0 + epsilon
x1 = it[0]-x
y1 = it[1]-y
x2y2 = x1**2+y1**2
a = x2y2*0.5
b = Math.sqrt(x2y2 - a**2)
x0 = (a*x1 + y1 * b) / x2y2
y0 = (a*y1 - x1 * b) / x2y2
cross << [x0+x, y0+y]
x0 = (a*x1 - y1 * b) / x2y2
y0 = (a*y1 + x1 * b) / x2y2
cross << [x0+x, y0+y]
end
}
circle[i] = [x, y]
}
max = 1
cross.each{|x0, y0|
cnt = 0
circle.each{|x1, y1|
cnt += 1 if (x1-x0)**2 + (y1-y0)**2 <= 1.0 + epsilon
# puts "#{x0} #{y0} #{x1} #{y1} #{(x1-x0)**2 + (y1-y0)**2}"
}
max = cnt if max < cnt
}
puts max
end
|
epsilon = 1e-10
while n = gets.to_i
break if n == 0
cross = []
circle = []
n.times{|i|
x, y = gets.split(",").map(&:to_f)
circle.each_with_index{|it, j|
if (it[0]-x)**2 + (it[1]-y)**2 <= 4.0 + epsilon
x1 = it[0]-x
y1 = it[1]-y
x2y2 = x1**2+y1**2
a = x2y2*0.5
b = Math.sqrt(x2y2 - a**2)
x0 = (a*x1 + y1 * b) / x2y2
y0 = (a*y1 - x1 * b) / x2y2
cross << [x0+x, y0+y]
x0 = (a*x1 - y1 * b) / x2y2
y0 = (a*y1 + x1 * b) / x2y2
cross << [x0+x, y0+y]
end
}
circle[i] = [x, y]
}
max = 1
cross.each{|x0, y0|
cnt = 0
circle.each{|x1, y1|
cnt += 1 if (x1-x0)**2 + (y1-y0)**2 <= 1.0 + epsilon
# puts "#{x0} #{y0} #{x1} #{y1} #{(x1-x0)**2 + (y1-y0)**2}"
}
max = cnt if max < cnt
}
puts max
end
|
[["-", 36, 36, 36, 36, 0, 493, 0, 662, 12, 612], ["+", 36, 36, 36, 36, 0, 493, 0, 662, 12, 531]]
| 4
| 271
| 2
|
# -*- coding: utf-8 -*-
import sys
import os
import math
for s in sys.stdin:
n = int(s)
if n == 0:
break
P = []
for i in range(n):
x, y = map(float, input().split(','))
P.append(complex(x, y))
def get_intersections(p0, p1):
"""
:type p0: complex
:type p1: complex
:return:
"""
dist = abs(p0 - p1)
if dist > 2:
return []
elif dist == 2:
return [(p0 + p1) / 2]
else:
m = (p0 + p1) / 2
v = m - p0
w = complex(v.imag, -v.real)
n = w / abs(w)
d = abs(v)
l = math.sqrt(1 - d ** 2)
inter0 = m + l * n
inter1 = m - l * n
return [inter0, inter1]
intersections = []
for i in range(n):
for j in range(i+1, n):
intersections += get_intersections(P[i], P[j])
counts = []
# each intersection, it is in how many circles?
for intersection in intersections:
cnt = 0
for p in P:
if abs(intersection - p) <= 1:
cnt += 1
counts.append(cnt)
if counts:
print(max(counts))
else:
print(0)
|
# -*- coding: utf-8 -*-
import sys
import os
import math
for s in sys.stdin:
n = int(s)
if n == 0:
break
P = []
for i in range(n):
x, y = map(float, input().split(','))
P.append(complex(x, y))
def get_intersections(p0, p1):
"""
:type p0: complex
:type p1: complex
:return:
"""
dist = abs(p0 - p1)
if dist > 2:
return []
elif dist == 2:
return [(p0 + p1) / 2]
else:
m = (p0 + p1) / 2
v = m - p0
w = complex(v.imag, -v.real)
n = w / abs(w)
d = abs(v)
l = math.sqrt(1 - d ** 2)
inter0 = m + l * n
inter1 = m - l * n
return [inter0, inter1]
intersections = []
for i in range(n):
for j in range(i+1, n):
intersections += get_intersections(P[i], P[j])
counts = []
# each intersection, it is in how many circles?
for intersection in intersections:
cnt = 0
for p in P:
if abs(intersection - p) <= 1.01:
cnt += 1
counts.append(cnt)
if counts:
print(max(counts))
else:
print(1)
|
[["-", 0, 7, 8, 196, 0, 57, 15, 666, 0, 612], ["+", 0, 7, 8, 196, 0, 57, 15, 666, 0, 531], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 612], ["+", 8, 196, 0, 1, 0, 652, 3, 4, 0, 612]]
| 5
| 276
| 4
|
def x(p0, p1):
d = abs(p0 - p1)
if d > 2:
return []
elif d == 2:
return [(p0 + p1) / 2]
else:
m = (p0 + p1) / 2
v = m - p0
w = complex(v.imag, -v.real)
l = abs(w)
h = (1 - l ** 2) ** .5 * w / l
return [m + h, m - h]
for e in iter(input, '0'):
n = int(e)
P = [complex(*map(float, input().split(','))) for _ in [0] * n]
Q = []
for i in range(n):
for j in range(i + 1, n):
Q += x(P[i], P[j])
print(max([sum(1.00 >= abs(q - p) for p in P) for q in Q] + [1]))
|
def x(p0, p1):
d = abs(p0 - p1)
if d > 2:
return []
elif d == 2:
return [(p0 + p1) / 2]
else:
m = (p0 + p1) / 2
v = m - p0
w = complex(v.imag, -v.real)
l = abs(w)
h = (1 - l ** 2) ** .5 * w / l
return [m + h, m - h]
for e in iter(input, '0'):
n = int(e)
P = [complex(*map(float, input().split(','))) for _ in [0] * n]
Q = []
for i in range(n):
for j in range(i + 1, n):
Q += x(P[i], P[j])
print(max([sum(1.02 >= abs(q - p) for p in P) for q in Q] + [1]))
|
[["-", 31, 658, 8, 652, 3, 668, 8, 666, 0, 531], ["+", 31, 658, 8, 652, 3, 668, 8, 666, 0, 531]]
| 5
| 217
| 2
|
import itertools,math
def isOverlapped(x1,y1,x2,y2,r1,r2):
return ((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))**0.5<=r1+r2+0.000009
while True:
n=eval(input())
if n==0:
break
li=[]
for i in range(n):
li.append(list(map(float,input().split(","))))
ma=0
for i,j in itertools.combinations(range(n),2):
if isOverlapped(li[i][0],li[i][1],li[j][0],li[j][1],1,1):
L=((li[i][0]-li[j][0])**2+(li[i][1]-li[j][1])**2)**0.5
t=math.atan2(li[j][1]-li[i][1],li[j][0]-li[i][0])
al=math.acos(L/2)
node=[[li[i][0]+math.cos(t+al),li[i][1]+math.sin(t+al)],
[li[i][0]+math.cos(t-al),li[i][1]+math.sin(t-al)]]
for p in range(2):
c=0
for q in range(n):
if isOverlapped(node[p][0],node[p][1],li[q][0],li[q][1],0,1):
c+=1
ma=max(c,ma)
print(ma)
|
import itertools,math
def isOverlapped(x1,y1,x2,y2,r1,r2):
return ((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))**0.5<=r1+r2+0.000009
while True:
n=eval(input())
if n==0:
break
li=[]
for i in range(n):
li.append(list(map(float,input().split(","))))
ma=1
for i,j in itertools.combinations(range(n),2):
if isOverlapped(li[i][0],li[i][1],li[j][0],li[j][1],1,1):
L=((li[i][0]-li[j][0])**2+(li[i][1]-li[j][1])**2)**0.5
t=math.atan2(li[j][1]-li[i][1],li[j][0]-li[i][0])
al=math.acos(L/2)
node=[[li[i][0]+math.cos(t+al),li[i][1]+math.sin(t+al)],
[li[i][0]+math.cos(t-al),li[i][1]+math.sin(t-al)]]
for p in range(2):
c=0
for q in range(n):
if isOverlapped(node[p][0],node[p][1],li[q][0],li[q][1],0,1):
c+=1
ma=max(c,ma)
print(ma)
|
[["-", 0, 52, 8, 196, 0, 1, 0, 662, 12, 612], ["+", 0, 52, 8, 196, 0, 1, 0, 662, 12, 612]]
| 5
| 408
| 2
|
import java.util.*;
public class Main {
private static final Scanner scn = new Scanner(System.in);
public static void main(String[] args) {
for (int n = scn.nextInt(); n > 0; n--) {
System.out.println(scn.nextLine().replace("Hoshino", "Hoshina"));
}
}
}
|
import java.util.*;
public class Main {
private static final Scanner scn = new Scanner(System.in);
public static void main(String[] args) {
for (int n = Integer.parseInt(scn.nextLine()); n > 0; n--) {
System.out.println(scn.nextLine().replace("Hoshino", "Hoshina"));
}
}
}
|
[["+", 0, 7, 502, 503, 49, 200, 51, 492, 500, 22], ["+", 0, 7, 502, 503, 49, 200, 51, 492, 0, 131], ["+", 0, 7, 502, 503, 49, 200, 51, 492, 141, 22], ["+", 502, 503, 49, 200, 51, 492, 3, 4, 0, 24], ["-", 0, 7, 502, 503, 49, 200, 51, 492, 141, 22], ["+", 49, 200, 51, 492, 3, 4, 0, 492, 141, 22], ["+", 51, 492, 3, 4, 0, 492, 3, 4, 0, 25]]
| 3
| 82
| 7
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class Main {
public static void main(String args[]) throws IOException {
BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));
int sets = Integer.parseInt(bfr.readLine());
for (int i = 0; i < sets; i++) {
String now = bfr.readLine();
char ans[] = now.toCharArray();
for (int j = 0; j < now.length() - 6; j++) {
if (now.substring(i, i + 7).equals("Hoshino")) {
ans[j] = 'H';
ans[j + 1] = 'o';
ans[j + 2] = 's';
ans[j + 3] = 'h';
ans[j + 4] = 'i';
ans[j + 5] = 'n';
ans[j + 6] = 'a';
}
}
System.out.println(new String(ans));
}
}
}
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class Main {
public static void main(String args[]) throws IOException {
BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));
int sets = Integer.parseInt(bfr.readLine());
for (int i = 0; i < sets; i++) {
String now = bfr.readLine();
char ans[] = now.toCharArray();
for (int j = 0; j < now.length() - 6; j++) {
if (now.substring(j, j + 7).equals("Hoshino")) {
ans[j] = 'H';
ans[j + 1] = 'o';
ans[j + 2] = 's';
ans[j + 3] = 'h';
ans[j + 4] = 'i';
ans[j + 5] = 'n';
ans[j + 6] = 'a';
}
}
System.out.println(new String(ans));
}
}
}
|
[["-", 15, 15, 0, 492, 500, 492, 3, 4, 0, 22], ["+", 15, 15, 0, 492, 500, 492, 3, 4, 0, 22], ["-", 0, 492, 500, 492, 3, 4, 0, 16, 31, 22], ["+", 0, 492, 500, 492, 3, 4, 0, 16, 31, 22]]
| 3
| 222
| 4
|
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
String str1 = sc.nextLine();
if (str1.contains("Hoshino")) {
String str2 = str1.replace("Hoshino", "Hoshina");
System.out.println(str2);
} else {
System.out.println(str1);
}
}
}
}
|
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
for (int i = 0; i < n; i++) {
String str1 = sc.nextLine();
if (str1.contains("Hoshino")) {
String str2 = str1.replace("Hoshino", "Hoshina");
System.out.println(str2);
} else {
System.out.println(str1);
}
}
}
}
|
[["+", 0, 195, 8, 196, 0, 1, 0, 492, 500, 22], ["+", 0, 195, 8, 196, 0, 1, 0, 492, 0, 131], ["+", 0, 195, 8, 196, 0, 1, 0, 492, 141, 22], ["+", 8, 196, 0, 1, 0, 492, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 492, 3, 4, 0, 25], ["+", 8, 498, 0, 195, 8, 196, 0, 1, 0, 35]]
| 3
| 119
| 6
|
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.io.*;
import java.lang.*;
import java.math.*;
import java.util.*;
public class Main {
Scanner sc;
static final int INF = 1 << 28;
static final double EPS = 1e-9;
void run() {
sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
for (int i = 0; i < n; i++) {
String s = sc.nextLine();
s.replaceAll("Hoshino", "Hoshina");
println(s);
}
sc.close();
}
void print(String s) { System.out.print(s); }
void println(String s) { System.out.println(s); }
public static void main(String[] args) { new Main().run(); }
}
|
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.io.*;
import java.lang.*;
import java.math.*;
import java.util.*;
public class Main {
Scanner sc;
static final int INF = 1 << 28;
static final double EPS = 1e-9;
void run() {
sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
for (int i = 0; i < n; i++) {
String s = sc.nextLine();
s = s.replaceAll("Hoshino", "Hoshina");
println(s);
}
sc.close();
}
void print(String s) { System.out.print(s); }
void println(String s) { System.out.println(s); }
public static void main(String[] args) { new Main().run(); }
}
|
[["+", 0, 7, 8, 196, 0, 1, 0, 11, 17, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 492, 500, 22]]
| 3
| 207
| 2
|
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws java.io.IOException {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
scan.nextLine();
for (int i = 0; i < n; i++) {
String str = scan.nextLine();
System.out.println(str.replaceAll("Hosino", "Hosina"));
}
}
}
|
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws java.io.IOException {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
scan.nextLine();
for (int i = 0; i < n; i++) {
String str = scan.nextLine();
System.out.println(str.replaceAll("Hoshino", "Hoshina"));
}
}
}
|
[["-", 3, 4, 0, 492, 3, 4, 0, 5, 0, 491], ["+", 3, 4, 0, 492, 3, 4, 0, 5, 0, 491]]
| 3
| 108
| 4
|
#include <stdio.h>
#include <string.h>
int main(void) {
char str[1024];
int i, j, n, len;
scanf("%d ", &n);
for (i = 0; i < n; i++) {
gets(str);
len = strlen(str);
for (j = 0; j < len - 6; j++) {
if (strncmp(&str[i], "Hoshino", 7) == 0) {
str[i + 6] = 'a';
}
}
puts(str);
}
return (0);
}
|
#include <stdio.h>
#include <string.h>
int main(void) {
char str[1024];
int i, j, n, len;
scanf("%d ", &n);
for (i = 0; i < n; i++) {
gets(str);
len = strlen(str);
for (j = 0; j < len - 5; j++) {
if (strncmp(&str[j], "Hoshino", 7) == 0) {
str[j + 6] = 'a';
}
}
puts(str);
}
return (0);
}
|
[["-", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13], ["-", 31, 2, 3, 4, 0, 66, 28, 69, 71, 22], ["+", 31, 2, 3, 4, 0, 66, 28, 69, 71, 22], ["-", 0, 1, 0, 11, 31, 69, 71, 16, 31, 22], ["+", 0, 1, 0, 11, 31, 69, 71, 16, 31, 22]]
| 0
| 122
| 6
|
#include <stdio.h>
#include <string.h>
int main(void) {
int n, i;
char *strptr;
char str[1002];
scanf("%d", &n);
for (i = 0; i < n; i++) {
fgets(str, 1002, stdin);
strptr = str;
while ((strptr = strstr(strptr, "Hoshino")) != NULL) {
strptr += 6;
*strptr = 'a';
}
printf("%s", str);
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
int main(void) {
int n, i;
char *strptr;
char str[1002];
scanf("%d", &n);
getchar();
for (i = 0; i < n; i++) {
fgets(str, 1002, stdin);
strptr = str;
while ((strptr = strstr(strptr, "Hoshino")) != NULL) {
strptr += 6;
*strptr = 'a';
}
printf("%s", str);
}
return 0;
}
|
[["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["+", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35]]
| 0
| 106
| 4
|
#include <stdio.h>
int main(void) {
char str[3000];
int i, j, k;
int n;
scanf("%d%*c", &n);
for (i = 0; i <= n; i++) {
fgets(str, 3000, stdin);
/*k = 0;
while(str[k] != '\0'){
if(str[k] == '\n'){
str[k] = '\0';
}
k++;
}*/
j = 0;
while (str[j] != '\0') {
if (str[j] == 'H') {
if (str[j + 1] == 'o') {
if (str[j + 2] == 's') {
if (str[j + 3] == 'h') {
if (str[j + 4] == 'i') {
if (str[j + 5] == 'n') {
if (str[j + 6] == 'o') {
str[j + 6] = 'a';
}
}
}
}
}
}
}
j++;
}
printf("%s", str);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
char str[3000];
int i, j, k;
int n;
scanf("%d%*c", &n);
for (i = 0; i < n; i++) {
fgets(str, 3000, stdin);
/*k = 0;
while(str[k] != '\0'){
if(str[k] == '\n'){
str[k] = '\0';
}
k++;
}*/
j = 0;
while (str[j] != '\0') {
if (str[j] == 'H') {
if (str[j + 1] == 'o') {
if (str[j + 2] == 's') {
if (str[j + 3] == 'h') {
if (str[j + 4] == 'i') {
if (str[j + 5] == 'n') {
if (str[j + 6] == 'o') {
str[j + 6] = 'a';
}
}
}
}
}
}
}
j++;
}
printf("%s", str);
}
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18]]
| 0
| 206
| 2
|
#include <stdio.h>
#include <string.h>
int main(void) {
int i, n;
char *p;
char a[1002];
// char word[]="hoshino"
scanf("%d\n", &n);
for (i = 0; i < n; i++) {
fgets(a, sizeof(a), stdin);
while ((p = strstr(a, "hoshino")) != NULL) {
p[6] = 'a';
}
printf("%s", a);
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
int main(void) {
int i, n;
char *p;
char a[1002];
// char word[]="hoshino";
scanf("%d\n", &n);
for (i = 0; i < n; i++) {
fgets(a, sizeof(a), stdin);
while ((p = strstr(a, "Hoshino")) != NULL) {
p[6] = 'a';
}
printf("%s", a);
}
return 0;
}
|
[["-", 0, 11, 12, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 11, 12, 2, 3, 4, 0, 5, 0, 6]]
| 0
| 105
| 2
|
#include <stdio.h>
#include <string.h>
int main() {
int n, i;
char *p;
char str[1007] = {};
scanf("%d", &n);
while (n--) {
fgets(str, sizeof(str), stdin);
while ((p = strstr(str, "Hoshino")) != NULL)
p[6] = 'a';
printf("%s", str);
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
int main() {
int n, i;
char *p;
char str[1003];
scanf("%d\n", &n);
while (n--) {
fgets(str, sizeof(str), stdin);
while ((p = strstr(str, "Hoshino")) != NULL)
p[6] = 'a';
printf("%s", str);
}
return 0;
}
|
[["-", 8, 9, 0, 43, 49, 50, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["-", 0, 14, 8, 9, 0, 43, 49, 50, 0, 32], ["-", 8, 9, 0, 43, 49, 50, 51, 83, 0, 45], ["-", 8, 9, 0, 43, 49, 50, 51, 83, 0, 46], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 95
| 6
|
#include <stdio.h>
#include <string.h>
int main() {
char word[1111];
int n, i;
scanf("%d", &n);
for (i = 0; i < n; i++) {
gets(word);
for (;;) {
if (strstr(word, "Hoshino") == 0) {
break;
} else {
strncpy(strstr(word, "Hoshino"), "Hoshina", 7);
}
}
printf("%s\n", word);
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
int main() {
char word[1111];
int n, i;
scanf("%d\n", &n);
for (i = 0; i < n; i++) {
gets(word);
for (;;) {
if (strstr(word, "Hoshino") == 0) {
break;
} else {
strncpy(strstr(word, "Hoshino"), "Hoshina", 7);
}
}
printf("%s\n", word);
}
return 0;
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 109
| 1
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define reep(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) reep((i), 0, (n))
#define ALL(v) (v).begin(), (v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair
static const double PI = 6 * asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
static const int INF = 1 << 24;
template <class T>
void initvv(vector<vector<T>> &v, int a, int b, const T &t = T()) {
v.assign(a, vector<T>(b, t));
}
int main() {
int n;
cin >> n;
string t;
getline(cin, t);
rep(i, n) {
string s;
getline(cin, s);
// cout<<s.size()<<endl;
if (s.size() <= 7) {
cout << s << endl;
continue;
}
rep(j, s.size() - 6) {
if (s.substr(j, 7) == "Hoshino") {
// cout<<"hoge"<<endl;
// cout<<s[j+6]<<endl;
s[j + 6] = 'a';
}
}
cout << s << endl;
}
return 0;
}
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define reep(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) reep((i), 0, (n))
#define ALL(v) (v).begin(), (v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair
static const double PI = 6 * asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
static const int INF = 1 << 24;
template <class T>
void initvv(vector<vector<T>> &v, int a, int b, const T &t = T()) {
v.assign(a, vector<T>(b, t));
}
int main() {
int n;
cin >> n;
string t;
getline(cin, t);
rep(i, n) {
string s;
getline(cin, s);
// cout<<s.size()<<endl;
if (s.size() < 7) {
cout << s << endl;
continue;
}
rep(j, s.size() - 6) {
if (s.substr(j, 7) == "Hoshino") {
// cout<<"hoge"<<endl;
// cout<<s[j+6]<<endl;
s[j + 6] = 'a';
}
}
cout << s << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18]]
| 1
| 295
| 2
|
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
using namespace std;
int main() {
int n, i, s, g;
string a;
cin >> n;
for (g = 0; g < n; g++) {
getline(cin, a);
if (a == "") {
g--;
continue;
}
for (i = 6; i <= a.size(); i++)
if (a[i - 6] == 'H' && a[i - 5] == 'o' && a[i - 4] == 's' &&
a[i - 3] == 'h' && a[i - 2] == 'i' && a[i - 1] == 'n' && a[i] == 'o')
a[i - 5] = 'a';
cout << a << endl;
}
return 0;
}
|
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
using namespace std;
int main() {
int n, i, s, g;
string a;
cin >> n;
for (g = 0; g < n; g++) {
getline(cin, a);
if (a == "") {
g--;
continue;
}
for (i = 6; i <= a.size(); i++)
if (a[i - 6] == 'H' && a[i - 5] == 'o' && a[i - 4] == 's' &&
a[i - 3] == 'h' && a[i - 2] == 'i' && a[i - 1] == 'n' && a[i] == 'o')
a[i] = 'a';
cout << a << endl;
}
return 0;
}
|
[["-", 0, 11, 31, 69, 341, 342, 0, 16, 17, 33], ["-", 0, 11, 31, 69, 341, 342, 0, 16, 12, 13]]
| 1
| 184
| 2
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
fflush(stdin);
while (N--) {
char S[1001];
for (int i = 0;; i++) {
scanf("%c", &S[i]);
if (S[i] == '\n') {
S[i] = '\0';
break;
}
}
int len = strlen(S);
for (int i = 0; i < len; i++) {
if (strncmp(S + i, "Hoshino", 7) == 0) {
printf("Hoshina");
i += 6;
} else
printf("%c", S[i]);
}
puts("");
}
return 0;
}
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
cin.ignore();
while (N--) {
char S[1001];
for (int i = 0;; i++) {
scanf("%c", &S[i]);
if (S[i] == '\n') {
S[i] = '\0';
break;
}
}
int len = strlen(S);
for (int i = 0; i < len; i++) {
if (strncmp(S + i, "Hoshino", 7) == 0) {
printf("Hoshina");
i += 6;
} else
printf("%c", S[i]);
}
puts("");
}
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 8, 9, 0, 1, 0, 2, 63, 118, 28, 22], ["+", 8, 9, 0, 1, 0, 2, 63, 118, 17, 131], ["+", 8, 9, 0, 1, 0, 2, 63, 118, 119, 120], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22]]
| 1
| 185
| 5
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.