Laboratory Test 10.6

Source: Internet
Author: User

Bricks



Very simple water problem, it is very simple to write.
Simulation writing is very short, whether it is also the embodiment of code force?

#include <cstdio> #include <cstring> #include <map> #define FN "block" int Mp[1105][1105],dao,ans;char    S[105];int x,y,dx[4]={0,0,-1,1},dy[4]={1,-1,0,0};std::map<char,int> m;void init () {memset (Mp,0,sizeof (MP));    Mp[550][550]=1;    ans=x=y=0; Dao=-1;}    int main () {Freopen (FN ". In", "R", stdin);    Freopen (FN ". Out", "w", stdout);    m[' N ']=0,m[' S ']=1,m[' W ']=2,m[' E ']=3;    int t;scanf ("%d", &t);        while (t--) {init ();        int k;scanf ("%d", &k);        scanf ("%s", s+1);        int Len=strlen (s+1);            for (int i=1;i<=len;i++) {x+=dx[m[s[i]];            Y+=dy[m[s[i]]; if (!~dao) {for (int j=0;j<k;j++) if (++mp[x+dx[m[s[i]]]*j+550][y+dy[m[s[i]]]*j+550]&                 Gt;ans) ans=mp[x+dx[m[s[i]]]*j+550][y+dy[m[s[i]]]*j+550];            Dao=m[s[i]];         } else if ((Dao^m[s[i]) ==1) {if (++mp[x+550][y+550]>ans) ans=mp[x+550][y+550];       Dao=-1;                } else if (Dao==m[s[i]]) {x+=dx[m[s[i]]]* (k-1), y+=dy[m[s[i]]]* (k-1);                if (++mp[x+550][y+550]>ans) ans=mp[x+550][y+550];            Dao=-1; } else {for (int j=0;j<k;j++) if (++mp[x+dx[dao]*j+550][y+dy[dao]*j+550]&gt            ; ans) ans=mp[x+dx[dao]*j+550][y+dy[dao]*j+550];        }} if (!~dao) printf ("%d\n%d\n", X, y); else if (dao==0 | | dao==3) {for (int j=0;j<k;j++) printf ("%d%c", x+dx[dao]*j,j==k-1? '            \ n ': '); for (int j=0;j<k;j++) printf ("%d%c", y+dy[dao]*j,j==k-1? '        \ n ': '); } else {for (int j=k-1;j>=0;j--) printf ("%d%c", x+dx[dao]*j,j? '            ': ' \ n '); for (int j=k-1;j>=0;j--) printf ("%d%c", y+dy[dao]*j,j? '        ': ' \ n ');    } printf ("%d\n", ans); } return 0;}

No map, but I'm too lazy to change it.
Flip there are several situations, as long as to think, still do not leak (if you miss the sample)

Digital

Really is called the fairy question, the problem has not been understood so far.

Wilson theorem plus Balabala can solve the situation of \ (k=1\) .

Preprocessing 1e7 factorial%1e7 can be 50 points,%1e5 only 20 points.

STD code (with high accuracy):

