题目地址: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. [洛谷P3195][HNOI2008]玩具装箱TOY

    题目大意:有n个物体,大小为$c_i$.把第i个到第j个放到一起,容器的长度为$x=j-i+\sum\limits_{k-i}^{j} c_k$,若长度为x,费用为$(x-L)^2$.费用最小. 题解 ...

  2. [国家集训队]Crash的数字表格 / JZPTAB 莫比乌斯反演

    ---题面--- 题解: $$ans = \sum_{i = 1}^{n}\sum_{j = 1}^{m}{\frac{ij}{gcd(i, j)}}$$ 改成枚举d(设n < m) $$ans ...

  3. Acunetix Web Vulnarability Scanner V10.5 详细中文手册

    目录: 0×00.什么是Acunetix Web Vulnarability Scanner ( What is AWVS?) 0×01.AWVS安装过程.主要文件介绍.界面简介.主要操作区域简介(I ...

  4. CMD批处理把txt文本中的每行写入一个新文件,第一列作文件名

    需求 现在有一个文件格式如图 ID 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17001 89.84 8.87 1.29 -0.0 0.0 68.99 0.0 0. ...

  5. ext radiogroup如何取值和设值

    var radios = Ext.create('Ext.form.Panel', { title: 'RadioGroup Example', width: 300, height: 125, bo ...

  6. Spring源码解析-AutowiredAnnotationBeanPostProcessor

    1.实现了BeanPostProcessor接口,可先看这个接口 ApplicationContext可以在自动检测BeanPostProcessor bean,在它创建完后可以创建任何的bean. ...

  7. eclipse+jetty+web项目调试---不显示源码

    本人eclipse版本:JUNO 1.问题现象:显示源码时,不显示箭头(指示到哪行) 解决办法: debug configurations  --->Goals设置参数  clean -X je ...

  8. GTK+与MFC不完全对比

    转载自:http://tech.ddvip.com/2007-11/119640973738229.html 1. 两者都是基于面向对象设计的.尽管MFC是用C++写的,而GTK+是用C写的,但思想都 ...

  9. js 读写文件

    读写文件: var f = fso.CreateTextFile("c:\\pexam\\"+name+".txt", true); f.write(arr); ...

  10. bzoj2683/4066 简单题

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2683 http://www.lydsy.com/JudgeOnline/problem.ph ...