HDU 1221 Rectangle and Circle(判断圆和矩形是不是相交)
传送门:
http://acm.hdu.edu.cn/showproblem.php?pid=1221
Rectangle and Circle
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3434 Accepted Submission(s): 904
Note: we call them intersect even if they are just tangent. The circle is located by its centre and radius, and the rectangle is located by one of its diagonal.

1 1 1 1 2 4 3
1 1 1 1 3 4 4.5
NO
#include<bits/stdc++.h>
using namespace std;
double dis(double x1,double y1,double x2,double y2)
{
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
double f(double x,double y,double x1,double y1,double x2,double y2)//圆心到矩形边的距离最小值
{
if(x1==x2)
{
if(y<=max(y1,y2)&&y>=min(y1,y2))
{
return fabs(x-x1);
}else
{
double b=dis(x,y,x1,y1);
double c=dis(x,y,x2,y2);
double result=min(b,c);
return result;
}
}else if(y1==y2)
{
if(x<=max(x1,x2)&&x>=min(x1,x2))
{
return fabs(y-y1);
}else
{
double b=dis(x,y,x1,y1);
double c=dis(x,y,x2,y2);
double result=min(b,c);
return result;
}
}
}
int main()
{
double x,y,r,x1,y1,x2,y2;
int t;
scanf("%d",&t);
while(t--)
{
scanf("%lf %lf %lf %lf %lf %lf %lf",&x,&y,&r,&x1,&y1,&x2,&y2);
double x3=x1,y3=y2;
double x4=x2,y4=y1;
double l1=f(x,y,x1,y1,x3,y3);
double l2=f(x,y,x1,y1,x4,y4);
double l3=f(x,y,x2,y2,x3,y3);
double l4=f(x,y,x2,y2,x4,y4); double L=min(l1,min(l2,min(l3,l4))); double r1=dis(x,y,x1,y1);
double r2=dis(x,y,x2,y2);
double r3=dis(x,y,x3,y3);
double r4=dis(x,y,x4,y4); double R=max(r1,max(r2,max(r3,r4))); if(L>r)
printf("NO\n");
else if(R<r)
printf("NO\n");
else if(L<=r&&R>=r)
printf("YES\n");
}
return ;
}
HDU 1221 Rectangle and Circle(判断圆和矩形是不是相交)的更多相关文章
- 判断圆和矩形是否相交C - Rectangle and Circle
Description Given a rectangle and a circle in the coordinate system(two edges of the rectangle are p ...
- HDU 1221 Rectangle and Circle 考虑很多情况,good题
http://acm.hdu.edu.cn/showproblem.php?pid=1221 114 92 31 95 13 96 3 这题只需要判断圆和矩形是否相交,然后在里面是不算相交的. 那么就 ...
- poj1410(判断线段和矩形是否相交)
题目链接:https://vjudge.net/problem/POJ-1410 题意:判断线段和矩形是否相交. 思路:注意这里的相交包括线段在矩形内,因此先判断线段与矩形的边是否相交,再判断线段的两 ...
- Judge Route Circle --判断圆路线
Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot m ...
- HDU 1110 Equipment Box (判断一个大矩形里面能不能放小矩形)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1110 Equipment Box Time Limit: 2000/1000 MS (Java/Oth ...
- PHP判断两个矩形是否相交
<?php $s = is_rect_intersect(1,2,1,2,4,5,0,3); var_dump($s); /* 如果两个矩形相交,那么矩形A B的中心点和矩形的边长是有一定关系的 ...
- C# 判断两个矩形是否相交
源代码 public bool JudgeRectangleIntersect(double RecAleftX, double RecAleftY, double RecArightX, doubl ...
- 【LeetCode】1401. 圆和矩形是否有重叠 Circle and Rectangle Overlapping
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 利用公式 日期 题目地址:https://leetco ...
- A Round Peg in a Ground Hole - POJ 1584 (判断凸多边形&判断点在多边形内&判断圆在多边形内)
题目大意:首先给一个圆的半径和圆心,然后给一个多边形的所有点(多边形按照顺时针或者逆时针给的),求,这个多边形是否是凸多边形,如果是凸多边形在判断这个圆是否在这个凸多边形内. 分析:判断凸多边形可 ...
随机推荐
- SpringBoot | 第三十三章:Spring web Servcies集成和使用
前言 最近有个单位内网系统需要对接统一门户,进行单点登录和待办事项对接功能.一般上政府系统都会要求做统一登录功能,这个没啥问题,反正业务系统都是做单点登录的,改下shiro相关类就好了.看了接入方案, ...
- 51nod 1245 Binomial Coefficients Revenge
Description C(M,N) = M! / N! / (M - N)! (组合数).给出M和质数p,求C(M,0), C(M,1)......C(M,M)这M + 1个数中,有多少数不是p的倍 ...
- jsp的动作标签
常用的标签: 1. forward 请求转发 [基本不使用] <==> request.getRequestDispatcher(url).forward(request,respon ...
- 三种ajax解析模式!
一.Ajax中的JSON格式 html代码: <html> <body> <input type="button" value="Ajax& ...
- 【学习笔记】Java中生成对象的5中方法
概述:本文介绍以下java五种创建对象的方式: 1.用new语句创建对象,这是最常用的创建对象的方式. 2.使用Class类的newInstance方法 3.运用反射手段,调用java.lang.re ...
- Java集合篇二:LinkList
package com.test.collection; /** * 自定义实现LinkList * * 1.双向链表 * 实现原理:底层封装Node节点对象(每个节点存放有3部分内容:1.上个节点的 ...
- setTimeout的实现原理以及setTimeout(0)的使用场景
先看一段代码: var start = new Date(); setTimeout(function(){ var end = new Date(); console.log("Tim ...
- H5前端的行业知识
今天咱们不说代码!咱们说点行内的只是吧!! 一.前端基本技能: 会点设计,不要求精湛,处理图片,设计个小广告是要的: 精通HTML+CSS,并能快速处理各浏览器兼容问题: 熟练掌握Javascript ...
- matlab绘图(详细)(全面)
Matlab绘图 强大的绘图功能是Matlab的特点之一,Matlab提供了一系列的绘图函数,用户不需要过多的考虑绘图的细节,只需要给出一些基本参数就能得到所需图形,这类函数称为高层绘图函数.此外,M ...
- 【NLP_Stanford课堂】词形规范化
一.为什么要规范化 在做信息检索的时候,一般都是精确匹配,如果不做规范化,难以做查询,比如用U.S.A去检索文本,结果文本里实际上存的是USA,那么实际上应该能查到的结果查不到了. 所以需要对所有内容 ...