贪心
程序员文章站
2022-06-13 12:23:44
...
原文链接:https://ac.nowcoder.com/acm/problem/13228
AC代码:
#include<iostream>
#include<algorithm>
#include<iomanip>
using namespace std;
double T,C;
int n;
double p,k,maxt=0,mint=10000;
int main(){
int i,j;
cin>>n;
cin>>T>>C;
p=T*C;k=C;
for(i=0;i<n;i++){
cin>>T>>C;
p+=T*C;
k+=C;
if(T>maxt) maxt=T;
if(T<mint) mint=T;
}
double ave=p/k;
cout<<setiosflags(ios::fixed)<<setprecision(4);
if(ave>=maxt){
cout<<"Possible"<<endl;
cout<<ave<<endl;
}
else if(ave<=mint){
cout<<"Possible"<<endl;
cout<<mint<<endl;
}
else{
cout<<"Impossible"<<endl;
}
return 0;
}
上一篇: 切长条(贪心)
推荐阅读