Party All the Time

Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5462    Accepted Submission(s): 1707

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<=i<N). The i-th line contains two real number : Xi,Wi, representing the location and the weight of the i-th spirit. ( |xi|<=106, 0<wi<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
 
 
直接代码了
#include<bits/stdc++.h>
using namespace std;
#define N 50500
struct node{
double p;
double w;
}a[N];
int n;
double sum(double mid){
double sum=0.0;
for(int i=;i<n;i++){
double s=fabs(a[i].p-mid);
sum+=s*s*s*a[i].w;
}
return sum;
}
double sanfen(double l,double r){
double mid,midd,ans1,ans2,left,right;
left=l;right=r;
while(left+0.000000001<right){
mid=(left+right)/2.0;
midd=(mid+right)/2.0;
ans1=sum(mid);
ans2=sum(midd);
if(ans1<ans2)right=midd;
else left=mid;
}
return left;
}
int main(){
int t,num;
double left,right,ans,m;
num=;
while(~scanf("%d",&t)){
while(t--){
num++;
left=1e5;right=1e-;
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%lf%lf",&a[i].p,&a[i].w);
left=min(left,a[i].p);
right=max(right,a[i].p);
}
m=sanfen(left,right);
ans=sum(m);
printf("Case #%d: %.0lf\n",num,ans);
}
}
return ;
}
 

HDU4355-Party All the Time-三分的更多相关文章

  1. hdu4355 三分

    F - 三分 Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:32768KB     64bit I ...

  2. HDU4355 三分查找

    /*  * 三分查找  */ #include<cstdio> #include<cmath> #define eps 1e-6 //typedef __int64 LL; i ...

  3. hdu3714 三分找最值

    Error Curves Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  4. BZOJ 1857 传送带 (三分套三分)

    在一个2维平面上有两条传送带,每一条传送带可以看成是一条线段.两条传送带分别为线段AB和线段CD.lxhgww在AB上的移动速度为P,在CD上的移动速度为Q,在平面上的移动速度R.现在lxhgww想从 ...

  5. hdu 4717(三分求极值)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4717 思路:三分时间求极小值. #include <iostream> #include ...

  6. HDU2438 数学+三分

    Turn the corner Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  7. 三分之一的程序猿之社交类app踩过的那些坑

    三分之一的程序猿之社交类app踩过的那些坑 万众创新,全民创业.哪怕去年陌生人社交不管融资与否都倒闭了不知道多少家,但是依然有很多陌生人社交应用层出不穷的冒出来.各种脑洞大开,让人拍案叫起. 下面我们 ...

  8. 基于jPlayer的三分屏制作

    三分屏,这里的三分屏只是在一个播放器里同时播放三个视频,但是要求只有一个控制面板同时控制它们,要求它们共享一个时间轨道.这次只是简单的模拟了一下功能,并没有深入的研究. 首先,需要下载jPlayer, ...

  9. 【BZOJ-1857】传送带 三分套三分

    1857: [Scoi2010]传送带 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 1077  Solved: 575[Submit][Status][ ...

  10. ACM : HDU 2899 Strange fuction 解题报告 -二分、三分

    Strange fuction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...

随机推荐

  1. iOS UI特效

    1.iOS特效 a.对应APP中的基本动作分三类: 1.指向性动效(滑动,弹出等) 2.提示性动效(滑动删除,下拉刷新等) 3.空间扩展(翻动,放大等) b.这类动效在设计过程中需要主意几点: 1.系 ...

  2. iOS 控制器的跳转、页面四个方向的跳转

    指定滑动方向的跳转 CATransition *transition = [CATransition animation]; transition.duration = 0.3f; transitio ...

  3. mvn命令笔记

    #发布到本地仓库 mvn deploy -DaltDeploymentRepository=snapshots::default::http://mvnrepo.xxx.com/mvn/snapsho ...

  4. ArcGIS API for JavaScript 4.2学习笔记[11] 官方第五章Popups(弹窗)概览与解释

    直接跳过第三第四章了,第三章Layer和第四章可视化,怎么说呢,Layer是组织数据的,是Map的属性之一.可视化属于符号化编程,暂时不看. 第五章是对数据.结果的显示,类似于alert()..NET ...

  5. Python练习100则--部分概念的没有做

    # coding = utf-8 import math, osfrom random import randint def Binary(): res = int(-1 / 2) res1 = in ...

  6. DNS查询的工作原理

    二.DNS查询的工作原理 1.DNS查询过程按两部分进行     1.名称查询从客户端计算机开始, 并传送给本机的DNS客户服务程序进行解析     2.如果不能再本机解析查询, 可根据设定的查询DN ...

  7. 串口调试者v2.1------开源c#串口调试工具

    第一步:上图 第二步:上代码 >>>>>>>>>>>源代码下载<<<<<<<<< ...

  8. 10 Easy Steps to a Complete Understanding of SQL

    原文出处:http://tech.pro/tutorial/1555/10-easy-steps-to-a-complete-understanding-of-sql(已经失效,现在收集如下) Too ...

  9. C# new关键字和对象类型转换(双括号、is操作符、as操作符)

    一.new关键字 CLR要求所有的对象都通过new来创建,代码如下: Object obj=new Object(); 以下是new操作符做的事情 1.计算类型及其所有基类型(一直到System.Ob ...

  10. js间隔几秒弹出一次联系框

    运行效果截图如下: 在线演示地址如下: http://demo.jb51.net/js/2015/js-3-sec-alert-dlg-codes/ 具体代码如下: <html> < ...