Atcoder-Sports Festival(二分+暴力+思维+贪心)
来源:互联网 发布:淘宝达人cps是什么意思 编辑:程序博客网 时间:2024/05/22 18:36
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
- 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 MA11 A12 … A1MA21 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
4 55 1 3 4 22 5 3 1 42 3 1 4 52 5 4 3 1
Sample Output 1
2
Assume that Sports 1, 3 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
3 32 1 32 1 32 1 3
Sample Output 2
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.
#include<cstdio>#include<algorithm>#include<cstring>#include<iostream>#include<sstream>#include<queue>#include<set>#include<cmath>#define LL long long#define INF 0x3f3f3f3fusing 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;i<n;i++){ cnt[mp2[i][idx[i]]]++; } int mx = -1; int res ; for(int i = 1;i<=m;i++){ if(mx<cnt[i]){ mx = max(mx,cnt[i]); res = i; } } if(mx>x) return -res; return res;}void print(){ for(int i = 0 ;i<n;i++){ for(int j = 0;j<m;j++){ printf("%d%c",mp2[i][j],j==m-1?'\n':' '); } }}int ok(int x){ for(int i = 0;i<n;i++){ for(int j = 0;j<m;j++){ mp2[i][j] = mp[i][j]; } } memset(idx,0,sizeof(idx)); for(int i = 0;i<m;i++) { int res = check(x); //print(); if(res>0) return 1; for(int j = 0;j<n;j++){ mp2[j][pos[j][-res]] = 0; } for(int j = 0;j<n;j++){ while(mp2[j][idx[j]]==0&&idx[j]<m){ idx[j]++; } if(idx[j]>=m) return 0; } } return 0;}int main(){ while(~scanf("%d%d",&n,&m)) { for(int i = 0;i<n;i++){ for(int j = 0;j<m;j++){ scanf("%d",&mp[i][j]); pos[i][mp[i][j]] = j; } } int l = 0; int r = n+1; while(r-l>1){ int mid = (l+r)>>1; if(ok(mid)){ r = mid; } else l =mid; } cout<<r<<endl; }}
- Atcoder-Sports Festival(二分+暴力+思维+贪心)
- AtCoder GC 018B: Sports Festival 题解
- AGC018:Sports Festival(二分)
- Atcoder 056 D 贪心+二分
- 【二分图染色】AtCoder CODE FESTIVAL 2017(qual B)C[3 Steps]题解
- AtCoder Grand Contest 011 A\B 贪心、二分
- Atcoder Code Festival 2016 Qual A D
- Atcoder CODE FESTIVAL 2017 qual C D
- [Atcoder CODE FESTIVAL 2017 qual C]D
- 【AtCoder CODE FESTIVAL 2017 qual C】D
- Atcoder CODE FESTIVAL 2017 Final 简要题解
- AtCoder:Connected?(思维)
- 简单思维 AtCoder
- 数学 | 推理 | 思维 | 打表 | 找规律 | 贪心 | 暴力
- AtCoder:AtCoder Group Contest(思维)
- AtCoder:Widespread(二分)
- nyoj 1078 汉诺塔(四)[二分图 || 规律 || 暴力 || 贪心]
- Atcoder:TrBBnsformBBtion(思维 & 字符串)
- Mac编辑hosts配置文件
- eclipse 设置快捷键 查找下一个 上一个 运行 java 程序
- js获取table的行数与列数
- topgp登陆不了提示DVM connection timed out
- PXE启动原理以及与普通Linux启动的对比
- Atcoder-Sports Festival(二分+暴力+思维+贪心)
- Docker网络管理机制实例解析+创建自己Docker网络
- ArrayList、LinkedList、Vector的区别
- PLSQL条件语句完成员工加薪功能(记录类型+游标case when+if+for update+where current of)
- 推荐系统方法概览
- 安卓常用的框架
- VideoView之视频播放
- 使用Delve调试Go语言报错的结果办法
- 平面中判断点是否在某一三角形内算法 .