1
8
2016
0

POJ2434 Waves

http://poj.org/problem?id=2434

单纯是看过题人少才来写一下_(:зゝ∠)_毕竟是USACO少数过题量少得可怜的题才不会说是因为从4月底开始翻翻到5月底感觉只有这一题能写一下

没有什么技巧,直接模拟上,因为只要输出(-4,-4)到(4,4)这个矩阵就行了,所以只要在这个9*9的矩阵建一个二维数组表示这个地方的高度,然后直接模拟就行了(比起其他一些强模题还是很和善的),注意遇到墙的反弹和输出中有墙

 

#include<cstdio>
using namespace std;
int a[9][9],tem,b1,b2,n,t,x,y,time;
bool init(int xx){
	if (xx>4)return false;
	if (xx<-4)return false;
	return true;
}
int wz(int xx){
	if (xx>b2)return 2;
	if (xx<b1)return 0;
	return 1;
}
void cover(int x,int y,int t,int jj){
	int k=wz(x);
	for (int i=0;i<t;i++){
		int xx=x+t-i;int yy=y+i;
		if (yy>4)break;
		if (yy<-4)continue;
		if ((k==0)&&(wz(xx)>0))xx=(b1<<1)-1-xx;
		if (k==1){
			xx=x+(t-i)%((b2-b1-1)<<1);
			if (xx>=b2)xx=(b2<<1)-xx-1;
			if (xx<=b1)xx=(b1<<1)-xx+1;
		}
		if (init(xx))a[xx+4][yy+4]+=jj;
	}
	for (int i=0;i<t;i++){
		int xx=x+i;int yy=y-t+i;
		if (yy>4)break;
		if (yy<-4)continue;
		if ((k==0)&&(wz(xx)>0))xx=(b1<<1)-1-xx;
		if (k==1){
			xx=x+i%((b2-b1-1)<<1);
			if (xx>=b2)xx=(b2<<1)-xx-1;
			if (xx<=b1)xx=(b1<<1)-xx+1;
		}
		if (init(xx))a[xx+4][yy+4]+=jj;
	}
	for (int i=0;i<t;i++){
		int xx=x-t+i;int yy=y-i;
		if (yy<-4)break;
		if (yy>4)continue;
		if ((k==2)&&(wz(xx)<2))xx=(b2<<1)-xx+1;
		if (k==1){
			xx=x-(t-i)%((b2-b1-1)<<1);
			if (xx<=b1)xx=(b1<<1)-xx+1;
			if (xx>=b2)xx=(b2<<1)-xx-1;
		}
		if (init(xx))a[xx+4][yy+4]+=jj;
	}
	for (int i=0;i<t;i++){
		int xx=x-i;int yy=y+t-i;
		if (yy<-4)break;
		if (yy>4)continue;
		if ((k==2)&&(wz(xx)<2))xx=(b2<<1)-xx+1;
		if (k==1){
			xx=x-i%((b2-b1-1)<<1);
			if (xx<=b1)xx=(b1<<1)-xx+1;
			if (xx>=b2)xx=(b2<<1)-xx-1;
		}
		if (init(xx))a[xx+4][yy+4]+=jj;
	}
}
int main(){
	scanf("%d%d%d%d",&n,&b1,&b2,&t);
	if (b2<b1){
		tem=b1;
		b1=b2;
		b2=tem;
	}
	for (int i=1;i<=n;i++){
		scanf("%d%d%d",&x,&y,&time);
		if (time>t)continue;
		if (time==t){
			if ((init(x))&&(init(y)))a[x+4][y+4]++;
			continue;
		}
		if (t-time==1){
			cover(x,y,1,1);
			continue;
		}
		if (t-time==2){
			cover(x,y,2,1);
			if ((init(x))&&(init(y)))a[x+4][y+4]--;
			continue;
		}
		cover(x,y,t-time,1);
		cover(x,y,t-time-2,-1);
	}
	for (int i=8;i>=0;i--){
		for (int j=0;j<=8;j++)if ((j==b1+4)||(j==b2+4))printf("X");
			else if (a[j][i]==0)printf("-");
				else if (a[j][i]>0)printf("*");
					else printf("o");
		printf("\n");
	}
	return 0;
}
Category: POJ | Tags: 模拟 usaco | Read Count: 1356

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com