Codeforeces 13B
Codeforeces 13B-Letter A
二维基础
题目链接:https://codeforces.com/problemset/problem/13/B
题意:给定三条线段,判断三条线段是否是“A”形的。“A”形的定义如下:
- 线段A和线段B有一个公共点。
- 线段C的两个端点分别位于线段A和线段B上。
- 线段A和线段B所形成的夹角在\((0^\circ,90^\circ]\)。
- 线段C分线段A为\(x_1\)和\(x_2\)两部分且较短线段与较长线段的比值大于等于\(1/4\),线段B亦是。
思路:这是一道十分基础的练习题。只需要读取输入后按照条件一项一项判断即可。对于每一个条件,我们可以这样判断:
- 在给定的6个端点中有且仅有2个点的坐标一致。
- 设线段A的两个端点为\(a_1和a_2\)且线段C的端点\(c_1\)在线段A上,则有\(\vec {c_1a_1} \times \vec{c_1a_2} = 0\) 并且 \(\vec {c_1a_1} \cdot \vec{c_1a_2} < 0\),线段B同理。
- 设线段A和线段B的公共点为\(x_1\),各自另外一点分别为\(a_1,b_1\),则有\(\vec {x_1a_1} \cdot \vec{x_1b_1} \geq 0\) 并且 \(\vec {x_1a_1} \times \vec{x_1b_1} \neq 0\)。
- 设线段A的两个端点为\(a_1和a_2\)且线段C的端点\(c_1\)在线段A上, 则有\(16*min(\vert \vec {c_1a_1}\vert^2,\vert \vec {c_1a_2}\vert^2) \geq max(\vert \vec {c_1a_1}\vert^2,\vert \vec {c_1a_2}\vert^2)\),线段B同理。
*此处使用线段长度的平方判断,避免开根号带来的精度误差。
代码如下:
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ywh666 std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define all(a) a.begin(),a.end()
typedef long long ll ;
using _T = long long;//long long
const _T eps = 0;// 0
template<typename T> struct point
{
T x,y;
void read(){cin >> x >> y;}
bool operator<(const point &a) const
{if (abs(x-a.x)<=eps) return y<a.y-eps; return x<a.x-eps;}
bool operator>(const point &a) const
{return !(*this<a || *this==a);}
bool operator==(const point &a) const
{return (abs(x-a.x)<=eps && abs(y-a.y)<=eps);}
bool operator!=(const point &a) const
{return (abs(x-a.x)>eps || abs(y-a.y)>eps);}
point operator+(const point &a) const {return {x+a.x,y+a.y};}
point operator-(const point &a) const {return {x-a.x,y-a.y};}
point operator-() const {return {-x,-y};}
point operator*(const T k) const {return {k*x,k*y};}
point operator/(const T k) const {return {x/k,y/k};}
T operator*(const point &a) const {return x*a.x+y*a.y;}
T operator^(const point &a) const {return x*a.y-y*a.x;}
T dis2(const point &a) const {return (a-(*this)).len2();}
T len2() const {return (*this)*(*this);}
};
using Point = point<_T>;
map<Point, int> mp;
bool check(Point bo, Point end1, Point end2, Point a1, Point a2){
if(((end1 - bo) ^ (end2 - bo)) == 0) return 0 ;
if(((end1 - bo) * (end2 - bo)) < 0) return 0 ;
if(((end1 - a1) ^ (bo - a1)) == 0 &&((end1 - a1) * (bo - a1) < 0)
&& ((end2 - a2) ^ (bo - a2)) == 0 &&((end2 - a2) * (bo - a2) < 0)){
if(16 * min(bo.dis2(a1), a1.dis2(end1)) >= max(bo.dis2(a1), a1.dis2(end1)) &&
16 * min(bo.dis2(a2), a2.dis2(end2)) >= max(bo.dis2(a2), a2.dis2(end2))){
return 1 ;
}else{
return 0 ;
}
}else if(((end1 - a2) ^ (bo - a2)) == 0 &&((end1 - a2) * (bo - a2) < 0)
&& ((end2 - a1) ^ (bo - a1)) == 0 &&((end2 - a1) * (bo - a1) < 0)){
if(16 * min(bo.dis2(a2), a2.dis2(end1)) >= max(bo.dis2(a2), a2.dis2(end1)) &&
16 * min(bo.dis2(a1), a1.dis2(end2)) >= max(bo.dis2(a1), a1.dis2(end2))){
return 1 ;
}else{
return 0 ;
}
}else{
return 0 ;
}
}
void solve(){
Point a[6];
mp.clear();
for(int i = 0 ; i < 6 ; i ++) {
a[i].read();
mp[a[i]] ++;
}
bool f = 0 ;
Point both;
for(auto i : mp){
if(i.second == 2 && !f){
both = i.first;
f = 1;
}else if(i.second != 1){
cout << "NO" << endl;
return ;
}
}
if(!f){
cout << "NO" << endl;
return ;
}
mp.clear();
Point cnt[4];
int nn = 0 ;
for(int i = 0 ; i < 6 ; i ++){
if(a[i] == both){
cnt[nn ++] = a[(((i & 1) == 1) ? (i - 1) : (i + 1))];
mp[cnt[nn - 1]] ++;
}
}
for(int i = 0 ; i < 6 ; i ++){
if(!mp.count(a[i]) && a[i] != both) cnt[nn ++] = a[i];
}
bool ff = check(both, cnt[0], cnt[1], cnt[2], cnt[3]);
if(ff){
cout << "YES" << endl;
}else{
cout << "NO" << endl;
}
return ;
}
int main(){
ywh666;
int t ;
cin >> t;
while(t --){
solve();
}
return 0 ;
}
Codeforeces 13B的更多相关文章
- codeforeces近日题目小结
题目源自codeforeces的三场contest contest/1043+1055+1076 目前都是solved 6/7,都差了最后一题 简单题: contest/1043/E: 先不考虑m个限 ...
- Codeforeces 617E XOR and Favorite Number(莫队+小技巧)
E. XOR and Favorite Number time limit per test 4 seconds memory limit per test 256 megabytes input s ...
- Codeforeces 707B Bakery(BFS)
B. Bakery time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...
- 牛客练习赛13B 幸运数字2
题目链接:https://ac.nowcoder.com/acm/contest/70/B 题目大意: 略 分析: 先DFS求出所有幸运数,然后暴力即可 代码如下: #pragma GCC optim ...
- CodeForeces 25E (kmp)
E. Test time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputst ...
- CodeForeces 665C Simple Strings
C. Simple Strings time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- codeforeces:Mister B and Astronomers分析和实现
题目很长,稍微翻译一下: 外星球每隔T秒中只有一秒可以被观测到,其它T-1秒无法被观测.n个天文学家(分别编号为1,...,n)轮流观测天空1秒,且第i+1个科学家在第i个天文学家后ai+1秒后才执行 ...
- Codeforeces 954C Matrix Walk
题目大意 考虑一个 $x\times y$ 的矩阵 $A_{x\times y}$ ,$A_{i,j} = (i-1)x+y$ . 从矩阵中的某个位置出发,每次可向上下左右移动一步,每到一个位置,记录 ...
- CodeForeces 842d Vitya and Strange Lesson ——(带lazy标记的01字典树)
给一个序列,每次操作对这个序列中的所有数异或一个x,问每次操作完以后整个序列的mex值. 做法是去重后构建01字典树,异或x就是对root加一个x的lazy标志,每次pushDown时如果lazy的这 ...
随机推荐
- Net中委托之一
1.委托的用法 委托是一种特殊的类型 a. 委托可以类外定义,也可以在类里面定义 b. 委托的操作步骤 1.委托的声明 2.委托的实例化 3.委托的调用 2.委托实例 amespace MyDeleg ...
- IEAD关于git配置以及拉代码和提交代码
1.提前安装git客户端,注册码云帐号 注册地址:https://gitee.com/signup 2.新建仓库 3.修改仓库信息 4.从IDEA拉git项目,下面两个地方都可以配置 首次创建需要输入 ...
- 面试突击32:为什么创建线程池一定要用ThreadPoolExecutor?
在 Java 语言中,并发编程都是依靠线程池完成的,而线程池的创建方式又有很多,但从大的分类来说,线程池的创建总共分为两大类:手动方式使用 ThreadPoolExecutor 创建线程池和使用 Ex ...
- GitLab 常用命令
1. 进入本地仓库访问位置之后执行命令 1) 远程仓库相关命令检出仓库:$ git clone git://github.com/jquery/jquery.git查看远程仓库:$ git remot ...
- 分布式 PostgreSQL 集群(Citus),分布式表中的分布列选择最佳实践
确定应用程序类型 在 Citus 集群上运行高效查询要求数据在机器之间正确分布.这因应用程序类型及其查询模式而异. 大致上有两种应用程序在 Citus 上运行良好.数据建模的第一步是确定哪些应用程序类 ...
- spring boot使用注解进行模糊查询
spring boot中mybatis使用注解进行模糊查询@Select("select * from dept where dname like CONCAT('%',#{dname},' ...
- 张高兴的 Entity Framework Core 即学即用:(一)创建第一个 EF Core 应用
写在前面 Entity Framework Core (EF Core) 是 .NET 平台流行的对象关系映射(ORM)框架.虽然 .NET 平台中 ORM 框架有很多,比如 Dapper.NHibe ...
- 程序流程控制2 for循环
for循环是python中的一个通用的序列迭代器,可以遍历序列对象中的所有对象. 1.for循环基本格式 for循环基本格式如下. for var in object: 循环体语句块 else: 语句 ...
- 常见的反爬措施:UA反爬和Cookie反爬
摘要:为了屏蔽这些垃圾流量,或者为了降低自己服务器压力,避免被爬虫程序影响到正常人类的使用,开发者会研究各种各样的手段,去反爬虫. 本文分享自华为云社区<Python爬虫反爬,你应该从这篇博客开 ...
- 数据库篇:mysql日志类型之 redo、undo、binlog
前言 可以说mysql的多数特性都是围绕日志文件实现,而其中最重要的有以下三种 redo 日志 undo 日志 binlog 日志 关注公众号,一起交流:微信搜一搜: 潜行前行 1 redo日志 in ...