Codeforces Round #481 (Div. 3) G. Petya's Exams (贪心,模拟)
题意:你有\(n\)天的时间,这段时间中你有\(m\)长考试,\(s\)表示宣布考试的日期,\(d\)表示考试的时间,\(c\)表示需要准备时间,如果你不能准备好所有考试,输出\(-1\),否则输出你每天都在干什么,如果这一天你有考试,输出\(m+1\),如果你要准备第\(i\)场考试,输出\(i\),否则休息,输出\(0\).
题解:数据范围小,直接模拟,但我们需要先贪心,即每次都要先准备最早的考试,然后直接写两个\(for\)循环就行了.
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<long,long> PLL; int n,m;
struct S{
int s,d,c;
}p[N];
int ans[N];
int main() {
ios::sync_with_stdio(false);cin.tie(0);
cin>>n>>m;
for(int i=1;i<=m;++i){
cin>>p[i].s>>p[i].d>>p[i].c;
} for(int i=1;i<=n;++i){
int cnt=-1;
int mi=n+1;
for(int j=1;j<=m;++j){
if(p[j].d==i) ans[i]=m+1;
if(p[j].s<=i && p[j].d>i && p[j].c>0 && (p[j].d<mi)){
mi=p[j].d;
cnt=j;
}
}
if(ans[i]==0 && cnt!=-1) ans[i]=cnt,p[cnt].c--;
}
for(int i=1;i<=m;++i){
if(p[i].c>0){
puts("-1");
return 0;
}
}
for(int i=1;i<=n;++i){
printf("%d ",ans[i]);
} return 0;
}
Codeforces Round #481 (Div. 3) G. Petya's Exams (贪心,模拟)的更多相关文章
- Codeforces Round #481 (Div. 3) G. Petya's Exams
http://codeforces.com/contest/978/problem/G 感冒是真的受不了...敲代码都没力气... 题目大意: 期末复习周,一共持续n天,有m场考试 每场考试有如下信息 ...
- Codeforces Round #425 (Div. 2) B. Petya and Exam(字符串模拟 水)
题目链接:http://codeforces.com/contest/832/problem/B B. Petya and Exam time limit per test 2 seconds mem ...
- Codeforces Round #373 (Div. 2) A B C 水 贪心 模拟(四舍五入进位)
A. Vitya in the Countryside time limit per test 1 second memory limit per test 256 megabytes input s ...
- Codeforces Round #280 (Div. 2) C. Vanya and Exams 贪心
C. Vanya and Exams Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/492/pr ...
- Codeforces Round #550 (Div. 3) D. Equalize Them All (贪心,模拟)
题意:有一组数,可以选择某个数\(a_i\)相邻的一个数\(a_j\),然后可以让\(a_i\)加上或者减去\(|a_i-a_j|\),问最少操作多少次使得数组中所有数相同. 题解:不难发现,每次操作 ...
- Codeforces Round #656 (Div. 3) C. Make It Good (贪心,模拟)
题意:给你一个数组\(a\),可以删除其前缀,要求操作后得到的数组是"good"的.对于"good":可以从数组的头和尾选择元素移动到新数组,使得所有元素移动后 ...
- 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 #297 (Div. 2)C. Ilya and Sticks 贪心
Codeforces Round #297 (Div. 2)C. Ilya and Sticks Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
随机推荐
- 【Docker】安装docker18.09.6后,无法启动
------------------------------------------------------------------------------------------------- | ...
- Poj-P2533题解【动态规划】
本文为原创,转载请注明:http://www.cnblogs.com/kylewilson/ 题目出处: http://poj.org/problem?id=2533 题目描述: 如果ai1 < ...
- IP2188中文资料书
IP2188 是一款集成 12 种.用于 USB 输出端口的快充协议 IC,支持 USB 端口充电协议.支持 11种快充协议,包括 USB TypeC PD2.0/PD3.0/PPS DFP,HVDC ...
- Java 迭代器的使用 Iterator
Java的集合类可以使用for ... each循环 List Set Queue Deque 我们以List为例 其实一个java编译器并不知道如何遍历一个List 编译器只是把一个for ... ...
- three.js cannon.js物理引擎地形生成器和使用指针锁定控件
今天郭先生说一说使用cannon.js物理引擎绘制地形和使用指针锁定控件.效果如下图.线案例请点击博客原文. 这里面的生成地形的插件和指针锁定控件也是cannon.js的作者schteppe封装的,当 ...
- scrapy异步的爬虫框架简单的使用
scrapy异步的爬虫框架 异步的爬虫框架 高性能的数据解析,持久化存储,全栈数据的爬取,中间件,分布式 框架:就是一个集成好了各种功能且具有很强通用性的一个项目模板. 环境安装: Linux: pi ...
- uwsgi 启动django
1, django 官方文档可配置项如下: 2,启动django 的配置: 1,和settings.py 同级目录下新建wsgi.py (该配置和manager.py 的配置基本是一样的) impo ...
- C#高级编程第11版 - 第八章 索引
[1]8.1 引用方法 1.委托是指向方法的.NET地址变量. 2.委托是类型安全的类,定义了返回类型和参数类型.委托类不单单只包含一个方法引用,它也可以保存多个方法的引用. 3.Lambda表达式直 ...
- error out of table range
.
- chmod a+w . 权限控制 su、sudo 修改文件所有者和文件所在组 添加用户到sudoer列表中 当前用户信息
对当前目录对所有用户开放读写权限 chmod a+r . $ sudo chmod -R a+w /usr/lib/python2.7 所有用户添加文件的写权限 [linux]su.sudo.sudo ...