题目地址: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. (补漏)Springboot2.0 集成shiro权限管理

    原文Springboot2.0 集成shiro权限管理 一.关于停止使用外键. 原本集成shiro建立用户.角色.权限表的时候使用了外键,系统自动创建其中两个关联表,用@JoinTable.看起来省事 ...

  2. BZOJ2337: [HNOI2011]XOR和路径 期望概率dp 高斯

    这个题让我认识到我以往对于图上期望概率的认识是不完整的,我之前只知道正着退还硬生生的AC做过的所有图,那么现在让我来说一下逆退,一般来说对于概率性的东西都只是正推,因为有了他爸爸才有了他,而对于期望性 ...

  3. More on understanding sort_buffer_size

    There have been a few posts by Sheeri and Baron today on the MySQL sort_buffer_size variable. I want ...

  4. inflate

    LayoutInflater是用 来找res/layout/下的xml布局文件,并且实例化 https://www.cnblogs.com/savagemorgan/p/3865831.html

  5. bzoj2424 [HAOI2010]订货 dp+单调性

    [HAOI2010]订货 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1311  Solved: 884[Submit][Status][Discu ...

  6. maven2应用之jar插件使用介绍

    [转载声明] 转载时必须标注:本文来源于铁木箱子的博客http://www.mzone.cc [本文地址] 本文永久地址是:http://www.mzone.cc/article/236.html 有 ...

  7. [USACO07FEB]新牛棚Building A New Barn

    洛谷题目链接:[USACO07FEB]新牛棚Building A New Barn 题目描述 After scrimping and saving for years, Farmer John has ...

  8. UVa11988 Broken Keyboard (a.k.a. Beiju Text)

    题目复制太麻烦了,甩个链接 http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18693 直接模拟光标操作时间复杂度较高,所以用链 ...

  9. MINA 网络黏包处理代码

    本文完整代码,可以浏览: https://github.com/hjj2017/xgame-code_server/blob/master/game_server/src/com/game/gameS ...

  10. 2017年上海金马五校程序设计竞赛:Problem C : Count the Number (模拟)

    Description Given n numbers, your task is to insert '+' or '-' in front of each number to construct ...