CodeForces - 1200C——小模擬

【題目描述】

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 qquestions.For each question, check if he can move between two given sectors.

Input

The first line contains three integers n, m and q (1≤n,m≤1018, 1≤q≤104) — 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 qlines contains four integers sx, sy, ex, ey (1≤sx,ex≤2; if sx=1, then 1≤sy≤n, otherwise 1≤sy≤m; constraints on ey are similar). Amague wants to know if it is possible to move from sector (sx,sy) to sector (ex,ey)

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

【題目分析】
很簡單的一道題,就是分類討論,不過1A還是很爽
【AC代碼】

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<climits>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;typedef long long ll;
const int INF=0x3f3f3f3f;
const int MAXN=1e4+5;
ll n,m,x,y;
int T;ll gcd(ll a,ll b)
{return a%b==0?b:gcd(b,a%b);
}int main()
{ll tmp;ll s1,s2,e1,e2,is,ie,l,r;bool flag;scanf("%lld%lld%d",&n,&m,&T);while(T--){flag=false;scanf("%lld%lld%lld%lld",&s1,&s2,&e1,&e2);tmp=gcd(n,m);x=n/tmp; y=m/tmp;if(s1==e1){if(s1==1){is=(s2%x==0)?(s2/x-1):s2/x;ie=(e2%x==0)?(e2/x-1):e2/x;if(is==ie){flag=true;}}else if(s1==2){is=(s2%y==0)?(s2/y-1):s2/y;ie=(e2%y==0)?(e2/y-1):e2/y;if(is==ie){flag=true;}}}else{if(s1==2){s1=1; e1=2; swap(s2,e2);}if(s2%x==0){r=s2/x*y;l=r-y;}else{l=s2/x*y;r=l+y;}if(e2>l && e2<=r){flag=true;}}if(flag) printf("YES\n");else printf("NO\n");}return 0;
}

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/384050.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/384050.shtml
英文地址,請注明出處:http://en.pswp.cn/news/384050.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

1 單例模式

達內 閔大神 //餓漢單例模式 #include <iostream> using namespace std;class Singleton { public:static Singleton& getInstance(){return s_instance;} private:Singleton(){}Singleton(const Singleton& that){}static Singleton s_instance;//靜態成員變量 …

共享棧

