zoukankan      html  css  js  c++  java
  • CodeForce Round 578 Div 2 C. Round Corridor

    C. Round Corridor

    Problem

    Amugae is in a very large round corridor. The corridor consists of two areas. The inner area is equally divided by (n) sectors, and the outer area is equally divided by (m) sectors. A wall exists between each pair of sectors of same area (inner or outer), but there is no wall between the inner area and the outer area. A wall always exists at the 12 o'clock position.

    The inner area's sectors are denoted as ((1,1),(1,2),…,(1,n)) in clockwise direction. The outer area's sectors are denoted as ((2,1),(2,2),…,(2,m)) in the same manner. For a clear understanding, see the example image above.

    Amugae wants to know if he can move from one sector to another sector. He has (q) questions.

    For each question, check if he can move between two given sectors.

    Input

    The first line contains three integers $ n , m , q (1 leq n,m leq 10^{18}, 1 leq q leq 10^4) $— the number of sectors in the inner area, the number of sectors in the outer area and the number of questions.

    Each of the next (q) lines contains four integers (s_x, s_y, e_x, e_y (1 leq s_x,e_x leq 2); if$ s_x=1(, then) 1 leq s_y leq n$, otherwise (1 leq s_y leq m); constraints on (e_y) are similar). Amague wants to know if it is possible to move from sector$ (s_x,s_y) (to sector) (e_x,e_y)$.

    Output

    For each question, print "YES" if Amugae can move from ((sx,sy)) to ((ex,ey)), and "NO" otherwise.

    You can print each letter in any case (upper or lower).

    Example

    input

    4 6 3
    1 1 2 3
    2 6 1 2
    2 6 2 4

    output

    YES
    NO
    YES

    Note

    Example is shown on the picture in the statement.

    想法

    看到图就想到内圈每隔(x)个,外圈每隔(y)个,形成一个自闭组,那么这有什么关系吗?

    有,每隔几个每隔几个,就是gcd的意义啊

    那么思路清晰了,计算他们的gcd,就是最大公约数——代表着他们同时分成多少大自闭组,再分别用内外圈总数/自闭组数,就是内外圈每个自闭组包含几个单位范围,再确定询问的位置是否属于同一个自闭组,判断即可

    The Code Of My Program

    /*********************
    *@Author:   ChenShou *
    *@Language: C++11    *
    *********************/
    //#include <bits/stdc++.h> 
    #pragma comment(linker, "/STACK:102400000,102400000")
    #include<functional>
    #include<algorithm>
    #include<iostream>
    #include<cstdlib>
    #include<cstring>
    #include<sstream>
    #include<iomanip>
    #include<numeric>
    #include<cctype>
    #include<cstdio>
    #include<string>
    #include<vector>
    #include<bitset>
    #include<queue>
    #include<deque>
    #include<stack>
    #include<cmath>
    #include<list>
    #include<map>
    #include<set>
     
    //#define DEBUG
    #define RI register int
    #define endl "
    "
     
    using namespace std;
    typedef long long ll;
    //typedef __int128 lll;
    //const int N=100000+10;
    const int M=100000+10;
    const int MOD=1e9+7;
    const double PI = acos(-1.0);
    const double EXP = 1E-9;
    const int INF = 0x3f3f3f3f;
     
    inline ll read(){
        ll x=0,f=1;
        char ch=getchar();
        while(ch<'0'||ch>'9'){
            if(ch=='-')
                f=-1;
            ch=getchar();
        }
        while(ch>='0'&&ch<='9'){
            x=(x<<1)+(x<<3)+(ch^48);
            ch=getchar();
        }
        return x*f; 
    }
     
     
    int main()
    {
    #ifdef DEBUG
        freopen("input.in", "r", stdin);
        //freopen("output.out", "w", stdout);
    #endif
        //cout.tie(0);
        ll n=read(),m=read(),q=read();
        ll ggcd=__gcd(n,m);
        while(q--){
    	ll x_1=read(),y_1=read(),x_2=read(),y_2=read();
    	if(x_1!=x_2){
    		if(x_1==2&&x_2==1)swap(y_1,y_2);
    	    ll num_1=n/ggcd,num_2=m/ggcd;
    	    ll no_1=y_1/num_1,no_2=y_2/num_2;
    	    if(y_1%num_1)no_1++;
    	    if(y_2%num_2)no_2++;
    	    if(no_1==no_2){
    	    	printf("YES
    ");
    	    }
    	    else printf("NO
    ");
    	}
    	else if(x_1==1){
    		ll num_1=n/ggcd,num_2=n/ggcd;
    	    ll no_1=y_1/num_1,no_2=y_2/num_1;
    	    if(y_1%num_1)no_1++;
    	    if(y_2%num_1)no_2++;
    	    if(no_1==no_2){
    	    	printf("YES
    ");
    	    }
    	    else printf("NO
    ");
    	}
    	else {
    		ll num_1=m/ggcd,num_2=m/ggcd;
    	    ll no_1=y_1/num_1,no_2=y_2/num_2;
    	    if(y_1%num_1)no_1++;
    	    if(y_2%num_2)no_2++;
    	    if(no_1==no_2){
    	    	printf("YES
    ");
    	    }
    	    else printf("NO
    ");
    	}
    }
        //continue;
    #ifdef DEBUG
        printf("Time cost : %lf s
    ",(double)clock()/CLOCKS_PER_SEC);
    #endif
        //cout << "Fuck You !" << endl;
        return 0;
    }
    
  • 相关阅读:
    UnityShader
    Unity
    Tools
    linux下解压命令
    进程 同步、互斥
    I/O模型
    jclass jobject
    javah javap
    IDA 结构体
    Windows CSRSS API List (NT/2000/XP/2003/Vista/2008/7/2012/8)
  • 原文地址:https://www.cnblogs.com/--ChenShou--/p/11356054.html
Copyright © 2011-2022 走看看