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 ;
}

xtu summer individual-4 B - Party All the Time的更多相关文章

  1. xtu summer individual 4 C - Dancing Lessons

    Dancing Lessons Time Limit: 5000ms Memory Limit: 262144KB This problem will be judged on CodeForces. ...

  2. xtu summer individual 3 C.Infinite Maze

    B. Infinite Maze time limit per test  2 seconds memory limit per test  256 megabytes input standard ...

  3. xtu summer individual 2 E - Double Profiles

    Double Profiles Time Limit: 3000ms Memory Limit: 262144KB This problem will be judged on CodeForces. ...

  4. xtu summer individual 2 C - Hometask

    Hometask Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Origin ...

  5. xtu summer individual 1 A - An interesting mobile game

    An interesting mobile game Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on H ...

  6. xtu summer individual 2 D - Colliders

    Colliders Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Origi ...

  7. xtu summer individual 1 C - Design the city

    C - Design the city Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu D ...

  8. xtu summer individual 1 E - Palindromic Numbers

    E - Palindromic Numbers Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %l ...

  9. xtu summer individual 1 D - Round Numbers

    D - Round Numbers Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u D ...

  10. xtu summer individual 5 F - Post Office

    Post Office Time Limit: 1000ms Memory Limit: 10000KB This problem will be judged on PKU. Original ID ...

随机推荐

  1. Codeforces Round #323 (Div. 2)

    被进爷坑了,第二天的比赛改到了12点 水 A - Asphalting Roads /************************************************ * Author ...

  2. B. Connecting Universities DFS,无向树

    http://codeforces.com/problemset/problem/700/B 题意是,在一颗树中,有k个大学,要求两两匹配,他们之间的距离作为贡献,使得距离总和最大. 一开始的时候无从 ...

  3. 1051 - Good or Bad DFS 记忆化搜索

    http://lightoj.com/volume_showproblem.php?problem=1051 对于每个位置,设dfs(cur, one, two)表示前i个字母,拥有辅音字母one个, ...

  4. JavaScript中函数是不能重载原因

    以前有一次写JS插件的时候,由于后台写习惯了,妄想在JS中写重载函数,可惜不能成功,原因花了一点时间记了下来 首先要理解重载的含义:函数返回值不同或者形式参数个数不同但函数名相同的函数 JavasSc ...

  5. JAVA 运用流编程实现简单的"记事本"功能

    一.概要 1.功能介绍 2.实现的思路及步骤代码 3.完整代码 二.功能 运用IO流和Swing实现简单的记事本功能(打开.保存.退出) 三.思路及实现步骤 1.在构造函数中画出操作界面 //创建jt ...

  6. AJPFX总结jvm运行时内存分布

    jvm的运行过程中将java程序运行时数据区分为以下几个部分:      (1)程序计数器:存储虚拟机字节码执行的地址 (2)java虚拟机栈:java方法运行时的局部变量表,操作数栈,方法出口等 ( ...

  7. SSM-WebMVC(三)

    SSM-WebMVC(三) 一.Annotated Controllers ​ 应用程序控制器 handlerMethod(处理方法) ㈠方法入参 ​ (springmvc针对于在controller ...

  8. 进程间通信的两种实现方式(IPC)

    进程间通信的两种实现方式(IPC) IPC: iter processing communicate 进程间通信:IPC(iter process communicate)linux free-m 可 ...

  9. ios 微信环境 axios请求 status 0

    做了一个支付页面,调用post请求但是请求status 0,出现这个的原因居然是https的网页请求http的数据. 但是这个再ios里面不会报错,安卓正常. 记录一下客户端的这个特征!

  10. 在项目中运用精益 - Five Why

    今天成功地运用了5个why对一个项目上的问题进行剖析,收获良多,在此分享给大家. 事情是这样的,该项目是个固定价格项目,处于收尾阶段,客户提出来了一些需求,我们(实施方)认为这些要求是不在最初项目范围 ...