1.定義 所謂共享棧就是利用一個數組實現兩個棧. 先來看一下共享棧的數據結構 typedef struct SharedStack {int top1;int top2;SeqStackType* data; }SharedStack; 2. 初始化 void SharedStackInit(SharedStack* stack) {if(stack NULL){return;//非法輸入}stack -> top…

BZOJ1018 | SHOI2008-堵塞的交通traffic——線段樹維護區間連通性+細節

【題目描述】 BZOJ1018 | SHOI2008-堵塞的交通traffic 有一天&#xff0c;由于某種穿越現象作用&#xff0c;你來到了傳說中的小人國。小人國的布局非常奇特&#xff0c;整個國家的交通系統可 以被看成是一個2行C列的矩形網格&#xff0c;網格上的每個點代表一個城市&#xff0…

C++ 函數隱藏

C該函數隱藏 只有基類成員函數的定義已聲明virtualkeyword&#xff0c;當在派生類中的時間&#xff0c;以支付功能實現&#xff0c;virtualkeyword可以從時間被添加以增加。它不影響多狀態。 easy混淆視聽&#xff0c;掩蓋&#xff1a; &#xff0c;規則例如以下&#xff1a; …

迷宮求解(遞歸)

首先來看一下迷宮簡易圖 ???????????????????????????? ????我們用 0 來表示該位置是墻, 用 1 來表示該位置是路. 所以, 我們在處理迷宮問題的時候可以將其看成一個二維數組即可, 而對應的每一條路我們可以用坐標的形式將其表示, 所以還需要…

CodeForces - 786C——二分+模擬?

【題目描述】 Rick and Morty want to find MR. PBH and they cant do it alone. So they need of Mr. Meeseeks. They Have generated n Mr. Meeseeks, standing in a line numbered from 1 to n. Each of them has his own color. i-th Mr. Meeseeks color is ai.Rick and M…

迷宮求解(非遞歸)

上篇文章寫出了利用函數形成棧楨的特性完成迷宮求解問題, 本篇文章我們自己手動維護一個棧, 其進行出棧, 入棧, 取棧頂元素, 來完成迷宮求解尋路的過程 ????思路和以前一樣, 首先, 我們先定義一個棧, 對其初始化, 同時, 定義一個迷宮地圖, 對該地圖進行初始化, 先判斷當前…

數據結構練習——雙向鏈表

http://www.cnblogs.com/-Lei/archive/2012/04/10/2440399.html 復習一下數據結構。。。。說不準下個星期就用上了 只不過寫的很簡單&#xff0c;沒有封裝 DoubleLinkList.h #ifndef GUARD_DoubleLinkList_h #define GUARD_DoubleLinkList_h#include <stdio.h>struct Li…

CodeChef - DGCD——樹鏈剖分+差分

【題目描述】 Youre given a tree on N vertices. Each vertex has a positive integer written on it, number on the ith vertex being vi. Your program must process two types of queries :1. Find query represented by F u v : Find out gcd of all numbers on the uniq…

UVa272-TeX中的引號

【題目描述】 傳送門 【題目分析】 今天開始刷紫書的題目啦 這道題很簡單&#xff0c;需要注意的是cgetchar()需要加上括號&#xff0c;因為賦值語句的優先級比判等低 而且書中說好像最好用整型變量&#xff0c;因為EOF的值為-1&#xff0c;在字符變量中沒有這個值。&#xf…

C++中友元(友元函數和友元類)的用法和功能

http://blog.csdn.net/adriano119/article/details/5914443/ 采用類的機制后實現了數據的隱藏與封裝&#xff0c;類的數據成員一般定義為私有成員&#xff0c;成員函數一般定義為公有的&#xff0c;依此提供類與外界間的通信接口。但是&#xff0c;有時需要定義一些函數&#x…

線程的終止分離

1.線程的終止 注意該函數是針對用戶級別的, 其中 retal 必須指向一個全局變量, 或者是一個 malloc 分配的, 因為如果是線程的局部變量, 當該線程退出時, 其他線程不能得到這個變量, 因為線程的局部變量各自私有 2. 現成的取消 其中thread是線程的 tid 3.線程的等待與分離 (1)…

UVa10082

【題目描述】 傳送門 【題目分析】 同樣是一道模擬&#xff0c;但是如何巧妙快速的解決仍然不簡單。通過這道題告訴我們對于復雜確定的對應關系我們要靈活運用常量數組。 同時還需要注意的一個小問題就是字符串數組中的"//"指的是轉義后的單斜杠&#xff0c;如果只…

C語言中的深拷貝和淺拷貝

http://www.cnblogs.com/zhanggaofeng/p/5421804.html C語言中的深拷貝和淺拷貝 //C語言中的深拷貝和淺拷貝 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> #include<string.h>typedef struct _student{char name[30];char *title;…

死鎖的產生和避免

1.死鎖產生的四個必要條件 (1)互斥條件&#xff1a;資源是獨占的且排他使用&#xff0c;進程互斥使用資源&#xff0c;即任意時刻一個資源只能給一個進程使用&#xff0c;其他進程若申請一個資源&#xff0c;而該資源被另一進程占有時&#xff0c;則申請者等待直到資源被占有者…

UVa401

【題目描述】 傳送門 【題目描述】 嘻嘻&#xff0c;自己做直接AC還是比較開心的。當然有一部分原因是之前看書的時候詳細看過這個題的代碼&#xff0c;但是這已經快一年了&#xff0c;應該說做出這道題憑借的是自己的能力吧。回過身去看了一下書中的代碼發現自己寫的不算復…

gethostbyname() 函數說明

https://www.cnblogs.com/cxz2009/archive/2010/11/19/1881611.html gethostbyname()函數說明——用域名或主機名獲取IP地址 包含頭文件#include <netdb.h>#include <sys/socket.h>函數原型struct hostent *gethostbyname(const char *name);這個函數的傳入值是域…

求解迷宮最短路徑

1. 多通路迷宮初始化 先構建一個多通路迷宮,并且對其初始化 void MazeInitShortPath(Maze* maze) {if(maze NULL){return;}int row 0;int col 0;for(; row < MAX_COL; row){for(col 0; col < MAX_COL; col){maze -> map[row][col] Map[row][col];}printf("…

UVa340

【題目描述】 傳送門 【題目分析】 題目理解以后十分簡單&#xff0c;但是這題面實在讓人自閉&#xff0c;這么簡單的題目啦啦啦啦說了那么多&#xff0c;實在是看不懂。&#xff08;幸虧我看了書理解了題目的意思&#xff0c;要不然。。&#xff09;還是要鍛煉自己的讀題能…

C語言:結構體中一級指針和二級指針的創建與釋放示例

http://blog.csdn.net/Bixiwen_liu/article/details/53610952 這幾天把C語言鞏固了一下&#xff0c;作為一門最基本的編程語言&#xff0c;C語言還是相當基礎和非常重要的&#xff0c;個人認為C語言還是很有必要學好吃透的。 今天寫的話題是結構體結構體中一級指針和二級指針的…