zoukankan      html  css  js  c++  java
  • (贪心)AtCoder Grand Contest 018 B : Sports Festival

    Problem Statement

    Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi will select one or more sports (possibly all) to be played in the event.

    Takahashi knows that Person i's j-th favorite sport is Sport Aij. Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports.

    Takahashi is worried that one of the sports will attract too many people. Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized. Find the minimum possible number of the participants in the sport with the largest number of participants.

    Constraints

    • 1≤N≤300
    • 1≤M≤300
    • Ai1 , Ai2 ,  , AiM is a permutation of the integers from 1 to M.

    Input

    Input is given from Standard Input in the following format:

    N M
    A11 A12  A1M
    A21 A22  A2M
    :
    AN1 AN2  ANM
    

    Output

    Print the minimum possible number of the participants in the sport with the largest number of participants.


    Sample Input 1

    Copy
    4 5
    5 1 3 4 2
    2 5 3 1 4
    2 3 1 4 5
    2 5 4 3 1
    

    Sample Output 1

    Copy
    2
    

    Assume that Sports 13 and 4 are selected to be played. In this case, Person 1 will participate in Sport 1, Person 2 in Sport 3, Person 3 in Sport 3 and Person 4 in Sport 4. Here, the sport with the largest number of participants is Sport 3, with two participants. There is no way to reduce the number of participants in the sport with the largest number of participants to 1. Therefore, the answer is 2.


    Sample Input 2

    Copy
    3 3
    2 1 3
    2 1 3
    2 1 3
    

    Sample Output 2

    Copy
    3
    

    Since all the people have the same taste in sports, there will be a sport with three participants, no matter what sports are selected. Therefore, the answer is 3.

     1 #include <iostream>
     2 #include <string>
     3 #include <algorithm>
     4 #include <cstring>
     5 #include <cstdio>
     6 #include <cmath>
     7 #include <queue>
     8 #include <set>
     9 #include <map>
    10 #include <list>
    11 #include <vector>
    12 #include <stack>
    13 #define mp make_pair
    14 #define MIN(a,b) (a>b?b:a)
    15 //#define MAX(a,b) (a>b?a:b)
    16 typedef long long ll;
    17 typedef unsigned long long ull;
    18 const int MAX=2e5+5;
    19 const int INF=1e8+5;
    20 using namespace std;
    21 //const int MOD=1e9+7;
    22 typedef pair<ll,int> pii;
    23 const double eps=0.00000001;
    24 int n,m;
    25 queue<int> que[305];
    26 int tem;
    27 bool vi[305];
    28 int num[305];
    29 int cnt,an,who;
    30 int main()
    31 {
    32     scanf("%d%d",&n,&m);
    33     for(int i=1;i<=n;i++)
    34     {
    35         for(int j=1;j<=m;j++)
    36         {
    37             scanf("%d",&tem);
    38             que[i].push(tem);
    39         }
    40     }
    41     for(int i=1;i<=m;i++)
    42     {
    43         memset(num,0,sizeof(num));
    44         cnt=0;
    45         who=que[1].front();
    46         for(int j=1;j<=n;j++)
    47         {
    48             int pre=que[j].front();
    49             while(vi[pre])
    50             {
    51                 que[j].pop();
    52                 pre=que[j].front();
    53             }
    54             ++num[pre];
    55             if(num[pre]>cnt)
    56             {
    57                  cnt=num[pre];
    58                  who=pre;
    59             }
    60         }
    61         vi[who]=true;
    62         if(i!=1)
    63             an=min(an,cnt);
    64         else
    65             an=cnt;
    66     }
    67     printf("%d
    ",an);
    68     return 0;
    69 }
  • 相关阅读:
    Date类型转换成LocalDateTime 类型
    连接mysql数据库执行写入语句
    排序的的值为非数字时的处理方法
    git所遇到的问题
    visual studio快捷键
    Win10编译chromium
    下载chromium CIPD client失败的解决办法
    Linux内核源代码情景分析
    【赵强老师】史上最详细的PostgreSQL体系架构介绍
    3.Consul 安装配置(Proxysql+mgr)
  • 原文地址:https://www.cnblogs.com/quintessence/p/7226767.html
Copyright © 2011-2022 走看看