標籤: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