Atcoder- Sports Festival(二分+暴力+思维+贪心)

B - Sports Festival


Time limit : 2sec / Memory limit : 256MB

Score : 700 points

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

  • 1N300
  • 1M300
  • 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 Sport4. 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.

思路:一道考验脑子冷静程度和码力的题,居然没写出来、、、,首先我们很容易想到枚举子集然后更新答案,但是显然是不行的复杂度为2^n,容易想到二分答案,但是怎么判断当前答案是否可行,这就是这道题的难点了,我们可以尝试这样的做法,对于每个人,我们从每个人喜欢程度依次下降的选起,如果此时不行,那当前的最大值的哪个项目一定是不能选的,我们把他变为0,重复这个过程,这样的话,巧妙的利用的贪心思想找出当前可选的项目,复杂度为logn*m*n*3
ac代码:
#include
#include
#include
#include
#include
#include
#include
#include
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
int mp[300+5][300+56];
int n,m;
int idx[305];
int cnt[305];
int mp2[300+5][300+5];
int pos[305][305];
int check(int x){
    memset(cnt,0,sizeof(cnt));
    for(int i = 0;ix)
        return -res;
    return res;
}
void print()
{
    for(int i = 0 ;i0)
            return 1;
        for(int j = 0;j=m)
                return 0;
        }
    }
    return 0;
}
int main()
{
    while(~scanf("%d%d",&n,&m))
    {
        for(int i = 0;i1){
            int mid = (l+r)>>1;
            if(ok(mid)){
                r = mid;
            }
            else
                l =mid;
        }
        cout<


你可能感兴趣的:(二分,贪心,思维,atcoder)