zoukankan      html  css  js  c++  java
  • CSP.ac低仿机器人(T1-1)

    低仿机器人(T1-1)
    如果看不了请登入,如果还看不了就是你没去qbxt

    有这么几个问题要注意

    1> 注意指令参数
    2> 注意是上一步操作不是上一步,就是WG走了三步然后撞死了,不是走了两步的那个位置,是这个操作执行前的位置
    3> 还有一些问题在写的时候注意一下就行了(代码最后有400行的自造数据,可以自己试一下,应该基本包含了全部的细节)

    (Code)

    #include <cstdio>
    #include <iostream>
    #include <string>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <stack>
    
    #define int long long
    #define rr register
    
    #define MAXN 100010
    #define inf 1e18
    
    using namespace std;
    
    inline int read() {
    	int s = 0, f = 0;
    	char ch = getchar();
    	while (!isdigit(ch)) {if (ch == '
    ') break; f |= ch == '-'; ch = getchar();}
    	while (isdigit(ch)) {s = s * 10 + (ch ^ 48); ch = getchar();}
    	return f ? -s : s;
    }
    
    int T, n, m, x, y, a, b, c, k, opt;
    
    int paotai, jiqiren, bazix;
    
    bool fEND = 0, rio = 0;
    
    stack <int> S;
    
    int math[210][210], bazi[210][210];
    
    inline void init() {
    	memset(math, 0, sizeof math);
    	memset(bazi, 0, sizeof bazi);
    	fEND = 0;
    	rio = 0;
    	paotai = 0;
    	jiqiren = 0;
    	bazix = 0;
    	while (S.size()) S.pop();
    }
    
    inline void stepFE(int sjd);
    
    inline void stepWG(int step);
    
    signed main() {
    	cin >> T;
    	while (T--) {
    		init();
    		cin >> n >> m;
    		for (rr int i = 1; i <= n; i++)
    			for (rr int j = 1; j <= m; j++) {
    				cin >> math[i][j];
    				if (math[i][j] == 2) bazi[i][j] = 2;
    			}
    		for (rr int i = 1; i <= n; i++) math[i][0] = 1;
    		for (rr int i = 1; i <= m; i++)	math[0][i] = 1;
    		for (rr int i = 1; i <= n; i++)	math[i][m + 1] = 1;
    		for (rr int i = 1; i <= m; i++)	math[n + 1][i] = 1;
    		cin >> x >> y >> a >> b >> c >> k; 	
    		x++;
    		y++;
    		for (rr int i = 1; i <= k; i++) {
    			// if (math[x][y]) fEND = 1;
    			string stp;
    			if (fEND) {
    				getchar();
    				getline(cin, stp);
    				continue;
    			} 
    			cin >> stp;
    			double op;
    			if (stp == "FT") {
    				cin >> op;
    				if (op != (int)op) {
    					fEND = 1;
    					continue;
    				}
    				int opt = (int)op;
    				if (opt < 0 || opt > 1)  {
    					fEND = 1;
    					continue;
    				}
    				if (opt == 0) paotai = (paotai + 1) % 4;
    				else {
    					paotai--;
    					if (paotai < 0)
    						paotai = (paotai + 4) % 4;
    				}
    			}
    			else if (stp == "FF") {
    				cin >> op;				
    				if (op != (int)op) {
    					fEND = 1;
    					continue;
    				}
    				int opt = (int)op;
    				if (opt < 0 || opt > 1)  {
    					fEND = 1;
    					continue;
    				}
    				if (opt == 1) {
    					if (b == 0) continue;
    					if (S.size() == a) { fEND = 1; continue;}
    					b--, S.push(2);
    				} 
    				else {
    					if (c == 0) continue;
    					if (S.size() == a) { fEND = 1; continue;}
    					c--, S.push(1);
    				} 
    			}
    			else if (stp == "FE") {
    				int q = 0;
    				if (S.size()) {
    					q = S.top();
    					S.pop();
    				}
    				stepFE(q);	
    			}
    			else if (stp == "WT") {
    				cin >> op;
    				if (op != (int)op) {
    					fEND = 1;
    					continue;
    				}
    				int opt = (int)op;
    				if (opt < 0 || opt > 1)  {
    					fEND = 1;
    					continue;
    				}
    				if (opt == 0) jiqiren = (jiqiren + 1) % 4;
    				else {
    					jiqiren--;
    					if (jiqiren < 0)
    						jiqiren = (jiqiren + 4) % 4;
    				}
    			}
    			else if (stp == "WG") {
    				cin >> op;
    				if (op != (int)op) {
    					fEND = 1;
    					continue;
    				}
    				int opt = (int)op;
    				if (opt < 0 || opt >= (max(m, n)))  {
    					fEND = 1;
    					continue;
    				}
    				stepWG(opt);
    			}
    			else if (stp == "END") {
    				fEND = 1;
    				rio = 1;
    			}
    		}
    		if (rio) cout << "Complete" << "
    ";
    		else cout << "ERROR" << "
    ";
    		cout << x - 1 << " " << y - 1 << "
    ";
    		cout << bazix << "
    ";
    		cout << paotai << " " << jiqiren << " " << b << " " << c << "
    ";
    	}
    }
    
    inline void stepFE(int sjd) {
    	int xx = x, yy = y;
    	if (paotai == 0) {
    		while (math[xx][yy] != 1) {
    			if (math[xx][yy] == 2) {
    				bazi[xx][yy] -= sjd;
    				if (bazi[xx][yy] <= 0) {
    					math[xx][yy] = 0;
    					bazix++;
    				}
    				break;
    			}
    			xx--;
    		}
    	}
    	if (paotai == 1) {
    		while (math[xx][yy] != 1) {
    			if (math[xx][yy] == 2) {
    				bazi[xx][yy] -= sjd;
    				if (bazi[xx][yy] <= 0) {
    					math[xx][yy] = 0;
    					bazix++;
    				}
    				break;
    			}
    			yy--;
    		}
    	}
    	if (paotai == 2) {
    		while (math[xx][yy] != 1) {
    			if (math[xx][yy] == 2) {
    				bazi[xx][yy] -= sjd;
    				if (bazi[xx][yy] <= 0) {
    					math[xx][yy] = 0;
    					bazix++;
    				}
    				break;
    			}
    			xx++;
    		}
    	}
    	if (paotai == 3) {
    		while (math[xx][yy] != 1) {
    			if (math[xx][yy] == 2) {
    				bazi[xx][yy] -= sjd;
    				if (bazi[xx][yy] <= 0) {
    					math[xx][yy] = 0;
    					bazix++;
    				}
    				break;
    			}
    			yy++;
    		}
    	}
    }
    
    inline void stepWG(int step) {
    	int xx = x ,yy = y;
    	if (jiqiren == 0) {
    		while (step) {
    			x--;
    			step--;
    			if (math[x][y] != 0) {
    				fEND = 1;
    				break;
    			}
    		}
    	}
    	if (jiqiren == 1) {
    		while (step) {
    			y--;
    			step--;
    			if (math[x][y] != 0) {
    				fEND = 1;
    				break;
    			}
    		}
    	}
    	if (jiqiren == 2) {
    		while (step) {
    			x++;
    			step--;
    			if (math[x][y] != 0) {
    				fEND = 1;
    				break;
    			}
    		}
    	}
    	if (jiqiren == 3) {
    		while (step) {
    			y++;
    			step--;
    			if (math[x][y] != 0) {
    				fEND = 1;
    				break;
    			}
    		}
    	}
    	if (fEND) {
    		x = xx;
    		y = yy;
    	}
    }
    

    数据

    /*
    4
    5 5
    2 0 0 0 0
    0 0 0 0 0
    0 0 1 0 0
    0 0 0 0 0
    0 0 0 0 0
    4 4 3 1 1 6
    WG 4
    FT 0
    FF 1
    FE
    END
    FF
    5 5
    2 0 0 0 0
    0 0 0 0 0
    0 0 1 0 0
    0 0 0 0 0
    0 0 0 0 0
    4 4 3 1 1 6
    WG 4
    FT 0
    FE
    END
    FF
    FF
    5 5
    2 0 0 0 0
    0 0 0 0 0
    0 0 1 0 0
    0 0 0 0 0
    0 0 0 0 0
    4 4 3 1 1 6
    WG 4
    FT 0
    WG 1
    FE
    END
    FF
    5 5
    2 0 0 0 0
    0 0 0 0 0
    0 0 1 0 0
    0 0 0 0 0
    0 0 0 0 0
    4 4 3 1 1 6
    WG 4
    FT 0
    FF 1
    FT 0
    FT 0
    FT 0
    */
    /*
    5
    5 5
    2 0 0 0 0
    0 0 0 0 0
    0 0 1 0 0
    0 0 0 0 0
    0 0 0 0 0
    4 4 3 1 1 6
    WG 4
    FT 0
    WG 1
    FE
    END
    FF
    5 5
    2 0 0 0 0
    0 0 0 0 0
    0 0 1 0 0
    0 0 0 0 0
    0 0 0 0 0
    4 4 3 1 1 6
    WG 4
    FT 0
    WG 1
    FE
    END
    FF
    5 5
    2 0 0 0 0
    0 0 0 0 0
    0 0 1 0 0
    0 0 0 0 0
    0 0 0 0 0
    4 4 3 1 1 6
    WG 4
    FT 0
    WG 1
    FE
    END
    FF
    5 5
    2 0 0 0 0
    0 0 0 0 0
    0 0 1 0 0
    0 0 0 0 0
    0 0 0 0 0
    4 4 3 1 1 6
    WG 4
    FT 0
    WG 1
    FE
    END
    FF
    5 5
    2 0 0 0 0
    0 0 0 0 0
    0 0 1 0 0
    0 0 0 0 0
    0 0 0 0 0
    4 4 3 1 1 6
    WG 4
    FT 0
    WG 1
    FE
    END
    FF
    */
    
    
    
    /*
    2
    4 4
    2 0 0 0
    0 0 1 0
    0 0 0 0
    0 0 0 0
    3 0 1 2 2 3
    FF 1
    FF 1
    FE
    4 4
    2 0 0 0
    0 0 1 0
    0 0 0 0
    0 0 0 0
    3 2 2 1 1 3
    WG 2
    FT 0
    FT 0
    
    ERROR
    3 0
    0
    0 0 0 2
    ERROR
    2 2
    0
    0 0 1 1
    
    */
    
    /*
    1
    4 4
    2 2 2 2
    2 2 2 2
    2 2 2 2
    2 2 2 0
    3 3 1 1 1 7
    FT 0
    WT 0
    FF 1
    FE
    WG 1
    WG 1
    END
    */
    
    /*
    2
    4 4
    2 0 0 0
    3 0 1 0
    3 0 0 0
    0 0 0 0
    3 0 2 2 2 3
    FF 1
    FE
    END
    4 4
    2 0 0 0
    3 0 1 0
    3 0 0 0
    0 0 0 0
    3 0 2 2 2 4
    FF 0
    FF 0
    FE
    FE
    */
    
    /*
    1
    4 4
    0 0 1 0
    3 2 3 0
    3 2 2 2
    2 1 3 0
    3 3 2 2 2 11
    FF 1
    FE
    WG 2
    FT 0
    FF 0
    FF 0
    FE
    FE
    WT 0
    WG 2
    END
    */
    
    /*
    1
    4 4
    0 0 2 0
    3 2 3 0
    3 2 2 2
    2 1 3 0
    3 3 2 2 2 20
    FF 1
    FE
    WG 2
    FT 0
    FF 0
    FF 0
    FE
    FE
    WT 0
    WT 1
    WG 1
    FF 1
    FE
    WT 0
    WG 2
    WT 1
    WT 1
    WG 1
    WG 2
    END
    */
    
    /*
    1
    5 5
    2 2 2 2 2
    2 0 0 2 2
    2 0 0 2 2
    2 2 2 2 2
    0 0 0 0 0
    4 4 5 10 12 20
    WT 0
    WG 4
    FF 1
    FF 1
    FF 1
    FE
    FE
    FE
    WT 1
    WG 3
    FF 1
    FE
    WT 1
    FT 1
    FF 0
    FF 0
    FE
    FE
    WG 3
    END
    */
    
    /*
    
    1
    5 5
    2 2 2 2 2
    2 0 3 2 2
    2 0 0 2 2
    2 2 2 2 2
    0 0 0 0 0
    4 4 5 10 12 20
    WT 0
    WG 4
    FF 1
    FF 1
    FF 1
    FE
    FE
    FE
    WT 1
    WG 3
    FF 1
    FE
    WT 1
    FT 1
    FF 0
    FF 0
    FE
    FE
    WG 3
    END
    */
    
    /*
    1
    4 2
    0 0
    0 0
    0 0
    2 0
    0 0 5 5 5 12
    WT 0
    WT 0
    FT 0
    FT 0
    FE
    FF 1
    FF 0
    FF 1
    FF 0
    FE
    WG 2
    FE
    */
    
    
    /*
    1
    4 3
    0 0 0
    0 3 0
    3 0 0
    0 0 0
    3 0 1 1 1 7
    WT 1
    WG 2
    WT 0
    WG 1
    WG 1
    WT 0
    WG 1
    */
    
    /*
    1
    5 5
    2 2 2 2 2
    2 2 3 2 2
    1 2 3 2 2
    1 2 2 3 2
    1 1 1 1 0
    4 4 5 40 40 45
    FF 1
    FF 1
    FF 1
    FF 1
    FF 1
    FE
    FE
    FE
    FE
    WG 2
    FT 0
    FE
    WG 2
    FF 1
    FF 0
    FF 0
    FE
    FE
    FE
    WT 0
    WG 2
    FT 0
    FE
    FE
    FF 1
    FF 1
    FE
    FE
    FT 1
    FF 1
    FF 1
    FF 1
    FF 0
    FF 0
    FE
    FE
    WG 1
    FT 0
    FE
    FE
    FE
    WT 0
    WG 3
    WG 1
    END
    */
    
    /*
    2
    2 3
    2 0 0
    0 0 1
    1 0 2 1 1 8
    FF 1
    FE
    WG 1
    WT 1
    WG 2
    WT 1
    WG 1
    END
    2 3
    2 0 0
    0 0 1
    1 0 2 1 1 8
    FF 1
    FE
    WG 1
    WT 1
    WG 2
    WT 1
    END
    WG 1
    */
    
    /*
    2
    2 2
    0 0
    0 0
    0 0 1 1 1 2
    FF
    END
    */
    
  • 相关阅读:
    dapi 基于Django的轻量级测试平台七 怎样部署到生产环境
    dapi 基于Django的轻量级测试平台六 怎样使用压测功能
    dapi 基于Django的轻量级测试平台五 测试报告
    dapi 基于Django的轻量级测试平台四 任务设置
    【Spark 内核】 Spark 内核解析-上
    【数据结构与算法】—— 插入排序
    大数据框架开发基础之Sqoop(1) 入门
    【数据结构与算法】—— 二分查找
    【数据结构与算法】—— 插入排序
    【数据结构与算法】—— 选择排序
  • 原文地址:https://www.cnblogs.com/lieberdq/p/12791612.html
Copyright © 2011-2022 走看看