7.25第一次组队赛
Problem A UVA 11877
直接输出n/2
1 #include <stdio.h> 2 int main() 3 { 4 int n; 5 while(~scanf("%d",&n) && n) 6 { 7 printf("%d\n",n/2); 8 } 9 return 0; 10 }
也可以模拟
1 #include <stdio.h> 2 int main() 3 { 4 int n; 5 while(scanf("%d",&n)==1 && n) 6 { 7 int Sum=0; 8 while(n>=3) 9 { 10 Sum+=n/3; 11 n=n/3+n%3; 12 } 13 if(n==2) 14 { 15 ++Sum; 16 } 17 printf("%d\n",Sum); 18 } 19 return 0; 20 }
Problem B UVA 11878
不解释
1 #include <stdio.h> 2 3 int main() 4 { 5 int a, b, res, ans = 0; 6 char op, re[3]; 7 while(~scanf("%d%c%d=%s", &a, &op, &b, re)) 8 { 9 if(re[0] == '?')continue; 10 sscanf(re,"%d", &res); 11 if(op == '-' && a-b == res)ans ++; 12 else if(op == '+' && a+b == res)ans++; 13 } 14 printf("%d\n",ans); 15 return 0; 16 }
Problem C UVA 11879
java水过
1 import java.math.*; 2 import java.util.*; 3 import java.io.*; 4 5 public class Main{ 6 public static void main(String[] args) throws Exception 7 { 8 Scanner cin = new Scanner(new BufferedInputStream(System.in)); 9 BigInteger p; 10 while(cin.hasNext()) 11 { 12 p = cin.nextBigInteger(); 13 if(p.equals(BigInteger.valueOf(0)))break; 14 BigInteger ten = new BigInteger("10"); 15 BigInteger five = new BigInteger("5"); 16 BigInteger Seventeen = new BigInteger("17"); 17 BigInteger divideTen = p.divide(ten); 18 BigInteger flag =divideTen; 19 divideTen= divideTen.multiply(ten); 20 BigInteger cha = p.subtract(divideTen); 21 cha = cha.multiply(five); 22 flag = flag.subtract(cha); 23 BigInteger temp = flag; 24 flag = flag.divide(Seventeen); 25 flag = flag.multiply(Seventeen); 26 boolean ok = temp.equals(flag); 27 System.out.println(ok == true ? 1 : 0); 28 } 29 } 30 }
Problem E UVA 12289
1 #include<stdio.h> 2 #include<string.h> 3 4 int Same(char *str,const char *cmp) 5 { 6 int s=0; 7 for(int i=0;str[i]&&cmp[i];++i) 8 { 9 if(str[i]==cmp[i]) ++s; 10 } 11 return s; 12 } 13 14 int main() 15 { 16 int T; 17 char str[1005]; 18 while(scanf("%d",&T)==1) while(T--) 19 { 20 scanf("%s",str); 21 if(strlen(str)==5) 22 { 23 printf("3\n"); 24 } 25 else 26 { 27 int Same1=Same(str,"one"); 28 int Same2=Same(str,"two"); 29 printf("%d\n",Same1>Same2?1:2); 30 } 31 } 32 return 0; 33 }
Problem F UVA 12290
按照每次增加的个数,直接暴力,应为报数不会超过80000
1 #include <stdio.h> 2 3 int judge(int n) 4 { 5 if(n%7 == 0)return 1; 6 while(n) 7 { 8 if(n%10 == 7)return 1; 9 n/=10; 10 } 11 return 0; 12 } 13 14 int main() 15 { 16 int n,m,k; 17 while(~scanf("%d%d%d", &n,&m,&k) &&(m||n||k)) 18 { 19 int ans = 0,bao = m; 20 if(judge(bao)){k--;} 21 ans = bao; 22 while(k) 23 { 24 bao+=(2*(n-m)); 25 if(judge(bao)){ans = bao;k--;} 26 if(!k)break; 27 bao += (2*(m-1)); 28 if(judge(bao)){ans = bao;k--;} 29 if(n==m || m==1)if(judge(bao))k++; 30 } 31 printf("%d\n",ans); 32 } 33 return 0; 34 }
Problem G UVA 12293
推导得必输态为2^k - 1
1 #include <stdio.h> 2 #include <math.h> 3 4 int main() 5 { 6 double n; 7 while(~scanf("%lf",&n) && n ) 8 { 9 n+=1; 10 double ans = log(n)/log(2); 11 printf("%s\n", ans==(int)ans ? "Bob" : "Alice"); 12 } 13 return 0; 14 }
Problem J ZOJ 3714
取前导和,求距离为d的差的最大值
1 #include <stdio.h> 2 #define MAX(a,b) (a) > (b) ? (a) : (b) 3 int main() 4 { 5 int Case; 6 while(~scanf("%d", &Case))while(Case --) 7 { 8 int sum[402] = {0},n,m,a,ans=0; 9 scanf("%d%d", &n,&m); 10 for(int i=1;i<=n;i++) 11 { 12 scanf("%d",&a); 13 sum[i]=sum[i-1]+a; 14 sum[i+n] = sum[i]; 15 } 16 for(int i=m;i<=n+m;i++) 17 { 18 if(i>n)sum[i]+=sum[n]; 19 ans = MAX(ans, sum[i]-sum[i-m]); 20 } 21 printf("%d\n", ans); 22 } 23 return 0; 24 }
Problem K ZOJ 3706
1 #include <stdio.h> 2 #include <string.h> 3 4 #define MAX(a,b) (a)>(b)?(a):(b) 5 6 const int Hash[3]={-1,0,1}; 7 8 int x,y; 9 10 int Cnt(int a,int b,int c) 11 { 12 bool HashCnt[500]; 13 memset(HashCnt,0,sizeof(HashCnt)); 14 for(int i=0;i<3;++i) 15 { 16 for(int j=0;j<3;++j) 17 { 18 for(int k=0;k<3;++k) 19 { 20 int sss=a*Hash[i]+b*Hash[j]+c*Hash[k]; 21 if(sss>0) 22 { 23 HashCnt[sss]=true; 24 } 25 } 26 } 27 } 28 int sum=0; 29 for(int m=1;m<=x+y;++m) 30 { 31 sum+=HashCnt[m]; 32 } 33 return sum; 34 } 35 36 37 int main() 38 { 39 int T; 40 while(scanf("%d",&T)==1) while(T--) 41 { 42 scanf("%d%d",&x,&y); 43 int Ans=0; 44 for(int i=1;i+i<=x;++i) 45 { 46 int Kep=Cnt(i,x-i,y); 47 Ans=MAX(Ans,Kep); 48 } 49 for(int j=1;j+j<=y;++j) 50 { 51 int Kep=Cnt(x,j,y-j); 52 Ans=MAX(Ans,Kep); 53 } 54 printf("%d\n",Ans); 55 } 56 return 0; 57 }