【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]之间的数表示.当他使用某种装备时,他只能使用该装备的某一个属性.并且每种装备 ...
随机推荐
- 突破Http协议
突破Http协议 我到不先说什么Http什么的,对于HTTP的彻底理解是http是应用层的一个程序,就像我们写的诸多客户端和服务器模型,我们可能为了可靠,为了方便数据的解析,我们在数据包中其实就是结构 ...
- 2.3 js基础--DOM
一.javascript组成 ECMAScript:核心解释器[为我们提供好了最基本的功能:变量声明.函数.语法.运算]. 兼容性:完全兼容. DoM:文档对象 ...
- 【Shell】运行shell出现-ash: ./test.sh: not found
1.这是一个读取文件的脚本 #!/bin/bash for line in `cat pidtestconf` do echo $line done 因为命名的时候这边使用的是 test.sh 这边将 ...
- winfrom 树勾选
树勾选 /// <summary> /// 树勾选 /// </summary> /// <param name="sender"></p ...
- java版两人聊天程序
server.java import java.io.*; import java.net.*; import java.text.SimpleDateFormat; import java.util ...
- linux下快速安装python3.xx
安装python3之前的准备工作: 当前环境是centos操作系统[已经安装了gcc++],在安装前需要安装zlib-devel包: yum install zlib-devel yum instal ...
- 转载:.NET Memory Leak: XmlSerializing your way to a Memory Leak
原文地址:http://blogs.msdn.com/b/tess/archive/2006/02/15/532804.aspx I hate to give away the resolution ...
- HDU 5215 Cycle(dfs判环)
题意 题目链接 \(T\)组数据,给出\(n\)个点\(m\)条边的无向图,问是否存在一个奇环/偶环 Sol 奇环比较好判断吧,直接判是否是二分图就行了.. 偶环看起来很显然就是如果dfs到一个和他颜 ...
- cordova 开发 android app 简要流程
1. 安装cordova:npm install -g cordova --registry=https://registry.npm.taobao.org 2. 创建cordova工程:进入工作目录 ...
- android Viewpager取消预加载及Fragment方法的学习
1.在使用ViewPager嵌套Fragment的时候,由于VIewPager的几个Adapter的设置来说,都会有一定的预加载.通过设置setOffscreenPageLimit(int numbe ...