洛谷 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. 题目描述 超级玛丽是一个非常经典的游戏.请你用字符画的形式输出超级玛丽中的一个场景. *** ...
随机推荐
- 03-k8s认证
目录 k8s认证 客户端 ---> API Server 外部访问 pod 客户端 RBCA k8s 用户类型 dashboard 的认证登录 k8s认证 主要使用 RBAC授权检查机制 认证: ...
- 【iOS】Your account already has a valid ios
打包内测的时候遇到了这个问题,如图所示: 官网解决办法: If the certificate already exists in Member Center, a “Your account alr ...
- MOCTF-WEB-writeup
MOCTF-WEB-writeup 好菜,除了简单的几个题,自己会做,难的都是看老大WP完成的,太菜了 啥姿势都不会,就此记录一下,供日后查看及反省.菜鸡的自我修养 0x01 一道水题 题目链接:ht ...
- 100天搞定机器学习|Day15 朴素贝叶斯
Day15,开始学习朴素贝叶斯,先了解一下贝爷,以示敬意. 托马斯·贝叶斯 (Thomas Bayes),英国神学家.数学家.数理统计学家和哲学家,1702年出生于英国伦敦,做过神甫:1742年成为英 ...
- 什么是Singleton?
Singleton:在Java中即指单例设计模式,它是软件开发中最常用的设计模式之一. 单:指唯一 例:指实例 单例设计模式,即某个类在整个系统中只能有一个实例对象可被获取和使用的代码模式. 要点: ...
- 【0809 | Day 12】可变长参数/函数的对象/函数的嵌套/名称空间与作用域
可变长参数 一.形参 位置形参 默认形参 二.实参 位置实参 关键字实参 三.可变长参数之* def func(name,pwd,*args): print('name:',name,'pwd:',p ...
- 【数据结构】线段树(Segment Tree)
假设我们现在拿到了一个非常大的数组,对于这个数组里面的数字要反复不断地做两个操作. 1.(query)随机在这个数组中选一个区间,求出这个区间所有数的和. 2.(update)不断地随机修改这个数组中 ...
- 编译Assimp傻瓜教程
assimp的编译过程和搭建OpenGL环境时glfw的编译基本相同,建议先阅读环境搭建 下载源码 这里使用的是3.3.1版本,Github下载assimp源码 解压完你会得到 接下来我们要编译这些源 ...
- SIMBOSS:物联网业务如何应用领域驱动设计?
前言 在这个万物互联的时代,物联网业务蓬勃发展,但也瞬息万变,对于开发人员来说,这是一种挑战,但也是一种“折磨”. 在业务发展初期,因为时间有限,我们一般会遵循“小步快跑,迭代试错”的原则进行业务开发 ...
- 解决pyinstaller打包可执行文件,存放路径包含中文无法运行的问题
一.实验环境 1.Windows7x64_SP1 2.anaconda2.5.0 + python2.7(anaconda集成,不需单独安装) 3.pyinstaller3.0 二.问题描述 1.使用 ...