Codeforces 1039A. Timetable
Posted wa007
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces 1039A. Timetable相关的知识,希望对你有一定的参考价值。
题目地址: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 asfdasdasdfasdfasfdfasfsdfasfdas mt19937 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 "); 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 "); exit(0); } i=j; } printf("Yes "); for(ll i=1;i<=n;i++)printf("%I64d%c",b[i],i==n?‘ ‘:‘ ‘); return 0; }
以上是关于Codeforces 1039A. Timetable的主要内容,如果未能解决你的问题,请参考以下文章