跳到正文

题解

题解:CF2119B Line Segments

wenhaoran11约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年5月19日
篇幅
约 1 分钟
获赞
1
题目
CF2119B

版本

  1. v1当前

题意简介

给出起始点和终点,问能否在操作内从起点到终点。

很简单的一道题,先求出欧几里得距离。

C++
double ans=sqrt((px-qx)*(px-qx)+(py-qy)*(py-qy));

然后直接计算即可。 注意什么要开 double,而其他要开 long long 。

C++
#include<bits/stdc++.h>
using namespace std;
long long T;
double num;
long long n,cnt;
long long px,py,qx,qy;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>T;
	while(T--){
		n,cnt=0;
		num=-1e9;
		cin>>n;
		cin>>px>>py>>qx>>qy;
		double ans=sqrt((px-qx)*(px-qx)+(py-qy)*(py-qy));
		for(long long i=1;i<=n;i++){
			long long x;
			cin>>x;
			cnt+=x;
			num=max(num,(double) x);
		}
		if(num<=cnt-num+ans) cout<<"Yes\n";
		else cout<<"No\n";
	}
	return 0;
}
原文