题目链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=12756

Social Holidaying

Time Limit: 3000ms
Memory Limit: 131072KB
 
This problem will be judged on UVALive. Original ID: 5874
64-bit integer IO format: %lld      Java class name: Main
Font Size: + -
Type:  
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

 
题目大意:先输入一个P表示有几组测试数据,再输入一个n,m分别表示A、B集合中分别有多少元素。在A集合中找到多少对数相加=B集合中的元素。A集合中的数不可以重复,但是B集合中的数字可以重复出现。
解题思路:二分匹配。先将A集合中的和的所有可能情况列出来,然后在B集合中搜索即可。
 
详见代码。
 #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(二分匹配)的更多相关文章

  1. UVA5874 Social Holidaying 二分匹配

    二分匹配简单题,看懂题意,建图比较重要. #include<stdio.h> #include<string.h> #define maxn 1100 int map[maxn ...

  2. POJ 1274 The Perfect Stall、HDU 2063 过山车(最大流做二分匹配)

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24081   Accepted: 106 ...

  3. [kuangbin带你飞]专题十 匹配问题 二分匹配部分

    刚回到家 开了二分匹配专题 手握xyl模板 奋力写写写 终于写完了一群模板题 A hdu1045 对这个图进行 行列的重写 给每个位置赋予新的行列 使不能相互打到的位置 拥有不同的行与列 然后左行右列 ...

  4. BZOJ 1189 二分匹配 || 最大流

    1189: [HNOI2007]紧急疏散evacuate Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1155  Solved: 420[Submi ...

  5. Kingdom of Obsession---hdu5943(二分匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5943 题意:给你两个数n, s 然后让你判断是否存在(s+1, s+2, s+3, ... , s+n ...

  6. poj 2060 Taxi Cab Scheme (二分匹配)

    Taxi Cab Scheme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5710   Accepted: 2393 D ...

  7. [ACM_图论] Sorting Slides(挑选幻灯片,二分匹配,中等)

    Description Professor Clumsey is going to give an important talk this afternoon. Unfortunately, he i ...

  8. [ACM_图论] The Perfect Stall 完美的牛栏(匈牙利算法、最大二分匹配)

    描述 农夫约翰上个星期刚刚建好了他的新牛棚,他使用了最新的挤奶技术.不幸的是,由于工程问题,每个牛栏都不一样.第一个星期,农夫约翰随便地让奶牛们进入牛栏,但是问题很快地显露出来:每头奶牛都只愿意在她们 ...

  9. nyoj 237 游戏高手的烦恼 二分匹配--最小点覆盖

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=237 二分匹配--最小点覆盖模板题 Tips:用邻接矩阵超时,用数组模拟邻接表WA,暂时只 ...

随机推荐

  1. C++模式学习------模板模式

    模板模式: 定义一个操作中的算法的骨架,而将一些步骤延迟到子类中.模板方法使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤. 模板模式是一种很常用的模式,在很多的框架或者基类重载的时候都 ...

  2. D-Separation(D分离)-PRML-8.22-Graphical Model 五 18 by 小军

    D-Separation(D分离)-PRML-8.22-Graphical Model 五18by 小军   一.引言 在贝叶斯网络的学习过程中,经常会遇到(D-Separation)D-分离这个概念 ...

  3. 【bzoj1194】 HNOI2006—潘多拉的盒子

    http://www.lydsy.com/JudgeOnline/problem.php?id=1194 (题目链接) 题意 给出S个自动机,如果一个自动机u的所有状态是另一个自动机v的状态的子集,那 ...

  4. 安装配置openstack-dashboard(horizon)

    这里把dashboard安装在controller节点上. 1.安装程序包 # yum install -y openstack-dashboard 2.修改配置文件 # vim /etc/opens ...

  5. Linux使用vim进行多文件查找和替换的方法

    vim是Linux系统下常用的文本编辑,通过使用多种shell命令能够实现多文件的查找和替换,那么具体会使用到那些命令呢?下面小编就给大家介绍下Linux系统vim多文件查找和替换的方法. 在linu ...

  6. 前端学习 -- Xhtml语法规范

    Xhtml语法规范 HTML中不区分大小写,但是尽量使用小写: HTML的注释不能嵌套: 标签必须结构完整{要么成对出现,要么自结束标签,虽然浏览器会帮我们修正一些不符合规范的内容} 标签可以嵌套但是 ...

  7. 解题:SDOI 2014 数表

    题面 为了好写式子,先不管$a$的限制 设$facs$为因子和,那么有 $ans=\sum\limits_{i=1}^n\sum\limits_{j=1}^mfacs(gcd(i,j))$ 再设$f( ...

  8. 【Asp.net入门04】第一个ASP.NET 应用程序-如何添加Web窗体到网站中

    添加Web窗体 本部分内容: 什么是web form 怎样添加web form 1.添加Web窗体到项目中 Web 窗体是一项 ASP.NET 功能,您可以使用它为 Web 应用程序创建用户界面.We ...

  9. golang 中的 time 包的 Ticker

    真实的应用场景是:在测试收包的顺序的时候,加了个 tick 就发现丢包了 那么来看一个应用例子: package main import ( "fmt" "runtime ...

  10. Chapter One:数据结构和算法-解压序列赋值给多个变量

    一.问题: 现在有一个包含 N 个元素的元组或者是序列,怎样将它里面的值解压后同时赋值给 N 个变量? 二.解决方案: 代码示例: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 ...