本文主要是介绍kotori的设备--二分答案,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Luogu 3743
题目分析:
- 如果机器每秒总的消耗 < = p <=p <=p,则输出 − 1 -1 −1
- 二分时间,注意 r = 1 0 10 , e p s = 1 0 − 6 r=10^{10},eps=10^{-6} r=1010,eps=10−6
- 求出充电宝能充的总能量 p d c pdc pdc,对于一个机器能量不够就给它充,最后判断 p d c pdc pdc是否小于 0 0 0
Code:
#include <bits/stdc++.h>
using namespace std;
#define eps 1e-6
#define maxn 100010int n;
double sum=0,m,a[maxn],b[maxn];inline int read_() {int x=0,f=1;char c=getchar();while(c<'0'||c>'9') {if(c=='-') f=-1;c=getchar();}while(c>='0'&&c<='9') {x=(x<<1)+(x<<3)+c-'0';c=getchar();}return x*f;
}inline bool check_(double x) {double pdc=x*m;double AKIOI;for(int i=1;i<=n;++i) {if(pdc<0) return false;AKIOI=a[i]*x;if(AKIOI<=b[i]) continue;else {AKIOI-=b[i];pdc-=AKIOI;}}if(pdc>=0) return true;else return false;
}void readda_() {n=read_();scanf("%lf",&m);for(int i=1;i<=n;++i) {scanf("%lf%lf",&a[i],&b[i]);sum+=a[i];}if(m>=sum) printf("-1");else {double l=0,ans,r=10000000000,mid;while(r-l>eps) {mid=(l+r)/2;if(check_(mid)) {l=mid;ans=mid;}else r=mid;} printf("%.10lf",ans);}
}int main() {freopen("a.txt","r",stdin);readda_();return 0;
}
这篇关于kotori的设备--二分答案的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!