HDU ACM 2547无剑无我

分析:

f(x,y,a,b)+f(x,y,c,d)=sqrt(x^2+y^2+a^2+b^2-2*a*x-2*b*y)+sqrt(x^2+y^2+c^2+d^2-2*c*x-2*d*y)

=sqrt((x-a)^2+(y-b)^2)+sqrt((x-c)^2+(y-d)^2)也就是C点分别到A点B点的距离之和,因此要使最小,则C点应在AB线段上,所以最小值等于AB之间的距离。

#include<iostream>
#include<cmath>
using namespace std;

int main()
{
	int t;
	double a,b,c,d;

	cin>>t;
	while(t--)
	{
		cin>>a>>b>>c>>d;
		printf("%.1lf\n",sqrt((a-c)*(a-c)+(b-d)*(b-d)));
	}
    return 0;
}
时间: 2024-12-10 23:58:24

HDU ACM 2547无剑无我的相关文章

HDOJ/HDU 2547 无剑无我(两点间的距离)

Problem Description 北宋末年,奸臣当道,宦官掌权,外侮日亟,辽军再犯.时下战火连连,烽烟四起,哀鸿遍野,民不聊生,又有众多能人异士群起而反,天下志士云集响应,景粮影从. 值此危急存亡之秋,在一个与世隔绝的地方-MCA山上一位江湖人称<英雄哪里出来>的人正在为抗击辽贼研究剑法,终于于一雷电交加之夜精确计算出了荡剑回锋的剑气伤害公式. 定义 f(x, y, m, n) = sqrt(x*x + y*y + m*m + n*n - 2*m*x - 2*n*y); hint : s

HDU 2547 无剑无我(数学)

#include<cstdio> #include<iostream> #include<cmath> int main() { double a,b,c,d,m; int t; scanf("%d",&t); while(t--) { scanf("%lf%lf%lf%lf",&a,&b,&c,&d); m=sqrt((a-c)*(a-c)+(b-d)*(b-d)); printf(&qu

acm hdu p2547 无剑无我{水水水}

无剑无我 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4112    Accepted Submission(s): 2638 Problem Description 北宋末年,奸臣当道,宦官掌权,外侮日亟,辽军再犯.时下战火连连,烽烟四起,哀鸿遍野,民不聊生,又有众多能人异士群起而反,天下志士云集响应,景粮影从. 值此危急存亡之秋

HDU2547 无剑无我【水题】

无剑无我 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3811    Accepted Submission(s): 2429 Problem Description 北宋末年,奸臣当道,宦官掌权,外侮日亟,辽军再犯.时下战火连连,烽烟四起,哀鸿遍野,民不聊生,又有众多能人异士群起而反,天下志士云集响应,景粮影从. 值此危急存亡之秋

HDU ACM 1103 Flo&#39;s Restaurant

分析:借助STL的min_element实现.每次更新最先被占用的桌子,具体见注释. #include<iostream> #include<algorithm> using namespace std; int main() { int A,B,C; char s[10]; int a[102],b[102],c[102]; int curtime,count,ans; int *p; //桌子最先空闲时间 while(cin>>A>>B>>C

hdu acm 1425 sort(哈希表思想)

sort Time Limit: 6000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 25803    Accepted Submission(s): 7764 Problem Description 给你n个整数,请按从大到小的顺序输出其中前m大的数. Input 每组测试数据有两行,第一行有两个数n,m(0<n,m<1000000),第二行包含n个各不相同,且

HDU ACM 1005 Number Sequence

Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 119732    Accepted Submission(s): 29072 Problem Description A number sequence is defined as follows:f(1) = 1, f(2) = 1, f(n) = (A

hdu acm 1166 敌兵布阵 (线段树)

敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 37903    Accepted Submission(s): 15985 Problem Description C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务

HDU ACM 1025 Constructing Roads In JGShining&amp;#39;s Kingdom-&amp;gt;二分求解LIS+O(NlogN)

#include<iostream> using namespace std; //BFS+优先队列(打印路径) #define N 500005 int c[N]; int dp[N]; //dp[i]保存的是长度为i的最长不降子序列的最小尾元素 int BS(int n,int x) //二分查找下标,当x比全部元素小时下标为1,比全部元素大时下标为n+1. { int low,high,mid; low=1,high=n; while(low<=high) { mid=(low+h