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 ...
随机推荐
- python模块详解 | progressbar
参考官方文档:https://pypi.org/project/progressbar/#description progressbar 安装: pip install progressbar pro ...
- 十二:SQL注入之简要注入
SQL注入漏洞将是重点漏洞,分为数据库类型,提交方法,数据类型等方式.此类漏洞是WEB漏洞中的核心漏洞,学习如何的利用,挖掘,和修复是重要的. SQL注入的危害 SQL注入的原理 可控变量,带入数据库 ...
- java8 stream api流式编程
java8自带常用的函数式接口 Predicate boolean test(T t) 传入一个参数返回boolean值 Consumer void accept(T t) 传入一个参数,无返回值 F ...
- 怎么判断是旧版本的ext3还是新版本?
怎么判断是旧版本的ext3还是新版本的? ---高性能419
- 【Zabbix】配置zabbix agent向多个server发送数据
1.背景: server端: 172.16.59.197 ,172.16.59.98 agent 端: hostname:dba-test-hzj02 IP:172.16.59.98 2.方式: 配 ...
- 【Oracle LISTNER】oracle Listener 宕机解决办法
今天想起了很久没用的oracle库,用plsql尝试连接,发现报超时错误,以为是偶然,多次尝试连接,发现还是超时,于是登录到系统中,查看数据库情况,发现正常查询和修改添加,感觉不是数据库问题,查看监听 ...
- STL_deque容器
一.deque简介 deque是"double-ended queue"的缩写,和vector一样都是STL的容器,deque是双端数组,而vector是单端的. deque在接口 ...
- 基于go-cqhttp实现QQ机器人
本篇文章记录一下自己在编写QQ机器人的时候所遇到的一些问题和核心功能的实现. QQ机器人RabbitBot采用python编写,由于是个人学习使用,故目前不会开源完整代码,只会放出核心代码供学习参考. ...
- 【python刷题】LRU
什么是LRU? LRU是Least Recently Used的缩写,即最近最少使用,是一种常用的页面置换算法,选择最近最久未使用的页面予以淘汰.该算法赋予每个页面一个访问字段,用来记录一个页面自上次 ...
- Connection reset by peer的常见原因及解决办法 RST 大文件上传
Connection reset by peer的常见原因及解决办法 Connection reset by peer的常见原因 - 简书 https://www.jianshu.com/p/263e ...