贪心加高精

传送门: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. NavigationController.viewControllers

      NSMutableArray *viewControllersArray = [NSMutableArray new];    // 获取当前控制器数组    for (CardLoanBaseT ...

  2. ajax请求后台有时走有时不走

    ajax请求后台有时走有时不走   ajax请求后台有时走有时不走,是因为没有将请求设置为同步方式,async:false,(默认为true即异步).如果不想使用缓存可以将cache:false,例如 ...

  3. MySQL5.6.35部署

    1.下载软件 [root@localhost src]# wget -q http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glib ...

  4. c++ static笔记

    [转]http://www.cnblogs.com/zi-xing/p/4590282.html static的作用 在函数体,一个被声明为static的变量,在这一函数被调用的过程里,其数值维持不变 ...

  5. code3027 线段覆盖2

    dp 数据:d[i].a d[i].b d[i].v 分别表示第i条线段的起始点,结束点,价值 先按d[i].b排好序 dp[i]表示前i条线段的最大价值 方程: dp[i]=max{ dp[i-1] ...

  6. 最近公共祖先 LCA Tarjan算法

    来自:http://www.cnblogs.com/ylfdrib/archive/2010/11/03/1867901.html 对于一棵有根树,就会有父亲结点,祖先结点,当然最近公共祖先就是这两个 ...

  7. Python使用signal模块实现定时执行

    在liunx系统中要想每隔一分钟执行一个命令,最普遍的方法就是crontab了,如果不想使用crontab,经同事指点在程序中可以用定时器实现这种功能,于是就开始摸索了,发现需要一些信号的知识... ...

  8. 在linux下使用CMake构建应用程序

    本文介绍了一个跨平台的自动化构建系统 CMake 在 linux 上的使用方法. CMake 是一个比 automake 更加容易使用的工具,能够使程序员从复杂的编译连接过程中解脱出来.文中通过一些例 ...

  9. k8s启动Pod遇到CrashLoopBackOff的解决方法

    1.用kubectl get pod 当看到上面的状态后执行第2步 2.查看pod详情 [root@cc hzb]# kubectl describe pod ceph-mysql-hzb-pod 找 ...

  10. Spring实战-README.md

    教程 <Spring实战>(第四版),[美]Craig Walls著,张卫滨译 人民邮电出版社,2016.4 本系列博文包括: 第01章-Spring之旅 第02章-装配Bean 第03章 ...