Title Link: 625d-finals in arithmetic
This problem is special Judge. The beginning is Aynuzzh let me do. The main idea is to define a flip post for AR, for example when a=123, ar=321. Given a number n (1≤n≤10100 000), a satisfies a+ar=n. There may be a lot of answers, one of them can be output.
We first see, if there is a number per bit for a,b,c,d, then Flip is d,c,b,a, the result of the addition is A+d,b+c,c+b,d+a, is a palindrome number. Then we're going to break n into a palindrome sequence to ask for a. We know that every one of a must be one of the 0~9, then each of the decomposed palindrome sequence is one of 0+0~9+9, 0~18.
We deal with N in a high-precision manner. First, the highest bit of n is processed, and if the highest bit of n is not the same as the lowest bit, we will let the highest bit of n abdicate and match the equal. If there is no match, then there is no solution.
We set up l,r two pointers from the highest bit to the lowest bit to the middle scan. For each l,r that should match two positions, if they are equal, then no processing is required. If not equal, then if l>=10 (that is, the previous bit) and r<10 (that is, the previous one does not abdicate) we will leave the previous position of R to the point where the l,r points to meet the conditions of >=10 (the previous bit is retired). Next, if l-r=1, we will be the position L point to abdicate, then l,r match. If the operation still does not match, then there is no solution.
After the decomposition is complete, we need to find out the answer a. First of all, the palindrome sequence of each of the X+y (0≤x,y≤9) Form, we will match two items to take X, one to take Y. If there is one that matches itself, then this must be a form of x+x. We need to determine if this bit is an even number, only an even number can meet the 2x condition. If it is odd, then there is no solution. When the decomposition is complete, we have to verify that there are no non-conforming conditions (that is, greater than 9 or less than 0) of the value, if there is no solution. Finally, combining each item of the sequence into a can be a set of solutions. We sweep the sequence two times, so the time complexity is O (2n). Can I optimize it? OK. In the process of the first scan we can also complete the second scan of the task, to find out the answer a. So the last time complexity is only O (n).
#:15927417
Author:_snakes_
problem:625d
Lang:gnu c++11
verdict:accepted
Time:31 ms
memory:0 Kb
Sent:2016-02-10 13:33:00
Judged:2016-02-10 13:33:01
1#include <cstdio>2 using namespacestd;3 intMain ()4 {5 Chars[100005];6 intN,l,r;7 while((scanf ("%c", &s[++n]) = =1) && (s[n]>='0') && (s[n]<='9'))8s[n]-='0';9L=1;Tenr=--N; One if(s[l]!=S[r]) A { -s[l]--; -s[l+1]+=Ten; the if(s[l]==0) -l++; - } - while(l<=R) + { - if(s[l]!=S[r]) + { A if((s[l]-s[r]>=Ten) && (s[r]<Ten)) at { -s[r-1]--; -s[r]+=Ten; - } - if(s[l]-s[r]==1) - { ins[l]--; -s[l+1]+=Ten; to } + } - if(s[l]!=S[r]) the Break; * if(l!=R) $ {Panax Notoginsengs[l]=s[l]-(s[r]>>1); -s[r]>>=1; the } + Else A if(((s[l]>>1) <<1)==S[l]) thes[l]>>=1; + Else - Break; $ if(s[l]>9|| s[l]<0|| S[r]>9|| s[r]<0) $ Break; -l++; -r--; the } - if(l<=R)Wuyi { theprintf"0"); - return 0; Wu } -L=1; About if(s[l]==0) $l++; - while(l<=N) - { -printf"%d", S[l]); Al++; + } the return 0; -}
[Codeforces 625D] Finals in arithmetic