Created
April 16, 2011 03:43
-
-
Save cocoatomo/922848 to your computer and use it in GitHub Desktop.
Python は通ったが, C と Java が通らない.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() | |
{ | |
char buf[64]; | |
int N; | |
int i; | |
int x, y; | |
long sum_x=0, sum_y=0, sum_x2=0, sum_y2=0; | |
int n; | |
fgets(buf, sizeof(buf), stdin); | |
sscanf(buf, "%d\n", &N); | |
for (i = 0; i < N; i++) { | |
fgets(buf, sizeof(buf), stdin); | |
n = sscanf(buf, "%d %d\n", &x, &y); | |
sum_x += x; | |
sum_x2 += x*x; | |
sum_y += y; | |
sum_y2 += y*y; | |
} | |
printf("%ld\n", N * sum_x2 - sum_x * sum_x + N * sum_y2 - sum_y * sum_y); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
N = int(raw_input()) | |
sum_x = 0 | |
sum_x2 = 0 | |
sum_y = 0 | |
sum_y2 = 0 | |
for i in range(N): | |
x, y = (raw_input().split()) | |
x = int(x) | |
y = int(y) | |
sum_x += x | |
sum_x2 += x**2 | |
sum_y += y | |
sum_y2 += y**2 | |
print(N * sum_x2 - sum_x**2 + N * sum_y2 - sum_y**2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.math.BigInteger; | |
public class Prob76E { | |
public static void main(String[] args) throws IOException { | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
int N = Integer.parseInt(br.readLine()); | |
BigInteger sum_x = BigInteger.ZERO; | |
BigInteger sum_y = BigInteger.ZERO; | |
BigInteger sum_x2 = BigInteger.ZERO; | |
BigInteger sum_y2 = BigInteger.ZERO; | |
for (int i = 0; i < N; i++) { | |
String line = br.readLine(); | |
String[] nums = line.split(" +"); | |
BigInteger x = new BigInteger(nums[0]); | |
BigInteger y = new BigInteger(nums[1]); | |
sum_x = sum_x.add(x); | |
sum_y = sum_y.add(y); | |
sum_x2 = sum_x2.add(x.pow(2)); | |
sum_y2 = sum_y2.add(y.pow(2)); | |
System.out.println(sum_x + " " + sum_y + " " + sum_x2 + " " + sum_y2 + " "); | |
} | |
System.out.println(sum_x2.multiply(BigInteger.valueOf(N)) | |
.subtract(sum_x.pow(2)) | |
.add(sum_y2.multiply(BigInteger.valueOf(N))) | |
.subtract(sum_y.pow(2))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment