sdau 省赛热身4 C - Counting Pair
来源:互联网 发布:淘宝网网游交易平台 编辑:程序博客网 时间:2024/05/16 19:09
sdau 省赛热身4 C - Counting Pair
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.
数字组合
题目大意:一个party来了n男m女,每人有其对应(1~n)或(1~m)编号,主人给出一数,若男女两队人马中有两数之和等于此数,则可配对,问给出一数,可配多少对。
题目分析:若给出的数x既小于m,又小于n,则x-1就是答案。eg.在本例第三个数据中3可配1~2和2~1两对。但如果给出的数-1大于m,n之一,就出现问题了,组合往上找的时候会meet上界,这时需要把上界之上的部分减掉。(这部分代码挺绕的,不过多看两眼肯定能明白)
code:
#include<stdio.h>int main(){int i,j,t,n,m,p,count,k,l,test;scanf("%d",&t);for(i=1;i<=t;i++){scanf("%d%d%d",&n,&m,&p);printf("Case #%d:\n",i);for(j=0;j<p;j++){count=0;scanf("%d",&test);/*test--;for(k=1;k<=n;k++){if(test-k>0&&test-k<=m)count++;else if(test-k<=0)break;}printf("%d\n",count);*/if(test-1<=n&&test-1<=m)printf("%d\n",test-1);else if(test>n+m)printf("0\n");else printf("%d\n",test-1-(test>n?test-1-n:0)-(test>m?test-1-m:0));}}}PS:今天状态尚可,A出三道,后面还有一道。(continue praying)
- sdau 省赛热身4 C - Counting Pair
- sdau 省赛热身4 A - A Big Dinner
- sdau 省赛热身4 K - King's Sanctuary
- 省赛热身C题概率DP
- 弱校联萌十一大决战之背水一战C. Counting Pair
- 2012省赛热身题 Climbing Stairs
- 【C/C++】STL--pair
- GCC for C 热热身
- 【SeedCoder2015年 热身题7 搜索】Lake Counting (题目+答案)
- C++pair容器
- C++STL学习Pair
- c++pair的用法
- C++pair的用法
- pair (c++)
- [C++]Pair简介
- [C++]STL pair
- C++pair对组
- c++pair基本用法
- android超级课程表原理(各大高校教务平台的数据获取原理)
- LBA硬盘模式
- vc 注册表改网络设置立即生效
- spinlock分析
- 安卓平台使用sqlite
- sdau 省赛热身4 C - Counting Pair
- C++简史
- java.io.NotSerializableException: com.sysway.presentationmodel.NotifiableList
- Socket I/O模型
- sdau 省赛热身4 K - King's Sanctuary
- 不是抽象的,并且未覆盖 com.sysway.boss.service.internal.party.role.partyroleservice 中的抽象方法
- 从欧洲对中国太阳能征收惩罚性关税谈起
- 这是自己的第一篇日志,纪念一下
- 高端洋气上档次的终端控--tmux