• Factors and Multiples


    Factors and Multiples
    Time Limit: 2 second(s) Memory Limit: 32 MB

    You will be given two sets of integers. Let's call them set A and set B. Set A contains n elements and set B contains m elements. You have to remove k1 elements from set A and k2 elements from set B so that of the remaining values no integer in set B is a multiple of any integer in set Ak1 should be in the range [0, n] and k2 in the range [0, m].

    You have to find the value of (k1 + k2) such that (k1 + k2) is as low as possible. P is a multiple of Q if there is some integer K such that P = K * Q.

     

    Suppose set A is {2, 3, 4, 5} and set B is {6, 7, 8, 9}. By removing 2 and 3 from A and 8 from B, we get the sets {4, 5} and {6, 7, 9}. Here none of the integers 6, 7 or 9 is a multiple of 4or 5.

    So for this case the answer is 3 (two from set A and one from set B).

    Input

    Input starts with an integer T (≤ 50), denoting the number of test cases.

    The first line of each case starts with an integer n followed by n positive integers. The second line starts with m followed by m positive integers. Both n and m will be in the range [1, 100]. Each element of the two sets will fit in a 32 bit signed integer.

    Output

    For each case of input, print the case number and the result.

    Sample Input

    Output for Sample Input

    2

    4 2 3 4 5

    4 6 7 8 9

    3 100 200 300

    1 150

    Case 1: 3

    Case 2: 0

     题意:两个集合,删除元素使下一个集合没有上一个集合的倍数,问最少删除几个元素。匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~匹配~

    是猪么

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 
     5 using namespace std;
     6 
     7 #define N 110
     8 
     9 int used[N], vis[N], n, m;
    10 int maps[N][N];
    11 int a[N], b[N];
    12 
    13 int found(int x)
    14 {
    15     for(int i = 0; i < m; i++)
    16     {
    17         if(maps[x][i] && !vis[i])
    18         {
    19             vis[i] = 1;
    20             if(used[i] == -1 || found(used[i]))
    21             {
    22                 used[i] = x;
    23                 return true;
    24             }
    25         }
    26     }
    27     return false;
    28 }
    29 
    30 int main()
    31 {
    32     int t, k = 1;
    33 
    34     scanf("%d", &t);
    35 
    36     while(t--)
    37     {
    38         memset(used, -1, sizeof(used));
    39         memset(maps, 0, sizeof(maps));
    40 
    41         scanf("%d", &n);
    42         for(int i = 0; i < n; i++)
    43             scanf("%d", &a[i]);
    44         scanf("%d", &m);
    45         for(int j = 0; j < m; j++)
    46             scanf("%d", &b[j]);
    47         for(int i = 0; i < n; i++)
    48             for(int j = 0; j < m; j++)
    49             if(b[j] % a[i] == 0)
    50             maps[i][j] = 1;
    51         int cou = 0;
    52         for(int i = 0; i < n; i++)
    53         {
    54             memset(vis, 0, sizeof(vis));
    55             if(found(i))
    56                 cou++;
    57         }
    58         printf("Case %d: %d
    ", k++, cou);
    59     }
    60     return 0;
    61 }

    好好的福利场被人家抢了~是不是傻,是不是猪,是不是~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 是是是是是是是是是是是是是是是是是是是是是是是是是是是 

    让未来到来 让过去过去
  • 相关阅读:
    更换pip下载源
    django同步数据库时出现错误
    Django Debug Toolbar
    使用Django-environ区分环境
    CDOJ 1591 An easy problem A(ST表)
    for循环06(打印正三角形)
    了解 label 标签 与 goto (不建议使用)
    continue01
    break01
    break 与 continue
  • 原文地址:https://www.cnblogs.com/Tinamei/p/4746900.html
Copyright © 2020-2023  润新知