zoukankan      html  css  js  c++  java
  • Two distinct points CodeForces

    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';
            }
        }
    }
    
    
    本博客为本人原创,如需转载,请必须声明博客的源地址。 本人博客地址为:www.cnblogs.com/qieqiemin/ 希望所写的文章对您有帮助。
  • 相关阅读:
    批量SSH操作工具---OmniTTY安装
    CentOS6.6修改主机名和网络信息
    浪潮服务器通过ipmitool获取mac地址
    linux批量执行工具omnitty使用方法
    操作系统下查看HBA卡信息wwn的方法
    Linux下multipath多路径配置
    IPMITOOL 配置BMC用户设置
    第五讲 对于耦合的认识 target/action设计模式 delegate设计模式 手势识别器
    UI第四讲.事件处理(按钮点击切换视图,触摸事件)
    UI第三讲.自定义视图 视图控制器 检测屏幕旋转
  • 原文地址:https://www.cnblogs.com/qieqiemin/p/10313727.html
Copyright © 2011-2022 走看看