6.3.1 Strategic Game
来源:互联网 发布:php调用api接口 post 编辑:程序博客网 时间:2024/06/16 07:02
Strategic Game
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 100 Accepted Submission(s): 69
Problem Description
Bob enjoys playing computer games, especially strategic games, but sometimes he cannot find the solution fast enough and then he is very sad. Now he has the following problem. He must defend a medieval city, the roads of which form a tree. He has to put the minimum number of soldiers on the nodes so that they can observe all the edges. Can you help him?
Your program should find the minimum number of soldiers that Bob has to put for a given tree.
The input file contains several data sets in text format. Each data set represents a tree with the following description:
the number of nodes
the description of each node in the following format
node_identifier:(number_of_roads) node_identifier1 node_identifier2 ... node_identifier
or
node_identifier:(0)
The node identifiers are integer numbers between 0 and n-1, for n nodes (0 < n <= 1500). Every edge appears only once in the input data.
For example for the tree:
the solution is one soldier ( at the node 1).
The output should be printed on the standard output. For each given input data set, print one integer number in a single line that gives the result (the minimum number of soldiers). An example is given in the following table:
Your program should find the minimum number of soldiers that Bob has to put for a given tree.
The input file contains several data sets in text format. Each data set represents a tree with the following description:
the number of nodes
the description of each node in the following format
node_identifier:(number_of_roads) node_identifier1 node_identifier2 ... node_identifier
or
node_identifier:(0)
The node identifiers are integer numbers between 0 and n-1, for n nodes (0 < n <= 1500). Every edge appears only once in the input data.
For example for the tree:
the solution is one soldier ( at the node 1).
The output should be printed on the standard output. For each given input data set, print one integer number in a single line that gives the result (the minimum number of soldiers). An example is given in the following table:
Sample Input
40:(1) 11:(2) 2 32:(0)3:(0)53:(3) 1 4 21:(1) 02:(0)0:(0)4:(0)
Sample Output
12
在无向图上运行匈牙利算法,求的最大匹配数要除以2.
#include<cstdio>#include<cstring>#include<vector>using namespace std;const int MAXN = 1500 + 10;int link[MAXN], done[MAXN];int n;vector<int> G[MAXN];bool find_match(int k){for(int j = 0; j < G[k].size(); j++){int i = G[k][j];if(!done[i]){done[i] = 1;if(link[i] == -1 || find_match(link[i])){link[i] = k;return true;}}}return false;}int main(){char str[10];int a, b, cnt;while(~scanf("%d", &n)){for(int i = 0; i < MAXN; i++) G[i].clear();for(int i = 0; i < n; i++){scanf("%d:(%d)", &a, &cnt);for(int j = 0; j < cnt; j++){scanf("%d", &b);G[a].push_back(b);G[b].push_back(a);}}cnt = 0;memset(link, -1, sizeof(link));for(int i = 0; i < n; i++){memset(done, 0, sizeof(done));if(find_match(i)) cnt++;}printf("%d\n", cnt >> 1);}return 1;}
0 0
- 6.3.1 Strategic Game
- Strategic game
- Strategic game
- Strategic game
- Strategic Game
- Strategic game
- poj1463 Strategic game
- hdoj 1054 Strategic Game
- hdu 1054 Strategic Game
- HDU 1054 Strategic Game
- hdu 1054 Strategic Game
- hdu 1054 Strategic Game
- hdu_1054-Strategic Game
- Strategic Game LA 2038
- UvaLive-2083-Strategic game
- POJ-1463-Strategic game
- Hdu 1054 Strategic Game
- Strategic Game HDU
- OC特有语法
- Prim算法
- 评分星星New Version
- Spinner常用方法
- QQ5.0 新版 侧滑菜单效果实现!
- 6.3.1 Strategic Game
- dinic
- javascript 鼠标单击和双击事件并存的实现方法
- 谈谈藤艺的消费误区
- SIP 协议在Asterisk中的应用
- sprintf与swprintf
- dmesg七种用法
- 实现网页方式的即时消息通信
- 'sheet1$' 不是一个有效名称。请确认它不包含无效的字符或标点,且名称不太长。