题意比较难懂?反正我为此特地查了优先级倒置和优先级置顶协议是什么。

读懂题以后就好办了,直接模拟即可。

由于数据范围较小,写得比较暴力,应该还有很大优化空间。

#include<cstdio>
int clk,n,m,f[21],q[21];
struct node;
node*top;
void build();
node*find_top();
int id(node*);
node&at(int);
void max_eq(int&s,int t){
if(s<t)
s=t;
}
struct node{
char s[100][8];
int a,b,c,d,k,t,v[100];
bool r,l;
void scan(){
scanf("%d%d%d",&t,&b,&a);
for(int i=0;i!=a;++i){
scanf("%s",s[i]);
sscanf(s[i]+1,"%d",v+i);
if(*s[i]==76)
max_eq(q[v[i]],b);
}
}
bool test(int i){
return*s[k]==76&&(v[k]==i||c<=q[i]);
}
void run(){
c=b;
for(int i=1;i<=n;++i)
if(at(i).r&&!at(i).d)
for(int j=1;j<=m;++j)
if(f[j]==i&&test(j)){
l=1;
max_eq(at(i).c,c);
}
r=1;
}
void next(){
if(*s[k]==76)
f[v[k]]=id(this);
if(*s[k]==85){
f[v[k]]=0;
c=b;
for(int j=1;j<=m;++j)
if(f[j]==id(this))
for(int i=1;i<=n;++i)
if(i!=id(this)&&at(i).r&&!at(i).d&&at(i).test(j))
max_eq(c,at(i).c);
}
if((k+=*s[k]!=67||++clk&&!--v[k])==a)
d=clk;
}
}task[21];
int id(node*p){
return p-task;
}
node&at(int i){
return task[i];
}
void build(){
for(int i=1;i<=n;++i)
if(at(i).r&&!at(i).d){
at(i).l=0;
for(int j=1;j<=m;++j)
at(i).l|=f[j]&&f[j]!=i&&at(i).test(j);
}
}
node*find_top(){
top=0;
for(int i=1;i<=n;++i)
if(at(i).r&&!at(i).d&&!at(i).l&&(!top||at(i).c>top->c))
top=&at(i);
return top;
}
bool ended(){
for(int i=1;i<=n;++i)
if(!at(i).d)
return 0;
return 1;
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i)
at(i).scan();
while(!ended()){
for(int i=1;i<=n;++i)
if(!at(i).r&&at(i).t==clk)
at(i).run();
build();
if(find_top()||!++clk)
top->next();
}
for(int i=1;i<=n;++i)
printf("%d\n",at(i).d);
}

BZOJ4620: [Wf2016]What Really Happened on Mars?的更多相关文章

  1. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  2. (29)Why Earth may someday look like Mars

    https://www.ted.com/talks/anjali_tripathi_why_earth_may_someday_look_like_mars/transcript00:12So whe ...

  3. 【腾讯Bugly干货分享】微信终端跨平台组件 Mars 系列 - 我们如约而至

    导语 昨天上午,微信在广州举办了微信公开课Pro.于是,精神哥这两天的朋友圈被小龙的"八不做"刷屏了.小伙伴们可能不知道,下午,微信公开课专门开设了技术分论坛.在分论坛中,微信开源 ...

  4. 【腾讯Bugly干货分享】微信终端跨平台组件 mars 系列(二) - 信令传输超时设计

    本文来自于腾讯Bugly公众号(weixinBugly),未经作者同意,请勿转载,原文地址:http://mp.weixin.qq.com/s/9DJxipJaaBC8yC-buHgnTQ 作者简介: ...

  5. 如约而至:微信自用的移动端IM网络层跨平台组件库Mars已正式开源

    1.前言 关于微信内部正在使用的网络层封装库Mars开源的消息,1个多月前就已满天飞(参见<微信Mars:微信内部正在使用的网络层封装库,即将开源>),不过微信团队没有失约,微信Mars ...

  6. hdu4059 The Boss on Mars(差分+容斥原理)

    题意: 求小于n (1 ≤ n ≤ 10^8)的数中,与n互质的数的四次方和. 知识点: 差分: 一阶差分: 设  则    为一阶差分. 二阶差分: n阶差分:     且可推出    性质: 1. ...

  7. 【腾讯Bugly干货分享】微信mars 的高性能日志模块 xlog

    本文来自于腾讯bugly开发者社区,未经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/581c2c46bef1702a2db3ae53 Dev Club 是一个交流移动 ...

  8. [原创]Eclipse Mars 在Ubuntu升级后无法工作的解决方法

    近日将自己的Ubuntu从14.04LTS升级到了16.04LTS,顿时发现Eclipse不能正常工作了,到Ubuntu的官网上转了一圈发现以下解决方案: 症状: [1]Eclipse启动很慢; [2 ...

  9. PAT (Advanced Level) Practise:1027. Colors in Mars

    [题目链接] People in Mars represent the colors in their computers in a similar way as the Earth people. ...

随机推荐

  1. C语言strcat()函数:连接字符串

    头文件:#include <string.h> strcat() 函数用来连接字符串,其原型为:    char *strcat(char *dest, const char *src); ...

  2. 数据库MongoDB查询语句--持续更新

    模糊查询: 包含字符串str : find({'name':/str/i}); {'name':/str/} 以str开头:   {'name':/^str/} $in查询: 字段:{ field: ...

  3. IOS自学

    初识IOS 开发工具:xcode , 第一步学习c 打开xcode 新建一个object #include<stdio.h>//引入一个库,支持pringf输出功能 /* this is ...

  4. Oracle在中文环境下出现乱码解决办法

       zysong.ttf下载是一款oracle字体乱码解决工具,实质于缺乏中文字体包! 01情况的例子 02情况的例子 01.在开始安装的时候出现乱码 下载zysong.ttf,unzip 解压 一 ...

  5. dig 常用的域名查询工具

    dig 命令是常用的域名查询工具,可以用来测试域名系统工作是否正常. 语法: dig (选项) (参数) 选项: @<服务器地址>: 指定进行域名解析的域名服务器: -b: 当主机具有多个 ...

  6. 1021mysql 全外连接

    mysql 不支持全外连接,那么使用union all进行替换 -- 其他数据库 SELECT * FROM aa aFULL OUTER JOIN bb b ON a.col1=b.col1AND ...

  7. linux基础学习2

    http://www.chengzhier.com <a href="http://www.chengzhier.com">橙汁儿网</a> 1. date ...

  8. bootstrap实现pc屏幕五等分

    <!DOCTYPE html><html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...

  9. Redis集群(五):集群搭建

    一.本文目的        演示在一台机器上搭建3主3从的redis集群,通过演示了解redis集群的搭建,使用和注意事项     二.搭建说明        1.同一台机器搭建3主3从的伪集群   ...

  10. 在chrome下-webkit-box布局的一个bug

    chrome,也就是webkit内核下作的检测, chrome版本是40, -webkit-box这种布局在移动端用的比较多,主要是因为pc端的浏览器内核参差不齐. 因为在写HTML的时候看上了-we ...