hiho一下 第九十周 Swimming Plans

时间限制: 10000ms
单点时限: 1000ms
内存限制: 256MB

描述

Steven loves swimming! The swimming pool he goes to every afternoon consists of N parallel lanes which are number from 0 to N-1. Steven plans to swim for R rounds. Each round he chooses a lane and swim to the other side, spending exactly L units of time.

Since the weather is getting hotter, the swimming pool is very crowded. To prevent from accidents, the swimming pool manager asks everyone to submit their plans before swimming. A plan contains specific informations for a round, including t - the time he starts, l - the time he spends, n - the lane he chooses, d - the direction he swims(0 for swimming from west to east and 1 for swimming from east to west). Everyone starts at some integeral time and swims at a constant speed.

The plans should not conflict with each other: two swimmers are not allowed to meet in the middle of a lane (meeting at the sides is allowed).

Steven arrives at time T and gets Q plans of the other swimmers. So here's the question, what's the earliest time that Steven can finish his swimming plans?

Note that Steven starts from the west side and he moves from one side to the other only by swimming.

输入

Input contains multiple testcases.

The first line is an integer TASKS, representing the number of testcases.

For each testcase, the first line contains five integers T, L, R, N and Q which are described above.

The following Q lines describe the plans, each line with four integers, t, l, n, d, which are described above.

For all testcases:

0 <= T, t <= 104

1 <= L, l <= 104

1 <= R <= 104

0 <= Q <= 104

1 <= N <= 103

输出

The earliest time that Steven can finish his swimming plans.


题目分析

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct Event{
	int t;
	int x;
	int n;
}Event;

Event event[2][20000];
int count[2];

void AddEvent(int t, int x, int n, int d){
	event[d][count[d]].t = t;
	event[d][count[d]].x = x;
	event[d][count[d]].n = n;
	count[d]++;
}

int comp(const void* a, const void* b){
	Event* c = (Event*)a;
	Event* d = (Event*)b;
	
	if(c->t != d->t)
		return c->t - d->t;
	else
		return c->x - d->x;	
}

int main(){
	int TASK, T, L, R, N, Q;
	int t, l, n, d;
	int i, D, find, point[2], lane[2][1000];
	
	scanf("%d", &TASK);
	while(TASK--){
		count[0] = 0;
		count[1] = 0;
		scanf("%d%d%d%d%d", &T, &L, &R, &N, &Q);
		for(i=0; i<Q; i++){
			scanf("%d%d%d%d", &t, &l, &n, &d);
			if(l < L){
				AddEvent(t-L+l, 1, n, d);
				AddEvent(t, -1, n, d);
			}else if(l == L){
				AddEvent(t-1, 1, n, d);
				AddEvent(t+1, -1, n, d);
			}else{
				AddEvent(t, 1, n, d);
				AddEvent(t+l-L, -1, n, d);
			}
			
			AddEvent(t-L, 1, n, 1-d);
			AddEvent(t+l, -1, n, 1-d);
		}
		
		qsort(event[0], Q*2, sizeof(Event), comp);
		qsort(event[1], Q*2, sizeof(Event), comp);
		
		D = 0;
		point[0] = 0;
		point[1] = 0;
		memset(lane, 0, sizeof(lane));
		while(R){
			find = 0;
			while(point[D] < 2*Q){
				if(event[D][point[D]].t < T){
					lane[D][event[D][point[D]].n] += event[D][point[D]].x;
					point[D]++;
				}else{
					for(i=0; i<N; i++){
						if(lane[D][i] == 0){
							find = 1;
							T += L;
							break;
						}
					}
					if(find)
						break;
					T = event[D][point[D]].t;
					lane[D][event[D][point[D]].n] += event[D][point[D]].x;
					point[D]++;	
				}	
			}
			if(!find)
				T += L;
			D = 1 - D;
			R--;	
		}
		
		printf("%d\n", T);
	}
	
	return 0;
} 

这道题A得好辛苦,memset那句,用sizeof(int)*2*N就会出错

今天先不管了,明天再想

有人能给解释下吗?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值