贪心加高精

传送门:QWQ

先考虑两个人

a0 b0
p1 a1 b1
p2 a2 b2

那么满足:\(\huge ans1=\max(\frac{a0}{b1} , \frac{a0a1}{b2})\)

a0 b0
p2 a2 b2
p2 a1 b1

\(\huge ans2=\max(\frac{a0}{b2} , \frac{a0a2}{b1})\)

如果要让ans1<ans2

设 \(k1=\frac{a0}{b1} , k2=\frac{a0a1}{b2} , k3=\frac{a0}{b2} , k4=\frac{a0a2}{b1}\)

则 k1< k4

k2 > k3

如果要让ans1<ans2

那么 k4 > k2

展开,得:\(\frac{a0a2}{b1} > \frac{a0a1}{b2}\)

移项得:\(a1b1<a2b2\)

根据冒泡排序

两个相邻交换一定使答案更差

所以可以根据ab的大小排序(下标排序)

然后就是麻烦的高精了

//自动无视c++14
// luogu-judger-enable-o2
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=1e4+5;
int n;
// The MIT License (MIT) // Copyright (c) YEAR NAME // Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
struct big{
static const int base=10000;
int a[2333];
int len;
big(){memset(a,'\000',sizeof a);len=1;}
int& operator[](int x){return a[x];}
big(int x){*this=x;}
big& operator =(int x){
*this=big();
for(len=0;x;x/=base)a[++len]=x%base;
if(!x)len=1;
return *this;
}
friend big operator + (const big&a,const big& b){
big c;
c.len=max(a.len,b.len);
for(int i=1;i<=c.len;++i){
c[i+1]+=((c[i]+=(a.a[i]+b.a[i]))/base);
c[i]%=base;
}
if(c[c.len+1])c.len++;
return c;
}
friend big operator * (const big&a,const big& b){
big c;
c.len=a.len+b.len-1;
for(int i=1;i<=a.len;++i){
for(int j=1;j<=b.len;++j){
c[i+j-1]+=a.a[i]*b.a[j];
c[i+j]+=c[i+j-1]/base;
c[i+j-1]%=base;
}
}
while(c[c.len+1]){
c[c.len+1]+=c[c.len]/base;
c[c.len]%=base;
c.len++;
}
return c;
}
friend big operator + (const big a,int b){big c(b);return a+c;}
friend big operator * (const big a,int b){big c(b);return a*c;}
friend bool operator < (const big & a,const big&b){
if(a.len==b.len){
for(int i=a.len;i;--i){
if(a.a[i]!=b.a[i])return a.a[i]<b.a[i];
}
}else{
return a.len<b.len;
}
return 0;
}
friend big operator / (const big& a,int x){
big ans;
ans.len=a.len;
int jw=0;
for(int i=ans.len;i;--i){
ans[i]=(jw*base+a.a[i])/x;
((jw*=base)+=a.a[i])%=x;
}
while(!ans[ans.len]&&ans.len)ans.len--;
return ans;
}
void print()const{printf("%d",a[len]);
for(int i=len-1;i;i--){
printf("%04d",a[i]);
}
}
friend ostream& operator << (ostream& out,const big& a){
a.print();
return out;
}
};
int a[maxn],b[maxn];
int bit[maxn];
big f[maxn];
big ans;
big mul(1);
int main(){
cin>>n;
for(int i=0;i<=n;++i){
cin>>a[i]>>b[i];
big x(a[i]),y(b[i]);
f[i]=x*y;
bit[i]=i;
}
sort(bit+1,bit+1+n,[](const int& a,const int& b){
return f[a]<f[b];
});
for(int i=0;i<=n;++i){
if(i)ans=max(ans,mul/b[bit[i]]);
mul=mul*a[bit[i]];
}
ans.print();
return 0;
}

