UVALive 6269 Digital Clock --枚举,模拟
来源:互联网 发布:淘宝申诉失败再申述 编辑:程序博客网 时间:2024/06/06 15:42
题意:说不清楚,自己看吧,太恶心。
这题真是SB了,当时看了一下以为乱搞就好了,于是开始动手拍,结果拍了好几个小时都没拍出来,而且越想越想不通,直接把自己绕进去了,结果gg了。
总结:甭管什么题,想清楚了再拍。其实当初绕进去的时候,应该换个思路重新来一遍更好
解法:枚举时间从00:00~23:59,数字显示用7位01串表示,如图:
,每次检查与给出的观察序列是否能够逻辑一致。
关键在check部分,这部分我都写了注释了,应该比较易懂了。
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <algorithm>#include <string>#include <vector>using namespace std;#define N 100007string num[12] = {"1110111","0010010","1011101","1011011","0111010","1101011","1101111","1010010","1111111","1111011"};struct node{ int mi,sec; node(int _mi,int _sec) { mi = _mi; sec = _sec; } node(){}}p[56];int h1[5][8],h2[5][8],broken[5][8];vector<node> ans;int get(int *a,int n){ for(int i=0;i<7;i++) a[i] = num[n][i] - '0';}void add(node &x,int val){ x.sec += val; x.mi += x.sec/60; x.mi%=24; x.sec%=60;}void getH1(node ka) //观察的{ memset(h1,0,sizeof(h1)); get(h1[0],ka.mi/10); get(h1[1],ka.mi%10); get(h1[2],ka.sec/10); get(h1[3],ka.sec%10);}void getH2(node ka) //枚举的{ memset(h2,0,sizeof(h2)); get(h2[0],ka.mi/10); get(h2[1],ka.mi%10); get(h2[2],ka.sec/10); get(h2[3],ka.sec%10);}bool check(){ int i,j; for(i=0;i<4;i++) { for(j=0;j<7;j++) { if(h1[i][j] == 0 && h2[i][j] == 1) //观察到没有,现在枚举到有 -> 坏了 { if(broken[i][j] == 0) //还不知道坏没坏 broken[i][j] = -1; //定义为坏了 else if(broken[i][j] == 1) //与前面矛盾 return false; } else if(h1[i][j] == 1 && h2[i][j] == 0) //观察到有,枚举的没有,那么这个枚举的不行 return false; else if(h1[i][j] == 1 && h2[i][j] == 1) //都有 { if(broken[i][j] == 0) //还未定义好坏 broken[i][j] = 1; //肯定是好的 else if(broken[i][j] == -1) //前面说坏了,矛盾 return false; } } } return true;}int main(){ int n,i,j; while(scanf("%d",&n)!=EOF) { for(i=0;i<n;i++) scanf("%d:%d",&p[i].mi,&p[i].sec); ans.clear(); for(int H=0;H<=23;H++) { for(int M=0;M<=59;M++) { node tmp; tmp.mi = H,tmp.sec = M; int flag = 1; memset(broken,0,sizeof(broken)); for(i=0;i<n;i++) { node now = tmp; add(now,i); getH1(p[i]); getH2(now); if(!check()) { flag = 0; break; } } if(flag) ans.push_back(node(H,M)); } } if(ans.size() == 0) puts("none"); else { printf("%02d:%02d",ans[0].mi,ans[0].sec); for(i=1;i<ans.size();i++) printf(" %02d:%02d",ans[i].mi,ans[i].sec); puts(""); } } return 0;}
0 0
- UVALive 6269 Digital Clock --枚举,模拟
- UVALive - 6269 Digital Clock 模拟
- UvaLive--6664--Clock Hands【模拟】
- zoj 3131 Digital Clock
- ZOJ3131 Digital Clock
- zoj 3131 Digital Clock
- ZOJ 3131 Digital Clock
- QT实现Digital Clock
- UvaLive 6664 Clock Hands
- UVALive 6664 Clock Hands
- Clock Splitter+uvalive+二分
- UVALive 2037 Digital River
- zoj3131 Digital Clock(2)
- 【QT 教程】Digital Clock Example
- Digital Clock 数论水题
- UVa 1529 - Clock (模拟)
- HDU 5387 Clock // 模拟
- HDU5387 Clock 时钟模拟
- HDU 4865 Peter's Hobby --概率DP
- 树形DP求树的重心 --SGU 134
- HDU 4930 Fighting the Landlords --多Trick,较复杂模拟
- Codeforces Round 261 Div.2 D Pashmak and Parmida's problem --树状数组
- Codeforces Round 261 Div.2 E Pashmak and Graph --DAG上的DP
- UVALive 6269 Digital Clock --枚举,模拟
- UVALive 6656 Watching the Kangaroo --二分
- POJ 2528 Mayor's posters --线段树+离散化
- HDU 4964 Emmet --模拟
- ZOJ 2301 / HDU 1199 Color the Ball 离散化+线段树区间连续最大和
- POJ 1151 / HDU 1542 Atlantis 线段树求矩形面积并
- UVA 11983 Weird Advertisement --线段树求矩形问题
- HDU 1828 / POJ 1177 Picture --线段树求矩形周长并
- POJ 3225 Help with Intervals --线段树区间操作