Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) D. Field expansion
1 second
256 megabytes
standard input
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.
The first line contains five integers a, b, h, w 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.
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.
3 3 2 4 4
2 5 4 10
1
3 3 3 3 5
2 3 5 4 2
0
5 5 1 2 3
2 2 3
-1
3 4 1 1 3
2 3 2
3
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 <bits/stdc++.h>
using namespace std;
const int N = 1e6 + ;
int n;
int tar[N];
int ans = n + ;
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] == )
{
while (cur_a) cur_a /= , step++;
while (cur_b) cur_b /= , step++;
ans = min(ans, step);
return;
}
if (cur_a) dfs(cur_a / tar[step], cur_b, step + );
if (cur_b) dfs(cur_a, cur_b / tar[step], step + );
}
int main()
{
int a, b, h, w;
while (~scanf("%d%d%d%d%d", &a, &b, &h, &w, &n))
{
ans = n + ;
for (int i = ; i < n; i++)
scanf("%d", tar + i);
sort(tar, tar + n, cmp);
dfs((a - ) / h, (b - ) / w, );
dfs((a - ) / w, (b - ) / h, );
ans == n + ? printf("-1\n") : printf("%d\n", ans);
}
return ;
}
Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) D. Field expansion的更多相关文章
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)(A.暴力,B.优先队列,C.dp乱搞)
A. Carrot Cakes time limit per test:1 second memory limit per test:256 megabytes input:standard inpu ...
- C.Fountains(Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)+线段树+RMQ)
题目链接:http://codeforces.com/contest/799/problem/C 题目: 题意: 给你n种喷泉的价格和漂亮值,这n种喷泉题目指定用钻石或现金支付(分别用D和C表示),C ...
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains 【树状数组维护区间最大值】
题目传送门:http://codeforces.com/contest/799/problem/C C. Fountains time limit per test 2 seconds memory ...
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) 一夜回到小学生
我从来没想过自己可以被支配的这么惨,大神讲这个场不容易掉分的啊 A. Carrot Cakes time limit per test 1 second memory limit per test 2 ...
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) E - Aquarium decoration 贪心 + 平衡树
E - Aquarium decoration 枚举两个人都喜欢的个数,就能得到单个喜欢的个数,然后用平衡树维护前k大的和. #include<bits/stdc++.h> #define ...
- 【动态规划】【滚动数组】【搜索】Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) D. Field expansion
显然将扩张按从大到小排序之后,只有不超过前34个有效. d[i][j]表示使用前i个扩张,当length为j时,所能得到的最大的width是多少. 然后用二重循环更新即可, d[i][j*A[i]]= ...
- 【预处理】【分类讨论】Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains
分几种情况讨论: (1)仅用C或D买两个 ①买两个代价相同的(实际不同)(排个序) ②买两个代价不同的(因为买两个代价相同的情况已经考虑过了,所以此时对于同一个代价,只需要保存美丽度最高的喷泉即可)( ...
- 树状数组 Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains
C. Fountains time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces Round #413, rated, Div. 1 + Div. 2 C. Fountains(贪心 or 树状数组)
http://codeforces.com/contest/799/problem/C 题意: 有n做花园,有人有c个硬币,d个钻石 (2 ≤ n ≤ 100 000, 0 ≤ c, d ≤ 100 ...
随机推荐
- Redis的下载安装
Redis官网只提供了Linux版,MicroSoft自己搞了个Windows版,可在GitHub下载: https://github.com/microsoftarchive/redis/relea ...
- [转载]深入理解Java 8 Lambda
原文链接:http://zh.lucida.me/blog/java-8-lambdas-insideout-language-features/ 深入理解Java 8 Lambda(语言篇——lam ...
- Django分组查询
先补充两个知识点: 1.group by 大前提:可以按照任意字段分组,但是最好是按照分辨度比较低的来分组(重复比较多的分辨度比较低). group by分组可以单独使用,不搭配其他条件. 分组的字段 ...
- url各部分组成分解
url各部分组成分解介绍:关于url可能大家都不陌生,第一印象就是网址.但是深究起来,不少朋友并明白里面的一些细节,下面就来进行一下分解.scheme://host:port/path?query#f ...
- shell流程语句使用介绍
1)使用if.case.read例子1:#!/bin/bash#读取终端输入的字符read -p "Please input a Number:" nn1=`echo $n|sed ...
- JAVA初级必须要搞懂的事项(希望对新手有所帮助)
1 安装JDK=> (1,下载JDK,安装,一般目录为C:\Program Files\Java中:2,通过Dos命令测试JDK是否安装=>java –version命令查看 ...
- 诊断 Grid Infrastructure 启动问题 (文档 ID 1623340.1)
适用于: Oracle Database - Enterprise Edition - 版本 11.2.0.1 和更高版本本文档所含信息适用于所有平台 用途 本文提供了诊断 11GR2 和 12C G ...
- CocoaPods 安装使用
CocoaPods是一个负责管理iOS项目中第三方开源代码的工具.CocoaPods项目的源码在Github上管理.该项目开始于2011年8月 12日,经过一年多的发展,现在已经超过1000次提交,并 ...
- idea 发布和本地测试问题
1.maven本地打包成jar 提示[错误: 找不到或无法加载主类]修改 配置maven ---->Runner---->VM Optins [-DarchetypeCatalog=loc ...
- 双击窗体是模拟键盘上的Tab键
实现效果: 知识运用: SendKeys类的Send方法 //向活动应用程序发送击键 public static void Send (string keys) 实现代码: private void ...