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. SQLyog使用,连接ubuntu虚拟机(Error No.2003)

    1.为mysql设置远程访问权限 mysql> grant all PRIVILEGES on *.* to ‘账号’@’%’ identified by ‘密码′; mysql> flu ...

  2. 小 M 的算式(dfs)

    [问题描述]小 M 在做数学作业的时候遇到了一个有趣的问题:有一个长度为 n 的数字串 S,小 M 需要在数字之间填入若干个“+”和恰好一个“=”,使其成为一个合法的等式.如对于 S=“2349”,可 ...

  3. 浅谈UBUNTU

    一 UBUNTU介绍 Ubuntu(乌班图)是一个以桌面应用为主的Linux操作系统,其名称来自非洲南部祖鲁语或豪萨语的"ubuntu"一词,意思是"人性".& ...

  4. 手机APP测试

    注:以下内容来自网络: 一.手机APP测试类型 1.1 接口协议测试 在APP客户端开发设计时,一般服务端会提供相应的接口协议文档,接口协议文档的质量,决定了APP的开发进度.此部分的测试,应首先检测 ...

  5. 基于vue框架项目开发过程中遇到的问题总结(一)

    (一)关于computed修改data里变量的值 问题:computed里是不能直接修改data里变量的值,否则在git commit 时会报错 解决:在computed里使用get和set来进行获取 ...

  6. 【转】PHP微信上传永久图片素材

    $TOKEN="XXXX"; $file = "D:\www\weixin\game.jpg"; $data = array( 'media'=> new ...

  7. linux下redis的安装与django-redis使用方法

    Redis 是一个开源(BSD许可)的,内存中的数据结构存储系统,它可以用作数据库.缓存和消息中间件. Redis支持五种数据类型:string(字符串),hash(哈希),list(列表),set( ...

  8. 【bzoj4939】【YNOI2016】掉进兔子洞(莫队)

    题目描述 您正在打galgame,然后突然发现您今天太颓了,于是想写个数据结构题练练手: 一个长为 n 的序列 a. 有 m 个询问,每次询问三个区间,把三个区间中同时出现的数一个一个删掉,问最后三个 ...

  9. (Python OpenGL)【5】平移 PyOpenGL

    (Python OpenGL) 原文:http://ogldev.atspace.co.uk/www/tutorial06/tutorial06.html  (英文) 下面是我翻译过来的: 背景 在本 ...

  10. 使用esp32-Arduino+PubSubClient+mqtt 上传数据到中移动OneNet

    使用esp32-doit-dev-v1开发板,测试mqtt协议, 发布(publish)到onenet 平台.注意:1.使用的mqtt arduino 客户端是 pubsubclient 库.其默认是 ...