链接:http://codeforces.com/contest/1
A题: 水题, 依然wa了一次, 没注意用 I64 , 下次一点要注意一下数据范围;
View Code
1 #include <iostream> 2 #include <cmath> 3 #include <cstring> 4 #include <cstdio> 5 #include <string> 6 #include <stdlib.h> 7 using namespace std; 8 9 int main( ) 10 { 11 int m, n, a; 12 while(scanf( "%d%d%d",&m, &n, &a ) ==3){ 13 long long ans=1; 14 if( m%a ) 15 ans*=(m/a+1); 16 else ans*=(m/a); 17 if( n%a ) 18 ans*=( n/a+1 ); 19 else ans*=(n/a); 20 printf( "%I64d\n", ans ); 21 } 22 return 0; 23 }
B题:题意:在Excel中,一个格子的位置有2种表示:例如第23行第55列
①R23C55
②BC23
第一种表示方法很直观。第二种表示方法中BC表示列。23表示行。
1-26列:A, B, C...Z27-?列:AA, AB, AC...AZ, BA, BB, BC...ZZ
跟进制的转换很类似~
View Code
1 /* 2 题意:在Excel中,一个格子的位置有2种表示: 3 例如第23行第55列 4 ①R23C55 5 ②BC23 6 第一种表示方法很直观。 7 第二种表示方法中BC表示列。23表示行。 8 1-26列:A, B, C...Z 9 27-?列:AA, AB, AC...AZ, BA, BB, BC...ZZ 10 ?-?:AAA...ZZZ... 11 跟进制的转换很类似! 12 输入任意一种表示,你的任务是输出另一种表示 13 */ 14 #include <iostream> 15 #include <cmath> 16 #include <cstring> 17 #include <cstdio> 18 #include <string> 19 #include <stdlib.h> 20 using namespace std; 21 char s[1000]; 22 char ans[100]; 23 int main( ) 24 { 25 int T; 26 scanf("%d", &T ); 27 while( T -- ){ 28 scanf( "%s", s ); 29 int len=strlen( s ); 30 int key=0; 31 for( int i=1; i<len; ++ i ){ 32 if( s[i]>='A'&&s[i]<='Z'&& s[i-1]>='0'&&s[i-1]<='9' ){ 33 key++; 34 } 35 if( s[i-1]>='A'&&s[i-1]<='Z'&& s[i]>='0'&&s[i]<='9' ){ 36 key++; 37 } 38 } 39 if( key>1){ 40 int r=0, i, k=0; 41 for( i=1; ;++ i ){ 42 if( s[i]>='A'&&s[i]<='Z' ) 43 break; 44 } 45 key=i; 46 for( i++; i<len; ++ i ){ 47 r*=10; 48 r+=s[i]-'0'; 49 } 50 memset( ans, 0, sizeof ans); 51 while( r>0 ){ 52 r--; 53 ans[k++]=r%26+'A'; 54 r/=26; 55 } 56 s[key]='\0'; 57 len=strlen( ans ); 58 for( i=len-1; i>=0; --i ) 59 printf( "%c", ans[i] ); 60 printf( "%s\n", s+1 ); 61 62 } else{ 63 int i, r=0, c=0; 64 for( i=0; i<len; ++ i ){ 65 if( s[i]>='A'&&s[i]<='Z' ){ 66 c*=26; 67 c+=s[i]-'A'+1; 68 }else{ 69 r*=10; 70 r+=s[i]-'0'; 71 } 72 } 73 printf( "R%dC%d\n", r, c ); 74 } 75 } 76 return 0; 77 }
C题 :
题意:给三个点,要求这三个点是一个正n边形的三个顶点,而这个正n边形面积最小是多少;
思路:利用余弦定理和正弦定理求三角形的三个内角,和外接圆半径.
之后更关键的一点是这三个点组成的三角形的每个内角都是以这个圆为外接圆的正n边形的任意一条边的圆周角的整数倍~
因为其他点都是三角形所对的弧的等分点;
View Code
1 /* 2 题意:有一个正n边形 3 输入正n边形的其中3个点 4 问正n边形可能存在的最小面积,已知n<=100 5 */ 6 #include <cmath> 7 #include <cstdio> 8 #include <iostream> 9 using namespace std; 10 const double Pi=acos( -1 ); 11 const double eps=1e-6; 12 13 struct Point 14 { 15 double x, y; 16 }A, B, C; 17 double a, b, c, ag, agA, agB, agC, cA, cB, cC, R, ans; 18 double Dis( Point A, Point B ) 19 { 20 return sqrt( (A.x-B.x)*(A.x-B.x)+(A.y-B.y)*( A.y-B.y ) ); 21 } 22 void Init( ) // 求角 , 边, 半径 23 { 24 a=Dis( B, C ); 25 b=Dis( A, C ); 26 c=Dis( A, B ); 27 cA=(b*b+c*c-a*a)/(2.0*b*c); 28 cB=(a*a+c*c-b*b)/(2.0*a*c); 29 cC=(a*a+b*b-c*c)/(2.0*a*b); 30 agA=acos( cA ); 31 agB=acos( cB ); 32 agC=acos( cC ); 33 R=0.5*a/sin(agA); 34 } 35 bool Test( double a, double b )// 比较 36 { 37 double t=a; 38 if( fabs( b-a )<eps )return true; 39 while( b-a>eps ){ 40 a+=t; 41 if( fabs( b-a )<eps )return true; 42 } 43 return false; 44 } 45 int main( ) 46 { 47 while( ~scanf( "%lf%lf%lf%lf%lf%lf", &A.x, &A.y, &B.x, &B.y, &C.x, &C.y ) ){ 48 Init( ); 49 for( int i=3; i<=100; ++ i ){ // N越小 面积越小 相当于求三个内角的最小公约数; 50 ag=Pi/i; 51 if( Test( ag, agA )&& Test( ag, agB )&& Test( ag, agC ) ){ 52 ans=0.5*i*R*R*sin( 2*ag ); 53 printf( "%lf\n", ans ); 54 break; 55 } 56 } 57 } 58 return 0; 59 }