Robot solution

From ITRS
Jump to: navigation, search
#include <stdio.h>

enum{DE=0, DN=1};

int main()
{
	int m, n, x[2], y[2], te[2], tn[2], f[2], d[2], cd[2], i, time=0;

	cd[0] = cd[1] = 0;
	d[0] = DN, d[1] = DE;

	scanf(" %d %d %d %d %d %d %d %d %d %d %d %d",
			&m, &n, x, y, te, tn, f, x+1, y+1, te+1, tn+1, f+1);

	while(f[0] || f[1]){
		time++;
		for(i=0; i<2; i++){
			if(f[i]==0)
				continue;
			--f[i];
			x[i] += !d[i], y[i] += d[i];
			cd[i]++;
			if(d[i]==DE && cd[i]==te[i])
				d[i] = DN, cd[i] = 0;
			else if(d[i]==DN && cd[i]==tn[i])
				d[i] = DE, cd[i] = 0;
			if(x[i]==m) x[i] = 0;
			else if(y[i]==n) y[i] = 0;
		}
		//printf("%d %d ,%d %d\n", x[0], y[0], x[1], y[1]);
		if(x[0] == x[1] && y[0] == y[1]){
			printf("robots explode at time %d\n", time);
			return 0;
		}
	}
	printf("robots will not explode\n");

	return 0;
}

</span>

</pre>

Comments

blog comments powered by Disqus