【递推】C003_LQ_行动(找规律 / 枚举)

一、Problem

在这里插入图片描述

-1010 1010

二、Solution

方法一:规律

每 4*i 轮,纵坐标增量为 2 × i,横坐标增量为 -2 × i (i > 0)

...

方法二:枚举

import java.util.*;
import java.math.*;
import java.io.*;
public class Main{
	static class Solution {
		void init() {
			Scanner sc = new Scanner(new BufferedInputStream(System.in));
			int ex = 0, ey = 0;
			for (int i = 1; i <= 2020; i++) {
				if (i % 4 == 1)	ex+=i;
				if (i % 4 == 2)	ey-=i;
				if (i % 4 == 3)	ex-=i;
				if (i % 4 == 0)	ey+=i;
			}
			System.out.println(ex + " " + ey);
		}
	}
    public static void main(String[] args) throws IOException {  
        Solution s = new Solution();
		s.init();
    }
}
原创文章 787 获赞 314 访问量 5万+

猜你喜欢

转载自blog.csdn.net/qq_43539599/article/details/105825796
今日推荐