题目分析

题目答案不具有单调性,所以不可以二分,转而思考贪心。因为无法确定位置,所以考虑如何才能让对于每一个$1 ~ i$使得$i$的答案最大,即$1 ~ i$最后一个最优。若设对于位置$i$,$a[i]$表示左手,$b[i]$表示右手,$S$为其前面所有人的左手之积,那么他的答案就是$\frac{S}{b[i]}$,如果存在在$i$后边的$j$的答案更优, 即$\frac{S * a[i]}{b[j]} > \frac{S * a[j]}{b[i]} => a[i] * b[i] > a[j] * b[j]$,这样只要我们以a[i] * b[i]为关键字从小到大排序,就能保证每个前缀的最后一个都是最优的,只要$o(n)$扫一遍取最大值即可,记得使用高精度。

code

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std; const int N = ;
int n, a[N], b[N], c[N], ka, kb, kc; inline int read(){
int i = , f = ; char ch = getchar();
for(; (ch < '' || ch > '') && ch != '-'; ch = getchar());
if(ch == '-') f = -, ch = getchar();
for(; ch >= '' && ch <= ''; ch = getchar())
i = (i << ) + (i << ) + (ch - '');
return i * f;
} inline void wr(int x){
if(x < ) putchar('-'), x = -x;
if(x > ) wr(x / );
putchar(x % + '');
} struct bign{
int len, s[];
bign():len(){memset(s, , sizeof s);}
bign(int x):len(){
memset(s, , sizeof s);
while(x){
s[++len] = x % ;
x /= ;
}
if(!len) len = ;
}
inline void clear(){
while(len > && s[len] == ) len--;
}
inline bign operator * (const bign &b) const{
bign ret;
ret.len = len + b.len + ;
for(int i = ; i <= len; i++)
for(int j = ; j <= b.len; j++)
ret.s[i + j - ] += s[i] * b.s[j];
for(int i = ; i <= ret.len; i++)
if(ret.s[i] >= ){
ret.s[i + ] += ret.s[i] / ;
ret.s[i] %= ;
}
ret.clear();
return ret;
}
inline bign operator - (const bign &b) const{
bign ret;
ret.len = len;
for(int i = ; i <= len; i++){
ret.s[i] = ret.s[i] + s[i];
if(i <= b.len) ret.s[i] = ret.s[i] - b.s[i];
if(ret.s[i] < ){
ret.s[i + ]--;
ret.s[i] += ;
}
}
ret.clear();
return ret;
}
bign operator / (int b) {
bign c;
int f = ;
for(int i = len; i >= ; i--){
f = f * + s[i];
while(!(f < b)){
f -= b;
c.s[i]++;
}
}
c.len = len;
c.clear();
return c;
}
inline bool operator > (const bign &b) const{
if(len != b.len) return len > b.len;
for(int i = len; i >= ; i--)
if(s[i] != b.s[i]) return s[i] > b.s[i];
return false;
}
inline bool operator == (const bign &b) const{
if(len != b.len) return false;
for(int i = len; i >= ; i--)
if(s[i] != b.s[i]) return false;
return true;
}
inline bool operator < (const bign &b) const{
if(len != b.len) return len < b.len;
for(int i = len; i >= ; i--)
if(s[i] != b.s[i]) return s[i] < b.s[i];
return false;
}
inline void print(){
for(int i = len; i >= ; i--)
wr(s[i]);
}
}fa, ans, big0, big10; struct node{
int a, b, c;
inline bool operator < (const node &u) const{
if(c != u.c) return c < u.c;
return b > u.b;
}
}data[N]; int main(){
n = read(), ka = read(), kb = read();
for(int i = ; i<= n; i++){
data[i].a = read(), data[i].b = read();
data[i].c = data[i].a * data[i].b;
}
sort(data + , data + n + );
fa = ka;
ans = ;
bign tmpa, t;
for(int i = ; i <= n; i++){
tmpa = data[i].a;
t = fa / data[i].b;
if(t > ans) ans = t;
fa = fa * tmpa;
}
ans.print();
return ;
}

