CodeForces 407A 手速题

//CodeForces 407A

 1 #include "iostream"
 2 #include "cstdio"
 3 #include "cstring"
 4 #include "algorithm"
 5 using namespace std;
 6 int square[1010];
 7 struct p
 8 {
 9     int x, y;
10 }A[1010], B[1010];
11 int tot_a, tot_b;
12 int a, b;
13 
14 int main()
15 {
16     int i, j;
17     for(i = 1; i <= 1000; ++i)
18         square[i] = i * i;
19     scanf("%d%d", &a, &b);
20     a *= a;
21     b *= b;
22     tot_a = tot_b = 0;
23     for(i = 1; i <= 1000; ++i) {
24         for(j = 1; j <= i; ++j) {
25             if(square[i] + square[j] == a) {
26                 A[++tot_a].x = i;
27                 A[tot_a].y = j;
28                 A[++tot_a].x = -i;
29                 A[tot_a].y = j;
30                 if(i != j) {
31                     A[++tot_a].x = j;
32                     A[tot_a].y = i;
33                     A[++tot_a].x = -j;
34                     A[tot_a].y = i;
35                 }
36             }
37             if(square[i] + square[j] == b) {
38                 B[++tot_b].x = i;
39                 B[tot_b].y = j;
40                 B[++tot_b].x = -i;
41                 B[tot_b].y = j;
42                 if(i != j) {
43                     B[++tot_b].x = j;
44                     B[tot_b].y = i;
45                     B[++tot_b].x = -j;
46                     B[tot_b].y = i;
47                 }
48             }
49 
50 
51         }
52     }
53     int cx, cy;
54     bool done = 0;
55     for(i = 1; i <= tot_a; ++i) {
56         for(j = 1; j <= tot_b; ++j) {
57             cx = A[i].x - B[j].x;
58             cy = A[i].y - B[j].y;
59             cx *= cx;
60             cy *= cy;
61             if((cx + cy == a + b || cx + cy + a == b || cx + cy + b == a) && A[i].x != B[j].x && A[i].y != B[j].y) {
62                 done = 1;
63                 break;
64             }
65         }
66         if(done)
67             break;
68     }
69     if(done) {
70         printf("YES\n0 0\n%d %d\n%d %d\n", A[i].x, A[i]. y, B[j].x, B[j].y);
71     }
72     else {
73         printf("NO\n");
74     }
75 }

 

posted @ 2015-02-24 23:59  AC_Phoenix  阅读(143)  评论(0编辑  收藏  举报