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/ ...
随机推荐
- MacBook Pro 15寸常见问题及修复
苹果MacBook Pro更换SSD硬盘攻略教程 MacBook pro开机黑屏解决 苹果电脑 MAC PRO 开机黑屏了 MacBook Pro 开机后黑屏,怎么办啊 如果 Mac 无法开机 Mac ...
- OSG学习:使用OSG中预定义的几何体
常用的内嵌几何体包括: osg::Box //正方体 osg::Capsule //太空舱 osg::Cone //椎体 osg::Cylinder //柱体 osg::HeightField //高 ...
- mybatis_mysql
SELECT round(avg(c.AVG_DELAY_TIME)) as AVG_DELAY FROM `result_road_saturation_day` a LEFT JOIN info_ ...
- node.js入门(一)
NodeJS是一个使用了Google高性能V8引擎的服务器端JavaScript实现.它提供了一个(几乎)完全非阻塞I/O栈,与JavaScript提供的闭包和匿名函数相结合,使之成为编写高吞吐 量网 ...
- 使用JMeter录制Web应用测试脚本
环境 操作系统:Windows 7 工具:JMeter.Badboy 1. 使用代理录制Web性能测试脚本 使用代理录制脚本来创建测试计划无疑是一个简便的方法,代理所要完成的工作就是录制发往服务器的请 ...
- Java Machine Learning Tools & Libraries--转载
原文地址:http://www.demnag.com/b/java-machine-learning-tools-libraries-cm570/?ref=dzone This is a list o ...
- 【HLSDK系列】HL引擎入门篇
如果你打算拿HL的源码(也就是HLSDK)来改出一个自己的游戏,那你就非常有必要理解一些HL引擎的工作方式. HL引擎分成两个部分,服务端和客户端.服务端管理所有玩家的状态和游戏规则,客户端负责显示U ...
- P2762 太空飞行计划问题(网络流24题之一)
题目描述 W 教授正在为国家航天中心计划一系列的太空飞行.每次太空飞行可进行一系列商业性实验而获取利润.现已确定了一个可供选择的实验集合E={E1,E2,…,Em},和进行这些实验需要使用的全部仪器的 ...
- [BJWC2011]元素 线性基
题面 题面 题解 一个方案合法,当且仅当选取的01串凑不出0. 因此就是要使得选取的01串全在线性基内,具体原因可以看这道题:[CQOI2013]新Nim游戏 线性基 要使得魔力值最大,只需要按法力值 ...
- BZOJ3782 上学路线 【dp + Lucas + CRT】
题目链接 BZOJ3782 题解 我们把终点也加入障碍点中,将点排序,令\(f[i]\)表示从\((0,0)\)出发,不经过其它障碍,直接到达\((x_i,y_i)\)的方案数 首先我们有个大致的方案 ...