CF13B Letter A

洛谷传送门

题目描述

Little Petya learns how to write. The teacher gave pupils the task to write the letter AA on the sheet of paper. It is required to check whether Petya really had written the letter AA .

You are given three segments on the plane. They form the letter AA if the following conditions hold:

  • Two segments have common endpoint (lets call these segments first and second), while the third segment connects two points on the different segments.
  • The angle between the first and the second segments is greater than 00 and do not exceed 9090 degrees.
  • The third segment divides each of the first two segments in proportion not less than 1/41/4 (i.e. the ratio of the length of the shortest part to the length of the longest part is not less than 1/41/4 ).

输入格式

The first line contains one integer tt ( 1<=t<=100001<=t<=10000 ) — the number of test cases to solve. Each case consists of three lines. Each of these three lines contains four space-separated integers — coordinates of the endpoints of one of the segments. All coordinates do not exceed 10^{8}108 by absolute value. All segments have positive length.

输出格式

Output one line for each test case. Print «YES» (without quotes), if the segments form the letter AA and «NO» otherwise.

题意翻译

给定三条线段,请你判断这三条线段能否组成字母'A' 判定条件 1.其中的两条线段有共同的端点(我们暂且称它们为第一条,第二条线段),第三条线段的端点分别在这两条不同的线段上。 2.第一条和第二条线段的夹角必须大于0度小于等于90度。 3.第三条线段截得的另外两条线段的较小长度与较大长度的比值必须大于等于1/4。 输入:第一行一个整数t,下面3*t行每三行为一组数据,代表三条线段,每一行代表的是一条线段两个端点的坐标 输出:对于每一组数据,输出"YES"如果能组成'A',否则输出"NO" 感谢 @稀神探女 提供的翻译。

输入输出样例

输入 #1复制

输出 #1复制

题解:

本蒟蒻人生中的第一道黑题

一道复杂的模拟,其中掺杂了许些计算几何的风情。

其实涉及到的计算几何就是一点点的解析几何,判断三点共线,判断夹角小于90°,判断线段差分比例小于\(\frac{1}{4}\)。

求角小于90°的时候运用了叉积,需要平面向量的相关知识,不懂的同学请自行百度。

比较恶心的判断是差分比例小于\(\frac{1}{4}\)。让我来讲一下——

算了不讲了,看代码吧,模拟的思想还是比较简单的,相信大家能看明白。

代码:

#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct node
{
int x,y,j,k;
}a[10];
int t,x,y,m,n,p,q,x1,yy,x2,y2,c1,c2,flag;
int check_oneline(int a,int b,int c,int d,int e,int f)
{
if((ll)(f-b)*(c-a)==(ll)(d-b)*(e-a))
return 1;
return 0;
}
int check_angle(int x,int y,int a,int b,int p,int q)
{
if((ll)(a-x)*(p-x)+(ll)(b-y)*(q-y)<0)
return 0;
return 1;
}
int check_subseg(int x,int y,int m,int n,int a,int b)
{
if(x!=a)
{
if(a>x)
{
if((a-x)*5<(m-x))
return 0;
if((a-x)*5>(m-x)*4)
return 0;
return 1;
}
else
{
if((x-a)*5<(x-m))
return 0;
if((x-a)*5>(x-m)*4)
return 0;
return 1;
}
}
else
{
if(b>y)
{
if((b-y)*5<(n-y))
return 0;
if((b-y)*5>(n-y)*4)
return 0;
return 1;
}
else
{
if((y-b)*5<(y-n))
return 0;
if((y-b)*5>(y-n)*4)
return 0;
return 1;
}
}
}
int main()
{
scanf("%d",&t);
while(t--)
{
for(int i=1;i<=3;i++)
scanf("%d%d%d%d",&a[i].x,&a[i].y,&a[i].j,&a[i].k);
for(int i=1;i<=2;i++)
for(int j=i+1;j<=3;j++)
{
if(a[i].x==a[j].x&&a[i].y==a[j].y)
{
x=a[i].x,y=a[i].y;
m=a[i].j,n=a[i].k;
p=a[j].j,q=a[j].k;
c1=i,c2=j;
}
else if(a[i].x==a[j].j&&a[i].y==a[j].k)
{
x=a[i].x,y=a[i].y;
m=a[i].j,n=a[i].k;
p=a[j].x,q=a[j].y;
c1=i,c2=j;
}
else if(a[i].j==a[j].j&&a[i].k==a[j].k)
{
x=a[i].j,y=a[i].k;
m=a[i].x,n=a[i].y;
p=a[j].x,q=a[j].y;
c1=i,c2=j;
}
else if(a[i].j==a[j].x&&a[i].k==a[j].y)
{
x=a[i].j,y=a[i].k;
m=a[i].x,n=a[i].y;
p=a[j].j,q=a[j].k;
c1=i,c2=j;
}
}
for(int i=1;i<=3;i++)
if(i!=c1&&i!=c2)
{
x1=a[i].x,yy=a[i].y,x2=a[i].j,y2=a[i].k;
break;
}
flag=1;
if(check_angle(x,y,m,n,p,q)==0)
flag=0;
if(flag)
{
if(check_oneline(x,y,m,n,x1,yy)&&check_oneline(x,y,p,q,x2,y2))
{
if(check_subseg(x,y,m,n,x1,yy)==0)
flag=0;
if(check_subseg(x,y,p,q,x2,y2)==0)
flag=0;
}
else if(check_oneline(x,y,p,q,x1,yy)&&check_oneline(x,y,m,n,x2,y2))
{
if(check_subseg(x,y,m,n,x2,y2)==0)
flag=0;
if(check_subseg(x,y,p,q,x1,yy)==0)
flag=0;
}
else
flag=0;
}
printf(flag?"YES\n":"NO\n");
}
return 0;
}

