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. Android按钮单击事件处理的几种方法(Android学习笔记)

    方法一:匿名内部类实现按钮事件处理 this.btnButton=(Button)super.findViewById(R.id.mybtn); this.btnButton.setOnClickLi ...

  2. QQ空间爬虫--获取好友信息

    QQ空间网页版:https://user.qzone.qq.com/ 登陆后,进入设置,有一个权限设置,设置“谁能看我的空间”为好友可见,然后构造爬虫. (1)获取Cookie 两种方式: 第一种:通 ...

  3. flask + pymysql操作Mysql数据库

    安装flask-sqlalchemy.pymysql模块 pip install flask-sqlalchemy pymysql ### Flask-SQLAlchemy的介绍 1. ORM:Obj ...

  4. P1630 求和

    题意:求$\sum_{i=1}^a i^b,a,b\le 10^9$ 暴力只有30分QAQ(本数学蒟蒻当然想不到正解啦) 正解:模数很小,不难(?)想到$i^a%10000=(i+b)^a %1000 ...

  5. windows mysql导入sql文件

    当需要的sql文件很大时(>200M)怎么办?答:修改my.ini文件,max_allowed_packet的值可以设置为1024M 进入mysql.exe目录下,执行如下命令: mysql - ...

  6. Redis学习笔记(2)—— Redis的安装和使用

    一.CentOS安装Redis 1.1 安装环境 redis是C语言开发的,安装redis需要先将官网下载的源码进行编译,编译依赖gcc环境.如果没有gcc环境,需要安装gcc: yum instal ...

  7. 根据map中某一字段排序

    以上是从小到大的排序...要注意.! 需要jdk8...

  8. Web项目和Windows应用程序的配置文件

    1.Web项目,配置文件应创建在Web项目下,即使是要把配置文件作为一个单独的文件进行配置(比如log4net.config),也需要把该配置文件放在Web项目下:同理Windows应用程序的化,配置 ...

  9. javascript中的一元操作符

    题目如下: var s1 = "01"; var s2 = "1.1"; var s3 = "z"; var b = false; var ...

  10. management & Actuator

    self define indicator https://docs.spring.io/spring-boot/docs/current/reference/html/production-read ...