zoukankan      html  css  js  c++  java
  • 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:
    ", Case);
    37         pro();
    38         while(q--){
    39             scanf("%d", &qnum);
    40             printf("%d
    ", result());
    41         }
    42     }
    43 
    44     return 0;
    45 }
  • 相关阅读:
    Python 元类
    Rsync 基础配置
    linux shell find
    找最大的目录
    云主机的上下行带宽
    关于c3p0 ResourcePoolException: Attempted to use a closed or broken resource pool
    recover_file
    MegaCli 监控raid状态
    influxdb
    在Ubuntu 16.04如何安装Java使用apt-get的
  • 原文地址:https://www.cnblogs.com/miaowTracy/p/4858661.html
Copyright © 2011-2022 走看看