博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) D. Field expansion
阅读量:6656 次
发布时间:2019-06-25

本文共 2944 字,大约阅读时间需要 9 分钟。

D. Field expansion
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

In one of the games Arkady is fond of the game process happens on a rectangular field. In the game process Arkady can buy extensions for his field, each extension enlarges one of the field sizes in a particular number of times. Formally, there are n extensions, the i-th of them multiplies the width or the length (by Arkady's choice) by ai. Each extension can't be used more than once, the extensions can be used in any order.

Now Arkady's field has size h × w. He wants to enlarge it so that it is possible to place a rectangle of size a × b on it (along the width or along the length, with sides parallel to the field sides). Find the minimum number of extensions needed to reach Arkady's goal.

Input

The first line contains five integers abhw and n (1 ≤ a, b, h, w, n ≤ 100 000) — the sizes of the rectangle needed to be placed, the initial sizes of the field and the number of available extensions.

The second line contains n integers a1, a2, ..., an (2 ≤ ai ≤ 100 000), where ai equals the integer a side multiplies by when the i-th extension is applied.

Output

Print the minimum number of extensions needed to reach Arkady's goal. If it is not possible to place the rectangle on the field with all extensions, print -1. If the rectangle can be placed on the initial field, print 0.

Examples
input
3 3 2 4 4 2 5 4 10
output
1
input
3 3 3 3 5 2 3 5 4 2
output
0
input
5 5 1 2 3 2 2 3
output
-1
input
3 4 1 1 3 2 3 2
output
3
Note

In the first example it is enough to use any of the extensions available. For example, we can enlarge h in 5 times using the second extension. Then h becomes equal 10 and it is now possible to place the rectangle on the field.

没时间看的D居然是道暴力可以过的题唉,想着后面很难就没做,确实CF这种两小时赛制的比较机灵,有人觉得A难读,分数不高就放弃A,后面的题倒是容易看出他让你做什么。这个题的意思是你有一块h*w的

地经过放大ai倍使其不小于a*b,这不是直接dfs都可以过么,有些人以为这个扩大是相加,可能是读错题啦,这种写法类似于记忆化搜索

#include 
using namespace std;const int N = 1e6 + 5;int n;int tar[N];int ans = n + 1;bool cmp(int a, int b){ return a > b;}void dfs(int cur_a, int cur_b, int step){ if (!cur_a && !cur_b) { ans = min(ans, step); return; } if (step == n) return; if (tar[step] == 2) { while (cur_a) cur_a /= 2, step++; while (cur_b) cur_b /= 2, step++; ans = min(ans, step); return; } if (cur_a) dfs(cur_a / tar[step], cur_b, step + 1); if (cur_b) dfs(cur_a, cur_b / tar[step], step + 1);}int main(){ int a, b, h, w; while (~scanf("%d%d%d%d%d", &a, &b, &h, &w, &n)) { ans = n + 1; for (int i = 0; i < n; i++) scanf("%d", tar + i); sort(tar, tar + n, cmp); dfs((a - 1) / h, (b - 1) / w, 0); dfs((a - 1) / w, (b - 1) / h, 0); ans == n + 1 ? printf("-1\n") : printf("%d\n", ans); } return 0;}

 

转载于:https://www.cnblogs.com/BobHuang/p/6845955.html

你可能感兴趣的文章
2. ZooKeeper的ZAB协议。
查看>>
Hibernate Validation与Spring整合各注解的用法Demo
查看>>
myeclipse debug 工具栏不见了
查看>>
程序员成熟的标志
查看>>
How Google Backs Up The Internet Along With Exabytes Of Other Data
查看>>
js----预解析,作用域链
查看>>
leetcode 264. Ugly Number II
查看>>
如何创建Hiren的BootCD USB磁盘 -- 制作U盘启动盘
查看>>
lubuntu自动登录(lxde)
查看>>
Python--day39--管道和数据共享(面试可能会问到)
查看>>
第十二章 Python网络编程
查看>>
Caffe错误汇总与解决办法
查看>>
1079. Total Sales of Supply Chain (25)
查看>>
xcrun: error: unable to find utility "PackageApplication", not a developer tool or in PATH
查看>>
Oracle数据库中的左连接与右连接
查看>>
POJ-1742 Coins
查看>>
segmentController
查看>>
淘宝初始化代码 - 解决浏览器的兼容问题
查看>>
在win8 64位操作系统下Power Designer 16.5对MySQL5.6逆向工程的配置详解
查看>>
07.Javascript——入门高阶函数
查看>>