经典屏保
标题:经典屏保 | 时间限制:1秒 | 内存限制:262144K | 语言限制:不限
DVD机在视频输出时,为了保护电视显像管,在待机状态会显示“屏保动画”,如下图所示,DVD Logo在屏幕内来回运动,碰到边缘会反弹:
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String[] s = scan.nextLine().split(" "); scan.close(); int width = 800, height = 600, w = 50, h = 25, _x = 1, _y = 1, x = Integer.parseInt(s[0]), y = Integer.parseInt(s[1]), t = Integer.parseInt(s[2]); for (int i = 0; i < t; i++) { if (x == 0) { _x = 1; } if (x + w == width) { _x = -1; } if (y == 0) { _y = 1; } if (y + h == height) { _y = -1; } x += _x; y += _y; } System.out.println(x + " " + y); } }