弱校联萌十一大决战之背水一战C. Counting Pair

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.


这个题当时读了好久 学弟看明白才给我讲的orz

他给的Q行数分别是要求的和!但是需要分类讨论 总共也没多麻烦

#include<cstdio>
#include<iostream>
using namespace std;
int t,n,m,p,test;
int main()
{

	scanf("%d",&t);
	for(int cas=1;cas<=t;cas++)
	{
		scanf("%d%d%d",&n,&m,&p);
		printf("Case #%d:\n",cas);
		for(int j=0;j<p;j++)
		{
			scanf("%d",&test);
			if(test-1<=n&&test-1<=m)printf("%d\n",test-1);
			else if(test>n+m) printf("0\n");
			else
			{
			    int maxn1=(test>n?test-1-n:0),maxn2=test>m?test-1-m:0;
			    printf("%d\n",test-1-(maxn1)-(maxn2));
			}
		}
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值