HDU 5014 Number Sequence greedy 2014 ACM/ICPC Asia Regional Xi 'an Online, hdu5014
Try to join 2 ^ X-1
# Include <cstdio> # include <cstring> const int N = 100005; int a [N], p [N]; int init (int x) {int cnt = 0; while (x> 1) {x/= 2; cnt ++;} return cnt + 1;} int main () {int n; while (~ Scanf ("% d", & n) {for (int I = 0; I <= n; I ++) {scanf ("% d ", & a [I]);} memset (p, 0, sizeof p); long ans = 0; for (int I = n; I> = 0; I --) {if (p [I]! = 0) continue; if (I = 0) continue; int t = 1 <(init (I); if (t = 2 * I) {p [I] = I-1; p [I-1] = I; ans + = 2 * (I ^ (I-1);} else if (t = I + 1) {p [I] = 0; p [0] = I; ans + = 2 * I;} else {if (p [t-I] = 0) {p [I] = t-I-1; p [t-i-1] = I; ans + = 2 * (t-1) ;}} printf ("% I64d \ n ", ans); for (int I = 0; I <= n; I ++) {if (I! = 0) printf (""); printf ("% d", p [a [I]);} puts ("") ;}return 0 ;}
What is ACM/ICPC Asia Regional?
International. The finals are world-class. Asia belongs to the intercontinental and international level!