标签:graph 顺序 rip desc lan 分组 sub friends fill
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 445 | Accepted: 162 |
Description
Input
Output
Sample Input
3 1 1 2 2 16 1 3 4 33
Sample Output
10 30 50
Source
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <cmath> 6 7 inline void read(long long &x) 8 { 9 x = 0;char ch = getchar(),c = ch; 10 while(ch < ‘0‘ || ch > ‘9‘)c = ch, ch = getchar(); 11 while(ch <= ‘9‘ && ch >= ‘0‘)x = x * 10 + ch - ‘0‘, ch = getchar(); 12 if(c == ‘-‘)x = -x; 13 } 14 15 16 const long long INF = 0x3f3f3f3f; 17 18 long long t, N, S, D, pow4[40], pow2[40]; 19 20 struct Node 21 { 22 long long x, y; 23 Node(long long _x, long long _y){x = _x,y = _y;} 24 Node(){} 25 }; 26 27 //求解编号为m的房子,在逆时针旋转p度后的n级城市中的坐标 28 //p只能取值0,90,270 29 //90,270编号反转,0不变 30 31 Node cal(long long n, long long p, long long m) 32 { 33 if(n == 1) 34 { 35 if(p == 0) 36 { 37 if(m == 1)return Node(0,0); 38 else if(m == 2) return Node(0,1); 39 else if(m == 3) return Node(1,1); 40 else return Node(1,0); 41 } 42 else if(p == 90) 43 { 44 if(m == 3)return Node(0,0); 45 else if(m == 2) return Node(0,1); 46 else if(m == 1) return Node(1,1); 47 else return Node(1,0); 48 } 49 else if(p == 270) 50 { 51 if(m == 1)return Node(0,0); 52 else if(m == 4) return Node(0,1); 53 else if(m == 3) return Node(1,1); 54 else return Node(1,0); 55 } 56 else if(p == 180) 57 { 58 if(m == 3)return Node(0,0); 59 else if(m == 4) return Node(0,1); 60 else if(m == 1) return Node(1,1); 61 else return Node(1,0); 62 } 63 } 64 Node tmp; 65 long long a = pow4[n - 1]; 66 long long r = (m - 1) / a + 1; 67 if(p == 0) 68 { 69 if(r == 1) tmp = cal(n - 1, 270, m); 70 else if(r == 2) tmp = cal(n - 1, 0, m - a), tmp.y += pow2[n - 1]; 71 else if(r == 3) tmp = cal(n - 1, 0, m - 2 * a), tmp.x += pow2[n - 1], tmp.y += pow2[n - 1]; 72 else tmp = cal(n - 1, 90, m - a * 3), tmp.x += pow2[n - 1]; 73 } 74 else if(p == 90) 75 { 76 if(r == 1) tmp = cal(n - 1, 180, m), tmp.x += pow2[n - 1], tmp.y += pow2[n - 1]; 77 else if(r == 2) tmp = cal(n - 1, 90, m - a), tmp.y += pow2[n - 1]; 78 else if(r == 3) tmp = cal(n - 1, 90, m - a * 2); 79 else tmp = cal(n - 1, 0, m - a * 3), tmp.x += pow2[n - 1]; 80 } 81 else if(p == 270) 82 { 83 if(r == 1) tmp = cal(n - 1, 0, m); 84 else if(r == 2) tmp = cal(n - 1, 270, m - a), tmp.x += pow2[n - 1]; 85 else if(r == 3) tmp = cal(n - 1, 270, m - 2 * a), tmp.x += pow2[n - 1], tmp.y += pow2[n - 1]; 86 else tmp = cal(n - 1, 180, m - 3 * a), tmp.y += pow2[n - 1]; 87 } 88 else if(p == 180) 89 { 90 if(r == 1) tmp = cal(n - 1, 90, m), tmp.x += pow2[n - 1], tmp.y += pow2[n - 1]; 91 else if(r == 2) tmp = cal(n - 1, 180, m - a), tmp.x += pow2[n - 1]; 92 else if(r == 3) tmp = cal(n - 1, 180, m - a * 2); 93 else tmp = cal(n - 1, 270, m - a * 3), tmp.y += pow2[n - 1]; 94 } 95 return tmp; 96 } 97 98 int main() 99 { 100 //freopen("data.txt", "r" ,stdin); 101 read(t); 102 pow4[0] = 1, pow2[0] = 1; 103 for(register int i = 1;i <= 33;++ i) pow4[i] = (pow4[i - 1] << 2), pow2[i] = (pow2[i - 1] << 1); 104 Node tmp1, tmp2; 105 for(;t;-- t) 106 { 107 read(N),read(S),read(D); 108 tmp1 = cal(N, 0, S); 109 tmp2 = cal(N, 0, D); 110 double len = sqrt((long long)abs(tmp1.x - tmp2.x) * abs(tmp1.x - tmp2.x) + (long long)abs(tmp1.y - tmp2.y) * abs(tmp1.y - tmp2.y)) * 10; 111 printf("%lld\n", (long long)(len + 0.5)); 112 } 113 return 0; 114 }
标签:graph 顺序 rip desc lan 分组 sub friends fill
原文地址:http://www.cnblogs.com/huibixiaoxing/p/7289242.html