#include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm>using namespace std  ; typedef long long ll;const int con=100000000;  const int wei=8;  Class int{Public:long long a[100];    void Read () {memset (a,0,sizeof (a)); Char s[105]={0};    int len=0; scanf ("%s", s+1);    Len=strlen (s+1);    for (int i=1;i<=len/2;i++) swap (s[i],s[len-i+1]);    for (int i=1;i<=len;i++) s[i]-= ' 0 ';    a[0]=0;      for (int i=1;i<=len;i+=8) {a[0]++;    for (int j=i+7;j>=i;j--) A[A[0]]=A[A[0]]*10+S[J];  }} void GetData (int x) {memset (a,0,sizeof (a)); while (x) {A[++a[0]]=x%con;x=x/con;}}  int (int x=0) {GetData (x); } void PRI (BOOL flag) {if (a[0]==0| | (a[0]==1&&a[1]==0))        {printf ("0"); if (flag) printf ("\ n"); return;}        printf ("%lld", A[a[0]]);        for (int i=a[0]-1;i;i--) printf ("%08lld", A[i]);      if (flag) printf ("\ n"); } BOOL operator < (const Int &x) {if (a[0]<x.a[0]) return true;if (a[0]>x.A[0]) return false;        for (int i=a[0];i;i--) {if (A[i]<x.a[i]) return true;if (A[i]>x.a[i]) return false;}      return false;        } BOOL operator > (const Int &x) {if (a[0]<x.a[0]) return false;if (A[0]>x.a[0]) return true;        for (int i=a[0];i;i--) {if (A[i]<x.a[i]) return false;if (A[i]>x.a[i]) return true;      return false;        } BOOL operator <= (const Int &x) {if (a[0]<x.a[0]) return true;if (A[0]>x.a[0]) return false;        for (int i=a[0];i;i--) {if (A[i]<x.a[i]) return true;if (A[i]>x.a[i]) return false;}      return true;        } BOOL operator >= (const Int &x) {if (a[0]<x.a[0]) return false;if (A[0]>x.a[0]) return true;        for (int i=a[0];i;i--) {if (A[i]<x.a[i]) return false;if (A[i]>x.a[i]) return true;      return true; } bool operator = = (Const Int &x) {if (a[0]!=x.a[0]) return false;for (Int i=a[0];i;i--) if (A[i]!=x.a[i]) ret        Urn false; return TRUe        } int operator + (const int &x) {int C;memset (c.a,0,sizeof (C.A)); for (int i=1;i<=a[0]| |        i<=x.a[0];i++) {C.a[i]=c.a[i]+a[i]+x.a[i];c.a[i+1]+=c.a[i]/con;c.a[i]%=con;}        C.a[0]=max (a[0],x.a[0]); if (c.a[c.a[0]+1]) c.a[0]++;      return C;        } int operator + (int num) {int c;memcpy (c.a,a,sizeof (C.A)); c.a[1]+=num;        for (int i=1;i<=c.a[0]&&c.a[i]>=con;i++) c.a[i]-=con,c.a[i+1]++;        while (c.a[c.a[0]+1]) c.a[0]++;      return C;        } int operator-(const int &x) {int c;memcpy (c.a,a,sizeof (C.A));        for (int i=1;i<=a[0];i++) {c.a[i]=c.a[i]-x.a[i];if (c.a[i]<0) {C.a[i+1]--;c.a[i]+=con;}}        while (C.a[0]&&!c.a[c.a[0]]) c.a[0]--;      return C;        } int operator-(int num) {int c;memcpy (c.a,a,sizeof (C.A)); c.a[1]-=num;        for (int i=1;i<=c.a[0]&&c.a[i]<0;i++) c.a[i]+=con,c.a[i+1]--;     while (C.a[0]&&!c.a[c.a[0]]) c.a[0]--;   return C;        } int operator * (const int &x) {int C;memset (c.a,0,sizeof (C.A)); for (int i=1;i<=a[0];i++) for (int j=1;j<=x.a[0];j++) {c.a[i+j-1]+=a[i]*x.a[j];c.a[i+j]+=c.a[i+        J-1]/con;c.a[i+j-1]%=con;}        C.a[0]=max (A[0]+X.A[0]-1,0LL); if (c.a[a[0]+x.a[0]]>0) c.a[0]++;      return C;        } int operator * (int num) {int c;memset (c.a,0,sizeof (C.A));        for (int i=1;i<=a[0];i++) {c.a[i]+=a[i]*num;if (C.a[i]>=con) {C.a[i+1]+=c.a[i]/con;c.a[i]%=con;}}        C.a[0]=a[0];if (c.a[c.a[0]+1]>0) c.a[0]++;      return C;        } int operator/(int num) {int c;memset (c.a,0,sizeof (C.A));        Long long x=0;for (int i=a[0];i;i--) {x=x*con+a[i];c.a[i]=x/num;x=x%num;}        C.a[0]=a[0];if (C.a[0]&&!c.a[c.a[0]]) c.a[0]--;      return C;    } int operator% (int num) {int ret=0;    for (int i=a[0];i;i--) ret= ((LL) ret*con+a[i])%num;      return ret; }};inline int Pow (int a,int b,int p) {int ret=1;  for (int i=1;i<=b;i++) ret=ret*a%p; return ret;} int n,k,k0;int k;int s[1005],m;inline void Pre () {int t=n;  K0.getdata (0); while (!) ( t==0)) K0=K0+T/5,T=T/5;}  int ans[200][200];int a[200];inline int Solve () {int phi=k==1?4: (k==2?4*5:4*5*5);  int Mod2=0,mod5,k2=pow (2,k,2333), K5=pow (5,k,2333);  for (int i=0;i<k2*k5;i++) ans[i%k2][i%k5]=i;    int Inv=pow (2,PHI-1,K5), Inv=pow (INV,K0%PHI,K5);  A[0]=1;    for (int i=1;i<k5;i++) {int t=i; if (t%5==0) t=1;  a[i]= (a[i-1]*t)%k5; } Int t=n;  Mod5=1; while (!) (    t==0)) {Mod5=mod5*pow (a[k5-1], (T/K5)%phi,k5)%k5;    MOD5=MOD5*A[T%K5]%K5;  T=T/5;    } mod5=mod5*inv%k5; return ANS[MOD2][MOD5];}  inline void print (long long t,int k) {if (k==1) printf ("%lld\n", t%10);  else if (k==2) printf ("%02lld\n", t%100); else if (k==3) printf ("%03lld\n", t%1000);}  int main () {freopen ("num.in", "R", stdin);  Freopen ("Num.out", "w", stdout);  int T;  scanf ("%d", &t);    while (t--) {n.read ();    scanf ("%d", &k); if (n< =15) {Long long t=1;      for (int i=1;int (i) <=n;i++) t*=i;      while (t%10==0) t/=10;    Print (T,K);    }else{Pre (); Print (Solve (), k); }} return 0;}

