码迷,mamicode.com
首页 > Web开发 > 详细

Codeforces 1039A. Timetable

时间:2018-09-06 21:32:46      阅读:335      评论:0      收藏:0      [点我收藏+]

标签: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 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\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

标签:count   freopen   color   大于   col   double   sdfsdf   max   def   

原文地址:https://www.cnblogs.com/wa007/p/9600994.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!