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的这 ...
随机推荐
- 《前端运维》一、Linux基础--06Shell流程控制
这章我们来学习下流程控制,简单来说就是逻辑判断和循环的写法.并不复杂,我们来简单地看下. 1.if语句 shell的if语句有两种写法,一种是shell脚本式的,一种是命令式的. if conditi ...
- 在/etc/docker/下 创建daemon.json重新加载后docker无法启动问题 /etc/docker/daemon.json编辑不了 找不到
可能产生这个问题的原因至少有以下几个: 编辑daemon.json步骤不对:想要创建并编辑daemon.json,应该是先启动docker服务,此时系统自动产生/etc/docker目录,此时cat生 ...
- Linux中ftp服务器的安装与部署
一.ftp简介FTP(File Transfer Protocol,文件传输协议) 是 TCP/IP 协议组中的协议之一.FTP协议包括两个组成部分,其一为FTP服务器,其二为FTP客户端.其中FTP ...
- phpstudy、Apache安装DVWA教程
1.下载DVWA(http://www.dvwa.co.uk/) 2.解压缩DVWA安装包到服务器的目录下 Apache: \Apache24\htdocs phpStudy: \PHPTutoria ...
- J20航模遥控器开源项目系列教程(七)PPM输出 | 关于按键版本和旋转编码器版本的兼容说明、布局建议 | 关于MINI版PCB的兼容说明
我们的开源宗旨:自由 协调 开放 合作 共享 拥抱开源,丰富国内开源生态,开展多人运动,欢迎加入我们哈~ 和一群志同道合的人,做自己所热爱的事! 项目开源地址:https://github.com/J ...
- 手把手带你使用EFR32 -- 土壤湿度传感器变身第二形态,以 ZigBee 形态出击
前言 后悔,总之就是非常后悔,我当时到底是为啥才会猪油蒙心,选择了 EFR32 来学习 ZigBee 使用啊? EFR32 这玩意看性能确实不错,但是资料太少了,EmberZnet SDK 也是用得一 ...
- Rust极简教程
目录 简介 特性 特征 用途 安装 核心组件 常用命令 基础语法 数据类型 标量类型 复合类型 示例 条件语句 循环 输出&输入 输出 输出花括号 输出非基础类型 输入 所有权 切片 结构体 ...
- Java有没有goto?
goto是Java中的保留字,暂时还不是Java的关键字.
- NO Oracle database,JUST USE Oracle client。远程导入导出dmp
序言: 你会发现,exp.exe 和imp.exe均存在于Oracle数据库的安装bin目录下.而很多情况下,我们不想安装庞大的Oracle数据库,但想使用imp和exp等工具命令,在我们本地机对Or ...
- JWT jti和kid属性的说明
jti chaim=== JWT ID " jti"(JWT ID)声明为JWT提供了唯一的标识符. 标识符值的分配方式必须确保将相同值偶然分配给不同数据对象的可能性可以忽略不计: ...