BNUOJ 24251 Counting Pair

题目链接:

  http://acm.bnu.edu.cn/v3/problem_show.php?pid=24251



数论:

  给定1~N, 1~M的编号作为男女的编号

  给定Q个查询,每个查询给出一个数字qnum,求出所有男女编号相加等于qnum的组合的情况

  最大的组合情况就是N/M中最小的那个数

  找规律发现在2~N+M这些数的两侧从1~min(N, M)-1进行排列,其他的位置填上min(N, M)即可


 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cstdio>
 4 #include<cstring>
 5 using namespace std;
 6 #define clr(c) memset(c, 0, sizeof(c));
 7 const int MAXL = 200000+5;
 8 int ans[MAXL];
 9 int t, n, m, q, qnum;
10
11 void pro(){
12     int maxnum = min(n, m);
13     int sum = n+m;
14     for(int i = 1; i < maxnum; i++){
15         ans[2+i-1] = i;
16         ans[sum-i+1] = i;
17     }
18     for(int i = 2+maxnum-1; i <= sum-maxnum+1; i++){
19         ans[i] = maxnum;
20     }
21 }
22
23 int result(){
24     if(qnum > n+m || qnum == 0 || qnum == 1) return 0;
25     else{
26         return ans[qnum];
27     }
28 }
29
30 int main(){
31     scanf("%d", &t);
32     for(int Case = 1; Case <= t; Case++){
33         clr(ans);
34         scanf("%d%d", &n, &m);
35         scanf("%d", &q);
36         printf("Case #%d:\n", Case);
37         pro();
38         while(q--){
39             scanf("%d", &qnum);
40             printf("%d\n", result());
41         }
42     }
43
44     return 0;
45 }
时间: 2024-08-28 12:06:00

BNUOJ 24251 Counting Pair的相关文章

BNUOJ 7629 Boring counting

Boring counting Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 351864-bit integer IO format: %I64d      Java class name: Main 035 now faced a tough problem,his english teacher gives him a string,which consis

hdu 2952 Counting Sheep

题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2952 Counting Sheep Description A while ago I had trouble sleeping. I used to lie awake, staring at the ceiling, for hours and hours. Then one day my grandmother suggested I tried counting sheep after I'

BNUOJ 1206 A Plug for UNIX

A Plug for UNIX Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID: 108764-bit integer IO format: %lld      Java class name: Main You are in charge of setting up the press room for the inaugural meeting of the Un

BNUOJ 17286 Dollars

Dollars Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVA. Original ID: 14764-bit integer IO format: %lld      Java class name: Main New Zealand currency consists of $100, $50, $20, $10, and $5 notes and $2, $1, 50c, 20c, 1

LightOJ - 1148 - Mad Counting

先上题目: 1148 - Mad Counting   PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 32 MB Mob was hijacked by the mayor of the Town "TruthTown". Mayor wants Mob to count the total population of the town. Now the naive approach to

HDU 1264 Counting Squares(线段树求面积的并)

Counting Squares Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1885    Accepted Submission(s): 946 Problem Description Your input is a series of rectangles, one per line. Each rectangle is sp

Twitter OA prepare: K-complementary pair

A non-empty zero-indexed array A consisting of N integers is given. A pair of integers (P, Q) is called K-complementary in array A if 0 ≤ P, Q < N and A[P] + A[Q] = K. For example, consider array A such that: A[0] = 1 A[1] = 8 A[2]= -3 A[3] = 0 A[4]

BNUOJ 1260 Brackets Sequence

Brackets Sequence Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID: 114164-bit integer IO format: %lld      Java class name: Main Special Judge Let us define a regular brackets sequence in the following way: 1.

BNUOJ 5997 Fibonacci again and again

Fibonacci again and again Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 184864-bit integer IO format: %I64d      Java class name: Main 任何一个大学生对菲波那契数列(Fibonacci numbers)应该都不会陌生,它是这样定义的:F(1)=1;F(2)=2;F(n)=F(n