洛谷题目:P1518 [USACO2.4]两只塔姆沃斯牛 The Tamworth Two
题目如下:
思路:
简单的模拟,不过像这种上下左右的移动方式倒是可以留意下,我是用%的方式来改变的。
我的代码
import java.io.*;
public class Main {
static char[][] chars = new char[10][10];
static int rx = 0,ry = 0; // 记录人的位置
static int nx = 0,ny = 0; // 记录牛的位置
static int lt = 0; // 转向时牛的朝向记录
static int rlt = 0; // 转向时人的朝向记录
static int[] ints = {
-1,0,0,1,1,0,0,-1}; // 依次为向北、东、南、西走一步
static BufferedReader ins = new BufferedReader(new InputStreamReader(System.in));
static StreamTokenizer in = new StreamTokenizer(ins);
static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
public static void main(String[] args) throws IOException{
char ct; // 在循环中定义变量好像会拖慢些速度,所以我尽量养成不在循环中定义变量
for(int i = 0;i<10;i++)
{
String strl = ins.readLine(); // 读取一行
for(int i1 = 0;i1<10;i1++)
{
ct