Codeforces Beta Round #1【完整题解】

6 篇文章 0 订阅
4 篇文章 0 订阅
[size=medium]KIDx 的解题报告
[url]http://codeforces.com/contest/1[/url]
[color=brown]以下省略头文件[/color]

[color=red]A题[/color]
[color=brown]水题[/color]
[/size]

int main()
{
LL n, m, a, res;
while (~scanf ("%I64d%I64d%I64d", &n, &m, &a))
{
res = ((n+a-1) / a) * ((m+a-1) / a);
printf ("%I64d\n", res);
}
return 0;
}


[size=medium][color=green]B题[/color]
[color=brown]题意:在Excel中,一个格子的位置有2种表示:
例如第23行第55列
①R23C55
②BC23
第一种表示方法很直观。
第二种表示方法中BC表示列。23表示行。
1-26列:A, B, C...Z
27-?列:AA, AB, AC...AZ, BA, BB, BC...ZZ
?-?:AAA...ZZZ...
跟进制的转换很类似!
输入任意一种表示,你的任务是输出另一种表示
[/color]
[/size]

int main()
{
char s[105];
int t, i, len, key, r, c, k;
scanf ("%d", &t);
while (t--)
{
scanf ("%s", s);
len = strlen (s);
key = 0;
for (i = 1; i < len; i++)
if (isalpha (s[i-1]) && !isalpha (s[i]))
key++;
if (key == 1) //输入的是第二种表示,如BC23
{
c = 0; //求是第几列
for (i = 0; i < len; i++)
{
if (!isalpha (s[i]))
break;
c *= 26;
c += s[i] - 'A' + 1;
}
r = 0; //求是第几行
for (; i < len; i++)
r *= 10, r += s[i] - '0';
printf ("R%dC%d\n", r, c);
}
else //输入的是第一种表示,如R23C55
{
r = 0; //求是第几行
for (i = 1; i < len; i++)
{
if (s[i] == 'C')
break;
r *= 10;
r += s[i] - '0';
}
i++;
c = 0; //求是第几列
for (; i < len; i++)
c *= 10, c += s[i] - '0';
k = 0;
while (c) //将列转换成字母表示形式
{ //跟普通的进制转换有区别!
c--; //突破口!琢磨很久才出来的一个想法!
s[k++] = c % 26 + 'A';
c /= 26;
}
for (i = k-1; i >= 0; i--)
printf ("%c", s[i]);
printf ("%d\n", r);
}
}
return 0;
}


[size=medium][color=blue]C题[/color]
参考白衣少年:[url]http://hi.baidu.com/%B0%D7%D2%C2%C9%D9%C4%EA2012/blog/item/abb86a05be0953037bec2cfe.html[/url]
[color=brown]题意:有一个正n边形
输入正n边形的其中3个点
问正n边形可能存在的最小面积,已知n<=100
该题关键技巧就是要画外接圆,然后玩玩圆周角,圆心角这些概念,当个平面几何问题,先尽量多推出一些结论。
具体解法如下:
首先,随便画个正多少边形,画个外接圆。根据正弦定理,可以直接知道外接圆半径。把这三个点连成一个三角形,三个角都会是正x边形的一个边对应这个外接圆的圆周角的整数倍。由于x很小,枚举+判断就可以了。
三角形外接圆半径公式:
[img]http://dl.iteye.com/upload/attachment/582912/6b3f3b18-9db8-3d28-8619-552e6917bbe8.png[/img]
每条边所对应的圆心角 = 2*PI/n
所以圆周角 = 圆心角/2 = PI/n
正n边形面积:
[img]http://dl.iteye.com/upload/attachment/582923/b76ab3fa-e406-31f2-ab9b-554fe03af35e.png[/img][/color][/size]

const double EP = 1e-3;
const double PI = 3.1415926535897932384626433832795;

struct point{
double x, y;
}p[5];

double dist (point a, point b)
{
return sqrt ((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
}

double area2 (point a, point b, point c)
{
return fabs(a.x*b.y+b.x*c.y+c.x*a.y-c.x*b.y-b.x*a.y-a.x*c.y);
}

bool isok (int n, double ang) //判断三角形的角ang是不是边对应圆周角PI/n的整数倍
{
double tp = n*ang/PI; //思路:判断相除的结果是不是整数
double x = floor(tp+EP);
if (tp - x < EP)
return true;
return false;
}

int main()
{
int i, n;
double r, a, b, c, s, A, B, C, Rang;
while (~scanf ("%lf%lf", &p[0].x, &p[0].y))
{
for (i = 1; i < 3; i++)
scanf ("%lf%lf", &p[i].x, &p[i].y);
a = dist (p[0], p[1]);
b = dist (p[0], p[2]);
c = dist (p[1], p[2]);
A = acos ((b*b + c*c - a*a) / 2 / b / c);
B = acos ((a*a + c*c - b*b) / 2 / a / c);
C = acos ((b*b + a*a - c*c) / 2 / b / a);
s = area2 (p[0], p[1], p[2]); //求三角形的面积的2倍
/*double p = (a+b+c)/2;
s = sqrt (p*(p-a)*(p-b)*(p-c));*/
r = a*b*c/2/s; //由于s已经是三角形面积的2倍了,所以除以2即可
for (n = 3; n <= 100; n++) //枚举边数,边越小面积越小
if (isok (n, A) && isok (n, B) && isok (n, C))
break;
Rang = PI/n; //中心角的一半
double res = n*r*r*sin(Rang)*cos(Rang);
printf ("%.8f\n", res);
}
return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值