HDU 5014 Number Sequence greedy 2014 ACM/ICPC Asia Regional Xi & #39; an Online, hdu5014

Source: Internet
Author: User

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!
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.