Codeforces 799 D. Field expansion
题目链接: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的更多相关文章
- codeforces 799 D. Field expansion(dfs+思维剪枝)
题目链接:http://codeforces.com/contest/799/problem/D 题意:给出h*w的矩阵,要求经过操作使得h*w的矩阵能够放下a*b的矩阵,操作为:将长或者宽*z[i] ...
- 【codeforces 799D】Field expansion
[题目链接]:http://codeforces.com/contest/799/problem/D [题意] 给你长方形的两条边h,w; 你每次可以从n个数字中选出一个数字x; 然后把h或w乘上x; ...
- 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 ...
- Codeforces 799D Field expansion(随机算法)
Field expansion [题目链接]Field expansion [题目类型]随机化算法 &题解: 参考自:http://www.cnblogs.com/Dragon-Light/p ...
- 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 ...
- 【动态规划】【滚动数组】【搜索】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]]= ...
- [413D][搜索]D - Field expansion
http://codeforces.com/contest/799/problem/D 解题关键:因为3^11>100000,所以若只把2单独拿出,最多只需要暴力2^11次,故只需要dfs一下即 ...
- 【贪心+DFS】D. Field expansion
http://codeforces.com/contest/799/problem/D [题意] 给定长方形的两条边h和w,你可以从给出的n个数字中随意选出一个x,把h或者w乘上x(每个x最多用一次) ...
- codeforces 799 C. Fountains(二分+思维)
题目链接:http://codeforces.com/contest/799/problem/C 题意:要求造2座fountains,可以用钻石,也可以用硬币来造,但是能用的钻石有限,硬币也有限,问能 ...
随机推荐
- iOS Version和Build的区别
iOS开发中,会面对一个问题,Version和Build的区别.这两种均是版本号,但是在开发中还是有一定的区别,而且用处很大. Version 是版本号,在info.plist中对应的key是 CFB ...
- JS获取页面复选框选中的值
function jqchk(){ //jquery获取复选框值 var chk_value =[]; $('input[class="sel"]:checked').each(f ...
- iphone X 底部留白 之 ionic3 项目
在全局css中加入 @media only screen and (device-width: 375px) and (device-height: 812px) and (-webkit- ...
- jmeter压测mysql报can not be represented as java.sql.Timestame错误解决方法
JDBC Request 测试mysql时报以下问题? jmeter报错信息: 解决方法: 在数据库url后拼接上字符串?characterEncoding=utf8&zeroDateTim ...
- 《linux就该这么学》第十七节课:第18,19,23章,mariadb数据库、PXE无人值守安装系统和openldap目录服务。
第23章 (借鉴请改动) openldap数据的特点:1.短小.2.读取次数较多 上述说明: openLDAP服务端配置: 1.yum install -y openldap openldap ...
- 前端学习历程--vue
---恢复内容开始--- 一.对比其他框架 1.react: 共同点: 使用 Virtual DOM 提供了响应式(Reactive)和组件化(Composable)的视图组件. 将注意力集中保持在核 ...
- eclipse jpa 工具生成实体类
1,配置数据库连接 打开eclipse, 选择数据库: 下一步,选择驱动包 根据自己的驱动包路径选择对应的驱动包: 2,配置jpa-tool 在项目上面右键->properties 点击ok,然 ...
- 使用 dom4j 处理 xml (2)
记录一些 xpath 的常规用法,备忘. //3.XPath 了解(用于在xml中选取元素,类似 jquery 选择器) //3.1 路径 Node node1 = root.selectSingle ...
- Windbg程序调试系列3-线程阻塞问题
上一篇博文给大家分享了使用Windbg分析内存泄露问题: Windbg程序调试系列2-内存泄露问题 本篇我们继续跟大家分享,如何分析解决线程阻塞问题. 从根本上讲,线程阻塞属于程序Hang的一种,其表 ...
- Blender学习
学习顺序(下面为引用他人的视频或博客) 51个必须知道的blender操作 https://www.bilibili.com/video/av4619930/ Blender常用快捷键一览表 http ...