luogu P1080国王游戏的更多相关文章

  1. Luogu P1080国王游戏(贪心)

    国王游戏 题目链接:国王游戏 ps:题目数据说明了要写高精度. 这个题的答案是\(a.l * a.r < b.l * b.r\)按照这个进行排序 题解中大部分只是如何证明排序是: \(a.l * ...

  2. luogu P1080 国王游戏

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

  3. 【题解】洛谷 P1080 国王游戏

    目录 题目 思路 \(Code\) 题目 P1080 国王游戏 思路 贪心+高精度.按\(a \times b\)从小到大排序就可以了. \(Code\) #include<bits/stdc+ ...

  4. P1080 国王游戏 (等待高精度AC)

    P1080 国王游戏 题解 贪心策略:按照大臣左右手数字乘积从小到大排序 假设我们已经把大臣排了一个顺序 假定在这个顺序下我们可以保证  得到奖赏最多的大臣所得奖赏最少 那么我们一旦交换任意两个大臣, ...

  5. 【流水调度问题】【邻项交换对比】【Johnson法则】洛谷P1080国王游戏/P1248加工生产调度/P2123皇后游戏/P1541爬山

    前提说明,因为我比较菜,关于理论性的证明大部分是搬来其他大佬的,相应地方有注明. 我自己写的部分换颜色来便于区分. 邻项交换对比是求一定条件下的最优排序的思想(个人理解).这部分最近做了一些题,就一起 ...

  6. 洛谷—— P1080 国王游戏

    https://www.luogu.org/problem/show?pid=1080 题目描述 恰逢 H 国国庆,国王邀请 n 位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右手上面分别写下一个整 ...

  7. 洛谷P1080 国王游戏【大数】【贪心】

    题目:https://www.luogu.org/problemnew/show/P1080 题意: 一个国王和n个大臣,每个人左右手上都有一个数值. 现在将国王排在队首,将大臣进行排序.每个大臣的值 ...

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

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

  9. [贪心][高精]P1080 国王游戏(整合)

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

随机推荐

  1. Docker03 Docker基础知识、Docker实战

    1 Docker基础知识 1.1 什么是Docker Docker是一个可以装应用的容器,就像杯子可以装水.书包可以装书一样:docker官网 Docker是Docker公司开发的,并开源到GitHu ...

  2. spring中添加google的guava缓存(demo)

    1.pom文件中配置 <dependencies> <dependency> <groupId>org.springframework</groupId> ...

  3. SQL Server 2005/2008/2012中应用分布式分区视图

    自2000版本起,SQL Server企业版中引入分布式分区视图,允许你为分布在不同的SQL 实例的两个或多个水平分区表创建视图. 简要步骤如下:根据Check约束中定义的一组值把大表分割成更小的一些 ...

  4. Openssl pkey命令

    一.简介 pkey是一个公钥或私钥的处理命令,可以用于打印和转换不同的表单和组件 二.语法 openssl pkey [-inform PEM|DER] [-outform PE|DER] [-in ...

  5. css中calc()的使用

    calc()是css3中新出现的特性,可以用于动态计算,非常方便. 首先是兼容性 再来看看怎么使用 html{ font-size: 20px; } div{ width: calc(50% - 1p ...

  6. if-return 语句

    if(A > B): return A+1 return A-1 or if(A > B): return A+1 else: return A-1 +++++++++++++++++++ ...

  7. 1 Python入门及计算机硬件知识

    一: Python是一种编程语言 语言: 语言是一种事物与另外一种事物沟通的介质 所以说编程语言是程序员和计算机之间实现沟通的桥梁 什么是编程?: 编程就是程序员用计算机所能理解的表达方式(编程语言) ...

  8. Dubbo服务启动依赖检查

    dubbo 官方文档地址:http://dubbo.io/User+Guide-zh.htm 项目中存在服务之间存在循环依赖,启动时总是报错,通过修改启动检查check=false解决,下面是dubb ...

  9. Java Decompiler(Java反编译工具)

    参考:http://blog.csdn.net/yulei_qq/article/details/24175547 Java Decompiler可以对整个jar包进行反编译,也可以将其集成到ecli ...

  10. mysql:unknown variable 'default -collation=utf8_general_ci'

    无法登陆,因为在配置文档中设置了默认编码方式 将它注释掉,问题就解决了 在utf8_bin中你就找不到 txt = 'A' 的那一行, 而 utf8_general_ci 则可以.utf8_gener ...