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. 解剖 Elasticsearch 集群 - 之二

    解剖 Elasticsearch 集群 - 之二 本篇文章是一系列涵盖 Elasticsearch 底层架构和原型示例的其中一篇.在本篇文章中,我们会讨论 Elasticsearch 是如何处理 3C ...

  2. UITableView 自定义多选

    前言 在上一篇文章中介绍了UITableView的多选操作,有提到将 return UITableViewCellEditingStyleDelete | UITableViewCellEditing ...

  3. 【2019年04月10日】股票的滚动市盈率PE最低排名

    仅根据最新的市盈率计算公式进行排名,无法对未来的业绩做出预测. 新钢股份(SH600782) - 滚动市盈率PE:3.87 - 滚动市净率PB:1.29 - 滚动年化股息收益率:1.31% - 钢铁 ...

  4. A new session could not be created. (Original error: Requested a new session but one was in progress) (WARNING: The server did not provide any stacktrace information)

    出现这个问题,是因为关毕了appium,或者是关毕了appium再次打开,那么session就不是一样的了所以报错. 一般是因为测试的时候报错了,appium自动关毕了,再次打出现的报错 解决方法:重 ...

  5. numpy学习之创建数组

    1.使用array函数创建数组 import numpy as np ndarray1 = np.array([1, 2, 3]) array([1, 2, 3]) ndarray2 = np.arr ...

  6. Oracle导出数据EXP00106错误

    在导出dmp文件的时候(命令:exp 用户名/密码@IP/实例名  file=D:\20180910.dmp log=D:\20180910.log),遇到以下错误: 错误原因: 导出使用的是Orac ...

  7. How not to alienate your reviewers, aka writing a decent rebuttal?

    [forwarded from https://nebelwelt.net/blog/20180704-rebuttal.html] Assuming you have given everythin ...

  8. linux/nginx命令

    1.ps查看服务器所有的进程: -aux 显示所有状态 -ef 简洁信息 ps -aux | grep node 第二列是pid,杀掉程序使用kill. ps -ef | grep node 第一列是 ...

  9. keras入门

    自己要搞深度学习,正好手上有本keras之父写的深度学习书,于是就从keras入手吧.看了一个电影的二分类问题,确实很简单,可以熟悉深度学习的流程.首先熟悉了结果keras的模块,如model,Seq ...

  10. Tomb Raider

    Lara Croft, the fiercely independent daughter of a missing adventurer, must push herself beyond her ...