BZOJ4620: [Wf2016]What Really Happened on Mars?
题意比较难懂?反正我为此特地查了优先级倒置和优先级置顶协议是什么。
读懂题以后就好办了,直接模拟即可。
由于数据范围较小,写得比较暴力,应该还有很大优化空间。
#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?的更多相关文章
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- (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 ...
- 【腾讯Bugly干货分享】微信终端跨平台组件 Mars 系列 - 我们如约而至
导语 昨天上午,微信在广州举办了微信公开课Pro.于是,精神哥这两天的朋友圈被小龙的"八不做"刷屏了.小伙伴们可能不知道,下午,微信公开课专门开设了技术分论坛.在分论坛中,微信开源 ...
- 【腾讯Bugly干货分享】微信终端跨平台组件 mars 系列(二) - 信令传输超时设计
本文来自于腾讯Bugly公众号(weixinBugly),未经作者同意,请勿转载,原文地址:http://mp.weixin.qq.com/s/9DJxipJaaBC8yC-buHgnTQ 作者简介: ...
- 如约而至:微信自用的移动端IM网络层跨平台组件库Mars已正式开源
1.前言 关于微信内部正在使用的网络层封装库Mars开源的消息,1个多月前就已满天飞(参见<微信Mars:微信内部正在使用的网络层封装库,即将开源>),不过微信团队没有失约,微信Mars ...
- hdu4059 The Boss on Mars(差分+容斥原理)
题意: 求小于n (1 ≤ n ≤ 10^8)的数中,与n互质的数的四次方和. 知识点: 差分: 一阶差分: 设 则 为一阶差分. 二阶差分: n阶差分: 且可推出 性质: 1. ...
- 【腾讯Bugly干货分享】微信mars 的高性能日志模块 xlog
本文来自于腾讯bugly开发者社区,未经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/581c2c46bef1702a2db3ae53 Dev Club 是一个交流移动 ...
- [原创]Eclipse Mars 在Ubuntu升级后无法工作的解决方法
近日将自己的Ubuntu从14.04LTS升级到了16.04LTS,顿时发现Eclipse不能正常工作了,到Ubuntu的官网上转了一圈发现以下解决方案: 症状: [1]Eclipse启动很慢; [2 ...
- 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. ...
随机推荐
- ServiceStack 概念参考文摘
摘自:http://www.cnblogs.com/woxpp/p/5010881.html ServiceStack 用于服务开发,可以为各种形式的网站.软件.APP等提供数据服务,可以提供REST ...
- 关于iphone 6 ios8网站背景图片错乱的问题解决办法
最近公司有个客户的网站用手机safari打开出现背景图片错乱,本来应该显示A图片的却显示B图片,网速越慢的情况下越容易出现这种问题,悲催的是这种情况只在iPhone 6上出现,并且不是一直这样,多刷新 ...
- spring MVC学习笔记
为开发团队选择一款优秀的MVC框架是件难事儿,在众多可行的方案中决择需要很高的经验和水平.你的一个决定会影响团队未来的几年.要考虑方面太多: 1.简单易用,以提高开发效率.使小部分的精力在框架上,大部 ...
- [转]史上最全最强SpringMVC详细示例实战教程
原文:http://www.cnblogs.com/sunniest/p/4555801.html?utm_source=tuicool&utm_medium=referral SpringM ...
- The superclass javax.servlet.http.HttpServlet was not found on the Java Build Path。
项目上右键-->Build Path-->Configuration Build Path -->Add Library -->Server Runtime 选择tomcat
- Spring + Spring MVC+Hibernate框架整合详细配置
来源于:http://www.jianshu.com/p/8e2f92d0838c 具体配置参数: Spring: spring-framework-4.2.2Hibernate: hibernate ...
- zabbix proxy 服务器 netstat 出现大量Time_Wait连接问题
问题描述: 监控系统云网关监控几万个TCP port的存活情况, 最近发现有几个端口出现告警闪断情况,怀疑因为运行TCP检查的 zabbix proxy 服务器 tcp参数配置不合理. netstat ...
- ClipDrawable 实现图片渐变现实
clip.xml <?xml version="1.0" encoding="utf-8"?><clip xmlns:android=&quo ...
- Android无线调试及手机设备与PC同屏工具——Chrome插件Vysor
我们平时用手机调试时,经常是手不离机,以前可以下载个jar包能把手机屏映射到电脑桌面,但是运行比较卡,后来就放弃了,再之,手机接数据线有时也不太方便 ,pc与手机(连wifi)如处同一网段,就可以通过 ...
- 状态压缩 HDU 1565
多组数据 给你一个n*n的矩阵 不能相邻的取数 上下左右 求最大的和 #include<stdio.h> #include<algorithm> #include<str ...