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

 看代码就懂了
  1. #include <iostream>
  2. #include <queue>
  3. #include <vector>
  4. #include <map>
  5. #include <string>
  6. #include <algorithm>
  7. #include <cstdio>
  8. #include <cstring>
  9. #include <cmath>
  10.  
  11. using namespace std;
  12.  
  13. int T, N, M, Q, s, cnt;
  14.  
  15. int main()
  16. {
  17. scanf("%d", &T);
  18. for(int ca = ; ca <= T; ca++)
  19. {
  20. scanf("%d %d", &N, &M);
  21. scanf("%d", &Q);
  22. printf("Case #%d:\n", ca);
  23. while(Q--)
  24. {
  25. scanf("%d", &s);
  26. if(s <= || s > M + N) cnt = ;
  27. else
  28. {
  29. if(N < M) swap(M, N);
  30. if(s <= M) cnt = s - ;
  31. else if(s > M && s <= N) cnt = M;
  32. else if(s > N) cnt = M + N - s + ;
  33. }
  34. printf("%d\n",cnt);
  35. }
  36. }
  37. return ;
  38. }
 

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. 电梯V2.0

    电梯V2.0 GitHub仓库地址 Problem 一栋10层的大楼(楼层编号1-10),设3台无限载重的电梯,初始时电梯停在1层.其中:1号电梯只能停留在奇数层,2号电梯可以各层都停留,3号电梯只停 ...

  2. timestamp 学习

    该答案摘抄自CSDN. 哇,奇迹,跨度三年了,不知道楼主是否已经解决了此问题. 路过,简单说一下,timestamp 主要是记录该行的最后修改时间戳, 注意,这个时间戳是不可以转换为时间的,只能标注该 ...

  3. 0429团队项目-Scrum团队成立

    Scrum团队成立 团队名称:开拓者 团队目标:努力让每一个小伙伴在学会走路的基础上学会跑. 团队口号:我们要的只是这片天而已. 团队照:正面照+背影照(那就是为什么组名叫开拓者) 5.2 角色分配 ...

  4. jQuery之数组处理函数

    摘要:$.each,$.grep,$.map,$.merge,$.inArray,$.unique,$.makeArray 1. $.each(array, [callback]) 遍历[常用] 解释 ...

  5. iOS- 再谈ARC里内存问题,ARC里数组、对象内存得不到释放?

    1.前言      本来以为在改成ARC以后,不再需要考虑内存问题了,可是在实践中还是发现有一些内存问题需要注意,今天我不谈block的循环引用的问题,主要说说一些对象.数组不内存得不到释放的情况. ...

  6. PXE推一半失败,HP服务器、曙光服务器删除数据

    一.#设备:惠普HP DL380 Gen9 PXE安装失败,系统尝试从硬盘启动 需要将安装未完整的系统数据删除,以便正常装机 从控制台重启设备 重启后,HP在此界面选择Intelligent Prov ...

  7. CCF——数位之和201512-1

    问题描述 给定一个十进制整数n,输出n的各位数字之和. 输入格式 输入一个整数n. 输出格式 输出一个整数,表示答案. 样例输入 20151220 样例输出 13 样例说明 20151220的各位数字 ...

  8. webgl学习笔记三-平移旋转缩放

    写在前面 建议先阅读下前面我的两篇文章. webgl学习笔记一-绘图单点 webgl学习笔记二-绘图多点 平移 1.关键点说明 顶点着色器需要加上 uniform vec4 u_Translation ...

  9. bootstrap练习制作网页

    导航条 <nav class="navbar navbar-default"> <div class="container-fluid"> ...

  10. 51nod 1682 中位数计数(差分统计)

    中位数定义为所有值从小到大排序后排在正中间的那个数,如果值有偶数个,通常取最中间的两个数值的平均数作为中位数. 现在有n个数,每个数都是独一无二的,求出每个数在多少个包含其的区间中是中位数. 首先,显 ...