問題 F: Exam Manipulation時間限制: 1 Sec 內存限制: 128 MB


題目描述

A group of students is taking a True/False exam. Each question is worth one point. You, as their teacher, want to make your students look as good as possible—so you cheat! (I know, you would never actually do that.) To cheat, you manipulate the answer key so that the lowest score in the class is as high as possible.
What is the best possible lowest score you can achieve?

輸入

The first line of input contains two integers n (1 ≤ n ≤ 1,000) and k (1 ≤ k ≤ 10), where n is the number of students, and k is the number of True/False questions on the exam.
Each of the next n lines contains a string of length k, consisting only of upper-case ‘T’ and upper-case ‘F’. This string represents the answers that a student submitted, in the order the questions were given.

輸出

Output, on a single line, the best possible lowest score in the class.

題目大意

輸入第一個數字代表學生數(行數),第二個代表題目數量(列數),老師可以更改每一個題的答案(也可以不改)以此讓這個題的正確率更高一些,要輸出最好情況下的最低分

大概思路

每一個題有兩種狀態0或者1,找出n位0和1的全排列,每一次都把當前的全排列當做正確答案,=來判斷每一個學生的分數,找出最小的,每一次的最小的中取最大的就是最好情況下的最低分

樣例輸入 [Copy](javascript:CopyToClipboard($('#sampleinput').text()))

【樣例1】
5 4
TFTF
TFFF
TFTT
TFFT
TFTF
【樣例2】
3 5
TFTFT
TFTFT
TFTFT

樣例輸出 [Copy](javascript:CopyToClipboard($('#sampleoutput').text()))

【樣例1】
2
【樣例2】
5

代碼

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
const int N = 1e3 + 10;
string s[N];
int main()
{
    int n, k;
    cin >> n >> k;//n是學生數目, m是題目數目
    for (int i = 0; i < n; i ++ )cin >> s[i];//輸入s[]
    //用全排列去計算每一個學生的成績然后取一個最大值
    int ans = -1e9;
    for (int i = 0; i < (1 << k); i ++ )
    {
        string now = "";
        for (int j = 0; j < k; j ++ )
        {
            now += (i >> j & 1) + '0';//i >> j & 1 是每一次取第i位
        }
        //計算每一個學生的成績    取最小
        int t = 1e9;
        for (int j = 0; j < n; j ++ )
        {
            int res = 0;//每一個人在當前情況下的分數
            for (int _k = 0; _k < k; _k ++ )
            {
                if(s[j][_k] == 'T' && now[_k] == '1')
                    res ++;
                else if(s[j][_k] == 'F' && now[_k] == '0')
                    res ++;
            }
            t = min(t, res);//每一個答案對應的 每一個學生的成績   取最小    就是每一個答案對應的最小分數
        }
        ans = max(t, ans);//每一個最小成績 取最大 就是最后的答案      就是沒余承恩最小分數的最大分數
    }
    cout << ans << endl;
    return 0;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM