zoukankan      html  css  js  c++  java
  • sicily 2001. Scavenger Hunt

    Description
    Farmer John has scattered treats for Bessie at special places in the pasture. Since everyone knows that smart cows make tasty milk, FJ has placed the treats at locations that require Bessie to think. He has given her two numbers, P and Q (1 <= P <= 6,000; 1 <= Q <= 6,000), and she has to check every point in the pasture whose x-coordinate is a factor of P and whose y-coordinate is a factor of Q to find her treat.
    Suppose FJ gives Bessie P = 24 and Q = 2. Here are all of their respective factors:
    P = 24 => 1, 2, 3, 4, 6, 8, 12, 24
    Q = 2 => 1, 2
    Bessie would thus check grid locations: (1, 1), (1, 2), (2, 1), (2, 2), (3, 1)...
    Help Bessie by printing all of the points she ought to check.


    Input
    * Line 1: Two space separated integers: P and Q


    Output
    * Lines 1..?: A complete list of unique pairs of space-separated integers sorted by the first number and, if tied, the second number: a factor of P followed by a factor of Q

    水题,枚举打表输出即可

    View Code
     1 #include<iostream>
     2 using namespace std;
     3 int pfac[6000];
     4 int qfac[6000];
     5 
     6 int ptable( int p )
     7 {
     8     int j = 0;
     9     
    10     for( int i = 1; i <= p; i++ )
    11         if( p % i == 0 )
    12             pfac[j++] = i;
    13             
    14     return j;
    15 }
    16 
    17 int qtable( int q )
    18 {
    19     int j = 0;
    20     
    21     for( int i = 1; i <= q; i++ )
    22         if( q % i == 0 )
    23             qfac[j++] = i;
    24     
    25     return j;
    26 }
    27 
    28 int main()
    29 {
    30     int p, q;
    31     cin >> p >> q; 
    32     
    33     int psize, qsize;
    34     psize = ptable(p);
    35     qsize = qtable(q);
    36     
    37     int i, j;
    38     for( i = 0; i < psize; i++ )
    39         for( j = 0; j < qsize; j++ )
    40             cout << pfac[i] << " " << qfac[j] << endl;
    41     
    42     return 0;
    43 } 
  • 相关阅读:
    2020.10.23 19级training 补题报告
    2020.10.17 天梯赛练习 补题报告
    2020.10.16 19级training 补题报告
    2020.10.9 19级training 补题报告
    2020.10.10 天梯赛练习 补题报告
    2020.10.3 天梯赛练习 补题报告
    2020.10.2 19级training 补题报告
    第十届山东省ACM省赛复现补题报告
    VVDI Key Tool Plus Adds VW Passat 2015 Key via OBD
    Xhorse VVDI Prog Software V5.0.3 Adds Many MCUs
  • 原文地址:https://www.cnblogs.com/joyeecheung/p/2909590.html
Copyright © 2011-2022 走看看