您的位置:首页 > 其它

ACM-PKU

2011-05-05 22:42 309 查看
PKU 题号1004,题目Financial Management

求12个浮点数的平均数,比较水的题目。注意打印的时候,“%.2f”C语言自动完成四舍五入了。

#include<stdio.h>
#define  ONLINE
void online()
{
#ifdef ONLINE
#else
freopen("Financial.in", "r", stdin);
freopen("Financial.out", "w", stdout);
#endif
}
int main()
{
online();
float sum = 0.000;
float month = 0.000;
for (int i = 0; i < 12; i ++)
{
scanf("%f", &month);
sum += month;
}
sum = sum / 12;
printf("$%.2f", sum);
return 0;
}


题号:1005,题目I Think I Need a Houseboat

以原点为中心的半圆进行腐蚀,每年的腐蚀面积为50平米,问点P能够支撑多少年不被腐蚀到。可以计算以原点O到P为半径的半圆的面积,然后除以50每年,即得到年数,取整+1,也是水题。

#include <stdio.h>
#define ONLINE
void online()
{
#ifdef ONLINE
#else
freopen("houseboat.in","r", stdin);
freopen("houseboat.out", "w", stdout);
#endif
}
int n;
float x, y;
const float PI = 3.1415926;
int main()
{
online();

scanf("%d", &n);
for (int i=1; i <= n; i ++)
{
scanf("%f%f", &x, &y);
float year = (x * x + y * y) * PI / 100;
printf("Property %d: This property will begin eroding in year %d./n", i, (int)year + 1);
}
printf("END OF OUTPUT./n");
return 0;
}


题号:1006,题目Biorhythms

这道题要好好说说,具体可以看解题报告,http://zi-jin.com/archives/52,写的很好,但是有个地方理解错了。具体可以看,中国剩余定理http://mba.shengwushibie.com/itbook/BookChapter.asp?id=17863

#include <stdio.h>
//#define  ONLINE
void online()
{
#ifdef ONLINE
#else
freopen("bio.in", "r", stdin);
freopen("bio.out", "w", stdout);
#endif
}
const int m[3] = {23, 28, 33};
int _gcd, t;
void gcd(int a, int b, int &x, int &y)
{
if (!b)
{
x = 1;
y = 0;
_gcd = a;
return;
}
gcd(b, a % b, x, y);
t = x;
x = y;
y = t - a / b * y;
}
int solve(int r[], int k, int &M)
{
//m[i]同文中的m_i
//k同文中的k,本题是定值3,但其他题目中可能是变量
int i, M_i, x, y, a = 0;
for (i = 0, M = 1; i < k; M *= m[i++]);
for (i = 0; i < k; ++i)
{
M_i = M / m[i];
//求逆的过程
gcd(m[i], M_i, x, y);
a = (a + y * M_i * r[i]) % M;
}
return (a + M) % M; //保证a非负
}
int main()
{
online();
int r[3], d=0, c = 1, ans, M;
while (scanf("%d%d%d%d", &r[0], &r[1], &r[2], &d) != EOF && r[0] != -1)
{
r[0] %= m[0];
r[1] %= m[1];
r[2] %= m[2];
ans = solve(r, 3, M);
while (ans <= d)
ans += M;
printf("Case %d: the next triple peak occurs in %d days./n", c, ans - d);
++c;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: