UESTC 2016 Summer Training #4 Div.2 A - (。•_•。) 预处理打表

来源:互联网 发布:淘宝ipad 编辑:程序博客网 时间:2024/05/29 16:25

A - (。•_•。)
Crawling in process...Crawling failedTime Limit:1000MS    Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
SubmitStatus Practice URAL 2091

Description

Winter in Yekaterinburg is the longest time of the year. And everyone spends long winter evenings in his own way. According to Nikita, he has no time for entertainment this year. Sure, because six months later he will try to enter the Institute of Mathematics and Computer Sciences. So now, Nikita should choose a degree program, that he wants to study. Recently, so much new programs appeared at the Institute that it is very difficult to compare them all together and to make the right choice.
At the beginning, Nikita found out what courses are included in each of the programs. After that, he wants to choose two coursesA and B and divide all programs into four sets (some of them may be empty):
  1. Programs, which include both course A and course B.
  2. Programs, which include the course A, but do not include the course B.
  3. Programs, which do not include the course A, but include the course B.
  4. Programs, which include neither course A nor course B.
Nikita wants to minimize the size of the largest of these four sets. What coursesA and B should he choose for this?

Input

The first line contains integers n and m that are the number of degree programs at the Institute and the number of courses(4 ≤ n, m ≤ 100) . The following n lines containm numbers 0 or 1. The j-th number in the i-th row is equal to 1, if thei-th program includes the j-th course, and 0 otherwise.

Output

Output in the first line the maximum size of four described sets under optimal division. In the second line output two different integers in the range from 1 tom meaning the courses that Nikita should choose. If there are many optimal solutions, you may output any one of them.

Sample Input

inputoutput
6 40 0 0 10 0 1 00 1 1 11 1 1 10 0 0 01 0 0 1
21 3

Notes

The choice of courses 1 and 3 divides all degree programs to the following sets: {4}, {6}, {2, 3}, {1, 5}. 


Source

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=122043#problem/A


My Solution

for for 枚举C(m, 2) 打好表, 然后然后找出最小的最大值  (。•_•。) 

题目很简单, 人人过的题, 但觉得还是有点意思所以也整理到这里

#include <iostream>#include <cstdio>#include <set>using namespace std;typedef long long LL;const int maxn = 100 + 8;bool deg[maxn][maxn];int ans[maxn][maxn];int main(){    #ifdef LOCAL    freopen("a.txt", "r", stdin);    //freopen("b.txt", "w", stdout);    int T = 1;    while(T--){    #endif // LOCAL    int n, m;    int s1, s2, s3, s4;    scanf("%d%d", &n, &m);    for(int i = 0; i < n; i++){        for(int j = 0; j < m; j++){            scanf("%d", °[i][j]);            //cout<<deg[i][j]<<" ";        }        //printf("\n");    }    for(int i = 0; i < m; i++){        for(int j = i + 1; j < m; j++){            s1 = s2 = s3 = s4 = 0;            for(int k = 0; k < n; k++){                if(deg[k][i] && deg[k][j]) s1++;                else if(deg[k][i] && !deg[k][j]) s2++;                else if(!deg[k][i] && deg[k][j]) s3++;                else s4++;            }            ans[i][j] = max(s1, max(s2, max(s3, s4)));        }    }    int min_max = 1000000000;    for(int i = 0; i < m; i++){        for(int j = i + 1; j < m; j++)            min_max = min(min_max, ans[i][j]);    }    bool okay = false;    for(int i = 0; i < m; i++){        for(int j = i + 1; j < m; j++){            if(min_max == ans[i][j]){                printf("%d\n%d %d", min_max, i + 1, j + 1);                okay = true; break;            }        }        if(okay) break;    }    #ifdef LOCAL    printf("\n");    }    #endif // LOCAL    return 0;}



  Thank you!

                                                                                                                                               ------from ProLights

0 0
原创粉丝点击