博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HNU13028Attacking rooks (二分匹配,一行变多行,一列变多列)
阅读量:5267 次
发布时间:2019-06-14

本文共 3234 字,大约阅读时间需要 10 分钟。

Attacking rooks
Time Limit: 20000ms, Special Time Limit:50000ms, Memory Limit:65536KB
Total submit users: 12, Accepted users: 7
Problem 13028 : No special judgement
Problem description
Chess inspired problems are a common source of exercises in algorithms classes. Starting with the well known 8-queens problem, several generalizations and variations were made. One of them is the N-rooks problem, which consists of placing N rooks in an N by N chessboard in such a way that they do not attack each other.
Professor Anand presented the N-rooks problem to his students. Since rooks only attack each other when they share a row or column, they soon discovered that the problem can be easily solved by placing the rooks along a main diagonal of the board. So, the professor decided to complicate the problem by adding some pawns to the board. In a board with pawns, two rooks attack each other if and only if they share a row or column and there is no pawn placed between them. Besides, pawns occupy some squares, which gives an additional restriction on which squares the rooks may be placed on.
Given the size of the board and the location of the pawns, tell Professor Anand the maximum number of rooks that can be placed on empty squares such that no two of them attack each other.
Input
The first line contains an integer N (1 ≤ N ≤ 100) representing the number of rows and columns of the board. Each of the next N lines contains a string of N characters. In the i-th of these strings, the j-th character represents the square in the i-th row and j-th column of the board. The character is either "." (dot) or the uppercase letter "X", indicating respectively an empty square or a square containing a pawn.
Output
Output a line with an integer representing the maximum number of rooks that can be placed on the empty squares of the board without attacking each other.
Sample Input
Sample input 15X....X......X...X.......XSample input 24.....X..........Sample input 31X
Sample Output
Sample output 17Sample output 25Sample output 30
Problem Source
ICPC Latin American Regional 2013
#include
#include
#include
#include
using namespace std;vector
map[10005];int match[10005],vist[10005];int find(int x){ int len=map[x].size(); for(int i=0;i
0) { for(int i=1;i<=n;i++) { getchar(); for(int j=1;j<=n;j++) { mpr[i][j]=mpl[i][j]=0; scanf("%c",&c); if(c=='X') mpr[i][j]=mpl[i][j]=-1; } } rn=0; for(int i=1;i<=n;i++)//一行变多行 for(int j=1;j<=n;j++) { while(mpr[i][j]==-1&&j<=n)j++; rn++; while(mpr[i][j]!=-1&&j<=n) { mpr[i][j]=rn; j++; } } ln=0; for(int j=1;j<=n;j++)//一列变多列 for(int i=1;i<=n;i++) { while(mpl[i][j]==-1&&i<=n)i++; ln++; while(mpl[i][j]!=-1&&i<=n) { mpl[i][j]=ln; i++; } } for(int i=1;i<=rn;i++) map[i].clear(); for(int i=1;i<=n;i++)//行列建图 for(int j=1;j<=n;j++) if(mpr[i][j]!=-1) map[mpr[i][j]].push_back(mpl[i][j]); memset(match,0,sizeof(match)); int ans=0; for(int i=1;i<=rn;i++) { for(int j=0;j<=ln;j++) vist[j]=0; ans+=find(i); } printf("%d\n",ans); }}

转载于:https://www.cnblogs.com/mengfanrong/p/5195267.html

你可能感兴趣的文章
C#.NET 大型通用信息化系统集成快速开发平台 4.1 版本 - 客户端多网络支持
查看>>
HDU 4122
查看>>
Suite3.4.7和Keil u3自带fx2.h、fx2regs.h文件的异同
查看>>
打飞机游戏【来源于Crossin的编程教室 http://chuansong.me/account/crossincode 】
查看>>
[LeetCode] Merge Intervals
查看>>
【翻译自mos文章】当点击完 finishbutton后,dbca 或者dbua hang住
查看>>
Linux编程简介——gcc
查看>>
2019年春季学期第四周作业
查看>>
MVC4.0 利用IActionFilter实现简单的后台操作日志功能
查看>>
windows下mongodb安装与使用
查看>>
rotate the clock
查看>>
bugku 变量
查看>>
Python 环境傻瓜式搭建 :Anaconda概述
查看>>
数据库01 /Mysql初识以及基本命令操作
查看>>
数据库02 /MySQL基础数据类型以及多表之间建立联系
查看>>
Python并发编程04/多线程
查看>>
CF461B Appleman and Tree
查看>>
CF219D Choosing Capital for Treeland
查看>>
杂七杂八的小笔记本
查看>>
51Nod1353 树
查看>>