题目地址: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[][]={{,},{,-},{,},{-,}};
const int mod=1e9+;
const int maxn=2e5+;
const int maxm=1e5+;
const double eps=1e-;
ll m,n;
ll ar[maxn];
ll b[maxn];
int x[maxn];
int main()
{
scanf("%I64d%I64d",&n,&m);
for(int i=;i<=n;i++)scanf("%I64d",&ar[i]);
for(int i=;i<=n;i++)scanf("%d",&x[i]);
for(int i=;i<=n;i++){
if(x[i]<x[i-] || x[i]<i){
printf("No\n");
exit();
}
}
int i=;
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+]+m;
else b[k]=max(b[k-]+, ar[k]+m);
//cout<<k<<" "<<b[k]<<endl;
}
if(x[j-]!=j-|| (j-<n && b[j-]>=ar[j]+m)){
printf("No\n");
exit();
}
i=j;
}
printf("Yes\n");
for(ll i=;i<=n;i++)printf("%I64d%c",b[i],i==n?'\n':' '); return ;
}

Codeforces 1039A. Timetable的更多相关文章

  1. Codeforces 946D - Timetable (预处理+分组背包)

    题目链接:Timetable 题意:Ivan是一个学生,在一个Berland周内要上n天课,每天最多会有m节,他能逃课的最大数量是k.求他在学校的时间最小是多少? 题解:先把每天逃课x节在学校呆的最小 ...

  2. Codeforces 946D Timetable(预处理+分组背包)

    题目链接:http://codeforces.com/problemset/problem/946/D 题目大意:有n个字符串,代表n天的课表,1表示这个时间要上课,0表示不要上课,一天在学校时间为第 ...

  3. [Codeforces 946D]Timetable

    Description 题库链接 给你一个 \(N\times M\) 的 \(01\) 矩阵,你可以从中将一些 \(1\) 变为 \(0\) ,最多 \(K\) 次.使操作之后使得每行最远的 \(1 ...

  4. 2018.12.08 codeforces 946D. Timetable(背包)

    传送门 题意简述:有一个人上n天课,每天有m个小时的时间安排表(一个01串),为1表示要上课,否则不上课,求出如果可以最多翘kkk节课这nnn天在校待的总时间的最小值(一天必须在所有课上完后才能离开) ...

  5. CodeForces 946D Timetable (DP)

    题意:给定 n,m,K,表示某个人一个周有 n 天,每天有 m 节课,但是他可以跳过 K 节课,然后下面每行一个长度为 m 个01字符串,0 表示该人在这一小时没有课,1 表示该人在这一个小时有课,每 ...

  6. CodeForces - 946D Timetable (分组背包+思维)

    题意 n天的课程,每天有m个时间单位.若时间i和j都有课,那么要在学校待\(j-i+1\)个时间.现在最多能翘k节课,问最少能在学校待多少时间. 分析 将一天的内容视作一个背包的组,可以预处理出该天内 ...

  7. cf946d 怎样逃最多的课dp

    来源:codeforces                                              D. Timetable Ivan is a student at Berland ...

  8. #分组背包 Educational Codeforces Round 39 (Rated for Div. 2) D. Timetable

    2018-03-11 http://codeforces.com/contest/946/problem/D D. Timetable time limit per test 2 seconds me ...

  9. Codeforces 37D Lesson Timetable - 组合数学 - 动态规划

    题目传送门 神奇的门I 神奇的门II 题目大意 有$n$组学生要上课2次课,有$m$个教室,编号为$1$到$m$.要确定有多少种不同的安排上课的教室的方案(每组学生都是本质不同的),使得它们满足: 每 ...

随机推荐

  1. hdu3068最长回文(Manacher算法)

    简单来说这是个很水的东西.有点dp的思想吧.推荐两个博客,很详细. http://blog.csdn.net/xingyeyongheng/article/details/9310555 http:/ ...

  2. table表头固定问题

    table表头固定问题 原生的table表头在表格滚动时候无法固定,可以使用以下的方法进行模拟 1. 双table法 表头和表体各用一个table,这样会产生表格列对不齐的问题,可以使用colgrou ...

  3. bzoj

    准确率爆棚啊,然而

  4. git使用笔记(四)远程操作

    By francis_hao    Nov 19,2016 以一张图说明远程操作,图片来自参考[2] git clone 从远端主机克隆一个版本库,若省略directory则生成一个和远端同名的版本库 ...

  5. HDU3488:Tour(KM算法)

    Tour Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submis ...

  6. 使用Word2010发布博客文章

    发布博客可以直接在web页面上面编辑,也可以使用客户端编辑,其中客户端支持windows live writer以及word本身的发布博客功能.个人试用后倾向于使用word发布博客文章. 下面的内容转 ...

  7. HDU2177取(2堆)石子游戏---(威佐夫博弈)

    http://acm.hdu.edu.cn/showproblem.php?pid=2177 取(2堆)石子游戏 Time Limit: 3000/1000 MS (Java/Others)    M ...

  8. 【Foreign】染色 [LCT][线段树]

    染色 Time Limit: 20 Sec  Memory Limit: 256 MB Description Input Output Sample Input 13 0 1 0 2 1 11 1 ...

  9. c:forEach 如何输出序号

    关键在于<c:forEach>的varStatus属性,具体代码如下: <table width="500" border="0" cells ...

  10. Python用户登陆

    #!/usr/bin/env python # _*_ coding:UTF-8 _*_ # __auth__:Dahlhin import sys userinfo = r'userinfo.txt ...