java:P1518 [USACO2.4]两只塔姆沃斯牛 The Tamworth Two

洛谷题目: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 =
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值