• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
ACM s1124yy
守りたいものが 強くさせること
博客园    首页    新随笔    联系   管理     

Codeforces 799D Field expansion(随机算法)

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;
}
posted @ 2017-05-14 16:19  s1124yy  阅读(383)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3