Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
看我的这个呢In Reply To:贴份c++暴搜AC代码,要找到合适的搜索方式 Posted by:a280920481 at 2018-11-19 22:17:07 #include <cstdio> #define s(n) scanf ("%d" ,&(n)) int qkpow(int b) { int x = 10 ,ans = 1; while (b) { if (b % 2) ans *= x; x *= x; b >>= 1; } return ans; } int T ,a[15]; int main() { s(T); while (T--) { int k = 0; while (scanf ("%d" ,&a[++k]) != EOF); k--; if (k % 2) { int t1 = 0 ,t2 = 0; if (!a[1]) { int t = a[1]; a[1] = a[2]; a[2] = t; } int m = k / 2 ,cnt = k; while (m) { t2 += qkpow(m - 1) * a[cnt--]; m--; } m = k / 2 + 1 ,cnt = 1; while (m) { t1 += qkpow(m - 1) * a[cnt++]; m--; } printf ("%d\n" ,t1 - t2); } else { int t1 = 0 ,t2 = 0; if (!a[1]) { int t = a[1]; a[1] = a[2]; a[2] = a[3]; a[3] = t; } int m = k / 2; t1 += qkpow(m - 1) * a[1]; t2 += qkpow(m - 1) * a[2]; m--; int cnt = k; while (m) { t1 += qkpow(m - 1) * a[cnt--]; m--; } cnt = 3; m = k / 2 - 1; while (m) { t2 += qkpow(m - 1) * a[cnt++]; m--; } printf ("%d\n" ,t2 - t1); } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator