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. JS前端开发判断是否是手机端并跳转操作(小结)

    JS前端开发判断是否是手机端并跳转操作(小结) 这篇文章主要介绍了JS前端开发判断是否是手机端并跳转操作,非常不错,具有参考借鉴价值,需要的朋友可以参考下 常用跳转代码 ? 1 2 3 4 5 6 7 ...

  2. zookeeper入门及使用(一)- 安装及操作

    zookeeper是什么? highly reliable distributed coordination,用来做高可靠的分布式协调者,可用来: 业务发现(service discovery)找到分 ...

  3. python 序列化模块之 json 和 pickle

    JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,采用完全独立于语言的文本格式,支持不同程序之间的数据转换.但是只能转换简单的类型如:(列表.字典.字符串. ...

  4. C#.net mysql There is already an open datareader associated with this command引发的问题

    [参考]There is already an open datareader associated with this command引发的问题 我在语句中并未使用 DataReader,未何也提示 ...

  5. springboot-async

    在项目中,当访问其他人的接口较慢或者做耗时任务时,不想程序一直卡在耗时任务上,想程序能够并行执行, 我们可以使用多线程来并行的处理任务,也可以使用spring提供的异步处理方式@Async. Spri ...

  6. Java Observer接口和Observable类实现观察者模式

    对于观察者模式,其实Java已经为我们提供了已有的接口和类.对于订阅者(Subscribe,观察者)Java为我们提供了一个接口,JDK源码如下: package java.util; public ...

  7. openwrt官方固件怎么中继网络

    关键一点,取消勾

  8. js返回上一页并刷新、返回上一页、自动刷新页面

    一.返回上一页并刷新 <a href="javascript:" onclick="self.location=document.referrer;"&g ...

  9. Thread类的join()方法

    public class Demo { /** * Thread类的join()方法 * -------------------------------- * 1)join() * 2)join(lo ...

  10. 10.vue框架

    vue框架 易用.灵活.高效 https://cn.vuejs.org/ mvc M model 数据 模型 V view 视图 dom操作 C controller 控制器 路由 C oBtn.on ...