洛谷 P1640 【连续攻击游戏】
- question bank :luogu
- question Number :1640
- title :Continuous attacking game
- link :https://www.luogu.org/problem/P1640
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 【连续攻击游戏】的更多相关文章
- 【二分图】洛谷P1640连续攻击游戏
题目描述 lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示.当他使用某种装备时,他只能使用该装备的某一个属性.并且每种装备 ...
- 洛谷 P2197 nim游戏
洛谷 P2197 nim游戏 题目描述 甲,乙两个人玩Nim取石子游戏. nim游戏的规则是这样的:地上有n堆石子(每堆石子数量小于10000),每人每次可从任意一堆石子里取出任意多枚石子扔掉,可以取 ...
- 洛谷 P1965 转圈游戏
洛谷 P1965 转圈游戏 传送门 思路 每一轮第 0 号位置上的小伙伴顺时针走到第 m 号位置,第 1 号位置小伙伴走到第 m+1 号位置,--,依此类推,第n − m号位置上的小伙伴走到第 0 号 ...
- 洛谷 P1640 [SCOI2010]连续攻击游戏 解题报告
P1640 [SCOI2010]连续攻击游戏 题目描述 lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示.当他使用某种装备 ...
- 洛谷——P1640 [SCOI2010]连续攻击游戏
P1640 [SCOI2010]连续攻击游戏 题目描述 lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示.当他使用某种装备 ...
- 洛谷 P1640 [SCOI2010]连续攻击问题
洛谷 一句话题意: 每个武器有两种属性,每种武器只能选择一种属性,从属性1连续递增才算攻击,求最大连续攻击次数. 因为同学告诉我这是二分图最大匹配,自然就往那个方向去想. 那么怎么建图呢? 每个武器只 ...
- 洛谷 P1000 超级玛丽游戏
P1000 超级玛丽游戏 题目背景 本题是洛谷的试机题目,可以帮助了解洛谷的使用. 建议完成本题目后继续尝试P1001.P1008. 题目描述 超级玛丽是一个非常经典的游戏.请你用字符画的形式输出超级 ...
- 【流水调度问题】【邻项交换对比】【Johnson法则】洛谷P1080国王游戏/P1248加工生产调度/P2123皇后游戏/P1541爬山
前提说明,因为我比较菜,关于理论性的证明大部分是搬来其他大佬的,相应地方有注明. 我自己写的部分换颜色来便于区分. 邻项交换对比是求一定条件下的最优排序的思想(个人理解).这部分最近做了一些题,就一起 ...
- $loj10156/$洛谷$2016$ 战略游戏 树形$DP$
洛谷loj Desription Bob 喜欢玩电脑游戏,特别是战略游戏.但是他经常无法找到快速玩过游戏的方法.现在他有个问题. 现在他有座古城堡,古城堡的路形成一棵树.他要在这棵树的节点上放置最少数 ...
- 洛谷P1000 超级玛丽游戏(洛谷新手村1-1-1)
题目背景 本题是洛谷的试机题目,可以帮助了解洛谷的使用. 建议完成本题目后继续尝试P1001.P1008. 题目描述 超级玛丽是一个非常经典的游戏.请你用字符画的形式输出超级玛丽中的一个场景. *** ...
随机推荐
- 敏捷和DevOps:是敌是友?
DevOps是敏捷在软件开发团队的另一应用.那么相比之下,哪个更胜一筹? 一边,有业界认可的scrum master,它的朋友极限编程者,以及由其衍生的 LeSS.SAFe.DAD等,是敏捷. 另一边 ...
- Linux命令(部分)
LINUX:实现某一功能,命令执行依赖于解释器程序. 内部:属于shell部分 外部:独立于shell解释器程序. 系统结构由外到内:用户 ⇢ 外围程序 ⇢ 硬件 ...
- HTML第六章 盒子模型
什么是盒子模型: (1)边框: (2)内边距: (3)外边距: (4)元素内容·: (5)背景色·: 边框: 属性: 颜色(border-color),粗细(border-width),样式(bord ...
- 一文读懂JS中的原型和原型链(图解)
讲原型的时候,我们应该先要记住以下几个要点,这几个要点是理解原型的关键: 1.所有的引用类型(数组.函数.对象)可以自由扩展属性(除null以外). 2.所有的引用类型都有一个’_ _ proto_ ...
- react-native 入门基础介绍
目录 安装 项目 主要目录结构 入口 Home模块 Coobook模块 List模块 novel模块 相关参考 一个简单的demo,用于介绍react-native相关基础信息,主要是针对有兴趣的同学 ...
- Java程序员备战“金九银十”必备的面试技巧(附携程Java岗面试题)
一.面试前的准备 1.1 如何准备一场面试1.1.1 如何获取大厂面试机会1.1.2 面试必知 ①. 准备介绍自己 ②. 关于着装 ③ .随身带上自己的成绩单和简历 ④. 如果笔试就提前刷一些笔试题 ...
- WPF中TimeSpan的坑
记一次在WPF中,在将格式为“DD.HH:mm:ss”字符串转换成TimeSpan时遇到的坑 如果字符串为:DD.HH:mm:ss,转换结果正确.例如: var currentValue = &quo ...
- (二十二)c#Winform自定义控件-半透明窗体
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- 【资源共享】eBook分享大集合
传送门:[GitHub] 欢迎各位指点,要是能补充更是感激不尽. 主要以IT领域经典书籍收藏,以备不时之需,不一定都能看完,权且当做收藏好玩. [x] 表示文件大小超过100M(LFS). 服务器系统 ...
- linux+jenkins+python+svn 自动化测试集成之路
本文背景: 背景1---个人基础: 本机win7上安装pycharm,使用python搭建API自动化测试框架,本地运行Pass.本机上搭建jenkins,创建测试任务,定时构建Pass. 背景2-- ...