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的更多相关文章

  1. bnuoj 24251 Counting Pair

    一道简单的规律题,画出二维表将数字分别相加可以发现很明显的对称性 题目链接:http://www.bnuoj.com/v3/problem_show.php?pid=24251 #include< ...

  2. Sichuan State Programming Contest 2012 C。Counting Pair

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=118254#problem/C 其实这道题目不难...就是没有仔细分析... 我们可以发现 ...

  3. HDU 4358 Boring counting(莫队+DFS序+离散化)

    Boring counting Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 98304/98304 K (Java/Others) ...

  4. HDU 1264 Counting Squares(线段树求面积的并)

    Counting Squares Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. SDUT 2610 Boring Counting(离散化+主席树区间内的区间求和)

    Boring Counting Time Limit: 3000MS Memory Limit: 65536KB Submit Statistic Discuss Problem Descriptio ...

  6. HDU 5952 Counting Cliques 【DFS+剪枝】 (2016ACM/ICPC亚洲区沈阳站)

    Counting Cliques Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  7. BZOJ2023: [Usaco2005 Nov]Ant Counting 数蚂蚁

    2023: [Usaco2005 Nov]Ant Counting 数蚂蚁 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 56  Solved: 16[S ...

  8. Counting Islands II

    Counting Islands II 描述 Country H is going to carry out a huge artificial islands project. The projec ...

  9. Counting Intersections

    Counting Intersections Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/ ...

随机推荐

  1. DCOM初步窥探二

    1.COM进程透明性表现在“组件对象和客户程序可以拥有各自的空间,也可以共享同一个进程空间”. COM负责把客户的调用正确传到组件对象中,并保证参数传递的正确性. 组件对象和客户代码不必考虑调用传递的 ...

  2. 第九章 Mysql函数

    简介 数学函数:处理数字 字符串函数:处理字符串 日期和时间函数:处理日期和时间,获取时间 条件判断函数:控制条件选择 系统信息函数:获取MySQL系统信息,包括数据库名称,当前用户名和数据库版本 加 ...

  3. .net 错误处理

    第一步在页面中写OnError方法: protected override void OnError(EventArgs e) { Exception ex = Server.GetLastError ...

  4. Java NIO中的Buffer

    简介 Buffer缓冲区,首先要弄明白的是,缓冲区是怎样一个概念.它其实是缓存的一种,我们常说的缓存,包括保存在硬盘上的浏览器缓存,保存在内存中的缓存(比如Redis.memcached).Buffe ...

  5. CSS预处理语言-less 的使用

    Less 是一门 CSS 预处理语言,它扩展了 CSS 语言,增加了变量.Mixin.函数等特性,使 CSS 更易维护和扩展. Less 可以运行在 Node 或浏览器端. Less的编译处理 作为一 ...

  6. Bond UVA - 11354(并查集按秩合并)

    题意: 给你一张无向图,然后有若干组询问,让你输出a->b的最小瓶颈路. 解析: 应该都想过用prime的次小生成树做..但二维数组开不了那么大..所以只能用kruskal了.... #incl ...

  7. 飞舞的蝴蝶(GraphicsView框架)

    飞舞的蝴蝶(GraphicsView框架) 一.简介 GraphicsView框架结构主要包含三个主要的类QGraphicsScene(容器).QGraphicsView(视图).QGraphicsI ...

  8. 【JQuery】css操作

    一.前言         接着上一章的内容,继续JQuery的学习 二.内容 css 设置或返回匹配元素的样式属性 $(selector).css(css-property-name) $(selec ...

  9. GDOI2015小Z的旅行路线

    GDOI2015小Z的旅行路线 题意: \(n\)个点的无根树,边上有权值. \(q\)个询问\(s\)和\(s\),问从\(s\)出发,找一条最长路(不经过重复点),保证路径上所有边边权不超过\(x ...

  10. php7实现基于openssl的加密解密方法

    还需要注意的是加密字符串长度问题,如果加密字符串长度太长需要进行分段加解密,如下代码: 加密:(公匙加密,私密一般用来解密) function encrypt($originalData){ $pub ...