2016SDAU程式設計練習二1002
Problem Description
Now, here is a fuction:<br> F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)<br>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<br>100<br>200
Sample Output
-74.4291<br>-178.8534
題意:求F(x)最小值
思路:求導就行了,注意精度
感想:二分三分都行,那個y唬人的,沒什麼用
AC程式碼:
#include <cstdio>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<math.h>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<iomanip>
using namespace std;
double y;
double q1(double x)
{
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;
}
double q (double x)
{
return 42*x*x*x*x*x*x+48*x*x*x*x*x+21*x*x+10*x-y;
}
int main()
{
double x,h,l,mid;
int N;
cin>>N;
while(N--)
{
cin>>y;
l=0;
h=100;
while((h-l)>0.000000001)
{
mid=(h+l)/2;
if(q(mid)>0) h=mid;
else l=mid;
}
mid=q1(mid);
printf("%.4f\n",mid);
}
}
相關推薦
2016SDAU程式設計練習二1002
Strange fuction Problem Description Now, here is a fuction:<br> F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <
2016SDAU程式設計練習二1018
Tempter of the Bone Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked
2016SDAU程式設計練習二1024
Sequence one Problem Description Search is important in the acm algorithm. When you want to solve a problem by using the search method,
2016SDAU程式設計練習二1015
Knight Moves Problem Description A friend of you is doing research on the Traveling Knight Problem (TKP) where you are to find the short
2016SDAU程式設計練習二1008
猜數字 A有1數m,B來猜.B每猜一次,A就說太大t太小或;對了問B猜n次可以猜到的最大數。 Input 第1行是整數T,表示有T組資料,下面有T行 <br>每行一個整數n (1 ≤ n ≤ 30) <br> Output 猜n次可以猜到
2016SDAU程式設計練習二1009
連連看 Problem Description “連連看”相信很多人都玩過。沒玩過也沒關係,下面我給大家介紹一下游戲規則:在一個棋盤中,放了很多的棋子。如果某兩個相同的棋子,可以通過一條線連起來(這條線不能經過其它棋子),而且線的轉折次數不超過兩次,那麼這兩個棋子就可以
2016SDAU程式設計練習二1025
Sequence two Problem Description Search is important in the acm algorithm. When you want to solve a problem by using the search method,
2016SDAU程式設計練習二1013
A strange lift Problem Description There is a strange lift.The lift can stop can at every floor as you want, and there is a number Ki(0
PAT程式設計練習——甲級1002(兩個多項式的解析與合併)
翻譯題目要求: 程式輸入為兩行:均為一個多項式,按 K N1 An1 N2 An2......Nk Ank,K代表的是多項式的非零項數,範圍閉區間是[1,10],N1到Nk的範圍區間是 1<= Nk <= ......<= N1 <= 1000;
2016SDAU程式設計練習三1007
Problem G Problem Description都說天上不會掉餡餅,但有一天gameboy正走在回家的小徑上,忽然天上掉下大把大把的餡餅。說來gameboy的人品實在是太好了,這餡餅別處都不掉,就掉落在他身旁的10米範圍內。餡餅如果掉在了地上當然就不能吃了,所以
2016SDAU程式設計練習三1010
Problem J Problem Description 有一樓梯共M級,剛開始時你在第一級,若每次只能跨上一級或二級,要走上第M級,共有多少種走法? Input 輸入資料首先包含一個整數N,表示測試例項的個數,然後是N行資料,每行包含一個整數M(1<=M&l
2016SDAU課程練習一1002
Problem C Problem Description Here is a famous story in Chinese history. "That was about 2300 years ago. General Tian Ji was a high offi
2016SDAU程式設計練習三1012
Problem L Problem Description 在2×n的一個長方形方格中,用一個1× 2的骨牌鋪滿方格,輸入n ,輸出鋪放方案的總數.<br>例如n=3時,為2× 3方格,骨牌的鋪放方案有三種,如下圖:<br><img src=
練習二1002
Strange fuction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Description Now, here is a
2016SDAU程式設計練習三1001
Problem A Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For
2016SDAU程式設計練習三1014
Problem N Problem Description 我們看到過很多直線分割平面的題目,今天的這個題目稍微有些變化,我們要求的是n條折線分割平面的最大數目。比如,一條折線可以將平面分成兩部分,兩條折線最多可以將平面分成7部分,具體如下所示。<br><
2016SDAU程式設計練習三1017
Problem Q Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like to col
C++Primer Plus筆記——第十二章 類和動態記憶體分配課後程式設計練習答案
目錄 課後習題 習題1 習題2 習題3 習題4 習題5&6 課後習題 習題1 #include <iostream> #include <cstring> using namespace std; class Cow {
函式程式設計實驗二:遞迴練習
module HW where {- 1. 定義求兩個非負整數最大公因子的函式: mygcd ::Integer ->Integer ->Integer -} mygcd ::Integer ->Integer ->Integer my
C primer plus 第六版 第六章 第十二題 程式設計練習答案
#include<stdio.h> #define l 1.0 int main(void) { int i = 0; // Create for loop. i