Not write high accuracy has 80 points, but so far do not know how to do.


The violence has been given enough.

Because a valid sequence is unique, a hash is performed, and if the hash value of all its operations is the same as the correct one, then it is correct.
So the addition and multiplication of the hash value is maintained with two tag line tree.

Std writing is wonderful, I learned a wave.

#include <cstdio> #include <cstdlib> #include <algorithm>using namespace std;typedef unsigned int uint  ; inline char NC () {static Char buf[100000],*p1=buf,*p2=buf; Return p1==p2&& (p2= (p1=buf) +fread (Buf,1,100000,stdin), P1==P2)? eof:*p1++;}  inline void read (int &x) {char c=nc (), b=1; for (;!  (c>= ' 0 ' && c<= ' 9 '); C=nc ()) if (c== '-') b=-1; for (x=0;c>= ' 0 ' && c<= ' 9 '; x=x*10+c-' 0 ', C=NC ()); X*=b;}  const int N=200005;CONST UINT SEED=233333;STRUCT abcd{uint A, B;  ABCD (UINT A=1,uint b=0): A (a), B (b) {} bool One () {return a==1 && b==0;}    void Add (ABCD B) {UINT _a=a,_b=b; A=b.a*_a;  b=b.a*_b+b.b; }}t[n<<2];inline void Modify (int x,int l,int r,int ql,int qr,abcd T) {if (ql<=l && r<=qr) {T[x].ad    D (t);  Return } if (!  T[x].one ()) T[x<<1].add (T[x]), T[x<<1|1].add (T[x]), T[X]=ABCD ();  int mid= (L+R) >>1;  if (ql<=mid) modify (x<<1,l,mid,ql,qr,t); if (qr>mid) modify (x<<1|1,mid+1,R,QL,QR,T);}    UINT hash[n];inline void query (int x,int l,int R) {if (l==r) {hash[l]=t[x].b;  Return } if (!  T[x].one ()) T[x<<1].add (T[x]), T[x<<1|1].add (T[x]), T[X]=ABCD ();  int mid= (L+R) >>1;  Query (X&LT;&LT;1,L,MID); Query (x<<1|1,mid+1,r);}  int N,k;int Main () {int t,l,r,x;  Freopen ("Deco.in", "R", stdin);  Freopen ("Deco.out", "w", stdout); Read (n);  Read (K);  Read (T);    while (t--) {read (L); Read (R); Read (x);   Modify (1,1,N,L,R,ABCD (seed,x));  } query (1,1,n);  UINT H=0;  for (int i=1;i<=k;i++) h=h*seed+i;  int ans=0;  for (int i=1;i<=n;i++) if (hash[i]==h) ans++;  printf ("%d\n", ans); return 0;}

Use the structure to save two tags, use the constructor to calculate the value.
Wonderful ~

Laboratory Test 10.6

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.