三亩地 三亩地SAN MU DI · CODE DIARY
ARTICLE DETAIL

日记详情

真实记录编程学习的某一天,欢迎挑你感兴趣的翻一翻。

题解:洛谷 AT_abc460_b [ABC460B] Two Rings

题解:洛谷 AT_abc460_b [ABC460B] Two Rings

本文分享的必刷题目是从蓝桥云课、洛谷、AcWing等知名刷题平台精心挑选而来,并结合各平台提供的算法标签和难度等级进行了系统分类。题目涵盖了从基础到进阶的多种算法和数据结构,旨在为不同阶段的编程学习者提供一条清晰、平稳的学习提升路径。

欢迎大家订阅我的专栏:算法题解:C++与Python实现!

附上汇总贴:算法竞赛备考冲刺必刷题(C++) | 汇总


【题目来源】

洛谷:AT_abc460_b [ABC460B] Two Rings - 洛谷

【题目描述】

There are two circlesC 1 C_1C1​andC 2 C_2C2​on thex y xyxy-plane. In this problem, a circle refers to the circumference.
CircleC 1 C_1C1​has its center at( X 1 , Y 1 ) (X_1, Y_1)(X1​,Y1​)and radiusR 1 R_1R1​.
CircleC 2 C_2C2​has its center at( X 2 , Y 2 ) (X_2, Y_2)(X2​,Y2​)and radiusR 2 R_2R2​.
Determine whether circlesC 1 C_1C1​andC 2 C_2C2​have a common point. In other words, determine whether there exists at least one point whose distance from( X 1 , Y 1 ) (X_1, Y_1)(X1​,Y1​)isR 1 R_1R1​and whose distance from( X 2 , Y 2 ) (X_2, Y_2)(X2​,Y2​)isR 2 R_2R2​.

You are givenT TTtest cases; solve each one.

在x y xyxy平面上有两个圆C 1 C_1C1​和C 2 C_2C2​。在这个问题中,圆指的是圆周。
圆C 1 C_1C1​的圆心在( X 1 , Y 1 ) (X_1, Y_1)(X1​,Y1​),半径为R 1 R_1R1​。
圆C 2 C_2C2​的圆心在( X 2 , Y 2 ) (X_2, Y_2)(X2​,Y2​),半径为R 2 R_2R2​。
判断圆C 1 C_1C1​和C 2 C_2C2​是否有公共点。换句话说,判断是否存在至少一个点,它到( X 1 , Y 1 ) (X_1, Y_1)(X1​,Y1​)的距离是R 1 R_1R1​,且到( X 2 , Y 2 ) (X_2, Y_2)(X2​,Y2​)的距离是R 2 R_2R2​。

给定T TT个测试用例;解决每个测试用例。

【输入】

The input is given from Standard Input in the following format, wherec a s e i \mathrm{case}_icasei​denotes thei ii-th test case:

T TT
c a s e 1 \mathrm{case}_1case1​
c a s e 2 \mathrm{case}_2case2​
⋮ \vdots⋮
c a s e T \mathrm{case}_TcaseT​

Each test case is given in the following format:

X 1 X_1X1​Y 1 Y_1Y1​R 1 R_1R1​X 2 X_2X2​Y 2 Y_2Y2​R 2 R_2R2​

【输出】

OutputT TTlines. Thei ii-th line should contain the answer for thei ii-th test case.
For each test case, outputYesif circlesC 1 C_1C1​andC 2 C_2C2​have a common point, andNootherwise.

【输入样例】

7 0 0 2 2 3 2 0 0 2 2 3 1 1 2 5 3 2 1 5 4 2 8 8 3 2 1 5 5 1 2 0 0 1 0 0 1 0 0 500000000 1 1000000000 500000000

【输出样例】

Yes No No Yes Yes Yes No

【算法标签】

#入门

【代码详解】

#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongintt;// 测试用例数量signedmain(){cin>>t;// 输入测试用例数量while(t--)// 处理每个测试用例{intx1,y1,r1,x2,y2,r2;// 两个圆的圆心坐标和半径cin>>x1>>y1>>r1>>x2>>y2>>r2;// 输入两个圆的参数intdx=x1-x2;// 圆心横坐标差intdy=y1-y2;// 圆心纵坐标差intd=dx*dx+dy*dy;// 圆心距离的平方intrSum=r1+r2;// 半径和intrSub=r1-r2;// 半径差if(d<=rSum*rSum&&d>=rSub*rSub)// 判断两圆是否相交cout<<"Yes"<<endl;// 相交elsecout<<"No"<<endl;// 不相交}return0;}

【运行结果】

7 0 0 2 2 3 2 Yes 0 0 2 2 3 1 No 1 2 5 3 2 1 No 5 4 2 8 8 3 Yes 2 1 5 5 1 2 Yes 0 0 1 0 0 1 Yes 0 0 500000000 1 1000000000 500000000 No
← 返回列表