当前位置:首页 > > 充电吧
[导读]题目链接: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


题意:

    给定一维上若干点xi,每个点有对应的权值wi,求一个点的位置p,使得sigma  fabs(p-xi)^3*wi最小。


解题:

  看了网上现有的所有博客,都是直接说是个凸函数,三分一下就好。求导好像也不直观,也不知道具体是怎么证明的,姑且认为是个开口向上的二次函数(因为求的是最小值,且直观上,p的位置肯定是在中间好),那么三分就可以求解了,需要注意的是,这题C++应该是会T的,交G++才能过,然后向最近位取舍,应该用%.0lf输出。

   【三分性质】

        将区间三等分,取左等分点为lmid,右等分点为rmid,比如此题,二次函数开口向上,那么就算lmid的函数值为lv,rmid的函数值为rmid,比较lv和rv的值,假设最小值不在lmid和rmid之间,在两侧,那么lv,rv哪个更小,其对应的等分点就更接近最值,故而舍弃大的那边。倘若,最小值在lmid和rmid之间,那么无论舍弃哪一边,都不会丢弃最值,同时达到逼近最值的效果,因为最值在何处,我们是不知道的,故而和第一种情况相统一,舍弃较大的一边。


代码:

#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;
}


本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除。
换一批
延伸阅读

晶体管开关电路的设计以及如何提高其开关速度

关键字: 体管 开关 技巧

你知道电子元器件应该如何检测吗?小小的电子元器件看似微小,实则是很重要的组成部分之一。因为电子设备出现故障现象,很大一部分情况是由于电子元器件失效或损坏所导致。如此一来,检测电子元器件成为很重要的事,那么对于电子元器件检...

关键字: 技巧 检测经验 电子元器件

你知道怎么学习单片机吗?有很多刚入行的初学者工程师在单片机这个领域经常是蒙圈的状态,完全不知道该从何下手,在开发过程中:代码的使用效率问题、单片机抗干扰性、可靠性等问题经常困扰着他们。为此,小编归纳总结出单片机开发中应该...

关键字: 单片机 技巧 电路

现在的电路越来越多,但是有一个关键问题很重要,那就是散热,对于电子设备来说,工作时都会产生一定的热量,从而使设备内部温度迅速上升,如果不及时将该热量散发出去,设备就会持续的升温,器件就会因过热而失效,电子设备的可靠性能就...

关键字: PCB 技巧 散热

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

关键字: hdu 入门

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

关键字: hdu 贪心

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

关键字: hdu 线段树

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

关键字: hdu 博弈

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

关键字: hdu 入门

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

关键字: hdu 区域赛
关闭