1430.cpp

来自「这是哈尔滨工业大学acmOJ的源代码」· C++ 代码 · 共 53 行

CPP
53
字号
/*  This Code is Submitted by wywcgs for Problem 1430 on 2006-01-20 at 19:18:47 */ 
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int B_MAX = 32;
const int S_MAX = 16;
const int INF = 1 << 30;

class Bus {
private:
	int stop, time[S_MAX];
public:
	void make();
	int next(int) const;
};
void Bus::make() {
	stop = 0; time[stop++] = 0;
	while(true) {
		scanf("%d", &time[stop]);
		time[stop] += time[stop-1]; stop++;
		char ch;
		while((ch = getchar()) == ' ') ;
		if(ch == '\n') break;
		else ungetc(ch, stdin);
	}
}
int Bus::next(int t) const {
	int real = t % time[stop-1];
	int n = lower_bound(time, time+stop, real) - time;
	return time[n] - real;
}

int main()
{
	char line[B_MAX];
	Bus bus[B_MAX];
	int i, bn, time, t;
	
	for(t = 0; scanf("%s", line) != EOF && strcmp(line, "ENDOFINPUT"); t++) {
		if(t != 0) putchar('\n');
		scanf("%d", &bn);
		for(i = 0; i < bn; i++) bus[i].make();
		scanf("%d %*s", &time);
		int wait = INF;
		for(i = 0; i < bn; i++) wait = min(wait, bus[i].next(time));
		printf("%d", wait);
	}
	
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?