1. 程式人生 > >UVa 509 RAID

UVa 509 RAID

put 難點 can lse tput sizeof -- inpu efi

這道題理解起來有點難,有點難寫,但是沒有什麽思維難點,可以看看別人博客上的翻譯,這裏我就懶的說了,233,下面是代碼。

//UVa 509
//PAID
#define LOCAL
#include <stdio.h> 
#include <string.h> //use memset

const int maxn = 10, maxd = 1e3 * 7; 
const char a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; 
const char b[] = {A, B, C, D, E, F};


char paid[maxn][maxd], Num[maxn*maxd];
int disk, size, block, cnt; void change_Printf() { memset(Num, 0, sizeof(Num)); printf("Disk set %d is valid, contents are: ", ++cnt); int N = 0, tot; for(int i = 0; i < size*block; i+=size) for(int j = 1; j <= disk; j++) { if(!((i/size - (j-1)) % disk)) continue
; for(int k = i; k < i+size; k++) Num[++N] = paid[j][k] - 0; } if(N % 4) N = (N / 4 + 1) * 4; for(int i = 0; i < N/4; i++) { tot = 0; for(int j = 4; j >= 1; j--) tot += (Num[i*4+j] * (1 << (4-j))); if(tot < 10
) printf("%d", a[tot]); else printf("%c", b[tot-10]); } printf("\n"); } int check(char M[]) { int T = 0, x, y; if(M[0] == O) T = 1; for(int i = 0; i < size*block; i++) { int cnt = 0; for(int j = 1; j <= disk; j++) if(paid[j][i] == x) { x = j; y = i; cnt++; } if(cnt >= 2) return 0; if(cnt == 1) { //change ‘x‘ paid[x][y] = 0; int C = paid[1][i] - 0; for(int j = 2; j <= disk; j++) C = C ^ (paid[j][i] - 0); if(C != T) paid[x][y] = 1; } if(cnt == 0) { int C = paid[1][i] - 0; for(int j = 2; j <= disk; j++) C = C ^ (paid[j][i] - 0); if(C != T) return 0; } } return 1; } int main() { #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif char mod[5]; while(scanf("%d", &disk) && disk != 0) { scanf("%d%d%s", &size, &block, mod); for(int i = 1; i <= disk; i++) scanf("%s", paid[i]); if(!check(mod)) { //no printf("Disk set %d is invalid.\n", ++cnt); continue; } change_Printf(); } return 0; }

UVa 509 RAID