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. 超级迷宫需求分析与建议-NABCD模型

    超级迷宫需求分析与建议-NABCD模型 制作者-姜中希 1N-Need 需求  首先这是一个手机游戏风靡的时代,随着智能手机不断的更新问世,4G网络的不断扩大普及,越来越多的手机游戏受到广大玩家的追捧 ...

  2. DP---基本思想 具体实现 经典题目 POJ1160 POJ1037

    POJ1160, post office.动态规划的经典题目.呃,又是经典题目,DP部分的经典题目怎就这么多.木有办法,事实就这样. 求:在村庄内建邮局,要使村庄到邮局的距离和最小. 设有m个村庄,分 ...

  3. 如何解决Unsupported Architecture. Your executable contains unsupported architecture '[x86_64, i386]

    APP改版测试后准备Archive发布时,结果居然出现题目中的错误提示.查了一下,如果archive的时候没有选[iOS](http://lib.csdn.net/base/ios)  Devices ...

  4. Solr初步研究

    Solr是一个高性能,采用Java5开发,Solr基于Lucene的全文搜索服务器.同时对其进行了扩展,提供了比Lucene更为丰富的查询语言,同时实现了可配置.可扩展并对查询性能进行了优化,并且提供 ...

  5. C语言文法阅读与理解序

    <指针>→*  | * < 指针> <直接声明符>  <标识符> | <直接声明>[]| <直接声明>[常量表达式] | < ...

  6. oracle & 的用法!

    /*select * from emp_bak where deptno = &"Department number" order by ename; select * f ...

  7. JSON和Django内置序列化

    JSON 什么是JSON JSON 指的是 JavaScript 对象表示法(JavaScript Object Notation) JSON 是轻量级的文本数据交换格式 JSON 独立于语言 * J ...

  8. Spring 学习7 -事务

    1 初步理解 理解事务之前,先讲一个你日常生活中最常干的事:取钱. 比如你去ATM机取1000块钱,大体有两个步骤:首先输入密码金额,银行卡扣掉1000元钱:然后ATM出1000元钱.这两个步骤必须是 ...

  9. MySQL专题 2 数据库优化 Slow Query log

    MySQL Server 有四种类型的日志——Error Log.General Query Log.Binary Log 和 Slow Query Log. 第一个是错误日志,记录 mysqld 的 ...

  10. IP地址转换32为长整型

    Programming Question: Convert an IPv4 address in the format of null-terminated C string into a 32-bi ...