codeforces 342C Cupboard and Balloons(公式题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud
A girl named Xenia has a cupboard that looks like an arc from ahead. The arc is made of a semicircle with radius r (the cupboard's top) and two walls of height h (the cupboard's sides). The cupboard's depth is r, that is, it looks like a rectangle with base r and height h + rfrom the sides. The figure below shows what the cupboard looks like (the front view is on the left, the side view is on the right).

Xenia got lots of balloons for her birthday. The girl hates the mess, so she wants to store the balloons in the cupboard. Luckily, each balloon is a sphere with radius
. Help Xenia calculate the maximum number of balloons she can put in her cupboard.
You can say that a balloon is in the cupboard if you can't see any part of the balloon on the left or right view. The balloons in the cupboard can touch each other. It is not allowed to squeeze the balloons or deform them in any way. You can assume that the cupboard's walls are negligibly thin.
The single line contains two integers r, h (1 ≤ r, h ≤ 107).
Print a single integer — the maximum number of balloons Xenia can put in the cupboard.
1 1
3
1 2
5
2 1
2
考虑到从下往上开始摆的空间利用率高,于是只需要考虑最终的顶上还能否再塞进一个气球即可。
//#####################
//Author:fraud
//Blog: http://www.cnblogs.com/fraud/
//#####################
#include <iostream>
#include <sstream>
#include <ios>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cctype>
using namespace std;
#define XINF INT_MAX
#define INF 0x3FFFFFFF
#define MP(X,Y) make_pair(X,Y)
#define PB(X) push_back(X)
#define REP(X,N) for(int X=0;X<N;X++)
#define REP2(X,L,R) for(int X=L;X<=R;X++)
#define DEP(X,R,L) for(int X=R;X>=L;X--)
#define CLR(A,X) memset(A,X,sizeof(A))
#define IT iterator
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<PII> VII;
typedef vector<int> VI; int main()
{
ios::sync_with_stdio(false);
double r,h;
while(cin>>r>>h){
double tmp=(h+r/);
int ans=(int)(tmp/r+1e-);
tmp-=ans*r;
ans*=;
tmp+=r/;
if(tmp-r*(sqrt(3.0)/)>-1e-)ans++;
cout<<ans<<endl; }
return ;
}
代码君
codeforces 342C Cupboard and Balloons(公式题)的更多相关文章
- CodeForces 342C Cupboard and Balloons (几何问题)
题意:给定一个 r 和 h,r 是上面那个半球的半径,h 是下面那个圆柱的高度,然后有一些半径为 r/2的气球,问你最多能放几个. 析:根据题意,很容易知道,先从下面往上放,两个两个的放,放到不能放的 ...
- Codeforces Round #199 (Div. 2) C. Cupboard and Balloons
C. Cupboard and Balloons time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- Codeforces Round #378 (Div. 2) D题(data structure)解题报告
题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...
- Codeforces 828B Black Square(简单题)
Codeforces 828B Black Square(简单题) Description Polycarp has a checkered sheet of paper of size n × m. ...
- http://codeforces.com/gym/100623/attachments E题
http://codeforces.com/gym/100623/attachments E题第一个优化它虽然是镜像对称,但它毕竟是一一对称的,所以可以匹配串和模式串都从头到尾颠倒一下第二个优化,与次 ...
- 华东交通大学2018年ACM“双基”程序设计竞赛 C. 公式题 (2) (矩阵快速幂)
题目链接:公式题 (2) 比赛链接:华东交通大学2018年ACM"双基"程序设计竞赛 题目描述 令f(n)=2f(n-1)+3f(n-2)+n,f(1)=1,f(2)=2 令g(n ...
- http://codeforces.com/gym/100623/attachments H题
http://codeforces.com/gym/100623/attachments H题已经给出来的,包括后来添加的,都累加得到ans,那么从1-ans都是可以凑出来的,如果ans<a[n ...
- Codeforces Round #612 (Div. 2) 前四题题解
这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...
- codeforces 340C Tourist Problem(公式题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Tourist Problem Iahub is a big fan of tou ...
随机推荐
- C# ITextShap 生成PDF 下载
using iTextSharp.text; using iTextSharp.text.pdf; //创建 Document Document pdfDoc = new Document(new R ...
- ubuntu中安装eclipse
1.下载eclipse安装包 http://mirror.neu.edu.cn/eclipse/technology/epp/downloads/release/kepler/SR2/eclipse- ...
- JS 多种变量定义
对象直接量创建一个对象: var obj = {x:[1,2],y:23}; 代码跟下面是一样的. var obj=new Object(); obj.x=new Array(1,2); obj. ...
- 最大子数组分治方案C++实现
大家好,我是小鸭酱,博客地址为:http://www.cnblogs.com/xiaoyajiang 以下实现最大子数组的分治策略,算法来自<算法导论> #include<iostr ...
- poj2505-A multplication game
题意:两个人轮流用2~9来乘n,使n不断扩大,n开始为1.当给一个固定值k,谁先使n超过k谁赢. 分析:能到达必败态的状态为必胜态,只能到达必胜态的状态为必败态.对于给定的k,n>=k时为必败态 ...
- Win8.1专业版、核心板和企业版有什么区别
Win8.1核心版(一般就称之为Windows 8.1) + Win8.1 专业版(称之为Windows 8.1 Pro),根据用户输入的序列号(就是Win8密钥)来区分安装.Win8.1企业版(称之 ...
- 为什么ASCII是7位(导致各家编码的128~256字符都不同,给我带来很多困惑)——在标准ASCII中,其最高位(b7)用作奇偶校验位,附ASCII每个控制符的中文解释
ASCII编码 ASCII是基于拉丁字母的一套电脑编码系统.它主要用于显示现代英语和其他西欧语言.它是现今最通用的单字节编码系统,并等同于国际标准ISO/IEC 646. 请注意,ASCII是Amer ...
- Delphi中ShellExecute使用详解(详细解释10种显示状态)
有三个API函数可以运行可执行文件WinExec.ShellExecute和CreateProcess.1.CreateProcess因为使用复杂,比较少用.2.WinExec主要运行EXE文件.如: ...
- linux下netstat命令详解
简介 Netstat 命令用于显示各种网络相关信息,如网络连接,路由表,接口状态 (Interface Statistics),masquerade 连接,多播成员 (Multicast Member ...
- 杭电1142(最短路径+dfs)
A Walk Through the Forest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...