luogu P1080国王游戏
发布日期:2022-02-22 18:04:12 浏览次数:8 分类:技术文章

本文共 3318 字,大约阅读时间需要 11 分钟。

贪心加高精

传送门:

先考虑两个人

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 k2

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

移项得:\(a1b1<a2b2\)

根据冒泡排序

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

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

然后就是麻烦的高精了

//自动无视c++14// luogu-judger-enable-o2#include
#include
#include
#include
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]
>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]

转载于:https://www.cnblogs.com/eric-walker/p/9535445.html

转载地址:https://blog.csdn.net/dengxingrao0615/article/details/102231332 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:C++类成员在内存中的存储及对齐方式
下一篇:P1979华容道(神仙题)

发表评论

最新留言

做的很好,不错不错
[***.243.131.199]2024年04月19日 04时06分11秒