AOJ1179 Millennium

問題リンク Millennium

  • 解法

1000年1月1日になるまで1日ずつ動かすことで解けます。
サンプルの1番目が最悪のケースでその答えは約20万です。テストケースは100個までしかないので最悪計算回数は2*10^5 * 10^2 = 2*10^7となります。計算時間の心配は要りません。

  • ソース
import java.util.Scanner;

//Millennium
public class AOJ1179 {

	void run(){
		Scanner sc = new Scanner(System.in);
		int[] d = {0, 20, 19, 20, 19, 20, 19, 20, 19, 20, 19};
		int T = sc.nextInt();
		while(T--!=0){
			int Y = sc.nextInt(), M = sc.nextInt(), D = sc.nextInt();
			int res = 0;
			while(!(Y==1000&&M==1&&D==1)){
				if(Y%3==0&&D==20 || Y%3!=0&&D==d[M]){
					M++; D=1;
				}
				else D++;
				if(M==11){
					Y++; M=1;
				}
				res++;
			}
			System.out.println(res);
		}
	}
	
	public static void main(String[] args) {
		new AOJ1179().run();
	}
}