ZOJ 3203 Light Bulb
来源:互联网 发布:重庆指尖网络 编辑:程序博客网 时间:2024/06/16 19:58
在LJOJ上说这是三分,我就懒得去推公式了。学习三分法第一题。十分方便。
//By Richard#include <cstdio>#include <algorithm>#include <iostream>#include <cstring>#include <cstdlib>#include <cmath>#include <ctime>#define rep(x,y,z) for (int x=(y);(x)<=(z);(x)++)#define per(x,y,z) for (int x=(y);(x)>=(z);(x)--)#define log2(x) (31-__builtin_clz(x))#define mod (int)(1e9+7)#define inf 0x3f3f3f3f#define cls(x) memset(x,0,sizeof(x))#ifdef DEBUG#define debugdo(X) X#define debugndo(X)#define debugout(X) cout<<(#X)<<"="<<(X)<<endl#else#define debugdo(X)#define debugndo(X) X#define debugout(X)#endif // debug#ifdef ONLINE_JUDGE#define debugdo(X)#define debugndo(X)#define debugout(X)#endif#define putarray(x,n) rep(iiii,1,n) printf("%d ",x[iiii])#define mp make_pairusing namespace std;typedef pair<int,int> pairs;typedef long long LL;/////////////////////read3.0////////////////////////////////////template <typename T>inline void read(T &x){char ch;x=0;bool flag=false;ch=getchar();while (ch>'9'||ch<'0') {ch=getchar();if (ch=='-') flag=true;}while ((ch<='9'&&ch>='0')){x=x*10+ch-'0';ch=getchar();}if (flag) x*=-1;}template <typename T>inline void read(T &x,T &y){read(x);read(y);}/////////////////variables&functions////////////////////int T;double H,h,D;const double eps=0.0000001;// #define calc(x) (x+((h/(x+(h*D-H*x)/(H-h)))*(h*D-H*x)/(H-h)))// #define calc(x) (x+((h*D-H*x)/(D-x)))inline double calc(double x){double temp=(h*D-H*x)/(D-x);if (temp>0) return x+temp;else return (D-x)/(H-h);}int main(){read(T);while (T--){scanf("%lf%lf%lf",&H,&h,&D);double l=0,r=D;while (r-l>eps){double ll=(r-l)/3+l,rr=(r-l)*2/3+l;double ansll=calc(ll),ansrr=calc(rr);if (ansll>ansrr) r=rr;else l=ll;}printf("%.3lf\n",calc(l));}return 0;}
阅读全文
0 0
- ZOJ 3203 Light Bulb
- ZOJ - 3203 Light Bulb
- ZOJ 3203 Light Bulb
- Zoj 3203 Light Bulb
- zoj 3203 Light Bulb
- ZOJ 3203 Light Bulb
- zoj 3203(Light Bulb)
- ZOJ 3203 Light Bulb
- ZOJ 3203 Light Bulb
- zoj 3203 Light Bulb
- ZOJ 3203 Light Bulb
- zoj 3203 Light Bulb
- zoj 3203 Light Bulb
- ZOJ 3203 Light Bulb
- ZOJ 3203 Light Bulb
- ZOJ 3203 Light Bulb
- ZOJ 3203 Light Bulb
- ZOJ 3203 Light Bulb
- 原生方式判断用户名是否被占用
- Springmvc 生成并且下载文件--直接在浏览器下载。
- 揭开POJO的神秘面纱
- 奇数单增序列
- 4 工作杂文4-一些小的技术点
- ZOJ 3203 Light Bulb
- 在k8s集群中部署nginx-ingress-controller.yaml遇到的问题
- Struts框架--获取servletApi
- idea安装配置maven
- acm二进制运算技巧
- [ICLR2015]Neural Machine Translation by Jointly Learning to Align and Translate
- python的三种字符串格式化方法
- JS_绘图_canvas
- 整数奇偶排序