SGU 520 Fire in the Country(博弈+搜索)
Description
To save the country, a small fire robot was left on its territory. He managed to extinguish fire in all cities except the capital before running out of liquid. The robot can't extinguish fire anymore, so the country is still in danger at the moment.
There are n cities in the country connected by m two-way roads. Each road connects a pair of cities. There is at most one road between any pair of cities. The cities are numbered from 1 to n, with capital having the number 1.
The fire spreads very quickly. On the very first day only the capital is on fire. But with every subsequent day, the fire devours all the cities connected by a road with the cities that are already on fire. Once the fire gets to a certain city, this city will continue to stay on fire till the very end.
The robot can't extinguish the fire anymore and there are no other means of firefighting left in the country, so obviously the country is going to be burned down to the ground. And you don't have to be a hero and save it. The key thing is that the robot is going to be destroyed by fire as well, and you need to figure out who will actually pay for the loss of government property.
Two pilots, Nikolay and Vladimir, are on Earth's natural satellite. They alternately take turns controlling the robot. The pilots alternate each day. Robot's speed is equal to the speed of fire, so the robot can get to the neighboring city in a day. Each pilot does not want the robot to be destroyed on his turn. For such a valuable loss they will have to pay a huge fee to the government.
On the first day the robot is located in the capital. Nikolay controls the robot on the first day. Thus, Nikolay controls the robot on the days with odd numbers, and Vladimir controls it on the days with even numbers. Taking turn, a pilot has to move the robot from the current city to any city connected by a road with the current one. If a pilot moves the robot to a city which is on fire, the robot is destroyed.
You task is to figure out who will pay the fine for the destroyed robot, assuming both pilots act optimally.
Input
Output
Nikolay
" — if it is Nikolay, "
Vladimir
" — if it is Vladimir).
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std; const int MAXN = ;
const int MAXE = ; int n, m, f, ecnt;
int head[MAXN], dis[MAXN];
int to[MAXE], next[MAXE]; void add_edge(int u, int v) {
to[ecnt] = v; next[ecnt] = head[u]; head[u] = ecnt++;
to[ecnt] = u; next[ecnt] = head[v]; head[v] = ecnt++;
} void bfs() {
queue<int> que; que.push();
dis[] = ;
while(!que.empty()) {
int u = que.front(); que.pop();
for(int p = head[u]; p; p = next[p]) {
int &v = to[p];
if(!dis[v]) {
dis[v] = dis[u] + ;
que.push(v);
}
}
}
} int win[MAXN]; int dfs(int u) {
if(win[u] != -) return win[u];
for(int p = head[u]; p; p = next[p]) {
int &v = to[p];
if(dis[v] == dis[u] + ) {
if(dis[u] & ) {if(dfs(v)) return win[u] = ;}
else if(!dfs(v)) return win[u] = ;
}
}
return win[u] = !(dis[u] & );
} int main() {
scanf("%d%d", &n, &m);
ecnt = ;
while(m--) {
int u, v;
scanf("%d%d", &u, &v);
add_edge(u, v);
}
bfs();
memset(win, -, sizeof(win));
if(dfs()) puts("Vladimir");
else puts("Nikolay");
}
SGU 520 Fire in the Country(博弈+搜索)的更多相关文章
- HDU 5723 Abandoned country 最小生成树+搜索
		
Abandoned country Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
 - 【迭代博弈+搜索+剪枝】poj-1568--Find the Winning Move
		
poj 1568:Find the Winning Move [迭代博弈+搜索+剪枝] 题面省略... Input The input contains one or more test cas ...
 - Gym 101246D	Fire in the Country(dfs求SG函数)
		
http://codeforces.com/gym/101246/problem/D 题意: 给定一个无向有环图,大火从1点开始,每个时间点与它相邻的点也将会着火,现在有两个人轮流操作机器人,机器人从 ...
 - D - Stone Division HackerRank - stone-division (博弈+搜索)
		
