A. Two distinct points

Posted studyshare777

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了A. Two distinct points相关的知识,希望对你有一定的参考价值。

  A. Two distinct points

You are given two segments l1;r1 and l2;r2 on the xx-axis. It is guaranteed that l1<r1l1<r1 and l2<r2l2<r2. Segments may intersect, overlap or even coincide with each other.

技术图片The example of two segments on the xx-axis.

Your problem is to find two integers aa and bb such that l1≤a≤r1l1≤a≤r1, l2≤b≤r2l2≤b≤r2 and a≠ba≠b. In other words, you have to choose two distinct integer points in such a way that the first point belongs to the segment l1;r1 and the second one belongs to the segment l2;r2.

It is guaranteed that the answer exists. If there are multiple answers, you can print any of them.

You have to answer qq independent queries.

Input

The first line of the input contains one integer qq (1≤q≤5001≤q≤500) — the number of queries.

Each of the next qq lines contains four integers l1i,r1i,l2il1i,r1i,l2i and r2ir2i (1≤l1i,r1i,l2i,r2i≤109,l1i<r1i,l2i<r2i1≤l1i,r1i,l2i,r2i≤109,l1i<r1i,l2i<r2i) — the ends of the segments in the ii-th query.

Output

Print 2q2q integers. For the ii-th query print two integers aiai and bibi — such numbers that l1i≤ai≤r1il1i≤ai≤r1i, l2i≤bi≤r2il2i≤bi≤r2i and ai≠biai≠bi. Queries are numbered in order of the input.

It is guaranteed that the answer exists. If there are multiple answers, you can print any.

Example

input

5
1 2 1 2
2 6 3 4
2 4 1 3
1 2 1 3
1 4 5 8

output

2 1
3 4
3 2
1 2
3 7

题目描述:

在2个区间内,分别输出1个在区间里的数,2个数要不同。

分析:

从最边往里选,依次判断是否相同即可。(水题,我还打了这么多)

代码:

#include <iostream>
#include <cstdio>
using namespace std;
 
int main()
{
    int n;
    cin>>n;
    while(n--)
    {
        int l,r,L,R;
        scanf("%d%d%d%d",&l,&r,&L,&R);
        if(l==r)
        {
            printf("%d ",l);
            if(R!=r)
            printf("%d
",R);
            else
            {
                printf("%d
",R-1);
            }
        }
        else if(L==R)
        {
            if(l!=L)
            printf("%d ",l);
            else
            {
                printf("%d ",l+1);
            }
            printf("%d
",R);
        }
        else 
        {
            printf("%d ",l);
            if(l!=R)
            {
                printf("%d
",R);
            }
            else
            {
                printf("%d
",R-1);
            }
        }
    }
    return 0;
} 

 

 

以上是关于A. Two distinct points的主要内容,如果未能解决你的问题,请参考以下文章

2021-09-03:直线上最多的点数。给你一个数组 points ,其中 points[i] = [xi, yi] 表示 X-Y 平面上的一个点。求最多有多少个点在同一条直线上。力扣149。(代码片

LeetCode Longest Substring with At Most Two Distinct Characters

Microsoft - Union Two Sorted List with Distinct Value

Codeforces Round #589 (Div. 2) A. Distinct Digits

Leetcode 159: Longest Substring with At Most Two Distinct Characters

159 Longest Substring with At Most Two Distinct Characters