Codeforces 1039A. Timetable

來源:互聯網
上載者:User

標籤:count   freopen   color   大於   col   double   sdfsdf   max   def   

題目地址:http://codeforces.com/problemset/problem/1039/A

 

題目的關鍵在於理清楚思路,然後代碼就比較容易寫了

 

對於每一個位置的bus,即對於每一個i(i>=1 && i<=n) ,x[i]必然大於等於 i ,假設第 i 個車可以停在 x[i] 處,則對於j(j>i && j<=x[i]) 令車j停在j-1處,即b[j-1]>=ar[j]+t

如果x[x[i]]==x[i],只需控制讓b[x[i]]<ar[x[i]+1]+t即可

如果x[x[i]]!=x[i],則x[x[i]]>x[i],則必然有b[x[i]]>=ar[x[i]+1]+t,讓x[i]+1個車停在x[i]處,以讓x[i]停在x[x[i]]處;由此可以知,i也可以停在x[x[i]]處,與題意相悖,輸出No即可

 

 

 

#include<iostream>#include<cstdio> #include<cmath>#include<queue>#include<vector>#include<string.h>#include<cstring>#include<algorithm>#include<set>#include<map>#include<fstream>#include<cstdlib>#include<ctime>#include<list>#include<climits>#include<bitset>#include<random>#include <ctime>#include <cassert>#include <complex>#include <cstring>#include <chrono>using namespace std;#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);#define fopen freopen("input.in", "r", stdin);freopen("output.in", "w", stdout);#define left asfdasdasdfasdfsdfasfsdfasfdas1#define tan asfdasdasdfasdfasfdfasfsdfasfdasmt19937 rng(chrono::steady_clock::now().time_since_epoch().count());typedef long long ll;typedef unsigned int un;const int desll[4][2]={{0,1},{0,-1},{1,0},{-1,0}};const int mod=1e9+7;const int maxn=2e5+7;const int maxm=1e5+7;const double eps=1e-4;ll m,n;ll ar[maxn];ll b[maxn];int x[maxn];int main(){    scanf("%I64d%I64d",&n,&m);    for(int i=1;i<=n;i++)scanf("%I64d",&ar[i]);    for(int i=1;i<=n;i++)scanf("%d",&x[i]);    for(int i=2;i<=n;i++){        if(x[i]<x[i-1] || x[i]<i){            printf("No\n");            exit(0);        }    }    int i=1;    while(i<=n)    {        int j=i;        while(j<=n && x[j]==x[i]){            j++;        }        for(int k=i;k<j;k++){            if(x[k]>k)b[k]=ar[k+1]+m;            else b[k]=max(b[k-1]+1, ar[k]+m);            //cout<<k<<" "<<b[k]<<endl;        }        if(x[j-1]!=j-1|| (j-1<n && b[j-1]>=ar[j]+m)){            printf("No\n");            exit(0);        }        i=j;    }    printf("Yes\n");    for(ll i=1;i<=n;i++)printf("%I64d%c",b[i],i==n?‘\n‘:‘ ‘);    return 0;}

 

Codeforces 1039A. Timetable

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.