Codeforces Round #481 (Div. 3) G. Petya's Exams
http://codeforces.com/contest/978/problem/G
感冒是真的受不了。。。敲代码都没力气。。。
题目大意:
期末复习周,一共持续n天,有m场考试
每场考试有如下信息:
①si表示知道第i门课的考试时间是在第si天的时候
②di表示第i门课的考试时间
③ci表示准备第i门课需要ci天的复习
在考试的那一天不能复习。
问n天中每一天都需要干啥?
三种情况,休息(输出0),复习(输出复习那一门科目的id),考试(输出m+1)
思路:按照di排序(即按照截止时间),然后反过来暴力扫一遍,对于s(i)大的我们进行优先复习,所以优先队列维护一下si即可
//看看会不会爆int!数组会不会少了一维!
//取物问题一定要小心先手胜利的条件
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker,"/STACK:102400000,102400000")
#define LL long long
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define haha printf("haha\n")
const int maxn = 1e3 + ;
vector<int> day[maxn];
int n, m;
int d[maxn], s[maxn], c[maxn];
int ans[maxn]; bool solve(){
memset(ans, -, sizeof(ans));
for (int i = ; i <= m; i++){
day[d[i]].pb(i);
ans[d[i]] = m + ;
}
priority_queue<pair<int, pair<int, int> > > que;
for (int i = n; i >= ; i--){
if (day[i].size() > ){
for (int j = ; j < day[i].size(); j++){
int p = day[i][j];
que.push(mk(s[p], mk(c[p], p)));
}
}
if (ans[i] != -) continue;
if (que.empty()){///休息
ans[i] = ;
continue;
}
int spos = que.top().fi;
int restday = que.top().se.fi;
int pos = que.top().se.se;
que.pop();
if (spos > i && restday > ) return false;
restday--;
ans[i] = pos;
if (restday == ){
continue;
}
que.push(mk(spos, mk(restday, pos)));
}
if (!que.empty()) return false;
for (int i = ; i <= n; i++){
printf("%d ", ans[i]);
}
cout << endl;
return true;
} int main(){
cin >> n >> m;
for (int i = ; i <= m; i++){
scanf("%d%d%d", s + i, d + i, c + i);
}
if (solve() == false) puts("-1");
return ;
}
Codeforces Round #481 (Div. 3) G. Petya's Exams的更多相关文章
- Codeforces Round #481 (Div. 3) G. Petya's Exams (贪心,模拟)
题意:你有\(n\)天的时间,这段时间中你有\(m\)长考试,\(s\)表示宣布考试的日期,\(d\)表示考试的时间,\(c\)表示需要准备时间,如果你不能准备好所有考试,输出\(-1\),否则输出你 ...
- Codeforces Round #582 (Div. 3)-G. Path Queries-并查集
Codeforces Round #582 (Div. 3)-G. Path Queries-并查集 [Problem Description] 给你一棵树,求有多少条简单路径\((u,v)\),满足 ...
- Codeforces Round #481 (Div. 3)
我实在是因为无聊至极来写Div3题解 感觉我主要的作用也就是翻译一下题目 第一次线上打CF的比赛,手速很重要. 这次由于所有题目都是1A,所以罚时还可以. 下面开始讲题 A.Remove Duplic ...
- Codeforces Round #547 (Div. 3) G 贪心
https://codeforces.com/contest/1141/problem/G 题意 在一棵有n个点的树上给边染色,连在同一个点上的边颜色不能相同,除非舍弃掉这个点,问最少需要多少种颜色来 ...
- Codeforces Round #541 (Div. 2) G dp + 思维 + 单调栈 or 链表 (连锁反应)
https://codeforces.com/contest/1131/problem/G 题意 给你一排m个的骨牌(m<=1e7),每块之间相距1,每块高h[i],推倒代价c[i],假如\(a ...
- Codeforces Round #346 (Div. 2) G. Fence Divercity dp
G. Fence Divercity 题目连接: http://www.codeforces.com/contest/659/problem/G Description Long ago, Vasil ...
- Codeforces Round #481 (Div. 3) 全题解
A题,题目链接:http://codeforces.com/contest/978/problem/A 解题心得:题意就是让你将这个数列去重,重复的数只保留最右边的那个,最后按顺序打印数列.set+m ...
- Codeforces Round #677 (Div. 3) G. Reducing Delivery Cost(dijkstra算法)
题目链接:https://codeforces.com/contest/1433/problem/G 题解 跑 \(n\) 遍 \(dijkstra\) 得到任意两点间的距离,然后枚举哪一条边权为 \ ...
- Codeforces Round #481 (Div. 3)Petya's Exams CodeForces - 978G
Petya studies at university. The current academic year finishes with nn special days. Petya needs to ...
随机推荐
- 基于.NET的3D开发框架/工具比较
好久木有写博客了,这么日子以来忙忙碌碌的,也没大有时间潜心学习和梳理.最近刚好接手一个3D显示的活,虽然还没怎么弄明白,但是也看过一些方案,走了一些弯路,经过一些浅显的了解(3D Display这里面 ...
- Asp.net MVC Razor常见问题及解决方法(转载>云中客)
没有经验的童鞋就是这样磕磕碰碰出来的经验. 1,Datatype的错误提示消息无法自定义 这也许是Asp.net MVC的一个Bug.ViewModel中定义了DataType为Date字段: 1 2 ...
- From today 2019.02.27
HIT开设软件构造课程,需要在博客上分享记录学习体验,感觉还是挺好的. 以后会不定期更新一些关于学下java的笔记和实验相关的内容.
- 详细聊聊k8s deployment的滚动更新(一)
一.知识准备 ● 本文详细探索deployment在滚动更新时候的行为 二.环境准备 组件 版本 OS Ubuntu 18.04.1 LTS docker 18.06.0-ce 三.准备镜像 首先准备 ...
- Scalable Object Detection using Deep Neural Networks译文
原文:https://arxiv.org/abs/1312.2249
- 软件工程实践-git的使用
² Github使用心得 其实以前就注册过一个github账号,不过那时只不过是因为在网上看到这个挺对于程序员有着重大作用就顺手去弄了,从未使用过,直到这次软工实践需要我才从新回想起来. 之前的几篇随 ...
- Alpha冲刺第9天
Alpha第9天 1.团队成员 郑西坤 031602542 (队长) 陈俊杰 031602504 陈顺兴 031602505 张胜男 031602540 廖钰萍 031602323 雷光游 03160 ...
- C语言入门:01.C语言概述
一.计算机和软件常识 1.计算机运行原理 (1)硬件基本组成:硬盘.内存.CPU (2)个部件之间的运作协调(下图)
- 新安装的Ubuntu设置root密码
一.问题描述 新安装的Ubuntu切换到root用户时如果没有设置root用户密码会操作失败.此时需要先设置root用户密码. 二.解决办法 打开终端执行 sudo passwd 命令. 输入设置的密 ...
- Torch,Tensorflow使用: Ubuntu14.04(x64)+ CUDA8.0 安装 Torch和Tensorflow
系统配置: Ubuntu14.04(x64) CUDA8.0 cudnn-8.0-linux-x64-v5.1.tgz(Tensorflow依赖) Anaconda 1. Torch安装 Torch是 ...