QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#717766#3567. Digital ClockOdyssey0 164ms3796kbC++233.7kb2024-11-06 18:54:512024-11-06 18:54:52

Judging History

This is the latest submission verdict.

  • [2024-11-06 18:54:52]
  • Judged
  • Verdict: 0
  • Time: 164ms
  • Memory: 3796kb
  • [2024-11-06 18:54:51]
  • Submitted

answer




//坏的电子时钟
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <iomanip>
#include <sstream>

using namespace std;

// 7段显示器的数字0-9的段表示,使用7位二进制数表示每个段的开/关状态
const int DIGIT_SEGMENTS[10] = {
    0b1111110, // 0
    0b0110000, // 1
    0b1101101, // 2
    0b1111001, // 3
    0b0110011, // 4
    0b1011011, // 5
    0b1011111, // 6
    0b1110000, // 7
    0b1111111, // 8
    0b1111011  // 9
};

// 将时间字符串 "HH:MM" 转换为4个7段表示
vector<int> timeToSegments(const string& time) {
    int hours = stoi(time.substr(0, 2));
    int minutes = stoi(time.substr(3, 2));
    return { DIGIT_SEGMENTS[hours / 10], DIGIT_SEGMENTS[hours % 10],
            DIGIT_SEGMENTS[minutes / 10], DIGIT_SEGMENTS[minutes % 10] };
}

// 检查观察到的段模式是否可以与目标段模式匹配
bool isPatternConsistent(const vector<int>& observed, const vector<int>& target) {
    for (int i = 0; i < 4; ++i) {
        if ((observed[i] & target[i]) != observed[i]) {  // 观察到的段必须是目标段的子集
            return false;
        }
    }
    return true;
}

// 生成所有可能的初始时间
vector<string> generatePossibleTimes(int N, const vector<string>& observedPatterns) {
    vector<string> results;

    for (int h = 0; h < 24; ++h) {
        for (int m = 0; m < 60; ++m) {
            bool possible = true;
            vector<string> timesSequence;

            int hours = h;
            int minutes = m;

            for (int minute = 0; minute < N; ++minute) {
                ostringstream oss;
                oss << setw(2) << setfill('0') << hours << ":"
                    << setw(2) << setfill('0') << minutes;
                string timeStr = oss.str();

                //cout << timeStr << endl;

                vector<int> expectedSegments = timeToSegments(timeStr);
                vector<int> observedSegments = timeToSegments(observedPatterns[minute]);

                if (!isPatternConsistent(observedSegments, expectedSegments)) {
                    possible = false;
                    break;
                }

                timesSequence.push_back(timeStr);

                // 增加1分钟
                minutes++;
                if (minutes == 60) {
                    minutes = 0;
                    hours = (hours + 1) % 24;
                }
            }

            if (possible) {
                results.push_back(timesSequence[0]);
            }
        }
    }

    return results;
}

int main() {
   /* vector<pair<int, vector<string>>> cases = {
        {1, {"88:88"}},
        {2, {"23:25", "23:26"}},
        {3, {"71:57", "71:57", "71:07"}}
    };*/
    vector<pair<int, vector<string>>> cases;
    int cnt = 0, n;
    while (cin>>n)
    {
        string bin;
        vector<string> pattern;
        for (int i = 0; i < n; i++)
        {
            cin >> bin;
            pattern.push_back(bin);
        }
        cases.push_back(make_pair(n, pattern));
        
        int N = cases[cnt].first;
        const vector<string>& patterns = cases[cnt].second;

        vector<string> possibleTimes = generatePossibleTimes(N, patterns);

        if (possibleTimes.empty()) {
            cout << "none" << endl;
        }
        else {
            for (size_t i = 0; i < possibleTimes.size(); ++i) {
                if (i > 0) cout << " ";
                cout << possibleTimes[i];
            }
            cout << endl;
        }
        cnt++;

    }
 /*   for (const auto& caseItem : cases) {
       
    }*/

    

    return 0;
}



詳細信息


Pretests


Final Tests

Test #1:

score: 0
Wrong Answer
time: 164ms
memory: 3796kb

input:

1 88:88
2 23:25 23:26
3 71:57 71:57 71:07
1 00:00
1 11:11
1 22:22
1 33:33
1 44:44
1 55:55
1 66:66
1 77:77
1 88:88
1 99:99
1 08:28
1 78:48
1 24:11
1 31:11
1 11:60
5 23:11 23:11 23:11 23:11 23:11
6 23:11 23:11 23:11 23:11 23:11 23:11
6 23:11 23:11 23:11 23:11 23:11 23:12
2 08:19 08:20
2 27:77 27:17
2 ...

output:

none
23:25
00:58 03:58 07:58 08:58
00:00 00:08 08:00 08:08
00:00 00:01 00:03 00:04 00:07 00:08 00:09 00:10 00:11 00:13 00:14 00:17 00:18 00:19 00:30 00:31 00:33 00:34 00:37 00:38 00:39 00:40 00:41 00:43 00:44 00:47 00:48 00:49 01:00 01:01 01:03 01:04 01:07 01:08 01:09 01:10 01:11 01:13 01:14 01:17 0...

result:

wrong answer 21st lines differ - expected: 'none', found: '23:07 23:37'