Codeforces round #380 (Div. 2) C. Road to cinema binary

Source: Internet
Author: User
Question:

1. Give you N vehicles, K gas stations, S-route, within T seconds

2. There are two modes for all vehicles: 1 km/min and 1 km/2 min. The fuel consumption is 2/km and 1/km.

3. Each vehicle has a price and a tank capacity. When passing through a gas station, gasoline can be filled with blood instantly. Find the cheapest car.

Ideas:

1. Write a bool function judge to judge whether the vehicle spends the minimum time mint. If mint <= t, the system returns true. Use a gas station to group the routes, find the mints for each group, and accumulate them.

2. There are three cases of DIS in each group:

A. The tank capacity feul <DIS, which indicates that the slow speed is too big. Return false;

B. Tank Capacity fuel> = 2 * Dis, indicating that the tank can be reached directly at a high speed. The speed is 1 km/min, so mint + = DIS;

C. The tank capacity is between AB and use high speed as much as possible. High speed X km, low speed y km.

X + y = DIS, 2x + Y <= feul.

Obtain the value of X <= fuel-Dis, that is, the maximum value of X is fuel-dis. Mint + = x + 2 * Y.

3. The maximum tank volume in the vehicle maxcompute uses judge once. If not, output-1 directly. Otherwise, the minimum tank capacity (0, maxfuel) that can be reached on time is obtained.

4. Scan the car. If the capacity of the car is greater than the minimum capacity, Res = min (Res, car [I]. cost );

The Code is as follows:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 #include<iostream>#include<algorithm>#include<cstdio>using namespace std;const int maxn=200200;struct Car{    int cost, fuel;}car[maxn];int gas[maxn];bool judge(int fuel,int k,int t){    /*        x+y=dis        2x+y<=fuel        so x<=fuel-dis        x represent the distance with high speed, y ...    */    int i,j;    int mint=0;    for(i=1;i<=k+1;i++)    {        int dis=gas[i]-gas[i-1];        if(fuel<dis)            return false;        else if(fuel>=2*dis)            mint+=dis;        else        {            int x=fuel-dis;            int y=dis-x;            mint+=x+2*y;        }    }    return mint<=t;}int main(){    int n,k,s,t,i,j;    scanf("%d%d%d%d",&n,&k,&s,&t);    int maxfuel=-1;    for(i=1;i<=n;i++)        scanf("%d%d",&car[i].cost,&car[i].fuel),        maxfuel=max(maxfuel,car[i].fuel);    for(i=1;i<=k;i++)        scanf("%d",&gas[i]);    sort(gas+1,gas+k+1);    gas[0]=0;    gas[k+1]=s;    if(!judge(maxfuel,k,t))    {        printf("-1\n");        return 0;    }    int low,high;    low=0,high=maxfuel;    while(low    {        int mid=low+high >> 1;        if(judge(mid,k,t))            high=mid;        else            low=mid+1;    }    int res=2e9+5;    for(i=1;i<=n;i++)        if(car[i].fuel>=low)            res=min(res,car[i].cost);    printf("%d\n",res);}    

Codeforces round #380 (Div. 2) C. Road to cinema binary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.