Field expansion

【题目链接】Field expansion

【题目类型】随机化算法

&题解:

参考自:http://www.cnblogs.com/Dragon-Light/p/6843866.html

这种想法简直让我大开眼界啊, 原来这题还可以这么写!!

&代码:

#include <cstdio>
#include <bitset>
#include <iostream>
#include <set>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
#include <ctime>
using namespace std;
#define INF 0x3f3f3f3f
#define ll long long
#define fo(i,a,b) for(int i=(a);i<=(b);i++)
#define fd(i,a,b) for(int i=(a);i>=(b);i--)
const int maxn = 1e5 + 7;
int h, w, c, d, n, a[maxn];
ll ans;
void sol(ll x, ll y) {
ll cnt = 0;
while(x < h || y < w) {
cnt++;
if(cnt > n) return ;
if(x >= h) {
y *= a[cnt];
}
else if(y >= w) {
x *= a[cnt];
}
else {
if(rand() % 2) {
x *= a[cnt];
}
else {
y *= a[cnt];
}
}
}
ans = min(ans, cnt);
}
bool cmp(int a, int b) { return a > b;}
int main() {
freopen("E:1.in", "r", stdin);
srand(time(NULL));
scanf("%d%d%d%d%d", &h, &w, &c, &d, &n);
fo(i, 1, n) scanf("%d", &a[i]);
ans = INF;
int zz = 0;
sort(a + 1, a + 1 + n, cmp);
while((double)clock() / CLOCKS_PER_SEC <= 0.93) {
sol(c, d); sol(d, c);
zz++;
}
if(ans == INF) ans = -1;
printf("%d\n", ans);
// cout << zz << endl;
return 0;
}

Codeforces 799D Field expansion(随机算法)的更多相关文章

  1. 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 ...

  2. Codeforces 417E Square Table(随机算法)

    题目链接:Codeforces 417E Square Table 题目大意:给出n和m.要求给出一个矩阵,要求每一列每一行的元素的平方总和是一个平方数. 解题思路:构造.依照 a a a b a a ...

  3. [Codeforces 364D]Ghd(随机算法+gcd)

    [Codeforces 364D]Ghd(随机算法) 题面 给出n个正整数,在其中选出n/2(向上取整)个数,要求这些数的最大公约数最大,求最大公约数的最大值 分析 每个数被选到的概率\(\geq \ ...

  4. 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 ...

  5. 微信红包中使用的技术:AA收款+随机算法

    除夕夜你领到红包了吗?有的说“我领了好几K!”“我领了几W!” 土豪何其多,苦逼也不少!有的说“我出来工作了,没压岁钱了,还要发红包”.那您有去抢微信红包吗?微信群中抢“新年红包”春节爆红.618微信 ...

  6. POJ 3318 Matrix Multiplication(随机算法)

    题目链接 随机算法使劲水...srand((unsigned)time(0))比srand(NULL)靠谱很多,可能是更加随机. #include <cstdio> #include &l ...

  7. 抽奖随机算法的技术探讨与C#实现

    一.模拟客户需求 1.1 客户A需求:要求每次都按照下图的概率随机,数量不限,每个用户只能抽一次,抽奖结果的分布与抽奖概率近似. 1.2 客户B需求:固定奖项10个,抽奖次数不限,每个用户只能抽一次, ...

  8. hdu 4712 (随机算法)

    第一次听说随机算法,在给的n组数据间随机取两个组比较,当随机次数达到一定量时,答案就出来了. #include<stdio.h> #include<stdlib.h> #inc ...

  9. 权重随机算法的java实现

    一.概述 平时,经常会遇到权重随机算法,从不同权重的N个元素中随机选择一个,并使得总体选择结果是按照权重分布的.如广告投放.负载均衡等. 如有4个元素A.B.C.D,权重分别为1.2.3.4,随机结果 ...

随机推荐

  1. C语言 · 礼物盒

    礼物盒 分值: 20 小y 有一个宽度为 100cm,高度为 20cm,深度为 1cm 的柜子,如下图. 小y 还有 36 个礼物盒,他们的深度都为 1cm. 他们对应的宽度和高度如下,单位(cm). ...

  2. Java编程的逻辑 (88) - 正则表达式 (上)

    本系列文章经补充和完善,已修订整理成书<Java编程的逻辑>,由机械工业出版社华章分社出版,于2018年1月上市热销,读者好评如潮!各大网店和书店有售,欢迎购买,京东自营链接:http:/ ...

  3. Caffe 分类问题 Check failed: error == cudaSuccess (2 vs. 0) out of memory

    如果图片过大,需要适当缩小batch_size的值,否则使用GPU时可能超出其缓存大小而报错

  4. java.lang.UnsatisfiedLinkError: No implementation found for long org.opencv.core.Mat.n_Mat()

    Android调试openCV4Android的时候出现以下错误 java.lang.UnsatisfiedLinkError: No implementation found for long or ...

  5. CSS外边距属性,深入理解margin

    margin See the Pen margin by wmui (@wmui) on CodePen. 该属性用于设置元素的外边距,外边距是透明的,默认值0.这是一个简写属性,属性值最多为4个,例 ...

  6. 【Zookeeper系列】zookeeper面试题(转)

    原文链接:https://segmentfault.com/a/1190000014479433 1.ZooKeeper是什么? ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是 ...

  7. ASP.NET Core MVC+EF Core从开发到部署

    笔记本电脑装了双系统(Windows 10和Ubuntu16.04)快半年了,平时有时间就喜欢切换到Ubuntu系统下耍耍Linux,熟悉熟悉Linux命令.Shell脚本以及Linux下的各种应用的 ...

  8. js如何获取字符串第几次出现的位置

    str:查询字符串: cha:查询子字符串: num:第几次出现:第一次则为 1: function findStrIndex(str, cha, num-1) { var x = str.index ...

  9. Realm 简介

    是一个跨平台的本地数据库,比sqlite 数据库更轻量级,执行效率更高. 官网地址:https://realm.io/docs/java/latest/

  10. 22.2、react生命周期与react脚手架(二)

    一.类:es6 <script type="text/babel"> class Person{ age = 10; constructor(name){ this.n ...