UVALive 6858 Frame (模擬)

Frame

題目連接:

http://acm.hust.edu.cn/vjudge/contest/130303#problem/Dios

Description


http://7xjob4.com1.z0.glb.clouddn.com/17e6574035df3f9b6d1fc6dfd8b650ac
spa

Input


The input file contains several test cases, each of them as described below.
The first line contains 2 integers — X and Y (3 ≤ X ≤ 10^6, 3 ≤ Y ≤ 10^6). The second line
contains integer N — the number of tile types to be analyzed (1 ≤ N ≤ 1000). Each of following N
lines contains one integer, not exceeding 10^6. We designate with AK the integer on the (k + 2)-th line of the input file.
code

Output


For each test case, your goal is to print N lines, where the K-th line should contain the word ‘YES’, if it is possible to tile the frame with size X × Y with tiles AK × 1, and the word ‘NO’ otherwise.
ip

Sample Input

5 6
2
3
4

Sample Output

YES
NO

Source


2016-HUST-線下組隊賽-4
get


題意:


在XY的矩形的最外圈放若干個 A1 的小矩形,判斷對於給定的A可以剛好徹底覆蓋.
input


題解:


考慮最上面一行的狀況,第一塊小矩形要麼從#(1,1)開始,要麼從#(1,2)開始(留出第一格給豎的矩形).
肯定第一塊的位置後,後面的擺放狀況是固定的,因此依次判斷一下是否合法便可.
string


代碼:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#define LL long long
#define maxn 101000
#define inf 0x3f3f3f3f
#define mod 1000000007
#define mid(a,b) ((a+b)>>1)
#define eps 1e-8
#define IN freopen("in.txt","r",stdin);
using namespace std;

int n;

int x,y;
bool solve(int a) {
    int last1 = x % a;
    if(last1 > 1) return 0;
    if(last1 == 1) {
        int last2 = y % a;
        if(last2 > 1) return 0;
        if(last2 == 1) return 1;
        if(last2 == 0) return (y-2) % a == 0;
    }
    if(last1 == 0) {
        int last2 = (y-1) % a;
        if(last2 > 1) return 0;
        if(last2 == 1) return 1;
        if(last2 == 0) return (x-2) % a == 0;
    }
}

bool solve2(int a) {
    int last1 = (x-1) % a;
    if(last1 > 1) return 0;
    if(last1 == 1) {
        int last2 = y % a;
        if(last2 > 1) return 0;
        if(last2 == 0) return 1;
        if(last2 == 1) return x % a == 0;
    }
    if(last1 == 0) {
        int last2 = (y-1) % a;
        if(last2 > 1) return 0;
        if(last2 == 0) return 1;
        if(last2 == 1) return y % a == 0;
    }
}

int main()
{
    //IN;

    while(scanf("%d %d", &x,&y) != EOF)
    {
        swap(x,y);
        int n; scanf("%d", &n);
        while(n--) {
            int a; scanf("%d", &a);
            if(solve(a) || solve2(a)) puts("YES");
            else puts("NO");
        }
    }

    return 0;
}
相關文章
相關標籤/搜索