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/ ...
随机推荐
- 软工1816 · Alpha冲刺(5/10)
团队信息 队名:爸爸饿了 组长博客:here 作业博客:here 组员情况 组员1(组长):王彬 过去两天完成了哪些任务 后端代码复审 福大各个食堂的菜品口味量化.属性标记 组织前后端线下协作 接下来 ...
- Lucene 分词
在Lucene中很多数据是通过Attribute进行存储的 步骤是同过TokenStrem获取文本信息流 TokenStream stream = a.tokenStream("conten ...
- HTML&CSS实体
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- 小程序 坐标算距离 (copy)
var EARTH_RADIUS = 6378137.0; //单位M var PI = Math.PI; function getRad(d){ retu ...
- Spring MVC @RequestParam @RequestHeader @CookieValue用法
摘要: package com.hust.springmvc1; import org.springframework.stereotype.Controller; import org.spring ...
- jquery实现可编辑的下拉框( input + select )
HTML: <input id="inputModel" /> <select name="EngineModel" size="1 ...
- 详解免费高效实用的.NET操作Excel组件NPOI(转)
有时间研究一下NPOI http://www.cnblogs.com/pengze0902/p/6150070.html
- 【Quartz.Net】.net 下使用Quartz.Net
Quartz.net是作业调度框架 1. 项目中添加quartz.net的引用(这里使用nuget管理) 新建一个类TimingJob,该类主要用于实现任务逻辑 using Quartz; usi ...
- HDU3710-Battle Over Cities
题意 给出一个\(n\)个点\(m\)条边的无向连通图,问删掉每一个点后的最小生成树权值和为多少(如果不存在最下生成树就输出inf). \(n\le 2\times 10^4,m\le 10^5\) ...
- 【uoj#174】新年的破栈 贪心
题目描述 给你一个长度为 $n$ 的序列和一个空的双端队列,每次进行3种操作种的一种: 1.将序列中编号最小的数加入到双端队列的队尾:2.从双端队列的队尾取出一个数:3.从双端队列的队头取出一个数. ...