Frame

题目链接:

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

Description


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

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.

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.

Sample Input


```
5 6
2
3
4
```

Sample Output


```
YES
NO
```

Source


2016-HUST-线下组队赛-4


##题意:

在X*Y的矩形的最外圈放若干个 A*1 的小矩形,判断对于给定的A能够恰好完全覆盖.


##题解:

考虑最上面一行的情况,第一块小矩形要么从#(1,1)开始,要么从#(1,2)开始(留出第一格给竖的矩形).
确定第一块的位置后,后面的摆放情况是固定的,所以依次判断一下是否合法即可.


##代码:
``` cpp
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#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;

}

最新文章

  1. html5+css3 制作音乐播放器
  2. Quartz任务调度器
  3. git常用命令学习
  4. nginx https使用
  5. KVC笔记
  6. 【转】require.js学习笔记(二)
  7. 【不积跬步,无以致千里】安装roundcube 时出现 “DSN (write): NOT OK(SQLSTATE[HY000] [2002] No such file or directory)”
  8. PHP中的可变参数函数和可选参数函数
  9. HOOK windows消息 C# 代码
  10. Map的内容按字母顺序排序
  11. Js Json 互转
  12. [转]从数据库中导出用友U8的现存量数据到Excel表
  13. 八 Appium常用方法介绍
  14. 20165223 《信息安全系统设计基础》 改进ls的实现
  15. PHP 递归几种方法
  16. 织梦自定义表单ajax提交范例
  17. vue 安卓5.1 ios9 兼容性 白屏问题
  18. thymeleaf参考手册
  19. 对扫描的pdf文件生成目录
  20. fiddler4如何只抓取指定浏览器的包

热门文章

  1. unittest中的断言方法
  2. linux 正则表达式 目录
  3. 这款多线程中间件,吊打 Redis!
  4. HNUSTOJ-1690 千纸鹤
  5. CyclicBarrier、CountDownLatch、Callable、FutureTask、thread.join() 、wait()、notify()、Condition
  6. hdu 2586 How far away ? ( 离线 LCA , tarjan )
  7. P2516 [HAOI2010]最长公共子序列
  8. 中国各个省市县的人口统计,echart展示
  9. RAC heartbeat 心跳机制
  10. CentOS8 安装部署Apache+Php+MariaDB(pdo扩展)