题目分析

题目答案不具有单调性,所以不可以二分,转而思考贪心。因为无法确定位置,所以考虑如何才能让对于每一个$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. Day2:数据运算

    一.算数运算 如: #!/usr/bin/env python # -*- coding:utf-8 -*- # Author:Hiuhung Wan print(10%2) #求模(取模) # 0 ...

  2. 驱动学习3-make

    在向内核中添加驱动的时候要完成3项工作 (1)在Kconfig中添加新代码对应项目的编译条件(下面Makefile文件中需要用到它定义的的宏变量) (2)将驱动源码添加到对应的目录中 (3)在目录Ma ...

  3. HTML 5 中FileReader的使用

    FileReader 接口主要用来把文件读入到内存中,而且读取文件里的数据.FileReader接口提供了一个异步API,使用该API能够在浏览器主线程中异步訪问文件系统 ,读取文件里的数据. Fil ...

  4. 面向对象的CSS

    原文 简书原文:https://www.jianshu.com/p/cb5e9f56ddcc 大纲 1.面向对象的CSS(OOCSS)概念 2.面向对象的CSS的作用 3.面向对象的CSS的注意事项 ...

  5. UVA 11489 - Integer Game 博弈

    看题传送门 题目大意: S和T在玩游戏,S先.给出一数字串,两人轮流取出一个数字,要求每次取完之后剩下的数为3的倍数,或者没有数字留下.如果两个人足够聪明,求胜利的一方. 思路: 我一开始竟然没有输C ...

  6. 算法 Tricks(四)—— 判断序列中的字符/数值是否交替出现

    比如:353, 54545,数字都是交替出现的: bool alternate = true; for (int i = 0; i < M.size(); ++i){ if (M[i] != M ...

  7. [array] leetCode-18. 4Sum -Medium

    18. 4Sum -Medium descrition Given an array S of n integers, are there elements a, b, c, and d in S s ...

  8. css 单行图片文字水平垂直居中汇总

    (1) 水平居中 a. 行内元素水平居中 因为img是行内元素(行内块级元素也一样)父级元素设置text-align:center即可,例如: <div style="width: 6 ...

  9. 【Codeforces Round #439 (Div. 2) A】The Artful Expedient

    [链接] 链接 [题意] [题解] 暴力 [错的次数] 在这里输入错的次数 [反思] 在这里输入反思 [代码] #include <bits/stdc++.h> using namespa ...

  10. [Javascript] Validate Data with the Every() Method

    The every method returns true or false based on whether or not every item in the array passes the co ...