Clock and Strings

Clock and Strings

题面翻译

输入 t ( 1 ≤ t ≤ 5940 ) t(1\le t\le 5940) t(1t5940) 行,每行 4 4 4 个整数 a , b , c , d ( 1 ≤ a , b , c , d ≤ 12 ) a,b,c,d(1\le a,b,c,d\le 12) a,b,c,d(1a,b,c,d12),表示钟面上 a , b a, b a,b c , d c, d c,d 两条线段的四个端点所对应的刻度,问这两条线段会不会在钟面上相交。如果会,则输出 YES,不会则输出 NO

题目描述

There is a clock labeled with the numbers $ 1 $ through $ 12 $ in clockwise order, as shown below.

In this example, $ (a,b,c,d)=(2,9,10,6) $ , and the strings intersect.

Alice and Bob have four distinct integers $ a $ , $ b $ , $ c $ , $ d $ not more than $ 12 $ . Alice ties a red string connecting $ a $ and $ b $ , and Bob ties a blue string connecting $ c $ and $ d $ . Do the strings intersect? (The strings are straight line segments.)

输入格式

The first line contains a single integer $ t $ ( $ 1 \leq t \leq 5940 $ ) — the number of test cases.

The only line of each test case contains four distinct integers $ a $ , $ b $ , $ c $ , $ d $ ( $ 1 \leq a, b, c, d \leq 12 $ ).

输出格式

For each test case, output “YES” (without quotes) if the strings intersect, and “NO” (without quotes) otherwise.

You can output “YES” and “NO” in any case (for example, strings “yEs”, “yes”, and “Yes” will be recognized as a positive response).

样例 #1

样例输入 #1

15
2 9 10 6
3 8 9 1
1 2 3 4
5 3 4 12
1 8 2 10
3 12 11 8
9 10 12 1
12 1 10 2
3 12 6 9
1 9 8 4
6 7 9 12
7 12 9 6
10 12 11 1
3 9 6 12
1 4 3 5

样例输出 #1

YES
NO
NO
YES
YES
NO
NO
NO
NO
NO
NO
YES
YES
YES
YES

提示

The first test case is pictured in the statement.

In the second test case, the strings do not intersect, as shown below.


今天刷到了一道感觉很有意思的题目。
题意:在一个圆里面,给出四个点a,b,c,d。ab练成一条线段,bc连成一条线段。判断是否相交

刚开始我还傻傻的想判断他们是否包含,例如判断c或者d是否≥a并且≤b这样的方法来写。(⊙o⊙)。结果发现根本不是这样写的。后来我想了想,发现了一个很简单的东西,就是,如果二者相交,在线段a,b的一端是不是就只有一个交点。例如下图
在这里插入图片描述
在2 9的一端,有且仅有一个交点的话才能叫做相交。
附上我的丑陋代码

#include <bits/stdc++.h>
#define int long long 
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define fi first
#define se second
#define PII pair<int,int>
using namespace std;
const int N = 1e5+5;
//int a[N],b[N];
void solve ()
{
	int n;cin>>n;
	for (int i=1;i<=n;i++)
	{
		int a,b,c,d;map<int,int>mp;int ans=0;
		cin>>a>>b>>c>>d;mp[c]=1,mp[d]=1;
		int q=min(a,b);
		int w=max(a,b);
		if (c==a||c==b||d==a||d==b) cout<<"YES"<<'\n';//如果四者但凡有一个相同就肯定相交
		else
		{
			for (int j=q;j<=w;j++)
			{
				if (mp[j]==1) ans++;
			}
			if (ans==1) cout<<"YES"<<'\n';//ans记录交点个数,后续判断有且只有一个交点的时候输出YES,否则输出NO
			else cout<<"NO"<<'\n';
		}
	}
}

signed main ()
{
	IOS;
	int T =1;
//	cin>>T;
	while(T--) solve ();
	return 0;
}
  • 19
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值