博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Counting Pair
阅读量:5248 次
发布时间:2019-06-14

本文共 2072 字,大约阅读时间需要 6 分钟。

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 
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
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 = 1; 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 <= 1 || s > M + N) cnt = 0;27 else28 {29 if(N < M) swap(M, N);30 if(s <= M) cnt = s - 1;31 else if(s > M && s <= N) cnt = M;32 else if(s > N) cnt = M + N - s + 1;33 }34 printf("%d\n",cnt);35 }36 }37 return 0;38 }

 

 

转载于:https://www.cnblogs.com/cszlg/p/3220713.html

你可能感兴趣的文章
110104_LC-Display(液晶显示屏)
查看>>
httpd_Vhosts文件的配置
查看>>
php学习笔记
查看>>
普通求素数和线性筛素数
查看>>
PHP截取中英文混合字符
查看>>
【洛谷P1816 忠诚】线段树
查看>>
电子眼抓拍大解密
查看>>
poj 1331 Multiply
查看>>
tomcat7的数据库连接池tomcatjdbc的25个优势
查看>>
Html 小插件5 百度搜索代码2
查看>>
P1107 最大整数
查看>>
多进程与多线程的区别
查看>>
Ubuntu(虚拟机)下安装Qt5.5.1
查看>>
java.io.IOException: read failed, socket might closed or timeout, read ret: -1
查看>>
java 常用命令
查看>>
CodeForces Round #545 Div.2
查看>>
卷积中的参数
查看>>
51nod1076 (边双连通)
查看>>
Item 9: Avoid Conversion Operators in Your APIs(Effective C#)
查看>>
深入浅出JavaScript(2)—ECMAScript
查看>>