好久没有写题了。实在闲来无事,就又写一个水题。
以后不管参不参加比赛,坚持做题总是好的。cf,tc的比赛至少都是可以做做的。
这个题目其实也很简单,枚举一天中的每个时间,总共有60*24个,然后拿这些时间去检验和输入的两个时间是否相符即可。
代码写的比较长,不过应该还算比较清晰。
惭愧的是连这个题的wa了一次,因为下标变换的时候漏写了一个-1。
/*
* Author: stormdpzh
* Created Time: 2013/3/3 12:41:23
* File Name: poj_1676.cpp
*/
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <functional>
#define sz(v) ((int)(v).size())
#define rep(i, n) for(int i = 0; i < n; i++)
#define repf(i, a, b) for(int i = a; i <= b; i++)
#define repd(i, a, b) for(int i = a; i >= b; i--)
#define out(n) printf("%d\n", n)
#define mset(a, b) memset(a, b, sizeof(a))
#define lint long long
using namespace std;
const int INF = 1 << 30;
const int MaxN = 100005;
const int digit[10][9] = {
{0, 1, 0, 1, 0, 1, 1, 1, 1}, //0
{0, 0, 0, 0, 0, 1, 0, 0, 1}, //1
{0, 1, 0, 0, 1, 1, 1, 1, 0}, //2
{0, 1, 0, 0, 1, 1, 0, 1, 1}, //3
{0, 0, 0, 1, 1, 1, 0, 0, 1}, //4
{0, 1, 0, 1, 1, 0, 0, 1, 1}, //5
{0, 1, 0, 1, 1, 0, 1, 1, 1}, //6
{0, 1, 0, 0, 0, 1, 0, 0, 1}, //7
{0, 1, 0, 1, 1, 1, 1, 1, 1}, //8
{0, 1, 0, 1, 1, 1, 0, 1, 1} //9
};
int ac_time[5][10];
int sl_time[5][10];
char buf[35];
void init()
{
rep(i, 3) {
gets(buf);
rep(j, 12) {
if(buf[j] == '_' || buf[j] == '|') ac_time[j / 3][i * 3 + j % 3] = 1;
else ac_time[j / 3][i * 3 + j % 3] = 0;
}
repf(j, 13, 24) {
if(buf[j] == '_' || buf[j] == '|') sl_time[(j - 1) / 3 - 4][i * 3 + (j - 1) % 3] = 1;
else sl_time[(j - 1) / 3 - 4][i * 3 + (j - 1) % 3] = 0;
}
}
}
bool judge_ac_time(int h, int m)
{
int x = h / 10;
rep(i, 9) {
if(ac_time[0][i] == 1 && digit[x][i] == 0)
return false;
}
x = h % 10;
rep(i, 9) {
if(ac_time[1][i] == 1 && digit[x][i] == 0)
return false;
}
x = m / 10;
rep(i, 9) {
if(ac_time[2][i] == 1 && digit[x][i] == 0)
return false;
}
x = m % 10;
rep(i, 9) {
if(ac_time[3][i] == 1 && digit[x][i] == 0)
return false;
}
return true;
}
bool judge_sl_time(int h, int m)
{
int x = h / 10;
rep(i, 9) {
if(sl_time[0][i] == 1 && digit[x][i] == 0) {
return false;
}
}
x = h % 10;
rep(i, 9) {
if(sl_time[1][i] == 1 && digit[x][i] == 0)
return false;
}
x = m / 10;
rep(i, 9) {
if(sl_time[2][i] == 1 && digit[x][i] == 0)
return false;
}
x = m % 10;
rep(i, 9) {
if(sl_time[3][i] == 1 && digit[x][i] == 0)
return false;
}
return true;
}
void gao()
{
int h = -1, m = -1;
rep(i, 24) {
rep(j, 60) {
if(judge_ac_time(i, j)) {
int x = i;
int y = j - 15;
if(y < 0) {
y += 60;
x--;
if(x < 0) x = 23;
}
if(judge_sl_time(x, y)) {
if(h != -1) {
printf("Not Sure\n");
return ;
}
h = i;
m = j;
}
}
}
}
if(h == -1) printf("Not Sure\n");
else printf("%02d%02d\n", h, m);
}
int main()
{
int t;
scanf("%d", &t);
getchar();
while(t--) {
init();
gao();
}
return 0;
}
本文探讨了一种简单的时间匹配算法,通过枚举一天中的所有时间点,与给定的两个时间进行比较验证。该算法适用于CF、TC等比赛场景,尽管代码较长,但逻辑清晰。作者分享了在实现过程中遇到的错误,如下标变换时忘记减一的情况,并提供了完整的代码示例。

1742

被折叠的 条评论
为什么被折叠?



