Title Link:http://acm.hdu.edu.cn/showproblem.php?pid=5587

The main idea is to start with a 1, and then each operation is to add a 0after the sequence, and then add the original sequence after 0 , and then from 0 to the end, each one is added 1.

For example:A0, a1, A2 = a0, A1, A2, 1, A0+1 , a1+1, a2+1

That's the way it says: "

In fact, AI is the number of the I binary in 1. Each change a{k+2^i}=a{k}+1, (k<2^?i??) does not produce a carry, the number of binary 1 plus 1. Then the digital DP statistics before the number of binary binary 1, the number of each to calculate the contribution of the answer. Just consider the bit fill 1, its high and low number of species can be.

”

But I didn't think of that.

I wrote a few transformations and found:

Add a 0to the front,

The length of each transformation is then changed to twice times, and each of the previous and posterior sequences has a corresponding difference of 1.

However, it is clear that the second and second points of m+1 are 2 of the time required.

But for each of the 2 groups, it is found that at least each transformation is 2 times the number of transformations.

That is to say that i%2== 1 of the number of ai, found that they composed of sequence transformation and the original sequence is identical.

i%2== 0 is the same, but you need to add 1 on top of each number .

Then for s (n), the natural can be i%2 = = 1 in front of it, i%2 = = 0 of the two sets of sequences constitute

So it becomes s (n) = S (N/2) +s (N/2) +N/2 or S (n/2+1) +s (N/2) +n/2 ( depending on n%2)

This will be two points down, but the need for memory, where the use of map for memory.

But at the time of the game, I wrote four for a group. Because the above N/2 and n/2+1 only when a large number of n%2 equals 0 to cut off half each time. However, if four is a group, each length becomes a section, but generates N/4 and n/4+1. But these two do not remember the situation will be T.

However, after using map memory, I am afraid of the MLE, the local measurement of several sets of data, do not occupy a lot of memory.

Code: (two points)

#include <iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<cstring>#include<algorithm>#include<Set>#include<map>#include<queue>#include<string>#defineLL Long Longusing namespacestd; LL M;map<ll, ll>s; ll Dfs (ll N) {if(n = =1)return 0; if(n = =2)return 1; LL ans, T1=0, T2; if(n%2) { if(s[n/2+1] ==0) {T1= DFS (n/2+1); S[n/2+1] =T1; } ElseT1 = s[n/2+1]; } if(s[n/2] ==0) {T2= DFS (n/2); S[n/2] =T2; } ElseT2 = s[n/2]; Ans= (n%2) *t1+ (2-n%2)*T2; Ans+ = n/2; returnans;}intMain () {//freopen ("test.in", "R", stdin); intT; scanf ("%d", &T); for(intTimes =1; Times <= T; ++Times ) {scanf ("%i64d", &m); LL ans; Ans= DFS (m+1); printf ("%i64d\n", ans); } return 0;}

View Code

Code: (Four points)

#include <iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<cstring>#include<algorithm>#include<Set>#include<map>#include<queue>#include<string>#defineLL Long Longusing namespacestd; LL M;map<ll, ll>s; ll Dfs (ll N) {if(n = =1)return 0; if(n = =2)return 1; if(n = =3)return 2; if(n = =4)return 4; LL ans, T1=0, T2; if(n%4) { if(s[n/4+1] ==0) {T1= DFS (n/4+1); S[n/4+1] =T1; } ElseT1 = s[n/4+1]; } if(s[n/4] ==0) {T2= DFS (n/4); S[n/4] =T2; } ElseT2 = s[n/4]; Ans= (n%4) *t1+ (4-n%4)*T2; Ans+ = n/4*4; if(n%4) ans + = n%4-1; returnans;}intMain () {//freopen ("test.in", "R", stdin); intT; scanf ("%d", &T); for(intTimes =1; Times <= T; ++Times ) { //s.clear ();scanf"%i64d", &m); LL ans; Ans= DFS (m+1); printf ("%i64d\n", ans); } return 0;}

View Code

ACM Learning process-hdu5587 Array (Math && dichotomy && Memory | | Digital DP) (Bestcoder Round #64 (Div.2) 1003)