Codeforces Round #409 Div.2(C. Voltage Keepsake) 2점
5446 단어 Codeforces
The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.
You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.
You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Input The first line contains two integers, n and p (1 ≤ n ≤ 100 000, 1 ≤ p ≤ 109) — the number of devices and the power of the charger.
This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≤ ai, bi ≤ 100 000) — the power of the device and the amount of power stored in the device in the beginning.
Output If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4.
Namely, let’s assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if .
Examples input 2 1 2 2 2 1000 output 2.0000000000 input 1 100 1 1 output -1 input 3 5 4 3 5 2 6 1 output 0.5000000000 Note In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.
In sample test 2, you can use the device indefinitely.
In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second. n개의 전기 기구.초당 P를 충전하는 충전기모든 전기 제품의 소모 속도와 현재 전량을 제시하다.그 중 한 기계가 전기를 다 쓰기 전에 최대 얼마나 걸리느냐고 물었다.문제풀이: 2분 동안 가능한지 아닌지를 판단하고 소수 2분은 횟수를 판단하는 방법이 좋다!상계가 충분해야 한다는 것을 주의해라.코드:
#include
#include
#include
#include
#define ll long long
using namespace std;
int cnt;
int n;
double m;
struct node
{
double x,y;
}a[100100];
int solve(double mid)
{
double mx=mid*m;
for(int i=1;i<=n;i++)
{
double q=a[i].x*mid;
q-=a[i].y;
if(q<=0) continue;
if(mx>=q)
{
mx-=q;
}
else
{
return 0;
}
}
return 1;
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>a[i].x>>a[i].y;
cnt=0;
double ans=-1;
double l=0;
double r=100000000005;
while(cnt<=150)
{
cnt++;
double mid=(l+r)/2;
if(solve(mid))
{
l=mid;
ans=mid;
}
else r=mid;
}
if(ans>=10000000005) printf("-1
");
else
printf("%.9lf
",ans);
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Codeforces 1287C Garland제목 링크:Codeforces 1287C Garland 사고방식: 우리기dp[i][j][0]와 dp[i][j][1]는 각각 i개가 홀수/짝수이고 앞의 i개 안에 j개의 짝수가 있는 상황에서 i개의 최소 복잡도.첫 번...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.