hdu - 2199 - Can you solve this equation?(二分)
来源:互联网 发布:人工智能 sci期刊 编辑:程序博客网 时间:2024/06/06 04:59
题意:求8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y在[0, 100]上的解。
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2199
——>>简单二分。
发现,在hust上用函数写法0ms过,用define写法15ms过,而这两种写法在hdu上都是0ms过。奇葩~
函数写法:
#include <cstdio>#include <cmath>using namespace std;const double eps = 1e-14;double Y;double F(double x){ return 8*pow(x, 4) + 7*pow(x, 3) + 2*pow(x, 2) + 3*x + 6 - Y;}int main(){ int T, i; scanf("%d", &T); while(T--) { scanf("%lf", &Y); double f0 = F(0), f100 = F(100); if(f0 > eps || f100 < -eps) printf("No solution!\n"); else { double x = 0, y = 100, m; for(i = 0; i < 100; i++) { m = x + (y - x) / 2; if(F(m) < 0) x = m; else y = m; } printf("%.4lf\n", m); } } return 0;}
define写法:
#include <cstdio>#include <cmath>#define F(x) (8*pow(x, 4) + 7*pow(x, 3) + 2*pow(x, 2) + 3*x + 6 - Y)using namespace std;const double eps = 1e-14;double Y;int main(){ int T, i; scanf("%d", &T); while(T--) { scanf("%lf", &Y); double f0 = F(0), f100 = F(100); if(f0 > eps || f100 < -eps) printf("No solution!\n"); else { double x = 0, y = 100, m; for(i = 0; i < 100; i++) { m = x + (y - x) / 2; if(F(m) < 0) x = m; else y = m; } printf("%.4lf\n", m); } } return 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? 简单二分
- 比特币(bitcoin)硬件挖矿,性能比较
- tomcat启动的内存溢出解决
- IOS屏幕截图---Opengl截屏
- ABAP 三种操作数据库的方法 OPEN SQL, EXEC SQL, ADBC
- Which version number corresponds to which patch/SP for SAP BusinessObjects BI 4.x ?
- hdu - 2199 - Can you solve this equation?(二分)
- 正则过滤不严引发的注入漏洞小记
- How dvm calls native method
- 工作中经常使用的JAVA集合类
- 字符串处理类StringUtils
- SDK 升级缓慢
- AS3.0 正则表达式规则
- Android 添加系统串口服务步骤
- Effective C++读书笔记 第七部分 模板与泛型编程