Solution : At first you may have no idea of this subject,but there is a very ingenious train of thought. One thought would be to add two attributes of the same equipment,but this would be too hard to solve. So we have other thought : we can add the level of the attributes of the same equipment to the number of the equitment,then we use the bipartite graph. Because in the subject we can only use one attribute of one equipment && if we add  attributes level of the same equipment to the number of the equitment,the graph of the sample will be shown as below:

then we will realize that we can enumerate 1 ~ 10001(the attribute level) to run bipartite graph,if we can't find the equipment of that attribute level(there is no equipment of that level || that equipment used other attribute)then the answer is that attribute level - 1

code:

 #include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
using namespace std;
char buf[ << ];
char *p1 = buf;
char *p2 = buf;
template < class T >
inline void read(T & x)
{
x = ;
char c = getchar();
bool f = ;
for(; !isdigit(c); c = getchar())
{
f ^= c == '-';
}
for(; isdigit(c); c = getchar())
{
x = x * + (c ^ );
}
x = f ? -x : x;
return;
}
template < class T >
inline void write(T x)
{
if(x < )
{
putchar('-');
x = -x;
}
T y = ;
int len = ;
for(; y <= x / ; y *= )
{
++len;
}
for(; len; --len, x %= y, y /= )
{
putchar(x / y + );
}
return;
}
int n, choose[], vis[], num, head[], cnt;
struct node
{
int next, to;
}stu[];
inline void add(int x, int y)
{
stu[++num].next = head[x];
stu[num].to = y;
head[x] = num;
return;
}
inline int dfs(int u)//bipartite graph masterplate
{
for(register int i = head[u]; i; i = stu[i].next)
{
int k = stu[i].to;
if(vis[k] == cnt)//it is just the same as if(vis[k]),but we can't use memset(TLE) so we can only use this
{
continue;
}
vis[k] = cnt;//(self-understanding)
if(!choose[k] || dfs(choose[k]))
{
choose[k] = u;
return ;
}
}
return ;
}
signed main()
{
read(n);
for(register int i = , x, y; i <= n; ++i)
{
read(x);
read(y);
add(x, i);
add(y, i);
}
for(register int i = ; i <= ; ++i)//warning: to 10001 not to 10000(self-understanding)
{
//warning:you can't use memset here because that will TLE(O(10000 * n))
++cnt;//leave out the memset(self-understanding)
if(!dfs(i))
{
write(i - );
return ;
}
}
return ;
}

//2 hrs

洛谷 P1640 【连续攻击游戏】的更多相关文章

  1. 【二分图】洛谷P1640连续攻击游戏

    题目描述 lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示.当他使用某种装备时,他只能使用该装备的某一个属性.并且每种装备 ...

  2. 洛谷 P2197 nim游戏

    洛谷 P2197 nim游戏 题目描述 甲,乙两个人玩Nim取石子游戏. nim游戏的规则是这样的:地上有n堆石子(每堆石子数量小于10000),每人每次可从任意一堆石子里取出任意多枚石子扔掉,可以取 ...

  3. 洛谷 P1965 转圈游戏

    洛谷 P1965 转圈游戏 传送门 思路 每一轮第 0 号位置上的小伙伴顺时针走到第 m 号位置,第 1 号位置小伙伴走到第 m+1 号位置,--,依此类推,第n − m号位置上的小伙伴走到第 0 号 ...

  4. 洛谷 P1640 [SCOI2010]连续攻击游戏 解题报告

    P1640 [SCOI2010]连续攻击游戏 题目描述 lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示.当他使用某种装备 ...

  5. 洛谷——P1640 [SCOI2010]连续攻击游戏

    P1640 [SCOI2010]连续攻击游戏 题目描述 lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示.当他使用某种装备 ...

  6. 洛谷 P1640 [SCOI2010]连续攻击问题

    洛谷 一句话题意: 每个武器有两种属性,每种武器只能选择一种属性,从属性1连续递增才算攻击,求最大连续攻击次数. 因为同学告诉我这是二分图最大匹配,自然就往那个方向去想. 那么怎么建图呢? 每个武器只 ...

  7. 洛谷 P1000 超级玛丽游戏

    P1000 超级玛丽游戏 题目背景 本题是洛谷的试机题目,可以帮助了解洛谷的使用. 建议完成本题目后继续尝试P1001.P1008. 题目描述 超级玛丽是一个非常经典的游戏.请你用字符画的形式输出超级 ...

  8. 【流水调度问题】【邻项交换对比】【Johnson法则】洛谷P1080国王游戏/P1248加工生产调度/P2123皇后游戏/P1541爬山

    前提说明,因为我比较菜,关于理论性的证明大部分是搬来其他大佬的,相应地方有注明. 我自己写的部分换颜色来便于区分. 邻项交换对比是求一定条件下的最优排序的思想(个人理解).这部分最近做了一些题,就一起 ...

  9. $loj10156/$洛谷$2016$ 战略游戏 树形$DP$

    洛谷loj Desription Bob 喜欢玩电脑游戏,特别是战略游戏.但是他经常无法找到快速玩过游戏的方法.现在他有个问题. 现在他有座古城堡,古城堡的路形成一棵树.他要在这棵树的节点上放置最少数 ...

  10. 洛谷P1000 超级玛丽游戏(洛谷新手村1-1-1)

    题目背景 本题是洛谷的试机题目,可以帮助了解洛谷的使用. 建议完成本题目后继续尝试P1001.P1008. 题目描述 超级玛丽是一个非常经典的游戏.请你用字符画的形式输出超级玛丽中的一个场景. *** ...

