zoukankan      html  css  js  c++  java
  • 【题解】 csp.ac #6. 低仿机器人(T1-1)

    题目

    csp.ac #6. 低仿机器人(T1-1)
    进去404可能是你没登账号,等了账号还是404可能是你没权限。

    思路

    大模拟。相比猪国杀和琪露诺的冰雪小屋而言这完全不用动脑子,实在是适合我。

    分析

    按题目说的做就行。不用动脑子。
    几个需要注意的点:
    1.给你的 (n imes m)的矩阵是从第 (0) 行第 (0) 列开始编号的,不看样例注意不到。。
    2.给你的命令后的参数可能是实数。
    3.不论最后是ERROR还是Complete都要把这一组数据剩下的命令读完。

    Code

    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<iostream>
    #include<algorithm>
    
    inline void read(int &T) {
    	int x=0;bool f=0;char c=getchar();
    	while(c<'0'||c>'9'){if(c=='-')f=!f;c=getchar();}
    	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    	T=f?-x:x;
    }
    
    int t,n,m,map[201][201];
    int jqx,jqy,a,b,c,k,h;
    int djrl,pdlx[31];
    int jqfx,ptfx;
    bool fin;
    
    void format() {
    	h=0,ptfx=0,jqfx=0;
    	djrl=0,fin=0;
    }
    
    void clear(int x) {
    	std::string s;getchar();
    	for(int i=1;i<=k-x;++i) {
    		getline(std::cin,s);
    	}
    }
    
    void finish(bool type) {
    	fin=1;
    	if(!type) puts("ERROR");
    	else puts("Complete");
    	printf("%d %d
    ",jqx,jqy);
    	printf("%d
    ",h);
    	printf("%d %d %d %d
    ",ptfx,jqfx,b,c);
    }
    
    void FT() {
    	double x1;std::cin>>x1;
    	int x=x1;if(x!=x1) {finish(0);return;}
    	if(x!=0&&x!=1) {finish(0);return;}
    	if(x==0) {
    		ptfx+=1;
    		if(ptfx==4) ptfx=0;
    	}else {
    		ptfx-=1;
    		if(ptfx==-1) ptfx=3;
    	}
    }
    
    void FF() {
    	double x1;std::cin>>x1;
    	int x=x1;if(x!=x1) {finish(0);return;}
    	if(x!=0&&x!=1) {finish(0);return;}
    	if(djrl==a) {finish(0);return;}
    	if(x==0) {
    		if(c==0) return;
    		--c;
    		pdlx[++djrl]=x+1;
    	}else {
    		if(b==0) return;
    		--b;
    		pdlx[++djrl]=x+1;
    	}
    }
    
    void FE() {
    	if(djrl==0) return;
    	int pdx=jqx,pdy=jqy;
    	if(ptfx==0) {
    		while(pdx>=0) {
    			--pdx;
    			if(map[pdx][pdy]==1||map[pdx][pdy]==2) {
    				map[pdx][pdy]=std::max(0,map[pdx][pdy]-pdlx[djrl]);
    				if(map[pdx][pdy]==0) ++h;
    				--djrl;return;
    			}
    			if(map[pdx][pdy]==2147483647) {--djrl;return;}
    		}
    	}else if(ptfx==1) {
    		while(pdy>=0) {
    			--pdy;
    			if(map[pdx][pdy]==1||map[pdx][pdy]==2) {
    				map[pdx][pdy]=std::max(0,map[pdx][pdy]-pdlx[djrl]);
    				if(map[pdx][pdy]==0) ++h;
    				--djrl;return;
    			}
    			if(map[pdx][pdy]==2147483647) {--djrl;return;}
    		}
    	}else if(ptfx==2) {
    		while(pdx<n) {
    			++pdx;
    			if(map[pdx][pdy]==1||map[pdx][pdy]==2) {
    				map[pdx][pdy]=std::max(0,map[pdx][pdy]-pdlx[djrl]);
    				if(map[pdx][pdy]==0) ++h;
    				--djrl;return;
    			}
    			if(map[pdx][pdy]==2147483647) {--djrl;return;}
    		}
    	}else if(ptfx==3) {
    		while(pdy<m) {
    			++pdy;
    			if(map[pdx][pdy]==1||map[pdx][pdy]==2) {
    				map[pdx][pdy]=std::max(0,map[pdx][pdy]-pdlx[djrl]);
    				if(map[pdx][pdy]==0) ++h;
    				--djrl;return;
    			}
    			if(map[pdx][pdy]==2147483647) {--djrl;return;}
    		}
    	}
    	--djrl;
    }
    
    void WT() {
    	double x1;std::cin>>x1;
    	int x=x1;if(x!=x1) {finish(0);return;}
    	if(x!=0&&x!=1) {finish(0);return;}
    	if(x==0) {
    		jqfx+=1;if(jqfx==4) jqfx=0;
    	}else {
    		jqfx-=1;if(jqfx==-1) jqfx=3;
    	}
    }
    
    void WG() {
    	double x1;std::cin>>x1;
    	int x=x1;if(x!=x1) {finish(0);return;}
    	if(x<0||x>=std::max(n,m)) {finish(0);return;}
    	int tempx=jqx,tempy=jqy;
    	if(jqfx==0) {
    		while(x) {
    			--tempx;
    			if(tempx<0) {finish(0);return;}
    			if(map[tempx][tempy]!=0) {finish(0);return;}
    			--x;
    		}
    		jqx=tempx;
    	}else if(jqfx==1) {
    		while(x) {
    			--tempy;
    			if(tempy<0) {finish(0);return;}
    			if(map[tempx][tempy]!=0) {finish(0);return;}
    			--x;
    		}
    		jqy=tempy;
    	}else if(jqfx==2) {
    		while(x) {
    			++tempx;
    			if(tempx>=n) {finish(0);return;}
    			if(map[tempx][tempy]!=0) {finish(0);return;}
    			--x;
    		}
    		jqx=tempx;
    	}else if(jqfx==3) {
    		while(x) {
    			++tempy;
    			if(tempy>=m) {finish(0);return;}
    			if(map[tempx][tempy]!=0) {finish(0);return;}
    			--x;
    		}
    		jqy=tempy;
    	}
    }
    
    int main() {
    	read(t);
    	while(t--) {
    		format();read(n),read(m);
    		for(int i=0;i<n;++i) {
    			for(int j=0;j<m;++j) {
    				read(map[i][j]);
    				if(map[i][j]==1) {
    					map[i][j]=2147483647;
    				}
    			}
    		}
    		read(jqx),read(jqy),read(a);
    		read(b),read(c),read(k);
    		std::string cmd;
    		for(int i=1;i<=k;++i) {
    			std::cin>>cmd;
    			if(cmd=="FT") {
    				FT();if(fin) {clear(i);break;}
    			}else if(cmd=="FF") {
    				FF();if(fin) {clear(i);break;}
    			}else if(cmd=="FE") {
    				FE();
    			}else if(cmd=="WT") {
    				WT();if(fin) {clear(i);break;}
    			}else if(cmd=="WG") {
    				WG();if(fin) {clear(i);break;}
    			}else if(cmd=="END") {
    				finish(1);if(fin) {clear(i);break;}
    			}
    		}
    		if(!fin) finish(0);
    	}
    	return 0;
    }
    
  • 相关阅读:
    namespace std 定义的位置
    [Struts]学习日记3 在页面中显示条目列表
    [Hibernate]关于ID的一个容易混淆的地方
    [Struts]"Cannot find bean in any scope"之一解
    [Struts]HibernatePlugIn for Struts(转贴)
    日志搬家了!
    [Struts]学习日记2 增加一些验证
    实验室的项目 讨论
    Struts常见异常信息和解决方法
    参加婚礼
  • 原文地址:https://www.cnblogs.com/poi-bolg-poi/p/12775778.html
Copyright © 2011-2022 走看看