NOIP2002PJ generation Number [Floyd high accuracy]

Source: Internet
Author: User
Tags x2 y2

Background

Gives an integer n (n<10^30) and a K transform rule (k<=15).

Rules:
One number variable to another one number:
The right part of the rule cannot be zero.

For example: n=234. There are rules (k=2):
2-> 5
3-> 6
The integer 234 above can be transformed to produce an integer (including the original number):
234
534
264
564
A total of 4 different production numbers

Describe

Gives an integer n and a K rule.

Find out:
The number of different integers that can be generated after any transformation (0 or more times).

仅要求输出个数。
Format input Format

N k
X1 Y1
X2 y2
... ...
Xn yn

Output format

An integer (satisfies the number of conditions):

Example 1 sample input 1[copy]
234 22 53 6
Sample output 1[Copy]
4
Limit

1s per test point

Source

The third problem of noip2002 popularization group

----------------

A number can be transformed several times, Floyd the transitive closure (initialization d[i][i]=1), the multiplication principle updates the answer

To use high precision, pay attention to the output

////main.cpp//noip2002 Generation Number////Created by Candy on 9/10/16.//copyright©2016 Candy. All rights reserved.//#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespacestd;typedef unsignedLong Longll;Const intn= -, b=1e4;inlineintRead () {intx=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}intK,x,y,d[n][n],f[n];CharS[n];voidFloyd () { for(intI=0; i<=9; i++) d[i][i]=1;  for(intk=0; k<=9; k++)         for(intI=0; i<=9; i++)             for(intj=0; j<=9; j + +) D[i][j]=d[i][j]| | (d[i][k]&&D[k][j]);  for(intI=0; i<=9; i++)         for(intj=0; j<=9; j + +)if(D[i][j]) f[i]++;}structbig{intd[ -],size; Big () {size=1;}} ans;voidChengint (Big &a,intk) {    intg=0, I;  for(i=1; i<=a.size;i++){        inttmp=a.d[i]*K; A.d[i]= (tmp+g)%B; G= (tmp+g)/C; }     while(g) {A.d[i++]=g%b; a.size++; G/=C; }}intMainintargcConst Char*argv[]) {scanf ("%s%d",s,&k);  for(intI=1; i<=k;i++) scanf ("%d%d", &x,&y), d[x][y]=1;    Floyd (); ans.d[1]=1; intlen=strlen (s);  for(intI=0; i<len;i++){        inta=s[i]-'0';        Chengint (Ans,f[a]); //printf ("F%d%d\n", A,f[a]);    }     for(inti=ans.size;i>=1; i--){        if(i!=ans.size) {            if(ans.d[i]<Ten) cout<<" the"; Else if(ans.d[i]< -) cout<<"xx"; Else if(ans.d[i]< +) cout<<"0"; } cout<<Ans.d[i]; }    return 0;}

NOIP2002PJ generation Number [Floyd high accuracy]

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.