1. 程式人生 > >UESTC 2016 Summer Training #4 Div.2 A

UESTC 2016 Summer Training #4 Div.2 A

A - (。•_•。) Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

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 courses A
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 courses A 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 contain m numbers 0 or 1. The j-th number in the i-th row is equal to 1, if the i-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 to m meaning the courses that Nikita should choose. If there are many optimal solutions, you may output any one of them.

Sample Input

input output
6 4
0 0 0 1
0 0 1 0
0 1 1 1
1 1 1 1
0 0 0 0
1 0 0 1
2
1 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!