zoukankan      html  css  js  c++  java
  • HDU 6075 Questionnaire 17多校4 水题

    Problem Description
    In order to get better results in official ACM/ICPC contests, the team leader comes up with a questionnaire. He asked everyone in the team whether to have more training.



    Picture from Wikimedia Commons


    Obviously many people don't want more training, so the clever leader didn't write down their words such as ''Yes'' or ''No''. Instead, he let everyone choose a positive integer ai to represent his opinion. When finished, the leader will choose a pair of positive interges m(m>1) and k(0k<m), and regard those people whose number is exactly k modulo m as ''Yes'', while others as ''No''. If the number of ''Yes'' is not less than ''No'', the leader can have chance to offer more training.

    Please help the team leader to find such pair of m and k.
     
    Input
    The first line of the input contains an integer T(1T15), denoting the number of test cases.

    In each test case, there is an integer n(3n100000) in the first line, denoting the number of people in the ACM/ICPC team.

    In the next line, there are n distinct integers a1,a2,...,an(1ai109), denoting the number that each person chosen.
     
    Output
    For each test case, print a single line containing two integers m and k, if there are multiple solutions, print any of them.
     
    Sample Input
    1
    6
    23 3 18 8 13 9
     
    Sample Output
    5
    3
     
    题意:给出n个数a[i],要求你回答任意一组m,k,使得a[i]%m==k的个数大于等于剩余个数
    题解:使m=2,计算序列中奇偶个数并比较即可
     
     1 #include <iostream>
     2 #include<cstdio>
     3 #include<algorithm>
     4 #include<queue>
     5 #include<map>
     6 #include<vector>
     7 #include<cmath>
     8 #include<cstring>
     9 using namespace std;
    10 
    11 int main()
    12 {
    13     int T,n,num;
    14     int a,b;
    15     scanf("%d",&T);
    16     while(T--)
    17     {
    18         scanf("%d",&n);
    19         a=0;b=0;
    20         while(n--)
    21         {
    22             scanf("%d",&num);
    23             if(num%2==0)
    24                 a++;
    25             else
    26                 b++;
    27         }
    28         if(a>=b)
    29             printf("%d %d
    ",2,0);
    30         else
    31             printf("%d %d
    ",2,1);
    32     }
    33     return 0;
    34 }
  • 相关阅读:
    拓扑排序笔记
    Codeforces Round #683 (Div. 2, by Meet IT)(A->C)(构造,思维,贪心)
    Acwing 846. 树的重心(DFS枚举删除每一个点)
    Acwing 125. 耍杂技的牛(贪心)(从局部到全局)
    Acwing 802. 区间和(下标离散化+vector+二分)
    Acwing 799. 最长连续不重复子序列(双指针)
    Acwing 139. 回文子串的最大长度(前缀+后缀处理+哈希+二分)
    Linux shell 变量$#,$@,$0....的含义
    一双不锈钢筷子 的测试用例?
    OSI模型 TCP/IP模型 再整理
  • 原文地址:https://www.cnblogs.com/Annetree/p/7289269.html
Copyright © 2011-2022 走看看