题目链接:http://codeforces.com/contest/799/problem/D

因为${a_i>=2}$那么一个数字至多操作${log_{2}^{max(a,b)/min(h,w)}}$之后就会超过给定的${a,b}$,所以可以搜索,考虑复杂度问题我们就直接随机化,显然按照a_i的大小从大往小选。

辣鸡出题人没有把$h,w$旋转$90$度的情况放在PP里面,我的rating啊...

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<cstring>
using namespace std;
#define maxn 1001000
#define llg long long
#define inf 0x7fffffff
#define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
llg n,m,a[maxn],c,d,w,h,ans=inf,f[maxn]; bool cmp(llg a,llg b) {return a>b;} inline int getint()
{
int w=,q=; char c=getchar();
while((c<'' || c>'') && c!='-') c=getchar(); if(c=='-') q=,c=getchar();
while (c>='' && c<='') w=w*+c-'', c=getchar(); return q ? -w : w;
} void work()
{
llg cs=;
llg x=c,y=d;
while (x<h || y<w)
{
cs++;
if (cs>n) return ;
if (x>=h) {y*=a[cs]; continue;}
if (y>=w) {x*=a[cs]; continue;}
if (rand()%) x*=a[cs];else y*=a[cs];
}
ans=min(ans,cs);
} int main()
{
yyj("D");
cin>>h>>w>>c>>d>>n;
for (llg i=;i<=n;i++) a[i]=getint(),f[a[i]]++;
sort(a+,a+n+,cmp);
// n=min(n,(llg)40);
while ((double)clock()/CLOCKS_PER_SEC<=0.91) work(),swap(h,w),work(),swap(h,w);
if (ans==inf) ans=-;
cout<<ans; return ;
}

Codeforces 799 D. Field expansion的更多相关文章

  1. codeforces 799 D. Field expansion(dfs+思维剪枝)

    题目链接:http://codeforces.com/contest/799/problem/D 题意:给出h*w的矩阵,要求经过操作使得h*w的矩阵能够放下a*b的矩阵,操作为:将长或者宽*z[i] ...

  2. 【codeforces 799D】Field expansion

    [题目链接]:http://codeforces.com/contest/799/problem/D [题意] 给你长方形的两条边h,w; 你每次可以从n个数字中选出一个数字x; 然后把h或w乘上x; ...

  3. Codeforces 799D Field expansion - 搜索 - 贪心

    In one of the games Arkady is fond of the game process happens on a rectangular field. In the game p ...

  4. Codeforces 799D Field expansion(随机算法)

    Field expansion [题目链接]Field expansion [题目类型]随机化算法 &题解: 参考自:http://www.cnblogs.com/Dragon-Light/p ...

  5. Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) D. Field expansion

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

  6. 【动态规划】【滚动数组】【搜索】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]]= ...

  7. [413D][搜索]D - Field expansion

    http://codeforces.com/contest/799/problem/D 解题关键:因为3^11>100000,所以若只把2单独拿出,最多只需要暴力2^11次,故只需要dfs一下即 ...

  8. 【贪心+DFS】D. Field expansion

    http://codeforces.com/contest/799/problem/D [题意] 给定长方形的两条边h和w,你可以从给出的n个数字中随意选出一个x,把h或者w乘上x(每个x最多用一次) ...

  9. codeforces 799 C. Fountains(二分+思维)

    题目链接:http://codeforces.com/contest/799/problem/C 题意:要求造2座fountains,可以用钻石,也可以用硬币来造,但是能用的钻石有限,硬币也有限,问能 ...

随机推荐

  1. RN启动报错,环境相关问题

    启动RN的时候刚开始报错: The request was denied by service delegate (SBMainWorkspace) for reason: Security (&qu ...

  2. urlib库的使用

    urlib库实际上不是很常用,因为其api调用复杂,已被requests模块取代. 1.request发送请求 from urllib import request #默认指定的是get请求 #url ...

  3. 干了这杯java之ThreadLocal

    ThreadLocal Java篇 是什么 怎么用 源码 缺点 总结 是什么 ThreadLocal是一个关于创建线程局部变量的类,这个变量只能当前线程使用,其他线程不可用. ThreadLocal提 ...

  4. eval() 和 int()区别,以及eval作用

    eval()方法作用是将数据转换回原本的类型 a = str(list) type(a)--->str eval(a) type(a)--->list

  5. Scala面向对象详解

    Scala的包(作用域) package com.jh.scala 等同于 package jh \n package scala 等同于 package com.jh{ package scala ...

  6. git本地分支与远程分支

    github上已经有master分支 和dev分支 在本地 git checkout -b dev 新建并切换到本地dev分支 git pull origin dev 本地分支与远程分支相关联 在本地 ...

  7. orcl数据库锁等级研究小记

    上周通过orcl 悲观锁的方式解决了一个并发临界值的问题.现在来研究下orcl各中锁的机制以及如何手动释放锁. 首先,通过查阅资料,先了解下数据的的各种操作语言分类. SQL语言共分为四大类:数据查询 ...

  8. git之commit

    面解释的话, 1.git commit -m用于提交暂存区的文件: 2.git commit -am用于提交跟踪过的文件. 要理解它们的区别,首先要明白git的文件状态变化周期,如下图所示 工作目录下 ...

  9. elastic-job集成到springboot教程,和它的一个异常处理办法:Sharding item parameters '1' format error, should be int=xx,int=xx

    先说这个Sharding item parameters '1' format error, should be int=xx,int=xx异常吧,这是在做动态添加调度任务的时候出现的,网上找了一会没 ...

  10. gvim keil 快捷跳转至出现错误(警告)行

    开发环境 win7系统中:用keil 对工程进行编译链接,用gvim编辑查看源文件. 实现效果 一键跳转到出现警告或者错误的源码. 实现原理 gvim 调用外部shell脚本,对keil编译生成的lo ...