中国大学生计算机系统与程序设计竞赛 CCF-CCSP-2017 串行调度(serial)
串行调度(serial)

除等价条件, 根据题意设置限制条件,然后求字典序最小拓扑序。
简洁版
#include<bits/stdc++.h>
using namespace std;
const int N=2e4+;
const int M=2e4+;
const int E=8e5+;
template <typename T>
inline void read(T &x){
T f=;char ch=getchar();x=;
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
x*=f;
}
vector<int>lastR[N];int lastW[N];
bitset<M>d[M];
int n,m,pcnt,qcnt,tot,ind[M],to[E],nxt[E],head[M];
inline void add(int x,int y){
if(!x||x==y) return ;
ind[y]++;
to[++tot]=y;nxt[tot]=head[x];head[x]=tot;
}
inline void init(){
read(n);read(m);read(pcnt);read(qcnt);
for(int i=,op,xk,tk;i<=pcnt;i++){
read(op);read(xk);read(tk);
if(op){
if(!lastR[xk].empty()){
for(auto &i:lastR[xk]) add(i,tk);
lastR[xk].clear();
}
else{
add(lastW[xk],tk);
}
lastW[xk]=tk;
}
else{
add(lastW[xk],tk);
lastR[xk].push_back(tk);
}
}
}
priority_queue<int,vector<int>,greater<int> >q;
inline void topo(){
d[]=;
for(int i=;i<=m;i++) d[i]=d[i-]<<;
for(int i=;i<=m;i++) if(!ind[i]) q.push(i);
for(int i=;i<=m;i++){
int x=q.top();q.pop();
printf("%d ",x);
for(int j=head[x];j;j=nxt[j]){
if(!--ind[to[j]]){
q.push(to[j]);
}
d[to[j]]|=d[x];
}
}
puts("");
for(int i=qcnt,x,y;i;i--){
read(x);read(y);
puts(!d[x].test(y)?"YES":"NO");
}
}
int main(){
init();
topo();
return ;
}
纯手写bitset
#include<queue>
#include<vector>
#include<cstdio>
using std::vector;
using std::priority_queue;
const int N=2e4+;
const int M=2e4+;
const int E=8e5+;
template <typename T>
inline void read(T &x){
T f=;char ch=getchar();x=;
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
x*=f;
}
vector<int>lastR[N];int lastW[N];
struct BitSet{//模拟bitset
// unsigned int 以压缩32位
// unsigned long long 可以压缩64位
const static int N = M / + ;
unsigned data[N];
unsigned& operator[](int a){
return data[a];
}
const unsigned& operator[](int a)const{
return data[a];
}
bool get(int a){
return (data[a >> ] >> (a & )) & ;
}
void set(int a){
data[a >> ] |= << (a & );
}
void unset(int a){
data[a >> ] &= ~( << (a & ));
}
BitSet& operator|=(const BitSet& a){
for(int i = ; i < N; i++)
data[i] |= a[i];
return *this;
}
}used[M];
int n,m,pcnt,qcnt,tot,ind[M],to[E],nxt[E],head[M];
inline void add(int x,int y){
if(!x||x==y) return ;
ind[y]++;
to[++tot]=y;nxt[tot]=head[x];head[x]=tot;
}
inline void init(){
read(n);read(m);read(pcnt);read(qcnt);
for(int i=,op,xk,tk;i<=pcnt;i++){
read(op);read(xk);read(tk);
if(op){
if(!lastR[xk].empty()){
for(auto &i:lastR[xk]) add(i,tk);
lastR[xk].clear();
}
else{
add(lastW[xk],tk);
}
lastW[xk]=tk;
}
else{
add(lastW[xk],tk);
lastR[xk].push_back(tk);
}
}
}
priority_queue<int,vector<int>,std::greater<int> >q;
inline void topo(){
for(int i=;i<=m;i++) used[i].set(i);
for(int i=;i<=m;i++) if(!ind[i]) q.push(i);
for(int i=;i<=m;i++){
int x=q.top();q.pop();
printf("%d ",x);
for(int j=head[x];j;j=nxt[j]){
if(!--ind[to[j]]){
q.push(to[j]);
}
used[to[j]]|=used[x];
}
}
puts("");
for(int i=qcnt,x,y;i;i--){
read(x);read(y);
puts(!used[x].get(y)?"YES":"NO");
}
}
int main(){
init();
topo();
return ;
}
中国大学生计算机系统与程序设计竞赛 CCF-CCSP-2017 串行调度(serial)的更多相关文章
- 中国大学生计算机系统与程序设计竞赛 CCF-CCSP-2016 选座( ticket_chooser )
选座( ticket_chooser ) 不会正解,欢迎讨论 //60分 #include<cstdio> #define max(a,b) (a)>(b)?a:b #define ...
- “知乎杯”2018 CCF 大学生计算机系统与程序设计竞赛 分组加密器(encryption)
分组加密器(encryption) 题解点这里 #include<map> #include<stack> #include<vector> #include< ...
- “知乎杯”2018 CCF 大学生计算机系统与程序设计竞赛 贪心算法(greedy)
--> 贪心算法 1)题解 • 分别用V0.V1和V>=2表示度为0.1以及至少为2的顶点集合 • 对于每个顶点,维护三个属性: • degree ...
- “知乎杯”2018 CCF 大学生计算机系统与程序设计竞赛 绝地求生(battleground)
/* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-ts ...
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 题目9 : Minimum
时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 You are given a list of integers a0, a1, …, a2^k-1. You need t ...
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 i题 Minimum(线段树)
描述 You are given a list of integers a0, a1, …, a2^k-1. You need to support two types of queries: 1. ...
- 【分类讨论】【计算几何】【凸包】hihocoder 1582 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 E. Territorial Dispute
题意:平面上n个点,问你是否存在一种黑白染色方案,使得对于该方案,无法使用一条直线使得黑色点划分在直线一侧,白色点划分在另一侧.如果存在,输出一种方案. 如果n<=2,显然不存在. 如果所有点共 ...
- 【线段树】hihocoder 1586 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 I. Minimum
题意:给你一个序列(长度不超过2^17),支持两种操作:单点修改:询问区间中最小的ai*aj是多少(i可以等于j). 只需要线段树维护区间最小值和最大值,如果最小值大于等于0,那答案就是minv*mi ...
- 【最短路】【Heap-dijkstra】hihocoder 1587 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 J. Typist's Problem
题意:给你一个串,仅含有a~g,且每个字母只出现最多一次.和一个光标初始位置,以及一个目标串,问你最少要多少的代价变化成目标串. 有五种操作:在光标前添加一个未出现过的字母,代价1. 删除光标前或者光 ...
随机推荐
- LaTeX转义特殊符号
转义字符在LaTeX中有一些符号被用于特殊的用途,如 \\ \backslash\ 符号被用于命令的转义,直接在LaTeX中输入这些符号是无法正确得到这些符号的,甚至会引起LaTeX的报错. ...
- Redis 获取和设置密码
1.config get reuqirepass //获取当前密码 2.config set requirepass "password"//设置当前密码,双引号里面为密码
- python numPy模块 与numpy里的数据类型、数据类型对象dtype
学习链接:http://www.runoob.com/numpy/numpy-tutorial.html 官方链接:https://numpy.org/devdocs/user/quickstart. ...
- Geany——Python配置
Geany是一个很不错的编辑器,操作很简单,这里记录一下Geany的入手设置(在下是一个Python程序猿,就以Python为例): 1:新建:选择 下拉菜单中的 main.py ,然后就能生成P ...
- OpenResty下载安装教程
原文链接:http://www.studyshare.cn/software/details/1174/0 一.OpenResty简介 OpenResty是一个全功能的 Web 应用服务器.它打包了标 ...
- web基础运用
目录 web框架 web应用本质 Web应用程序的优点 Web应用程序的缺点 BS架构优点 web框架的分类 web框架包含了三部分 web框架分类 Http协议 路由系统 自定制的web框架案例 w ...
- JavaScript设计模式与开发实践随笔(三)
封装 1. 封装数据 a) 只能依赖变量的作用域来实现封装特性,es6中可以通过symbol创建私有属性 var myObject = (function(){ var __name = ' ...
- git的基本使用和多人协作合并管理
1.代码版本控制工具 git 分布式 svn 集中式 2.配置git 配置用户名以及邮箱账号,用于记录用户信息 git config --global user.name 'wudaxun' git ...
- idea/借阅系统的APP开发
(一) 今天去还书时,偶尔想到的idea. 看着在自主借还书机器面前的长龙,我突然想到为什么不将这部机器的功能弄成APP? 通过用手机扫条形码借书不是很方便吗? 哦,不行.借书可以,怎么确保用户将书还 ...
- 【MySQL】查看建表语句
命令如下: SHOW CREATE TABLE tbl_name 例子: mysql> show create table m_zhbess_vehicle_report\G ********* ...