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. C - 又见GCD

    有三个正整数a,b,c(0<a,b,c<10^6),其中c不等于b.若a和c的最大公约数为b,现已知a和b,求满足条件的最小的c.  Input第一行输入一个n,表示有n组测试数据,接下来 ...

  2. 【阿圆实验】Alertmanager HA 高可用配置

    注意:没有使用supervisor进程管理器的,只参考配置,忽略和supervisor相关命令.并且alertmanager的版本不得低于0.15.2,低版本alert不支持集群配置. 一.alert ...

  3. Java性能优化之高性能JAVA代码的若干个习惯

    创建对象: 1.避免在循环体中创建对象,循环前应该创建对象,避免浪费更多内存空间和增加GC负担 这种情况在我们的实际应用中经常遇到,而且我们很容易犯类似的错误,例如下面的代码: for (int i ...

  4. 解决“System.Data.OracleClient 需要 Oracle 客户端软件 version 8.1.7 或更高版本”的问题

    以server2008为例: 首先确保使用sqlplus能访问数据库. 1.管理工具->计算机管理->本地用户和组->组->administrators属性,添加,高级,立即查 ...

  5. iOS 上的相机捕捉 swift

    第一台 iPhone 问世就装有相机.在第一个 SKDs 版本中,在 app 里面整合相机的唯一方法就是使用 UIImagePickerController,但到了 iOS 4,发布了更灵活的 AVF ...

  6. 弃用serv-u,改用 Xlight FTP

    Serv-u 强大,设置也较麻烦一点,针对serv-u的攻击也很丰富.试用期只有一个月,破解版的用着也不放心 Xlight FTP 设置简单,个人版免费使用,感觉良好!

  7. SprimgMVC学习笔记(二)—— 整合Mybatis

    一.整合思路 1.1 Dao层 SqlMapConfig.xml:空文件即可,但是需要文件头. applicationContext-dao.xml 数据库连接池 SqlSessionFactory对 ...

  8. java 柱状图、折线图、饼状图

    1.绘制柱状图: //BarChartTool工具类代码 package GUIview; import HibernateTool.HibernateTools; import ProductCla ...

  9. lintcode - 删除数字

    class Solution { public: /* * @param A: A positive integer which has N digits, A is a string * @para ...

  10. 时间复杂度——cin加速器

    static auto _=[]() { ios::sync_with_stdio(false); cin.tie(); ; }(); 代码简析:   cin,cout效率低是因为他们要将输入输出的数 ...