为什么wa了一个点 第17 求大佬救命
查看原帖
为什么wa了一个点 第17 求大佬救命
103226
BeautifulWater楼主2021/1/25 10:13
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
int n,p;
double r=1e10,l=0;
int consume[100005],store[100005];//极端情况全部都没有储存 
bool check(double x)
{
	int i;
    double judge=x*p;
	
	double total=0;
	for(i=0;i<n;i++)
	{
		if(x*consume[i]<=store[i])
		   continue;
		   
		else
		{
			total=total+x*consume[i]-store[i];
			
			if(total>=p*x)
			{
				return 1;
			}
			  
	    }   
	   
	} 
	return 0; 
}

int main()
{
	int i;double totalconsume=0;
	cin>>n>>p;
	for(i=0;i<n;i++)
	{
		cin>>consume[i]>>store[i];
		totalconsume+=consume[i];
    }
    if(totalconsume<p)
    {
    	cout<<-1;
    	return 0;
	}
    
    double mid,ans;
    
    while(r-l>1e-6)//大于小于指的是双开区间 ,实数没差 
    {
    	mid=l+((r-l)/2);
    	//cout<<l<<"  "<<mid<<"  "<<r<<endl;
    	if(check(mid))
    	{
     		r=mid;
		}
		else
		{
			l=mid; 
		}
	}
	printf("%.10lf",r);
	return 0;
 } 
2021/1/25 10:13
加载中...