HUST1027-Enemy Target!
来源:互联网 发布:淘宝店铺装修收费标准 编辑:程序博客网 时间:2024/06/16 17:47
Enemy Target!
时间限制:2秒 内存限制:128兆
自定评测 114 次提交 34 次通过
- 题目描述
- In the Game Red Alert, a group of soviet infantry marches towards our base. And we have N Prism Tanks to defend our base. Suppose the coming infantry marches in a ROW*COLUMN rectangle grid, and keeps the shape unchanged. A Prism Tank can eliminate infantry in any row or column at a shot. Prism Tank is weak in self-defense, so your task is to assign the least Prism Tanks, fire simultaneously to eliminate all the invading enemies. If our Prism Tank is enough, submit any assignment using the least Prism Tanks. Otherwise, report it.
- 输入
- First line: 3 integers ROW,COLUMN,N--number of Prism Tanks we have now(ROW<=1000, COLUMN<=1000,N<=1000). Line 2 to ROW+1: Each line is a binary 01 string with length COLUMN, represent the shape of infantry. Set 1 if a position have a soldier, otherwise 0.
- 输出
- If there exist an assignment, output it in the format: k1+k2 ROW: R1 R2...Rk1 COLUMN: C1 C2...Ck2 k1+k2 is the totoal number of Prism Tanks. Otherwise print one line "NOT ENOUGH TANK".
- 样例输入
4 4 40101101010100010
- 样例输出
3ROW: 1COLUMN: 1 3
- 提示
- 来源
- liruqi
题意:一些步兵在r*c的矩阵中,一辆坦克可以消灭一列或一行的步兵,问所派的坦克够不够,若够,需要在哪几列或哪几行放置坦克
解题思路:二分图,根据x轴和y轴进行匹配,若有步兵则连一条边,然后找出最小覆盖点集即可,然后判断需要在哪几行或哪几列放坦克
#include <iostream> #include <cstdio> #include <string> #include <cstring> #include <algorithm> #include <queue> #include <vector> #include <set> #include <stack> #include <map> #include <climits> #include <functional> using namespace std; #define LL long long const int INF=0x3f3f3f3f; int r,c,n; char ch[1005][1005]; int x[1509],y[1509]; int s[1509],nt[1000509],e[1000509]; int visit[1009];int rr[1009],cc[1009]; bool path(int k) { for(int i=s[k];~i;i=nt[i]) { int ee=e[i]; if(!visit[ee]) { visit[ee]=1; if(y[ee]==-1||path(y[ee])) { y[ee]=k; x[k]=ee; return 1; } } } return 0; } void MaxMatch() { int ans=0; memset(x,-1,sizeof x); memset(y,-1,sizeof y); for(int i=0;i<r;i++) { if(x[i]==-1) { memset(visit,0,sizeof visit); if(path(i)) ans++; } } if(ans>n) printf("NOT ENOUGH TANK\n"); else { printf("%d\n",ans); memset(rr,0,sizeof rr); memset(cc,0,sizeof cc); for(int i=0;i<r;i++) { for(int j=0;j<c;j++) if(ch[i][j]=='1'&&y[j]==-1) rr[i]=1;}for(int i=0;i<r;i++) { for(int j=0;j<c;j++) if(ch[i][j]=='1'&&!rr[i]) cc[j]=1;}printf("ROW:"); for(int i=0;i<r;i++) if(rr[i]) printf(" %d",i+1); printf("\n"); printf("COLUMN:"); for(int i=0;i<c;i++) if(cc[i]) printf(" %d",i+1); printf("\n");}} int main() { while(~scanf("%d %d %d",&r,&c,&n)){int cnt=1; for(int i=0;i<r;i++) scanf("%s",ch[i]); memset(s,-1,sizeof s); for(int i=0;i<r;i++) { for(int j=0;j<c;j++) { if(ch[i][j]=='1') nt[cnt]=s[i],s[i]=cnt,e[cnt++]=j; } } MaxMatch();} return 0; }
0 0
- HUST1027-Enemy Target!
- HUST 1027 Enemy Target!
- enemy
- HUST 1027 Enemy Target! 最小点覆盖集
- 7.Enemy
- target
- Target
- @Target:
- Target
- target
- Target
- target
- Know Your Enemy
- Sleeping with the Enemy
- know your enemy 主页
- Know Your Enemy
- enemy 视野 实现
- 实现分析 - Enemy part2
- Mac安装Python版OpenCV
- 为什么说网站权重第一要素是网站结构
- leetcode解题之124. Binary Tree Maximum Path Sum Java版 (二叉树的最大路径和)
- error while loading shared libraries: xxx.so.x" 错误的原因和解决办法
- java 线程 通知 虚假唤醒
- HUST1027-Enemy Target!
- libpcap编程(1)
- dropDownSelect枚举下拉框
- PAT乙级(Basic Level)真题 >在霍格沃茨找零钱
- mutex与semaphore的区别
- 【Java8】Guava——Charsets
- 欢迎使用CSDN-markdown编辑器
- BIEE 11g 应用角色同步程序 1.0 发布
- from表单提交验证