buggy_code
stringlengths 11
625k
| fixed_code
stringlengths 17
625k
| bug_type
stringlengths 2
4.45k
| language
int64 0
8
| token_count
int64 5
200k
|
|---|---|---|---|---|
#include <cstdio>
#include <iostream>
#include <math.h>
using namespace std;
int prime[10000];
bool is_prime[1000000];
int sosuu(int n) {
int p = 0;
for (int i = 0; i < n; i++)
is_prime[i] = true;
is_prime[0] = is_prime[1] = false;
for (int i = 2; i <= n; i++) {
if (is_prime[i]) {
prime[p++] = i;
for (int j = i * 2; j <= n; j += i) {
is_prime[j] = false;
}
}
}
return p;
}
int main(void) {
int n;
while (cin >> n)
cout << sosuu(n) << endl;
return 0;
}
|
#include <cstdio>
#include <iostream>
#include <math.h>
using namespace std;
int prime[100000];
bool is_prime[1000000];
int sosuu(int n) {
int p = 0;
for (int i = 0; i <= n; i++)
is_prime[i] = true;
is_prime[0] = is_prime[1] = false;
for (int i = 2; i <= n; i++) {
if (is_prime[i]) {
prime[p++] = i;
for (int j = i * 2; j <= n; j += i) {
is_prime[j] = false;
}
}
}
return p;
}
int main(void) {
int n;
while (cin >> n)
cout << sosuu(n) << endl;
return 0;
}
|
[["-", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19]]
| 1
| 158
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int const M = 40;
int a, hantei[M];
int main() {
hantei[0] = hantei[1] = 1;
for (int i = 2; i < M; i++) {
if (hantei[i] == 0) {
for (int j = 2; j * i < M; j++) {
if (j * i < M) {
hantei[j * i] = 1;
}
}
}
}
for (; cin >> a;) {
int count = 0;
for (int i = 0; i <= a; i++) {
if (hantei[i] == 0) {
count++;
}
}
cout << count << endl;
}
}
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int const M = 1000010;
int a, hantei[M];
int main() {
hantei[0] = hantei[1] = 1;
for (int i = 2; i < M; i++) {
if (hantei[i] == 0) {
for (int j = 2; j * i < M; j++) {
if (j * i < M) {
hantei[j * i] = 1;
}
}
}
}
for (; cin >> a;) {
int count = 0;
for (int i = 0; i <= a; i++) {
if (hantei[i] == 0) {
count++;
}
}
cout << count << endl;
}
}
|
[["-", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13]]
| 1
| 159
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
vector<int> prime;
void init() {
for (int i = 2; i < 999999; i++) {
bool isprime = true;
for (vector<int>::iterator p(prime.begin()); p != prime.end(); p++) {
if ((*p) * (*p) > i)
break;
if (i % *p == 0) {
isprime = false;
break;
}
}
if (isprime) {
prime.push_back(i);
}
}
}
int main() {
int n;
init();
while (cin >> n) {
cout << lower_bound(prime.begin(), prime.end(), n) - prime.begin() + 1
<< endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
vector<int> prime;
void init() {
for (int i = 2; i < 999999; i++) {
bool isprime = true;
for (vector<int>::iterator p(prime.begin()); p != prime.end(); p++) {
if ((*p) * (*p) > i)
break;
if (i % *p == 0) {
isprime = false;
break;
}
}
if (isprime) {
prime.push_back(i);
}
}
}
int main() {
int n;
init();
while (cin >> n) {
cout << upper_bound(prime.begin(), prime.end(), n) - prime.begin() << endl;
}
return 0;
}
|
[["-", 31, 16, 12, 16, 31, 16, 31, 2, 63, 22], ["+", 0, 16, 31, 16, 12, 16, 31, 2, 63, 22], ["-", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["-", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
| 1
| 172
|
#include <iostream>
using namespace std;
int main() {
long n, i, j, *nn;
for (;;) {
cin >> n;
if (cin.eof())
break;
nn = new long[n + 1];
nn[1] = 0;
nn[2] = 1;
for (i = 3; i <= n; i += 2)
nn[i] = 1;
for (i = 4; i <= n; i += 2)
nn[i] = 0;
for (i = 3; i * i < n;) {
for (j = i; i * j <= n; j += 2)
nn[i * j] = 0;
i++;
while (nn[i] = 0)
i++;
}
for (i = 2, j = 0; i <= n; i++)
if (nn[i] == 1)
j++;
cout << j << endl;
delete[] nn;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
long n, i, j, *nn;
for (;;) {
cin >> n;
if (cin.eof())
break;
nn = new long[n + 1];
nn[1] = 0;
nn[2] = 1;
for (i = 3; i <= n; i += 2)
nn[i] = 1;
for (i = 4; i <= n; i += 2)
nn[i] = 0;
for (i = 3; i * i <= n;) {
for (j = i; i * j <= n; j += 2)
nn[i * j] = 0;
i++;
while (nn[i] == 0)
i++;
}
for (i = 2, j = 0; i <= n; i++)
if (nn[i] == 1)
j++;
cout << j << endl;
delete[] nn;
}
return 0;
}
|
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19], ["-", 8, 9, 0, 52, 15, 339, 51, 11, 17, 32], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 60]]
| 1
| 207
|
#include <bitset>
#include <iostream>
using namespace std;
int main() {
int count = 0, n;
bitset<1000001> prime;
prime[0] = 1;
prime[1] = 1;
for (int i = 2; i <= 1000; i++)
if (prime[i] == 0)
for (int j = i + 1; j <= 1000000; j++)
if (j % i == 0)
prime[j] = 1;
while (cin >> n) {
for (int i = 0; i <= n; i++)
if (prime[i] == 0)
count++;
cout << count << endl;
}
}
|
#include <bitset>
#include <iostream>
using namespace std;
int main() {
int count = 0, n;
bitset<1000001> prime;
prime[0] = 1;
prime[1] = 1;
for (int i = 2; i <= 1000; i++)
if (prime[i] == 0)
for (int j = i + 1; j <= 1000000; j++)
if (j % i == 0)
prime[j] = 1;
while (cin >> n) {
for (int i = 0; i <= n; i++)
if (prime[i] == 0)
count++;
cout << count << endl;
count = 0;
}
}
|
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 1
| 135
|
#include <iostream>
#include <vector>
int main() {
int n;
while (std::cin >> n) {
int ans = 0;
std::vector<int> vec(n);
for (int i = 0; i < n; i++)
vec[i] = 1;
vec[0] = vec[1] = 0;
for (int i = 2; i < n; i++) {
if (vec[i] == 1) {
ans++;
for (int j = 2 * i; j < n; j += i) {
vec[j] = 0;
}
}
}
std::cout << ans << std::endl;
}
return 0;
}
|
#include <iostream>
#include <vector>
int main() {
int n;
while (std::cin >> n) {
int ans = 0;
std::vector<int> vec(n + 1);
for (int i = 0; i <= n; i++)
vec[i] = 1;
vec[0] = vec[1] = 0;
for (int i = 2; i <= n; i++) {
if (vec[i] == 1) {
ans++;
for (int j = 2 * i; j <= n; j += i) {
vec[j] = 0;
}
}
}
std::cout << ans << std::endl;
}
return 0;
}
|
[["+", 0, 43, 49, 50, 51, 4, 0, 16, 17, 72], ["+", 0, 43, 49, 50, 51, 4, 0, 16, 12, 13], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19], ["-", 0, 57, 64, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 57, 64, 9, 0, 7, 15, 16, 17, 19]]
| 1
| 141
|
#include <stdio.h>
#include <string.h>
int main(void) {
int n = 99, a, b, c;
char x[1000000];
memset(x, 0, sizeof(x));
for (a = 2, c = 0; a <= n; a++) {
if (x[a]) {
x[a] = c;
continue;
}
x[a] = ++c;
for (b = a * 2; b <= n; b += a)
x[b] = -1;
}
while (~scanf("%d", &n)) {
printf("%d\n", x[n]);
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
int main(void) {
int n = 999999, a, b, c;
int x[1000000];
memset(x, 0, sizeof(x));
for (a = 2, c = 0; a <= n; a++) {
if (x[a]) {
x[a] = c;
continue;
}
x[a] = ++c;
for (b = a * 2; b <= n; b += a)
x[b] = -1;
}
while (~scanf("%d", &n)) {
printf("%d\n", x[n]);
}
return 0;
}
|
[["-", 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, 43, 39, 40], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40]]
| 1
| 139
|
#include <cstdio>
int d[1000000], c[1000000];
int main() {
int i, j, r = 0, n;
for (i = 2; i < 500000; i++) {
if (d[i]) {
c[i] = r;
continue;
}
c[i] = ++r;
for (j = i * 2; j <= 999999; j += i)
d[j] = 1;
}
while (scanf("%d", &n) != EOF) {
printf("%d\n", d[n]);
}
}
|
#include <cstdio>
int d[1000000], c[1000000];
int main() {
int i, j, r = 0, n;
for (i = 2; i <= 999999; i++) {
if (d[i]) {
c[i] = r;
continue;
}
c[i] = ++r;
for (j = i * 2; j <= 999999; j += i)
d[j] = 1;
}
while (scanf("%d", &n) != EOF) {
printf("%d\n", c[n]);
}
}
|
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["-", 0, 1, 0, 2, 3, 4, 0, 69, 28, 22], ["+", 0, 1, 0, 2, 3, 4, 0, 69, 28, 22]]
| 1
| 123
|
#include <iostream>
using namespace std;
int main() {
int prime[999999];
bool is_prime[1000000];
int p = 0;
int n;
int i;
while (cin >> n) {
for (i = 0; i <= n; i++)
is_prime[i] = true;
is_prime[0] = is_prime[1] = false;
for (i = 2; i <= n; i++) {
if (is_prime[i]) {
prime[p++] = i;
for (int j = 2 * i; j <= n; j += i)
is_prime[j] = false;
}
}
cout << p << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int prime[999999];
bool is_prime[1000000];
int p = 0;
int n;
int i;
while (cin >> n) {
for (i = 0; i <= n; i++)
is_prime[i] = true;
is_prime[0] = is_prime[1] = false;
for (i = 2; i <= n; i++) {
if (is_prime[i]) {
prime[p++] = i;
for (int j = 2 * i; j <= n; j += i)
is_prime[j] = false;
}
}
cout << p << endl;
p = 0;
}
return 0;
}
|
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 1
| 140
|
#include <math.h>
#include <stdio.h>
#define DB(x) (x)
int prime[80000];
int GetPrime(int num);
int main() {
int count = GetPrime(1000000);
DB(printf("%d\n", count));
int n, ans[100], cor = 0;
int i;
while (scanf("%d", &n) != EOF) {
for (i = 0; n >= prime[i] && i < count; i++)
;
ans[cor] = i;
cor++;
}
for (i = 0; i < cor; i++)
printf("%d\n", ans[i]);
return 0;
}
int GetPrime(int num) {
int i, j, count = 0;
int sqnum = sqrt((double)num);
for (i = 2; i <= num; i++) {
for (j = 0; j < count; j++) {
if (prime[j] > sqnum)
goto COUNT;
if (i % prime[j] == 0)
break;
}
if (j < count)
continue;
COUNT:
prime[count] = i;
count++;
}
return count;
}
|
#include <math.h>
#include <stdio.h>
#define DB(x)
int prime[80000];
int GetPrime(int num);
int main() {
int count = GetPrime(1000000);
DB(printf("%d\n", count));
int n, ans[100], cor = 0;
int i;
while (scanf("%d", &n) != EOF) {
for (i = 0; n >= prime[i] && i < count; i++)
;
ans[cor] = i;
cor++;
}
for (i = 0; i < cor; i++)
printf("%d\n", ans[i]);
return 0;
}
int GetPrime(int num) {
int i, j, count = 0;
int sqnum = sqrt((double)num);
for (i = 2; i <= num; i++) {
for (j = 0; j < count; j++) {
if (prime[j] > sqnum)
goto COUNT;
if (i % prime[j] == 0)
break;
}
if (j < count)
continue;
COUNT:
prime[count] = i;
count++;
}
return count;
}
|
[["-", 36, 36, 36, 36, 0, 30, 0, 112, 51, 59]]
| 1
| 247
|
#include <iostream>
#include <math.h>
using namespace std;
int main() {
int b[1000000];
for (int k = 0; k < 1000001; k++) {
b[k] = 0;
}
b[2] = 1;
b[3] = 1;
b[4] = 0;
b[5] = 1;
b[6] = 0;
b[7] = 1;
for (int p = 11; p < 1000001; p += 2) {
int i, a = 0;
i = 3;
while (i < sqrt(p)) {
if (p % i == 0) {
break;
}
i = i + 2;
}
if (i >= sqrt(p)) {
a = 1;
}
b[p] = a;
}
int c[1000000];
for (int l = 0; l < 1000001; l++) {
c[l + 1] = c[l] + b[l + 1];
}
int r;
while (cin >> r) {
cout << c[r] << endl;
}
return 0;
}
|
#include <iostream>
#include <math.h>
using namespace std;
int main() {
int b[1000000];
for (int k = 0; k < 1000001; k++) {
b[k] = 0;
}
b[2] = 1;
b[3] = 1;
b[4] = 0;
b[5] = 1;
b[6] = 0;
b[7] = 1;
for (int p = 11; p < 1000001; p += 2) {
int i, a = 0;
i = 3;
while (i <= sqrt(p)) {
if (p % i == 0) {
break;
}
i = i + 2;
}
if (i > sqrt(p)) {
a = 1;
}
b[p] = a;
}
int c[1000000];
for (int l = 0; l < 1000001; l++) {
c[l + 1] = c[l] + b[l + 1];
}
int r;
while (cin >> r) {
cout << c[r] << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 52, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 19], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47]]
| 1
| 228
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Map<String, Integer> cache = new HashMap<String, Integer>();
final Integer MAX = 1000000;
boolean[] natural = new boolean[MAX];
int[] counts = new int[MAX];
for (int i = 2; i <= 500000; i++) {
for (int j = 2; j <= Math.ceil(999999 / i); j++) {
natural[i * j] = true;
}
}
String line;
while ((line = br.readLine()) != null && !line.isEmpty()) {
if (cache.containsKey(line))
System.out.println(cache.get(line));
int cnt = 0;
for (int i = 2; i <= Integer.parseInt(line); i++) {
if (!natural[i])
cnt++;
}
cache.put(line, cnt);
System.out.println(cnt);
}
}
}
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Map<String, Integer> cache = new HashMap<String, Integer>();
final Integer MAX = 1000000;
boolean[] natural = new boolean[MAX];
int[] counts = new int[MAX];
for (int i = 2; i <= 500000; i++) {
for (int j = 2; j <= Math.ceil(999999 / i); j++) {
natural[i * j] = true;
}
}
String line;
while ((line = br.readLine()) != null && !line.isEmpty()) {
if (cache.containsKey(line)) {
System.out.println(cache.get(line));
continue;
}
int cnt = 0;
for (int i = 2; i <= Integer.parseInt(line); i++) {
if (!natural[i])
cnt++;
}
cache.put(line, cnt);
System.out.println(cnt);
}
}
}
|
[["+", 0, 52, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117], ["+", 0, 52, 8, 196, 0, 57, 64, 196, 0, 46]]
| 3
| 267
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNextInt()) {
int n = sc.nextInt();
int c = 0;
boolean[] p = new boolean[n + 1];
for (int i = 0; i <= n; i++) {
p[i] = true;
}
int l = Double.valueOf(Math.sqrt((double)n)).intValue() + 1;
for (int i = 2; i <= l; i++) {
for (int j = i * 2; j < n; j += i) {
p[j] = false;
}
}
for (int i = 2; i <= n; i++) {
if (p[i]) {
c++;
}
}
System.out.println(c);
}
}
}
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNextInt()) {
int n = sc.nextInt();
int c = 0;
boolean[] p = new boolean[n + 1];
for (int i = 0; i <= n; i++) {
p[i] = true;
}
int l = Double.valueOf(Math.sqrt((double)n)).intValue() + 1;
for (int i = 2; i <= l; i++) {
for (int j = i * 2; j <= n; j += i) {
p[j] = false;
}
}
for (int i = 2; i <= n; i++) {
if (p[i]) {
c++;
}
}
System.out.println(c);
}
}
}
|
[["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
| 3
| 198
|
import java.util.*;
class Main {
public static void main(String[] z) {
int i = 0, e = 2, c;
int[] p = new int[175];
for (; i < 175; p[i++] = e++)
for (; f(p, e) < 1; e++)
;
for (Scanner s = new Scanner(System.in); s.hasNext();
System.out.println(c)) {
e = s.nextInt();
for (c = 0, i = 2; i < e; ++i)
if (f(p, i) > 0)
++c;
}
}
static int f(int[] p, int n) {
for (int e : p)
if (e > 0 && n != e && n % e < 1)
return 0;
return 1;
}
}
|
import java.util.*;
class Main {
public static void main(String[] z) {
int i = 0, e = 2, c;
int[] p = new int[175];
for (; i < 175; p[i++] = e++)
for (; f(p, e) < 1; e++)
;
for (Scanner s = new Scanner(System.in); s.hasNext();
System.out.println(c)) {
e = s.nextInt();
for (c = 0, i = 2; i <= e; ++i)
if (f(p, i) > 0)
++c;
}
}
static int f(int[] p, int n) {
for (int e : p)
if (e > 0 && n != e && n % e < 1)
return 0;
return 1;
}
}
|
[["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
| 3
| 189
|
import java.util.*;
public class Main {
static Scanner sc = new Scanner(System.in);
static int n;
static boolean[] prime;
public static void main(String[] args) {
makePrime();
while (read()) {
solve();
}
}
static boolean read() {
if (!sc.hasNext())
return false;
n = sc.nextInt();
return true;
}
static void solve() {
int res = 0;
for (int i = 2; i < n; i++) {
if (prime[i])
res++;
}
System.out.println(res);
}
static void makePrime() {
prime = new boolean[1000001];
Arrays.fill(prime, true);
prime[0] = false;
prime[1] = false;
for (int i = 2; i < prime.length; i++) {
if (prime[i]) {
for (int j = i * 2; j < prime.length; j = j + i) {
prime[j] = false;
}
}
}
}
}
|
import java.util.*;
public class Main {
static Scanner sc = new Scanner(System.in);
static int n;
static boolean[] prime;
public static void main(String[] args) {
makePrime();
while (read()) {
solve();
}
}
static boolean read() {
if (!sc.hasNext())
return false;
n = sc.nextInt();
return true;
}
static void solve() {
int res = 0;
for (int i = 2; i <= n; i++) {
if (prime[i])
res++;
}
System.out.println(res);
}
static void makePrime() {
prime = new boolean[1000001];
Arrays.fill(prime, true);
prime[0] = false;
prime[1] = false;
for (int i = 2; i < prime.length; i++) {
if (prime[i]) {
for (int j = i * 2; j < prime.length; j = j + i) {
prime[j] = false;
}
}
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 3
| 234
|
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int[] prime = new int[999999];
prime[0] = 2;
int num = 1;
while (s.hasNext()) {
int n = s.nextInt();
if (prime[num - 1] > n) {
int out = 0;
for (int i = 0;; i++) {
if (prime[i] > n) {
out = i;
break;
}
}
System.out.println(out);
} else {
for (int i = prime[num - 1] + 1; i <= n; i++) {
boolean flag = true;
for (int j = 0; prime[j] * prime[j] < i; j++) {
if (i % prime[j] == 0) {
flag = false;
break;
}
}
if (flag) {
prime[num] = i;
num++;
}
}
System.out.println(num);
}
}
}
}
|
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int[] prime = new int[999999];
prime[0] = 2;
int num = 1;
while (s.hasNext()) {
int n = s.nextInt();
if (prime[num - 1] > n) {
int out = 0;
for (int i = 0;; i++) {
if (prime[i] > n) {
out = i;
break;
}
}
System.out.println(out);
} else {
for (int i = prime[num - 1] + 1; i <= n; i++) {
boolean flag = true;
for (int j = 0; prime[j] * prime[j] <= i; j++) {
if (i % prime[j] == 0) {
flag = false;
break;
}
}
if (flag) {
prime[num] = i;
num++;
}
}
System.out.println(num);
}
}
}
}
|
[["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
| 3
| 232
|
import java.util.*;
public class Main {
static Scanner sc = new Scanner(System.in);
static boolean[] prime_number;
static int max;
public static void main(String[] args) {
eratosu(999999);
while (read()) {
solve();
}
}
public static void eratosu(int max_int) {
prime_number = new boolean[max_int + 1];
prime_number[0] = false;
prime_number[1] = false;
for (int i = 2; i <= max_int; i++) {
prime_number[i] = true;
}
for (int i = 2; i <= max_int; i++) {
int n = i;
int x = 2;
while (n * x <= max_int) {
prime_number[n * x] = false;
x++;
}
}
}
public static Boolean read() {
if (!sc.hasNextInt())
return false;
max = sc.nextInt();
return true;
}
public static void solve() {
int cnt = 0;
for (int i = 2; i < max; i++) {
if (prime_number[i]) {
cnt++;
}
}
System.out.println(cnt);
}
}
|
import java.util.*;
public class Main {
static Scanner sc = new Scanner(System.in);
static boolean[] prime_number;
static int max;
public static void main(String[] args) {
eratosu(999999);
while (read()) {
solve();
}
}
public static void eratosu(int max_int) {
prime_number = new boolean[max_int + 1];
prime_number[0] = false;
prime_number[1] = false;
for (int i = 2; i <= max_int; i++) {
prime_number[i] = true;
}
for (int i = 2; i <= max_int; i++) {
int n = i;
int x = 2;
while (n * x <= max_int) {
prime_number[n * x] = false;
x++;
}
}
}
public static Boolean read() {
if (!sc.hasNextInt())
return false;
max = sc.nextInt();
return true;
}
public static void solve() {
int cnt = 0;
for (int i = 2; i <= max; i++) {
if (prime_number[i]) {
cnt++;
}
}
System.out.println(cnt);
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 3
| 249
|
import java.util.Scanner;
public class Main {
static boolean[] primes;
static void primeSet(final int MAX) {
primes = new boolean[MAX + 1];
primes[2] = true;
for (int i = 3; i <= MAX; i += 2) {
primes[i] = true;
}
int rt = (int)Math.sqrt(MAX);
for (int i = 3; i <= rt; i += 2) {
if (primes[i]) {
for (int j = i * 2; j <= MAX; j += i) {
primes[j] = false;
}
}
}
}
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
while (stdIn.hasNext()) {
int n = stdIn.nextInt();
int cnt = 0;
if (n < 2) {
System.out.println("0");
return;
}
primeSet(n);
for (int i = 0; i <= n; i++) {
if (primes[i]) {
cnt++;
}
}
System.out.println(cnt);
}
}
}
|
import java.util.Scanner;
public class Main {
static boolean[] primes;
static void primeSet(final int MAX) {
primes = new boolean[MAX + 1];
primes[2] = true;
for (int i = 3; i <= MAX; i += 2) {
primes[i] = true;
}
int rt = (int)Math.sqrt(MAX);
for (int i = 3; i <= rt; i += 2) {
if (primes[i]) {
for (int j = i * 2; j <= MAX; j += i) {
primes[j] = false;
}
}
}
}
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
while (stdIn.hasNext()) {
int n = stdIn.nextInt();
int cnt = 0;
if (n < 2) {
System.out.println("0");
continue;
}
primeSet(n);
for (int i = 0; i <= n; i++) {
if (primes[i]) {
cnt++;
}
}
System.out.println(cnt);
}
}
}
|
[["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117]]
| 3
| 244
|
import java.io.*;
import java.util.*;
public class Main {
public static void main(String... args) {
Main m = new Main();
m.start();
m.close();
}
private Scanner sc;
private PrintWriter pw;
public Main() {
sc = new Scanner(System.in);
pw = new PrintWriter(System.out);
}
private void close() {
pw.flush();
pw.close();
}
private boolean has() { return sc.hasNextInt(); }
private int nint() { return sc.nextInt(); }
static int MAX = 1000000;
boolean[] primes = new boolean[MAX];
boolean[] isPrime = new boolean[MAX];
private void start() {
for (int i = 0; i < MAX; i++) {
primes[i] = false;
isPrime[i] = true;
}
for (int i = 2; i < MAX - 1; i++) {
if (isPrime[i])
primes[i] = true;
for (int j = i; j < MAX; j += i)
isPrime[j] = false;
}
while (has()) {
pw.println(solve());
}
}
private int solve() {
int N = nint();
int ans = 0;
for (int i = 0; i < N; i++) {
if (primes[i])
ans++;
}
return ans;
}
}
|
import java.io.*;
import java.util.*;
public class Main {
public static void main(String... args) {
Main m = new Main();
m.start();
m.close();
}
private Scanner sc;
private PrintWriter pw;
public Main() {
sc = new Scanner(System.in);
pw = new PrintWriter(System.out);
}
private void close() {
pw.flush();
pw.close();
}
private boolean has() { return sc.hasNextInt(); }
private int nint() { return sc.nextInt(); }
static int MAX = 1000000;
boolean[] primes = new boolean[MAX];
boolean[] isPrime = new boolean[MAX];
private void start() {
for (int i = 0; i < MAX; i++) {
primes[i] = false;
isPrime[i] = true;
}
for (int i = 2; i < MAX - 1; i++) {
if (isPrime[i])
primes[i] = true;
for (int j = i; j < MAX; j += i)
isPrime[j] = false;
}
while (has()) {
pw.println(solve());
}
}
private int solve() {
int N = nint();
int ans = 0;
for (int i = 0; i <= N; i++) {
if (primes[i])
ans++;
}
return ans;
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 3
| 315
|
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
boolean[] flag = new boolean[1000000];
for (int i = 2; i * i <= 1000000; i++) {
if (!flag[i]) {
for (int j = i * 2; j <= 1000000; j += i) {
flag[j] = true;
}
}
}
while (sc.hasNext()) {
int n = sc.nextInt();
int count = 0;
for (int i = 2; i <= n; i++) {
if (!flag[i])
count++;
}
System.out.println(count);
}
}
}
|
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
boolean[] flag = new boolean[1000001];
for (int i = 2; i * i <= 1000000; i++) {
if (!flag[i]) {
for (int j = i * 2; j <= 1000000; j += i) {
flag[j] = true;
}
}
}
while (sc.hasNext()) {
int n = sc.nextInt();
int count = 0;
for (int i = 2; i <= n; i++) {
if (!flag[i])
count++;
}
System.out.println(count);
}
}
}
|
[["-", 0, 503, 49, 200, 51, 227, 497, 505, 0, 499], ["+", 0, 503, 49, 200, 51, 227, 497, 505, 0, 499]]
| 3
| 167
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] a) {
String str;
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
try {
while (null != (str = bf.readLine())) {
int n = Integer.parseInt(str);
int[] arr = createArray(n);
for (int i = 2; i <= n; i++) {
for (int j = 2; n > i * j; j++) {
arr[i * j] = -1;
}
}
System.out.println(countArray(arr));
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
bf.close();
} catch (IOException e) {
}
}
}
private static int[] createArray(int number) {
int[] arr = new int[number + 1];
arr[0] = arr[1] = -1;
for (int i = 2; i <= number; i++) {
arr[i] = i;
}
return arr;
}
private static int countArray(int[] arr) {
int count = 0;
for (int n : arr)
if (n != -1)
count++;
return count;
}
}
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] a) {
String str;
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
try {
while (null != (str = bf.readLine())) {
int n = Integer.parseInt(str);
int[] arr = createArray(n);
for (int i = 2; i <= n; i++) {
for (int j = 2; n >= i * j; j++) {
arr[i * j] = -1;
}
}
System.out.println(countArray(arr));
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
bf.close();
} catch (IOException e) {
}
}
}
private static int[] createArray(int number) {
int[] arr = new int[number + 1];
arr[0] = arr[1] = -1;
for (int i = 2; i <= number; i++) {
arr[i] = i;
}
return arr;
}
private static int countArray(int[] arr) {
int count = 0;
for (int n : arr)
if (n != -1)
count++;
return count;
}
}
|
[["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 20]]
| 3
| 284
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
while (input.hasNextInt()) {
int n = input.nextInt();
int count = 1;
if (n < 2) {
System.out.println("0");
} else {
for (int i = 3; i <= n; i += 2) {
boolean isprime = true;
for (int j = 3; j <= Math.sqrt(i); j += 2) {
if (i % j == 0) {
isprime = false;
break;
}
}
if (isprime)
count++;
}
}
System.out.println(count);
}
}
}
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
while (input.hasNextInt()) {
int n = input.nextInt();
int count = 1;
if (n < 2) {
System.out.println("0");
} else {
for (int i = 3; i <= n; i += 2) {
boolean isprime = true;
for (int j = 3; j <= Math.sqrt(i); j += 2) {
if (i % j == 0) {
isprime = false;
break;
}
}
if (isprime)
count++;
}
System.out.println(count);
}
}
}
}
|
[["-", 0, 52, 8, 196, 0, 57, 75, 196, 0, 46], ["+", 0, 52, 8, 196, 0, 57, 75, 196, 0, 46]]
| 3
| 157
|
import java.util.*;
public class Main {
public static void main(String[] args) {
final int MAX = 999999;
Scanner sc = new Scanner(System.in);
boolean[] prime = primeList(MAX);
while (sc.hasNextInt()) {
int n = sc.nextInt();
int cnt = 0;
for (int i = 0; i < n; i++) {
if (prime[i])
cnt++;
}
System.out.println(cnt);
}
sc.close();
}
static boolean isPrime(int n) {
if (n < 2)
return false;
for (int i = 2; i * i < n; i++) {
if (n % i == 0)
return false;
}
return true;
}
static boolean[] primeList(int n) {
boolean[] prime = new boolean[n + 1];
for (int i = 2; i <= prime.length; i++)
prime[i] = true;
for (int i = 2; i * i < n; i++) {
if (isPrime(i)) {
for (int j = i + i; j <= n; j += i) {
prime[j] = false;
}
}
}
return prime;
}
}
|
import java.util.*;
public class Main {
public static void main(String[] args) {
final int MAX = 999999;
Scanner sc = new Scanner(System.in);
boolean[] prime = primeList(MAX);
while (sc.hasNextInt()) {
int n = sc.nextInt();
int cnt = 0;
for (int i = 0; i <= n; i++) {
if (prime[i])
cnt++;
}
System.out.println(cnt);
}
sc.close();
}
static boolean isPrime(int n) {
if (n < 2)
return false;
for (int i = 2; i * i < n; i++) {
if (n % i == 0)
return false;
}
return true;
}
static boolean[] primeList(int n) {
boolean[] prime = new boolean[n + 1];
for (int i = 2; i <= n; i++)
prime[i] = true;
for (int i = 2; i * i < n; i++) {
if (isPrime(i)) {
for (int j = i + i; j <= n; j += i) {
prime[j] = false;
}
}
}
return prime;
}
}
|
[["-", 0, 52, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 8, 196, 0, 7, 15, 16, 12, 509, 500, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 509, 0, 131], ["-", 8, 196, 0, 7, 15, 16, 12, 509, 119, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
| 3
| 269
|
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
int n = scanner.nextInt();
int result = 0;
boolean[] prime = new boolean[n + 1];
for (int i = 2; i < n + 1; i++) {
prime[i] = true;
}
for (int i = 2; i < n + 1; i++) {
if (prime[i]) {
result++;
for (int j = i + i; j < Math.sqrt(n + 1); j += i) {
prime[j] = false;
}
}
}
System.out.println(result);
}
}
}
|
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
int n = scanner.nextInt();
int result = 0;
boolean[] prime = new boolean[n + 1];
for (int i = 2; i < n + 1; i++) {
prime[i] = true;
}
for (int i = 2; i < n + 1; i++) {
if (prime[i]) {
result++;
for (int j = i + i; j < n + 1; j += i) {
prime[j] = false;
}
}
}
System.out.println(result);
}
}
}
|
[["-", 64, 196, 0, 7, 15, 16, 12, 492, 500, 22], ["-", 64, 196, 0, 7, 15, 16, 12, 492, 0, 131], ["-", 64, 196, 0, 7, 15, 16, 12, 492, 141, 22], ["-", 0, 7, 15, 16, 12, 492, 3, 4, 0, 24], ["-", 0, 7, 15, 16, 12, 492, 3, 4, 0, 25]]
| 3
| 169
|
import java.util.*;
public class Main {
/**
* @param args
*/
public static Scanner sc = new Scanner(System.in);
void run() {
int n, ans;
boolean[] sieve;
while (sc.hasNextInt()) {
n = sc.nextInt();
ans = 0;
sieve = new boolean[n + 1];
if (n <= 1)
System.out.println(1);
else {
for (int i = 2; i <= n; i++) {
if (!sieve[i]) {
ans++;
for (int j = 2; j * i <= n; j++)
sieve[j * i] = true;
}
}
System.out.println(ans);
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new Main().run();
}
}
|
import java.util.*;
public class Main {
/**
* @param args
*/
public static Scanner sc = new Scanner(System.in);
void run() {
int n, ans;
boolean[] sieve;
while (sc.hasNextInt()) {
n = sc.nextInt();
ans = 0;
sieve = new boolean[n + 1];
if (n <= 1)
System.out.println(0);
else {
for (int i = 2; i <= n; i++) {
if (!sieve[i]) {
ans++;
for (int j = 2; j * i <= n; j++)
sieve[j * i] = true;
}
}
System.out.println(ans);
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new Main().run();
}
}
|
[["-", 0, 57, 64, 1, 0, 492, 3, 4, 0, 499], ["+", 0, 57, 64, 1, 0, 492, 3, 4, 0, 499]]
| 3
| 177
|
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
int[] prime = new int[1000000];
for (int i = 2; i <= 500000; i++) {
for (int j = 2; i * j <= 1000000; j++) {
prime[i * j] = 1;
}
}
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
String s;
int n;
int cnt;
while ((s = buf.readLine()) != null) {
cnt = 0;
n = Integer.parseInt(s);
for (int i = 2; i <= n; i++) {
if (prime[i] == 0)
cnt++;
}
System.out.println(cnt);
}
}
}
|
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
int[] prime = new int[1000005];
for (int i = 2; i <= 500000; i++) {
for (int j = 2; i * j <= 1000000; j++) {
prime[i * j] = 1;
}
}
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
String s;
int n;
int cnt;
while ((s = buf.readLine()) != null) {
cnt = 0;
n = Integer.parseInt(s);
for (int i = 2; i <= n; i++) {
if (prime[i] == 0)
cnt++;
}
System.out.println(cnt);
}
}
}
|
[["-", 0, 503, 49, 200, 51, 227, 497, 505, 0, 499], ["+", 0, 503, 49, 200, 51, 227, 497, 505, 0, 499]]
| 3
| 170
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
@SuppressWarnings("resource") Scanner sc = new Scanner(System.in);
int MAX = 1000000;
int[] prime = new int[MAX];
prime[0] = prime[1] = 0;
for (int i = 2; i < MAX; i++) {
prime[i] = 1;
}
for (int i = 2; i < 1001; i++) {
if (prime[i] == 1) {
for (int j = 2 * i; j < MAX; j += i) {
prime[j] = 0;
}
}
}
while (sc.hasNext()) {
int number = Integer.parseInt(sc.nextLine());
int count = 0;
for (int i = 2; i < number; i++) {
count += prime[i];
}
System.out.println(count);
}
}
}
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
@SuppressWarnings("resource") Scanner sc = new Scanner(System.in);
int MAX = 1000000;
int[] prime = new int[MAX];
prime[0] = prime[1] = 0;
for (int i = 2; i < MAX; i++) {
prime[i] = 1;
}
for (int i = 2; i < 1001; i++) {
if (prime[i] == 1) {
for (int j = 2 * i; j < MAX; j += i) {
prime[j] = 0;
}
}
}
while (sc.hasNext()) {
int number = Integer.parseInt(sc.nextLine());
int count = 0;
for (int i = 2; i <= number; i++) {
count += prime[i];
}
System.out.println(count);
}
}
}
|
[["-", 0, 52, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 196, 0, 7, 15, 16, 17, 19]]
| 3
| 207
|
import java.util.HashSet;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while (scan.hasNext()) {
int n = scan.nextInt();
boolean[] isPrime = new boolean[n + 1];
for (int i = 2; i <= n; i++) {
isPrime[i] = true;
}
for (int i = 2; i <= n; i++) {
if (!isPrime[i])
continue;
for (int j = i * 2; j <= n; j += i) {
isPrime[i] = false;
}
}
int count = 0;
for (int i = 2; i <= n; i++) {
if (isPrime[i])
count++;
}
System.out.println(count);
}
}
}
|
import java.util.HashSet;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while (scan.hasNext()) {
int n = scan.nextInt();
boolean[] isPrime = new boolean[n + 1];
for (int i = 2; i <= n; i++) {
isPrime[i] = true;
}
for (int i = 2; i <= n; i++) {
if (!isPrime[i])
continue;
for (int j = i * 2; j <= n; j += i) {
isPrime[j] = false;
}
}
int count = 0;
for (int i = 2; i <= n; i++) {
if (isPrime[i])
count++;
}
System.out.println(count);
}
}
}
|
[["-", 8, 196, 0, 1, 0, 11, 31, 504, 71, 22], ["+", 8, 196, 0, 1, 0, 11, 31, 504, 71, 22]]
| 3
| 189
|
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
static int count = 1;
static int prime[500000] = {2, 3};
static bool primebool[500000] = {true, true};
int primesearch(int);
void primecount(int, int);
void reset();
int main() {
int n;
while (scanf("%d", &n) != EOF) {
if (n > 1) {
primecount(0, n);
printf("%d\n", count);
reset();
} else {
printf("0\n");
}
}
return 0;
}
void primecount(int i, int n) {
if (!primebool[i]) {
prime[i] = primesearch(prime[i - 1] + 2);
primebool[i] = true;
}
if (prime[i] <= n) {
count++;
primecount(i + 1, n);
}
}
int primesearch(int x) {
int i, sq;
sq = (int)sqrt(x);
for (i = 3; i <= sq; i = i + 2) {
if (x % i == 0) {
return primesearch(x + 2);
}
}
return x;
}
void reset() { count = 1; }
|
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
static int count = 0;
static int prime[500000] = {2, 3};
static bool primebool[500000] = {true, true};
int primesearch(int);
void primecount(int, int);
void reset();
int main() {
int n;
while (scanf("%d", &n) != EOF) {
if (n > 1) {
primecount(0, n);
printf("%d\n", count);
reset();
} else {
printf("0\n");
}
}
return 0;
}
void primecount(int i, int n) {
if (!primebool[i]) {
prime[i] = primesearch(prime[i - 1] + 2);
primebool[i] = true;
}
if (prime[i] <= n) {
count++;
primecount(i + 1, n);
}
}
int primesearch(int x) {
int i, sq;
sq = (int)sqrt(x);
for (i = 3; i <= sq; i = i + 2) {
if (x % i == 0) {
return primesearch(x + 2);
}
}
return x;
}
void reset() { count = 0; }
|
[["-", 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, 1, 0, 11, 12, 13], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 12, 13]]
| 0
| 265
|
#include <math.h>
#include <stdio.h>
int main(int argc, const char *argv[]) {
int n, i, j, k;
int count; //素数の個数
int l[100000]; //素数の数を格納
while (scanf("%d", &n) != EOF) {
count = 0;
//偶数で素数を持つのは2のみ
if (n >= 2) {
l[count++] = 2;
// printf("l[%d] = %d\n",count - 1,l[count - 1]);//
}
// 2より大きい偶数は素数を持たないので奇数のみ検査
if (n >= 3) {
l[count++] = 3;
// printf("l[%d] = %d\n",count - 1,l[count - 1]);//
for (i = 5; i <= n; i += 2) {
k = 0;
//エラトステネスのふるい
for (j = 1; pow(l[j], 2) <= i; j++) {
if (i % l[j] == 0) {
k = 1;
break;
}
}
if (k == 0) {
l[count++] = i;
// printf("l[%d] = %d\n",count - 1,l[count - 1]);//
}
}
}
printf("count = %d\n", count);
}
return 0;
}
|
#include <math.h>
#include <stdio.h>
int main(int argc, const char *argv[]) {
int n, i, j, k;
int count; //素数の個数
int l[100000]; //素数の数を格納
while (scanf("%d", &n) != EOF) {
count = 0;
//偶数で素数を持つのは2のみ
if (n >= 2) {
l[count++] = 2;
// printf("l[%d] = %d\n",count - 1,l[count - 1]);//
}
// 2より大きい偶数は素数を持たないので奇数のみ検査
if (n >= 3) {
l[count++] = 3;
// printf("l[%d] = %d\n",count - 1,l[count - 1]);//
for (i = 5; i <= n; i += 2) {
k = 0;
//エラトステネスのふるい
for (j = 1; pow(l[j], 2) <= i; j++) {
if (i % l[j] == 0) {
k = 1;
break;
}
}
if (k == 0) {
l[count++] = i;
// printf("l[%d] = %d\n",count - 1,l[count - 1]);//
}
}
}
printf("%d\n", count);
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 0
| 188
|
#include <stdio.h>
int main(void) {
long prm[78498] = {2, 3}, n, m, cnt = 2;
int judge;
for (n = 5; n <= 999999; n += 2) {
judge = 1;
for (m = 0; prm[m] * prm[m] <= n; m++) {
if (!n % prm[m]) {
judge = 0;
break;
}
}
if (judge) {
prm[cnt++] = n;
}
}
while (scanf("%ld", &n) != EOF) {
for (cnt = 0; prm[cnt] <= n; cnt++)
printf("%ld\n", cnt);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
long prm[78498] = {2, 3}, n, m, cnt = 2;
int judge;
for (n = 5; n <= 999999; n += 2) {
judge = 1;
for (m = 0; prm[m] * prm[m] <= n; m++) {
if (n % prm[m] == 0) {
judge = 0;
break;
}
}
if (judge) {
prm[cnt++] = n;
}
}
while (scanf("%ld", &n) != EOF) {
for (cnt = 0; prm[cnt] <= n; cnt++) {
}
printf("%ld\n", cnt);
}
return 0;
}
|
[["-", 0, 57, 15, 23, 0, 16, 31, 91, 17, 111], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 17, 60], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 12, 13], ["+", 0, 52, 8, 9, 0, 7, 8, 9, 0, 45], ["+", 0, 52, 8, 9, 0, 7, 8, 9, 0, 46]]
| 0
| 152
|
#include <stdio.h>
#define SIEVE_SIZE (1000000)
int not_p[SIEVE_SIZE] = {1, 1};
int prime_count[SIEVE_SIZE]; // [n] -> [0, n]
int main() {
int i, j;
int n;
for (i = 2; i * i < SIEVE_SIZE; i++) {
if (not_p[i])
continue;
for (j = i * i; j < SIEVE_SIZE; j += i) {
not_p[i] = 1;
}
}
for (i = 2; i < SIEVE_SIZE; i++) {
prime_count[i] = prime_count[i - 1] + !not_p[i];
}
while (scanf("%d", &n) == 1) {
printf("%d\n", prime_count[n]);
}
return (0);
}
|
#include <stdio.h>
#define SIEVE_SIZE (1000000)
int not_p[SIEVE_SIZE] = {1, 1};
int prime_count[SIEVE_SIZE]; // [n] -> [0, n]
int main() {
int i, j;
int n;
for (i = 2; i * i < SIEVE_SIZE; i++) {
if (not_p[i])
continue;
for (j = i * i; j < SIEVE_SIZE; j += i) {
not_p[j] = 1;
}
}
for (i = 2; i < SIEVE_SIZE; i++) {
prime_count[i] = prime_count[i - 1] + !not_p[i];
}
while (scanf("%d", &n) == 1) {
printf("%d\n", prime_count[n]);
}
return (0);
}
|
[["-", 8, 9, 0, 1, 0, 11, 31, 69, 71, 22], ["+", 8, 9, 0, 1, 0, 11, 31, 69, 71, 22]]
| 0
| 156
|
#include <stdio.h>
int p[1000000];
int main(void) {
int n;
int i, j;
p[0] = p[1] = 0;
for (i = 2; i < 1000000; i++) {
p[i] = 1;
}
for (i = 2; i * i < 1000000; i++) {
for (j = i * i; j < 1000000; j++) {
p[j] = 0;
}
}
for (i = 1; i < 1000000; i++) {
p[i] += p[i - 1];
}
while (scanf("%d", &n) != EOF) {
printf("%d\n", p[n]);
}
return (0);
}
|
#include <stdio.h>
int p[1000000];
int main(void) {
int n;
int i, j;
p[0] = p[1] = 0;
for (i = 2; i < 1000000; i++) {
p[i] = 1;
}
for (i = 2; i * i < 1000000; i++) {
for (j = i * i; j < 1000000; j += i) {
p[j] = 0;
}
}
for (i = 1; i < 1000000; i++) {
p[i] += p[i - 1];
}
while (scanf("%d", &n) != EOF) {
printf("%d\n", p[n]);
}
return (0);
}
|
[["-", 0, 7, 8, 9, 0, 7, 26, 27, 17, 29], ["+", 0, 7, 8, 9, 0, 7, 26, 11, 17, 107], ["+", 0, 7, 8, 9, 0, 7, 26, 11, 12, 22]]
| 0
| 159
|
#include <stdio.h>
int main(void) {
int i, j, n, count;
while (scanf("%d", &n) != EOF) {
int num[1000000] = {0};
for (i = 2; i <= n / 2; i++) {
for (j = 2; j * i < n; j++) {
num[i * j]++;
}
}
for (i = 2; i <= n; i++) {
if (num[i] == 0)
count++;
}
printf("%d\n", count);
}
return (0);
}
|
#include <stdio.h>
int main(void) {
int i, j, n, count;
while (scanf("%d", &n) != EOF) {
count = 0;
int num[1000000] = {0};
for (i = 2; i <= n / 2; i++) {
for (j = 2; j * i <= n; j++) {
num[i * j]++;
}
}
for (i = 2; i <= n; i++) {
if (num[i] == 0)
count++;
}
printf("%d\n", count);
}
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, 7, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19]]
| 0
| 128
|
#include <stdio.h>
#define N 1000000
int main() {
static int prime[N];
int i = 0, j = 0, k = 0, limit;
for (i = 2; i < N; i++) {
prime[i] = 1;
}
prime[0] = prime[1] = 0;
for (i = 2; i < N; i++) {
if (prime[i] == 1) {
for (j = i + i; j < N; j += i) {
prime[j] = 0;
}
}
}
while (scanf("%d", &limit) != EOF) {
for (i = 2; i <= limit; i++) {
if (prime[i] == 1) {
k++;
}
}
printf("%d\n", k);
}
return 0;
}
|
#include <stdio.h>
#define N 1000000
int main() {
static int prime[N];
int i = 0, j = 0, k = 0, limit;
for (i = 2; i < N; i++) {
prime[i] = 1;
}
prime[0] = prime[1] = 0;
for (i = 2; i < N; i++) {
if (prime[i] == 1) {
for (j = i + i; j < N; j += i) {
prime[j] = 0;
}
}
}
while (scanf("%d", &limit) != EOF) {
k = 0;
for (i = 2; i <= limit; i++) {
if (prime[i] == 1) {
k++;
}
}
printf("%d\n", k);
}
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
| 176
|
#include <stdio.h>
int memo[1000001] = {0};
int main() {
int n;
int i, j, k;
int sum;
for (i = 2; i <= 1000001; i++) {
if (memo[i] == 1)
continue;
for (k = i * 23; k <= 1000001; k += i)
memo[k] = 1;
}
while (scanf("%d", &n) != EOF) {
sum = 0;
for (i = 2; i <= n; i++) {
if (memo[i] == 1)
continue;
sum++;
}
printf("%d\n", sum);
}
return (0);
}
|
#include <stdio.h>
int memo[1000001] = {0};
int main() {
int n;
int i, j, k;
int sum;
for (i = 2; i <= 1000001; i++) {
if (memo[i] == 1)
continue;
for (k = i * 2; k <= 1000001; k += i)
memo[k] = 1;
}
while (scanf("%d", &n) != EOF) {
sum = 0;
for (i = 2; i <= n; i++) {
if (memo[i] == 1)
continue;
sum++;
}
printf("%d\n", sum);
}
return (0);
}
|
[["-", 8, 9, 0, 7, 10, 11, 12, 16, 12, 13], ["+", 8, 9, 0, 7, 10, 11, 12, 16, 12, 13]]
| 0
| 144
|
#include <math.h>
#include <stdio.h>
int prime(int x);
int main(void) {
int num[30], c[30], data[30];
int index = 0;
int i;
while (scanf("%d", &num[index]) != EOF) {
if ((1 <= num[index]) && (num[index] <= 999999))
index++;
if (index == 30)
break;
}
for (i = 0; i < index; i++) {
c[i] = prime(num[i]);
printf("%d\n", c[i]);
}
return 0;
}
int prime(int x) {
if (x < 2)
return 0;
if (x == 2)
return 1;
int count = 0;
int i, j, n;
int flg[500000];
for (i = 2; i < x; i++)
flg[i] = 1;
for (j = 2; j < x; j++) {
if (flg[j] == 1)
count++;
for (n = j * 2; n < x; n += j)
flg[n] = 0;
}
return count;
}
|
#include <math.h>
#include <stdio.h>
int prime(int x);
int main(void) {
int num[30], c[30], data[30];
int index = 0;
int i;
while (scanf("%d", &num[index]) != EOF) {
if ((1 <= num[index]) && (num[index] <= 999999))
index++;
if (index == 30)
break;
}
for (i = 0; i < index; i++) {
c[i] = prime(num[i]);
printf("%d\n", c[i]);
}
return 0;
}
int prime(int x) {
if (x < 2)
return 0;
if (x == 2)
return 1;
int count = 0;
int i, j, n;
int flg[x];
for (i = 1; i <= x; i++)
flg[i] = 1;
for (j = 2; j <= x; j++) {
if (flg[j] == 1)
count++;
for (n = j * 2; n <= x; n += j)
flg[n] = 0;
}
return count;
}
|
[["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 22], ["-", 0, 14, 8, 9, 0, 7, 10, 11, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 10, 11, 12, 13], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19]]
| 0
| 253
|
#include <stdio.h>
int main() {
int i, j, ch[1000000];
for (i = 0; i < 1000000; i += 2) {
ch[i] = 0;
ch[i + 1] = 1;
}
ch[1] = 0;
ch[2] = 1;
for (i = 3; i < 1000; i += 2)
if (ch[i])
for (j = i + i; j < 1000000; j += i)
ch[j] = 0;
for (i = 3; i < 1000000; i++)
ch[i] = ch[i - 1];
while (scanf("%d", &i) != EOF)
printf("%d\n", ch[i]);
return 0;
}
|
#include <stdio.h>
int main() {
int i, j, ch[1000000];
for (i = 0; i < 1000000; i += 2) {
ch[i] = 0;
ch[i + 1] = 1;
}
ch[1] = 0;
ch[2] = 1;
for (i = 3; i < 1000; i += 2)
if (ch[i])
for (j = i + i; j < 1000000; j += i)
ch[j] = 0;
for (i = 3; i < 1000000; i++)
ch[i] += ch[i - 1];
while (scanf("%d", &i) != EOF)
printf("%d\n", ch[i]);
return 0;
}
|
[["-", 8, 9, 0, 7, 8, 1, 0, 11, 17, 32], ["+", 8, 9, 0, 7, 8, 1, 0, 11, 17, 107]]
| 0
| 163
|
#include <stdio.h>
#define N 1000000
int calcPrime(int);
int main() {
int prime_num[N], i, num;
for (i = 0; i < N; i++)
prime_num[i] = 0;
for (i = 0; i < N; i++) {
if (calcPrime(i))
prime_num[i] = prime_num[i - 1] + 1;
else
prime_num[i] = prime_num[i - 1];
}
while (scanf("%d", &num) != EOF) {
printf("%d", prime_num[num]);
}
return 0;
}
int calcPrime(int num) {
int i;
if (num < 2)
return 0;
else if (num == 2)
return 1;
else if (num % 2 == 0)
return 0;
for (i = 3; i * i <= num; i = i + 2) {
if (num % i == 0)
return 0;
}
return 1;
}
|
#include <stdio.h>
#define N 1000000
int calcPrime(int);
int main() {
int prime_num[N], i, num;
for (i = 0; i < N; i++)
prime_num[i] = 0;
for (i = 0; i < N; i++) {
if (calcPrime(i))
prime_num[i] = prime_num[i - 1] + 1;
else
prime_num[i] = prime_num[i - 1];
}
while (scanf("%d", &num) != EOF) {
printf("%d\n", prime_num[num]);
}
return 0;
}
int calcPrime(int num) {
int i;
if (num < 2)
return 0;
else if (num == 2)
return 1;
else if (num % 2 == 0)
return 0;
for (i = 3; i * i <= num; i = i + 2) {
if (num % i == 0)
return 0;
}
return 1;
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 203
|
#include <stdio.h>
#define MAX 1000000
int total[MAX];
int main(void) {
int i, n, cnt;
total[0] = total[1] = 0;
for (i = 2; i < MAX; i++)
total[i] = 1;
for (i = 2; i * i < MAX; i++) {
if (total[i] == 1) {
for (n = i; n < MAX; n += i) {
total[n] = 0;
}
}
}
while (scanf("%d", &n) != EOF) {
cnt = 0;
for (i = 0; i <= n; i++) {
cnt += total[i];
}
printf("%d\n", cnt);
}
return 0;
}
|
#include <stdio.h>
#define MAX 1000000
int total[MAX];
int main(void) {
int i, n, cnt;
total[0] = total[1] = 0;
for (i = 2; i < MAX; i++)
total[i] = 1;
for (i = 2; i * i < MAX; i++) {
if (total[i] == 1) {
for (n = i * 2; n < MAX; n += i) {
total[n] = 0;
}
}
}
while (scanf("%d", &n) != EOF) {
cnt = 0;
for (i = 0; i <= n; i++) {
cnt += total[i];
}
printf("%d\n", cnt);
}
return 0;
}
|
[["+", 64, 9, 0, 7, 10, 11, 12, 16, 17, 48], ["+", 64, 9, 0, 7, 10, 11, 12, 16, 12, 13]]
| 0
| 163
|
#include <math.h>
#include <stdio.h>
#define MAX 999999
int Primes[MAX + 1];
int IsPrime(int n) {
if (n < 2) {
return 0;
}
else if (n == 2) {
return 1;
}
else if (n % 2 == 0) {
return 0;
}
else {
int i = 3;
for (; i < sqrt(n); i += 2) {
if (n % i == 0) {
return 0;
}
}
}
return 1;
}
int main(void) {
int i;
for (i = 1; i <= MAX; ++i) {
Primes[i] += IsPrime(i) + Primes[i - 1];
}
int N;
while (scanf("%d", &N) != EOF) {
printf("%d\n", Primes[N]);
}
return 0;
}
|
#include <math.h>
#include <stdio.h>
#define MAX 999999
int Primes[MAX + 1];
int IsPrime(int n) {
if (n < 2) {
return 0;
}
else if (n == 2) {
return 1;
}
else if (n % 2 == 0) {
return 0;
}
else {
int i = 3;
for (; i <= sqrt(n); i += 2) {
if (n % i == 0) {
return 0;
}
}
}
return 1;
}
int main(void) {
int i;
for (i = 1; i <= MAX; ++i) {
Primes[i] += IsPrime(i) + Primes[i - 1];
}
int N;
while (scanf("%d", &N) != EOF) {
printf("%d\n", Primes[N]);
}
return 0;
}
|
[["-", 75, 76, 0, 9, 0, 7, 15, 16, 17, 18], ["+", 75, 76, 0, 9, 0, 7, 15, 16, 17, 19]]
| 0
| 177
|
#include <stdio.h>
unsigned long long int N = 1000000;
int main(void) {
int i, j, n;
int pn[N];
for (i = 3; i < N; i += 2) {
pn[i] = -1;
}
pn[0] = pn[1] = -1;
pn[2] = 1;
for (i = 3; i < N; i += 2) {
if (pn[i] == -1) {
pn[i] = 1;
for (j = i * 2; j < N; j += i) {
pn[j] = 0;
}
}
}
for (i = 3; i < N; ++i) {
pn[i] += pn[i - 1];
}
while (scanf("%d", &n) != EOF) {
printf("%d\n", pn[n]);
}
return (0);
}
|
#include <stdio.h>
unsigned long long int N = 1000000;
int main(void) {
int i, j, n;
int pn[N];
for (i = 3; i < N; i += 2) {
pn[i] = -1;
}
pn[0] = pn[1] = 0;
pn[2] = 1;
for (i = 3; i < N; i += 2) {
if (pn[i] == -1) {
pn[i] = 1;
for (j = i * 2; j < N; j += i) {
pn[j] = 0;
}
}
}
for (i = 3; i < N; ++i) {
pn[i] += pn[i - 1];
}
while (scanf("%d", &n) != EOF) {
printf("%d\n", pn[n]);
}
return (0);
}
|
[["-", 8, 9, 0, 1, 0, 11, 12, 11, 12, 13], ["+", 8, 9, 0, 1, 0, 11, 12, 11, 12, 13]]
| 0
| 192
|
x=[0]*37
for a in range(10):
for b in range(10):
for c in range(10):
for d in range(10):
x[a+b+c+d]+=1
while True:
try:
print(x[int(input())])
except:
break
|
x=[0]*51
for a in range(10):
for b in range(10):
for c in range(10):
for d in range(10):
x[a+b+c+d]+=1
while True:
try:
print(x[int(input())])
except:
break
|
[["-", 0, 656, 0, 1, 0, 662, 12, 657, 12, 612], ["+", 0, 656, 0, 1, 0, 662, 12, 657, 12, 612]]
| 5
| 71
|
# -*- coding: utf-8 -*-
while(True):
try:
n = int(input())
sum = 0
for a in range(10):
for b in range(10):
for c in range(10):
for d in range(10):
if (a + b + c + d == n):
sum += 0
print(sum)
except EOFError:
break
|
# -*- coding: utf-8 -*-
while(True):
try:
n = int(input())
sum = 0
for a in range(10):
for b in range(10):
for c in range(10):
for d in range(10):
if (a + b + c + d == n):
sum += 1
print(sum)
except EOFError:
break
|
[["-", 0, 57, 64, 196, 0, 1, 0, 677, 12, 612], ["+", 0, 57, 64, 196, 0, 1, 0, 677, 12, 612]]
| 5
| 75
|
def get_input():
while True:
try:
yield ''.join(input())
except EOFError:
break
ar = [0] * 50
for i in range(10):
for j in range(10):
for k in range(10):
for l in range(10):
ar[i + j + k + l] += 1
for a in list(get_input()):
print(ar[int(a)])
|
def get_input():
while True:
try:
yield ''.join(input())
except EOFError:
break
ar = [0] * 51
for i in range(10):
for j in range(10):
for k in range(10):
for l in range(10):
ar[i + j + k + l] += 1
for a in list(get_input()):
print(ar[int(a)])
|
[["-", 0, 656, 0, 1, 0, 662, 12, 657, 12, 612], ["+", 0, 656, 0, 1, 0, 662, 12, 657, 12, 612]]
| 5
| 95
|
import sys
s=[0]*51
for a in range(10):
for b in range(10):
for c in range(10):
for d in range(10):
s[a+b+c+d]+=1
for l in sys.stdin:print(x[int(l)])
|
import sys
s=[0]*51
for a in range(10):
for b in range(10):
for c in range(10):
for d in range(10):
s[a+b+c+d]+=1
for l in sys.stdin:print(s[int(l)])
|
[["-", 0, 1, 0, 652, 3, 4, 0, 206, 51, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 206, 51, 22]]
| 5
| 70
|
import itertools
s=list(range(0,10))
chk=list(itertools.product(s,repeat=4))
for j in sys.stdin:
ans=0
for k in chk:
if sum(k)==int(j):
ans+=1
print(ans)
|
import itertools
import sys
s=list(range(0,10))
chk=list(itertools.product(s,repeat=4))
for j in sys.stdin:
ans=0
for k in chk:
if sum(k)==int(j):
ans+=1
print(ans)
|
[["+", 36, 36, 36, 36, 0, 656, 0, 596, 0, 487], ["+", 36, 36, 0, 656, 0, 596, 141, 673, 0, 22]]
| 5
| 61
|
from itertools import product
while True:
try:
n = int(input)
except:
break
count = sum(a + b + c + d == n for a, b, c, d in product(range(10), repeat=4))
print(count)
|
from itertools import product
while True:
try:
n = int(input())
except:
break
count = sum(a + b + c + d == n for a, b, c, d in product(range(10), repeat=4))
print(count)
|
[["+", 12, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["+", 12, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
| 5
| 56
|
import sys
for n in sys.stdin.readline():
ret = 0
for a in range(10):
for b in range(10):
for c in range(10):
for d in range(10):
if a+b+c+d == int(n):
ret += 1
print(ret)
|
import sys
for n in sys.stdin:
ret = 0
for a in range(10):
for b in range(10):
for c in range(10):
for d in range(10):
if a+b+c+d == int(n):
ret += 1
print(ret)
|
[["-", 0, 656, 0, 7, 12, 652, 63, 319, 0, 131], ["-", 0, 656, 0, 7, 12, 652, 63, 319, 319, 22], ["-", 0, 656, 0, 7, 12, 652, 3, 4, 0, 24], ["-", 0, 656, 0, 7, 12, 652, 3, 4, 0, 25]]
| 5
| 69
|
import itertools
def combination(n):
c=0
for i in itertools.product(range(10),repeat=4):
(a,b,c,d)=i
if a+b+c+d==n:
c+=1
return c
while True:
try:
n=int(input())
combination(n)
except EOFError:
break
|
import itertools
def combination(n):
m=0
for i in itertools.product(range(10),repeat=4):
(a,b,c,d)=i
if a+b+c+d==n:
m+=1
return m
while True:
try:
n=int(input())
print(combination(n))
except EOFError:
break
|
[["-", 0, 14, 8, 196, 0, 1, 0, 662, 31, 22], ["+", 0, 14, 8, 196, 0, 1, 0, 662, 31, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 677, 31, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 677, 31, 22], ["-", 0, 656, 0, 14, 8, 196, 0, 37, 0, 22], ["+", 0, 656, 0, 14, 8, 196, 0, 37, 0, 22], ["+", 0, 246, 8, 196, 0, 1, 0, 652, 63, 22], ["+", 8, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
| 5
| 76
|
import sys
for line in sys.stdin:
N = int(input())
ans = 0
for a in range(10):
for b in range(10):
for c in range(10):
for d in range(10):
if a+b+c+d == N:
ans += 1
print(ans)
|
import sys
for line in sys.stdin:
N = int(line)
ans = 0
for a in range(10):
for b in range(10):
for c in range(10):
for d in range(10):
if a+b+c+d == N:
ans += 1
print(ans)
|
[["-", 0, 662, 12, 652, 3, 4, 0, 652, 63, 22], ["-", 12, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["-", 12, 652, 3, 4, 0, 652, 3, 4, 0, 25], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 22]]
| 5
| 70
|
INF=-1
memo=[[INF]*51 for i in range(5)]
def rec(i,n):
if memo[i][n]!=INF:
return memo[i][n]
if i==4:
return 1 if n==0 else 0
for m in range(10):
memo[i][n]+=rec(i+1,n-m)
return memo[i][n]
while True:
try:
n=int(input())
print(rec(0,n))
except:
break
|
memo=[[0]*51 for i in range(5)]
def rec(i,n):
if memo[i][n]!=0:
return memo[i][n]
if i==4:
return 1 if n==0 else 0
for m in range(10):
memo[i][n]+=rec(i+1,n-m)
return memo[i][n]
while True:
try:
n=int(input())
print(rec(0,n))
except:
break
|
[["-", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22], ["-", 36, 36, 0, 656, 0, 1, 0, 662, 0, 32], ["-", 0, 656, 0, 1, 0, 662, 12, 664, 17, 33], ["-", 0, 656, 0, 1, 0, 662, 12, 664, 28, 612], ["-", 0, 662, 12, 658, 8, 657, 31, 634, 0, 22], ["+", 0, 662, 12, 658, 8, 657, 31, 634, 0, 612], ["-", 0, 14, 8, 196, 0, 57, 15, 666, 0, 22], ["+", 0, 14, 8, 196, 0, 57, 15, 666, 0, 612]]
| 5
| 119
|
import sys
values = []
for line in sys.stdin:
values.append(int(line))
ans = [1 for i in range(10) for j in range(10) for k in range(10) for l in range(10) if n == i + j + k + l]
print(ans.count(1))
|
import sys
values = []
for line in sys.stdin:
values.append(int(line))
for v in values:
ans = [1 for i in range(10) for j in range(10) for k in range(10) for l in range(10) if v == i + j + k + l]
print(ans.count(1))
|
[["+", 36, 36, 36, 36, 0, 656, 0, 7, 0, 88], ["+", 36, 36, 36, 36, 0, 656, 0, 7, 31, 22], ["+", 36, 36, 36, 36, 0, 656, 0, 7, 0, 267], ["+", 36, 36, 36, 36, 0, 656, 0, 7, 12, 22], ["+", 36, 36, 36, 36, 0, 656, 0, 7, 0, 102], ["-", 0, 662, 12, 658, 0, 678, 0, 666, 0, 22], ["+", 0, 662, 12, 658, 0, 678, 0, 666, 0, 22]]
| 5
| 74
|
ans=[0]*51
for a in range(10):
for b in range(10):
for c in range(10):
for d in range(10):
ans[sum([a,b,c,d])] += 1
while True:
try:print(sum[int(imput())])
except:break
|
ans=[0]*51
for a in range(10):
for b in range(10):
for c in range(10):
for d in range(10):
ans[sum([a,b,c,d])] += 1
while True:
try:print(ans[int(input())])
except:break
|
[["-", 0, 1, 0, 652, 3, 4, 0, 206, 51, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 206, 51, 22], ["-", 0, 206, 206, 652, 3, 4, 0, 652, 63, 22], ["+", 0, 206, 206, 652, 3, 4, 0, 652, 63, 22]]
| 5
| 76
|
lst=[0 for i in range(50)]
for a in range(10):
for b in range(10):
for c in range(10):
for d in range(10):
lst[a+b+c+d] += 1
while 1:
try:
print(lst[int(input())])
except:
break
|
lst=[0 for i in range(51)]
for a in range(10):
for b in range(10):
for c in range(10):
for d in range(10):
lst[a+b+c+d] += 1
while 1:
try:
print(lst[int(input())])
except:
break
|
[["-", 12, 658, 0, 659, 12, 652, 3, 4, 0, 612], ["+", 12, 658, 0, 659, 12, 652, 3, 4, 0, 612]]
| 5
| 76
|
while True:
try:
n = int(input())
count = 0
for i in range(10):
for j in range(10):
for k in range(10):
for l in range(10):
i+j+k+l == n
count += 1
print(count)
except:
break
|
while True:
try:
n = int(input())
count = 0
for i in range(10):
for j in range(10):
for k in range(10):
for l in range(10):
if i+j+k+l == n:
count += 1
print(count)
except:
break
|
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 102]]
| 5
| 67
|
import sys
for n in sys.stdin: print(len([None for a in range(10) for b in range(10) for c in range(10) for d in range(10) if a+b+c+d == N]))
|
import sys
for n in sys.stdin: print(len([None for a in range(10) for b in range(10) for c in range(10) for d in range(10) if a+b+c+d == int(n)]))
|
[["-", 3, 4, 0, 658, 0, 678, 0, 666, 0, 22], ["+", 0, 658, 0, 678, 0, 666, 0, 652, 63, 22], ["+", 0, 678, 0, 666, 0, 652, 3, 4, 0, 24], ["+", 0, 678, 0, 666, 0, 652, 3, 4, 0, 22], ["+", 0, 678, 0, 666, 0, 652, 3, 4, 0, 25]]
| 5
| 56
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = "";
boolean[] ns = new boolean[1000000];
for (int i = 2; i < 1000000; i++) {
if (ns[i])
continue;
for (int j = 2; j < 999999 / i + 1; j++) {
if (!ns[i * j]) {
ns[i * j] = true;
}
}
}
while ((line = br.readLine()) != null && !line.isEmpty()) {
int n = Integer.parseInt(line);
int m = 0;
for (int i = 1; i < n + 1; i++) {
if (!ns[i]) {
m++;
}
}
System.out.println(m);
}
}
}
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = "";
boolean[] ns = new boolean[1000000];
for (int i = 2; i < 1000000; i++) {
if (ns[i])
continue;
for (int j = 2; j < 999999 / i + 1; j++) {
if (!ns[i * j]) {
ns[i * j] = true;
}
}
}
while ((line = br.readLine()) != null && !line.isEmpty()) {
int n = Integer.parseInt(line);
int m = 0;
for (int i = 2; i < n + 1; i++) {
if (!ns[i]) {
m++;
}
}
System.out.println(m);
}
}
}
|
[["-", 8, 196, 0, 7, 502, 503, 49, 200, 51, 499], ["+", 8, 196, 0, 7, 502, 503, 49, 200, 51, 499]]
| 3
| 216
|
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNextInt()) {
int n = sc.nextInt();
int a = 0;
int b[] = new int[n + 1];
if (n < 2) {
System.out.println("0");
} else {
for (int i = 2; i <= n; i++) {
if (b[i] == 0) {
for (int j = i * 2; j <= n; j = j + i) {
b[j] = 1;
}
}
}
}
for (int i = 2; i <= n; i++) {
if (b[i] == 0)
a++;
}
System.out.println(a);
}
}
}
|
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNextInt()) {
int n = sc.nextInt();
int a = 0;
int b[] = new int[n + 1];
if (n < 2) {
System.out.println("0");
} else {
for (int i = 2; i <= n; i++) {
if (b[i] == 0) {
for (int j = i * 2; j <= n; j = j + i) {
b[j] = 1;
}
}
}
for (int i = 2; i <= n; i++) {
if (b[i] == 0)
a++;
}
System.out.println(a);
}
}
}
}
|
[["-", 0, 52, 8, 196, 0, 57, 75, 196, 0, 46], ["+", 0, 52, 8, 196, 0, 57, 75, 196, 0, 46]]
| 3
| 186
|
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = null;
try {
sc = new Scanner(System.in);
while (sc.hasNextInt()) {
int num = sc.nextInt();
int count = 0;
boolean isPrime = true;
if (num <= 1) {
System.out.println(count);
} else if (num == 2) {
count++;
System.out.println(count);
} else if (num == 3) {
count = 2;
System.out.println(count);
} else {
for (int i = 3; i <= num; i += 2) {
for (int j = 3; j < Math.sqrt(i); j += 2) {
if (i % j == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
count++;
} else {
isPrime = true;
}
}
System.out.println(count);
count = 0;
}
}
} finally {
sc.close();
}
}
}
|
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = null;
try {
sc = new Scanner(System.in);
while (sc.hasNextInt()) {
int num = sc.nextInt();
int count = 0;
boolean isPrime = true;
if (num <= 1) {
System.out.println(count);
} else if (num == 2) {
count++;
System.out.println(count);
} else if (num == 3) {
count = 2;
System.out.println(count);
} else {
count = 1;
for (int i = 3; i <= num; i += 2) {
for (int j = 3; j <= Math.sqrt(i); j += 2) {
if (i % j == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
count++;
} else {
isPrime = true;
}
}
System.out.println(count);
count = 0;
}
}
} finally {
sc.close();
}
}
}
|
[["+", 75, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 57, 75, 196, 0, 1, 0, 11, 17, 32], ["+", 75, 57, 75, 196, 0, 1, 0, 11, 12, 499], ["+", 75, 57, 75, 57, 75, 196, 0, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
| 3
| 226
|
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNextInt()) {
int count = 0;
int n = sc.nextInt();
boolean[] prime = new boolean[n + 1];
for (int i = 2; i <= n; i++) {
prime[i] = true;
}
for (int i = 0; i <= n; i++) {
if (prime[i]) {
count++;
for (int j = i + i; j < n; j += i) {
prime[j] = false;
}
}
}
System.out.println(count);
}
}
}
|
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNextInt()) {
int count = 0;
int n = sc.nextInt();
boolean[] prime = new boolean[n + 1];
for (int i = 2; i <= n; i++) {
prime[i] = true;
}
for (int i = 0; i <= n; i++) {
if (prime[i]) {
count++;
for (int j = i + i; j <= n; j += i) {
prime[j] = false;
}
}
}
System.out.println(count);
}
}
}
|
[["-", 0, 57, 64, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 57, 64, 196, 0, 7, 15, 16, 17, 19]]
| 3
| 157
|
import java.util.HashMap;
import java.util.Scanner;
class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
boolean[] isPrimes = new boolean[1000000];
for (int x = 2; x < 1000000 / 2 + 1; x++) {
if (!isPrimes[x]) {
for (int y = 2; y < 1000000 / x + 1; y++) {
isPrimes[x * y] = true;
}
}
}
int count = 0;
int[] nPrimes = new int[1000000];
for (int i = 2; i < 1000000; i++) {
if (!isPrimes[i]) {
count++;
}
nPrimes[i] = count;
}
while (sc.hasNext()) {
int n = sc.nextInt();
System.out.println(nPrimes[n]);
}
}
}
|
import java.util.HashMap;
import java.util.Scanner;
class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
boolean[] isPrimes = new boolean[1000000];
for (int x = 2; x < 1000000 / 2 + 1; x++) {
if (!isPrimes[x]) {
for (int y = 2; y < 999999 / x + 1; y++) {
isPrimes[x * y] = true;
}
}
}
int count = 0;
int[] nPrimes = new int[1000000];
for (int i = 2; i < 1000000; i++) {
if (!isPrimes[i]) {
count++;
}
nPrimes[i] = count;
}
while (sc.hasNext()) {
int n = sc.nextInt();
System.out.println(nPrimes[n]);
}
}
}
|
[["-", 0, 7, 15, 16, 12, 16, 31, 16, 31, 499], ["+", 0, 7, 15, 16, 12, 16, 31, 16, 31, 499]]
| 3
| 194
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String input;
int primes = 0;
int[] n = new int[1000000];
for (int i = 2; i < n.length; ++i) {
if (isPrime(i))
++primes;
n[i] = primes;
}
while ((input = bf.readLine()) != null) {
try {
int num = Integer.parseUnsignedInt(input);
System.out.print(n[num]);
} catch (NumberFormatException nfe) {
break;
}
}
}
private static boolean isPrime(int i) {
for (int div = 2; div <= Math.sqrt(i); div += 1) {
if (i % div == 0)
return false;
}
return true;
}
}
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String input;
int primes = 0;
int[] n = new int[1000000];
for (int i = 2; i < n.length; ++i) {
if (isPrime(i))
++primes;
n[i] = primes;
}
while ((input = bf.readLine()) != null) {
try {
int num = Integer.parseUnsignedInt(input);
System.out.print(n[num] + "\n");
} catch (NumberFormatException nfe) {
break;
}
}
}
private static boolean isPrime(int i) {
for (int div = 2; div <= Math.sqrt(i); div += 1) {
if (i % div == 0)
return false;
}
return true;
}
}
|
[["+", 0, 1, 0, 492, 3, 4, 0, 16, 17, 72], ["+", 0, 492, 3, 4, 0, 16, 12, 5, 0, 62], ["+", 0, 492, 3, 4, 0, 16, 12, 5, 0, 44]]
| 3
| 204
|
import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (true) {
try {
int n = Integer.parseInt(br.readLine());
int count = 0;
boolean[] map = new boolean[n];
Arrays.fill(map, true);
map[0] = false;
for (int i = 2; i * i < n; i++) {
if (map[i - 1]) {
for (int j = 2; j * i <= n; j++) {
map[i * j - 1] = false;
}
}
}
for (int i = 0; i < map.length; i++) {
if (map[i])
count++;
}
System.out.println(count);
} catch (Exception e) {
System.exit(0);
}
}
}
}
|
import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (true) {
try {
int n = Integer.parseInt(br.readLine());
int count = 0;
boolean[] map = new boolean[n];
Arrays.fill(map, true);
map[0] = false;
for (int i = 2; i * i <= n; i++) {
if (map[i - 1]) {
for (int j = 2; j * i <= n; j++) {
map[i * j - 1] = false;
}
}
}
for (int i = 0; i < map.length; i++) {
if (map[i])
count++;
}
System.out.println(count);
} catch (Exception e) {
System.exit(0);
}
}
}
}
|
[["-", 0, 246, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 246, 8, 196, 0, 7, 15, 16, 17, 19]]
| 3
| 211
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) { new Main(); }
public Main() {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String x = "";
try {
while ((x = in.readLine()) != null) {
int nico = Integer.parseInt(x);
boolean[] flag = new boolean[nico + 1];
for (int i = 0; i < (nico + 1); i++) {
flag[i] = true;
}
for (int i = 2; i * i < nico; i++) {
for (int j = i * 2; j < nico; j = j + i) {
if (flag[j] == false)
continue;
flag[j] = false;
}
}
int count = 0;
for (int i = 0; i < (nico + 1); i++) {
if (flag[i])
count++;
}
System.out.println(count);
}
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) { new Main(); }
public Main() {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String x = "";
try {
while ((x = in.readLine()) != null) {
int nico = Integer.parseInt(x);
boolean[] flag = new boolean[nico + 1];
for (int i = 0; i < (nico + 1); i++) {
flag[i] = true;
}
for (int i = 2; i * i <= nico; i++) {
for (int j = i * 2; j <= nico; j = j + i) {
if (flag[j] == false)
continue;
flag[j] = false;
}
}
int count = 0;
for (int i = 2; i < (nico + 1); i++) {
if (flag[i])
count++;
}
System.out.println(count);
}
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
|
[["-", 0, 52, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 8, 196, 0, 7, 502, 503, 49, 200, 51, 499], ["+", 8, 196, 0, 7, 502, 503, 49, 200, 51, 499]]
| 3
| 268
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
@SuppressWarnings("unchecked")
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int[] num = new int[1000000];
boolean[] nums = new boolean[1000000];
for (int i = 0; i < nums.length; i++) {
nums[i] = true;
}
nums[0] = false;
nums[1] = false;
int p = 0;
for (int i = 2; i < 1000000; i++) {
num[p++] = i;
if (nums[i]) {
for (int k = i * 2; k < 1000000; k += i) {
nums[k] = false;
}
}
}
String s = "";
while ((s = br.readLine()) != null) {
int n = Integer.parseInt(s);
int count = 0;
for (int k = 0; k < n; k++) {
if (nums[k]) {
count++;
}
}
System.out.println(count);
}
}
}
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
@SuppressWarnings("unchecked")
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int[] num = new int[1000000];
boolean[] nums = new boolean[1000000];
for (int i = 0; i < nums.length; i++) {
nums[i] = true;
}
nums[0] = false;
nums[1] = false;
int p = 0;
for (int i = 2; i < 1000000; i++) {
num[p++] = i;
if (nums[i]) {
for (int k = i * 2; k < 1000000; k += i) {
nums[k] = false;
}
}
}
String s = "";
while ((s = br.readLine()) != null) {
int n = Integer.parseInt(s);
int count = 0;
for (int k = 2; k <= n; k++) {
if (nums[k]) {
count++;
}
}
System.out.println(count);
}
}
}
|
[["-", 8, 196, 0, 7, 502, 503, 49, 200, 51, 499], ["+", 8, 196, 0, 7, 502, 503, 49, 200, 51, 499], ["-", 0, 52, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 196, 0, 7, 15, 16, 17, 19]]
| 3
| 261
|
import java.util.Scanner;
public class Main {
static Scanner sc = new java.util.Scanner(System.in);
public static void main(String[] args) {
while (sc.hasNext()) {
int n = sc.nextInt();
int x = 0;
for (int i = 3; i <= n; i = i + 2) {
for (int j = 3; j < Math.sqrt(i); j = j + 2) {
int y = i % j;
if (y == 0) {
x = x + 1;
break;
}
}
}
if (n == 1) {
System.out.println(0);
} else {
if (n % 2 == 0) {
n = n / 2;
} else {
n = (n + 1) / 2;
}
System.out.println(n - x);
}
}
}
}
|
import java.util.Scanner;
public class Main {
static Scanner sc = new java.util.Scanner(System.in);
public static void main(String[] args) {
while (sc.hasNext()) {
int n = sc.nextInt();
int x = 0;
for (int i = 3; i <= n; i = i + 2) {
for (int j = 3; j <= Math.sqrt(i); j = j + 2) {
int y = i % j;
if (y == 0) {
x = x + 1;
break;
}
}
}
if (n == 1) {
System.out.println(0);
} else {
if (n % 2 == 0) {
n = n / 2;
} else {
n = (n + 1) / 2;
}
System.out.println(n - x);
}
}
}
}
|
[["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
| 3
| 190
|
#include <complex>
#include <stdio.h>
using namespace std;
typedef complex<double> point;
#define X real()
#define Y imag()
typedef point vec;
double cross(vec a, vec b) { return a.X * b.Y - b.X * a.Y; }
double dis(point a, point b) { return abs(a - b); }
point center(point A, point B, point C) // Circumcenter
{
B -= A;
C -= A;
double b = norm(B), c = norm(C), d = 2 * cross(B, C);
return point(C.Y * b - B.Y * c, B.X * c - C.X * b) / d;
}
int main() {
int dat;
scanf("%d", &dat);
while (dat--) {
point p[3], c;
for (int i = 0; i < 3; ++i) {
double x, y;
scanf("%lf%lf", &x, &y);
p[i] = point(x, y);
}
c = center(p[0], p[1], p[2]);
printf("%.3lf %.3lf %.3lf\n", c.X, c.Y, dis(c, p[0]));
}
}
|
#include <complex>
#include <stdio.h>
using namespace std;
typedef complex<double> point;
#define X real()
#define Y imag()
typedef point vec;
double cross(vec a, vec b) { return a.X * b.Y - b.X * a.Y; }
double dis(point a, point b) { return abs(a - b); }
point center(point A, point B, point C) // Circumcenter
{
B -= A;
C -= A;
double b = norm(B), c = norm(C), d = 2 * cross(B, C);
return A + point(C.Y * b - B.Y * c, B.X * c - C.X * b) / d;
}
int main() {
int dat;
scanf("%d", &dat);
while (dat--) {
point p[3], c;
for (int i = 0; i < 3; ++i) {
double x, y;
scanf("%lf%lf", &x, &y);
p[i] = point(x, y);
}
c = center(p[0], p[1], p[2]);
printf("%.3lf %.3lf %.3lf\n", c.X, c.Y, dis(c, p[0]));
}
}
|
[["+", 0, 14, 8, 9, 0, 37, 0, 16, 31, 22], ["+", 0, 14, 8, 9, 0, 37, 0, 16, 17, 72]]
| 1
| 277
|
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
double fpx(double a, double b, double c, double d, double e, double f);
double fpy(double a, double b, double c, double d, double e, double f);
double fr(double a, double b, double c, double d);
string toStr(double a);
string intToString(int a);
int main() {
int n;
double x1, y1, x2, y2, x3, y3;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
double px = fpx(x1, y1, x2, y2, x3, y3);
double py = fpy(x1, y1, x2, y2, x3, y3);
double r = fr(x1, y1, px, py);
cout << toStr(px) << " " << toStr(py) << " " << toStr(r) << endl;
}
}
double fpx(double x1, double y1, double x2, double y2, double x3, double y3) {
double a1, a2, b1, b2, c1, c2;
a1 = 2 * (x2 - x1);
b1 = 2 * (y2 - y1);
c1 = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2;
a2 = 2 * (x3 - x1);
b2 = 2 * (y3 - y1);
c2 = x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3;
return (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1);
}
double fpy(double x1, double y1, double x2, double y2, double x3, double y3) {
double a1, a2, b1, b2, c1, c2;
a1 = 2 * (x2 - x1);
b1 = 2 * (y2 - y1);
c1 = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2;
a2 = 2 * (x3 - x1);
b2 = 2 * (y3 - y1);
c2 = x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3;
return (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1);
}
double fr(double x1, double y1, double x2, double y2) {
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
string toStr(double d) {
string pm = "", val = "";
if (d < 0) {
pm = "-";
d = -d;
}
int ipart = (int)d;
int fpart = (int)((d - (double)ipart) * 10000) + 10000;
val = pm + intToString(ipart) + "." + intToString(fpart).substr(1, 3);
return val;
}
string intToString(int n) {
stringstream ss;
ss << n;
return ss.str();
}
|
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
double fpx(double a, double b, double c, double d, double e, double f);
double fpy(double a, double b, double c, double d, double e, double f);
double fr(double a, double b, double c, double d);
string toStr(double a);
string intToString(int a);
int main() {
int n;
double x1, y1, x2, y2, x3, y3;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
double px = fpx(x1, y1, x2, y2, x3, y3);
double py = fpy(x1, y1, x2, y2, x3, y3);
double r = fr(x1, y1, px, py);
cout << toStr(px) << " " << toStr(py) << " " << toStr(r) << endl;
}
}
double fpx(double x1, double y1, double x2, double y2, double x3, double y3) {
double a1, a2, b1, b2, c1, c2;
a1 = 2 * (x2 - x1);
b1 = 2 * (y2 - y1);
c1 = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2;
a2 = 2 * (x3 - x1);
b2 = 2 * (y3 - y1);
c2 = x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3;
return (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1);
}
double fpy(double x1, double y1, double x2, double y2, double x3, double y3) {
double a1, a2, b1, b2, c1, c2;
a1 = 2 * (x2 - x1);
b1 = 2 * (y2 - y1);
c1 = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2;
a2 = 2 * (x3 - x1);
b2 = 2 * (y3 - y1);
c2 = x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3;
return (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1);
}
double fr(double x1, double y1, double x2, double y2) {
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
string toStr(double d) {
string pm = "", val = "";
if (d < 0) {
pm = "-";
d = -d;
}
int ipart = (int)d;
int fpart = (int)((d - (double)ipart) * 10000) + 10005;
val = pm + intToString(ipart) + "." + intToString(fpart).substr(1, 3);
return val;
}
string intToString(int n) {
stringstream ss;
ss << n;
return ss.str();
}
|
[["-", 8, 9, 0, 43, 49, 50, 51, 16, 12, 13], ["+", 8, 9, 0, 43, 49, 50, 51, 16, 12, 13]]
| 1
| 647
|
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int main(void) {
int n;
cin >> n;
double x1, x2, x3, y1, y2, y3;
for (int i = 0; i < n; i++) {
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
double a = x2 * x2 - x1 * x1 + y2 * y2 - y1 * y1;
double b = x3 * x3 - x1 * x1 + y3 * y3 - y1 * y1;
double c = 4 * (x2 - x1) * (y3 - y1) - 4 * (x3 - x1) * (y2 - y1);
double x = (2 * (y3 - y1) * a - 2 * (y2 - y1) * b) / c;
double y = (2 * (x3 - x1) * a - 2 * (x2 - x1) * b) / c;
double r = sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));
printf("%.3lf %.3lf %.3lf\n", x, y, r);
}
return 0;
}
|
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int main(void) {
int n;
cin >> n;
double x1, x2, x3, y1, y2, y3;
for (int i = 0; i < n; i++) {
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
double a = x2 * x2 - x1 * x1 + y2 * y2 - y1 * y1;
double b = x3 * x3 - x1 * x1 + y3 * y3 - y1 * y1;
double c = 4 * (x2 - x1) * (y3 - y1) - 4 * (x3 - x1) * (y2 - y1);
double x = (2 * (y3 - y1) * a - 2 * (y2 - y1) * b) / c;
double y = (-2 * (x3 - x1) * a + 2 * (x2 - x1) * b) / c;
double r = sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));
printf("%.3lf %.3lf %.3lf\n", x, y, r);
}
return 0;
}
|
[["-", 31, 23, 0, 16, 31, 16, 31, 16, 31, 13], ["+", 31, 23, 0, 16, 31, 16, 31, 16, 31, 13], ["-", 49, 50, 51, 16, 31, 23, 0, 16, 17, 33], ["+", 49, 50, 51, 16, 31, 23, 0, 16, 17, 72]]
| 1
| 237
|
#include <cmath>
#include <cstdio>
using namespace std;
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
double x[3], y[3], s[3];
double l, m, n;
for (int j = 0; j < 3; j++) {
scanf("%lf %lf", &x[j], &y[j]);
s[j] = x[j] * x[j] + y[j] * y[j];
}
double x2[2], y2[2], s2[2];
x2[0] = x[0] - x[1];
y2[0] = y[0] - y[1];
s2[0] = s[0] - s[1];
x2[1] = x[0] - x[2];
y2[1] = y[0] - y[2];
s2[1] = s[0] - s[2];
m = -(s2[0] * x2[1] - s2[1] * x2[0]) / (y2[0] * x2[1] - y2[1] * x2[0]);
l = -(s2[0] * y2[1] - s2[1] * y2[0]) / (x2[0] * y2[1] - x2[1] * y2[0]);
n = -s[0] - x[0] * 1 - y[0] * m;
double a, b, r;
a = l / -2;
b = m / -2;
r = sqrt(-n - a * a - b * b - l * a - m * b);
printf("%.3lf %.3lf %.3lf\n", a, b, r);
}
return (0);
}
|
#include <cmath>
#include <cstdio>
using namespace std;
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
double x[3], y[3], s[3];
double l, m, n;
for (int j = 0; j < 3; j++) {
scanf("%lf %lf", &x[j], &y[j]);
s[j] = x[j] * x[j] + y[j] * y[j];
}
double x2[2], y2[2], s2[2];
x2[0] = x[0] - x[1];
y2[0] = y[0] - y[1];
s2[0] = s[0] - s[1];
x2[1] = x[0] - x[2];
y2[1] = y[0] - y[2];
s2[1] = s[0] - s[2];
m = -(s2[0] * x2[1] - s2[1] * x2[0]) / (y2[0] * x2[1] - y2[1] * x2[0]);
l = -(s2[0] * y2[1] - s2[1] * y2[0]) / (x2[0] * y2[1] - x2[1] * y2[0]);
n = -s[0] - x[0] * l - y[0] * m;
double a, b, r;
a = l / -2;
b = m / -2;
r = sqrt(-n - a * a - b * b - l * a - m * b);
printf("%.3lf %.3lf %.3lf\n", a, b, r);
}
return (0);
}
|
[["-", 0, 11, 12, 16, 31, 16, 12, 16, 12, 13], ["+", 0, 11, 12, 16, 31, 16, 12, 16, 12, 22]]
| 1
| 410
|
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <string>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define FOR(i, b, e) for (int i = b; i < e; i++)
#define to_bit(i) static_cast<bitset<8>>(i)
#define INF (1 << 28)
#define int(n) \
int n; \
cin >> n;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef queue<int> QI;
typedef priority_queue<int> maxpq;
typedef priority_queue<int, vector<int>, greater<int>> minpq;
struct edge {
int to, cost;
};
void begin() {
cin.tie(0);
ios::sync_with_stdio(false);
};
int gcd(int a, int b) {
if (a % b == 0) {
return (b);
} else {
return (gcd(b, a % b));
}
};
int lcm(int m, int n) {
if ((0 == m) || (0 == n)) {
return 0;
}
return ((m / gcd(m, n)) * n);
};
unsigned long long comb(long n, long m) {
unsigned long long c = 1;
m = (n - m < m ? n - m : m);
for (long ns = n - m + 1, ms = 1; ms <= m; ns++, ms++) {
c *= ns;
c /= ms;
}
return c;
};
void cp(int a1[], int a2[], int l) { REP(i, l) a2[i] = a1[i]; };
void cp(string a1[], string a2[], int l) { REP(i, l) a2[i] = a1[i]; };
double sq(double d) { return d * d; };
int sq(int i) { return i * i; };
double sqdist(int x1, int y1, int x2, int y2) {
double dx = x1 - x2, dy = y1 - y2;
return dx * dx + dy * dy;
};
bool inside(int y, int x, int h, int w) {
return 0 <= y && y <= (h - 1) && 0 <= x && x <= (w - 1);
};
// 線分の交差判定
bool isCross(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
// 並行な場合
int m = (x2 - x1) * (y4 - y3) - (y2 - y1) * (x4 - x3);
if (m == 0)
return false;
// 媒介変数の値が0より大きく1以下なら交差する、これは問題の状況によって変わるかも。
double r = (double)((y4 - y3) * (x3 - x1) - (x4 - x3) * (y3 - y1)) / m;
double s = (double)((y2 - y1) * (x3 - x1) - (x2 - x1) * (y3 - y1)) / m;
return (0 < r && r <= 1 && 0 < s && s <= 1);
};
// 外積の計算 AB CD の内積を求める
int crossProdct(int ax, int ay, int bx, int by, int cx, int cy, int dx,
int dy) {
int abx = bx - ax;
int aby = by - ay;
int cdx = dx - cx;
int cdy = dy - cy;
return abx * cdy - cdx * aby;
};
double crossProdct(double ax, double ay, double bx, double by, double cx,
double cy, double dx, double dy) {
double abx = bx - ax;
double aby = by - ay;
double cdx = dx - cx;
double cdy = dy - cy;
return abx * cdy - cdx * aby;
};
double innerProduct(double ax, double ay, double bx, double by, double cx,
double cy, double dx, double dy) {
double abx = bx - ax;
double aby = by - ay;
double cdx = dx - cx;
double cdy = dy - cy;
return abx * cdx + aby * cdy;
};
// 三角形の内部判定 ABCの中にPがあるか判定
bool inTriangle(int ax, int ay, int bx, int by, int cx, int cy, int px,
int py) {
int c1 = crossProdct(ax, ay, bx, by, bx, by, px, py);
int c2 = crossProdct(bx, by, cx, cy, cx, cy, px, py);
int c3 = crossProdct(cx, cy, ax, ay, ax, ay, px, py);
return (c1 > 0 && c2 > 0 && c3 > 0) || (c1 < 0 && c2 < 0 && c3 < 0);
};
bool inTriangle(double ax, double ay, double bx, double by, double cx,
double cy, double px, double py) {
double c1 = crossProdct(ax, ay, bx, by, bx, by, px, py);
double c2 = crossProdct(bx, by, cx, cy, cx, cy, px, py);
double c3 = crossProdct(cx, cy, ax, ay, ax, ay, px, py);
return (c1 > 0 && c2 > 0 && c3 > 0) || (c1 < 0 && c2 < 0 && c3 < 0);
};
// 三角形の外心
void circumcenter(double ax, double ay, double bx, double by, double cx,
double cy, double res[3]) {
// AB AC を求める
double abx = bx - ax;
double aby = by - ay;
double acx = cx - ax;
double acy = cy - ay;
double m =
abx * acy - acx * aby; // 分母 m = 0 となるのは3点が一直線になるとき
double s = (abx * acx + aby * acy - sq(acx) - sq(acy)) / m; // 媒介変数s
res[0] = abx / 2 + s * aby / 2;
res[1] = aby / 2 - s * abx / 2;
// cout << res[0] << " " << res[1] << endl;
res[2] = sqrt(sqdist(0, 0, res[0], res[1]));
res[0] += ax;
res[1] += ay;
};
void circum(double x1, double y1, double x2, double y2, double x3, double y3,
double res[3]) {
double xp1 = (y1 - y3) * (y1 * y1 - y2 * y2 + x1 * x1 - x2 * x2) -
(y1 - y2) * (y1 * y1 - y3 * y3 + x1 * x1 - x3 * x3);
double xp2 = 2 * (y1 - y3) * (x1 - x2) - 2 * (y1 - y2) * (x1 - x3);
res[0] = xp1 / xp2;
double yp1 = (x1 - x3) * (x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2) -
(x1 - x2) * (x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3);
double yp2 = 2 * (x1 - x3) * (y1 - y2) - 2 * (x1 - x2) * (y1 - y3);
res[1] = yp1 / yp2;
double r = (x3 - res[0]) * (x3 - res[0]) + (y3 - res[1]) * (y3 - res[1]);
res[3] = sqrt(r);
}
class BinaryIndexedTree {
public:
int n;
vector<int> bit;
BinaryIndexedTree(int _n) {
n = _n;
bit.resize(n + 1, 0);
}
int sum(int i) {
int sum = 0;
while (i > 0) {
sum += bit[i];
i -= i & -i;
}
return sum;
}
void add(int i, int v) {
while (i <= n) {
bit[i] += v;
i += i & -i;
}
}
};
class UnionFindTree {
public:
vector<int> parent, rank;
int n;
std::set<int> set;
// 初期化
UnionFindTree(int _n) {
n = _n;
for (int i = 0; i < n; i++) {
parent.resize(n);
rank.resize(n);
parent[i] = i;
rank[i] = 0;
}
}
// 根を求める
int find(int x) {
if (parent[x] == x) {
return x;
} else {
return parent[x] = find(parent[x]);
}
}
// xとyの集合を結合
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y) {
set.insert(x);
return;
}
if (rank[x] < rank[y]) {
parent[x] = y;
set.erase(x);
set.insert(y);
} else {
parent[y] = x;
set.erase(y);
set.insert(x);
if (rank[x] == rank[y])
rank[x]++;
}
}
// xとyが同じ集合か
bool same(int x, int y) { return find(x) == find(y); }
// 集合の数を数える
int count() { return (int)set.size(); }
};
// ワーシャルフロイド法
void warshallFloyd(int graph[100][100], int graph_size) {
for (int mid_node = 0; mid_node < graph_size; mid_node++)
for (int s_node = 0; s_node < graph_size; s_node++)
for (int g_node = 0; g_node < graph_size; g_node++)
if (s_node == g_node)
graph[s_node][g_node] = 0;
else
graph[s_node][g_node] =
min(graph[s_node][g_node],
graph[s_node][mid_node] + graph[mid_node][g_node]);
};
// d:隣接行列 n:グラフのサイズ s:始点 dist:始点からの距離が入る配列
void dijkstra(int graph[1000][1000], int node_count, int start_node,
int distances[1000]) {
REP(i, node_count) distances[i] = -1;
distances[start_node] = 0;
priority_queue<PII, vector<PII>, greater<PII>> dijkstra_pq;
dijkstra_pq.push(PII(0, start_node));
while (!dijkstra_pq.empty()) {
PII p = dijkstra_pq.top();
dijkstra_pq.pop();
int i = p.second;
if (distances[i] < p.first)
continue;
for (int j = 0; j < node_count; j++) {
if (graph[i][j] == -1)
continue;
if (distances[j] == -1) {
distances[j] = distances[i] + graph[i][j];
dijkstra_pq.push(PII(distances[j], j));
} else if (distances[j] > distances[i] + graph[i][j]) {
distances[j] = distances[i] + graph[i][j];
dijkstra_pq.push(PII(distances[j], j));
}
}
}
};
// return とかの位置によってうまい具合にする
int vi[4] = {-1, 1, 0, 0}, vj[4] = {0, 0, -1, 1};
void dfs2d(int i, int j, int r, int c){// 終了条件とかをここに書く
REP(k, 4){int ni = i + vi[k];
int nj = j + vj[k];
if (inside(ni, nj, r, c)) {
dfs2d(ni, nj, r, c);
}
}
}
;
/**
* start
* @author yoshikyoto
*/
int main(int argc, const char *argv[]) {
begin();
int(n);
REP(i, n) {
double x1, y1, x2, y2, x3, y3;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
double ans[3];
circum(x1, y1, x2, y2, x3, y3, ans);
// cout << ans[0] << " " << ans[1] << " " << ans[2] << endl;
printf("%.3f %.3f %.3f\n", ans[0], ans[1], ans[2]);
}
}
|
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <string>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define FOR(i, b, e) for (int i = b; i < e; i++)
#define to_bit(i) static_cast<bitset<8>>(i)
#define INF (1 << 28)
#define int(n) \
int n; \
cin >> n;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef queue<int> QI;
typedef priority_queue<int> maxpq;
typedef priority_queue<int, vector<int>, greater<int>> minpq;
struct edge {
int to, cost;
};
void begin() {
cin.tie(0);
ios::sync_with_stdio(false);
};
int gcd(int a, int b) {
if (a % b == 0) {
return (b);
} else {
return (gcd(b, a % b));
}
};
int lcm(int m, int n) {
if ((0 == m) || (0 == n)) {
return 0;
}
return ((m / gcd(m, n)) * n);
};
unsigned long long comb(long n, long m) {
unsigned long long c = 1;
m = (n - m < m ? n - m : m);
for (long ns = n - m + 1, ms = 1; ms <= m; ns++, ms++) {
c *= ns;
c /= ms;
}
return c;
};
void cp(int a1[], int a2[], int l) { REP(i, l) a2[i] = a1[i]; };
void cp(string a1[], string a2[], int l) { REP(i, l) a2[i] = a1[i]; };
double sq(double d) { return d * d; };
int sq(int i) { return i * i; };
double sqdist(int x1, int y1, int x2, int y2) {
double dx = x1 - x2, dy = y1 - y2;
return dx * dx + dy * dy;
};
bool inside(int y, int x, int h, int w) {
return 0 <= y && y <= (h - 1) && 0 <= x && x <= (w - 1);
};
// 線分の交差判定
bool isCross(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
// 並行な場合
int m = (x2 - x1) * (y4 - y3) - (y2 - y1) * (x4 - x3);
if (m == 0)
return false;
// 媒介変数の値が0より大きく1以下なら交差する、これは問題の状況によって変わるかも。
double r = (double)((y4 - y3) * (x3 - x1) - (x4 - x3) * (y3 - y1)) / m;
double s = (double)((y2 - y1) * (x3 - x1) - (x2 - x1) * (y3 - y1)) / m;
return (0 < r && r <= 1 && 0 < s && s <= 1);
};
// 外積の計算 AB CD の内積を求める
int crossProdct(int ax, int ay, int bx, int by, int cx, int cy, int dx,
int dy) {
int abx = bx - ax;
int aby = by - ay;
int cdx = dx - cx;
int cdy = dy - cy;
return abx * cdy - cdx * aby;
};
double crossProdct(double ax, double ay, double bx, double by, double cx,
double cy, double dx, double dy) {
double abx = bx - ax;
double aby = by - ay;
double cdx = dx - cx;
double cdy = dy - cy;
return abx * cdy - cdx * aby;
};
double innerProduct(double ax, double ay, double bx, double by, double cx,
double cy, double dx, double dy) {
double abx = bx - ax;
double aby = by - ay;
double cdx = dx - cx;
double cdy = dy - cy;
return abx * cdx + aby * cdy;
};
// 三角形の内部判定 ABCの中にPがあるか判定
bool inTriangle(int ax, int ay, int bx, int by, int cx, int cy, int px,
int py) {
int c1 = crossProdct(ax, ay, bx, by, bx, by, px, py);
int c2 = crossProdct(bx, by, cx, cy, cx, cy, px, py);
int c3 = crossProdct(cx, cy, ax, ay, ax, ay, px, py);
return (c1 > 0 && c2 > 0 && c3 > 0) || (c1 < 0 && c2 < 0 && c3 < 0);
};
bool inTriangle(double ax, double ay, double bx, double by, double cx,
double cy, double px, double py) {
double c1 = crossProdct(ax, ay, bx, by, bx, by, px, py);
double c2 = crossProdct(bx, by, cx, cy, cx, cy, px, py);
double c3 = crossProdct(cx, cy, ax, ay, ax, ay, px, py);
return (c1 > 0 && c2 > 0 && c3 > 0) || (c1 < 0 && c2 < 0 && c3 < 0);
};
// 三角形の外心
void circumcenter(double ax, double ay, double bx, double by, double cx,
double cy, double res[3]) {
// AB AC を求める
double abx = bx - ax;
double aby = by - ay;
double acx = cx - ax;
double acy = cy - ay;
double m =
abx * acy - acx * aby; // 分母 m = 0 となるのは3点が一直線になるとき
double s = (abx * acx + aby * acy - sq(acx) - sq(acy)) / m; // 媒介変数s
res[0] = abx / 2 + s * aby / 2;
res[1] = aby / 2 - s * abx / 2;
// cout << res[0] << " " << res[1] << endl;
res[2] = sqrt(sqdist(0, 0, res[0], res[1]));
res[0] += ax;
res[1] += ay;
};
void circum(double x1, double y1, double x2, double y2, double x3, double y3,
double res[3]) {
double xp1 = (y1 - y3) * (y1 * y1 - y2 * y2 + x1 * x1 - x2 * x2) -
(y1 - y2) * (y1 * y1 - y3 * y3 + x1 * x1 - x3 * x3);
double xp2 = 2 * (y1 - y3) * (x1 - x2) - 2 * (y1 - y2) * (x1 - x3);
res[0] = xp1 / xp2;
double yp1 = (x1 - x3) * (x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2) -
(x1 - x2) * (x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3);
double yp2 = 2 * (x1 - x3) * (y1 - y2) - 2 * (x1 - x2) * (y1 - y3);
res[1] = yp1 / yp2;
double r = (x3 - res[0]) * (x3 - res[0]) + (y3 - res[1]) * (y3 - res[1]);
res[2] = sqrt(r);
}
class BinaryIndexedTree {
public:
int n;
vector<int> bit;
BinaryIndexedTree(int _n) {
n = _n;
bit.resize(n + 1, 0);
}
int sum(int i) {
int sum = 0;
while (i > 0) {
sum += bit[i];
i -= i & -i;
}
return sum;
}
void add(int i, int v) {
while (i <= n) {
bit[i] += v;
i += i & -i;
}
}
};
class UnionFindTree {
public:
vector<int> parent, rank;
int n;
std::set<int> set;
// 初期化
UnionFindTree(int _n) {
n = _n;
for (int i = 0; i < n; i++) {
parent.resize(n);
rank.resize(n);
parent[i] = i;
rank[i] = 0;
}
}
// 根を求める
int find(int x) {
if (parent[x] == x) {
return x;
} else {
return parent[x] = find(parent[x]);
}
}
// xとyの集合を結合
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y) {
set.insert(x);
return;
}
if (rank[x] < rank[y]) {
parent[x] = y;
set.erase(x);
set.insert(y);
} else {
parent[y] = x;
set.erase(y);
set.insert(x);
if (rank[x] == rank[y])
rank[x]++;
}
}
// xとyが同じ集合か
bool same(int x, int y) { return find(x) == find(y); }
// 集合の数を数える
int count() { return (int)set.size(); }
};
// ワーシャルフロイド法
void warshallFloyd(int graph[100][100], int graph_size) {
for (int mid_node = 0; mid_node < graph_size; mid_node++)
for (int s_node = 0; s_node < graph_size; s_node++)
for (int g_node = 0; g_node < graph_size; g_node++)
if (s_node == g_node)
graph[s_node][g_node] = 0;
else
graph[s_node][g_node] =
min(graph[s_node][g_node],
graph[s_node][mid_node] + graph[mid_node][g_node]);
};
// d:隣接行列 n:グラフのサイズ s:始点 dist:始点からの距離が入る配列
void dijkstra(int graph[1000][1000], int node_count, int start_node,
int distances[1000]) {
REP(i, node_count) distances[i] = -1;
distances[start_node] = 0;
priority_queue<PII, vector<PII>, greater<PII>> dijkstra_pq;
dijkstra_pq.push(PII(0, start_node));
while (!dijkstra_pq.empty()) {
PII p = dijkstra_pq.top();
dijkstra_pq.pop();
int i = p.second;
if (distances[i] < p.first)
continue;
for (int j = 0; j < node_count; j++) {
if (graph[i][j] == -1)
continue;
if (distances[j] == -1) {
distances[j] = distances[i] + graph[i][j];
dijkstra_pq.push(PII(distances[j], j));
} else if (distances[j] > distances[i] + graph[i][j]) {
distances[j] = distances[i] + graph[i][j];
dijkstra_pq.push(PII(distances[j], j));
}
}
}
};
// return とかの位置によってうまい具合にする
int vi[4] = {-1, 1, 0, 0}, vj[4] = {0, 0, -1, 1};
void dfs2d(int i, int j, int r, int c){// 終了条件とかをここに書く
REP(k, 4){int ni = i + vi[k];
int nj = j + vj[k];
if (inside(ni, nj, r, c)) {
dfs2d(ni, nj, r, c);
}
}
}
;
/**
* start
* @author yoshikyoto
*/
int main(int argc, const char *argv[]) {
begin();
int(n);
REP(i, n) {
double x1, y1, x2, y2, x3, y3;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
double ans[3];
circum(x1, y1, x2, y2, x3, y3, ans);
// cout << ans[0] << " " << ans[1] << " " << ans[2] << endl;
printf("%.3f %.3f %.3f\n", ans[0], ans[1], ans[2]);
}
}
|
[["-", 0, 1, 0, 11, 31, 69, 341, 342, 0, 13], ["+", 0, 1, 0, 11, 31, 69, 341, 342, 0, 13]]
| 1
| 2,529
|
/*include*/
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define rp(a) while (a--)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
const double PI = acos(-1);
const double EPS = 1e-10;
const double inf = 1e8;
using namespace std;
#define shosu(x) fixed << setprecision(x)
typedef complex<double> P;
typedef vector<P> G;
typedef vector<int> vi;
typedef vector<vi> vvi;
struct L : public vector<P> {
L(const P &a, const P &b) {
push_back(a);
push_back(b);
}
};
struct C {
P c;
double r;
C(const P &c, double r) : c(c), r(r) {}
};
#define curr(P, i) P[i]
#define next(P, i) P[(i + 1) % P.size()]
#define diff(P, i) (next(P, i) - curr(P, i))
namespace std {
bool operator<(const P &a, const P &b) {
return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
// return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b);
}
bool operator==(const P &a, const P &b) {
return a.real() == b.real() && a.imag() == b.imag();
}
} // namespace std
P pin() {
double x, y;
char d;
cin >> x >> y;
P p(x, y);
return p;
}
void PIN(P *a, int n) { rep(i, n) a[i] = pin(); }
double dot(P a, P b) { return real(conj(a) * b); }
double cross(P a, P b) { return imag(conj(a) * b); }
int ccw(P a, P b, P c) {
b -= a;
c -= a;
if (cross(b, c) > 0)
return +1; // counter clockwise
if (cross(b, c) < 0)
return -1; // clockwise
if (dot(b, c) < 0)
return +2; // c--a--b on line
if (norm(b) < norm(c))
return -2; // a--b--c on line
return 0;
}
P projection(L a, P p) {
double t = dot(p - a[0], a[0] - a[1]) / norm(a[0] - a[1]);
return a[0] + t * (a[0] - a[1]);
}
P reflection(L a, P p) { return p + 2.0 * (projection(a, p) - p); }
bool intersectLL(const L &l, const L &m) {
return abs(cross(l[1] - l[0], m[1] - m[0])) > EPS || // non-parallel
abs(cross(l[1] - l[0], m[0] - l[0])) < EPS; // same line
}
bool intersectLS(const L &l, const L &s) {
return cross(l[1] - l[0], s[0] - l[0]) * // s[0] is left of l
cross(l[1] - l[0], s[1] - l[0]) <
EPS; // s[1] is right of l
}
bool intersectLP(const L &l, const P &p) {
return abs(cross(l[1] - p, l[0] - p)) < EPS;
}
bool intersectSS(const L &s, const L &t) {
return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 &&
ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
}
bool intersectSP(const L &s, const P &p) {
return abs(s[0] - p) + abs(s[1] - p) - abs(s[1] - s[0]) <
EPS; // triangle inequality
}
double distanceLP(const L &l, const P &p) { return abs(p - projection(l, p)); }
double distanceLL(const L &l, const L &m) {
return intersectLL(l, m) ? 0 : distanceLP(l, m[0]);
}
double distanceLS(const L &l, const L &s) {
if (intersectLS(l, s))
return 0;
return min(distanceLP(l, s[0]), distanceLP(l, s[1]));
}
double distanceSP(const L &s, const P &p) {
const P r = projection(s, p);
if (intersectSP(s, r))
return abs(r - p);
return min(abs(s[0] - p), abs(s[1] - p));
}
double distanceSS(const L &s, const L &t) {
if (intersectSS(s, t))
return 0;
return min(min(distanceSP(s, t[0]), distanceSP(s, t[1])),
min(distanceSP(t, s[0]), distanceSP(t, s[1])));
}
/*bool intersectCS(C c,const L &l){
return (distanceLP(l,c.c) < c.r+EPS &&
(c.r < abs(c.c-l[0]) + EPS || c.r < abs(c.c-l[1]) + EPS));
}*/
int intersectCS(C c, L &l) {
if (norm(projection(l, c.c) - c.c) - c.r * c.r > EPS)
return 0;
const double d1 = abs(c.c - l[0]), d2 = abs(c.c - l[1]);
if (d1 < c.r + EPS && d2 < c.r + EPS)
return 0;
if (d1 < c.r - EPS && d2 > c.r + EPS || d1 > c.r + EPS && d2 < c.r - EPS)
return 1;
const P h = projection(l, c.c);
if (dot(l[0] - h, l[1] - h) < 0)
return 2;
return 0;
}
P crosspointSS(L a, L b) {
double t1 = abs(cross(a[1] - a[0], b[0] - a[0]));
double t2 = abs(cross(a[1] - a[0], b[1] - a[0]));
return b[0] + (b[1] - b[0]) * t1 / (t1 + t2);
}
L crosspointCL(C c, L l) {
P pr = projection(l, c.c);
P e = (l[1] - l[0]) / abs(l[1] - l[0]);
double t = sqrt(c.r * c.r - norm(pr - c.c));
P a = pr + t * e;
P b = pr - t * e;
if (b < a)
swap(a, b);
return L(a, b);
}
L crosspointCS(C c, L l) {
if (intersectCS(c, l) == 2)
return crosspointCL(c, l);
L ret = crosspointCL(c, l);
if (dot(l[0] - ret[0], l[1] - ret[0]) < 0)
ret[1] = ret[0];
else
ret[0] = ret[1];
return ret;
}
L crosspointCC(C a, C b) {
P tmp = b.c - a.c;
double d = abs(tmp);
double q = acos((a.r * a.r + d * d - b.r * b.r) / (2 * a.r * d));
double t = arg(tmp); // atan(tmp.imag()/tmp.real());
P p1 = a.c + polar(a.r, t + q);
P p2 = a.c + polar(a.r, t - q);
if (p2 < p1)
swap(p1, p2);
return L(p1, p2);
}
P crosspointLL(const L &l, const L &m) {
double A = cross(l[1] - l[0], m[1] - m[0]);
double B = cross(l[1] - l[0], l[1] - m[0]);
if (abs(A) < EPS && abs(B) < EPS)
return m[0]; // same line
return m[0] + B / A * (m[1] - m[0]);
}
double area(const G &g) {
double S = 0;
for (int i = 0; i < g.size(); i++) {
S += (cross(g[i], g[(i + 1) % g.size()]));
}
return abs(S / 2.0);
}
bool isconvex(const G &g) {
int n = g.size();
rep(i, n) if (ccw(g[(i + n - 1) % n], g[i % n], g[(i + 1) % n]) ==
-1) return false;
return true;
}
int inconvex(const G &g, const P &p) {
bool in = false;
int n = g.size();
rep(i, n) {
P a = g[i % n] - p;
P b = g[(i + 1) % n] - p;
if (imag(a) > imag(b))
swap(a, b);
if (imag(a) <= 0 && 0 < imag(b))
if (cross(a, b) < 0)
in = !in;
if (cross(a, b) == 0 && dot(a, b) <= 0)
return 1; // ON
}
return in ? 2 : 0; // IN : OUT;
}
G convex_hull(G &ps) {
int n = ps.size(), k = 0;
sort(ps.begin(), ps.end());
G ch(2 * n);
for (int i = 0; i < n; ch[k++] = ps[i++]) // lower-hull
while (k >= 2 && ccw(ch[k - 2], ch[k - 1], ps[i]) == -1)
--k; //<=0 -> ==-1
for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = ps[i--]) // upper-hull
while (k >= t && ccw(ch[k - 2], ch[k - 1], ps[i]) == -1)
--k; //
ch.resize(k - 1);
return ch;
}
double convex_diameter(const G &pt) {
const int n = pt.size();
int is = 0, js = 0;
for (int i = 1; i < n; ++i) {
if (imag(pt[i]) > imag(pt[is]))
is = i;
if (imag(pt[i]) < imag(pt[js]))
js = i;
}
double maxd = norm(pt[is] - pt[js]);
int i, maxi, j, maxj;
i = maxi = is;
j = maxj = js;
do {
if (cross(diff(pt, i), diff(pt, j)) >= 0)
j = (j + 1) % n;
else
i = (i + 1) % n;
if (norm(pt[i] - pt[j]) > maxd) {
maxd = norm(pt[i] - pt[j]);
maxi = i;
maxj = j;
}
} while (i != is || j != js);
return sqrt(maxd); /* farthest pair is (maxi, maxj). */
} // convex_diameter(g)
G convex_cut(const G &g, const L &l) {
G Q;
for (int i = 0; i < g.size(); ++i) {
P a = curr(g, i), b = next(g, i);
if (ccw(l[0], l[1], a) != -1)
Q.push_back(a);
if (ccw(l[0], l[1], a) * ccw(l[0], l[1], b) < 0)
Q.push_back(crosspointLL(L(a, b), l));
}
return Q;
}
P turn(P p, double t) { return p * exp(P(.0, t * PI / 180.0)); }
P turn2(P p, double t) { return p * exp(P(.0, t)); }
vector<L> tangentCC(C a, C b) {
if (a.r < b.r)
swap(a, b);
double d = abs(a.c - b.c);
vector<L> l;
if (d < EPS)
return l;
if (a.r + b.r < d - EPS) { // hanareteiru
double t = acos((a.r + b.r) / d);
t = t * 180 / PI;
l.pb(L(a.c + turn(a.r / d * (b.c - a.c), t),
b.c + turn(b.r / d * (a.c - b.c), t)));
l.pb(L(a.c + turn(a.r / d * (b.c - a.c), -t),
b.c + turn(b.r / d * (a.c - b.c), -t)));
} else if (a.r + b.r < d + EPS) { // kuttuiteiru soto
P p = a.c + a.r / d * (b.c - a.c);
l.pb(L(p, p + turn(b.c - a.c, 90)));
}
if (abs(a.r - b.r) < d - EPS) { // majiwatteiru
double t1 = acos((a.r - b.r) / d);
t1 = t1 * 180 / PI;
double t2 = 180 - t1;
l.pb(L(a.c + turn(a.r / d * (b.c - a.c), t1),
b.c + turn(b.r / d * (a.c - b.c), -t2)));
l.pb(L(a.c + turn(a.r / d * (b.c - a.c), -t1),
b.c + turn(b.r / d * (a.c - b.c), t2)));
} else if (abs(a.r - b.r) < d + EPS) { // kuttuiteiru uti
P p = a.c + a.r / d * (b.c - a.c);
l.pb(L(p, p + turn(b.c - a.c, 90)));
}
return l;
}
void printL(const L &out) {
printf("%.9f %.9f %.9f %.9f\n", out[0].real(), out[0].imag(), out[1].real(),
out[1].imag());
}
C CIN() {
P p = pin();
double r;
cin >> r;
return C(p, r);
}
bool para(L a, L b) { return (abs(cross(a[1] - a[0], b[1] - b[0])) < EPS); }
double min(double a, double b) { return a < b ? a : b; }
int main() {
int q;
cin >> q;
while (q--) {
P a = pin(), b = pin(), c = pin();
L s(a + b, P(0, 0)), t(b + c, P(0, 0));
s[0] /= 2;
t[0] /= 2;
s[1] = P(0, 1) * (b - a) + s[0];
t[1] = P(0, 1) * (c - b) + t[0];
P p = crosspointLL(s, t);
cout << shosu(9) << p.real() << " " << p.imag() << " " << abs(p - c)
<< endl;
}
}
|
/*include*/
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define rp(a) while (a--)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
const double PI = acos(-1);
const double EPS = 1e-10;
const double inf = 1e8;
using namespace std;
#define shosu(x) fixed << setprecision(x)
typedef complex<double> P;
typedef vector<P> G;
typedef vector<int> vi;
typedef vector<vi> vvi;
struct L : public vector<P> {
L(const P &a, const P &b) {
push_back(a);
push_back(b);
}
};
struct C {
P c;
double r;
C(const P &c, double r) : c(c), r(r) {}
};
#define curr(P, i) P[i]
#define next(P, i) P[(i + 1) % P.size()]
#define diff(P, i) (next(P, i) - curr(P, i))
namespace std {
bool operator<(const P &a, const P &b) {
return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
// return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b);
}
bool operator==(const P &a, const P &b) {
return a.real() == b.real() && a.imag() == b.imag();
}
} // namespace std
P pin() {
double x, y;
char d;
cin >> x >> y;
P p(x, y);
return p;
}
void PIN(P *a, int n) { rep(i, n) a[i] = pin(); }
double dot(P a, P b) { return real(conj(a) * b); }
double cross(P a, P b) { return imag(conj(a) * b); }
int ccw(P a, P b, P c) {
b -= a;
c -= a;
if (cross(b, c) > 0)
return +1; // counter clockwise
if (cross(b, c) < 0)
return -1; // clockwise
if (dot(b, c) < 0)
return +2; // c--a--b on line
if (norm(b) < norm(c))
return -2; // a--b--c on line
return 0;
}
P projection(L a, P p) {
double t = dot(p - a[0], a[0] - a[1]) / norm(a[0] - a[1]);
return a[0] + t * (a[0] - a[1]);
}
P reflection(L a, P p) { return p + 2.0 * (projection(a, p) - p); }
bool intersectLL(const L &l, const L &m) {
return abs(cross(l[1] - l[0], m[1] - m[0])) > EPS || // non-parallel
abs(cross(l[1] - l[0], m[0] - l[0])) < EPS; // same line
}
bool intersectLS(const L &l, const L &s) {
return cross(l[1] - l[0], s[0] - l[0]) * // s[0] is left of l
cross(l[1] - l[0], s[1] - l[0]) <
EPS; // s[1] is right of l
}
bool intersectLP(const L &l, const P &p) {
return abs(cross(l[1] - p, l[0] - p)) < EPS;
}
bool intersectSS(const L &s, const L &t) {
return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 &&
ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
}
bool intersectSP(const L &s, const P &p) {
return abs(s[0] - p) + abs(s[1] - p) - abs(s[1] - s[0]) <
EPS; // triangle inequality
}
double distanceLP(const L &l, const P &p) { return abs(p - projection(l, p)); }
double distanceLL(const L &l, const L &m) {
return intersectLL(l, m) ? 0 : distanceLP(l, m[0]);
}
double distanceLS(const L &l, const L &s) {
if (intersectLS(l, s))
return 0;
return min(distanceLP(l, s[0]), distanceLP(l, s[1]));
}
double distanceSP(const L &s, const P &p) {
const P r = projection(s, p);
if (intersectSP(s, r))
return abs(r - p);
return min(abs(s[0] - p), abs(s[1] - p));
}
double distanceSS(const L &s, const L &t) {
if (intersectSS(s, t))
return 0;
return min(min(distanceSP(s, t[0]), distanceSP(s, t[1])),
min(distanceSP(t, s[0]), distanceSP(t, s[1])));
}
/*bool intersectCS(C c,const L &l){
return (distanceLP(l,c.c) < c.r+EPS &&
(c.r < abs(c.c-l[0]) + EPS || c.r < abs(c.c-l[1]) + EPS));
}*/
int intersectCS(C c, L &l) {
if (norm(projection(l, c.c) - c.c) - c.r * c.r > EPS)
return 0;
const double d1 = abs(c.c - l[0]), d2 = abs(c.c - l[1]);
if (d1 < c.r + EPS && d2 < c.r + EPS)
return 0;
if (d1 < c.r - EPS && d2 > c.r + EPS || d1 > c.r + EPS && d2 < c.r - EPS)
return 1;
const P h = projection(l, c.c);
if (dot(l[0] - h, l[1] - h) < 0)
return 2;
return 0;
}
P crosspointSS(L a, L b) {
double t1 = abs(cross(a[1] - a[0], b[0] - a[0]));
double t2 = abs(cross(a[1] - a[0], b[1] - a[0]));
return b[0] + (b[1] - b[0]) * t1 / (t1 + t2);
}
L crosspointCL(C c, L l) {
P pr = projection(l, c.c);
P e = (l[1] - l[0]) / abs(l[1] - l[0]);
double t = sqrt(c.r * c.r - norm(pr - c.c));
P a = pr + t * e;
P b = pr - t * e;
if (b < a)
swap(a, b);
return L(a, b);
}
L crosspointCS(C c, L l) {
if (intersectCS(c, l) == 2)
return crosspointCL(c, l);
L ret = crosspointCL(c, l);
if (dot(l[0] - ret[0], l[1] - ret[0]) < 0)
ret[1] = ret[0];
else
ret[0] = ret[1];
return ret;
}
L crosspointCC(C a, C b) {
P tmp = b.c - a.c;
double d = abs(tmp);
double q = acos((a.r * a.r + d * d - b.r * b.r) / (2 * a.r * d));
double t = arg(tmp); // atan(tmp.imag()/tmp.real());
P p1 = a.c + polar(a.r, t + q);
P p2 = a.c + polar(a.r, t - q);
if (p2 < p1)
swap(p1, p2);
return L(p1, p2);
}
P crosspointLL(const L &l, const L &m) {
double A = cross(l[1] - l[0], m[1] - m[0]);
double B = cross(l[1] - l[0], l[1] - m[0]);
if (abs(A) < EPS && abs(B) < EPS)
return m[0]; // same line
return m[0] + B / A * (m[1] - m[0]);
}
double area(const G &g) {
double S = 0;
for (int i = 0; i < g.size(); i++) {
S += (cross(g[i], g[(i + 1) % g.size()]));
}
return abs(S / 2.0);
}
bool isconvex(const G &g) {
int n = g.size();
rep(i, n) if (ccw(g[(i + n - 1) % n], g[i % n], g[(i + 1) % n]) ==
-1) return false;
return true;
}
int inconvex(const G &g, const P &p) {
bool in = false;
int n = g.size();
rep(i, n) {
P a = g[i % n] - p;
P b = g[(i + 1) % n] - p;
if (imag(a) > imag(b))
swap(a, b);
if (imag(a) <= 0 && 0 < imag(b))
if (cross(a, b) < 0)
in = !in;
if (cross(a, b) == 0 && dot(a, b) <= 0)
return 1; // ON
}
return in ? 2 : 0; // IN : OUT;
}
G convex_hull(G &ps) {
int n = ps.size(), k = 0;
sort(ps.begin(), ps.end());
G ch(2 * n);
for (int i = 0; i < n; ch[k++] = ps[i++]) // lower-hull
while (k >= 2 && ccw(ch[k - 2], ch[k - 1], ps[i]) == -1)
--k; //<=0 -> ==-1
for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = ps[i--]) // upper-hull
while (k >= t && ccw(ch[k - 2], ch[k - 1], ps[i]) == -1)
--k; //
ch.resize(k - 1);
return ch;
}
double convex_diameter(const G &pt) {
const int n = pt.size();
int is = 0, js = 0;
for (int i = 1; i < n; ++i) {
if (imag(pt[i]) > imag(pt[is]))
is = i;
if (imag(pt[i]) < imag(pt[js]))
js = i;
}
double maxd = norm(pt[is] - pt[js]);
int i, maxi, j, maxj;
i = maxi = is;
j = maxj = js;
do {
if (cross(diff(pt, i), diff(pt, j)) >= 0)
j = (j + 1) % n;
else
i = (i + 1) % n;
if (norm(pt[i] - pt[j]) > maxd) {
maxd = norm(pt[i] - pt[j]);
maxi = i;
maxj = j;
}
} while (i != is || j != js);
return sqrt(maxd); /* farthest pair is (maxi, maxj). */
} // convex_diameter(g)
G convex_cut(const G &g, const L &l) {
G Q;
for (int i = 0; i < g.size(); ++i) {
P a = curr(g, i), b = next(g, i);
if (ccw(l[0], l[1], a) != -1)
Q.push_back(a);
if (ccw(l[0], l[1], a) * ccw(l[0], l[1], b) < 0)
Q.push_back(crosspointLL(L(a, b), l));
}
return Q;
}
P turn(P p, double t) { return p * exp(P(.0, t * PI / 180.0)); }
P turn2(P p, double t) { return p * exp(P(.0, t)); }
vector<L> tangentCC(C a, C b) {
if (a.r < b.r)
swap(a, b);
double d = abs(a.c - b.c);
vector<L> l;
if (d < EPS)
return l;
if (a.r + b.r < d - EPS) { // hanareteiru
double t = acos((a.r + b.r) / d);
t = t * 180 / PI;
l.pb(L(a.c + turn(a.r / d * (b.c - a.c), t),
b.c + turn(b.r / d * (a.c - b.c), t)));
l.pb(L(a.c + turn(a.r / d * (b.c - a.c), -t),
b.c + turn(b.r / d * (a.c - b.c), -t)));
} else if (a.r + b.r < d + EPS) { // kuttuiteiru soto
P p = a.c + a.r / d * (b.c - a.c);
l.pb(L(p, p + turn(b.c - a.c, 90)));
}
if (abs(a.r - b.r) < d - EPS) { // majiwatteiru
double t1 = acos((a.r - b.r) / d);
t1 = t1 * 180 / PI;
double t2 = 180 - t1;
l.pb(L(a.c + turn(a.r / d * (b.c - a.c), t1),
b.c + turn(b.r / d * (a.c - b.c), -t2)));
l.pb(L(a.c + turn(a.r / d * (b.c - a.c), -t1),
b.c + turn(b.r / d * (a.c - b.c), t2)));
} else if (abs(a.r - b.r) < d + EPS) { // kuttuiteiru uti
P p = a.c + a.r / d * (b.c - a.c);
l.pb(L(p, p + turn(b.c - a.c, 90)));
}
return l;
}
void printL(const L &out) {
printf("%.9f %.9f %.9f %.9f\n", out[0].real(), out[0].imag(), out[1].real(),
out[1].imag());
}
C CIN() {
P p = pin();
double r;
cin >> r;
return C(p, r);
}
bool para(L a, L b) { return (abs(cross(a[1] - a[0], b[1] - b[0])) < EPS); }
double min(double a, double b) { return a < b ? a : b; }
int main() {
int q;
cin >> q;
while (q--) {
P a = pin(), b = pin(), c = pin();
L s(a + b, P(0, 0)), t(b + c, P(0, 0));
s[0] /= 2;
t[0] /= 2;
s[1] = P(0, 1) * (b - a) + s[0];
t[1] = P(0, 1) * (c - b) + t[0];
P p = crosspointLL(s, t);
cout << shosu(3) << p.real() << " " << p.imag() << " " << abs(p - c)
<< endl;
}
}
|
[["-", 31, 16, 31, 16, 12, 2, 3, 4, 0, 13], ["+", 31, 16, 31, 16, 12, 2, 3, 4, 0, 13]]
| 1
| 3,630
|
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
typedef pair<double, double> vec;
vec operator+(vec v1, vec v2) {
return make_pair(v1.first + v2.first, v1.second + v2.second);
}
vec operator-(vec v1, vec v2) {
return make_pair(v1.first - v2.first, v1.second - v2.second);
}
vec operator*(double v, vec v2) {
return make_pair(v * v2.first, v * v2.second);
}
vec operator/(vec v1, double d) {
return make_pair(v1.first / d, v1.second / d);
}
int norm2(vec v1, vec v2) {
return (v1 - v2).first * (v1 - v2).first +
(v1 - v2).second * (v1 - v2).second;
}
int main() {
double x1, x2, x3, y1, y2, y3, n, r;
cin >> n;
while (n--) {
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
vec A = make_pair(x1, y1);
vec B = make_pair(x2, y2);
vec C = make_pair(x3, y3);
double a2, b2, c2, a, b, c, cosA, cosB, cosC, sinA, sinB, sinC, cos2A,
cos2B, cos2C, sin2A, sin2B, sin2C;
a2 = norm2(B, C);
b2 = norm2(A, C);
c2 = norm2(A, B);
a = sqrt(a2);
b = sqrt(b2);
c = sqrt(c2);
cosA = (b2 + c2 - a2) / (2 * b * c);
cosB = (a2 + c2 - b2) / (2 * c * a);
cosC = (b2 + a2 - c2) / (2 * b * a);
sinA = sqrt(1 - cosA * cosA);
sinB = sqrt(1 - cosB * cosB);
sinC = sqrt(1 - cosC * cosC);
r = (a / sinA) / 2;
cos2A = cosA * cosA - sinA * sinA;
cos2B = cosB * cosB - sinB * sinB;
cos2C = cosC * cosC - sinC * sinC;
sin2A = 2 * sinA * cosA;
sin2B = 2 * sinB * cosB;
sin2C = 2 * sinC * cosC;
vec v = (sin2A * A + sin2B * B + sin2C * C) / (sin2A + sin2B + sin2C);
printf("%.3f %.3f %.3f\n", v.first, v.second, r);
}
}
|
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
typedef pair<double, double> vec;
vec operator+(vec v1, vec v2) {
return make_pair(v1.first + v2.first, v1.second + v2.second);
}
vec operator-(vec v1, vec v2) {
return make_pair(v1.first - v2.first, v1.second - v2.second);
}
vec operator*(double v, vec v2) {
return make_pair(v * v2.first, v * v2.second);
}
vec operator/(vec v1, double d) {
return make_pair(v1.first / d, v1.second / d);
}
double norm2(vec v1, vec v2) {
return (v1 - v2).first * (v1 - v2).first +
(v1 - v2).second * (v1 - v2).second;
}
int main() {
double x1, x2, x3, y1, y2, y3, n, r;
cin >> n;
while (n--) {
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
vec A = make_pair(x1, y1);
vec B = make_pair(x2, y2);
vec C = make_pair(x3, y3);
double a2, b2, c2, a, b, c, cosA, cosB, cosC, sinA, sinB, sinC, cos2A,
cos2B, cos2C, sin2A, sin2B, sin2C;
a2 = norm2(B, C);
b2 = norm2(A, C);
c2 = norm2(A, B);
a = sqrt(a2);
b = sqrt(b2);
c = sqrt(c2);
cosA = (b2 + c2 - a2) / (2 * b * c);
cosB = (a2 + c2 - b2) / (2 * c * a);
cosC = (b2 + a2 - c2) / (2 * b * a);
sinA = sqrt(1 - cosA * cosA);
sinB = sqrt(1 - cosB * cosB);
sinC = sqrt(1 - cosC * cosC);
r = (a / sinA) / 2;
cos2A = cosA * cosA - sinA * sinA;
cos2B = cosB * cosB - sinB * sinB;
cos2C = cosC * cosC - sinC * sinC;
sin2A = 2 * sinA * cosA;
sin2B = 2 * sinB * cosB;
sin2C = 2 * sinC * cosC;
vec v = (sin2A * A + sin2B * B + sin2C * C) / (sin2A + sin2B + sin2C);
printf("%.3f %.3f %.3f\n", v.first, v.second, r);
}
}
|
[["-", 36, 36, 36, 36, 0, 30, 0, 14, 39, 40], ["+", 36, 36, 36, 36, 0, 30, 0, 14, 39, 40]]
| 1
| 540
|
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
int n;
double x1, y1, x2, y2, x3, y3;
cin >> n;
while (n > 0) {
double px, py, r;
double A, B, C, a, b, c;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
A = 2 * (x2 - x1);
B = 2 * (y2 - y1);
C = (pow(x1, 2) - pow(x2, 2)) + (pow(y1, 2) - pow(y2, 2));
a = 2 * (x3 - x1);
b = 2 * (y3 - y1);
c = (pow(x1, 2) - pow(x3, 2)) + (pow(y1, 2) + pow(y3, 2));
px = (B * c - b * C) / (A * b - a * B);
py = (C * a - c * A) / (A * b - a * B);
r = sqrt(pow(x1 - px, 2) + pow(y1 - py, 2));
printf("%.3f %.3f %.3f\n", px, py, r);
n--;
}
}
|
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
int n;
double x1, y1, x2, y2, x3, y3;
cin >> n;
while (n > 0) {
double px, py, r;
double A, B, C, a, b, c;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
A = 2 * (x2 - x1);
B = 2 * (y2 - y1);
C = (pow(x1, 2) - pow(x2, 2)) + (pow(y1, 2) - pow(y2, 2));
a = 2 * (x3 - x1);
b = 2 * (y3 - y1);
c = (pow(x1, 2) - pow(x3, 2)) + (pow(y1, 2) - pow(y3, 2));
px = (B * c - b * C) / (A * b - a * B);
py = (C * a - c * A) / (A * b - a * B);
r = sqrt(pow(x1 - px, 2) + pow(y1 - py, 2));
printf("%.3f %.3f %.3f\n", px, py, r);
n--;
}
}
|
[["-", 0, 11, 12, 16, 12, 23, 0, 16, 17, 72], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 17, 33]]
| 1
| 270
|
#include <iomanip>
#include <iostream>
#include <math.h>
using namespace std;
double length(double x1, double y1, double x2, double y2) {
return sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
}
double round(double d) {
if (d < 0) {
d *= 1000;
d -= 0.5;
int i = d;
d = i / 1000.0;
} else {
d *= 1000;
d += 0.5;
int i = d;
d = i / 1000.0;
}
return d;
}
int main() {
int n;
cin >> n;
double x1, y1, x2, y2, x3, y3, px, py, r;
for (int i = 0; i < n; ++i) {
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
px = ((y1 - y3) * (pow(x1, 2) - pow(x2, 2) + pow(y1, 2) - pow(y2, 2)) -
(y1 - y2) * (pow(x1, 2) - pow(x3, 2) + pow(y1, 2) - pow(y3, 2))) /
((x1 - x2) * (y1 - y3) - (x1 - x3) * (y1 - y2)) / 2.0;
py = ((x1 - x3) * (pow(x1, 2) - pow(x2, 2) + pow(y1, 2) - pow(y2, 2)) -
(x1 - x2) * (pow(x1, 2) - pow(x3, 2) + pow(y1, 2) - pow(y3, 2))) /
((x1 - x3) * (y1 - y2) - (x1 - x2) * (y1 - y3)) / 2.0;
r = length(x1, x2, px, py);
px = round(px);
py = round(py);
r = round(r);
cout << fixed << setprecision(3) << px << " " << py << " " << r << endl;
}
return 0;
}
|
#include <iomanip>
#include <iostream>
#include <math.h>
using namespace std;
double length(double x1, double y1, double x2, double y2) {
return sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
}
double round(double d) {
if (d < 0) {
d *= 1000;
d -= 0.5;
int i = d;
d = i / 1000.0;
} else {
d *= 1000;
d += 0.5;
int i = d;
d = i / 1000.0;
}
return d;
}
int main() {
int n;
cin >> n;
double x1, y1, x2, y2, x3, y3, px, py, r;
for (int i = 0; i < n; ++i) {
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
px = ((y1 - y3) * (pow(x1, 2) - pow(x2, 2) + pow(y1, 2) - pow(y2, 2)) -
(y1 - y2) * (pow(x1, 2) - pow(x3, 2) + pow(y1, 2) - pow(y3, 2))) /
((x1 - x2) * (y1 - y3) - (x1 - x3) * (y1 - y2)) / 2.0;
py = ((x1 - x3) * (pow(x1, 2) - pow(x2, 2) + pow(y1, 2) - pow(y2, 2)) -
(x1 - x2) * (pow(x1, 2) - pow(x3, 2) + pow(y1, 2) - pow(y3, 2))) /
((x1 - x3) * (y1 - y2) - (x1 - x2) * (y1 - y3)) / 2.0;
r = length(x1, y1, px, py);
px = round(px);
py = round(py);
r = round(r);
cout << fixed << setprecision(3) << px << " " << py << " " << r << endl;
}
return 0;
}
|
[["-", 0, 1, 0, 11, 12, 2, 3, 4, 0, 22], ["+", 0, 1, 0, 11, 12, 2, 3, 4, 0, 22]]
| 1
| 441
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>
#define rep(i, j) FOR(i, 0, j)
#define FOR(i, j, k) for (int i = j; i < k; ++i)
#define SQ(i) ((i) * (i))
using namespace std;
int main() {
double x1, y1, x2, y2, x3, y3;
double a1, b1, c1, a2, b2, c2, x, y, a, b, c, cos_a, sin_a, r;
int n;
scanf("%d", &n);
while (n--) {
scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3);
a1 = 2 * (x2 - x1);
b1 = 2 * (y2 - y1);
c1 = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2;
a2 = 2 * (x3 - x1);
b2 = 2 * (y3 - y1);
c2 = x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3;
x = (b1 * c1 - b2 * c1) / (a1 * b2 - a2 * b1);
y = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1);
r = SQ(x3 - x) + SQ(y3 - y);
r = sqrt(r);
printf("%.3f %.3f %.3f\n", x, y, r);
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>
#define rep(i, j) FOR(i, 0, j)
#define FOR(i, j, k) for (int i = j; i < k; ++i)
#define SQ(i) ((i) * (i))
using namespace std;
int main() {
double x1, y1, x2, y2, x3, y3;
double a1, b1, c1, a2, b2, c2, x, y, a, b, c, cos_a, sin_a, r;
int n;
scanf("%d", &n);
while (n--) {
scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3);
a1 = 2 * (x2 - x1);
b1 = 2 * (y2 - y1);
c1 = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2;
a2 = 2 * (x3 - x1);
b2 = 2 * (y3 - y1);
c2 = x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3;
x = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1);
y = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1);
r = SQ(x3 - x) + SQ(y3 - y);
r = sqrt(r);
printf("%.3f %.3f %.3f\n", x, y, r);
}
return 0;
}
|
[["-", 12, 16, 31, 23, 0, 16, 31, 16, 12, 22], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 12, 22]]
| 1
| 297
|
#include <cmath>
#include <cstdio>
int n;
double x[3], y[3];
struct data {
double a, b, c;
data(double aa, double bb, double cc) {
a = aa;
b = bb;
c = cc;
}
};
struct data2 {
double x, y, r;
data2() {}
data2(double xx, double yy, double rr) {
x = xx;
y = yy;
r = rr;
}
};
data make_line(int i, int j) {
if (x[i] == x[j]) {
return data(0.0, (y[i] + y[j]) / 2.0, 1);
}
if (y[i] == y[j]) {
return data((x[i] + x[j]) / 2, 0, 0);
}
double aa = (y[i] - y[j]) / (x[i] - x[j]);
aa = -1.0 / aa;
double bb = (y[i] + y[j]) / 2.0 - (x[j] + x[i]) / 2.0 * aa;
return data(aa, bb, 1);
}
data2 cross(data y1, data y2) {
data2 d;
if (y1.c == 0) {
d.x = y1.a;
d.y = y2.a * d.x + y2.b;
}
if (y2.c == 0) {
d.x = y2.a;
d.y = y1.a * d.x + y1.b;
}
if (y1.c == 1 && y2.c == 1) {
d.x = (y1.b - y2.b) / (y1.a - y2.a);
d.y = y1.a * d.x + y1.b;
}
d.r = sqrt(pow(d.x - x[0], 2) + pow(d.y - y[0], 2));
return d;
}
int main(void) {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) {
scanf("%lf %lf", &x[j], &y[j]);
}
data y1 = make_line(0, 1);
data y2 = make_line(0, 2);
data2 y3 = cross(y1, y2);
printf("%.3f %.3f %.3f\n", y3.x, y3.y, y3.r);
}
return 0;
}
|
#include <cmath>
#include <cstdio>
int n;
double x[3], y[3];
struct data {
double a, b, c;
data(double aa, double bb, double cc) {
a = aa;
b = bb;
c = cc;
}
};
struct data2 {
double x, y, r;
data2() {}
data2(double xx, double yy, double rr) {
x = xx;
y = yy;
r = rr;
}
};
data make_line(int i, int j) {
if (x[i] == x[j]) {
return data(0.0, (y[i] + y[j]) / 2.0, 1);
}
if (y[i] == y[j]) {
return data((x[i] + x[j]) / 2, 0, 0);
}
double aa = (y[i] - y[j]) / (x[i] - x[j]);
aa = -1.0 / aa;
double bb = (y[i] + y[j]) / 2.0 - (x[j] + x[i]) / 2.0 * aa;
return data(aa, bb, 1);
}
data2 cross(data y1, data y2) {
data2 d;
if (y1.c == 0) {
d.x = y1.a;
d.y = y2.a * d.x + y2.b;
}
if (y2.c == 0) {
d.x = y2.a;
d.y = y1.a * d.x + y1.b;
}
if (y1.c == 1 && y2.c == 1) {
d.x = -(y1.b - y2.b) / (y1.a - y2.a);
d.y = y1.a * d.x + y1.b;
}
d.r = sqrt(pow(d.x - x[0], 2) + pow(d.y - y[0], 2));
return d;
}
int main(void) {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) {
scanf("%lf %lf", &x[j], &y[j]);
}
data y1 = make_line(0, 1);
// printf("%.3f %.3f\n",y1.a,y1.b);
data y2 = make_line(0, 2);
// printf("%.3f %.3f\n",y2.a,y2.b);
data2 y3 = cross(y1, y2);
printf("%.3f %.3f %.3f\n", y3.x, y3.y, y3.r);
}
return 0;
}
|
[["+", 0, 1, 0, 11, 12, 16, 31, 91, 17, 33]]
| 1
| 553
|
#include <cmath>
#include <cstdio>
#include <iostream>
#include <utility>
// ax + by = e1
// cx + dy = e2
auto solve(double a, double b, double c, double d, double e1, double e2)
-> std::pair<double, double> {
auto delta = a * d - b * c;
auto x = (d * e1 - b * e2) / delta;
auto y = (a * e2 - c * e1) / delta;
return std::make_pair(std::move(x), std::move(y));
}
auto distance(const std::pair<double, double> &a,
const std::pair<double, double> &b) -> double {
auto dx = a.first - b.first;
auto dy = a.second - b.second;
return std::sqrt(dx * dx + dy * dy);
}
auto show(double v) -> std::string {
if (-0.5 < v && v < 0) {
return "0.000";
}
char s[100];
std::sprintf(s, "%.3f", v);
return s;
}
auto main() -> int {
int n;
std::cin >> n;
for (auto i = 0; i < n; ++i) {
double x1, y1, x2, y2, x3, y3;
std::cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
auto b1 = (y2 - y1) * (y1 + y2) / 2 + (x2 - x1) * (x1 + x2) / 2;
auto b2 = (y3 - y1) * (y1 + y3) / 2 + (x3 - x1) * (x1 + x3) / 2;
auto p = solve((x2 - x1), (y2 - y1), (x3 - x1), (y3 - y1), b1, b2);
auto r = distance(p, std::make_pair(x1, y1));
std::cout << show(p.first) << ' ' << show(p.second) << ' ' << show(r)
<< std::endl;
}
}
|
#include <cmath>
#include <cstdio>
#include <iostream>
#include <utility>
// ax + by = e1
// cx + dy = e2
auto solve(double a, double b, double c, double d, double e1, double e2)
-> std::pair<double, double> {
auto delta = a * d - b * c;
auto x = (d * e1 - b * e2) / delta;
auto y = (a * e2 - c * e1) / delta;
return std::make_pair(std::move(x), std::move(y));
}
auto distance(const std::pair<double, double> &a,
const std::pair<double, double> &b) -> double {
auto dx = a.first - b.first;
auto dy = a.second - b.second;
return std::sqrt(dx * dx + dy * dy);
}
auto show(double v) -> std::string {
if (-0.0005 < v && v < 0.0005) {
return "0.000";
}
char s[100];
std::sprintf(s, "%.3f", v);
return s;
}
auto main() -> int {
int n;
std::cin >> n;
for (auto i = 0; i < n; ++i) {
double x1, y1, x2, y2, x3, y3;
std::cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
auto b1 = (y2 - y1) * (y1 + y2) / 2 + (x2 - x1) * (x1 + x2) / 2;
auto b2 = (y3 - y1) * (y1 + y3) / 2 + (x3 - x1) * (x1 + x3) / 2;
auto p = solve((x2 - x1), (y2 - y1), (x3 - x1), (y3 - y1), b1, b2);
auto r = distance(p, std::make_pair(x1, y1));
std::cout << show(p.first) << ' ' << show(p.second) << ' ' << show(r)
<< std::endl;
}
}
|
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 31, 13], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 31, 13], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
| 1
| 431
|
#include <algorithm>
#include <complex>
#include <cstdio>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define pb push_back
#define ALL(a) (a).begin(), (a).end()
typedef long long ll;
typedef complex<double> C;
double dot(C a, C b) { return real(conj(a) * b); }
double cross(C a, C b) { return imag(conj(a) * b); }
C triangle_circumcenter(C a, C b, C c) {
a -= c;
b -= c;
C z =
(abs(a) * abs(a) * b - abs(b) * abs(b) * a) / (conj(a) * b - a * conj(b));
z += c;
return z;
}
int main() {
int n;
scanf("%d", &n);
while (n--) {
double x1, y1, x2, y2, x3, y3;
scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3);
C a = C(x1, y1);
C b = C(x2, y2);
C c = C(x3, y3);
C z = triangle_circumcenter(a, b, c);
printf("%.3f, %.3f, %.3f\n", real(z), imag(z), abs(z - c));
}
return 0;
}
|
#include <algorithm>
#include <complex>
#include <cstdio>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define pb push_back
#define ALL(a) (a).begin(), (a).end()
typedef long long ll;
typedef complex<double> C;
double dot(C a, C b) { return real(conj(a) * b); }
double cross(C a, C b) { return imag(conj(a) * b); }
C triangle_circumcenter(C a, C b, C c) {
a -= c;
b -= c;
C z =
(abs(a) * abs(a) * b - abs(b) * abs(b) * a) / (conj(a) * b - a * conj(b));
z += c;
return z;
}
int main() {
int n;
scanf("%d", &n);
while (n--) {
double x1, y1, x2, y2, x3, y3;
scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3);
C a = C(x1, y1);
C b = C(x2, y2);
C c = C(x3, y3);
C z = triangle_circumcenter(a, b, c);
printf("%.3f %.3f %.3f\n", real(z), imag(z), abs(z - c));
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 1
| 319
|
#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
int main() {
int datasetnum;
double x1, y1, x2, y2, x3, y3;
cin >> datasetnum;
for (int loopcount = 0; loopcount < datasetnum; loopcount++) {
double px, py, r;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
double len_1 = sqrt(pow(x3 - x2, 2) + pow(y3 - y2, 2));
double len_2 = sqrt(pow(x1 - x3, 2) + pow(y1 - y3, 2));
double len_3 = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
double s = (len_1 + len_2 + len_3) / 2;
double area = sqrt(s * (s - len_1) * (s - len_2) * (s - len_3));
double sin_1 = 2 * area / (len_2 * len_3);
r = len_1 / (2 * sin_1);
double a = x1 - x3;
double b = y1 - y3;
double c = pow(x1, 2) - pow(x3, 2) + pow(y1, 2) - pow(y3, 2);
double d = x2 - x3;
double e = y2 - y3;
double f = pow(x2, 2) - pow(x3, 2) + pow(y2, 2) - pow(y3, 2);
px = (c * e - b * f) / (2 * (a * e - b * d));
py = (c * d - a * f) / (2 * (b * d - a * e));
cout << setprecision(4) << px << " " << py << " " << r << endl;
}
return 0;
}
|
#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
int main() {
int datasetnum;
double x1, y1, x2, y2, x3, y3;
cin >> datasetnum;
for (int loopcount = 0; loopcount < datasetnum; loopcount++) {
double px, py, r;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
double len_1 = sqrt(pow(x3 - x2, 2) + pow(y3 - y2, 2));
double len_2 = sqrt(pow(x1 - x3, 2) + pow(y1 - y3, 2));
double len_3 = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
double s = (len_1 + len_2 + len_3) / 2;
double area = sqrt(s * (s - len_1) * (s - len_2) * (s - len_3));
double sin_1 = 2 * area / (len_2 * len_3);
r = len_1 / (2 * sin_1);
double a = x1 - x3;
double b = y1 - y3;
double c = pow(x1, 2) - pow(x3, 2) + pow(y1, 2) - pow(y3, 2);
double d = x2 - x3;
double e = y2 - y3;
double f = pow(x2, 2) - pow(x3, 2) + pow(y2, 2) - pow(y3, 2);
px = (c * e - b * f) / (2 * (a * e - b * d));
py = (c * d - a * f) / (2 * (b * d - a * e));
cout << fixed << setprecision(3) << px << " " << py << " " << r << endl;
}
return 0;
}
|
[["+", 31, 16, 31, 16, 31, 16, 31, 16, 12, 22], ["+", 31, 16, 31, 16, 31, 16, 31, 16, 17, 151], ["-", 31, 16, 31, 16, 12, 2, 3, 4, 0, 13], ["+", 31, 16, 31, 16, 12, 2, 3, 4, 0, 13]]
| 1
| 375
|
#include <math.h>
#include <stdio.h>
int main() {
int i, n;
double x1, x2, x3, y1, y2, y3;
double a, b, c, d, e, f;
double X1, Y1, r;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);
a = 2 * (x2 - x1);
b = 2 * (y2 - y1);
c = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2;
d = 2 * (x3 - x1);
e = 2 * (y3 - y1);
f = x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3;
X1 = (b * f - e * c) / (a * e - d * b);
Y1 = (c * d - f * a) / (a * d - d * b);
r = sqrt((X1 - x1) * (X1 - x1) + (Y1 - y1) * (Y1 - y1));
// X1 *= 1000;
// Y1 *= 1000;
// r *= 1000;
// X1 = (int)(X1 > 0.0 ? X1+0.5 : X1-0.5);
// Y1 = (int)(Y1 > 0.0 ? Y1+0.5 : Y1-0.5);
// r = (int)(r > 0.0 ? r +0.5 : r -0.5);
// X1 = (double)X1/1000;
// Y1 = (double)Y1/1000;
// r = (double)r /1000;
printf("%.3f %.3f %.3f\n", X1, Y1, r);
}
return 0;
}
|
#include <math.h>
#include <stdio.h>
int main() {
int i, n;
double x1, x2, x3, y1, y2, y3;
double a, b, c, d, e, f;
double X1, Y1, r;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);
a = 2 * (x2 - x1);
b = 2 * (y2 - y1);
c = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2;
d = 2 * (x3 - x1);
e = 2 * (y3 - y1);
f = x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3;
X1 = (b * f - e * c) / (a * e - d * b);
Y1 = (c * d - f * a) / (a * e - d * b);
r = sqrt((X1 - x1) * (X1 - x1) + (Y1 - y1) * (Y1 - y1));
// X1 *= 1000;
// Y1 *= 1000;
// r *= 1000;
// X1 = (int)(X1 > 0.0 ? X1+0.5 : X1-0.5);
// Y1 = (int)(Y1 > 0.0 ? Y1+0.5 : Y1-0.5);
// r = (int)(r > 0.0 ? r +0.5 : r -0.5);
// X1 = (double)X1/1000;
// Y1 = (double)Y1/1000;
// r = (double)r /1000;
printf("%.3f %.3f %.3f\n", X1, Y1, r);
}
return 0;
}
|
[["-", 12, 16, 12, 23, 0, 16, 31, 16, 12, 22], ["+", 12, 16, 12, 23, 0, 16, 31, 16, 12, 22]]
| 1
| 273
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
double x1, x2, x3, y1, y2, y3;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
double a1 = 2 * (x2 - x1);
double b1 = 2 * (y2 - y1);
double c1 = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2;
double a2 = 2 * (x3 - x1);
double b2 = 2 * (x3 - x1);
double c2 = x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3;
double x = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1);
double y = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1);
double r = hypot(x - x1, y - y1);
printf("%.3f %.3f %.3f\n", x, y, r);
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
double x1, x2, x3, y1, y2, y3;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
double a1 = 2 * (x2 - x1);
double b1 = 2 * (y2 - y1);
double c1 = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2;
double a2 = 2 * (x3 - x1);
double b2 = 2 * (y3 - y1);
double c2 = x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3;
double x = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1);
double y = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1);
double r = hypot(x - x1, y - y1);
printf("%.3f %.3f %.3f\n", x, y, r);
}
}
|
[["-", 49, 50, 51, 16, 12, 23, 0, 16, 31, 22], ["+", 49, 50, 51, 16, 12, 23, 0, 16, 31, 22], ["-", 49, 50, 51, 16, 12, 23, 0, 16, 12, 22], ["+", 49, 50, 51, 16, 12, 23, 0, 16, 12, 22]]
| 1
| 209
|
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <utility>
#include <vector>
using namespace std;
typedef complex<double> Point;
#define X real()
#define Y imag()
#define EPS 10e-8
namespace std {
bool operator<(Point a, Point b) {
if (a.X != b.X)
return a.X < b.X;
return a.Y < b.Y;
}
} // namespace std
double cross(Point a, Point b) { return (conj(a) * b).Y; }
double dot(Point a, Point b) { return (conj(a) * b).X; }
double dist2(Point a, Point b) { return dot(a - b, a - b); }
struct Line : public vector<Point> {
Line(Point a, Point b) {
push_back(a);
push_back(b);
}
};
int n;
Point ps[3];
Line PerpendBisect(Line l) {
Point mid = (l[0] + l[1]) / 2.0;
return Line(mid, mid + (l[1] - l[0]) * Point(0, 1));
}
Point GetCrossPoint(Line l, Line 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];
if (abs(A) < EPS)
assert(false);
return m[0] + B / A * (m[1] - m[0]);
}
double round3(double t) { return int(t * 1000 + 0.5) / 1000.0; }
int main() {
scanf("%d", &n);
while (n--) {
for (int i = 0; i < 3; i++) {
double x, y;
scanf("%lf%lf", &x, &y);
ps[i] = Point(x, y);
}
Line l(ps[0], ps[1]);
Line m(ps[1], ps[2]);
Point p = GetCrossPoint(PerpendBisect(l), PerpendBisect(m));
double r = sqrt(dist2(p, ps[0]));
printf("%.3f %.3f %.3f\n", round3(p.X), round3(p.Y), round3(r));
}
}
|
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <utility>
#include <vector>
using namespace std;
typedef complex<double> Point;
#define X real()
#define Y imag()
#define EPS 10e-8
namespace std {
bool operator<(Point a, Point b) {
if (a.X != b.X)
return a.X < b.X;
return a.Y < b.Y;
}
} // namespace std
double cross(Point a, Point b) { return (conj(a) * b).Y; }
double dot(Point a, Point b) { return (conj(a) * b).X; }
double dist2(Point a, Point b) { return dot(a - b, a - b); }
struct Line : public vector<Point> {
Line(Point a, Point b) {
push_back(a);
push_back(b);
}
};
int n;
Point ps[3];
Line PerpendBisect(Line l) {
Point mid = (l[0] + l[1]) / 2.0;
return Line(mid, mid + (l[1] - l[0]) * Point(0, 1));
}
Point GetCrossPoint(Line l, Line 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];
if (abs(A) < EPS)
assert(false);
return m[0] + B / A * (m[1] - m[0]);
}
double round3(double t) { return round(t * 1000) / 1000.0; }
int main() {
scanf("%d", &n);
while (n--) {
for (int i = 0; i < 3; i++) {
double x, y;
scanf("%lf%lf", &x, &y);
ps[i] = Point(x, y);
}
Line l(ps[0], ps[1]);
Line m(ps[1], ps[2]);
Point p = GetCrossPoint(PerpendBisect(l), PerpendBisect(m));
double r = sqrt(dist2(p, ps[0]));
printf("%.3f %.3f %.3f\n", round3(p.X), round3(p.Y), round3(r));
}
}
|
[["-", 8, 9, 0, 37, 0, 16, 31, 2, 63, 40], ["+", 8, 9, 0, 37, 0, 16, 31, 2, 63, 22], ["-", 0, 16, 31, 2, 3, 4, 0, 16, 17, 72], ["-", 0, 16, 31, 2, 3, 4, 0, 16, 12, 13]]
| 1
| 535
|
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
double x1, x2, x3, y1, y2, y3, x12, x13, y12, y13, xx12, yy12, xx13, yy13, x,
y, r;
for (int i = 0; i < n; i++) {
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
x12 = x1 - x2;
x13 = x1 - x3;
y12 = y1 - y2;
y13 = y1 - y3;
xx12 = x1 * x1 - x2 * 2;
xx13 = x1 * x1 - x3 * x3;
yy12 = y1 * y1 - y2 * y2;
yy13 = y1 * y1 - y3 * y3;
x = -0.5 * (y12 * (xx13 + yy13) - y13 * (xx12 + yy12)) /
(x12 * y13 - x13 * y12);
y = -0.5 * (x12 * (xx13 + yy13) - x13 * (xx12 + yy12)) /
(y12 * x13 - y13 * x12);
r = sqrt(x * x + y * y + x1 * x1 + y1 * y1 - 2 * x * x1 - 2 * y * y1);
printf("%.3lf %.3lf %.3lf\n", x, y, r);
}
return 0;
}
|
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
double x1, x2, x3, y1, y2, y3, x12, x13, y12, y13, xx12, yy12, xx13, yy13, x,
y, r;
for (int i = 0; i < n; i++) {
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
x12 = x1 - x2;
x13 = x1 - x3;
y12 = y1 - y2;
y13 = y1 - y3;
xx12 = x1 * x1 - x2 * x2;
xx13 = x1 * x1 - x3 * x3;
yy12 = y1 * y1 - y2 * y2;
yy13 = y1 * y1 - y3 * y3;
x = -0.5 * (y12 * (xx13 + yy13) - y13 * (xx12 + yy12)) /
(x12 * y13 - x13 * y12);
y = -0.5 * (x12 * (xx13 + yy13) - x13 * (xx12 + yy12)) /
(y12 * x13 - y13 * x12);
r = sqrt(x * x + y * y + x1 * x1 + y1 * y1 - 2 * x * x1 - 2 * y * y1);
printf("%.3lf %.3lf %.3lf\n", x, y, r);
}
return 0;
}
|
[["-", 0, 1, 0, 11, 12, 16, 12, 16, 12, 13], ["+", 0, 1, 0, 11, 12, 16, 12, 16, 12, 22]]
| 1
| 266
|
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using LL = long long;
constexpr int MOD = 1000000000 + 7;
//?¶????????????????????????????????????§??????????????????????¢????????????????
constexpr int INF = 2000000000;
const double PI = acos(-1);
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
double x1, y1, x2, y2, x3, y3;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
double a = -x1 + x2, b = -y1 + y2,
c = (-pow(x1, 2) - pow(y1, 2) + pow(x2, 2) + pow(y2, 2)) / 2;
double d = -x1 + x3, e = -y1 + y3,
f = (-pow(x1, 2) - pow(y1, 2) + pow(x3, 2) + pow(y3, 2)) / 2;
double y = (c * d - a * f) / (b * d - a * e);
double x = (f - e * y) / d;
cout << fixed << setprecision(20) << x << " " << y << " "
<< hypot(x1 - x, y1 - y) << endl;
}
}
|
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using LL = long long;
constexpr int MOD = 1000000000 + 7;
//?¶????????????????????????????????????§??????????????????????¢????????????????
constexpr int INF = 2000000000;
const double PI = acos(-1);
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
double x1, y1, x2, y2, x3, y3;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
double a = -x1 + x2, b = -y1 + y2,
c = (-pow(x1, 2) - pow(y1, 2) + pow(x2, 2) + pow(y2, 2)) / 2;
double d = -x1 + x3, e = -y1 + y3,
f = (-pow(x1, 2) - pow(y1, 2) + pow(x3, 2) + pow(y3, 2)) / 2;
double y = (c * d - a * f) / (b * d - a * e);
double x = (f - e * y) / d;
cout << fixed << setprecision(3) << x << " " << y << " "
<< hypot(x1 - x, y1 - y) << endl;
}
}
|
[["-", 31, 16, 31, 16, 12, 2, 3, 4, 0, 13], ["+", 31, 16, 31, 16, 12, 2, 3, 4, 0, 13]]
| 1
| 286
|
#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
int main(void) {
int n;
double x1, x2, x3, y1, y2, y3;
cin >> n;
while (cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3) {
double a = 2 * (x1 - x2);
double b = 2 * (y1 - y2);
double c = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2;
double d = 2 * (x1 - x3);
double e = 2 * (y1 - y3);
double f = x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3;
double p1 = (e * c - b * f) / (e * a - b * d);
double p2 = (d * c - a * f) / (d * b - a * e);
double r = sqrt(pow(x1 - p1, 2) + pow(y1 - p2, 2));
cout << fixed << std::setprecision(10);
cout << p1 << " " << p2 << " " << r << endl;
;
}
return 0;
}
|
#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
int main(void) {
int n;
double x1, x2, x3, y1, y2, y3;
cin >> n;
while (cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3) {
double a = 2 * (x1 - x2);
double b = 2 * (y1 - y2);
double c = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2;
double d = 2 * (x1 - x3);
double e = 2 * (y1 - y3);
double f = x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3;
double p1 = (e * c - b * f) / (e * a - b * d);
double p2 = (d * c - a * f) / (d * b - a * e);
double r = sqrt(pow(x1 - p1, 2) + pow(y1 - p2, 2));
cout << fixed << std::setprecision(3);
cout << p1 << " " << p2 << " " << r << endl;
;
}
return 0;
}
|
[["-", 0, 1, 0, 16, 12, 2, 3, 4, 0, 13], ["+", 0, 1, 0, 16, 12, 2, 3, 4, 0, 13]]
| 1
| 240
|
#include <math.h>
#include <stdio.h>
int main(void) {
int i, n, j, k;
double x1, y1, x2, y2, x3, y3;
scanf("%d", &n);
for (i = 0; i < n; ++i) {
scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3);
double xt1 = (x1 + x2) / 2, xt2 = (x3 + x2) / 2, yt1 = (y1 + y2) / 2,
yt2 = (y3 + y2) / 2;
double t1 = y1 - y2, t2 = y2 - y3;
double x, y, k1, k2;
if (!t1) {
x = xt1;
k2 = (x2 - x3) / (y2 - y3);
y = k2 * (x - xt2) + yt2;
} else if (!t2) {
x = xt2;
k1 = (x1 - x2) / (y1 - y2);
y = k1 * (x - xt1) + yt1;
} else {
k1 = (x1 - x2) / (y1 - y2), k2 = (x2 - x3) / (y2 - y3);
x = ((k1 * xt1 - k2 * xt2) - (yt1 - yt2)) / (k1 - k2);
y = k1 * (x - xt1) + yt1;
}
double r = sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));
// printf("%f %f %f %f \n", xt1, yt1, xt2, yt2);
printf("%.3f %.3f %.3f\n", x, y, r);
}
return 0;
}
|
#include <math.h>
#include <stdio.h>
int main(void) {
int i, n, j, k;
double x1, y1, x2, y2, x3, y3;
scanf("%d", &n);
for (i = 0; i < n; ++i) {
scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3);
double xt1 = (x1 + x2) / 2, xt2 = (x3 + x2) / 2, yt1 = (y1 + y2) / 2,
yt2 = (y3 + y2) / 2;
double t1 = y1 - y2, t2 = y2 - y3;
double x, y, k1, k2;
if (!t1) {
x = xt1;
k2 = -(x2 - x3) / (y2 - y3);
y = k2 * (x - xt2) + yt2;
} else if (!t2) {
x = xt2;
k1 = -(x1 - x2) / (y1 - y2);
y = k1 * (x - xt1) + yt1;
} else {
k1 = -(x1 - x2) / (y1 - y2), k2 = -(x2 - x3) / (y2 - y3);
x = ((k1 * xt1 - k2 * xt2) - (yt1 - yt2)) / (k1 - k2);
y = k1 * (x - xt1) + yt1;
// printf("%f %f ", k1, k2);
}
double r = sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));
// printf("%f %f %f %f\n", xt1, yt1, xt2, yt2);
printf("%.3f %.3f %.3f\n", x, y, r);
}
return 0;
}
|
[["+", 0, 1, 0, 11, 12, 16, 31, 91, 17, 33], ["+", 0, 34, 31, 11, 12, 16, 31, 91, 17, 33], ["+", 0, 34, 12, 11, 12, 16, 31, 91, 17, 33]]
| 1
| 338
|
#include <cmath>
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
int n = 0, p, q, r;
double ax = 0, ay = 0, bx = 0, by = 0, cx = 0, cy = 0, S = 0, R = 0, a = 0,
b = 0, c = 0, x = 0, y = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> ax >> ay >> bx >> by >> cx >> cy;
S = ((bx - ax) * (cy - ay) - (cx - ax) * (by - ay)) / 2;
a = sqrt((cx - bx) * (cx - bx) + (cy - by) * (cy - by));
b = sqrt((cx - ax) * (cx - ax) + (cy - ay) * (cy - ay));
c = sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));
R = a * b * c / (4 * S);
x = (a * a * (b * b + c * c - a * a) * ax +
b * b * (c * c + a * a - b * b) * bx +
c * c * (a * a + b * b - c * c) * cx) /
(16 * S * S);
y = (a * a * (b * b + c * c - a * a) * ay +
b * b * (c * c + a * a - b * b) * by +
c * c * (a * a + b * b - c * c) * cy) /
(16 * S * S);
printf("%.3f %.3f %.3f\n", x, y, R);
}
}
|
#include <cmath>
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
int n = 0, p, q, r;
double ax = 0, ay = 0, bx = 0, by = 0, cx = 0, cy = 0, S = 0, R = 0, a = 0,
b = 0, c = 0, x = 0, y = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> ax >> ay >> bx >> by >> cx >> cy;
S = abs(((bx - ax) * (cy - ay) - (cx - ax) * (by - ay)) / 2);
a = sqrt((cx - bx) * (cx - bx) + (cy - by) * (cy - by));
b = sqrt((cx - ax) * (cx - ax) + (cy - ay) * (cy - ay));
c = sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));
R = a * b * c / (4 * S);
x = (a * a * (b * b + c * c - a * a) * ax +
b * b * (c * c + a * a - b * b) * bx +
c * c * (a * a + b * b - c * c) * cx) /
(16 * S * S);
y = (a * a * (b * b + c * c - a * a) * ay +
b * b * (c * c + a * a - b * b) * by +
c * c * (a * a + b * b - c * c) * cy) /
(16 * S * S);
printf("%.3f %.3f %.3f\n", x, y, R);
}
}
|
[["+", 8, 9, 0, 1, 0, 11, 12, 2, 63, 22], ["+", 31, 23, 0, 16, 31, 16, 31, 23, 0, 24], ["+", 0, 1, 0, 11, 12, 2, 3, 4, 0, 25]]
| 1
| 403
|
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
using namespace std;
typedef complex<double> Point;
bool eqv(double d1, double d2) { return abs(d1 - d2) < 1e-10; }
double r_(double x) {
if (abs(x) < 0.001)
return 0;
return x;
}
int main() {
int N;
cin >> N;
while (N--) {
double x1, x2, x3, y1, y2, y3;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
Point p1(x1, y1), p2(x2, y2), p3(x3, y3);
//³·è
double R = abs(abs(p3 - p2) / sin(arg(p2 - p1) - arg(p3 - p1))) / 2;
Point vb = p3 - p2;
double len = sqrt(R * R - norm(vb) / 4.0);
Point vbh = vb * Point(0, 1);
Point center = p1 + vb / 2.0 + vbh * len / abs(vbh);
if (eqv(abs(center - p1), R) && eqv(abs(center - p2), R) &&
eqv(abs(center - p3), R)) {
} else
center = p1 + vb / 2.0 - vbh * len / abs(vbh);
printf("%.3f %.3f %.3f\n", center.real(), center.imag(), R);
}
return 0;
}
|
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
using namespace std;
typedef complex<double> Point;
bool eqv(double d1, double d2) { return abs(d1 - d2) < 1e-10; }
double r_(double x) {
if (abs(x) < 0.001)
return 0;
return x;
}
int main() {
int N;
cin >> N;
while (N--) {
double x1, x2, x3, y1, y2, y3;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
Point p1(x1, y1), p2(x2, y2), p3(x3, y3);
//³·è
double R = abs(abs(p3 - p2) / sin(arg(p2 - p1) - arg(p3 - p1))) / 2;
Point vb = p3 - p2;
double len = sqrt(R * R - norm(vb) / 4.0);
Point vbh = vb * Point(0, 1);
Point center = p2 + vb / 2.0 + vbh * len / abs(vbh);
if (eqv(abs(center - p1), R) && eqv(abs(center - p2), R) &&
eqv(abs(center - p3), R)) {
} else
center = p2 + vb / 2.0 - vbh * len / abs(vbh);
printf("%.3f %.3f %.3f\n", center.real(), center.imag(), R);
}
return 0;
}
|
[["-", 0, 43, 49, 50, 51, 16, 31, 16, 31, 22], ["+", 0, 43, 49, 50, 51, 16, 31, 16, 31, 22], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 31, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 31, 22]]
| 1
| 302
|
#include <math.h>
#include <stdio.h>
int main() {
int a;
scanf("%d", &a);
while (a--) {
double x1, y1, x2, y2, x3, y3;
scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3);
double a1 = 2 * (x2 - x1);
double b1 = 2 * (y2 - y2);
double c1 = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2;
double a2 = 2 * (x3 - x1);
double b2 = 2 * (y3 - y1);
double c2 = x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3;
double x = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1);
double y = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1);
double r = hypot(x - x1, y - y1);
printf("%.3lf %.3lf %.3lf\n", x, y, r);
}
}
|
#include <math.h>
#include <stdio.h>
int main() {
int a;
scanf("%d", &a);
while (a--) {
double x1, y1, x2, y2, x3, y3;
scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3);
double a1 = 2 * (x2 - x1);
double b1 = 2 * (y2 - y1);
double c1 = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2;
double a2 = 2 * (x3 - x1);
double b2 = 2 * (y3 - y1);
double c2 = x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3;
double x = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1);
double y = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1);
double r = hypot(x - x1, y - y1);
printf("%.3lf %.3lf %.3lf\n", x, y, r);
}
}
|
[["-", 49, 50, 51, 16, 12, 23, 0, 16, 12, 22], ["+", 49, 50, 51, 16, 12, 23, 0, 16, 12, 22]]
| 1
| 224
|
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
int main(void) {
int n, i;
float x1, x2, x3, y1, y2, y3, a1, a2, b1, b2, c1, c2, xp, yp, r;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%f %f %f %f %f %f", &x1, &y1, &x2, &y2, &x3, &y3);
a1 = 2 * (x2 - x1);
b1 = 2 * (y2 - y1);
c1 = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2;
a2 = 2 * (x3 - y1);
b2 = 2 * (y3 - y1);
c2 = x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3;
xp = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1);
yp = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1);
r = sqrt((xp - x1) * (xp - x1) + (yp - y1) * (yp - y1));
printf("%.3f %.3f %.3f\n", xp, yp, r);
}
return 0;
}
|
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
int main(void) {
int n, i, buf;
float x1, x2, x3, y1, y2, y3, a1, a2, b1, b2, c1, c2, xp, yp, r;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%f %f %f %f %f %f", &x1, &y1, &x2, &y2, &x3, &y3);
a1 = 2 * (x2 - x1);
b1 = 2 * (y2 - y1);
c1 = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2;
a2 = 2 * (x3 - x1);
b2 = 2 * (y3 - y1);
c2 = x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3;
xp = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1);
yp = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1);
r = sqrt((xp - x1) * (xp - x1) + (yp - y1) * (yp - y1));
printf("%.3f %.3f %.3f\n", xp, yp, r);
}
return 0;
}
|
[["+", 0, 30, 0, 14, 8, 9, 0, 43, 0, 21], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["-", 0, 11, 12, 16, 12, 23, 0, 16, 12, 22], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 12, 22]]
| 1
| 265
|
#include <algorithm> // require sort next_permutation count __gcd reverse etc.
#include <cctype> // require tolower, toupper
#include <cfloat>
#include <climits>
#include <cmath> // require fabs
#include <cstdio> // require scanf printf
#include <cstdlib> // require abs exit atof atoi
#include <cstring> // require memset
#include <ctime> // require srand
#include <deque>
#include <fstream> // require freopen
#include <functional>
#include <iomanip> // require setw
#include <iostream>
#include <limits>
#include <map>
#include <numeric> // require accumulate
#include <queue>
#include <set>
#include <sstream> // require stringstream
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(A) A.begin(), A.end()
using namespace std;
typedef long long ll;
typedef pair<double, double> P;
typedef pair<double, P> dP;
dP calc_eq(double xa, double ya, double xb, double yb) {
double a = (xb - xa);
double b = (yb - ya);
double c = (xb - xa) * (xb + xa) / 2. + (yb - ya) * (yb + ya) / 2.;
return dP(a, P(b, c));
}
double calc_radius(int xa, int ya, int xb, int yb) {
double res = (xa - xb) * (xa - xb) + (ya - yb) * (ya - yb);
return sqrt(res);
}
int main() {
// cut here before submit
// freopen ("testcase.CCT", "r", stdin );
int n;
cin >> n;
rep(i, n) {
double x1, y1, x2, y2, x3, y3;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
dP l1 = calc_eq(x1, y1, x2, y2);
dP l2 = calc_eq(x1, y1, x3, y3);
double a = l1.first, b = l1.second.first, c = l1.second.second;
double d = l2.first, e = l2.second.first, f = l2.second.second;
/*
cerr << "a: " << a << " b: " << b << " c: " << c << endl;
cerr << "d: " << d << " e: " << e << " f: " << f << endl;
*/
double x = 0.0, y = 0.0, r = 0.0;
x = (c * e - b * f) / (a * e - b * d);
y = (c * d - a * f) / (b * d - a * e);
r = calc_radius(x, y, x1, y1);
if (fabs(x) < 1.0e-3) {
x = 0.0;
} // end if
if (fabs(y) < 1.0e-3) {
y = 0.0;
} // end if
printf("%.3f %.3f %.3f\n", x, y, r);
} // end loop
// printf ("%d\n", res );
return 0;
}
|
#include <algorithm> // require sort next_permutation count __gcd reverse etc.
#include <cctype> // require tolower, toupper
#include <cfloat>
#include <climits>
#include <cmath> // require fabs
#include <cstdio> // require scanf printf
#include <cstdlib> // require abs exit atof atoi
#include <cstring> // require memset
#include <ctime> // require srand
#include <deque>
#include <fstream> // require freopen
#include <functional>
#include <iomanip> // require setw
#include <iostream>
#include <limits>
#include <map>
#include <numeric> // require accumulate
#include <queue>
#include <set>
#include <sstream> // require stringstream
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(A) A.begin(), A.end()
using namespace std;
typedef long long ll;
typedef pair<double, double> P;
typedef pair<double, P> dP;
dP calc_eq(double xa, double ya, double xb, double yb) {
double a = (xb - xa);
double b = (yb - ya);
double c = (xb - xa) * (xb + xa) / 2. + (yb - ya) * (yb + ya) / 2.;
return dP(a, P(b, c));
}
double calc_radius(double xa, double ya, double xb, double yb) {
double res = (xa - xb) * (xa - xb) + (ya - yb) * (ya - yb);
return sqrt(res);
}
int main() {
// cut here before submit
// freopen ("testcase.CCT", "r", stdin );
int n;
cin >> n;
rep(i, n) {
double x1, y1, x2, y2, x3, y3;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
dP l1 = calc_eq(x1, y1, x2, y2);
dP l2 = calc_eq(x1, y1, x3, y3);
double a = l1.first, b = l1.second.first, c = l1.second.second;
double d = l2.first, e = l2.second.first, f = l2.second.second;
/*
cerr << "a: " << a << " b: " << b << " c: " << c << endl;
cerr << "d: " << d << " e: " << e << " f: " << f << endl;
*/
double x = 0.0, y = 0.0, r = 0.0;
x = (c * e - b * f) / (a * e - b * d);
y = (c * d - a * f) / (b * d - a * e);
r = calc_radius(x, y, x1, y1);
if (fabs(x) < 1.0e-3) {
x = 0.0;
} // end if
if (fabs(y) < 1.0e-3) {
y = 0.0;
} // end if
printf("%.3f %.3f %.3f\n", x, y, r);
} // end loop
return 0;
}
|
[["-", 0, 14, 49, 53, 54, 55, 0, 56, 39, 40], ["+", 0, 14, 49, 53, 54, 55, 0, 56, 39, 40]]
| 1
| 473
|
/*
Write a program which prints the central coordinate (px, py) and the radius r of
a circumscribed circle of a triangle which is constructed by three points (x1,
y1)(x2, y2)(x3, y3) on the plane surface.
*/
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
/*
http://zo3kirin3.net/?p=297
http://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q104383420
http://www.nn.iij4u.or.jp/~hsat/misc/math/centre/circumcentre.html
*/
int main() {
int n;
cin >> n;
vector<double> x(3), y(3), x2(3),
y2(3); // x,yªÀWÌXgAx2,y2ªÀWÌñæÌXg
for (int p = 0; p < n; p++) {
cin >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2];
for (int i = 0; i < 3; i++) {
x2[i] = x[i] * x[i];
y2[i] = y[i] * y[i];
}
// eÓÌ·³ðßéBO½ûÌèðp
double a, b, c, a2, b2, c2;
a2 = abs((x[2] - x[1]) * (x[2] - x[1]) + (y[2] - y[1]) * (y[2] - y[1]));
b2 = abs((x[0] - x[2]) * (x[0] - x[2]) + (y[0] - y[2]) * (y[0] - y[2]));
c2 = abs((x[1] - x[0]) * (x[1] - x[0]) + (y[1] - y[0]) * (y[1] - y[0]));
a = sqrt(a2);
b = sqrt(b2);
c = sqrt(c2);
// ÊÏBwÌö®ðpB
double s, S2;
s = (a + b + c) / 2;
S2 = s + (s - a) + (s - b) + (s - c);
// OSðßéBö®ÍWeby[WðQÆ©xNgâÁÄÈ¢©çà¾Å«È¢c
double px, py;
px = (a2 * (b2 + c2 - a2) * x[0] + b2 * (c2 + a2 - b2) * x[1] +
c2 * (a2 + b2 - c2) * x[2]) /
(16 * S2);
py = (a2 * (b2 + c2 - a2) * y[0] + b2 * (c2 + a2 - b2) * y[1] +
c2 * (a2 + b2 - c2) * y[2]) /
(16 * S2);
// oÍB®`µÄoÍ·éB¼aͼüÌûö®ÅB
cout << setprecision(3) << fixed << px << " " << py << " "
<< sqrt(abs((px - x[0]) * (px - x[0]) + (py - y[0]) * (py - y[0])))
<< endl;
}
return 0;
}
|
/*
Write a program which prints the central coordinate (px, py) and the radius r of
a circumscribed circle of a triangle which is constructed by three points (x1,
y1)(x2, y2)(x3, y3) on the plane surface.
*/
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
/*
http://zo3kirin3.net/?p=297
http://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q104383420
http://www.nn.iij4u.or.jp/~hsat/misc/math/centre/circumcentre.html
*/
int main() {
int n;
cin >> n;
vector<double> x(3), y(3), x2(3),
y2(3); // x,yªÀWÌXgAx2,y2ªÀWÌñæÌXg
for (int p = 0; p < n; p++) {
cin >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2];
for (int i = 0; i < 3; i++) {
x2[i] = x[i] * x[i];
y2[i] = y[i] * y[i];
}
// eÓÌ·³ðßéBO½ûÌèðp
double a, b, c, a2, b2, c2;
a2 = abs((x[2] - x[1]) * (x[2] - x[1]) + (y[2] - y[1]) * (y[2] - y[1]));
b2 = abs((x[0] - x[2]) * (x[0] - x[2]) + (y[0] - y[2]) * (y[0] - y[2]));
c2 = abs((x[1] - x[0]) * (x[1] - x[0]) + (y[1] - y[0]) * (y[1] - y[0]));
a = sqrt(a2);
b = sqrt(b2);
c = sqrt(c2);
// ÊÏBwÌö®ðpB
double s, S2;
s = (a + b + c) / 2;
S2 = s * (s - a) * (s - b) * (s - c);
// OSðßéBö®ÍWeby[WðQÆ©xNgâÁÄÈ¢©çà¾Å«È¢c
double px, py;
px = (a2 * (b2 + c2 - a2) * x[0] + b2 * (c2 + a2 - b2) * x[1] +
c2 * (a2 + b2 - c2) * x[2]) /
(16 * S2);
py = (a2 * (b2 + c2 - a2) * y[0] + b2 * (c2 + a2 - b2) * y[1] +
c2 * (a2 + b2 - c2) * y[2]) /
(16 * S2);
// oÍB®`µÄoÍ·éB¼aͼüÌûö®ÅB
cout << setprecision(3) << fixed << px << " " << py << " "
<< sqrt(abs((px - x[0]) * (px - x[0]) + (py - y[0]) * (py - y[0])))
<< endl;
}
return 0;
}
|
[["-", 0, 11, 12, 16, 31, 16, 31, 16, 17, 72], ["+", 0, 11, 12, 16, 31, 16, 31, 16, 17, 48], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 17, 72], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 17, 48], ["-", 8, 9, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 17, 48]]
| 1
| 565
|
#include <math.h>
#include <stdio.h>
void solve(double x1, double x2, double x3, double y1, double y2, double y3) {
double cx1 = (x1 + x2) / 2.0, cx2 = (x2 + x3) / 2.0;
double cy1 = (y1 + y2) / 2.0, cy2 = (y2 + y3) / 2.0;
double tx1 = y2 - y1, tx2 = y3 - y2;
double ty1 = x2 - x1, ty2 = x3 - x2;
double a = ty1, b = -tx1, c = cx1 * ty1 - cy1 * tx1;
double d = ty2, e = -tx2, f = cx2 * ty2 - cy2 * tx2;
double det = a * e - b * d;
double x = (e * c - b * f) / det;
double y = (-d * c + a * f) / det;
double r = sqrt((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y));
printf("%.3f %.3f %.3f\n", x, y, r);
}
int main(void) {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
double x1, x2, x3, y1, y2, y3;
scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3);
solve(x1, x2, x3, y1, y2, y3);
}
return 0;
}
|
#include <math.h>
#include <stdio.h>
void solve(double x1, double x2, double x3, double y1, double y2, double y3) {
double cx1 = (x1 + x2) / 2.0, cx2 = (x2 + x3) / 2.0;
double cy1 = (y1 + y2) / 2.0, cy2 = (y2 + y3) / 2.0;
double tx1 = y1 - y2, tx2 = y2 - y3;
double ty1 = x2 - x1, ty2 = x3 - x2;
double a = ty1, b = -tx1, c = cx1 * ty1 - cy1 * tx1;
double d = ty2, e = -tx2, f = cx2 * ty2 - cy2 * tx2;
double det = a * e - b * d;
double x = (e * c - b * f) / det;
double y = (-d * c + a * f) / det;
double r = sqrt((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y));
printf("%.3f %.3f %.3f\n", x, y, r);
}
int main(void) {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
double x1, x2, x3, y1, y2, y3;
scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3);
solve(x1, x2, x3, y1, y2, y3);
}
return 0;
}
|
[["-", 8, 9, 0, 43, 49, 50, 51, 16, 31, 22], ["-", 8, 9, 0, 43, 49, 50, 51, 16, 17, 33], ["+", 8, 9, 0, 43, 49, 50, 51, 16, 17, 33], ["+", 8, 9, 0, 43, 49, 50, 51, 16, 12, 22]]
| 1
| 313
|
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
struct vect {
double x, y;
};
int main() {
vect a, b, c, p, l1, l2, M1, M2;
double t1, r;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y;
M1.x = (a.x + b.x) / 2;
M1.y = (a.y + b.y) / 2;
M2.x = (b.x + c.x) / 2;
M2.y = (b.y + c.y) / 2;
l1.y = -(b.x - a.x);
l1.x = b.y - a.y;
l2.y = -(c.x - b.x);
l2.x = c.y - b.y;
t1 = 1 / (-l1.x * l2.y + l2.x * l1.y) *
(-l2.y * (M2.x - M1.x) + l2.x * (M2.y - M1.y));
p.x = M1.x + l1.x * t1;
p.y = M1.y + l1.y * t1;
r = sqrt((p.x - a.x) * (p.x - a.x) + (p.y - a.y) * (p.x - a.y));
printf("%.3f %.3f %.3f\n", p.x, p.y, r);
}
}
|
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
struct vect {
double x, y;
};
int main() {
vect a, b, c, p, l1, l2, M1, M2;
double t1, r;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y;
M1.x = (a.x + b.x) / 2;
M1.y = (a.y + b.y) / 2;
M2.x = (b.x + c.x) / 2;
M2.y = (b.y + c.y) / 2;
l1.y = -(b.x - a.x);
l1.x = b.y - a.y;
l2.y = -(c.x - b.x);
l2.x = c.y - b.y;
t1 = 1 / (-l1.x * l2.y + l2.x * l1.y) *
(-l2.y * (M2.x - M1.x) + l2.x * (M2.y - M1.y));
p.x = M1.x + l1.x * t1;
p.y = M1.y + l1.y * t1;
r = sqrt((p.x - a.x) * (p.x - a.x) + (p.y - a.y) * (p.y - a.y));
printf("%.3f %.3f %.3f\n", p.x, p.y, r);
}
}
|
[["-", 12, 16, 12, 23, 0, 16, 31, 118, 119, 120], ["+", 12, 16, 12, 23, 0, 16, 31, 118, 119, 120]]
| 1
| 360
|
#include <cstdio>
#include <iostream>
#define _USE_MATH_DEFINES
#include <cmath>
#include <map>
#include <vector>
using namespace std;
#define INF 1e+10
#define EPS 1e-10
#define EQ(a, b) (abs(a - b) < EPS)
//誤差を考慮して足し算
double add(double a, double b) {
if (abs(a + b) < EPS * (abs(a) + abs(b)))
return 0;
return a + b;
}
struct P { // 2次元ベクトル
double x, y;
P() {}
P(double x, double y) : x(x), y(y) {}
P operator+(P p) { return P(add(x, p.x), add(y, p.y)); }
P operator-(P p) { return P(add(x, -p.x), add(y, -p.y)); }
P operator*(double d) { return P(x * d, y * d); }
P operator/(double d) { return P(x / d, y / d); }
double dot(P p) { //内積
return add(x * p.x, y * p.y);
}
double det(P p) { //外積
return add(x * p.y, -y * p.x);
}
bool equal(P p) {
return (x - p.x) * (x - p.x) + (y - p.y) * (y - p.y) < EPS * EPS;
}
};
// typedef pair<P,P> Line;
//線分p1-p2上に点qがあるか判定
bool on_seg(P p1, P p2, P q) {
return (p1 - q).det(p2 - q) == 0 && (p1 - q).dot(p2 - q) <= 0;
}
//直線p1-p2と直線q1-q2の交点
P intersection(P p1, P p2, P q1, P q2) {
return p1 + (p2 - p1) * ((q2 - q1).det(q1 - p1) / (q2 - q1).det(p2 - p1));
}
//線分p1-p2と線分q1-q2が交差するか
bool intersecting(P p1, P p2, P q1, P q2) {
if (on_seg(p1, p2, q1) || on_seg(p1, p2, q2) || on_seg(q1, q2, p1) ||
on_seg(q1, q2, p2))
return true;
if ((p1 - p2).det(q1 - q2) == 0)
return false; //平行
P a = intersection(p1, p2, q1, q2);
return on_seg(p1, p2, a) && on_seg(q1, q2, a);
}
//原点中心回転
P rotate(P p, double rad) {
double s = sin(rad), c = cos(rad);
return P(c * p.x - s * p.y, s * p.x + c * p.y);
}
// originを中心回転
P rotate(P p, double rad, P origin) { return origin + rotate(p - origin, rad); }
//二点間の距離
double dist(P p, P q) {
p = p - q;
return sqrt(p.x * p.x + p.y * p.y);
}
//単位ベクトルに変換
P to_unit(P p) {
double d = sqrt(p.x * p.x + p.y * p.y);
return p / d;
}
//円同士の交点を計算
pair<P, P> circle_intersection(double x1, double y1, double r1, double x2,
double y2, double r2) {
double rad = atan2(y2 - y1, x2 - x1);
x2 -= x1;
y2 -= y1;
P tmp = rotate(P(x2, y2), -rad);
x2 = tmp.x;
y2 = tmp.y;
double x = (r1 * r1 - r2 * r2 + x2 * x2) / (2 * x2);
if (abs(r1) < abs(x))
return make_pair(P(0, 0), P(0, 0)); //交点なし
double y = sqrt(r1 * r1 - x * x);
return make_pair(P(x1, y1) + rotate(P(x, y), rad),
P(x1, y1) + rotate(P(x, -y), rad));
}
//線分と点の距離
double dist_lp(P p1, P p2, P q) {
double dx, dy;
dx = p1.x - p2.x;
dy = p1.y - p2.y;
double d = min(dist(p1, q), dist(p2, q));
pair<P, P> normal = make_pair(q + to_unit(P(-dy, dx)) * d,
q + to_unit(P(dy, -dx)) * d); //法線ベクトル
if (intersecting(p1, p2, normal.first, normal.second)) {
return dist(q, intersection(p1, p2, normal.first, normal.second));
}
return d;
}
//線分同士の距離
double dist_ll(P p1, P p2, P q1, P q2) {
if (intersecting(p1, p2, q1, q2))
return 0;
return min(min(dist_lp(p1, p2, q1), dist_lp(p1, p2, q2)),
min(dist_lp(q1, q2, p1), dist_lp(q1, q2, p2)));
}
//ラジアンに変換
double radian(double angle) { return angle / 180.0 * M_PI; }
int main() {
P a, b, c, g;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a.x >> a.y;
cin >> b.x >> b.y;
cin >> c.x >> c.y;
g = intersection((a + b) / 2, (a + b) / 2 + P(-(a.x - b.y), a.x - b.x),
(a + c) / 2, (a + c) / 2 + P(-(a.x - c.y), a.x - c.x));
printf("%.3f %.3f %.3f\n", g.x, g.y, dist(g, a));
}
return 0;
}
|
#include <cstdio>
#include <iostream>
#define _USE_MATH_DEFINES
#include <cmath>
#include <map>
#include <vector>
using namespace std;
#define INF 1e+10
#define EPS 1e-10
#define EQ(a, b) (abs(a - b) < EPS)
//誤差を考慮して足し算
double add(double a, double b) {
if (abs(a + b) < EPS * (abs(a) + abs(b)))
return 0;
return a + b;
}
struct P { // 2次元ベクトル
double x, y;
P() {}
P(double x, double y) : x(x), y(y) {}
P operator+(P p) { return P(add(x, p.x), add(y, p.y)); }
P operator-(P p) { return P(add(x, -p.x), add(y, -p.y)); }
P operator*(double d) { return P(x * d, y * d); }
P operator/(double d) { return P(x / d, y / d); }
double dot(P p) { //内積
return add(x * p.x, y * p.y);
}
double det(P p) { //外積
return add(x * p.y, -y * p.x);
}
bool equal(P p) {
return (x - p.x) * (x - p.x) + (y - p.y) * (y - p.y) < EPS * EPS;
}
};
// typedef pair<P,P> Line;
//線分p1-p2上に点qがあるか判定
bool on_seg(P p1, P p2, P q) {
return (p1 - q).det(p2 - q) == 0 && (p1 - q).dot(p2 - q) <= 0;
}
//直線p1-p2と直線q1-q2の交点
P intersection(P p1, P p2, P q1, P q2) {
return p1 + (p2 - p1) * ((q2 - q1).det(q1 - p1) / (q2 - q1).det(p2 - p1));
}
//線分p1-p2と線分q1-q2が交差するか
bool intersecting(P p1, P p2, P q1, P q2) {
if (on_seg(p1, p2, q1) || on_seg(p1, p2, q2) || on_seg(q1, q2, p1) ||
on_seg(q1, q2, p2))
return true;
if ((p1 - p2).det(q1 - q2) == 0)
return false; //平行
P a = intersection(p1, p2, q1, q2);
return on_seg(p1, p2, a) && on_seg(q1, q2, a);
}
//原点中心回転
P rotate(P p, double rad) {
double s = sin(rad), c = cos(rad);
return P(c * p.x - s * p.y, s * p.x + c * p.y);
}
// originを中心回転
P rotate(P p, double rad, P origin) { return origin + rotate(p - origin, rad); }
//二点間の距離
double dist(P p, P q) {
p = p - q;
return sqrt(p.x * p.x + p.y * p.y);
}
//単位ベクトルに変換
P to_unit(P p) {
double d = sqrt(p.x * p.x + p.y * p.y);
return p / d;
}
//円同士の交点を計算
pair<P, P> circle_intersection(double x1, double y1, double r1, double x2,
double y2, double r2) {
double rad = atan2(y2 - y1, x2 - x1);
x2 -= x1;
y2 -= y1;
P tmp = rotate(P(x2, y2), -rad);
x2 = tmp.x;
y2 = tmp.y;
double x = (r1 * r1 - r2 * r2 + x2 * x2) / (2 * x2);
if (abs(r1) < abs(x))
return make_pair(P(0, 0), P(0, 0)); //交点なし
double y = sqrt(r1 * r1 - x * x);
return make_pair(P(x1, y1) + rotate(P(x, y), rad),
P(x1, y1) + rotate(P(x, -y), rad));
}
//線分と点の距離
double dist_lp(P p1, P p2, P q) {
double dx, dy;
dx = p1.x - p2.x;
dy = p1.y - p2.y;
double d = min(dist(p1, q), dist(p2, q));
pair<P, P> normal = make_pair(q + to_unit(P(-dy, dx)) * d,
q + to_unit(P(dy, -dx)) * d); //法線ベクトル
if (intersecting(p1, p2, normal.first, normal.second)) {
return dist(q, intersection(p1, p2, normal.first, normal.second));
}
return d;
}
//線分同士の距離
double dist_ll(P p1, P p2, P q1, P q2) {
if (intersecting(p1, p2, q1, q2))
return 0;
return min(min(dist_lp(p1, p2, q1), dist_lp(p1, p2, q2)),
min(dist_lp(q1, q2, p1), dist_lp(q1, q2, p2)));
}
//ラジアンに変換
double radian(double angle) { return angle / 180.0 * M_PI; }
int main() {
P a, b, c, g;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a.x >> a.y;
cin >> b.x >> b.y;
cin >> c.x >> c.y;
g = intersection((a + b) / 2, (a + b) / 2 + P(-(a.y - b.y), a.x - b.x),
(a + c) / 2, (a + c) / 2 + P(-(a.y - c.y), a.x - c.x));
printf("%.3f %.3f %.3f\n", g.x, g.y, dist(g, a));
}
return 0;
}
|
[["-", 0, 91, 28, 23, 0, 16, 31, 118, 119, 120], ["+", 0, 91, 28, 23, 0, 16, 31, 118, 119, 120]]
| 1
| 1,288
|
#include <cmath>
#include <iostream>
using namespace std;
int main() {
int n;
double x1, y1, x2, y2, x3, y3;
double a1, b1, c1, a2, b2, c2;
double x, y, r;
cin >> n;
while (n--) {
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
a1 = x2 - x1;
b1 = y2 - x1;
c1 = -a1 * (x1 + x2) * 0.5 - b1 * (y1 + y2) * 0.5;
a2 = x3 - x2;
b2 = y3 - y2;
c2 = -a2 * (x2 + x3) * 0.5 - b2 * (y2 + y3) * 0.5;
y = (a2 * c1 - a1 * c2) / (a1 * b2 - a2 * b1);
if (a1) {
x = -(b1 * y + c1) / a1;
} else {
x = -(b2 * y + c2) / a2;
}
r = sqrt((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y));
cout.setf(ios::fixed);
cout.precision(3);
cout << x << " " << y << " " << r << endl;
}
}
|
#include <cmath>
#include <iostream>
using namespace std;
int main() {
int n;
double x1, y1, x2, y2, x3, y3;
double a1, b1, c1, a2, b2, c2;
double x, y, r;
cin >> n;
while (n--) {
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
a1 = x2 - x1;
b1 = y2 - y1;
c1 = -a1 * (x1 + x2) * 0.5 - b1 * (y1 + y2) * 0.5;
a2 = x3 - x2;
b2 = y3 - y2;
c2 = -a2 * (x2 + x3) * 0.5 - b2 * (y2 + y3) * 0.5;
y = (a2 * c1 - a1 * c2) / (a1 * b2 - a2 * b1);
if (a1) {
x = -(b1 * y + c1) / a1;
} else {
x = -(b2 * y + c2) / a2;
}
r = sqrt((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y));
cout.setf(ios::fixed);
cout.precision(3);
cout << x << " " << y << " " << r << endl;
}
}
|
[["-", 8, 9, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 12, 22]]
| 1
| 265
|
#include <cmath>
#include <iomanip>
#include <iostream>
#define PI 3.1415
using namespace std;
int main() {
int n;
double x1, y1, x2, y2, x3, y3;
double la, lb, lc;
double a, b, c;
double r;
double px, py;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
// lc = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
la = (x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3);
// lb = (x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1);
a = fabs((atan2(y2 - y1, x2 - x1) - atan2(y3 - y1, x3 - x1)));
b = fabs((atan2(y1 - y2, x1 - x2) - atan2(y3 - y2, x3 - x2)));
c = fabs((atan2(y1 - y3, x1 - x3) - atan2(y2 - y3, x2 - x3)));
if (a >= PI)
a = 2 * PI - a;
if (b >= PI)
b = 2 * PI - b;
if (c >= PI)
c = 2 * PI - c;
r = sqrt(la) / (sin(a) * 2);
px = (sin(2 * a) * x1 + sin(2 * b) * x2 + sin(2 * c) * x3) /
(sin(2 * a) + sin(2 * b) + sin(2 * c));
py = (sin(2 * a) * y1 + sin(2 * b) * y2 + sin(2 * c) * y3) /
(sin(2 * a) + sin(2 * b) + sin(2 * c));
r = floor(r * 1000 + 0.5) / 1000;
px = floor(px * 1000 + 0.5) / 1000;
py = floor(py * 1000 + 0.5) / 1000;
cout << setprecision(3) << fixed << px << " " << py << " " << r << endl;
}
return 0;
}
|
#include <cmath>
#include <iomanip>
#include <iostream>
#define PI 3.14159265359
using namespace std;
int main() {
int n;
double x1, y1, x2, y2, x3, y3;
double la, lb, lc;
double a, b, c;
double r;
double px, py;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
// lc = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
la = (x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3);
// lb = (x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1);
a = fabs((atan2(y2 - y1, x2 - x1) - atan2(y3 - y1, x3 - x1)));
b = fabs((atan2(y1 - y2, x1 - x2) - atan2(y3 - y2, x3 - x2)));
c = fabs((atan2(y1 - y3, x1 - x3) - atan2(y2 - y3, x2 - x3)));
if (a >= PI)
a = 2 * PI - a;
if (b >= PI)
b = 2 * PI - b;
if (c >= PI)
c = 2 * PI - c;
r = sqrt(la) / (sin(a) * 2);
px = (sin(2 * a) * x1 + sin(2 * b) * x2 + sin(2 * c) * x3) /
(sin(2 * a) + sin(2 * b) + sin(2 * c));
py = (sin(2 * a) * y1 + sin(2 * b) * y2 + sin(2 * c) * y3) /
(sin(2 * a) + sin(2 * b) + sin(2 * c));
r = floor(r * 1000 + 0.5) / 1000;
px = floor(px * 1000 + 0.5) / 1000;
py = floor(py * 1000 + 0.5) / 1000;
cout << setprecision(3) << fixed << px << " " << py << " " << r << endl;
}
return 0;
}
|
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59]]
| 1
| 439
|
#include <cstdio>
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
double x1, y1, x2, y2, x3, y3, xp, yp, r;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
xp = 0;
yp = 0;
double a = y2 - y1, b = y3 - y1, c = y2 - y3, d = x2 - x1, e = x3 - x1;
if (y1 != y2 && y1 != y3) {
xp = (c / 2 - e * (x1 + x3) / 2 / b - d * (x2 + x1) / 2 / a) /
(-e / b + d / a);
yp = -e / b * (xp - (x1 + x3) / 2) + (y1 + y3) / 2;
} else if (y1 == y2) {
xp = (x1 + x2) / 2;
yp = -e / b * (xp - (x1 + x3) / 2) + (y1 + y3) / 2;
} else if (y1 == y3) {
xp = (x1 + x3) / 2;
yp = -d / a * (xp - (x1 + x2) / 2) + (y1 + y2) / 2;
}
r = sqrt((x1 - xp) * (x1 - xp) + (y1 - yp) * (y1 - yp));
xp *= 1000;
if (xp > 0)
xp += 0.5;
else
xp -= 0.5;
int xp2 = xp;
yp *= 1000;
if (yp > 0)
yp += 0.5;
else
yp -= 0.5;
int yp2 = yp;
printf("%.3lf %.3lf %.3lf\n", xp2 / (double)1000, yp2 / (double)1000, r);
}
return 0;
}
|
#include <cstdio>
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
double x1, y1, x2, y2, x3, y3, xp, yp, r;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
xp = 0;
yp = 0;
double a = y2 - y1, b = y3 - y1, c = y2 - y3, d = x2 - x1, e = x3 - x1;
if (y1 != y2 && y1 != y3) {
xp = (c / 2 - e * (x1 + x3) / 2 / b + d * (x2 + x1) / 2 / a) /
(-e / b + d / a);
yp = -e / b * (xp - (x1 + x3) / 2) + (y1 + y3) / 2;
} else if (y1 == y2) {
xp = (x1 + x2) / 2;
yp = -e / b * (xp - (x1 + x3) / 2) + (y1 + y3) / 2;
} else if (y1 == y3) {
xp = (x1 + x3) / 2;
yp = -d / a * (xp - (x1 + x2) / 2) + (y1 + y2) / 2;
}
r = sqrt((x1 - xp) * (x1 - xp) + (y1 - yp) * (y1 - yp));
xp *= 1000;
if (xp > 0)
xp += 0.5;
else
xp -= 0.5;
int xp2 = xp;
yp *= 1000;
if (yp > 0)
yp += 0.5;
else
yp -= 0.5;
int yp2 = yp;
printf("%.3lf %.3lf %.3lf\n", xp2 / (double)1000, yp2 / (double)1000, r);
}
return 0;
}
|
[["-", 0, 11, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 72]]
| 1
| 391
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.