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. Xamarin截取/删除emoji表情bug解决方案

    大家都知道,一个英文=1字节,一个汉字2字节,而一个emoji表情=4个字节,在有这三种混用的时候,比如app聊天界面,那么删除和截取便成了很头痛的事情. 问题描述 截取导致乱码,如下图: 解决方案 ...

  2. 2018年的UX设计师薪酬预测,你能拿多少?

    以下内容由Mockplus团队翻译整理,仅供学习交流,Mockplus是更快更简单的原型设计工具.   一个经验丰富的设计师完全可以根据地区和专业来可以预期薪酬之间的差距,其中悬殊最高可达80K. 本 ...

  3. bzoj 3551: [ONTAK2010]Peaks加强版

    Description [题目描述]同3545 Input 第一行三个数N,M,Q. 第二行N个数,第i个数为h_i 接下来M行,每行3个数a b c,表示从a到b有一条困难值为c的双向路径. 接下来 ...

  4. LODOP打印控件示例

    一.lodop打印预览效果图 LODOP.PRINT_SETUP();打印维护效果图 LODOP.PREVIEW();打印预览图 二.写在前面 最近项目用到了LODOP的套打,主要用到两个地方,一是物 ...

  5. phpexcel用法(转)

    .php导出excel(多种方法) (2013-03-23 15:44:02) 转载▼   分类: php 基本上导出的文件分为两种: 1:类Excel格式,这个其实不是传统意义上的Excel文件,只 ...

  6. 获取SpringMVC的映射路径

    public String init(HttpServletRequest request, HttpServletResponse response){ List<String> uLi ...

  7. Jmeter中java.net.URISyntaxException错误

    今天在做服务发布性能测试的时候,傻傻的犯了个错,没有对参数进行仔细的检查,直接从fiddler中copy到jmeter中了,业务流程配置好后执行测试报错... jmeter中的响应结果如下: java ...

  8. java的运行机制(基础)

    1:高级语言的运行机制: 我们编程都是用的高级语言(写汇编和机器语言的大牛们除外),计算机不能直接理解高级语言,只能理解和运行机器语言,所以必须要把高级语言翻译成机器语言,计算机才能运行高级语言所编写 ...

  9. golang sql database drivers

    https://github.com/golang/go/wiki/SQLDrivers SQL database drivers The database/sql and database/sql/ ...

  10. python爬虫爬取大众点评并导入redis

    直接上代码,导入redis的中文编码没有解决,日后解决了会第一时间上代码!新手上路,多多包涵! # -*- coding: utf-8 -*- import re import requests fr ...