【NOIP2012提高组】国王游戏 贪心 + 高精度的更多相关文章

  1. [NOIP2012提高组]国王游戏

    题目:洛谷P1080.Vijos P1779.codevs1198. 题目大意:国王和每个大臣左.右手各写了一个数.规定每个大臣得到的金币数为他前面所有人左手的数字的乘积除以他自己右手的数(向下取整) ...

  2. [noip2012]国王游戏<贪心+高精度>

    题目链接: https://vijos.org/p/1779 https://www.luogu.org/problem/show?pid=1080 http://codevs.cn/problem/ ...

  3. P1080 国王游戏 贪心 高精度

    题目描述 恰逢 HH国国庆,国王邀请nn 位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右手上面分别写下一个整数,国王自己也在左.右手上各写一个整数.然后,让这 nn 位大臣排成一排,国王站在队伍的 ...

  4. P1080 【NOIP 2012】 国王游戏[贪心+高精度]

    题目来源:洛谷 题目描述 恰逢 H国国庆,国王邀请n 位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右手上面分别写下一个整数,国王自己也在左.右手上各写一个整数.然后,让这 n 位大臣排成一排,国王 ...

  5. NOIP2012提高组

    D1T1.Vigenère密码 模拟 #include<iostream> #include<cstdio> using namespace std; int main() { ...

  6. GZOJ 1361. 国王游戏【NOIP2012提高组DAY1】

    国王游戏[NOIP2012提高组DAY1] Time Limit:1000MS Memory Limit:128000K Description 国王游戏(game.cpp/c/pas) [问题描述] ...

  7. 刷题总结——疫情控制(NOIP2012提高组)

    题目: 题目背景 NOIP2012 提高组 DAY2 试题. 题目描述 H 国有 n 个城市,这 n 个城市用 n-1 条双向道路相互连通构成一棵树,1 号城市是首都,也是树中的根节点. H 国的首都 ...

  8. 洛谷P1080 [NOIP2012提高组D1T2]国王游戏 [2017年5月计划 清北学堂51精英班Day1]

    P1080 国王游戏 题目描述 恰逢 H 国国庆,国王邀请 n 位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右 手上面分别写下一个整数,国王自己也在左.右手上各写一个整数.然后,让这 n 位大臣排 ...

  9. [NOIP2012] 提高组 洛谷P1080 国王游戏

    题目描述 恰逢 H 国国庆,国王邀请 n 位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右 手上面分别写下一个整数,国王自己也在左.右手上各写一个整数.然后,让这 n 位大臣排 成一排,国王站在队伍 ...

随机推荐

  1. vb.net structure 定义静态数组

    Const RAS95_MaxEntryName = 256 Const RAS95_MaxDeviceName = 128 Const RAS_MaxDeviceType = 16 Structur ...

  2. 洛谷 P2430 严酷的训练

    P2430 严酷的训练 题目背景 Lj的朋友WKY是一名神奇的少年,在同龄人之中有着极高的地位... 题目描述 他的老师老王对他的程序水平赞叹不已,于是下决心培养这名小子. 老王的训练方式很奇怪,他会 ...

  3. SQLite基础学习

    SQLite是一款轻量级数据库,集成于android中,以下从分享一下自己学习的. 在查阅资料时有一些好的说明就直接用了: 主要的curd语句 以下SQL语句获取5条记录,跳过前面3条记录 selec ...

  4. web.config访问走代理的配置

    <system.net>    <defaultProxy>      <proxy bypassonlocal="False" usesystemd ...

  5. amazeui学习笔记--css(基本样式)--样式统一Normalize

    amazeui学习笔记--css(基本样式)--样式统一Normalize 一.总结 1.统一浏览器默认样式: Amaze UI 也使用了 normalize.css,就是让不同浏览器显示相同的样式 ...

  6. 【AtCoder Beginner Contest 074 D】Restoring Road Network

    [链接]h在这里写链接 [题意] 给你任意两点之间的最短路. 让你求出原图. 或者输出原图不存在. 输出原图的边长总和的最小值. [题解] floyd算法. 先在原有的矩阵上. 做一遍floyd. 如 ...

  7. vue指令应用--实现输入框常见过滤功能

    前端开发最常碰到的就是输入框,经常要做各种验证,本公司惯用的需求是直接屏蔽特定字符的输入,如禁止非数字输入,特殊符号输入,空格输入等,这些功能反复使用,做成指令的形式,直接调用,非常方便,上代码: 目 ...

  8. Mac怎么设置wifi热点

    苹果 Mac 系统中要把无线当作 Wifi 热点来用的话,需要电脑有其它网络接入才可以,也就是说它需要一个可以用于上网的网络,比如有线网络.尤其是对于使用 MacBook Pro 或 MacBook ...

  9. Swift--使图片360° 周期旋转

    UIImageView+Extension.swift import UIKit extension UIImageView { // 360度旋转图片 func rotate360Degree() ...

  10. 【47.40%】【codeforces 743B】Chloe and the sequence

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...