⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1430.cpp

📁 这是哈尔滨工业大学acmOJ的源代码
💻 CPP
字号:
/*  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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -