BNUOJ 12756 Social Holidaying(二分匹配)
题目链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=12756
Social Holidaying
64-bit integer IO format: %lld Java class name: Main
None
Graph Theory
2-SAT
Articulation/Bridge/Biconnected Component
Cycles/Topological Sorting/Strongly Connected Component
Shortest Path
Bellman Ford
Dijkstra/Floyd Warshall
Euler Trail/Circuit
Heavy-Light Decomposition
Minimum Spanning Tree
Stable Marriage Problem
Trees
Directed Minimum Spanning Tree
Flow/Matching
Graph Matching
Bipartite Matching
Hopcroft–Karp Bipartite Matching
Weighted Bipartite Matching/Hungarian Algorithm
Flow
Max Flow/Min Cut
Min Cost Max Flow
DFS-like
Backtracking with Pruning/Branch and Bound
Basic Recursion
IDA* Search
Parsing/Grammar
Breadth First Search/Depth First Search
Advanced Search Techniques
Binary Search/Bisection
Ternary Search
Geometry
Basic Geometry
Computational Geometry
Convex Hull
Pick's Theorem
Game Theory
Green Hackenbush/Colon Principle/Fusion Principle
Nim
Sprague-Grundy Number
Matrix
Gaussian Elimination
Matrix Exponentiation
Data Structures
Basic Data Structures
Binary Indexed Tree
Binary Search Tree
Hashing
Orthogonal Range Search
Range Minimum Query/Lowest Common Ancestor
Segment Tree/Interval Tree
Trie Tree
Sorting
Disjoint Set
String
Aho Corasick
Knuth-Morris-Pratt
Suffix Array/Suffix Tree
Math
Basic Math
Big Integer Arithmetic
Number Theory
Chinese Remainder Theorem
Extended Euclid
Inclusion/Exclusion
Modular Arithmetic
Combinatorics
Group Theory/Burnside's lemma
Counting
Probability/Expected Value
Others
Tricky
Hardest
Unusual
Brute Force
Implementation
Constructive Algorithms
Two Pointer
Bitmask
Beginner
Discrete Logarithm/Shank's Baby-step Giant-step Algorithm
Greedy
Divide and Conquer
Dynamic Programming
Tag it!
Source
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; int ss[],Map[][];
int ok[],vis[];
int a[],b[];
int n,m; bool Find(int x)
{
for (int i=; i<=n; i++)
{
if (!vis[i]&&Map[x][i]==)
{
vis[i]=;
if (!ok[i])
{
ok[i]=x;
return true;
}
else
{
if (Find(ok[i]))
{
ok[i]=x;
return true;
}
}
}
}
return false;
} int main()
{
int t;
scanf("%d",&t);
while (t--)
{
scanf("%d%d",&n,&m);
int ans=;
memset(vis,,sizeof(vis));
memset(Map,,sizeof(Map));
memset(ok,,sizeof(ok));
memset(ss,,sizeof(ss));
for (int i=; i<=n; i++)
{
scanf("%d",&a[i]);
}
for (int i=; i<=m; i++)
{
scanf("%d",&b[i]);
ss[b[i]]=;
}
for (int i=; i<=n; i++)
{
for (int j=i+; j<=n; j++)
{
if (ss[a[i]+a[j]]==)
Map[i][j]=Map[j][i]=;
}
}
for (int i=; i<=n; i++)
{
memset(vis,,sizeof(vis));
if (Find(i))
ans++;
}
printf ("%d\n",ans/);
}
return ;
}
BNUOJ 12756 Social Holidaying(二分匹配)的更多相关文章
- UVA5874 Social Holidaying 二分匹配
二分匹配简单题,看懂题意,建图比较重要. #include<stdio.h> #include<string.h> #define maxn 1100 int map[maxn ...
- POJ 1274 The Perfect Stall、HDU 2063 过山车(最大流做二分匹配)
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24081 Accepted: 106 ...
- [kuangbin带你飞]专题十 匹配问题 二分匹配部分
刚回到家 开了二分匹配专题 手握xyl模板 奋力写写写 终于写完了一群模板题 A hdu1045 对这个图进行 行列的重写 给每个位置赋予新的行列 使不能相互打到的位置 拥有不同的行与列 然后左行右列 ...
- BZOJ 1189 二分匹配 || 最大流
1189: [HNOI2007]紧急疏散evacuate Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1155 Solved: 420[Submi ...
- Kingdom of Obsession---hdu5943(二分匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5943 题意:给你两个数n, s 然后让你判断是否存在(s+1, s+2, s+3, ... , s+n ...
- poj 2060 Taxi Cab Scheme (二分匹配)
Taxi Cab Scheme Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5710 Accepted: 2393 D ...
- [ACM_图论] Sorting Slides(挑选幻灯片,二分匹配,中等)
Description Professor Clumsey is going to give an important talk this afternoon. Unfortunately, he i ...
- [ACM_图论] The Perfect Stall 完美的牛栏(匈牙利算法、最大二分匹配)
描述 农夫约翰上个星期刚刚建好了他的新牛棚,他使用了最新的挤奶技术.不幸的是,由于工程问题,每个牛栏都不一样.第一个星期,农夫约翰随便地让奶牛们进入牛栏,但是问题很快地显露出来:每头奶牛都只愿意在她们 ...
- nyoj 237 游戏高手的烦恼 二分匹配--最小点覆盖
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=237 二分匹配--最小点覆盖模板题 Tips:用邻接矩阵超时,用数组模拟邻接表WA,暂时只 ...
随机推荐
- mysql实现消息队列
mysql之消息队列 消息队列:在消息的传输过程中保存消息的容器. 消息队列管理器在将消息从它的源中继到它的目标时充当中间人.队列的主要目的是提供路由并保证消息的传递:如果发送消息时接收者不可用, ...
- Memcache 服务管理脚本
自定义脚本将memcached作为系统服务启动以及开机启动. 一.编写脚本 在/etc/init.d/目录下新建一个脚本,名称为:memcached.内容如下: vi /etc/init.d/memc ...
- 【刷题】BZOJ 3667 Rabin-Miller算法
Input 第一行:CAS,代表数据组数(不大于350),以下CAS行,每行一个数字,保证在64位长整形范围内,并且没有负数.你需要对于每个数字:第一,检验是否是质数,是质数就输出Prime 第二,如 ...
- 【刷题】BZOJ 2693 jzptab
Description Input 一个正整数T表示数据组数 接下来T行 每行两个正整数 表示N.M Output T行 每行一个整数 表示第i组数据的结果 Sample Input 1 4 5 Sa ...
- BZOJ 3143 游走 | 数学期望 高斯消元
啊 我永远喜欢期望题 BZOJ 3143 游走 题意 有一个n个点m条边的无向联通图,每条边按1~m编号,从1号点出发,每次随机选择与当前点相连的一条边,走到这条边的另一个端点,一旦走到n号节点就停下 ...
- 【科技】KD-tree随想
大概就是个复杂度对的暴力做法,在你不想写二维线段树等的时候优秀的替代品. 优点:思路简单,代码好写. 他大概有两种用法(虽然差不多). 在平面坐标系中干一些事情: 例如最常规的平面最近最远点,不管是欧 ...
- 洛谷 P1777 帮助_NOI导刊2010提高(03) 解题报告
P1777 帮助_NOI导刊2010提高(03) 题目描述 Bubu的书架乱成一团了!帮他一下吧! 他的书架上一共有n本书.我们定义混乱值是连续相同高度书本的段数.例如,如果书的高度是30,30,31 ...
- BAT脚本如何自动执行 adb shell 以后的命令
@echo off echo su > temp.txt echo 其它命令 >> temp.txt adb shell < temp.txt del temp.txt 求问 ...
- struts的namespace理解
转载: namespace决定了action的访问路径,默认为"",可以接受所有路径的action namespace可以写为/,或者/xxx,或者/xxx/yyy,对应的acti ...
- 802.11 ------ Beacon帧、Beacon Interval、TBTT、Listen Interval、TIM、DTIM
Beacon帧:Beacon的实际发送一般都是采用最低速率的,其包含两个原因,1)beacon帧是一个广播帧,其没有ACK反馈,所以无法设置重传机制,2)beacon帧目的是广播AP的基本信息,所以希 ...