题意:
(abc)代表abc无穷的循环....问(a1a2a3....)+(b1b2b3...)的值是多少..表示为(...)**的形式(前面是循环的..后面小段不循环的)
题解
练习赛的时候想得有点多..这题暴力展开两个之和~~然后暴力判断就好...
Program:
#include<iostream> #include<stack> #include<queue> #include<stdio.h> #include<algorithm> #include<string.h> #include<cmath> #define ll long long #define oo 1000000007 #define MAXN 5005 #define MM 55 using namespace std; char s[MAXN]; int a[MAXN],b[MAXN],c[MAXN]; void getans(int n) { int i,j,x,k,t; memset(c,0,sizeof(c)); for (i=1;i<=n;i++) c[i]+=a[i]+b[i],c[i+1]+=c[i]/10,c[i]%=10; printf("("); k=c[n+1]; for (t=2;t<=MM;t++) { for (i=1;i<=n;i++) { x=(t-1)*n+i; c[x]+=c[i],c[x+1]+=c[x]/10,c[x]%=10; } c[x+1]=k; } for (k=1;k<=n*MM;k++) for (x=1;x<=n*5;x++) { t=x; while (t<=n*20) { for (j=0;j<k && x+j<=n*MM;j++) if (c[x+j]!=c[t++]) goto A; } goto B; A: ; } B: ; for (i=x+k-1;i>=x;i--) printf("%d",c[i]); printf(")"); for (i=x-1;i>=1;i--) printf("%d",c[i]); printf("\n"); } int main() { scanf("%s",s); int n=strlen(s),i; for (i=1;i<=n-2;i++) a[i]=s[n-i-1]-'0'; scanf("%s",s); for (i=1;i<=n-2;i++) b[i]=s[n-i-1]-'0'; getans(n-2); return 0; } /* (13681872) (95650177) ans=(50093320)49 */