Codeforces Beta Round #1

A:大水题;

代码:

 1 #include<iostream>
 2 #define ll long long
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     ll n,m,a;
 8     cin>>n>>m>>a;
 9     cout<<(((n+a-1)/a)*((m+a-1)/a));
10     return 0;
11 }
View Code

B:灵活的运用sscanf

代码:

 1 #include<cstdio>
 2 #include<cstring>
 3 #define maxn 1000005
 4 using namespace std;
 5 int n;
 6 char s[50];
 7 void a_to_b()
 8 {
 9     int a,b;
10     int p=maxn-1;
11     char t[maxn];
12     sscanf(s,"R%dC%d",&a,&b);
13     t[p--]=0;
14     while(a)
15     {
16         t[p--]=a%10+'0';
17         a/=10;
18     }
19     while(b)
20     {
21         t[p--]=(b-1)%26+'A';
22         b=(b-1)/26;
23     }
24     printf("%s
",&t[p+1]);
25 }
26 
27 void b_to_a()
28 {
29     char t[maxn];
30     int c = 0;
31     int r;
32     sscanf(s,"%[A-Z]%d",t,&r);
33     int len = strlen(t);
34     int p = 0;
35     while (p<len)
36     {
37         c+=t[p++]-'A'+1;
38         c*=26;
39     }
40     c/=26;
41     printf("R%dC%d
",r,c);
42 }
43 
44 int main()
45 {
46     int a,b;
47     scanf("%d",&n);
48     while(n--)
49     {
50         scanf("%s",s);
51         if(sscanf(s,"R%dC%d",&a,&b)==2)a_to_b();
52         else b_to_a();
53     }
54     return 0;
55 }
View Code

C:

很水的一个计算几何,关键是枚举,因为最多100个角;

稍微要用到一点圆的知识,因为它是正的多边形,所以所有的点都在外接圆上,判断三角形的内角是否是单位圆心角一半的倍数;

代码:

 1 #include<cstdio>
 2 #include<cmath>
 3 #define eps 0.0001
 4 #define pi acos(-1)
 5 using namespace std;
 6 
 7 struct point
 8 {
 9     double x,y;
10     point(double x=0,double y=0):x(x),y(y){ }
11 }p[3];
12 point operator - (point a,point b){return point(a.x-b.x,a.y-b.y);}
13 double dis(point a,point b){return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}
14 double cross(point a,point b){return a.x*b.y-a.y*b.x;}
15 
16 bool isok(double a,int n)
17 {
18     double alph=a*n/pi;
19     double x=floor(alph+eps);
20     if(alph-x<eps)return 1;
21     return 0;
22 }
23 
24 int main()
25 {
26     for(int i=0;i<3;i++)scanf("%lf%lf",&p[i].x,&p[i].y);
27     double d1=dis(p[0],p[2]);
28     double d2=dis(p[1],p[0]);
29     double d3=dis(p[2],p[1]);
30     double a=asin(cross(p[1]-p[0],p[2]-p[0])/d1/d2);
31     double b=asin(cross(p[2]-p[1],p[0]-p[1])/d2/d3);
32     double c=asin(cross(p[0]-p[2],p[1]-p[2])/d3/d1);
33     double r=d1*d2*d3/2/cross(p[1]-p[0],p[2]-p[0]);
34     int i;
35     for(i=3;i<=100;i++)
36         if(isok(a,i)&&isok(b,i)&&isok(c,i))break;
37     double ans=i*r*r*sin(2*pi/i)*0.5;
38     printf("%lf",ans);
39 }
View Code
原文地址:https://www.cnblogs.com/yours1103/p/3375004.html