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,可以用钻石,也可以用硬币来造,但是能用的钻石有限,硬币也有限,问能 ...
随机推荐
- 【Vagrant】-NO.130.Vagrant.1 -【Vagrant】
Style:Mac Series:Java Since:2018-09-10 End:2018-09-10 Total Hours:1 Degree Of Diffculty:5 Degree Of ...
- ESP8266小知识与注意事项
小知识 1. 什么是"512+512".“1024+1024”? 当ESP8266支持FOTA(无线升级)时,会给系统做个备份,当升级失败时,使之不至于死机.所以flash会被分割 ...
- [INS-06006] Passwordless SSH connectivity not set up between the following node(s)
解决方法1 参考:11.2.0.4 runInstaller: [INS-06006] Passwordless SSH connectivity not set up between the fol ...
- iOS深浅拷贝
浅拷贝:你和你的影子,你改变,你的影子发生改变 深拷贝:你的克隆人,你改变,你的克隆人并不会发生变化 eg: NSString *string = @"我是一个小白鼠"; NSSt ...
- 关于信号打断正在读取终端的read与select来监视0文件描述符的问题
首先说一下对于这个问题外的一些话: 我觉得我们应该有种质疑的态度,因为接下来的这个问题就和我们平常所想的不一样. 介绍一下问题: 曾经一直听说信号可以打断一个正在阻塞的进程,但是今天我试了一下关于信号 ...
- CLR 无法从 COM 上下文 0x208f68 转换为 COM 上下文 0x2090d8,这种状态已持续 60 秒
问题: CLR 无法从 COM 上下文 0x208f68 转换为 COM 上下文 0x2090d8,这种状态已持续 60 秒.拥有目标上下文/单元的线程很有可能执行的是非泵式等待或者在不发送 Wind ...
- PureMVC 官方文档翻译(一)
最近在学习PureMVC框架,感觉最权威的还是阅读官方文档,顺便翻译了下全当记笔记了. PureMVC概览 这篇文档他讨论PureMVC框架的类和接口,使用UML来阐述它们的角色.职责和协作. Pur ...
- C# 键盘钩子
p{ text-align:center; } blockquote > p > span{ text-align:center; font-size: 18px; color: #ff0 ...
- forms-隐藏处理
获取pin码. 查看网页源码<form action="" method="post"> PIN:<br> <inpu ...
- Mysql 版本号、存储引擎、索引查询
[1]Mysql 版本号.存储引擎.索引查询 # 查看数据库版本号 SELECT VERSION(); # 查看数据库支持的引擎(默认即Support == DEFAULT行) SHOW ENGINE ...