HDU 4355.Party All the Time-三分
Party All the Time
Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5462 Accepted Submission(s): 1707
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.
#include<bits/stdc++.h>
using namespace std;
#define N 50500
struct node{
double p;
double w;
}a[N];
int n;
double sum(double mid){
double sum=0.0;
for(int i=;i<n;i++){
double s=fabs(a[i].p-mid);
sum+=s*s*s*a[i].w;
}
return sum;
}
double sanfen(double l,double r){
double mid,midd,ans1,ans2,left,right;
left=l;right=r;
while(left+0.000000001<right){
mid=(left+right)/2.0;
midd=(mid+right)/2.0;
ans1=sum(mid);
ans2=sum(midd);
if(ans1<ans2)right=midd;
else left=mid;
}
return left;
}
int main(){
int t,num;
double left,right,ans,m;
num=;
while(~scanf("%d",&t)){
while(t--){
num++;
left=1e5;right=1e-;
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%lf%lf",&a[i].p,&a[i].w);
left=min(left,a[i].p);
right=max(right,a[i].p);
}
m=sanfen(left,right);
ans=sum(m);
printf("Case #%d: %.0lf\n",num,ans);
}
}
return ;
}
HDU 4355.Party All the Time-三分的更多相关文章
- codeforces 782B The Meeting Place Cannot Be Changed+hdu 4355+hdu 2438 (三分)
B. The Meeting Place Cannot Be Change ...
- hdu 4355 Party All the Time(三分搜索)
Problem Description In the Dark forest, there is a Fairy kingdom where all the spirits will go toget ...
- HDU 4355 Party All the Time (三分求极值)
题意:给定x轴上有n个点,每一个点都有一个权值,让在x轴上选一个点,求出各点到这个点的距离的三次方乘以权值最小. 析:首先一开始我根本不会三分,也并没有看出来这是一个三分的题目的,学长说这是一个三分的 ...
- HDU 4355——Party All the Time——————【三分求最小和】
Party All the Time Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDU 4355 Party All the Time(三分|二分)
题意:n个人,都要去參加活动,每一个人都有所在位置xi和Wi,每一个人没走S km,就会产生S^3*Wi的"不舒适度",求在何位置举办活动才干使全部人的"不舒适度&quo ...
- HDU 4355:Party All the Time(三分模板)
Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s) ...
- hdu 4717 The Moving Points(三分+计算几何)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4717 说明下为啥满足三分: 设y=f(x) (x>0)表示任意两个点的距离随时间x的增长,距离y ...
- hdu 5144 NPY and shot 物理+三分
NPY and shot Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Pro ...
- hdu 4717 The Moving Points(三分)
http://acm.hdu.edu.cn/showproblem.php?pid=4717 大致题意:给出每一个点的坐标以及每一个点移动的速度和方向. 问在那一时刻点集中最远的距离在全部时刻的最远距 ...
- HDU 4454 - Stealing a Cake(三分)
我比较快速的想到了三分,但是我是从0到2*pi区间进行三分,并且漏了一种点到边距离的情况,一直WA了好几次 后来画了下图才发现,0到2*pi区间内是有两个极值的,每个半圆存在一个极值 以下是代码 #i ...
随机推荐
- hdu 3357 Stock Chase (图论froyd变形)
Stock Chase Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- bootstrap table表格属性、列属性、事件、方法
留存一份,原文地址http://bootstrap-table.wenzhixin.net.cn/zh-cn/documentation/ 表格参数 表格的参数定义在 jQuery.fn.bootst ...
- [洛谷P4838]P哥破解密码
题目大意:求长度为$n$的$01$串中,没有连续至少$3$个$1$的串的个数 题解:令$a_1$为结尾一个$1$的串个数,$a_2$为结尾两个$1$的串的个数,$b$为结尾是$0$的串的个数.$a_1 ...
- Brainf**k(一位数求max)
题目大意:给你两个一位数,要你求出其中的较大值(使用$Brainf**k$) ($Brainf**k$简介,相当于有一个数组和一个指针,","为把数组当前位赋值为读入的数,&quo ...
- Android开发注意点小记
暂时主要讨论以下几点: Android引用外部包,报NoClassDefFoundError异常崩溃 同名包引用关系问题 程序图标 9patch图片素材 Android引用外部包,程序报java.la ...
- Android-使用ViewFlipper实现轮番切换广告栏
所谓的轮番切换广告栏,指的是下面这个东西,笔主不知道该怎么确切描述这货... 笔主没有百度研究过其他大牛是怎么实现这个功能的,在这里笔主充分发挥DIY精神,利用ViewFlipper闭门土制了一个,下 ...
- mybatis的注解功能
一.mybatis 简单注解 关键注解词 : @Insert : 插入sql , 和xml insert sql语法完全一样 @Select : 查询sql, 和xml select sql语法完全一 ...
- angularjs的验证信息的写法
<div ng-messages="alarmDelayForm.alarmRuleName.$error" role="alert"> <d ...
- javascript继承有5种实现方式
1.对象冒充 function Parent(username){ this.username = username; this.hello = function(){ alert(this.user ...
- tomcat编码配置
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" ...