"Uoj #6" AB

Source: Internet
Author: User


#74 hack Password


First, it is easy to get the formula for the letter of the I-digit number x:

(26^n-1) *x=26*h[i]-h[i+1]


We can find out the inverse of the (26^n-1)%mod, and take it to the right.


However, this is only 50 points!


(26^n-1)%mod=0 when there is no inverse yuan!! That is, in this case x is any number can, and this algorithm will cause all output a,h[] All is 0, and may not be read in the H.


So the way to do this is to find out the N-digits represented by the 26 binary, and the direct output is the answer. h[1 Because he satisfies the h[1], the back of the inevitable satisfaction.


<span style= "FONT-SIZE:18PX;" > #include <iostream> #include <cstring> #include <cstdio> #include <cstdlib> #include < String> #define LL Long longusing namespace std; LL Ni;int n,mod,ans[100005]; ll Pow (ll x,int nn) {int n=nn; LL base=x,ans=1ll;while (n) {if (n&1) ans=ans*base%mod;base=base*base%mod;n>>=1;} return ans;} void Prepare () {LL x=1;for (int i=1;i<=n;i++) x=1ll*x*26ll%mod;x= (x-1+mod)%mod;ni=pow (x,mod-2);} void Solve1 () {LL x;scanf ("%lld", &x); for (int i=n;i;i--) {ans[i]=x%26;x/=26;} for (int i=1;i<=n;i++) cout<< (char) (ans[i]+ ' a '); Cout<<endl;} int main () {scanf ("%d%d", &n,&mod); Prepare (); if (NI==0LL) {Solve1 (); return 0;} LL xx,x,y;scanf ("%lld", &xx); x=xx;for (int i=1;i<n;i++) {scanf ("%lld", &y); ans[i]= (X*26ll-y+mod)%mod*ni% Mod;while (ans[i]>26) ans[i]-=mod;x=y;} ans[n]= (X*26ll-xx+mod)%mod*ni%mod;while (ans[n]>26) ans[n]-=mod;for (int i=1;i<=n;i++) cout<< (char) (ans [i]+ ' a '); Cout<<endl;return 0;} &lT;/span> 


B:

#75 IQ Lock


Kirchhoff's theorem + wtf


The Kirchhoff theorem can use O (n^3) time to find out the number of spanning trees of an image without a direction.


Vfk's Kirchhoff theorem proves .


Describe the process of this algorithm:

1. Construct the matrix corresponding to the graph, (i,i) The value is the number of degrees I point, if i,j between the edge, then (i,j) = (j,i) =-1


2. The value of the determinant of this graph is to generate several numbers:

First Gaussian elimination, the result is the product of the diagonal


The way to do this is to extend the data from number 7th:

Number 7th of the K is a number of small prime numbers multiplied, then the small prime numbers can be directly constructed into a ring, the ring with the bridge to connect the number of the spanning tree is the request!


The process of promiscuity and proof see the official puzzle.

<span style= "FONT-SIZE:18PX;" > #include <iostream> #include <cstring> #include <algorithm> #include <cmath> #include < cstdlib> #include <cstdio> #include <map> #define MOD 998244353#define LL long longusing namespace Std;int TOT=0,AAA=0,H[1001010],A[1005][15][15],EDGE[1005]; LL inv[1005],num[1005],d[15][15];int t;struct edge{int x,y,ne,v;} E[1001010];void Build (int x) {memset (d,0,sizeof (d)); for (int. i=1;i<12;i++) for (int j=i+1;j<=12;j++) if (rand ()%10 >=2) {a[x][i][j]=a[x][j][i]=1;d[i][j]=d[j][i]=mod-1;edge[x]++;d [i][i]++,d[j][j]++;}} ll Pow (ll X,int N) {ll ans=1,base=x;while (n) {if (n&1) ans=ans*base%mod;base=base*base%mod;n>>=1;} return ans;} void Gauss () {int i,j,k;for (i=1;i<12;i++) {for (j=i;j<12;j++) if (d[j][i]!=0) break;for (k=i;k<12;k++) Swap (d[i ][k],d[j][k]); LL S=pow (d[i][i],mod-2); for (j=i+1;j<12;j++) {int rate= (mod-d[j][i]*s%mod)%mod;for (k=i;k<12;k++) (d[j][k]+=d[ i][k]*rate)%=mod;}}} void Hash (int x,int y) {int s= (int)) (num[x]*num[y]%mod); int k=s%1001001;for (int i=h[k];i;i=e[i].ne) if (e[i].v==s) return;e[++tot].x=x,e[tot].y=y,e[ Tot].ne=h[k],h[k]=tot,e[tot].v=s;} int Get (int x) {int k=x%1001001;for (int i=h[k];i;i=e[i].ne) if (e[i].v==x) return I;return 0;} void P (int x,int k) {for (Int. i=1;i<=12;i++) for (int j=i+1;j<=12;j++) if (A[x][i][j]) printf ("%d%d\n", k+i,k+j);} void Print (int aa,int bb,int cc,int dd) {printf ("%d\n", edge[aa]+edge[bb]+edge[cc]+edge[dd]+3); P (aa,0); P (bb,12); P (cc,24); P (dd,36);p rintf ("13\n24 25\n36 37\n");}        int main () {srand (12341234); scanf ("%d", &t); for (int i=1;i<=1000;i++) {Build (i); Gauss (); num[i]=1;for (int j=1;j<12;j++) num[i]=num[i]*d[j][j]%mod;if (Num[i]) Inv[i]=pow (num[i],mod-2);} for (int i=1;i<=1000;i++) if (Num[i]) for (int j=i;j<=1000;j++) if (Num[j]) Hash (I,J), and while (t--) {int k;scanf ("%d", & amp;k), if (k==0) {printf ("ten 0\n"); continue;} int ok=0;for (int i=1;i<=1000;i++) {if (Num[i]) for (int j=i;j<=1000;j++) if (Num[j]) {LL invv=inv[i]*inv[j]%mOd;int id=get ((int) (LL) k*invv%mod); if (id) {ok=1,print (I,J,E[ID].X,E[ID].Y); break;}} if (OK) break;} if (!ok) puts ("QwQ");} return 0;} </span>

C:

#76 Lazy Cancer



Only the number 7th data is very:

1. Only one dog was ill: The dog's owner saw that all the dogs were not sick, and it must have been his dog's illness.

Day+=1,dog+=1


2. Two dogs were ill: one of the owners of a sick dog began to think that his dog was not ill, and when he saw a dog was ill, the owner of the dog could not see any of the dogs being ill and should have shot the first day; he did not open, stating that his dog was ill and shot the next day. The owner of another sick dog analyzed the same.

day+=2,dog+=2


3. Three dogs were ill: one of the owners of a sick dog thought his dog was not sick, and the two sick dogs he had seen were in the 2 situation, but he did not hear gunfire the next day, so his dog must have been ill, so he shot him on the third day. The other two have the same empathy.

Day+=3,dog+=3

So the final answer is: Dog=day=sigma (C (n,i) *i)


Sentiment:

1. Use the inverse element must consider whether the inverse element exists!


2. Do well the Magic ~ Random good Bad ~


3. The assumption of law, the introduction of contradictions.


"Uoj #6" AB

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.