1. 程式人生 > >HDU 6607 Time To Get Up(狀態壓縮+枚舉)

HDU 6607 Time To Get Up(狀態壓縮+枚舉)

code ace scanf += sin pac 進制 != spa

題目網址: http://acm.hdu.edu.cn/showproblem.php?pid=6077

思路:

先預處理一下,將每個數字塊的“X”看作1,“.”看作0,進行狀態壓縮轉換成二進制數,用數組保存。再遍歷每個塊點的元素,枚舉0-9看是否符合當前位數。

代碼:

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cmath>
 4 typedef long long ll;
 5 using namespace std;
 6 char clock[10][25];
 7 char str[30];
8 int vis[10]; 9 int mp[15]={//分別對應0-9 10 110692758, 11 1114384, 12 101804166, 13 101802262, 14 10051856, 15 109601046, 16 109603222, 17 101777680, 18 110717334, 19 110715158 20 }; 21 int main(){ 22 int t,cur=0; 23 scanf("%d",&t); 24 while(t--){ 25 for(int i=0
; i<7; ++i) { 26 for(int j=0; j<21; ++j) { 27 scanf(" %c",&clock[i][j]); 28 } 29 } 30 int cnt=0; 31 for(int k=0;k<4;k++){ 32 memset(vis,0,sizeof(vis));//處理每個塊之前都要初始化vis 33 for(int i=0;i<7;i++){ 34 for
(int j=0;j<4;j++){ 35 int pos=27-i*4-j;//當前對應的右移數 36 int w=clock[i][j+cnt]==X?1:0; 37 for(int v=0;v<=9;v++){ 38 if(((mp[v]>>pos)&1)!=w){ 39 vis[v]=1; 40 } 41 } 42 } 43 } 44 cnt+=5;//進入下一個模塊 45 for(int i=0;i<10;i++){ 46 if(!vis[i]) printf("%d",i); 47 } 48 if(k==1) cnt+=2,printf(":");// 略過“:” 49 } 50 printf("\n"); 51 } 52 return 0; 53 }

HDU 6607 Time To Get Up(狀態壓縮+枚舉)