Party All the Time

Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4282    Accepted Submission(s): 1355

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
 
Author
Enterpaise@UESTC_Goldfinger
 
Source
 
 
题目大意:n个人要在某一条线段某位置聚会,这n个人开始有一个坐标xi,一个体重wi,每个人到该位置距离设为S。让你算所有人到该位置的S^3*w的和最小。求出最小和。
 
 
解题思路:套用三分求解。
 
#include<bits/stdc++.h>
using namespace std;
typedef long long INT;
const int maxn=1e5+200;
int n;
const int Mv=1e6;
const double eps=1e-2;
struct Spirit{
double x;
double w;
}spirits[5*maxn];
double Abs(double xx){
return xx>0?xx:-xx;
}
double Pow(double x,int nn){
double ret=1.0;
for(int i=1;i<=nn;i++)
ret*=x;
return ret;
}
double cal(double xx){
double sum=0;
for(int i=1;i<=n;i++){
sum+=Pow(Abs(spirits[i].x-xx),3)*spirits[i].w;
}
return sum;
}
double three_div(double L,double R){ //三分求最值
double mid=(L+R)/2,mid_L=(L+mid)/2;
while(Abs(cal(mid)-cal(mid_L))>eps){ //条件应该视情况而定
mid=(R+L)/2.0;
mid_L=(L+mid)/2.0;
if(cal(mid)>cal(mid_L)){
R=mid;
}else{
L=mid_L;
}
}
return mid; //得到最值的坐标位置
}
int main(){
int t,cnt=0;
scanf("%d",&t);
double min_v=Mv*(-1.0),max_v=Mv*1.0;
while(t--){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%lf%lf",&spirits[i].x,&spirits[i].w);
}
double xx=three_div(min_v,max_v);
printf("Case #%d: %lld\n",++cnt,(INT)(cal(xx)+0.5));
}
return 0;
}

  

 

HDU 4355——Party All the Time——————【三分求最小和】的更多相关文章

  1. HDU 2795——Billboard——————【单点更新、求最小位置】

    Billboard Time Limit:8000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit St ...

  2. hdu 3746 Cyclic Nacklace(next数组求最小循环节)

    题意:给出一串字符串,可以在字符串的开头的结尾添加字符,求添加最少的字符,使这个字符串是循环的(例如:abcab 在结尾添加1个c变为 abcabc 既可). 思路:求出最小循环节,看总长能不能整除. ...

  3. hdu3756 三分求最小圆锥

    题意:       让你找到一个最小的圆柱去覆盖所有的竖直的线段.. 思路:       三分,直接去三分他的半径,因为想下,如果某个半径是最优值,那么 从R(MAX->now->MIN) ...

  4. codeforces 782B The Meeting Place Cannot Be Changed+hdu 4355+hdu 2438 (三分)

                                                                   B. The Meeting Place Cannot Be Change ...

  5. hdu 5017 模拟退火/三分求椭圆上离圆心最近的点的距离

    http://acm.hdu.edu.cn/showproblem.php?pid=5017 求椭圆上离圆心最近的点的距离. 模拟退火和三分套三分都能解决 #include <cstdio> ...

  6. hdu 4507 数位dp(求和,求平方和)

    http://acm.hdu.edu.cn/showproblem.php?pid=4507 Problem Description 单身! 依旧单身! 吉哥依旧单身! DS级码农吉哥依旧单身! 所以 ...

  7. HDU - 3035 War(对偶图求最小割+最短路)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3035 题意 给个图,求把s和t分开的最小割. 分析 实际顶点和边非常多,不能用最大流来求解.这道题要用 ...

  8. 模板题 + KMP + 求最小循环节 --- HDU 3746 Cyclic Nacklace

    Cyclic Nacklace Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=3746 Mean: 给你一个字符串,让你在后面加尽 ...

  9. HLJU 1221: 高考签到题 (三分求极值)

    1221: 高考签到题 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 9  Solved: 4 [Submit][id=1221">St ...

随机推荐

  1. H - the Sum of Cube(水题)

    A range is given, the begin and the end are both integers. You should sum the cube of all the intege ...

  2. P1472 奶牛家谱 Cow Pedigrees

    题意:问你指定二叉树有几种 1.高度为k 2.节点数为n 3.每个点的度为0或2 爆搜------->30分QAQ 首先,因为每个节点度为0或2, 所以如果n是偶数直接输出0就行了吧(嘿嘿) 如 ...

  3. 浅谈c语言的线性表的基本操作———基于严蔚敏的数据结构(c语言版)

    主要讲的是线性表的创建,插入及删除: 0. 线性表的建立,对于这类操作主要是利用了结构体的性质,对于定义的线性表的特性主要有三点:首先 Typedef struct { ElemType   *ele ...

  4. Experimental Educational Round: VolBIT Formulas Blitz F

    Description One company of IT City decided to create a group of innovative developments consisting f ...

  5. 浅谈dedecms模板引擎工作原理及其自定义标签

    浅谈dedecms模板引擎工作原理: 理解织梦模板引擎有什么意思? 可以更好地自定义标签.更多在于了解织梦系统,理解模板引擎是理解织梦工作原理的第一步. 理解织梦会使我们写PHP代码是更顺手,同时能学 ...

  6. day_04 列表

    1. 列表list 能装对象的对象,有序的(按照我们存放的顺序) 以[]表示,里面可以存放大量各种元素,各个元组用逗号隔开 列表也具有索引和切片 2. 列表的增改删查 1. 增 1.append() ...

  7. msyql操作100题

    1.1.1 开启MySQL服务 /etc/init.d/mysqld start 使用/etc/init.d/mysqld start命令启动数据库的本质就相当于执行mysqld_safe --use ...

  8. 你不得不知道的5个神奇的Docker工具

    Docker社区非常活跃,每天都会推出大量有用的工具.要想持续追踪社区中发生的各项创新其实非常困难.为了帮助你,我收集了一些每天在日常工作中使用.令人感兴趣并且十分有用的Docker工具.这些工具消除 ...

  9. PHP任意文件上传漏洞(CVE-2015-2348)

    安全研究人员今天发布了一个中危漏洞——PHP任意文件上传漏洞(CVE-2015-2348). 在上传文件的时候只判断文件名是合法的文件名就断定这个文件不是恶意文件,这确实会导致其他安全问题.并且在这种 ...

  10. centos 7 安装 最小化 碰到的问题

    1)分区推荐 2)更新yum源  (收藏 https://mirror.webtatic.com/yum/el7/) cd /etc/yum.repos.d/ 更新源 wget http://mirr ...