vijosP1447 Switch Bulb
Links: https://vijos.org/p/1447
Ideas
Math + High precision.
Analysis of the topic: in the words, I will be all its multiples of the lights out, so that a number of how many multiples will be operated how many times, because the initial all extinguished, so the operation of the odd lamp will finally light, and further, only the number of squares of the lamp in the end will be lit.
The number of sqrt (n) is converted to the number of squares within n (don't ask me how I know =_=)
Data range requires that we use high-precision. At this point, the topic is to a large number of the problem, Noip in the preliminary round has appeared this program.
Code
1#include <iostream>2#include <cstring>3#include <cmath>4 using namespacestd;5 6 Const intMAXN = $+Ten;7 structbign{8 intLen;9 intNUM[MAXN];TenBign () {memset (num,0,sizeof(num)); } One }; A - bign goal; - the bign times (bign a,bign b) { - bign C; -c.len=a.len+b.len+2; - for(intI=0; i<a.len;i++) + for(intj=0; j<b.len;j++) -C.NUM[I+J] + = a.num[i]*B.num[j]; + for(intI=0; i<c.len-1; i++) { Ac.num[i+1] + = c.num[i]/Ten; atC.num[i]%=Ten; - } - while(c.num[c.len-1]==0) c.len--; - returnC; - } - in bign average (bign a,bign b) { -Bign C; c.len=Max (A.len,b.len); to for(intI=0; i<c.len;i++) { +C.num[i] + = a.num[i]+B.num[i]; -c.num[i+1] + = c.num[i]/Ten; theC.num[i]%=Ten; * } $ Panax Notoginseng if(C.num[c.len]) c.len++; - for(inti=c.len-1; i;i--) { thec.num[i-1] + = (c.num[i]%2) *Ten; +C.num[i]/=2; A } thec.num[0]/=2; + if(c.num[c.len-1]==0) c.len--; - returnC; $ } $ - bign Plustwo (Bign a) { -a.num[0] +=2; the intI=0; - while(I<a.len && a.num[i]>=Ten) {Wuyia.num[i+1] + = a.num[i]/Ten; theA.num[i]%=Ten; -i++; Wu } - if(A.num[a.len]) a.len++; About returnA; $ } - - BOOLOver (bign a,bign b) { - if(A.len>b.len)return true; A Else if(A.len<b.len)return false; + the for(inti=a.len;i>=0; i--)//Reverse - if(A.num[i]>b.num[i])return true; $ Else if(A.num[i]<b.num[i])return false; the the return false; the } the - intMain () { inIos::sync_with_stdio (false); the strings; theCin>>s; Aboutgoal.len=s.size (); the for(intI=0; i<goal.len;i++) goal.num[i]=s[goal.len-1-i]-'0'; theBign L, r=goal, M; thel.len=1; l.num[0]=1; + Do - { them=average (l,r);Bayi if(Over (Times (M,M), goal)) R=M; the ElseL=M; the} while(!Over (Plustwo (L), R)); - for(inti=l.len-1; i>=0; i--) cout<<L.num[i]; - return 0; the}
vijosP1447 Switch Bulb