Two distinct points CodeForces - 1108A (签到)

Posted qieqiemin

tags:

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

You are given two segments [l1;r1][l1;r1] and [l2;r2][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 l1ar1l1≤a≤r1, l2br2l2≤b≤r2 and aba≠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][l1;r1] and the second one belongs to the segment [l2;r2][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 (1q5001≤q≤500) — the number of queries.

Each of the next qq lines contains four integers l1i,r1i,l2il1i,r1i,l2i and r2ir2i (1l1i,r1i,l2i,r2i109,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 l1iair1il1i≤ai≤r1i, l2ibir2il2i≤bi≤r2i and aibiai≠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

思路:给你两个区间,分别表示为[l1,r1] , [l2,r2]
让你输出两个不同的整数a和b,使之a属于第一个区间,b属于第二个区间。保证答案存在,注意a!=b
很签到的一题,注意下细节就好了。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), ‘‘, sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int n;

int main()
{
    int l1,l2,r1,r2;
    gg(n);
    while(n--)
    {
        scanf("%d %d %d %d",&l1,&r1,&l2,&r2);
        if(l1!=r2)
            printf("%d %d
",l1,r2 );
        else
            printf("%d %d
",r1,l2 );
    }    
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch ==   || ch == 
);
    if (ch == -) {
        *p = -(getchar() - 0);
        while ((ch = getchar()) >= 0 && ch <= 9) {
            *p = *p * 10 - ch + 0;
        }
    }
    else {
        *p = ch - 0;
        while ((ch = getchar()) >= 0 && ch <= 9) {
            *p = *p * 10 + ch - 0;
        }
    }
}

 


以上是关于Two distinct points CodeForces - 1108A (签到)的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode Longest Substring with At Most Two Distinct Characters

Microsoft - Union Two Sorted List with Distinct Value

Leetcode 159: Longest Substring with At Most Two Distinct Characters

159 Longest Substring with At Most Two Distinct Characters

[LC] 159. Longest Substring with At Most Two Distinct Characters

Two Points问题--之LeetCode 11题