随机推荐

  1. 高级查询语句____ Mysql

    MySQL高级查询 高级查询 关键字书写顺序  关键字执行顺序select:投影结果       1    5 from:定位到表             2    1 where:分组前第一道过滤  ...

  2. 如何编译生成Linux-C静态链接库

    目标生成的静态库文件为:libnpcp.a 举例:我们有四个文件分别为:npcp.c npcp.h other.h main.c main.h在npcp.c里面#include "other ...

  3. 定时延时设计FPGA

    以50MHZ时钟为例,进行1秒钟延时,并输出延时使能信号. 首先计算需要多少次计时,MHZ=10的六次方HZ.T=20ns 一秒钟需要计时次数为5的七次方即5000_0000. 然后计算需要几位的寄存 ...

  4. 向.Net/Unity 程序员推荐一个十分因吹斯听的网站:sharplab.io

    0x00 前言 & 过程 & 结论 今天发现了一个十分有趣的网站: https://sharplab.io/ 网站的页面并不复杂,功能大体上能够在题图中得到概括.发现它的过程也很偶然, ...

  5. JavaWeb——Filter过滤器

    1.Filter的目的 Filter用于在Servlet之前检测和修改请求和响应,它可以拒绝.重定向或转发请求.常见的有这几种: 日志过滤器 使用过滤器记录请求,提供请求日志记录,还可以添加追踪信息用 ...

  6. 使用DOM4J 对xml解析操作

    参考自:https://blog.csdn.net/redarmy_chen/article/details/12969219 dom4j是一个Java的XML API,类似于jdom,用来读写XML ...

  7. Ubuntu 16.04 安装 SVN-Client (RaabitVCS)

    1.添加源 sudo add-apt-repository ppa:rabbitvcs/ppa 2. 更新源 sudo apt-get update 3.安装依赖库 sudo apt-get inst ...

  8. Oracle Job定时任务详解、跨数据库数据同步

    业务需求,需要与A公司做数据对接,我们公司用的Oracle,A公司用的SQL Server数据库,如何跨数据库建立连接呢?这里使用的是DBLink,不会配置的请看我的另外一篇博客:https://ww ...

  9. VMware安装Centos7虚拟机

    首先安装虚拟机很简单,所以呢,具体的安装过程就引用别人的博客,这篇文字很详细,引用之后会在后面加上一些遇到的问题: 原文:https://blog.csdn.net/babyxue/article/d ...

  10. 无重复字符的最长子串[双指针+哈希表] LeetCode.3

    给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度. 示例 1: 输入: "abcabcbb" 输出: 3 解释: 因为无重复字符的最长子串是 "abc&qu ...