GYM - 100812B Set of Tasks (思维好题)

Set of Tasks
time limit per test
2.0 s
memory limit per test
256 MB
input
standard input
output
standard output

I was heading to the old tavern «ChivalryForces», because I knew that the Princess spent a lot of time there. In the basement of the tavern the bets on a popular joust «ACM ICPC» were taken. Disgusting place, full of all sorts of scum of society. On the tournament knights formed teams of three and performed tasks, which had been prepared earlier by the members of special jury consisting of nrepresentatives of oligarchic clans and bandit gangs. The atmosphere was extremely tense there. The judges once nearly killed each other during the preparation of tasks.

They had prepared m tasks, but every judge had his own opinion which of them should have been included to the final set and which should have been kept for the next tournament. If the final set had included the task which the judge didn't want to see in it, or if it hadn't included the task he wanted to be included, he would have got terribly upset, and of course that upset included physical abuse with the use of bladed weapons. Little known that time bandit called Dragon was one of the judges, and he managed to correct everything. He suggested to choose such set of tasks for the tournament so that the number of judges who would become upset was as minimal as possible. Also, according to the rules, the number of tasks for the tournament had to be between eight and fifteen inclusively, and it should have been taken into account. It was not a great problem to choose such set of tasks. Much more difficult thing was to persuade those who got upset because of the fairness of that decision, but Dragon had a special approach to people.

Input

The first line contains two integers separated by a space: n and m (1 ≤ n ≤ 50008 ≤ m ≤ 5000) — the number of judges and the number of tasks correspondingly.

The next n lines contains m digits each, without spaces. The i-th line on its j-th position has digit 0 if the i-th judge doesn't want to see the j-th task in the final set, or digit 1 if he, on the contrary, wants this task to be included to the final set.

Output

Output a line of m digits. On the j-th position output 0 if the j-th task should not be included to the final set, otherwise output 1 there. The number of ones in the line should be between 8 and 15, inclusively. If there are several suitable sets of tasks, output any of them.

Examples
input
4 20
11000000001111111111
11100000001111111111
11000000001111111111
10000000001111111111
output
11000000001111111111
input
8 20
10101010001111111111
10101001001111111111
10101010001111111111
10101001001111111111
11111001001111111111
11111001001111111111
11111001001111111111
11111001001111111111
output
10101001001111111111


题意:有N个裁判,每个裁判喜欢不同的任务,现在有一个比赛要8~15个任务,找到最好的方案,使得最少的裁判不开心。


解题思路:一开始往DP那想了,其实没有必要……你只能尽可能的去满足更多的裁判。因为当两个裁判对同一个任务兴趣有不同时,你只能满足其中任意一个裁判,所以你永远都无法做到最优!这个时候只能满足尽可能多兴趣相同的裁判


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <memory.h>
#include <bitset>
#include <map>
using namespace std;
typedef long long int ll;
int N, M;

map<string, int> snum;

int main()
{

    ios::sync_with_stdio(false);
    cin >> N >> M;
    string ans;
    string temp;

    int num = 0;

    for (int i = 0; i < N; i++)
    {

        cin >> temp;

        int ones = 0;
        for (int i = 0; i < temp.size(); i++)
            if (temp[i] == '1')
                ones++;

        if (8 <= ones && ones <= 15)
        {
            if (++snum[temp] > num)
            {
                num = snum[temp];
                ans = temp;
            }
        }
    }

    if (ans == "")
    {
        ans.resize(M, '0');
        for (int i = 0; i < 8; i++)
            ans[i] = '1';
    }

    cout << ans << endl;

    return 0;
}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值