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 ...
随机推荐
- iOS9如何隐藏各种bar
转载自:http://www.cnblogs.com/aBigRoybot/articles/2234487.html 状态条StatusBar 1 [UIApplication sharedAppl ...
- 多线程synchronized用例解析
当用synchronized来修饰一个方法或者一个代码块的时候,能够保证在同一时刻最多只有一个线程执行该段代码.即使在执行过程中,CPU切换到别的线程了,因为有锁的缘故,其他线程也不会进来执行代码,而 ...
- 你所不知道的mybatis居然也有拦截器
对于mybatis的拦截器这个想法我来自于三个地方 也就是下面这个三个地方是可以使用的,其他的情况需要开发人员根据实际情况来使用. 1.对于分页的查询,我们可以对于分页的方法采用比较规范的命名,然后根 ...
- allegro 导Gerber文件
今天抽空好好整理了一下有关Allegro出Gerber文件文档,此文档在网上搜到的基础上进一步完善,把每个需要注意的地方都用红色字体框出 http://files.cnblogs.com/files/ ...
- JavaScript高级程序设计:第五章
引用类型 一.object类型: 创建object实例的方式有两种.第一种是使用new操作符后跟Object构造函数,如下所示: var person = new Object(): person ...
- webapp前端开发软键盘与position:fixed为我们带来的不便
前提:我们考虑兼容的环境为android和ios两种智能手机 兼容环境测试结果显示android的表现明显好于ios,ios手机在软键盘呼起收起时存在着很严重的兼容性问题 场景展示: 页面正常状态 软 ...
- myeclipse复制项目
一.myEclipse 复制后修改名称,访问不到项目 这是因为,你只是改了项目的名称,而没有改 下面是解决方法: 方法 1.右击你的项目,选择"properties",在" ...
- .Cannot create an NSPersistentStoreCoordinator with a nil model
今天用coredata事,忽然遇到这个问题:找了一会终于发现问题所在,与大家分享一下 导致这个问题的原因是因为找不到.xcdatamodeld所致,不同的人可能遇到的问题不同 可能原因1: NSURL ...
- a标签无跳转的死链接
<a href="#" onclick="return false;">link1</a> <a href="javas ...
- Android Service学习之IntentService 深入分析
什么是IntentService? (本文转自http://blog.csdn.net/gaojie314/archive/2010/11/28/6040701.aspx) 官方的解释是: ...