1741: [Usaco2005 nov]Asteroids 穿越小行星群

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 231  Solved: 166
[Submit][Status][Discuss]

Description

Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N grid (1 <= N <= 500). The grid contains K asteroids (1 <= K <= 10,000), which are conveniently located at the lattice points of the grid. Fortunately, Bessie has a powerful weapon that can vaporize all the asteroids in any given row or column of the grid with a single shot. This weapon is quite expensive, so she wishes to use it sparingly. Given the location of all the asteroids in the field, find the minimum number of shots Bessie needs to fire to eliminate all of the asteroids.

贝茜想驾驶她的飞船穿过危险的小行星群.小行星群是一个NxN的网格(1≤N≤500),在网格内有K个小行星(1≤K≤10000). 幸运地是贝茜有一个很强大的武器,一次可以消除所有在一行或一列中的小行星,这种武器很贵,所以她希望尽量地少用.给出所有的小行星的位置,算出贝茜最少需要多少次射击就能消除所有的小行星.
 

Input

* Line 1: Two integers N and K, separated by a single space.

* Lines 2..K+1: Each line contains two space-separated integers R and C (1 <= R, C <= N) denoting the row and column coordinates of an asteroid, respectively.

    第1行:两个整数N和K,用一个空格隔开.
    第2行至K+1行:每一行有两个空格隔开的整数R,C(1≤R,C≤N),分别表示小行星所在的行和列.

Output

* Line 1: The integer representing the minimum number of times Bessie must shoot.

一个整数表示贝茜需要的最少射击次数,可以消除所有的小行星

Sample Input

3 4
1 1
1 3
2 2
3 2

INPUT DETAILS:

The following diagram represents the data, where "X" is an
asteroid and "." is empty space:
X.X
.X.
.X.

Sample Output

2

OUTPUT DETAILS:

Bessie may fire across row 1 to destroy the asteroids at (1,1) and
(1,3), and then she may fire down column 2 to destroy the asteroids
at (2,2) and (3,2).

HINT

 

Source

Gold

题解:看了半天,感觉还是网络流= =,而且貌似还是二分图

分别以横坐标与纵坐标建立点集,然后根据各点来连边建立二分图,然后二分图匹配或者网络流秒之

网络流:(这个程序其实还可以优化——因为我在A掉此题之后才想到不需要根据每一个点再在中间建立一个节点,直接二分图就可以搞定)

 /**************************************************************
Problem:
User: HansBug
Language: Pascal
Result: Accepted
Time: ms
Memory: kb
****************************************************************/ type
point=^node;
node=record
g,w:longint;
next,anti:point;
end;
var
i,j,k,l,m,n,s,t,ans:longint;
a:array[..] of point;
d,dv:array[..] of longint;
function min(x,y:longint):longint;
begin
if x<y then min:=x else min:=y;
end;
procedure add(x,y,z:longint);
var p:point;
begin
new(p);p^.g:=y;p^.w:=z;p^.next:=a[x];a[x]:=p;
new(p);p^.g:=x;p^.w:=;p^.next:=a[y];a[y]:=p;
a[x]^.anti:=a[y];a[y]^.anti:=a[x];
end;
function dfs(x,flow:longint):longint;
var p:point;k:longint;
begin
if x=t then exit(flow);
p:=a[x];dfs:=;
while p<>nil do
begin
if (p^.w<>) and (d[x]=(d[p^.g]+)) then
begin
k:=dfs(p^.g,min(flow-dfs,p^.w));
if p^.w<>maxlongint then dec(p^.w,k);
if p^.anti^.w<>maxlongint then inc(p^.anti^.w,k);
inc(dfs,k);
if dfs=flow then exit;
end;
p:=p^.next;
end;
if d[s]=n then exit;
dec(dv[d[x]]);
if dv[d[x]]= then d[s]:=n;
inc(d[x]);inc(dv[d[x]]);
end;
begin
readln(n,m);
for i:= to n*+m+ do a[i]:=nil;
for i:= to n do
begin
add(,i,);add(n+m+i,n*+m+,);
end;
for i:= to m do
begin
readln(j,k);
add(j,n+i,);add(n+i,n+m+k,);
end;
s:=;t:=n*+m+;
n:=n*+m+;
fillchar(d,sizeof(d),);
fillchar(dv,sizeof(dv),);
dv[]:=n;ans:=;
while d[s]<n do inc(ans,dfs(s,maxlongint));
writeln(ans);
readln;
end.

二分图:(话说二分图居然比优化的不到位的网络流满是什么鬼QAQ)

 /**************************************************************
Problem:
User: HansBug
Language: Pascal
Result: Accepted
Time: ms
Memory: kb
****************************************************************/ type
point=^node;
node=record
g:longint;
next:point;
end;
var
i,j,k,l,m,n,ans:longint;
a:array[..] of point;
c,f:array[..] of longint;
procedure add(x,y:longint);
var p:point;
begin
new(p);p^.g:=y;
p^.next:=a[x];a[x]:=p;
end;
function check(x:longint):boolean;
var p:point;
begin
p:=a[x];
while p<>nil do
begin
if f[p^.g]<>i then
begin
f[p^.g]:=i;
if c[p^.g]= then
begin
c[p^.g]:=x;
exit(true);
end
else if check(c[p^.g]) then
begin
c[p^.g]:=x;
exit(true);
end;
end;
p:=p^.next;
end;
exit(false);
end;
begin
readln(n,m);
for i:= to n do a[i]:=nil;
for i:= to m do
begin
readln(j,k);
add(j,k);
end;
ans:=;
fillchar(c,sizeof(c),);
fillchar(f,sizeof(f),);
for i:= to n do if check(i) then inc(ans);
writeln(ans);;
readln;
end.

