<html>

题意:一个数轴上有n个点,如今要找一个点到全部点的距离Si的立方乘以点的权Wi的和最小

分析:三分。

浮点数的二分或者三分能够直接用一个数字来限制查找的次数。

TLE了几次,把查找次数从10000改到100就过了,本来以为数据范围比較大,100的精度不够。

代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#define eps 1e-8
#define eps2 1e-5
#define INF  100000000000007
using namespace std;
int t,n;
double x[100005],w[100005];
double ans;
long long ans1;
double dis(double a,double b)
{
	if(a>b){
		double tmp=a;
		a=b;
		b=tmp;
	}
	return pow((b-a),3);
	
}
double ll(double a)
{
	double sum=0;
	for(int i=0;i<n;i++){
		sum+=dis(a,x[i])*w[i];
	}
	return sum;
}
double find(double left,double right)
{
	double l=left,r=right;
	double ans1,ans2;
	for(int i=0;i<100;i++){
		double mid1=(l+r)/2.0;
		double mid2=(mid1+r)/2.0;
		ans1=ll(mid1);
		ans2=ll(mid2);
		if(ll(mid1)<ll(mid2))  r=mid2;
		else  l=mid1;
	}
	return ans1;
}
int main()
{
	scanf("%d",&t);
	for(int cas=1;cas<=t;cas++){
		scanf("%d",&n);
		for(int i=0;i<n;i++) scanf("%lf%lf",&x[i],&w[i]);
		ans=find(x[0],x[n-1]);
	    ans1=(long long int)(ans+0.5);	
		printf("Case #%d: %I64d\n",cas,ans1);
	}
}


版权声明:本文为博主原创文章。未经博主同意不得转载。 举报
  • 本文已收录于下面专栏:

相关文章推荐

(swf file format spec v10)swf文件格式中英文说明书v10,定点数浮点数,笔记3

Fixed-point numbers The SWF file format supports two types of fixed-point numbers: 32-bit and 16-bit. The 32-bit fixed-point numbers are 16.16. That is, the high 16 bits represent the number before the decimal point, and the low 16 bits represent the number after the decimal point. FIXED values

Party All the Time HDU - 4355 三分

DescriptionIn the Dark forest, there is a Fairy kingdom where all the spirits will go together and C...

[转]浮点数在计算机中存储方式与浮点(float。double)不精确问题

作者: jillzhang 联系方式:jillzhang@126.com C语言和C#语言中,对于浮点类型的数据採用单精度类型(float)和双精度类型(double)来存储,float数据占用 32bit,double数据占用64bit,我们在声明一个变量float f= 2.25f的时候。是怎样分配内存的呢?假设胡乱分配。那世界岂不是乱套了么。事实上不论是float还是double在存储方式上都是遵从IEEE的规范的,float遵从的是IEEE R32.24 ,而double 遵从的是R64.53。

不管是单精度还是双精度在存储中都分为三个部分:

hdu4355(三分)

题意:在森林里面,举行一个庆祝大典须要选定一个地点(一维的直线上),各位精灵不开心值和自己须要移动的距离和本身一个权值有关,计算公式是距离差^3乘以权值,全部精灵不开心值之和满足一个二次函数,有一个最...

hdu 4355 Party All the Time 三分

Problem Description In the Dark forest, there is a Fairy kingdom where all the spirits will go toge...

浮点数的计算注意点

System.out.println(2.1-1.2); System.out.println(2.1-0.1); System.out.println(2.1f-1.2f); System.out.println((new BigDecimal("4.0")).subtract(new BigDecimal("3.1")).doubleValue()); result: 0.9000000000000001 2.0 0.89999986 0.9 总结:当差额大于1时。计算的结果就是你希望得到的,当差额小于1时。因为浮点结算的原因(double、fl

HDU 4355-三分

http://acm.hdu.edu.cn/showproblem.php?pid=4355 题目 给n个人的位置 和 权值w 选 数轴上一实数点。 求每一个人到该点的距离dis的三次方*w。的和 ...

HDU 4355 Party All the Time(三分)

转载请注明出处。谢谢<a href="http://blog.csdn.net/acm_cxlove/

三分求一元三次方程的极值:hdu 4355

转:http://blog.csdn.net/rabia/article/details/7826144     二分法作为分治中最常见的方法。在各种比赛中常常出现(如:POJ 1434),但仅仅适用...
  • 微博
    微信
    QQ
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多仅仅同意输入30个字)

posted @ 2017-08-14 16:01  wzzkaifa  阅读(183)  评论(0编辑  收藏  举报