1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cmath> 5 using namespace std; 6 int a[100],b[100]; 7 int main(){ 8 int r,c; 9 scanf("%d %d",&r,&c); 10 11 int max1=0,max2=0; 12 for(int i=0;i<r;i++){ 13 scanf("%d",&a[i]); 14 if(max1<a[i]){ 15 max1=a[i]; 16 } 17 18 } 19 for(int j=0;j<r;j++){ 20 scanf("%d",&b[j]); 21 if(max2<b[j]){ 22 max2=b[j]; 23 } 24 } 25 if(max1==max2){ 26 printf("possible\n"); 27 }else{ 28 printf("impossible\n"); 29 } 30 31 32 33 }
E.Exits in Excess
题目:对于酒吧里面多余的走廊进行删除,以便不会让人在里面绕圈
思路:给走廊分类,一类从小号码通向大号码的走廊,另一类是大号码通向小号码的走廊,谁的数量少就输出哪个的位置,如果一样,随便输出即可
1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<string> 5 using namespace std; 6 int b[200000]={}; 7 int main(){ 8 int t1=0,t2=0,m,n,num1=0,num2=0; 9 scanf("%d %d",&m,&n); 10 for(int i=0;i<n;i++){ 11 b[i]=-1; 12 } 13 for(int i=0;i<n;i++){ 14 scanf("%d %d",&num1,&num2); 15 if(num1<num2){ 16 b[i]=0; 17 t1++; 18 }else{ 19 b[i]=1; 20 t2++; 21 } 22 } 23 if(t1<t2){ 24 printf("%d\n",t1); 25 for(int j=0;j<n;j++){ 26 if(b[j]==0){ 27 printf("%d\n",j+1); 28 } 29 } 30 }else if(t1>t2){ 31 printf("%d\n",t2); 32 for(int j=0;j<n;j++){ 33 if(b[j]==1){ 34 printf("%d\n",j+1); 35 } 36 } 37 }else{ 38 printf("%d\n",t1); 39 for(int j=0;j<n;j++){ 40 if(b[j]==0){ 41 printf("%d\n",j+1); 42 } 43 } 44 } 45 }
F.Floor Plan
题意:就是计算n=m^2-k^2,有没有整数m,k存在
思路:m^2-k^2=(m+k)(m-k),由此进行查找n的因数,然后进行判断求解
1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<string> 5 #include<cmath> 6 using namespace std; 7 8 int main(){ 9 long long int n,t,m,num1,num2,flag=0; 10 double s; 11 scanf("%lld",&n); 12 s=sqrt(n); 13 num1=sqrt(n); 14 if(num1*num1==n){ 15 flag=1; 16 printf("%lld 0\n",num1); 17 }else{ 18 for(int i=1;i<s;i++){ 19 t=n/i; 20 if(t*i==n){ 21 if(t%2==0&&i%2==0){ 22 flag=1; 23 printf("%lld %lld\n",(t+i)/2,abs((t-i)/2)); 24 break; 25 }else if(t%2==1&&i%2==1){ 26 flag=1; 27 printf("%lld %lld\n",(t+i)/2,abs((t-i)/2)); 28 break; 29 } 30 } 31 } 32 } 33 if(flag==0){ 34 printf("impossible\n"); 35 } 36 }
G.Greetings
题意:遇到‘e'则输出两个e
思路:直接遍历
1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cmath> 6 using namespace std; 7 char a[1000]; 8 int main(){ 9 gets(a); 10 int len; 11 len=strlen(a); 12 for(int i=0;i<len;i++){ 13 if(a[i]=='e'){ 14 printf("ee"); 15 }else{ 16 printf("%c",a[i]); 17 } 18 } 19 }I.Inquiry I 题目:求题目所给公式的最大值 思路:边读入边计算平方和,再进行遍历
1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cmath> 6 using namespace std; 7 8 int main(){ 9 long long int sum=0,s=0; 10 vector<int> a; 11 int n,i=0,num; 12 scanf("%d",&n); 13 14 for(int i=0;i<n;i++){ 15 scanf("%d",&num); 16 a.push_back(num); 17 sum+=a[i]*a[i]; 18 19 } 20 long long int result=0; 21 for(int i=n-1;i>=1;i--){ 22 sum-=a[i]*a[i]; 23 s+=a[i]; 24 result=max(result,sum*s); 25 } 26 printf("%lld",result); 27 }