A 题 水题 将字符串的第一个字母转换成大写
#include<iostream> #include<stdio.h> #include<cstring> using namespace std; char str[1002]; int main( ) { while( scanf("%s",&str) != EOF ) { if( (str[0] - 'A' ) > 26 ) str[0] = (str[0] - '0') - 32 +'0'; printf("%s\n",str); } //system("pause"); return 0; }
B 题 将方程转化一下 然后取到 最靠近的两个值; 注意用 GNC c++ 提交
1 #include<iostream> 2 #include<stdio.h> 3 #include<cstring> 4 #include<algorithm> 5 #include<cmath> 6 #define eps 0.000000001 7 using namespace std; 8 9 int main( ) 10 { 11 double i,x,y,n,a,b,Min; 12 while( scanf("%lf%lf%lf",&x,&y,&n) != EOF ) 13 { 14 Min = 1<<30; 15 for( i = 1; i <= n; i++ ) 16 { 17 double res = x*i/y; 18 if( res - 0 < eps ) 19 { 20 a = res; b = i; 21 break; 22 } 23 double res_1 = int( res ); 24 double res_2 = int( res + 1 ); 25 bool fell = false; 26 if( abs( x/y - res_1/i ) <= abs( x/y - res_2/i ) ) 27 { 28 res = abs( x/y - res_1/i ); 29 fell = true; 30 } 31 else res = abs( x/y - res_2/i ); 32 if( res < Min ) 33 { 34 Min = res; 35 if( fell ) a = res_1; 36 else a = res_2; 37 b = i; 38 } 39 } 40 printf("%.lf/%.lf\n",a,b); 41 } 42 //system("pause"); 43 return 0; 44 }
C 题 三步 第一步 就是 角度> 90 度时,直接取 180 - a; 第二步 判断重合的多边形的模样 第一种为 四边形 第二种为平行四边形;第二种好说,直接可以出来,第一种的话 列举方程 ( 需要证明的是看下图)那个标有 a 角度的三角形和标有w 的三角形是相等的,如何证明,请连接两个正方形的对角线,利用三角形面积相等可以证明; 得到这个证明后 列举方程; 四个旋转后在外边的三角形中只有两种三角形 设他们的斜边 为 x 和 y 得到等式;
x + x*cos(a) + y*sin(a) = h;
y + y*cos(a) + x*sin(a) = w;
进一步 化简得到 可以得到方程的解;
1 #include<iostream> 2 #include<stdio.h> 3 #include<cstring> 4 #include<algorithm> 5 #include<cmath> 6 #define pi 3.141592654 7 using namespace std; 8 9 int main( ) 10 { 11 double w,h,a,res; 12 while( scanf("%lf%lf%lf",&w,&h,&a) != EOF ) 13 { 14 if( w > h )swap(w,h); 15 if( a > 90 ) // 第一步 16 a = (180-a)*pi/180.0; 17 else a = a*pi/180.0; 18 double f = atan(w/h)*2.0; 19 if( f <= a ) // 第二步 20 res = w*w/sin(a); 21 else 22 { // 第三步 23 double s = (1+cos(a)); 24 double t = sin(a); 25 double x = (s*h-t*w)/(s*s-t*t); 26 double y = (t*h-s*w)/(s*s-t*t); 27 res = w*h - x*x*sin(a)*cos(a) - y*y*sin(a)*cos(a); 28 } 29 printf("%.9lf\n",res); 30 } 31 return 0; 32 }
D 题 单调栈 先往左扫描一遍 然后 往右边扫描一遍;
1 #include<iostream> 2 #include<stdio.h> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 7 int N,arr[100005],sta[100005]; 8 9 int main( ) 10 { 11 int i,top,res; 12 while( scanf("%d",&N) != EOF ) 13 { 14 for( i = 1; i <= N; i++ ) 15 scanf("%d",&arr[i]); 16 top = 1;res = -1; 17 sta[top] = arr[1]; 18 for( i = 2; i <= N; i++ ) 19 { 20 while( arr[i] >= sta[top] && top >= 1 ) 21 res = max( res,(arr[i]^sta[top--]) ); 22 sta[++top] = arr[i]; 23 } 24 top = 1;sta[top] = arr[N]; 25 for( i = N-1; i >= 1; i-- ) 26 { 27 while( arr[i] >= sta[top] && top >= 1 ) 28 res = max( res,(arr[i]^sta[top--]) ); 29 sta[++top] = arr[i]; 30 } 31 printf("%d\n",res); 32 } 33 return 0; 34 }
E题 不会