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 ...
随机推荐
- 直接粘贴代码到网络上:command-line pastebins
软件作用 直接把管道里面的文字内容传到网站上面,然后反馈一个地址可以读取内容. 同类软件 wgetpaste dpaste pastebin pasteie 用法 介绍wgetpaste为例: GEN ...
- sqlite 学习
到谷歌上搜sqlite,第一项便是官方网站:www.sqlite.org.进去后,先了解一下大体,感觉还不错. 进入Document页面,大标题SQLite Programming Interface ...
- 禁用 VS2010 的 vcpkgsrv.exe 运行
VS2010经常使用一段时间后巨卡,发现vcpkgsrv.exe这个进程相当占内存,但是结束后又会自己启动,百度之原来是IntelliSense的问题,关闭之即可,设置如下
- 感知哈希算法 python 3.4
#!/usr/bin/python # -*- coding: UTF-8 -*- #Less than 10 add to list and sort import glob import os i ...
- ADO.NET 学生管理
今天,我主要是对前面所做的学生管理系统加以完善. 通过今天的学习,我了解到了,在做程序时,一定要充分的为用户考虑.能用下拉列表让用户选择的,就不要让他们手动输入,能少输入的就少输入.在程序中,应尽可能 ...
- 配置elasticsearch 以及ik分词
https://github.com/medcl/elasticsearch-analysis-ikhttps://www.elastic.co/downloads/past-releases/ela ...
- ElasticSearch 的一次非正常master脱离的调查 (转 和我碰到的情况一模一样)
转自 http://simonlei.iteye.com/blog/1669992 一共有4个节点的cluster,其中es4 是master,某个时间突然es1脱离了整个cluster,调查过程如下 ...
- mysql基本操作 [http://www.cnblogs.com/ggjucheng/archive/2012/11/03/2752082.html]
创建表 简单的方式 CREATE TABLE person ( number INT(11), name VARCHAR(255), birthday DATE ); 或者是 CREATE TABLE ...
- python unitest基本
基本 import unittest class OneTest(unittest.TestCase): def setUp(self): self.verificationErrors = [] s ...
- ice调通过iceReplica用所有server instance的方法---客户端控制服务端的负载均衡
I 使用此方法,可以增量的通知Ice服务配置的改变,刷新每个服务进程的数据 可以手动控制客户端调用的负载均衡,客户端程序决定将请求发往那个进程 上代码: import logging import I ...