编程语言
首页 > 编程语言> > Java-POJ1006-Biorhythms(中国剩余定理)

Java-POJ1006-Biorhythms(中国剩余定理)

作者:互联网

https://blog.csdn.net/shanshanpt/article/details/8724769

有中文题面,就不解释了。

妥妥的中国剩余定理没跑了。

Java跑得慢,一点办法也没有,必须写正解,暴力居然TLE

 1 package poj.ProblemSet;
 2 
 3 import java.util.Scanner;
 4 
 5 public class poj1006 {
 6     public static final int MOD = 23 * 28 * 33;
 7     public static final int X1 = 28 * 33 * 6;
 8     public static final int X2 = 23 * 33 * 19;
 9     public static final int X3 = 23 * 28 * 2;
10 
11     public static void main(String[] args) {
12         Scanner cin = new Scanner(System.in);
13         for (int p = cin.nextInt(), e = cin.nextInt(), i = cin.nextInt(), d = cin.nextInt(), n = 1; p != -1 && e != -1 && i != -1 && d != -1; p = cin.nextInt(), e = cin.nextInt(), i = cin.nextInt(), d = cin.nextInt()) {
14             int ans = (X1 * p + X2 * e + X3 * i - d + MOD) % MOD;
15             System.out.println("Case " + (n++) + ": the next triple peak occurs in " + (ans == 0 ? MOD : ans) + " days.");
16         }
17     }
18 }
poj1006

 

标签:Java,final,int,Biorhythms,POJ1006,cin,nextInt,static,public
来源: https://www.cnblogs.com/JasonCow/p/12236158.html