Created
September 12, 2012 13:20
-
-
Save hyfrey/3706544 to your computer and use it in GitHub Desktop.
pat 1014
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#define MAX_TIME 9*60 | |
int main(){ | |
int N, M, K, Q; | |
scanf( "%d %d %d %d", &N, &M, &K, &Q ); | |
int **win = (int **)malloc(sizeof(int *)*N); | |
int i; | |
int *start = (int *)malloc(sizeof(int)*N); | |
int *end = (int *)malloc(sizeof(int)*N); | |
int *time = (int *)malloc(sizeof(int)*N); | |
for( i=0; i<N; i++){ | |
win[i] = (int *)malloc(sizeof(int)*K); | |
end[i] = time[i] = 0; | |
start[i] = 0; | |
} | |
int *query = (int*)malloc(sizeof(int)*Q); | |
int *time_length = (int *)malloc(sizeof(int)*K); | |
int *end_time = (int *)malloc(sizeof(int)*K); | |
for( i=0; i<K; i++){ | |
scanf("%d", &time_length[i]); | |
end_time[i] = -1; | |
} | |
for( i=0; i<Q; i++){ | |
scanf("%d", &query[i] ); | |
} | |
int j=0; | |
int index; | |
while( j<K && j< N*M ){ | |
i = j%N; | |
index = end[i]; | |
win[i][index] = j; | |
end[i]++; | |
time[i] += time_length[j]; | |
if( time[i] - time_length[j] < MAX_TIME ){ | |
end_time[j] = time[i]; | |
} | |
j++; | |
} | |
int n = 0; | |
for( i=1; i<=540; i++){ | |
int flag = 0; | |
for( n = 0; n < N; n++ ){ | |
if( start[n] == end[n] ){ | |
continue; | |
} | |
index = start[n]; | |
int c_id = win[n][index]; | |
/* | |
if( end_time[c_id] == -1 ){ | |
continue; | |
} | |
*/ | |
flag = 1; | |
if( end_time[c_id] == i ){ | |
start[n]++; | |
if( j<K ){ | |
win[n][end[n]++] = j; | |
time[n] += time_length[j]; | |
if( time[n] - time_length[j] < MAX_TIME ){ | |
end_time[j] = time[n]; | |
} | |
j++; | |
} | |
} | |
} | |
if( flag == 0 ){ | |
break; | |
} | |
} | |
for( i=0; i<Q; i++){ | |
int k = query[i]-1; | |
if( end_time[k] == -1 ){ | |
printf("Sorry\n"); | |
continue; | |
} | |
int hour = end_time[k]/60 +8; | |
int mins = end_time[k]%60; | |
printf("%02d:%02d\n", hour, mins ); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment