acm课程练习2--1001
题目描述
Now,given the equation 8x^4 + 7x^3 + 2x^2 + 3x + 6 == Y,can you find its solution between 0 and 100;
Now please try your lucky.
Input
The first line of the input contains an integer T(1<=T<=100) which means the number of test cases. Then T lines follow, each line has a real number Y (fabs(Y) <= 1e10);
Output
For each test case, you should just output one real number(accurate up to 4 decimal places),which is the solution of the equation,or “No solution!”,if there is no solution for the equation between 0 and 100.
Sample Input
2
100
-4
Sample Output
1.6152
No solution!
大意
求解方程的简单水题
思路
简单的水题,使用二分法即可。但需要注意浮点数比较时的精度,我写的是1e-5,如果精度太高的话会超时的
#include<iostream>#include<stdio.h>#include<cmath>#include<iomanip>using namespace std;double m, res = 0;int ji = 0;double f(double res){return res*res*res*res * 8 + res*res*res * 7 + res*res * 2 + res * 3 + 6;}int main(){//cin.sync_with_stdio(false);//freopen("date.in", "r", stdin);//freopen("date.out", "w", stdout);int N, temp;double b, e, tem = 50;scanf("%d", &N);for (int i = 0; i<N; i++){b = 0, e = 100, tem = 50;cin >> m;if (m<6 || m>807020306)//cout << "No solution!" << endl;printf("No solution!\n");else{while (fabs(f(tem) - m) >= 1e-5)if (f(tem)>m){e = tem;tem = (b + e) / 2;}else{b = tem;tem = (b + e) / 2;}//cout << fixed << setprecision(4) << tem << endl;printf("%0.4f\n", tem);}}}
acm课程练习2--1001的更多相关文章
- ACM课程学习总结
ACM课程学习总结报告 通过一个学期的ACM课程的学习,我学习了到了许多算法方面的知识,感受到了算法知识的精彩与博大,以及算法在解决问题时的巨大作用.此篇ACM课程学习总结报告将从以下方面展开: 学习 ...
- acm入门 杭电1001题 有关溢出的考虑
最近在尝试做acm试题,刚刚是1001题就把我困住了,这是题目: Problem Description In this problem, your task is to calculate SUM( ...
- ACM课程总结
当我还是一个被P哥哥忽悠来的无知少年时,以为编程只有C语言那么点东西,半个学期学完C语言的我以为天下无敌了,谁知自从有了杭电练习题之后,才发现自己简直就是渣渣--咳咳进入正题: STL篇: 成长为一名 ...
- 华东交通大学2016年ACM“双基”程序设计竞赛 1001
Problem Description 输入一个非负的int型整数,是奇数的话输出"ECJTU",是偶数则输出"ACM". Input 多组数据,每组数据输入一 ...
- acm课程练习2--1013(同1014)
题目描述 There is a strange lift.The lift can stop can at every floor as you want, and there is a number ...
- acm课程练习2--1005
题目描述 Mr. West bought a new car! So he is travelling around the city.One day he comes to a vertical c ...
- acm课程练习2--1003
题目描述 My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a numb ...
- acm课程练习2--1002
题目描述 Now, here is a fuction: F(x) = 6 * x^7+8x^6+7x^3+5x^2-yx (0 <= x <=100)Can you find the ...
- SDAU课程练习--problemB(1001)
题目描述 There is a pile of n wooden sticks. The length and weight of each stick are known in advance. T ...
随机推荐
- C/C++ - <string> 与<string.h>、<cstring>的区别
<string.h><string.h>是C版本的头文件,包含比如strcpy.strcat之类的字符串处理函数. <string><string>是C ...
- static 控件颜色修改
在对话框上放一个StaticText控件后如果文字长度不能铺满控件的 rect,如下: 那么运行时会出现如下效果 通过MSG_WM_CTLCOLORSTATIC消息修改static控件背景色模式为透明 ...
- nmon性能统计工具使用-初认识
1.概述 监控,在检查系统问题或优化系统性能工作上是一个不可缺少的部分.通过操作系统监控工具监视操作系统资源的使用情况,间接地反映了各服务器程序的运行情况.根据运行结果分析可以帮助我们快速定位系统问题 ...
- ajaxpro——js调用后台的方法
前提:添加并引用类库ajaxpro.dll 1.把引用的类库改为自己(如果是自己的话,就不用修改): <%@ Page Language="C#" AutoEventWire ...
- 观后感-MySQL索引类型 btree索引和hash索引的区别
http://www.cnblogs.com/osfipin/p/4943229.html.http://www.2cto.com/database/201411/351106.html-文章地址 首 ...
- 软件测试之α测试和Beta测试
实施验收测试的常用策略有三种,它们分别是: · 正式验收 · 非正式验收或Alpha 测试 · Beta 测试 因此,Alpha测试和Beta测试都属于验收测试.所谓验收测试是软件产品完成了功能测试和 ...
- over 分析函数之 lag() lead()
/*语法*/ lag(exp_str,offset,defval) over() 取前 Lead(exp_str,offset,defval) over() 取后 --exp_str要取的列 -- ...
- Network view
network view 组件用来在局域网之内去同步一个游戏物体的组件属性,只响应创建它的那个客户端事件
- apache 添加到windows服务
cmd命令行下 输入 “d:\apache\bin\httpd.exe” -k install 如果是resin的话直接运行目录下的setup就可以了, 前提是需要.net framework 3.5
- CSS3秘笈:第十二章&第十三章
第十二章 1.网页布局类型 (1)固定宽度 (2)流式 (3)响应式Web设计 2.CSS布局的方法 通过给元素设置一个宽度,将它浮到左侧或右侧,就可以创建一个列(元素后面的文本会环绕浮动的元素,仿佛 ...