贪心加高精

传送门: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. JavaScript中的一些小技巧

    js 数字操作:1.1 取整:取整有很多方法如: parseInt(a,10); Math.floor(a); a>>0; ~~a; a|0; 前面2种是经常用到的,后面3种算是比较偏的, ...

  2. 530.Minimum Absolute Difference in BST 二叉搜索树中的最小差的绝对值

    [抄题]: Given a binary search tree with non-negative values, find the minimum absolute difference betw ...

  3. tftp-hpa客户端使用说明

    1.板子 sudo apt-get install tftp-hpa 2.主机chmod 777 tftp—dir 3.tftp -4 192.168.1.122 -c put lib2.tar.gz ...

  4. 3d点云与cad模型

    https://stackoverflow.com/questions/19000096/match-3d-point-cloud-to-cad-model

  5. myeclipse工程中library 和 web-inf下lib的区别

    eclipse工程下的library是用来编译里面的src中java文件的实际发布到tomcat时,仅仅只复制了WEB-INF/lib里面的jar包,所以出现eclipse可以正常编译但tomcat运 ...

  6. JS中的唯一容器:数组

    JS中的唯一容器:数组 一.什么类型的数据都可以存储 二. 定义的方式有两种  1 .    var  arra=[];var  arra=[“a”,“b”,"c"];   2.v ...

  7. 白盒测试实践-任务进度-Day02

    所使用静态代码检查工具 阿里巴巴Java开发代码检测IDE插件 小组成员 华同学.郭同学.覃同学.刘同学.穆同学.沈同学 任务进度 在经过任务分配阶段后,大家都投入到了各自的任务中,以下是大家今天任务 ...

  8. Qt编译,imp_CommandLineToArgvW@8问题

    Tested msvc2013. The linker can not find _imp_CommandLineToArgvW@8. It's in shell32.lib. I see qtmai ...

  9. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'supplierAction': Injection of resource dependencies failed; nested exception is org.springframework.beans.factor

    这个错误是因为抽象Action类的时候,把ServletContext写成了serverContext,导致无法注入,正确写法是 import javax.annotation.Resource; i ...

  10. 编写高质量代码改善C#程序的157个建议——建议132:考虑用类名作为属性名

    建议132:考虑用类名作为属性名 一般来说,若果属性对应一个类型,应该直接用类型名命名属性名.如下: class Person { public Company Company { get; set; ...