【luogu P1640 [SCOI2010]连续攻击游戏】 题解
题目链接:https://www.luogu.org/problemnew/show/P1640
数据有点水吧,从属性值连向对应武器编号。
枚举属性值匹配,遇到第一个无法匹配的直接跳出就好惹~。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
inline int read()
{
int ret=0;
char c=getchar();
while (c<'0' || c>'9') c=getchar();
while (c>='0' && c<='9'){
ret=((ret<<3)+(ret<<1))+c-'0';
c=getchar();
}
return ret;
}
const int maxn = 500000+1;
int n, ans, cnt;
int link[maxn], head[maxn];
bool vis[maxn];
struct edge{
int v,next;
}e[maxn<<2];
void add(int u, int v)
{
e[++cnt].v = v;
e[cnt].next = head[u];
head[u] = cnt;
}
bool dfs(int u)
{
int v = head[u];
for(int i = v; i != 0; i = e[i].next)
{
if(!vis[e[i].v])
{
vis[e[i].v] = 1;
if(!link[e[i].v] || dfs(link[e[i].v]))
{
link[e[i].v] = u;
return 1;
}
}
}
return 0;
}
int main()
{
int u,v;
n = read();
for(int i = 1; i <= n; i++)
{
u = read(); v = read();
add(u,i);
add(v,i);
}
for(int i = 1; i <= n; i++)
{
memset(vis,0,sizeof(vis));
if(dfs(i)) ans++;
else break;
}
printf("%d\n",ans);
return 0;
}
【luogu P1640 [SCOI2010]连续攻击游戏】 题解的更多相关文章
- 洛谷P1640 [SCOI2010]连续攻击游戏 题解
题目链接: https://www.luogu.org/problemnew/show/P1640 分析: 这道题用二分图来解决即可.应该可以作为网络流中的模板题来食用, 每一个武器有两个属性,但是只 ...
- 洛谷 P1640 [SCOI2010]连续攻击游戏 解题报告
P1640 [SCOI2010]连续攻击游戏 题目描述 lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示.当他使用某种装备 ...
- [Luogu 1640] SCOI2010 连续攻击游戏
[Luogu 1640] SCOI2010 连续攻击游戏 DP太恶心,回来二分图这边放松一下心智. 这个建图真的是难以想到. 因为要递增啊,属性值放x部,装备放y部,对应连边跑Hungary就好了. ...
- 洛谷——P1640 [SCOI2010]连续攻击游戏
P1640 [SCOI2010]连续攻击游戏 题目描述 lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示.当他使用某种装备 ...
- BZOJ1854:[SCOI2010]连续攻击游戏——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=1854 https://www.luogu.org/problemnew/show/P1640 lxh ...
- P1640 [SCOI2010]连续攻击游戏 二分图构造
https://www.luogu.org/problemnew/show/P1640 题意 lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10 ...
- 洛谷P1640 [SCOI2010]连续攻击游戏(二分图)
题目描述 lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示.当他使用某种装备时,他只能使用该装备的某一个属性.并且每种装备 ...
- 洛谷—— P1640 [SCOI2010]连续攻击游戏
https://www.luogu.org/problem/show?pid=1640 题目描述 lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1, ...
- P1640 [SCOI2010]连续攻击游戏 二分图最大匹配 匈牙利算法
题目描述 lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示.当他使用某种装备时,他只能使用该装备的某一个属性.并且每种装备 ...
随机推荐
- TOJ 3184 Mine sweeping
描述 I think most of you are using system named of xp or vista or win7.And these system is consist of ...
- 【算法】K-Means聚类算法(k-平均或k-均值)
1.聚类算法和分类算法的区别 a)分类 分类(Categorization or Classification)就是按照某种标准给对象贴标签(label),再根据标签来区分归类. 举例: 假如你有一堆 ...
- BulletedList项目控件基础CSS基础
呈现形态&控件语法: <ul id=“...”> <li></li> . <li></li> . <li></li ...
- HDU 5007 字符串匹配
http://acm.hust.edu.cn/vjudge/contest/122814#problem/A 匹配到字符串就输出,水题,主要是substr的运用 #include <iostre ...
- initBinder转换日期格式
@Controller public class FirstController { @RequestMapping("/first") //类型转化工作一定是在真正的handle ...
- link 和 import 导入外部样式的区别
差别一:link 属于 XHTML 标签,而 @import 完全是 CSS 提供的 一种方式.link标签除了可以加载 CSS 外,还可以做很多事情,比如定义 RSS ,定义 rel 链接属性等. ...
- 【Linux】IPC-消息队列
问题 消息队列id 和键值KEY区别? 首先要注意一个概念:IPC结构都是内核的结构.也就是说IPC结构由内核维护,对于每个进程都是公共的,不属于某个特定进程.只有这样,IPC结构才能支持它们&quo ...
- CSS3布局样式
CSS3多列布局columns 为了能在Web页面中方便实现类似报纸.杂志那种多列排版的布局,W3C特意给CSS3增加了一个多列布局模块(CSS Multi Column Layout Module) ...
- qt打开url
QDesktopServices::openUrl(QUrl(QLatin1String(“http://blog.const.net.cn“)))
- CodeMirror教程,CodeMirrorAPI中文信息
<html> <head> <link rel="stylesheet" href="codemirror.css"> ...