hdu(2199)——Can you solve this equation?(浮点数二分)
来源:互联网 发布:intent获取数据 编辑:程序博客网 时间:2024/05/29 19:32
题意:
就是让你在0~100的范围内找出一个x,使得这个式子成立。
思路:
二分,注意这里判断no solution的时候不能由二分直接得来,因为二分浮点会有误差。而要通过式子,当Y<6||Y>res的时候那么就肯定是不存在的。
然后二分的时候要注意最好不要出现等于判断,而是用一个ans来保存中间结果,然后最后输出ans就好。
#include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>#include<vector>#include<set>#include<cmath>using namespace std;#define maxn 550#define eps 1e-8double Y;double ans=0;int cal(double x){double res=8*x*x*x*x+7*x*x*x+2*x*x+3*x+6-Y;if(res>=1e-20) return 1;return 0;}double bin(double x,double y){double mid;while(y-x>eps){mid=x+(y-x)/2;int yy=cal(mid);if(yy==1){ans=mid;y=mid;}else x=mid;}return ans;}int main(){int T;scanf("%d",&T);while(T--){scanf("%lf",&Y);ans=bin(0,100.0);double res=8*100.0*100.0*100.0*100.0+7*100.0*100*100+2*100*100+3*100+6;if(Y>res||Y<6) printf("No solution!\n");else printf("%.4lf\n",ans);}}/*2100-4*/
0 0
- hdu(2199)——Can you solve this equation?(浮点数二分)
- hdu - 2199 - Can you solve this equation?(二分)
- hdu-2199 Can you solve this equation?(二分+精度)
- HDU 2199 Can you solve this equation(二分)
- HDU 2199 Can you solve this equation?(二分)
- HDU 2199 Can you solve this equation?(二分)
- 【HDU】2199 - Can you solve this equation?(二分)
- 【HDU】-2199-Can you solve this equation?(二分)
- HDU(2199)Can you solve this equation?二分
- HDU 2199 Can you solve this equation?(二分)
- HDU:2199 Can you solve this equation?(二分)
- HDU 2199 Can you solve this equation?(二分)
- HDU—2199—Can you solve this equation?—【二分】【精度控制】
- (二分) HDU 2199 Can you solve this equation?
- hdu 2199 Can you solve this equation? 简单二分查找
- HDU 2199 Can you solve this equation? (二分 水题)
- HDU 2199 Can you solve this equation? 二分
- HDU 2199 Can you solve this equation? 二分
- hdu1796How many integers can you find
- fread fwrite read write 区别
- 重建二叉树
- Eclipse+adt+sdk配置Android开发环境
- 损失函数:Hinge Loss(max margin)
- hdu(2199)——Can you solve this equation?(浮点数二分)
- 链表头结点存在的意义
- Win10 利用 easybcd 安装 Ubuntu 14.04
- classmethod demo
- opencv学习之一简单的图片显示
- 在VS2015中配置和测试DCMTK遇到的问题
- Merge Intervals
- android stdio中的project和module的概念
- 菜鸟的Linux历程-学习大纲