1741: [Usaco2005 nov]Asteroids 穿越小行星群的更多相关文章

  1. BZOJ 1741: [Usaco2005 nov]Asteroids 穿越小行星群

    Description 贝茜想驾驶她的飞船穿过危险的小行星群.小行星群是一个NxN的网格(1≤N≤500),在网格内有K个小行星(1≤K≤10000). 幸运地是贝茜有一个很强大的武器,一次可以消除所 ...

  2. 【BZOJ】1741: [Usaco2005 nov]Asteroids 穿越小行星群

    [题意]给定n*n网格,有k个物品,每次可以消灭一行或一列,求消灭掉所有物品的最少操作次数. [算法]二分图最小覆盖 [题解]此题是最小覆盖模型的出处. 将物品的x-y连边建立二分图. 最小覆盖:选择 ...

  3. bzoj1741 [Usaco2005 nov]Asteroids 穿越小行星群

    网络流,对于每一个行星,将行星所在行到行星连一条流量为1的边,将行星到其所在列连一条流量为1的边,从源点到所有行连一条流量为1的边,将所有列到汇点都连一条流量为1的边,最大流即为答案. 代码 #inc ...

  4. bzoj 1741: [Usaco2005 nov]Asteroids 穿越小行星群【最大点覆盖】

    二分图最大点覆盖模型,因为对于一个点(x,y)显然只要选x或者y就好了,于是连边,跑最大匹配=最大点覆盖(不会证) #include<iostream> #include<cstdi ...

  5. 【JZOJ1922】【Usaco 2005 NOV Gold】小行星群

    题目描述 Bessie想驾驶她的飞船穿过危险的小行星群,小行星群是一个N×N的网格(1 <= N <= 500),在网格内有K个小行星(1 <= K <= 10,000). 幸 ...

  6. bzoj1741 [Usaco2005 nov]Asteroids 穿越小行星群 最小点覆盖

    链接 https://www.lydsy.com/JudgeOnline/problem.php?id=1741 思路 消除所有的小行星 每个点(x,y)只有选择x或者y才能被覆盖 二分图最小点覆盖= ...

  7. [bzoj1741]穿越小行星群

    将每一行/每一列作为一个点,对于一个障碍(x,y),要么第x行和第y列的状态(是否攻击)只需要有一个就可以了,将第x行和第y列连边,就是二分图的最小点覆盖=最大匹配数. 1 #include<b ...

  8. [Usaco2005 Nov]Asteroids

    Description Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape o ...

  9. BZOJ2023: [Usaco2005 Nov]Ant Counting 数蚂蚁

    2023: [Usaco2005 Nov]Ant Counting 数蚂蚁 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 56  Solved: 16[S ...

随机推荐

  1. App Store Review Guideline(带翻译)

    1. Terms and conditions(法律与条款) 1.1  As a developer of applications for the App Store you are bound b ...

  2. HoloLens开发手记 - 构建2D应用 Building 2D apps

    HoloLens可以让我们在真实世界中看到全息图像内容.但是它本质上还是一台Windows 10设备,这意味着HoloLens可以以2D应用形式运行Windows Store里的大部分UWP应用. 目 ...

  3. 为 Jenkins 配置 .Net 持续集成环境

    去年年底,得益于公司引入 Jenkins,让我们在持续集成方面迈出了第一步,本文不赘述如何安装 Jenkins,主要关注点在于配置 .Net 环境.另外本文是在 Windows 环境下安装的 Jenk ...

  4. SmartRoute之远程接口调用和负载

    基于接口的调用远比基于基础消息交互来得更简单和便于维护,特别在业务展现上,接口作为业务表现更适合其便利性.为了让SmartRoute更适合业务应用集成,在新的一年开始SmartRoute集成了远程接口 ...

  5. vs 2015常用快捷键

    原文 :http://www.23pro.com/post/4.html 1.回到上一个光标位置/前进到下一个光标位置 1)回到上一个光标位置:使用组合键"Ctrl + -"; 2 ...

  6. "table" is not mapped 解决方法

    现象:使用hql="from person" 出现" person is not mapped " 错误 配置文件如下:<hibernate-mappin ...

  7. java8-lamba表达式的使用-遁地龙卷风

    (-1)前言 学习lamba表达式是十分重要的,你会发现java变的可爱多了. (0)函数式接口 只有一个方法的接口称为函数式接口 JButton jButton = new JButton(&quo ...

  8. SQL基础笔记

    Codecademy中Learn SQL, SQL: Table Transformaton和SQL: Analyzing Business Metrics三门课程的笔记,以及补充的附加笔记. Cod ...

  9. OpenGl编程指南第7版(红宝书)环境配制

    环境 OS:win7 旗舰版SP1 64位 编译器: VS 2013 express 的cl 软件 glut. 在这个页面https://www.opengl.org/resources/librar ...

  10. 一张图理解RACSignal的Subscription过程

    通过下面一张图理解RACSignal的调用过程: 创建signale RACSignal通过子类[RACDynamicSignal createSignal:]方法获得Signal,并将disSubs ...