杭电二分题

Description

Now, here is a fuction:

F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)

Can you find the minimum value when x is between 0 and 100.

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 only one real numbers Y.(0 < Y <1e10)

Output

Just the minimum value (accurate up to 4 decimal places),when x is between 0 and 100.

Sample Input

 2
100
200 

Sample Output


         -74.4291
-178.8534 
#include<iostream>
#include <iomanip>
using namespace std;
long double fun(double x)
{
	return 42*x*x*x*x*x*x+48*x*x*x*x*x+21*x*x+10*x ;
}
long double fun1(double x,double y)
{
	return 6*x*x*x*x*x*x*x+8*x*x*x*x*x*x+7*x*x*x+5*x*x - y*x ;
}
int main()
{
	int t;
	long double y,hight=100,low=0,mid,k;
	cin >> t ;
	while(t--)
	{
		cin >> y;
		hight=100;
		low=0;
		while(hight - low >1e-8)
		{
			mid=(hight + low)/2;
			k=fun(mid);
			if(k>y)
			{
				hight=mid;
			}
			if(k<y)
			{
				low=mid;
			}
		}
		cout << setiosflags(ios::fixed) ;
		cout << setprecision(4) << fun1(mid , y) << endl;
	}
	return 0;
}

时间: 2024-10-10 06:58:13

杭电二分题的相关文章

杭电dp题集,附链接

Robberies 点击打开链接 背包;第一次做的时候把概率当做背包(放大100000倍化为整数):在此范围内最多能抢多少钱  最脑残的是把总的概率以为是抢N家银行的概率之和- 把状态转移方程写成了f[j]=max{f[j],f[j-q[i].v]+q[i].money}(f[j]表示在概率j之下能抢的大洋); 正确的方程是:f[j]=max(f[j],f[j-q[i].money]*q[i].v)  其中,f[j]表示抢j块大洋的最大的逃脱概率,条件是f[j-q[i].money]可达,也就是

acm入门 杭电1001题 有关溢出的考虑

最近在尝试做acm试题,刚刚是1001题就把我困住了,这是题目: Problem Description In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n. Input The input will consist of a series of integers n, one integer per line Output For each case, output SUM(n) in one line

杭电水题

杭电OJ上的水题:C语言程序设计练习 题目如下: 链接: http://acm.hdu.edu.cn/showproblem.php?pid=2001 注:pid=后面可以为2000 - 2050中的任何一个(对应50道题目) 另外也可以做1000之后的(按顺序做,从1000开始把,1000开头的都蛮简单的) 原文地址:https://www.cnblogs.com/wyb666/p/10909202.html

杭电算法题 HDU 1000-1004

h1,h2,h3,h4,h5,h6,p,blockquote { margin: 0; padding: 0 } body { font-family: "Helvetica Neue", Helvetica, "Hiragino Sans GB", Arial, sans-serif; font-size: 13px; line-height: 18px; color: #737373; background-color: white; margin: 10px

小试牛刀-搜索基础入门(杭电五题)

hdu 1241 Oil Deposits 水题,BFS,判断区域的块数. 代码清单: #include<queue> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; typedef pair<int,int>P; int m,n; char s[105][105]; int xy[8][2]=

动态规划解决杭电OJ1080题——LCS的变种

首先上题目: Human Gene Functions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2570    Accepted Submission(s): 1451 Problem Description It is well known that a human gene can be considered as a se

杭电一水题(DFS)Untitled

Problem Description There is an integer a and n integers b1,…,bn. After selecting some numbers from b1,…,bn in any order, say c1,…,cr, we want to make sure that a mod c1 mod c2 mod… mod cr=0 (i.e., a will become the remainder divided by ci each time,

Dijk入门(杭电2544题)

#include<iostream> #include<cstring> using namespace std; #define INF 0x3f3f3f3f int n,m; int map[105][105]; int vis[105]; int stemp[105]; int dijk(){ memset(vis,0,sizeof(vis)); vis[1]=1; //标记第一个已选 memset(stemp,0,sizeof(stemp)); int min; int f

杭电acm 1002 大数模板(一)

从杭电第一题开始A,发现做到1002就不会了,经过几天时间终于A出来了,顺便整理了一下关于大数的东西 其实这是刘汝佳老师在<算法竞赛 经典入门 第二版> 中所讲的模板,代码原封不动写上的,但是经过自己的使用与调试也明白了其中的内涵. 首先定义大数的结构体: struct BigNum{ static const int BASE=100000000; static const int WIDTH=8; vector<int> s; BigNum(long long num=0){