题目链接:https://cn.vjudge.net/problem/HackerRank-stone-division 题目大意:给你n,m,然后是m个数.每一次你可以选择一个a[i],如果能被n整 ...
 - B. Sleepy Game 博弈搜索
		
题意:给一个有向图和起点,然后只有一名选手,这名选手可以随意挪动棋子,最终不能动的时候走过的边为奇数边为Win并输出路径,否则如果有环输出Draw,否则输出Lose; 题目链接 知道状态数最多只有n* ...
 - 极小极大搜索方法、负值最大算法和Alpha-Beta搜索方法
		
1. 极小极大搜索方法 一般应用在博弈搜索中,比如:围棋,五子棋,象棋等.结果有三种可能:胜利.失败和平局.暴力搜索,如果想通过暴力搜索,把最终的结果得到的话,搜索树的深度太大了,机器不能满足, ...
 - 转:极小极大搜索方法、负值最大算法和Alpha-Beta搜索方法
		
转自:极小极大搜索方法.负值最大算法和Alpha-Beta搜索方法 1. 极小极大搜索方法 一般应用在博弈搜索中,比如:围棋,五子棋,象棋等.结果有三种可能:胜利.失败和平局.暴力搜索,如果想通 ...
 - shodan搜索
		
扫描一切联网的设备 www.shodan.io 一.ip 直接搜索:123.123.123.123 二.搜索服务 http http country:"DE" 指定搜索德国 htt ...
 - Shodan新手入坑指南
		
*本文原创作者:xiaix,本文属FreeBuf原创奖励计划,未经许可禁止转载 亲们~黑五 Shodan Membership 只要5刀,你剁手了没? 什么是 Shodan? 首先,Shodan 是一 ...
 
随机推荐
- MVC进行多文件上传
			
用mvc做多文件的上传和保存到本地,大致流程就是,前台通过form表单提交多文件,Controller接受到文件流,将文件流保存到本地 然后将保存地址 存到数据库中. 将文件通过from提交 < ...
 - mysql  支持四字节设置
			
设置文件mysql/bin/my.ini[mac用户在ect文件夹里创建文件my.cnf] 添加以下代码: [mysqld] character-set-server=utf8mb4
 - Win7装在其他盘 (非C盘)办法
			
Win7装在其他盘 (非C盘)办法 1]将GHO还原到其他盘(非C盘),如H盘 2]用进U盘系统,里的工具,恢复启动H盘 3]将H盘的Boot文件夹,及其他根目录的所有文件复制到C盘根目录,重启即可开 ...
 - ACM1003:Max Sum
			
Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum ...
 - 牛客小白月赛4C——病菌感染
			
链接:https://www.nowcoder.com/acm/contest/134/C 来源:牛客网 #include <bits/stdc++.h> using namespace ...
 - Nodejs实战 —— 测试 Node 程序
			
读 <node.js实战2.0>,进行学习记录总结. 当当网购买链接 豆瓣网1.0链接 测试 Node 程序 本章内容 用 Node 的 assert 模块测试 使用其他断言库 使用 No ...
 - See You Again——我最后的汇编程序
			
汇编语言:课程设计2 前言 由于本人水平不够,这里的课程设计2的程序实现并没有像王爽书中所说的那样可以不依赖于操作系统运行. 这里的程序依然要在dos下运行,而且没有实现引导现有操作系统的功能. 该程 ...
 - 【原创】Odoo开发文档学习之:构建接口扩展(Building Interface Extensions)(边Google翻译边学习)
			
构建接口扩展(Building Interface Extensions) 本指南是关于为Odoo的web客户创建模块. 要创建有Odoo的网站,请参见建立网站;要添加业务功能或扩展Odoo的现有业务 ...
 - 北京Uber优步司机奖励政策(12月8日)
			
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
 - 成都Uber优步司机奖励政策(1月27日)
			
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...