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 S 3*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 : X i,W i, representing the location and the weight of the i-th spirit. ( |x i|<=10 6, 0<w i<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

基本是三分模板题(注意w也是浮点数)

代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<vector>
#include<cmath> const int maxn=1e5+5;
typedef long long ll;
using namespace std;
struct node
{
double s;
double w;
}p[maxn];
int n;
double fun(double x)
{
double sum=0;
for(int t=0;t<n;t++)
{
double ss;
ss=fabs(p[t].s-x);
sum+=ss*ss*ss*p[t].w;
}
return sum;
}
int main()
{
int T;
cin>>T;
for(int t=0;t<T;t++)
{
scanf("%d",&n);
for(int j=0;j<n;j++)
{
scanf("%lf%lf",&p[j].s,&p[j].w);
}
double l=p[0].s,r=p[n-1].s;
double m1,m2;
while(r-l>1e-6)
{ m1=(l+r)/2;
m2=(m1+r)/2;
if(fun(m1)>fun(m2)+1e-6)
{
l=m1;
}
else
{
r=m2;
}
}
int sss=fun(l)+0.5;
cout<<"Case #"<<t+1<<": "<<sss<<endl;
} return 0;
}

Party All the Time(三分)的更多相关文章

  1. hdu3714 三分找最值

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

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

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

  3. hdu 4717(三分求极值)

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

  4. HDU2438 数学+三分

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

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

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

  6. 基于jPlayer的三分屏制作

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

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

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

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

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

  9. bzoj1857: [Scoi2010]传送带--三分套三分

    三分套三分模板 貌似只要是单峰函数就可以用三分求解 #include<stdio.h> #include<string.h> #include<algorithm> ...

  10. poj3301Texas Trip(三分)

    链接 这题还真没看出来长得像三分.. 三分角度,旋转点. 最初找到所有点中最左边.右边.上边.下边的点,正方形边长为上下距离和左右距离的最大值,如图样例中的四个点(蓝色的),初始正方形为红色的正方形. ...

随机推荐

  1. ARCGIS中怎么去除重复的面?(转)

    ARCGIS中怎么去除重复的面? https://blog.csdn.net/gswwldp/article/details/66974522   第一种: 1.用polygon to line将面转 ...

  2. 内存cache使用的场景

    Q.业务场景内为什么要使用内存cache? A.为了利用内存cache的优点, 解决业务场景内的缺陷 Q.内存cache的优点和缺点 A.优点: 内存读写速度比磁盘块 缺点: 内存空间有限, 内存单价 ...

  3. 数字图像处理实验(14):PROJECT 06-01,Web-Safe Colors 标签: 图像处理MATLAB 2017-05-27 20:45 116人阅读

    实验要求: Objective: To know what are Web-safe colors, how to generate the RGB components for a given jp ...

  4. osm2pgsql windows “illegal option -W” error

    新版本不支持 解决: 修改pg_hba.conf的METHOD为trust 参考:http://stackoverflow.com/questions/15510428/osm2pgsql-windo ...

  5. C# JackLib系列之字体使用

    字体的使用一般我们都是使用系统字体,这样比较方便,直接 Font font=new Font("微软雅黑",16f,FontStyle.Bold); 但是当我们用到一个系统没有的字 ...

  6. XE下创建及调用Frame

    1.创建Form1: 2.创建FMXFrame(New -> Other->Delphi Files -> FMXFrame); // 单元名为UnitFrame,窗体名为frm  ...

  7. Unity Ioc框架简单例子

    IOC:英文全称:Inversion of Control,中文名称:控制反转,它还有个名字叫依赖注入(Dependency Injection).作用:将各层的对象以松耦合的方式组织在一起,解耦,各 ...

  8. Linux中的SELinux与chcon以及Samba实现【转】

    一.SELinux SElinux的前身是NSA(美国国家安全局)发起的一个项目.它的目的是将系统加固到可以达到军方级别. 为什么NSA选择Linux呢? 在目前市面上大多数操作系统都是商用闭源的,只 ...

  9. .NET架构转Java开发必须了解的历史

    终于不在职守在.NET领域 .NET的winform和webform项目也开发了很多了  尤其是WEB领域 从ASP -> ASP.NET 2.0 -> ASP.NET MVC 4.0 - ...

  10. form表单以get方式提交时action中?后面的参数部分不生效

    form表单的提交方式是get方式,action="?sss=test",问号后面参数是接受不到的,谨记!