2017计蒜客
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2017计蒜客相关的知识,希望对你有一定的参考价值。
1 #include <bits/stdc++.h> 2 using namespace std; 3 int x[100],y[100]; 4 int n,m; 5 bool find(int a,int b) 6 { 7 for(int i=0;i<n;i++) if(x[i]==a && y[i]==b) return true; 8 return false; 9 } 10 int main() 11 { 12 while(scanf("%d%d",&n,&m)==2) { 13 for(int i=0;i<n;i++) scanf("%d%d",x+i,y+i); 14 for(int j=0;j<m;j++) scanf("%*d%*d"); 15 int ans=0; 16 for(int i=0;i<n;i++) 17 { 18 for(int j=1;j<=3;j++) 19 { 20 if(find(x[i]+j,y[i]) && find(x[i]+j+j,y[i]) && !(j==2 && y[i]==0)) ans++; 21 if(find(x[i],y[i]+j) && find(x[i],y[i]+j+j) && !(j==2 && x[i]==0)) ans++; 22 } 23 } 24 printf("%d\n",ans); 25 } 26 return 0; 27 }
1 //TLE1 2 #include<bits/stdc++.h> 3 using namespace std; 4 const int N=1e6+10; 5 char s[N],t[N]; 6 int n,a,b,L,R,f[N]; 7 void getFail(char *P,int *f) 8 { 9 int m=strlen(P); 10 f[0]=0;f[1]=0; 11 for(int i=1;i<m;i++) 12 { 13 int j=f[i]; 14 while(j&& P[i]!=P[j]) j=f[j]; 15 f[i+1]=P[i] == P[j]?j+1:0; 16 } 17 } 18 int find(char *T,char *P,int *f) 19 { 20 int n=strlen(T),m=strlen(P); 21 getFail(P,f); 22 int j=0,ans=0; 23 for(int i=0;i<n;i++) 24 { 25 while(j && P[j]!=T[i]) j=f[i]; 26 if(P[j]==T[i]) j++; 27 if (j==m) ans++; 28 } 29 return ans; 30 } 31 int main() 32 { 33 while(scanf("%d%d%d%d%d",&n,&a,&b,&L,&R)==5) 34 { 35 scanf("%s",t); 36 for(int i=0,w=b;i<n;i++,w=(w+a)%n) 37 { 38 int x,y=w&1; 39 if(L<=w && w<=R) x=0; 40 else x=2; 41 switch(x|y) 42 { 43 case 0: 44 s[i]=‘A‘; 45 break; 46 case 1: 47 s[i]=‘T‘; 48 break; 49 case 2: 50 s[i]=‘G‘; 51 break; 52 case 3: 53 s[i]=‘C‘; 54 break; 55 } 56 } 57 s[n]=0; 58 puts(s); 59 printf("%d\n",find(s,t,f)); 60 } 61 return 0; 62 } 63 //TLE2 64 #include<bits/stdc++.h> 65 using namespace std; 66 const int N=1e6+10; 67 char s[N],t[N]; 68 int n,a,b,L,R,f[N]; 69 void getFail(char *P,int *f) 70 { 71 int m=strlen(P); 72 f[0]=0;f[1]=0; 73 for(int i=1;i<m;i++) 74 { 75 int j=f[i]; 76 while(j&& P[i]!=P[j]) j=f[j]; 77 f[i+1]=P[i] == P[j]?j+1:0; 78 } 79 } 80 int find(char *T,char *P,int *f) 81 { 82 int n=strlen(T),m=strlen(P); 83 getFail(P,f); 84 int j=0,ans=0; 85 for(int i=0;i<n;i++) 86 { 87 while(j && P[j]!=T[i]) j=f[i]; 88 if(P[j]==T[i]) j++; 89 if (j==m) ans++; 90 } 91 return ans; 92 } 93 int main() 94 { 95 while(scanf("%d%d%d%d%d",&n,&a,&b,&L,&R)==5) 96 { 97 scanf("%s",t); 98 for(int i=0,w=b;i<n;i++,w=(w+a)%n) 99 { 100 int x,y=w&1; 101 if(L<=w && w<=R) x=0; 102 else x=2; 103 switch(x|y) 104 { 105 case 0: 106 s[i]=‘A‘; 107 break; 108 case 1: 109 s[i]=‘T‘; 110 break; 111 case 2: 112 s[i]=‘G‘; 113 break; 114 case 3: 115 s[i]=‘C‘; 116 break; 117 } 118 } 119 s[n]=0; 120 //puts(s); 121 printf("%d\n",find(s,t,f)); 122 } 123 return 0; 124 } 125 //TLE3 126 #include<bits/stdc++.h> 127 using namespace std; 128 const int N=1e6+10; 129 char s[N],t[N]; 130 int n,a,b,L,R,f[N]; 131 void getFail(char *P,int *f,int m) 132 { 133 f[0]=0;f[1]=0; 134 for(int i=1;i<m;i++) 135 { 136 int j=f[i]; 137 while(j&& P[i]!=P[j]) j=f[j]; 138 f[i+1]=P[i] == P[j]?j+1:0; 139 } 140 } 141 int find(char *T,char *P,int *f,int n) 142 { 143 int m=strlen(P); 144 getFail(P,f,m); 145 if(m>n) return 0; 146 int j=0,ans=0; 147 for(int i=0;i<n;i++) 148 { 149 while(j && P[j]!=T[i]) j=f[i]; 150 if(P[j]==T[i]) j++; 151 if (j==m) ans++; 152 } 153 return ans; 154 } 155 int main() 156 { 157 while(scanf("%d%d%d%d%d",&n,&a,&b,&L,&R)==5) 158 { 159 scanf("%s",t); 160 for(int i=0,w=b;i<n;i++,w=(w+a)%n) 161 { 162 int x,y=w&1; 163 if(L<=w && w<=R) x=0; 164 else x=2; 165 switch(x|y) 166 { 167 case 0: 168 s[i]=‘A‘; 169 break; 170 case 1: 171 s[i]=‘T‘; 172 break; 173 case 2: 174 s[i]=‘G‘; 175 break; 176 case 3: 177 s[i]=‘C‘; 178 break; 179 } 180 } 181 s[n]=0; 182 //puts(s); 183 printf("%d\n",find(s,t,f,n)); 184 } 185 return 0; 186 } 187 //AC 188 #include<bits/stdc++.h> 189 using namespace std; 190 const int N=1e6+10; 191 char s[N],t[N]; 192 int n,a,b,L,R,f[N]; 193 void getFail(char *P,int *f,int m) 194 { 195 f[0]=0;f[1]=0; 196 for(int i=1;i<m;i++) 197 { 198 int j=f[i]; 199 while(j&& P[i]!=P[j]) j=f[j]; 200 f[i+1]=P[i] == P[j]?j+1:0; 201 } 202 } 203 int find(char *T,char *P,int *f,int n) 204 { 205 int m=strlen(P); 206 getFail(P,f,m); 207 int j=0,ans=0; 208 for(int i=0;i<n;i++) 209 { 210 while(j && P[j]!=T[i]) j=f[j]; 211 if(P[j]==T[i]) j++; 212 if (j==m) ans++; 213 } 214 return ans; 215 } 216 int main() 217 { 218 while(scanf("%d%d%d%d%d",&n,&a,&b,&L,&R)==5) 219 { 220 scanf("%s",t); 221 for(int i=0,w=b;i<n;i++,w=(w+a)%n) 222 { 223 int x,y=w&1; 224 if(L<=w && w<=R) x=0; 225 else x=2; 226 switch(x|y) 227 { 228 case 0: 229 s[i]=‘A‘; 230 break; 231 case 1: 232 s[i]=‘T‘; 233 break; 234 case 2: 235 s[i]=‘G‘; 236 break; 237 case 3: 238 s[i]=‘C‘; 239 break; 240 } 241 } 242 s[n]=0; 243 //puts(s); 244 printf("%d\n",find(s,t,f,n)); 245 } 246 return 0; 247 }
1 //WA1 2 #include <bits/stdc++.h> 3 using namespace std; 4 int main() 5 { 6 int a[4]; 7 int k,d; 8 while(scanf("%d%d%d%d",a+1,a+2,a+3,a+0)==4) 9 { 10 scanf("%d%d",&k,&d); 11 if(a[k%4]==d) 12 { 13 puts("0"); 14 continue; 15 } 16 int ans=0; 17 for(int i=1;i<=6;i++) 18 { 19 for(int j=i;j<=6;j++) 20 { 21 int b=(i+j)%4;//num user 22 int c=i+1; 23 for(int l=b,t=3;t;t--) 24 { 25 if(l==k && c==d) 26 { 27 ans++; 28 break; 29 } 30 c+=8; 31 if(c>a[l]) c-=a[l],l=(l+3)%4; 32 } 33 } 34 } 35 printf("%d\n",ans); 36 } 37 return 0; 38 } 39 //WA2 40 #include <bits/stdc++.h> 41 using namespace std; 42 int main() 43 { 44 int a[4]; 45 int k,d; 46 while(scanf("%d%d%d%d",a+1,a+2,a+3,a+0)==4) 47 { 48 scanf("%d%d",&k,&d); 49 if(a[k%4]==d) 50 { 51 puts("0"); 52 continue; 53 } 54 int ans=0; 55 for(int i=1;i<=6;i++) 56 { 57 for(int j=i;j<=6;j++) 58 { 59 int b=(i+j)%4;//num user 60 int c=i+1; 61 for(int l=b,t=3;t;t--) 62 { 63 if(l==k && c==d) 64 { 65 ans++; 66 break; 67 } 68 c+=8; 69 while(c>a[l]) c-=a[l],l=(l+3)%4; 70 } 71 } 72 } 73 printf("%d\n",ans); 74 } 75 return 0; 76 } 77 //WA3 78 #include <bits/stdc++.h> 79 using namespace std; 80 int main() 81 { 82 int a[4]; 83 int k,d; 84 while(scanf("%d%d%d%d",a+1,a+2,a+3,a+0)==4) 85 { 86 scanf("%d%d",&k,&d); 87 int ans=0; 88 for(int i=1;i<=6;i++) 89 { 90 for(int j=i;j<=6;j++) 91 { 92 int b=(i+j)%4;//num user 93 int c=i+1; 94 for(int l=b,t=3;t;t--) 95 { 96 if(l==k && c==d) 97 { 98 ans++; 99 break; 100 } 101 c+=8; 102 while(c>a[l]) 103 { 104 c-=a[l]; 105 l=(l+3)%4; 106 } 107 } 108 } 109 } 110 printf("%d\n",ans); 111 } 112 return 0; 113 } 114 //WA4 115 #include <bits/stdc++.h> 116 using namespace std; 117 int main() 118 { 119 int a[4]; 120 int k,d; 121 while(scanf("%d%d%d%d",a+1,a+2,a+3,a+0)==4) 122 { 123 scanf("%d%d",&k,&d); 124 k%=4; 125 int ans=0; 126 for(int i=1;i<=6;i++) 127 { 128 for(int j=i;j<=6;j++) 129 { 130 int b=(i+j)%4;//num user 131 int c=i+1; 132 for(int l=b,t=3;t;t--) 133 { 134 if(l==k && c==d) 135 { 136 ans++; 137 break; 138 } 139 c+=8; 140 while(c>a[l]) 141 { 142 c-=a[l]; 143 l=(l+3)%4; 144 } 145 } 146 } 147 } 148 printf("%d\n",ans); 149 } 150 return 0; 151 } 152 //AC 153 #include <bits/stdc++.h> 154 using namespace std; 155 int main() 156 { 157 int a[4]; 158 int k,d; 159 while(scanf("%d%d%d%d",a+1,a+2,a+3,a+0)==4) 160 { 161 scanf("%d%d",&k,&d); 162 k%=4; 163 int ans=0; 164 for(int i=1;i<=6;i++) 165 { 166 for(int j=i;j<=6;j++) 167 { 168 int b=(i+j)%4;//num user 169 int c=i+1; 170 for(int l=b,t=3;t;t--) 171 { 172 while(c>a[l]) 173 { 174 c-=a[l]; 175 l=(l+3)%4; 176 } 177 if(l==k && c==d) 178 { 179 ans++; 180 break; 181 } 182 c+=8; 183 } 184 } 185 } 186 printf("%d\n",ans); 187 } 188 return 0; 189 }
1 //赛后WA1 2 #include <bits/stdc++.h> 3 using namespace std; 4 map<string,int>op; 5 map<string,string>func; 6 const int N=1e3+10; 7 char s[N],tf1[N],tf2[N]; 8 string getNum(char *s,int &i) 9 { 10 string res=""; 11 while(isdigit(s[i])) res+=s[i],i++; 12 if(s[i]==‘.‘) res+=s[i],i++; 13 else return res; 14 while(isdigit(s[i])) res+=s[i],i++; 15 return res; 16 } 17 string getOp(char *s,int &i) 18 { 19 string res=""; 20 while(isalnum(s[i])) res+=s[i],i++; 21 res+=s[i],i++; 22 return res; 23 } 24 string solve(char *s) 25 { 26 stack<string>ops; 27 stack<string>num; 28 ops.push("#"); 29 int i=0; 30 while(s[i]!=‘#‘ || ops.top()!="#") 31 { 32 //printf("%c\n",s[i]); 33 if(isdigit(s[i])) 34 { 35 num.push(getNum(s,i)); 36 //cout<<"numtop:"<<num.top()<<endl; 37 continue; 38 } 39 string oper=getOp(s,i); 40 if(ops.top()=="(" && oper==")") 41 { 42 ops.pop(); 43 continue; 44 } 45 if(oper=="(" || op[ops.top()]<op[oper]) 46 { 47 ops.push(oper); 48 continue; 49 } 50 for(int j=oper.length()-1;j>=0;j--) s[--i]=oper[j]; 51 //cout<<"top"<<num.top()<<endl; 52 string num1=num.top();num.pop(); 53 string num2=num.top();num.pop(); 54 string ope=ops.top();ops.pop(); 55 char num3[100]; 56 if(num1.find(‘.‘)==-1 && num2.find(‘.‘)==-1) 57 { 58 long long a,b; 59 b=atoi(num1.c_str()); 60 a=atoi(num2.c_str()); 61 //cout<<a<<ope<<b<<endl; 62 long long ans; 63 if(ope=="+") ans=a+b; 64 else if(ope=="-") ans=a-b; 65 else if(ope=="*") ans=a*b; 66 else if(ope=="/") ans=a/b; 67 sprintf(num3,"%lld",ans); 68 } 69 else 70 { 71 double a,b,ans; 72 b=atof(num1.c_str()); 73 a=atof(num2.c_str()); 74 //cout<<a<<ope<<b<<endl; 75 if(ope=="+") ans=a+b; 76 else if(ope=="-") ans=a-b; 77 else if(ope=="*") ans=a*b; 78 else if(ope=="/") ans=a/b; 79 sprintf(num3,"%.6f",ans); 80 } 81 //cout<<"num3:"<<num3<<endl; 82 num.push(num3); 83 } 84 return num.top(); 85 } 86 int main() 87 { 88 op["#"]=0; 89 op["("]=1; 90 op["+"]=2; 91 op["-"]=2; 92 op["*"]=3; 93 op["/"]=3; 94 op[")"]=1; 95 op["int("]=1; 96 op["float("]=1; 97 int n; 98 while(scanf("%d",&n)==1) 99 { 100 for(int i=0;i<n;i++) 101 { 102 scanf("%[^=]=%s",tf1,tf2); 103 tf2[strlen(tf2)]=‘#‘; 104 func[tf1]=tf2; 105 } 106 scanf("%s",s); 107 s[strlen(s)]=‘#‘; 108 string ans=solve(s); 109 cout<<ans<<endl; 110 } 111 return 0; 112 } 113 //赛后AC 114 #include <bits/stdc++.h> 115 using namespace std; 116 map<string,int>op; 117 map<string,string>func; 118 const int N=1e3+10; 119 char s[N],tf1[N],tf2[N]; 120 string getNum(char *s,int &i) 121 { 122 string res=""; 123 while(isdigit(s[i])) res+=s[i],i++; 124 if(s[i]==‘.‘) res+=s[i],i++; 125 else return res; 126 while(isdigit(s[i])) res+=s[i],i++; 127 return res; 128 } 129 string getOp(char *s,int &i) 130 { 131 string res=""; 132 while(isalnum(s[i])) res+=s[i],i++; 133 res+=s[i],i++; 134 return res; 135 } 136 string solve(char *s) 137 { 138 stack<string>ops; 139 stack<string>num; 140 ops.push("#"); 141 int i=0; 142 string neg=""; 143 if(s[i]==‘-‘) neg="-",i++; 144 while(s[i]!=‘#‘ || ops.top()!="#") 145 { 146 //printf("%c\n",s[i]); 147 if(isdigit(s[i])) 148 { 149 num.push(neg+getNum(s,i)); 150 neg=""; 151 //cout<<"numtop:"<<num.top()<<endl; 152 continue; 153 } 154 string oper=getOp(s,i); 155 if(ops.top()=="(" && oper==")") 156 { 157 ops.pop(); 158 continue; 159 } 160 if(oper=="(" || op[ops.top()]<op[oper]) 161 { 162 ops.push(oper); 163 if(oper=="(") 164 { 165 if(s[i]==‘-‘) neg="-",i++; 166 } 167 continue; 168 } 169 for(int j=oper.length()-1;j>=0;j--) s[--i]=oper[j]; 170 //cout<<"top"<<num.top()<<endl; 171 string num1=num.top();num.pop(); 172 string ope=ops.top();ops.pop(); 173 string num2=num.top();num.pop(); 174 char num3[100]; 175 if(num1.find(‘.‘)==-1 && num2.find(‘.‘)==-1) 176 { 177 long long a,b; 178 sscanf(num1.c_str(),"%lld",&b); 179 sscanf(num2.c_str(),"%lld",&a); 180 //cout<<a<<ope<<b<<endl; 181 long long ans; 182 if(ope=="+") ans=a+b; 183 else if(ope=="-") ans=a-b; 184 else if(ope=="*") ans=a*b; 185 else if(ope=="/") ans=a/b; 186 sprintf(num3,"%lld",ans); 187 } 188 else 189 { 190 double a,b,ans; 191 sscanf(num1.c_str(),"%lf",&b); 192 sscanf(num2.c_str(),"%lf",&a); 193 //cout<<a<<ope<<b<<endl; 194 if(ope=="+") ans=a+b; 195 else if(ope=="-") ans=a-b; 196 else if(ope=="*") ans=a*b; 197 else if(ope=="/") ans=a/b; 198 sprintf(num3,"%.6f",ans); 199 } 200 //cout<<"num3:"<<num3<<endl; 201 num.push(num3); 202 } 203 return num.top(); 204 } 205 int main() 206 { 207 op["#"]=0; 208 op["("]=1; 209 op["+"]=2; 210 op["-"]=2; 211 op["*"]=3; 212 op["/"]=3; 213 op[")"]=1; 214 op["int("]=1; 215 op["float("]=1; 216 int n; 217 while(scanf("%d",&n)==1) 218 { 219 for(int i=0;i<n;i++) 220 { 221 scanf("%[^=]=%s",tf1,tf2); 222 tf2[strlen(tf2)]=‘#‘; 223 func[tf1]=tf2; 224 } 225 scanf("%s",s); 226 s[strlen(s)]=‘#‘; 227 string ans=solve(s); 228 cout<<ans<<endl; 229 } 230 return 0; 231 }
以上是关于2017计蒜客的主要内容,如果未能解决你的问题,请参考以下文章