Niuke IOI Weekly Contest 22-The end of the popular group war (c++)

End of the war

Click me to jump to the original question

"When the flares that successfully captured the main city were fired at the same time as the enemy's bullets, the flares illuminate the people's desire for peace and all their imaginations about a better life in the future, but the bullets shattered her belief in going down and the whole meaning of existence.

"Fireworks are easy to cold, and so is Shao Zuo's life. In the warm light, she illuminates her path where only death can walk, and this gentle light is also rapidly cooling, falling, and extinguishing in the smoke-filled air. Fall back to the cold, hard ground."

——Preface (skip does not affect the answer)

After more than 20 years of war, the continent finally saw the dawn of peace.
Under the leadership of several great powers, including the Kingdom of Angchel and Astraya, all the countries on the continent decided to shake hands and make peace and cultivate through truce.
As a sign of the end of the war, all countries need to sign an armistice agreement.
A complete armistice agreement has been drafted by our automatic memoir doll Violet, and
now all countries need to sign the armistice agreement at the same place at the same time.

Insert picture description here

In order to sign the armistice agreement peacefully, you now need to find a point on this continent to ensure that the distance from that point to all countries is "equal".
PS: The answer coordinates are all integers.
PS: Equal: the absolute value of the difference between the two distances is less than 10^-4

If you cannot find the point on the mainland, please output War is cruel.

Enter description:
Insert picture description here

Output description:

The first line, output the coordinates of the points that meet the conditions, separated by spaces

If there is more than one point that meets the condition, please output the point with the smaller abscissa x first. If the abscissa x is equal, output the point with the smaller ordinate y first.

If the point that meets the conditions does not exist, please output War is cruel.
PS: The answer coordinates are all integers

Problem-solving ideas:

Because it is a 200*200 coordinate system, you can directly traverse each point in the coordinate system.
If you want to determine that the absolute value of the distance between each point in the coordinate system is less than 10^-4,
then the distance between this point and the first country must be also The distance to other points is the same.
So when traversing each point, we only need to define a floating point variable sum1, its value is the distance between the first country and the point.
If sum1 and sum2 ( distance from this point to other countries) If the difference is less than 10^-4, then we can determine that this point is what we are looking for.
At the same time, if the problem requires x to be equal, the output with the smaller y is preferred,
so we use a double for loop

AC code

#include <cstdio>
#include <cmath>
using namespace std;
int a[201],b[201];
int n;
int Nebula(int x,int y) {
    
    
	double sum1=sqrt((x-a[1])*(x-a[1])+(y-b[1])*(y-b[1]));//这个点到第一个国家的距离
	for(int i=1; i<=n; i++) {
    
    
			double sum2=sqrt((x-a[i])*(x-a[i])+(y-b[i])*(y-b[i]));//这个点到其他国家的距离
			if(abs(sum2-sum1)>=0.0001)//10^-4
				return 0;
		}
	return 1;//在坐标系中abs(sum2-sum1)<0.0001 证明该点为我们所求
}
int main() {
    
    
	scanf("%d",&n); //老规矩 输入数据
	for(int i=1; i<=n; i++) {
    
    
		scanf("%d %d",&a[i],&b[i]);  //输入国家坐标
	}
	for(int i=1; i<=200; i++)
		for(int j=1; j<=200; j++) {
    
    
			if(Nebula(i,j)) {
    
    
				printf("%d %d",i,j);
				return 0; //如果找到点直接结束程序
			}
		}
	printf("War is cruel.");
	//return 0;
}

Attachment: If you are a newcomer, if you have any shortcomings, please correct me. If there are errors in the solution or not clearly written, you are welcome to ask questions in the comment area~

Guess you like

Origin blog.csdn.net/qq_34832548/article/details/113100047