CF13B Letter A的更多相关文章

  1. cf13B Letter A(分类+简单计算几何,,)

    题意: 给三个线段(每个线段的两个端点的坐标),问这三个线段能否组成字母A. 组成字母A的条件: 1.两个线段有公共端点. 2.这两个线段夹角小于等于90度. 3.第三个线段的两个端点分别在这两个线段 ...

  2. [LeetCode] Letter Combinations of a Phone Number 电话号码的字母组合

    Given a digit string, return all possible letter combinations that the number could represent. A map ...

  3. 17. Letter Combinations of a Phone Number

    题目: Given a digit string, return all possible letter combinations that the number could represent. A ...

  4. 什么是Unicode letter

    起因:从一段代码说起 using System; using System.Collections.Generic; using System.Linq; using System.Text; usi ...

  5. LeetCode——Letter Combinations of a Phone Number

    Given a digit string, return all possible letter combinations that the number could represent. A map ...

  6. No.017:Letter Combinations of a Phone Number

    问题: Given a digit string, return all possible letter combinations that the number could represent.A ...

  7. SCI/EI期刊投稿 Reply Letter 常用格式总结

    SCI/EI期刊投稿Reply Letter常用格式总结          整个论文投稿的过程中,会遇到各种问题,需要我们向主编询问或是回复.下面主要总结了responses to the comme ...

  8. 【leetcode】 Letter Combinations of a Phone Number(middle)

    Given a digit string, return all possible letter combinations that the number could represent. A map ...

  9. [LeetCode] Letter Combinations of a Phone Number

    Given a digit string, return all possible letter combinations that the number could represent. A map ...

随机推荐

  1. 编程中的policy

    policy,译为政策,一般是预设的一种限制条件,举个例子   var policyText = { "expiration": "2019-01-01T12:00:00 ...

  2. web app升级—带进度条的App自动更新

    带进度条的App自动更新,效果如下图所示:   技术:vue.vant-ui.5+ 封装独立组件AppProgress.vue: <template> <div> <va ...

  3. nowcoder941B 弹钢琴

    题目链接 思路 首先按照音色排个序,顺便离散化一下音高. 用\(h[i]\)表示第\(i\)个键的音高,用\(w[i]\)表示第\(i\)个键的春希度. 朴素\(dp\) \(f[i][j]\)表示前 ...

  4. sessionStorage 、localStorage 、 cookie 和session之间的区别

    四者的异同 特性 Session   Cookie localStorage sessionStorage 数据的生命期   在一定时间内保存在服务器上.当访问增多,会比较占用你服务器的性能,考虑到减 ...

  5. JavaScript 数据结构与算法之美 - 非线性表中的树、堆是干嘛用的 ?其数据结构是怎样的 ?

    1. 前言 想学好前端,先练好内功,内功不行,就算招式练的再花哨,终究成不了高手. 非线性表(树.堆),可以说是前端程序员的内功,要知其然,知其所以然. 笔者写的 JavaScript 数据结构与算法 ...

  6. HTML连载25-通配符选择器&选择器综合练习

    一.通配符选择器 作用:给当前页面上所有的标签设置属性 (2)格式: *{属性:值:} (3)注意点:由于通配符选择器是给界面上所有的标签设置属性,因此在设置之前会遍历所有的标签,如果当前界面上的标签 ...

  7. Window权限维持(五):屏幕保护程序

    屏幕保护是Windows功能的一部分,使用户可以在一段时间不活动后放置屏幕消息或图形动画.众所周知,Windows的此功能被威胁参与者滥用为持久性方法.这是因为屏幕保护程序是具有.scr文件扩展名的可 ...

  8. Zookeeper的安装与配置、使用

    Dubbo的介绍 如果表现层和服务层是不同的工程,然而表现层又要调用服务层的服务,肯定不能像之前那样,表现层和服务层在一个项目时,只需把服务层的Java类注入到表现层所需要的类中即可,但现在,表现层和 ...

  9. 关于@Autowired后Spring无法注入的问题

    1.对于新手来说,最明显的不过是在applicationContext.xml文件上没有加<context:component-scan base-package="com.xxx&q ...

  10. 在IIS配置时没有启用目录浏览功能 :HTTP 错误 403.14

    在IIS配置时没有启用目录浏览功能,浏览网站时,会出现“HTTP 错误 403.14–Forbidden,Web服务器被配置为不列出此目录内容”的提示,怎么解决这个问题呢? 01 02 03 04 0 ...