题目链接: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. delphi locate函数的使用

    loc1:= qry1.FieldbyName('SPBM').AsString;      //商品编码 loc2:= qry1.FieldbyName('XH').AsString;       ...

  2. UESTC 1832

    今天比赛的时候做的一个题目.感觉这个题目不错. 题目描述: Description In a laboratory, an assistant, Nathan Wada, is measuring w ...

  3. BZOJ1226 SDOI2009学校食堂(状压dp)

    由于Bi<=7,考虑状压. 如果考虑前i个位置的话,状态里需要压入前7个人后7个人,显然是跑不动的. 那么改成考虑前i个人.于是设f[i][j][k]表示前i个人都已吃完饭,i+1后面7个人的吃 ...

  4. HotSpot垃圾收集器GC的种类

      堆内存的结构:

  5. [洛谷P4819][中山市选]杀人游戏

    题目大意:有一张$n$个点$m$条边的有向图,有一个关键点,如果你访问一个点,你会知道它连出的边中有没有关键点,以及若有的话是哪个.问最优策略下不访问关键点而知道关键点的概率 题解:发现若一个点不是关 ...

  6. 【CF739E】Gosha is hunting(动态规划,凸优化)

    [CF739E]Gosha is hunting(动态规划,凸优化) 题面 洛谷 CF 题解 一个\(O(n^3)\)的\(dp\)很容易写出来. 我们设\(f[i][a][b]\)表示前\(i\)个 ...

  7. 模板:插头dp

    前言: 严格来讲有关dp的都不应该叫做模板,因为dp太活了,但是一是为了整理插头dp的知识,二是插头dp有良好的套路性,所以姑且还叫做模板吧. 这里先推荐一波CDQ的论文和这篇博客http://www ...

  8. 遇到问题----mongodb-----mongorestore报错too many open files甚至mongo服务崩溃

    之前运行mongorestore还原mongodb数据库一直都没问题,今天还原的时候 报错too many open files.而且mongo服务经常崩溃需要重启. 问题有两方面: 原因一 一个原因 ...

  9. windows10下R配置Rstdio,怎么处理

    首先要确保电脑上只有一个R程序,然后官网下载Rstdio安装包. 配置:选择Rstdio配置界面的第三项,然后关联到R的安装文件夹下的BIN文件夹即可. 但是,直接打开Rstdio的话,界面会一片空白 ...

  10. Tweepy1——抓取Twitter数据

    sklearn实战-乳腺癌细胞数据挖掘 https://study.163.com/course/introduction.htm?courseId=1005269003&utm_campai ...