ural 1251. Cemetery Manager
1251. Cemetery Manager
Memory limit: 64 MB
Input
Output
Sample
| input | output |
|---|---|
2 2 |
3 |
Notes
- Each tomb has 2 to 8 neighbors.
- If a client was buried on day T then the tomb may be dug over on day T+1001 and may not be dug over on day T+1000.
- If a tomb was visited on day T then its neighbors may be dug over on day T+101 and may not be dug over on day T+100.
- A tomb is dug over as soon as there is an opportunity (see items 2 and 3).
- During a funeral relatives notice nothing including the neighbors.
- The clients are numbered in the the order that they arrive (including those who was sent to crematorium).
- If there is already no tomb or the client has been sent to the crematorium immediately or there is no client with the required number then a visit affects nothing.
- The next in turn client may be always burried in an empty tomb inspite of the neighbor tombs visits (the neighbors' relatives wouldn't be surprised having found out that the adjacent empty tomb is already occupied).
Problem Source: Open collegiate programming contest for student teams, Ural State University, March 15, 2003
/**
Create By yzx - stupidboy
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef double DB;
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define mk make_pair inline int Getint()
{
int Ret = ;
char Ch = ' ';
bool Flag = ;
while(!(Ch >= '' && Ch <= ''))
{
if(Ch == '-') Flag ^= ;
Ch = getchar();
}
while(Ch >= '' && Ch <= '')
{
Ret = Ret * + Ch - '';
Ch = getchar();
}
return Flag ? -Ret : Ret;
} const int N = , MAXINDEX = , LEN = , ILEN = ;
class Node
{
private :
int x, y; public :
Node() {}
Node(int tx, int ty)
{
x = tx, y = ty;
} inline bool operator <(const Node &t) const
{
if(x != t.x) return x > t.x;
return y > t.y;
} inline int GetRow()
{
return x;
} inline int GetCol()
{
return y;
} inline int GetTime()
{
return x;
} inline int GetIndex()
{
return y;
}
} ;
class Heap
{
private :
priority_queue<Node> Store; public :
inline void Push(int x, int y)
{
Store.push(Node(x, y));
} inline void Push(const Node &x)
{
Store.push(x);
} inline void Pop()
{
Store.pop();
} inline Node GetTop()
{
return Store.top();
} inline bool Empty()
{
return Store.empty();
}
} deadtime, emptylist;
int n, m, cnttombs;
int endtime[MAXINDEX], graph[N][N];
Node where[MAXINDEX];
bool have[MAXINDEX];
int ans; inline void Input()
{
scanf("%d%d", &n, &m);
} inline void Dug(int now)
{
while(!deadtime.Empty())
{
Node t = deadtime.GetTop();
int idx = t.GetIndex(), deadline = t.GetTime();
if(!have[idx] || endtime[idx] != deadline)
deadtime.Pop();
else if(deadline >= now) break;
else
{
emptylist.Push(where[idx]);
graph[where[idx].GetRow()][where[idx].GetCol()] = -;
where[idx] = Node(-, -);
endtime[idx] = -, have[idx] = ;
deadtime.Pop();
}
}
} inline bool AddTomb(int now)
{
bool ret = ;
cnttombs++;
while(!ret && !emptylist.Empty())
{
Node t = emptylist.GetTop();
int x = t.GetRow(), y = t.GetCol();
graph[x][y] = cnttombs, where[cnttombs] = t;
have[cnttombs] = , endtime[cnttombs] = now + LEN;
deadtime.Push(endtime[cnttombs], cnttombs);
emptylist.Pop();
ret = ;
}
return ret;
} inline bool Check(int x, int y)
{
if(x < || x >= n || y < || y >= m) return ;
if(!graph[x][y] || !have[graph[x][y]]) return ;
return ;
} inline void Visit(int now, int idx)
{
const int DX[] = {-, , , , -, -, , },
DY[] = {, -, , , -, , -, };
if(!have[idx]) return;
int x = where[idx].GetRow(), y = where[idx].GetCol();
endtime[idx] = max(endtime[idx], now + LEN);
deadtime.Push(endtime[idx], idx);
for(int t = ; t < ; ++ t)
{
int dx = x + DX[t], dy = y + DY[t];
if(!Check(dx, dy)) continue;
endtime[graph[dx][dy]] = max(endtime[graph[dx][dy]], now + ILEN);
deadtime.Push(endtime[graph[dx][dy]], graph[dx][dy]);
}
} inline void Solve()
{
for(int i = ; i < n; i++)
for(int j = ; j < m; j++)
emptylist.Push(i, j); char type;
int t, idx;
while(scanf("%d", &t) == )
{
for(type = ' '; type != 'v' && type != 'd'; type = getchar());
Dug(t);
if(type == 'd')
{
bool ret = AddTomb(t);
ans += !ret;
}
else
{
scanf("%d", &idx);
Visit(t, idx);
}
} printf("%d\n", ans);
} int main()
{
freopen("a.in", "r", stdin);
Input();
Solve();
return ;
}
ural 1251. Cemetery Manager的更多相关文章
- ural 1255. Graveyard of the Cosa Nostra
1255. Graveyard of the Cosa Nostra Time limit: 1.0 secondMemory limit: 64 MB There is a custom among ...
- ural 1252. Sorting the Tombstones
1252. Sorting the Tombstones Time limit: 1.0 secondMemory limit: 64 MB There is time to throw stones ...
- ural 1249. Ancient Necropolis
1249. Ancient Necropolis Time limit: 5.0 secondMemory limit: 4 MB Aerophotography data provide a bit ...
- URAL 1252 ——Sorting the Tombstones——————【gcd的应用】
Sorting the Tombstones Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I ...
- URAL ——1249——————【想法题】
Ancient Necropolis Time Limit:5000MS Memory Limit:4096KB 64bit IO Format:%I64d & %I64u ...
- Windows下Redis缓存服务器的使用 .NET StackExchange.Redis Redis Desktop Manager
Redis缓存服务器是一款key/value数据库,读110000次/s,写81000次/s,因为是内存操作所以速度飞快,常见用法是存用户token.短信验证码等 官网显示Redis本身并没有Wind ...
- 如何重新注册VMware Update Manager(VUM)至vCenter Server中
在VMware的vSphere化境中,VUM的角色相当于Windows 环境中的WSUS(Windows 更新服务器),可以批量,自动化的完成所管辖ESXi主机的大版本迁移,小版本升级的任务,深受管理 ...
- 使用tomcat manager 管理和部署项目
在部署tomcat项目的时候,除了把war文件直接拷贝到tomcat的webapp目录下,还有一种方法可以浏览器中管理和部署项目,那就是使用tomcat manager. 默认情况下,tomcat m ...
- Ubuntu管理开机启动服务项 -- 图形界面的Boot-up Manager
有时学习时安装的服务太多,比如mysql.mongodb.redis.apache.nginx等等,它们都是默认开机启动的,如果不想让它们开机启动,用到时再自己手工启动怎么办呢? 使用sysv-rc- ...
随机推荐
- ASP.NET Global 全局事件处理
添加Global文件,名字不要改 Global类说明: using System; using System.Collections.Generic; using System.IO; using S ...
- timestamp 类型的索引
由这条语句datetime.strftime('2014/12/05','%Y/%m/%d')转换出来的索引 是pandas内置类型相同,如果使用datetime.strftime('2014/12/ ...
- AFNetworking(AFN)总结
AFNetworking(AFN) ----主要做下载上传之用 //他是干啥的?发送请求,主要做下载上传之用 (苹果自带有获取服务器数据的方法NSURLConnection send,AFNetwor ...
- "稀奇古怪的"delete this
myClass::foo(){ delete this; } .. void func(){ myClass *a = new myClass(); a->foo(); ...
- SQLServer多表连接查询
双表内部连接查询 select wName,dName from DepartMent,Worker where DepartMent.dID=Worker.did select wName,dNam ...
- webrtc中的带宽自适应算法
转自:http://www.xuebuyuan.com/1248366.html webrtc中的带宽自适应算法分为两种: 1, 发端带宽控制, 原理是由rtcp中的丢包统计来动态的增加或减少带宽,在 ...
- Win7下用IIS发布网站
安装IIS控制面板->程序->程序和功能, 点击左侧的“打开或关闭Windows功能”把这几项都勾上吧,虽然有些不是必须的,多勾无碍. 进入IIS管理器控制面板-> 系统和安全-&g ...
- HDU 4812 D Tree 树分治+逆元处理
D Tree Problem Description There is a skyscraping tree standing on the playground of Nanjing Unive ...
- python 多态
多态 类具有继承关系,并且子类类型可以向上转型看做父类类型,如果我们从 Person 派生出 Student和Teacher ,并都写了一个 whoAmI() 方法: class Person(obj ...
- 廖雪峰js教程笔记11 操作DOM(包含作业)
由于HTML文档被浏览器解析后就是一棵DOM树,要改变HTML的结构,就需要通过JavaScript来操作DOM. 始终记住DOM是一个树形结构.操作一个DOM节点实际上就是这么几个操作: 更新:更新 ...