11208: 【原1208】大圣切蛋糕
题目
题目描述
author: Fangkui Zhang 原OJ链接:https://acm.sjtu.edu.cn/OnlineJudge-old/problem/1208 ## Description
孙大圣在大一暑期的算法博弈论课程中深入研究了如何切蛋糕的问题,现在他想要实践一下。 孙大圣有很多不同大小的圆柱形蛋糕,想要每个都切一刀,取小的那一块看一下大小。可是他高中数学学得过好以至于不会算数了,不知道怎么计算切出的蛋糕有多大,因此想请你帮他计算一下切出的较小块蛋糕上表面面积是多少。 注意所有蛋糕都是扁圆柱,上表面是圆形,高都一样 。由于他不是一个那么较真的人,所以你的计算结果四舍五入保留两位小数就好。
Input Format
每行2个数r和a,分别表示原蛋糕上表面半径和孙大圣刀印所在直线到圆心的距离。
Output Format
所有被切下的较小块的蛋糕中最大那一块的上表面面积(四舍五入保留两位小数)。
Sample Input 1
10 5
Sample Output 1
61.42
Sample Input 2
10 5
20 8
Sample Output 2
317.07
Hint:
不定的多组数据输入请参考以下语句:while (cin >> a >> b) {cout << a + b << endl;}
Limits
所有运算均在double范围内。
FineArtz's solution
/* 大圣切蛋糕 */
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
const double pi = 3.1415926;
int main(){
double r, a, ans = 0.0;
while (cin >> r >> a){
double tans = acos(a/r) * r * r;
tans -= a * sqrt(r * r - a * a);
if (ans < tans) ans = tans;
}
cout << setiosflags(ios::fixed) << setprecision(2) << ans << endl;
return 0;
}
ligongzzz's solution
#include "iostream"
#include "cstring"
#include "cstdio"
#include "cmath"
using namespace std;
int main() {
double r, d;
double ans = 0.0;
while (cin >> r >> d) {
double cur_ans = r * r * acos(d / r) - d * sqrt(r * r - d * d);
ans = cur_ans > ans ? cur_ans : ans;
}
printf("%.2f", ans);
return 0;
}