2010-2011 ACM-ICPC, NEERC, Southern Subregional Contest Fire in the Country(博弈论+搜索)
来源:互联网 发布:淘宝外卖显示系统繁忙 编辑:程序博客网 时间:2024/06/06 20:52
This summer's heat wave and drought unleashed devastating wildfires all across the Earth. Of course, a tiny country on the island "Yars and Eva" is also affected by this ecological disaster. Thanks to the well-organized actions of rescuers, all the citizens were evacuated to the nearby planets on a spaceship.
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.
The first line of input contains the amount of cities n and the amount of roads m in the country (2 ≤ n ≤ 1000, n - 1 ≤ m ≤ 1000). The following m lines contain description of the roads: a, b — indices of the cities connected by roads (1 ≤ a ≤ n, 1 ≤ b ≤ n, a ≠ b). The roads are bidirectional. No pair of cities will be connected by more than one road. There will be a path between any two cities.
Output the name of the pilot who will pay the fine, assuming both pilots act optimally ("Nikolay" — if it is Nikolay, "Vladimir" — if it is Vladimir).
4 31 21 32 4
Vladimir
4 41 21 32 43 4
Nikolay
4 51 21 32 43 42 3
Nikolay
In the first sample test, an optimal strategy for Nicolay is to send the robot to the city 3 on the first day. Vladimir then will be forced to send the robot back to the capital, so the robot will be destroyed and Vladimir will have to pay.
题目大意:两个人操控一个机器人走一棵树,有一个火灾会从根1进行蔓延,每次会蔓延一层的点,之前的点也就有火灾,每天机器人可以往下走一个点,现在判断谁会导致机器人坏
解题思路:这是一个树上的博弈论,先用bfs把这棵树分层,然后跑dfs,根点为必败态对于先手,于是dfs推测当前点是否层数与子节点层数关系,转化为必胜态或必败态,从而推出1
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <cmath>#include <cstdlib>#include <ctime>using namespace std;typedef long long LL;vector<int> tu[1005];int vis[1005],check[1005],deep[1005];int n,m,MAX;void dfs(int x,int fa){int i,k;for(i=0;i<tu[x].size();i++){k=tu[x][i];if(k==fa||deep[x]>=deep[k])continue;dfs(k,x);}if(vis[x]==0) vis[fa]=1;}void bfs(){int x,k;queue<int> qua;qua.push(1);while(!qua.empty()){x=qua.front();qua.pop();for(int i=0;i<tu[x].size();i++){k=tu[x][i];if(deep[k]==0){deep[k]=deep[x]+1;qua.push(k);}}}}int main(){freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);int x,y,i;cin>>n>>m;MAX=0;for(i=1;i<=m;i++){cin>>x>>y;tu[x].push_back(y);tu[y].push_back(x);}deep[1]=1;bfs();memset(vis,0,sizeof(vis));dfs(1,0);/*for(i=1;i<=n;i++)cout<<vis[i]<<" "<<deep[i]<<endl;*/if(vis[1])cout<<"Vladimir"<<endl;elsecout<<"Nikolay"<<endl;return 0;}
- 2010-2011 ACM-ICPC, NEERC, Southern Subregional Contest Fire in the Country(博弈论+搜索)
- 2010-2011 ACM-ICPC, NEERC, Southern Subregional Contest
- 2010-2011 ACM-ICPC, NEERC, Southern Subregional Contest
- 2010-2011 ACM-ICPC, NEERC, Southern Subregional Contest E
- 2010-2011 ACM-ICPC, NEERC, Southern Subregional Contest C
- C. Explode 'Em All 搜索 2010-2011 ACM-ICPC, NEERC, Southern Subregional Contest
- 2009-2010 ACM-ICPC, NEERC, Southern Subregional Contest B kakuro
- Gym 101246(ACM ICPC 2010-2011, NEERC, Southern Subregional Contest Russia, Saratov)
- ACM ICPC 2010-2011, NEERC, Southern Subregional Contest Problem B. 3D City Model
- 2010-2011 ACM-ICPC, NEERC, Southern Subregional Contest B. 3D City Model(数论)
- 2010-2011 ACM-ICPC, NEERC, Southern Subregional Contest【solved :8 / 12 】
- 2012-2013 ACM-ICPC, NEERC, Southern Subregional Contest 解题报告
- 2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest
- 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest
- 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest J Bottles
- 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest J dp
- 2007-2008 ACM-ICPC, NEERC, Southern Subregional Contest J
- 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest
- Python视频教程哪里有
- Properties类
- 怎样理解阻塞非阻塞与同步异步的区别?
- 【字符串入门专题1】hdu3613 【一个悲伤的exkmp】
- 特殊字符组成的落体美女
- 2010-2011 ACM-ICPC, NEERC, Southern Subregional Contest Fire in the Country(博弈论+搜索)
- 将文件下载到本地以及删除本地文件
- /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found问题解决方法
- 串口关闭时候报错、死锁、还有数据在处理报串口关闭错误 解决办法
- JAVA集合之ArrayList
- 2017 Multi-University Training Contest
- 【Portfolio】IC、IR 和 BR 详解
- FIDO U2F NFC协议
- 记录spring controller从页面接收参数的几种方法