标签:color lld 变换 状态 pre def 限制 har sqrt
个人感受:这一次考试信心满满,但是还是炸了,第一题文件名写错,0+70+100,第三题花了不到半小时的反而对了,这个体现了基本功不扎实,哎。
over.cpp
1 #include<cstdio> 2 #include<algorithm> 3 #include<iostream> 4 #include<cmath> 5 #include<cstring> 6 #define ull unsigned long long 7 8 using namespace std; 9 10 int n; 11 unsigned long long pan[8]={127,255,32767,65535,2147483647,4294967295,9223372036854775807,18446744073709551615}; 12 char ch[1000007]; 13 14 int got_point(int x,int y) 15 { 16 if (y==1) 17 { 18 if (x==8) return 0; 19 if (x==1) return 2; 20 if (x==3) return 4; 21 if (x==6) return 6; 22 } 23 else 24 { 25 if (x==8) return 1; 26 if (x==1) return 3; 27 if (x==3) return 5; 28 if (x==6) return 7; 29 } 30 } 31 int main() 32 { 33 freopen("over.in","r",stdin); 34 freopen("over.out","w",stdout); 35 36 scanf("%d",&n); 37 for (int i=1;i<=n;i++) 38 { 39 scanf("%s",ch); 40 long double ans=1; 41 int x; 42 if (ch[0]==‘i‘) x=1; 43 else 44 { 45 scanf("%s",ch); 46 x=0; 47 } 48 int now=(got_point(ch[3]-‘0‘,x)),time=0,flag=0; 49 gets(ch); 50 gets(ch); 51 int len=strlen(ch); 52 ch[len]=‘ ‘; 53 long double p=0; 54 for (int i=0;i<=len;i++) 55 if (ch[i]==‘ ‘) 56 { 57 ans=ans*p; 58 p=0; 59 if (ans>(long double)pan[now]) 60 { 61 printf("%d\n",++time); 62 flag=1; 63 break; 64 } 65 ++time; 66 } 67 else 68 { 69 p=p*10+ch[i]-‘0‘; 70 } 71 if (!flag) printf("never\n"); 72 } 73 }
jumpcut.cpp
1 #include<cstdio> 2 #include<algorithm> 3 #include<iostream> 4 #include<cmath> 5 #include<cstring> 6 7 using namespace std; 8 9 int n,cnty; 10 int b[10007]={0}; 11 12 bool solve(long long num) 13 { 14 int cntx=0,a[1007]; 15 while (num!=0) 16 { 17 a[++cntx]=num%10; 18 num/=10; 19 } 20 if (cntx<cnty) return false; 21 if (cntx-cnty==0) 22 { 23 for (int i=1;i<=cntx;i++) 24 if (b[i]!=a[i]) return false; 25 return true; 26 } 27 if (cntx-cnty<=2) 28 { 29 int ckt=cntx-cnty; 30 int xx=1,flag=0; 31 for (int i=1;i<=cntx;i++) 32 if (b[xx]!=a[i]) 33 { 34 if (flag==ckt) return false; 35 else flag++; 36 } 37 else xx++; 38 return true; 39 } 40 int ckt=cntx-cnty; 41 for (int i=1;i<=cntx-ckt+1;i++) 42 { 43 int l=i,r=i+ckt-1; 44 bool flag=1; 45 int x1=1; 46 for (int j=1;j<=cntx;j++) 47 { 48 if (j>r||j<l) 49 { 50 if (a[j]!=b[x1]) 51 { 52 flag=0; 53 break; 54 } 55 else x1++; 56 } 57 } 58 if (flag==1) return true; 59 } 60 int boo[200]={0}; 61 for (int i=1;i<=cntx/ckt+1;i++)//jiange 62 { 63 for (int j=1;j+(ckt-1)*i<=cntx;j++)//qidian 64 { 65 int flag=1; 66 for (int k=j,num=1;num<=ckt;k+=i,num++) 67 boo[k]=j; 68 int x1=1; 69 for (int k=1;k<=cntx;k++) 70 { 71 if (boo[k]!=j) 72 { 73 if (b[x1]!=a[k]) 74 { 75 flag=0; 76 break; 77 } 78 else x1++; 79 } 80 } 81 if (flag==1) return true; 82 } 83 } 84 return false; 85 } 86 int main() 87 { 88 freopen("jumpcut.in","r",stdin); 89 freopen("jumpcut.out","w",stdout); 90 91 scanf("%d",&n); 92 int x,y; 93 for (int t=1;t<=n;t++) 94 { 95 cnty=0; 96 scanf("%d%d",&x,&y); 97 while (y!=0) 98 { 99 b[++cnty]=y%10; 100 y/=10; 101 } 102 for (int i=1;i<=1000000;i++) 103 { 104 long long now=(long long)i*x; 105 if (solve(now)) 106 { 107 printf("%lld\n",now); 108 break; 109 } 110 } 111 } 112 }
func.cpp
1 #include<cstdio> 2 #include<algorithm> 3 #include<iostream> 4 #include<cmath> 5 #include<cstring> 6 #define NN 10000007 7 #define inf 1000000007 8 9 using namespace std; 10 11 int n,cnt,ans; 12 int prime[NN],phi[NN]; 13 bool flag[NN]; 14 15 void init_prime_oula(int n) 16 { 17 for (int i=2;i<=n;i++) 18 { 19 if (flag[i]==0) 20 { 21 prime[++cnt]=i; 22 phi[i]=i-1; 23 } 24 for (int j=1;j<=cnt;j++) 25 { 26 long long x=prime[j]*i; 27 if (x>n) break; 28 int t=prime[j]*i; 29 if (t>n) break; 30 flag[t]=true; 31 if (i%prime[j]==0) 32 { 33 phi[i*prime[j]]=phi[i]*prime[j]; 34 break; 35 } 36 else phi[i*prime[j]]=phi[i]*(prime[j]-1); 37 } 38 } 39 } 40 int got_phi(int x) 41 { 42 long long res=x,k=(int)sqrt(x); 43 for (int i=1;i<=cnt;i++) 44 { 45 bool flag=0; 46 if (prime[i]>k) break; 47 while (x%prime[i]==0) 48 { 49 flag=1; 50 x/=prime[i]; 51 } 52 if (flag==0) continue; 53 res=res*(prime[i]-1); 54 res/=prime[i]; 55 } 56 if (x==1) return res; 57 res=res*(x-1); 58 res/=x; 59 } 60 void dfs(int x,int y,int time) 61 { 62 if (x==1) 63 { 64 ans=min(ans,time); 65 return; 66 } 67 if (time>=ans) return; 68 if (y>0) dfs(x/2+1,y-1,time+1); 69 if (x>10000000) x=got_phi(x); 70 else x=phi[x]; 71 dfs(x,y,time+1); 72 } 73 int main() 74 { 75 freopen("func.in","r",stdin); 76 freopen("func.out","w",stdout); 77 78 init_prime_oula(10000000); 79 80 scanf("%d",&n); 81 int x,y; 82 for (int i=1;i<=n;i++) 83 { 84 ans=inf; 85 scanf("%d%d",&x,&y); 86 dfs(x,y,0); 87 printf("%d\n",ans); 88 } 89 }
标签:color lld 变换 状态 pre def 限制 har sqrt
原文地址:http://www.cnblogs.com/fengzhiyuan/p/7522715.html