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. HtmlHelper扩展

    扩展 HtmlHelper类 public static class MyHtmlHelper { //扩展方法 //静态类,静态方法,this关键字 //调用方法<%=Html.MyLabel ...

  2. PyGrub

    from:https://wiki.debian.org/PyGrub Using pyGRUB on Wheezy to boot a domU kernel Using pyGRUB from x ...

  3. 学习PDO啦

    通过查找资料对PDO有了一定的了解,PDO(PHP Data Object )为PHP数据对象,为PHP访问数据库提供了一个轻量级的借口,但PDO本生不能实现访问数据库的任何功能,只能通过数据库的PD ...

  4. 数据库 MySQL 之 数据操作

    数据库 MySQL 之 数据操作 一.MySQL数据类型介绍 MySQL支持多种类型,大致可以分为四类:数值.字符串类型.日期/时间和其他类型. ①二进制类型 bit[(M)] 二进制位(101001 ...

  5. easyui-tabs 页签绑定click事件,动态加载jqgrid

    .前台代码 <%-- builed by manage.aspx.cmt [ver:] at // :: --%> <%@ Page Language="C#" ...

  6. Ubuntu 14.04 安装配置强大的星际译王(stardict)词典

    转载http://blog.csdn.net/huyisu/article/details/53437931

  7. [GO]将随机生成的四位数字拆分后放到一个切片里

    package main import ( "math/rand" "time" "fmt" ) func InitData(p *int) ...

  8. java 异常捕获与异常处理

    try{会产生异常的代码 }catch(出现异常的类型 e){ 异常出现后处理的方法 } 一旦异常出现又没有异常处理,程序就会中断. public static void main(String[] ...

  9. 获取下标实现导航切换jquery代码

    var lis = $(".proDetail_contentnav li");for(var i = 0; i < lis.length; i++) { lis[i].in ...

  10. 尝鲜.net core2.1 ——编写一个global tool

    本文内容参考微软工程师Nate McMaster的博文.NET Core 2.1 Global Tools 用过npm开发都知道,npm包都可以以全局的方式安装,例如安装一个http-server服务 ...