F. The Answer to the Ultimate Question of Life, The Universe, and Everything.
我的第一道真·打表题
这次是真的打表啊,不是初始化求值!
重现赛的时候,一直在搞在线的做法,map和unordered_map都上了,都是TLE,初始化建立两个map,然后枚举a,b再找是否有c,我算的复杂度也就 O(T*5000*10000/2)? 2e8?好像确实得T。实际复杂度或许更高 ?
unordered_map内部哈希表实现,应该可以O(1)查找呀我感觉。stl的好用归好用,复杂度还是不太清楚。
打表的方法也是刚学的,对每个x,枚举a,b,二分找c 。 反正最好就是按一定格式打表出来,直接复制存到一个数组交上去就行了。
枚举的时候注意,三个数中至少有一个非负数,a可以在0~5000,应该能少一半的时间,也许?反正能优化就上吧。
打表的适用范围:对每个输入的数据,答案固定可知,且输入的数据范围较小。数据范围较小是重点,这里要整个更大的数x,一场比赛都打不完表。
1 #include2 #define debug(x) cout << #x << ": " << x << endl 3 using namespace std; 4 typedef long long ll; 5 const int MAXN=2e5+7; 6 const int INF=0x3f3f3f3f; 7 const int MOD=1e9+7; 8 9 10 int ans[][3]= 11 { 12 -5000,0,5000, 13 -5000,1,5000, 14 -4373,-486,4375, 15 -5,4,4, 16 11111,0,0, 17 11111,0,0, 18 -637,-205,644, 19 -169,44,168, 20 -5000,2,5000, 21 -216,-52,217, 22 -650,-353,683, 23 -695,-641,843, 24 -11,7,10, 25 11111,0,0, 26 11111,0,0, 27 -265,-262,332, 28 -4114,-588,4118, 29 -3331,2195,2977, 30 -1373,-1276,1671, 31 -95,47,91, 32 -2816,-741,2833, 33 -401,-287,445, 34 11111,0,0, 35 11111,0,0, 36 -10,8,8, 37 -2683,1839,2357, 38 -2107,237,2106, 39 -5000,3,5000, 40 -2268,-249,2269, 41 -233,-69,235, 42 11111,0,0, 43 11111,0,0, 44 11111,0,0, 45 11111,0,0, 46 -1555,-244,1557, 47 -1120,-509,1154, 48 -3223,2358,2731, 49 -444,-84,445, 50 -27,16,25, 51 11111,0,0, 52 11111,0,0, 53 11111,0,0, 54 11111,0,0, 55 -823,-307,837, 56 -7,-5,8, 57 -2369,1709,2025, 58 -758,-473,815, 59 -141,49,139, 60 -3950,-1247,3991, 61 11111,0,0, 62 11111,0,0, 63 -796,602,659, 64 11111,0,0, 65 -2370,1518,2141, 66 -3885,-648,3891, 67 -3329,1837,3131, 68 -672,505,559, 69 -998,361,982, 70 11111,0,0, 71 11111,0,0, 72 -1201,-163,1202, 73 -966,668,845, 74 -2744,-1561,2903, 75 -161,102,146, 76 -5000,4,5000, 77 -929,403,903, 78 1,1,4, 79 11111,0,0, 80 11111,0,0, 81 -403,134,398, 82 -2359,824,2325, 83 -533,401,443, 84 -432,-104,434, 85 -335,-146,344, 86 11111,0,0, 87 11111,0,0, 88 11111,0,0, 89 11111,0,0, 90 -2080,-829,2123, 91 -706,-196,711, 92 -1300,-706,1366, 93 -2368,-1719,2638, 94 -1317,847,1188, 95 -3707,1315,3651, 96 11111,0,0, 97 11111,0,0, 98 11111,0,0, 99 -4126,-1972,4271, 100 -1390,-1282,1686, 101 -2514,1953,2036, 102 -1803,365,1798, 103 -3389,-2912,3992, 104 -4052,861,4039, 105 -248,-98,253, 106 11111,0,0, 107 11111,0,0, 108 -22,14,20, 109 -3168,-991,3200, 110 -2101,-1638,2391, 111 -893,-622,984, 112 -1797,-903,1870, 113 -2327,319,2325, 114 -239,118,229, 115 11111,0,0, 116 11111,0,0, 117 -7,-4,8, 118 -2689,-1165,2760, 119 -1309,947,1117, 120 -1165,-948,1345, 121 -2948,853,2924, 122 11111,0,0, 123 -4793,-2312,4966, 124 11111,0,0, 125 11111,0,0, 126 11111,0,0, 127 -12,8,11, 128 -1906,-757,1945, 129 -896,-555,962, 130 -4328,383,4327, 131 -3677,-1673,3789, 132 -2804,1219,2725, 133 11111,0,0, 134 11111,0,0, 135 -37,-16,38, 136 -1,0,5, 137 -5000,5,5000, 138 -2212,-419,2217, 139 -4034,-3881,4988, 140 -3989,-726,3997, 141 -1580,-1238,1801, 142 11111,0,0, 143 11111,0,0, 144 -1,2,5, 145 -399,167,389, 146 -3013,-1766,3203, 147 -1351,-629,1395, 148 -1116,816,946, 149 -758,-428,801, 150 -86,-77,103, 151 11111,0,0, 152 11111,0,0, 153 -139,104,116, 154 -7,-3,8, 155 11111,0,0, 156 -2746,-2552,3342, 157 -8,-7,10, 158 -327,-263,376, 159 -2366,1528,2131, 160 11111,0,0, 161 11111,0,0, 162 -367,260,317, 163 -463,215,447, 164 -805,486,741, 165 -3736,-695,3744, 166 -2135,-516,2145, 167 -3693,-1049,3721, 168 11111,0,0, 169 11111,0,0, 170 11111,0,0, 171 -1534,383,1526, 172 -3874,-1654,3972, 173 -4767,-2476,4980, 174 -4125,-1417,4180, 175 -3423,-2943,4033, 176 -66,-59,79, 177 11111,0,0, 178 11111,0,0, 179 11111,0,0, 180 -802,-574,890, 181 -1354,-1012,1521, 182 -3834,-2149,4047, 183 -1328,891,1178, 184 11111,0,0, 185 11111,0,0, 186 -335,-170,349, 187 11111,0,0, 188 11111,0,0, 189 -1168,-160,1169, 190 -13,-10,15, 191 -2839,1503,2691, 192 11111,0,0, 193 -4874,974,4861, 194 -90,-29,91, 195 -4889,976,4876, 196 11111,0,0, 197 11111,0,0, 198 -4,5,5, 199 -1885,-1092,2000, 200 -1639,318,1635, 201 -1702,-1403,1974, 202 -4812,-593,4815, 203 -377,-215,399, 204 -20,16,16, 205 11111,0,0, 206 11111,0,0, 207 11111,0,0, 208 -1057,-579,1112, 209 -2867,-1606,3026, 210 -3752,-1347,3809, 211 -2208,508,2199, 212 -2318,-638,2334, 213 }; 214 215 ll qq[210][3]; 216 217 218 ll check(ll t) 219 { 220 ll l=-5000,r=5000,res=INF; 221 while(l<=r) 222 { 223 ll mid=l+r>>1; 224 ll tmp=mid*mid*mid; 225 if(tmp==t) return mid; 226 if(tmp>t) r=mid-1; 227 else l=mid+1; 228 } 229 return res; 230 } 231 232 int main() 233 { 234 int t; 235 //init(); 236 237 /* for(ll x=0;x<=200;++x) 238 { 239 ll c=INF; 240 for(ll i=-5000;i<=5000;++i) 241 { 242 for(ll j=-5000;j<=5000;++j) 243 { 244 ll t=x-i*i*i-j*j*j; 245 c=check(t); 246 if( abs(c)<=5000) 247 { 248 printf("%lld,%lld,%lld,\n",i,j,c); 249 break; 250 } 251 } 252 if( abs(c)<=5000) break; 253 } 254 if( abs(c)<=5000) continue; 255 else printf("11111,0,0,\n"); 256 }*/ 257 cin>>t; 258 while(t--) 259 { 260 int x; 261 cin>>x; 262 if(ans[x][0]==11111) cout<<"impossible"<<endl; 263 else cout< 0]<<' '< 1]<<' '< 2]<<endl; 264 } 265 return 0; 266 }