我会做这样的事情:
#include <stdio.h>#include <stdlib.h>#include <string.h>typedef uint MASK;#define INPUT_SCALE 60#define MAX_TIME (1440 * 60)void readPlaneData(int& endTime, MASK landingMask[MAX_TIME], int index){ char buf[128]; gets(buf); int start, end; sscanf(buf, "%d %d", &start, &end); for(int i=start * INPUT_SCALE; i<=end * INPUT_SCALE; i++) landingMask[i] |= 1 << index; if(end * INPUT_SCALE > endTime) endTime = end * INPUT_SCALE;}int findNextLandingForPlane(MASK landingMask[MAX_TIME], int start, int index){ while(start < MAX_TIME) { if(landingMask[start] & (1 << index)) return start; start++; } return -1;}bool canLandPlanes(int minTime, MASK landingMask[MAX_TIME], int planeCount){ int next = 0; for(int i=0; i<planeCount; i++) { int nextForPlane = findNextLandingForPlane(landingMask, next, i); if(nextForPlane == -1) return false; next = nextForPlane + minTime; } return true;}int main(int argc, char* argv[]){ while(true) { char buf[128]; gets(buf); int count = atoi(buf); if(count == 0) break; MASK landingMask[MAX_TIME]; memset(landingMask, 0, sizeof(landingMask)); int endTime = 0; for(int i=0; i<count; i++) readPlaneData(endTime, landingMask, i); while((endTime > 0) && !canLandPlanes(endTime, landingMask, count)) endTime--; printf("%d:%02dn", endTime / 60, endTime % 60); }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)