日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁(yè) > > 充電吧
[導(dǎo)讀]題目鏈接:HDU 4355 題面: Party All the Time Time Limit: 6000/2000 MS (Java/Others)????Memory Limit: 65536

題目鏈接:HDU 4355


題面:

Party All the Time Time Limit: 6000/2000 MS (Java/Others)????Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5266????Accepted Submission(s): 1625


Problem Description In the Dark forest, there is a Fairy kingdom where all the spirits will go together and Celebrate the harvest every year. But there is one thing you may not know that they hate walking so much that they would prefer to stay at home if they need to walk a long way.According to our observation,a spirit weighing W will increase its unhappyness for S3*W units if it walks a distance of S kilometers.
Now give you every spirit's weight and location,find the best place to celebrate the harvest which make the sum of unhappyness of every spirit the least. ?
Input The first line of the input is the number T(T<=20), which is the number of cases followed. The first line of each case consists of one integer N(1<=N<=50000), indicating the number of spirits. Then comes N lines in the order that x[i]<=x[i+1] for all i(1<=ii,Wi, representing the location and the weight of the i-th spirit. ( |xi|<=106, 0i<15 ) ?
Output For each test case, please output a line which is "Case #X: Y", X means the number of the test case and Y means the minimum sum of unhappyness which is rounded to the nearest integer. ?
Sample Input
1
4
0.6 5
3.9 10
5.1 7
8.4 10

?

Sample Output
Case #1: 832

?

Author Enterpaise@UESTC_Goldfinger ?
Source 2012 Multi-University Training Contest 6


題意:

??? 給定一維上若干點(diǎn)xi,每個(gè)點(diǎn)有對(duì)應(yīng)的權(quán)值wi,求一個(gè)點(diǎn)的位置p,使得sigma? fabs(p-xi)^3*wi最小。


解題:

? 看了網(wǎng)上現(xiàn)有的所有博客,都是直接說(shuō)是個(gè)凸函數(shù),三分一下就好。求導(dǎo)好像也不直觀,也不知道具體是怎么證明的,姑且認(rèn)為是個(gè)開(kāi)口向上的二次函數(shù)(因?yàn)榍蟮氖亲钚≈担抑庇^上,p的位置肯定是在中間好),那么三分就可以求解了,需要注意的是,這題C++應(yīng)該是會(huì)T的,交G++才能過(guò),然后向最近位取舍,應(yīng)該用%.0lf輸出。

?? 【三分性質(zhì)】

??????? 將區(qū)間三等分,取左等分點(diǎn)為lmid,右等分點(diǎn)為rmid,比如此題,二次函數(shù)開(kāi)口向上,那么就算lmid的函數(shù)值為lv,rmid的函數(shù)值為rmid,比較lv和rv的值,假設(shè)最小值不在lmid和rmid之間,在兩側(cè),那么lv,rv哪個(gè)更小,其對(duì)應(yīng)的等分點(diǎn)就更接近最值,故而舍棄大的那邊。倘若,最小值在lmid和rmid之間,那么無(wú)論舍棄哪一邊,都不會(huì)丟棄最值,同時(shí)達(dá)到逼近最值的效果,因?yàn)樽钪翟诤翁帲覀兪遣恢赖?,故而和第一種情況相統(tǒng)一,舍棄較大的一邊。


代碼:

#include 
#include 
#include 
#include 
#include 
#include 
#define LL long long
#define eps 1e-8
using namespace std;
double x[50010],w[50010];
int n;
double cal(double y)
{
	double tmp,res=0.0;
	for(int i=0;ieps)
		{
			double lmid,rmid,lv,rv;
			lmid=(ri-le)/3+le;
			rmid=ri-(ri-le)/3;
            lv=cal(lmid);
			rv=cal(rmid);
			if(lv>rv)
				le=lmid;
			else
				ri=rmid;
		}
		printf("Case #%d: %.0lfn",i,cal(le));
	}
	return 0;
}


本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除。
換一批
延伸閱讀

晶體管開(kāi)關(guān)電路的設(shè)計(jì)以及如何提高其開(kāi)關(guān)速度

關(guān)鍵字: 體管 開(kāi)關(guān) 技巧

你知道電子元器件應(yīng)該如何檢測(cè)嗎?小小的電子元器件看似微小,實(shí)則是很重要的組成部分之一。因?yàn)殡娮釉O(shè)備出現(xiàn)故障現(xiàn)象,很大一部分情況是由于電子元器件失效或損壞所導(dǎo)致。如此一來(lái),檢測(cè)電子元器件成為很重要的事,那么對(duì)于電子元器件檢...

關(guān)鍵字: 技巧 檢測(cè)經(jīng)驗(yàn) 電子元器件

你知道怎么學(xué)習(xí)單片機(jī)嗎?有很多剛?cè)胄械某鯇W(xué)者工程師在單片機(jī)這個(gè)領(lǐng)域經(jīng)常是蒙圈的狀態(tài),完全不知道該從何下手,在開(kāi)發(fā)過(guò)程中:代碼的使用效率問(wèn)題、單片機(jī)抗干擾性、可靠性等問(wèn)題經(jīng)常困擾著他們。為此,小編歸納總結(jié)出單片機(jī)開(kāi)發(fā)中應(yīng)該...

關(guān)鍵字: 單片機(jī) 技巧 電路

現(xiàn)在的電路越來(lái)越多,但是有一個(gè)關(guān)鍵問(wèn)題很重要,那就是散熱,對(duì)于電子設(shè)備來(lái)說(shuō),工作時(shí)都會(huì)產(chǎn)生一定的熱量,從而使設(shè)備內(nèi)部溫度迅速上升,如果不及時(shí)將該熱量散發(fā)出去,設(shè)備就會(huì)持續(xù)的升溫,器件就會(huì)因過(guò)熱而失效,電子設(shè)備的可靠性能就...

關(guān)鍵字: PCB 技巧 散熱

題目鏈接:hdu 3062 題面: Party Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 32768/32768 K (Jav

關(guān)鍵字: hdu 入門

題目鏈接:HDU 4544 題面: 湫湫系列故事——消滅兔子 Time Limit: 3000/1000 MS (Java/Others)????Memory Limit: 65535/32768

關(guān)鍵字: hdu 貪心

題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=3911 題面: Black And White Time Limit: 9000/3000 MS (

關(guān)鍵字: hdu 線段樹(shù)

題目鏈接:HDU 5754 題面: Life Winner Bo Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 131072/13

關(guān)鍵字: hdu 博弈

題目鏈接:HDU 2045 題面: 不容易系列之(3)—— LELE的RPG難題 Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 6

關(guān)鍵字: hdu 入門

題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=5071 題面: Chat Time Limit: 2000/1000 MS (Java/Others

關(guān)鍵字: hdu 區(qū)域賽
關(guān)閉