Codevs Month Race 1

Source: Internet
Author: User

Topic HTTP://PAN.BAIDU.COM/S/1GDFB4BH

T1 water Problem

1#include <bits/stdc++.h>2 #defineOk (A,l,r) (((L) <= (a)) && ((a) <= (R))3 #defineCLR (a,x) memset (A,x,sizeof (a))4 #defineRep (i,l,r) for (int i=l;i<r;i++)5typedefLong Longll;6 using namespacestd;7 intRead ()8 {9     CharC=GetChar ();Ten     intans=0, f=1; One      while(!IsDigit (c)) { A         if(c=='-') f=-1; -C=GetChar (); -     } the      while(IsDigit (c)) { -ans=ans*Ten+c-'0'; -C=GetChar (); -     } +     returnans*F; - } + intGetsum (inta) { A     intans=0; at      while(a) { -ans+=a%Ten; -A/=Ten; -     } -     returnans; - } in Const intmaxs= -; - intANS[MAXS]; tovector<int>hehe; + intMain () - {     the     intK=read (), P=read (), Q=read (), L=read (), R=read (), cnt=0, cnt1=0; *Rep (I,1, the){ $         intT=pow (i,k) *p+Q;Panax Notoginseng         if(Getsum (t) = =i) { -ans[cnt++]=T; the         } +     } ASort (ans,ans+CNT); theRep (I,0, CNT) { +         if(OK (ans[i],l,r)) Hehe.push_back (Ans[i]); -     } $printf"%d\n", Hehe.size ()); $Rep (I,0, Hehe.size ()) { -printf"%d", Hehe[i]); -         if(I!=hehe.size ()-1) Putchar (' '); the     } -     return 0;Wuyi}
View Code

T2kmp

1#include <bits/stdc++.h>2 #defineCLR (a,x) memset (A,x,sizeof (a))3 #defineRep (i,l,r) for (int i=l;i<r;i++)4typedefLong Longll;5 using namespacestd;6 intRead ()7 {8     CharC=GetChar ();9     intcn1=0, f=1;Ten      while(!IsDigit (c)) { One         if(c=='-') f=-1; AC=GetChar (); -     } -      while(IsDigit (c)) { theans=ans*Ten+c-'0'; -C=GetChar (); -     } -     returnans*F; + } - Const intmaxn=1000009; + intN,M,A[MAXN],B[MAXN],A[MAXN],B[MAXN],NEXT[MAXN]; A voidGetNext () at { -     intj,k; -j=0; k=-1; next[0]=-1; -      while(j<N) { -         if(k==-1|| a[j]==A[k]) -next[++j]=++K; in         Else -k=Next[k]; to     } + } - intKmp_count () the {     *     /*Rep (i,0,n) cout<<a[i]<< "; $ cout<<endl;Panax Notoginseng Rep (i,0,m) cout<<b[i]<< "; - cout<<endl;*/ the     intans=0; +     inti,j=0; A     if(m==1&&n==1) the     { +         if(b[0]==a[0]) -             return 1; $         Else $             return 0; -     } - GetNext (); the      for(i=0; i<m;i++) -     {Wuyi          while(j>0&&b[i]!=A[j]) thej=Next[j]; -         if(b[i]==A[j]) WuJ + +; -         if(j==N) About         { $ans++; -j=Next[j]; -         } -     } A     returnn?ans:m+1; + } the intMain () - { $N=read (), m=read (); theCLR (A,0), CLR (b,0), the CLR (A,0), CLR (B,0); theRep (I,0, N) a[i]=read (); theRep (I,0, m) b[i]=read (); the--n;--m; -Rep (I,0, N) a[i]=a[i+1]-A[i]; inRep (I,0, m) b[i]=b[i+1]-B[i]; the     intsum=Kmp_count (); theCLR (A,0); Aboutsum+=Kmp_count (); theRep (I,0,m>>1) Swap (b[i],b[m-i-1]); thesum+=Kmp_count (); theRep (I,0, N) a[i]=a[i+1]-A[i]; +sum+=Kmp_count (); -printf"%d\n", sum); the     return 0;Bayi}
View Code

T3 won't

Codevs Month 1

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.