Counting Pair
Counting Pair
Time Limit: 1000 ms Memory Limit: 65535 kB Solved: 112 Tried: 1209
Submit
Status
Best Solution
Back
Description
Bob hosts a party and invites N boys and M girls. He gives every boy here a unique number Ni(1 <= Ni <= N). And for the girl, everyone holds a unique number Mi(1 <= Mi <= M), too.
Now when Bob name a number X, if a boy and a girl wants and their numbers' sum equals to X, they can get in pair and dance.
At this night, Bob will name Q numbers, and wants to know the maxinum pairs could dance in each time. Can you help him?
Input
First line of the input is a single integer T(1 <= T <= 30), indicating there are T test cases.
The first line of each test case contains two numbers N and M(1 <= N,M <= 100000).
The second line contains a single number Q(1 <= Q <= 100000).
Each of the next Q lines contains one number X(0 <= X <= 10^9), indicating the number Bob names.
Output
For each test case, print "Case #t:" first, in which t is the number of the test case starting from 1.
Then for each number Bob names, output a single num in each line, which shows the maxinum pairs that could dance together.
Sample Input
1
4 5
3
1
2
3
Sample Output
Case #1:
0
1
2
Hint
This problem has very large input data. scanf and printf are recommended for C++ I/O.
Source
Sichuan State Programming Contest 2012
#include <iostream>
#include <queue>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath> using namespace std; int T, N, M, Q, s, cnt; int main()
{
scanf("%d", &T);
for(int ca = ; ca <= T; ca++)
{
scanf("%d %d", &N, &M);
scanf("%d", &Q);
printf("Case #%d:\n", ca);
while(Q--)
{
scanf("%d", &s);
if(s <= || s > M + N) cnt = ;
else
{
if(N < M) swap(M, N);
if(s <= M) cnt = s - ;
else if(s > M && s <= N) cnt = M;
else if(s > N) cnt = M + N - s + ;
}
printf("%d\n",cnt);
}
}
return ;
}
Counting Pair的更多相关文章
- bnuoj 24251 Counting Pair
一道简单的规律题,画出二维表将数字分别相加可以发现很明显的对称性 题目链接:http://www.bnuoj.com/v3/problem_show.php?pid=24251 #include< ...
- Sichuan State Programming Contest 2012 C。Counting Pair
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=118254#problem/C 其实这道题目不难...就是没有仔细分析... 我们可以发现 ...
- HDU 4358 Boring counting(莫队+DFS序+离散化)
Boring counting Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 98304/98304 K (Java/Others) ...
- HDU 1264 Counting Squares(线段树求面积的并)
Counting Squares Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- SDUT 2610 Boring Counting(离散化+主席树区间内的区间求和)
Boring Counting Time Limit: 3000MS Memory Limit: 65536KB Submit Statistic Discuss Problem Descriptio ...
- HDU 5952 Counting Cliques 【DFS+剪枝】 (2016ACM/ICPC亚洲区沈阳站)
Counting Cliques Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- BZOJ2023: [Usaco2005 Nov]Ant Counting 数蚂蚁
2023: [Usaco2005 Nov]Ant Counting 数蚂蚁 Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 56 Solved: 16[S ...
- Counting Islands II
Counting Islands II 描述 Country H is going to carry out a huge artificial islands project. The projec ...
- Counting Intersections
Counting Intersections Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/ ...
随机推荐
- 自我介绍for软件工程课程
石家庄铁道大学学生,正在学习软件工程课程. 对于软件工程课程,没什么太大的希望.度了一下,发现软件工程课程近年来比较脱节,这次用新课本不知道效果怎么样.嗯,等课本到手看看再说吧. 自己的目标:我希望能 ...
- Python:生成器的简单理解
一.什么是生成器 在Python中,由于受到内存的限制,列表容量肯定是有限的.例如我们创建一个包含一亿个元素的列表,Python首先会在内存中开辟足够的空间来存储这个包含一亿个元素的列表,然后才允许用 ...
- Python安装Numpy,matplotlib库
<1> Numpy是一款基于python的功能强大的科学计算包.要安装numpy首先你得先安装python. python的安装非常简单,本人安装的是python2.7 具体安装步骤如下: ...
- Communications link failure--分析之(JDBC的多种超时情况)
本文是针对特定的情景下的特定错误,不是所有Communications link failure错误都是这个引起的,重要的区分特点是:程序是不是在卡主后两个小时(服务器的设置)后程序才感知到,才抛出了 ...
- 判断一个变量是不是json,以及如何将变量转换成json
https://blog.csdn.net/A123638/article/details/52486975这里看到一个很好的方法 // 判断变量是不是jsonisJson(variable: any ...
- linux学习笔记4
查看当前系统还有哪些用户 who 字符计数 wc -l(line) 可以统计有多少行 -w(word) 可以统计有多少个单词 -c(character) 可以统计有多少个字符 切个字符 - 排序 l ...
- javascript之彻底理解valueOf, toString
参与运算的都是简单类型(一般就字符串和数字), 复杂类型是不参与运算的. ***当对象(非简单类型)用作键时,会先调用toString()方法把对象转化成字符串 var a = {}, b = ...
- java & maven pom
java & maven pom https://maven.apache.org/pom.html http://www.tutorialspoint.com/maven/maven_pom ...
- dom对象转成jquery对象时候 变成数组 jquery转成dom时候 取数组第一个
- AtCoder Grand Contest 019 B: Reverse and Compare
题意: 给出一个字符串,你可以选择一个长度大于等于1的子串进行翻转,也可以什么都不做.只能翻转最多一次. 问所有不同的操作方式得到的字符串中有多少个是本质不同的. 分析 tourist的题妙妙啊. 首 ...