xtu summer individual-4 B - Party All the Time

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

2012 Multi-University Training Contest 6

解题:三分,三分,三分,三分。。。。。。。。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cmath>
 5 #include <algorithm>
 6 #include <climits>
 7 #include <vector>
 8 #include <queue>
 9 #include <cstdlib>
10 #include <string>
11 #include <set>
12 #define LL long long
13 #define INF 0x3f3f3f3f
14 using namespace std;
15 const int maxn = 50010;
16 const double exps = 1e-7;
17 int n;
18 double x[maxn],w[maxn];
19 double test(double px){
20     double sum = 0;
21     for(int i = 0; i < n; i++)
22         sum += fabs(px-x[i])*fabs(px-x[i])*fabs(px-x[i])*w[i];
23     return sum;
24 }
25 int main(){
26     int t,i,j,k = 1;
27     double low,high,mid,midd;
28     scanf("%d",&t);
29     while(t--){
30         scanf("%d",&n);
31         low = INF;
32         high = -INF;
33         for(i = 0; i < n; i++){
34             scanf("%lf %lf",x+i,w+i);
35             low = min(low,x[i]);
36             high = max(high,x[i]);
37         }
38         while(fabs(high - low) >= exps){
39             mid = (high+low)/2.0;
40             midd = (high+mid)/2.0;
41             if(test(mid)+exps < test(midd))
42                 high = midd;
43             else low = mid;
44         }
45         printf("Case #%d: %.0f\n",k++,test(low));
46     }
47     return 0;
48 }

xtu summer individual-4 B - Party All the Time

时间: 2024-12-27 14:34:40

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

xtu summer individual 6 B - Number Busters

Number Busters Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Original ID: 382B64-bit integer IO format: %I64d      Java class name: (Any) Arthur and Alexander are number busters. Today they've got a competition.

xtu summer individual 1 E - Palindromic Numbers

E - Palindromic Numbers Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Description A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the same when its digits are reversed. In this

xtu summer individual 6 D - Checkposts

Checkposts Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Original ID: 427C64-bit integer IO format: %I64d      Java class name: (Any) Your city has n junctions. There are m one-way roads between the junctions. A

xtu summer individual 5 D - Subsequence

Subsequence Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 353064-bit integer IO format: %I64d      Java class name: Main There is a sequence of integers. Your task is to find the longest subsequence that sa

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 HDU. Original ID: 329564-bit integer IO format: %I64d      Java class name: Main XQ,one of the three Sailormoon girls,is usually playing mobile games o

xtu summer individual 2 C - Hometask

Hometask Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Original ID: 154A64-bit integer IO format: %I64d      Java class name: (Any) Sergey attends lessons of the N-ish language. Each lesson he receives a hometas

xtu summer individual 5 F - Post Office

Post Office Time Limit: 1000ms Memory Limit: 10000KB This problem will be judged on PKU. Original ID: 116064-bit integer IO format: %lld      Java class name: Main There is a straight highway with villages alongside the highway. The highway is repres

xtu summer individual 5 A - To Add or Not to Add

To Add or Not to Add Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Original ID: 231C64-bit integer IO format: %I64d      Java class name: (Any) A piece of paper contains an array of n integers a1, a2, ..., an. Y

xtu summer individual 5 E - Burning Bridges

Burning Bridges Time Limit: 5000ms Memory Limit: 32768KB This problem will be judged on ZJU. Original ID: 258864-bit integer IO format: %lld      Java class name: Main Ferry Kingdom is a nice little country located on N islands that are connected by

xtu summer individual 2 D - Colliders

Colliders Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Original ID: 155D64-bit integer IO format: %I64d      Java class name: (Any) By 2312 there were n Large Hadron Colliders in the inhabited part of the unive