Party All the Time

Time Limit: 2000ms
Memory Limit: 32768KB

This problem will be judged on HDU. Original ID: 4355
64-bit integer IO format: %I64d      Java class name: Main

 
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

Source

 
 
 
解题:三分,三分,三分,三分。。。。。。。。
 
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
const double exps = 1e-;
int n;
double x[maxn],w[maxn];
double test(double px){
double sum = ;
for(int i = ; i < n; i++)
sum += fabs(px-x[i])*fabs(px-x[i])*fabs(px-x[i])*w[i];
return sum;
}
int main(){
int t,i,j,k = ;
double low,high,mid,midd;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
low = INF;
high = -INF;
for(i = ; i < n; i++){
scanf("%lf %lf",x+i,w+i);
low = min(low,x[i]);
high = max(high,x[i]);
}
while(fabs(high - low) >= exps){
mid = (high+low)/2.0;
midd = (high+mid)/2.0;
if(test(mid)+exps < test(midd))
high = midd;
else low = mid;
}
printf("Case #%d: %.0f\n",k++,test(low));
}
return ;
}

最新文章

  1. Android开发之基本控件和详解四种布局方式
  2. iOS开发常用校验
  3. 与IE奋战的血泪史
  4. .Net 程序集按需加载机制
  5. GOF业务场景的设计模式-----工厂模式
  6. 通过maven下载jar包
  7. Eclipse下编写的web项目部署到tomcat下
  8. linux下mysql定时备份数据库
  9. rtp的封包与拆包h264
  10. 简单的web三层架构系统【第二版】
  11. iOS项目在非测试设备上的安装方法(项目上线前)
  12. (图文实例)用VB.net操作SQLite数据库
  13. 新浪微博Oauth2.0授权认证及SDK、API的使用(Android)
  14. NewLife.Net——网络压测单机1.88亿tps
  15. k64 datasheet学习笔记39---Programmable Delay Block (PDB)
  16. Angular ( 一 ) angular的安装
  17. lua 的语法糖
  18. 云服务jdk 升级为 OpenJDK11
  19. IE6 select穿透问题(div 定位无法遮盖select)!
  20. MyEclipse10安装Log4E插件

热门文章

  1. 用python编写的excel拆分小工具
  2. poj2112Optimal Milking(二分+最大流)
  3. 【C#】枚举
  4. springboot项目启动问题
  5. re匹配语法-match、search和findall
  6. 毕业设计:主界面(ViewPager + FragmentPagerAdapter)
  7. Sql Server 2008R2升级 Sql Server 2012 问题
  8. 正确使用MySQL JDBC setFetchSize()方法解决JDBC处理大结果集 java.lang.OutOfMemoryError: Java heap space
  9. ie 导出不行,不兼容问题,或只出现后缀文件无法识别
  10. COGS 1743. 忠诚