倍数 :用户登录
https://www.lanqiao.cn/problems/583/learning/?page=5&first_category_id=1&sort=students_count
 
题目描述
本题为填空题,只需要算出结果后,在代码中使用输出语句将所填结果输出即可。
请问在 1 到 2020 中,有多少个数既是 4 的整数倍,又是 6 的整数倍。
import java.util.Scanner;
// 1:无需package
// 2: 类名必须Main, 不可修改
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int n=0;
        for(int i=1;i<=2020;i++){
          if(i%4==0&&i%6==0)
          n++;
        }
        System.out.println(n);
        scan.close();
    }
} 
路径之谜:用户登录
https://www.lanqiao.cn/problems/89/learning/?page=5&first_category_id=1&sort=students_count
 
题目描述
小明冒充 X 星球的骑士,进入了一个奇怪的城堡。
城堡里边什么都没有,只有方形石头铺成的地面。
假设城堡地面是 n×n 个方格。如下图所示。

按习俗,骑士要从西北角走到东南角。可以横向或纵向移动,但不能斜着走,也不能跳跃。每走到一个新方格,就要向正北方和正西方各射一箭。(城堡的西墙和北墙内各有 nn 个靶子)同一个方格只允许经过一次。但不必走完所有的方格。如果只给出靶子上箭的数目,你能推断出骑士的行走路线吗?有时是可以的,比如上图中的例子。
本题的要求就是已知箭靶数字,求骑士的行走路径(测试数据保证路径唯一)
输入描述
第一行一个整数 N (0≤N≤20),表示地面有 N×N 个方格。
第二行 N 个整数,空格分开,表示北边的箭靶上的数字(自西向东)
第三行 N 个整数,空格分开,表示西边的箭靶上的数字(自北向南)
输出描述
输出一行若干个整数,表示骑士路径。
为了方便表示,我们约定每个小格子用一个数字代表,从西北角开始编号: 0,1,2,3⋯
比如,上图中的方块编号为:
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
输入输出样例
示例
输入
4
2 4 3 4
4 3 3 3
 
 
输出
0 4 5 1 2 3 7 11 10 9 13 14 15 
代码:
import java.util.Scanner;
public class 路径之谜 {
    static int a[],b[], n;
    static int path[];
    static boolean vis[][],sca;
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        path = new int[n*n];
        vis = new boolean[n][n];
        a = new int [n];
        for (int i = 0; i < a.length; i++) {
            a[i] = sc.nextInt();
        }
        b = new int[n];
        for (int i = 0; i < b.length; i++) {
            b[i] = sc.nextInt();
        }
        dfs(0,0,0);
    }
    static int dx[] = {1,0,-1,0};
    static int dy[] = {0,1,0,-1};
    private static void dfs(int x, int y, int step) {
        path[step] = y*n+x;
        vis[x][y] = true;
        a[x]--;
        b[y]--;
        
        if(x==n-1&&y==n-1&&cheak()) {
            sca=true;
            for (int i = 0; i <= step; i++) {
                System.out.print(path[i]+" ");
            }
        }
        
        for (int i = 0; i < 4; i++) {
            int xx = x+dx[i];
            int yy = y+dy[i];
            if(!sca&&xx>=0&&xx<=n-1&&yy>=0&&yy<=n-1&&!vis[xx][yy]) {
                if(a[xx]>0&&b[yy]>0) {
                    dfs(xx,yy,step+1);
                    vis[xx][yy] = false;
                    a[xx]++;
                    b[yy]++;
                }
            }
        }
    }
    private static boolean cheak() {
        for (int i = 0; i < n; i++) {
            if(a[i]!=0||b[i]!=0)
                return false;
        }
        return true;
    }
} 
林深时见鹿,海蓝时见鲸,梦醒时见你



















