JAG 2013模擬国内予選

http://acm-icpc.aitea.net/index.php?2013%2FPractice%2F%CC%CF%B5%BC%B9%F1%C6%E2%CD%BD%C1%AA
模擬国内予選

A:王様の視察

アルファベットを円環型にする。
すごく効率の悪いゴリ押しな実装。

import java.util.Scanner;
public class ImitationDomestic2013_A{
	static Scanner sc=new Scanner(System.in);

	static char alpa(int a){
		return (char)(a+96);
	}
	static char alpA(int a){
		return (char)(a+64);
	}

	static int num(char a){
		if('a' <= a && 'z' >= a){
			return a-'a'+1;
		}else{
			return a-'A'+1;
		}
	}

	public static void main(String[] args){
		char[] alp=new char[52];
		for(int i2=0;i2<26;i2++){
			alp[i2]=alpa(i2+1);
		}
		for(int i=26;i<52;i++){
			alp[i]=alpA(i-25);
		}
		while(true){
			int n=sc.nextInt();
			if(n==0)break;
			int[] k=new int[n];
			for(int i=0;i<n;i++){
				int a=sc.nextInt();
				if(a > 52)a=a%52;
				k[i]=a;
			}
			String s=sc.next();
			int i2=0;
			for(int i=0;i<s.length();i++){
				int a=num(s.charAt(i)); //アルファベットを番号へ
				if('a' <= s.charAt(i) && 'z' >= s.charAt(i)){
					int t=a-k[i2]-1;
					if(t < 0)t=52+t;
					System.out.print(alp[t]);
					//System.out.println(a);
				}else{
					int t=a+26-k[i2]-1;
					if(t < 0)t=52+t;
					System.out.print(alp[t]);
				}
				i2++;
				if(i2==n)i2=0;
			}
			System.out.println();
		}
	}
}
B:どうぶつの盛り2013

卵が孵化する最高の確率を出す。
06:00~17:59がDay, 18:00|05:59がNight
1.0-(p-1.0)/p^mが孵化する確率。
一週間を分になおして10080とする。現在が何曜日であるかは time/1440 で算出。
if(360<=c1 && c1<1080 && 360<=c2 && c2<1080)で、昼であるか、
if((c1>=1080 || c1<360) && (c2>=1080 || c2<360)で、夜であるかを判定。
スタート位置を0から始め、終わったらスタート位置を1から始める、を繰り返してシミュレーションを行い確率の最高値をansに入れる。

/*
現在の時間/1440が0ならば日曜,1ならば月曜
360<=現在の時間%1440<=1080ならばDay
0<=現在の時間%1440<=360 または 1080<=現在の時間%1440ならばnight
 */

import java.util.Scanner;
import java.math.BigDecimal;

public class ImitationDomestic2013_B{
	static double EPS=1e-8;

	static final Scanner sc=new Scanner(System.in);
	final static String[] WEEK={"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
	static double n;
	static double p;
	static double m;
	static String week;
	static String time;

	public static void main(String[] args){

		while(true){
			int s=sc.nextInt();//s分後にn個の卵が孵化
			n=sc.nextDouble();//n個の卵
			int t=sc.nextInt();//t分後にステージ終了
			week=sc.next();//突然変異可能な曜日
			time=sc.next();//Dayは6:00~18:00, Nightは18:00~6:00
			p=sc.nextDouble();//
			m=sc.nextDouble();//フェイズ数
			if("None".equals(week))break;
			double ans=0.0;

			for(int i=0;i<10080;i++){
				int start=i;
				int c=0;

				for(int i2=0;i2<m;i2++){
					if(start > 10080)start-=10080;
					if(Wcheck(start) && Wcheck(start+s)){
						int c1=start%1440;
						int c2=(start+s)%1440;
						if("All".equals(time)){
							c++;
						}else if("Day".equals(time)){
							if(360<=c1 && c1<1080 && 360<=c2 && c2<1080){
								c++;
							}
						}else{
							if((c1>=1080 || c1<360) && (c2>=1080 || c2<360)){
								c++;
							}
						}
					}
					start+=t;
				}
				ans=Math.max(ans, probab(c));
			}
			//BigDecimal a=new BigDecimal(ans);
			System.out.printf("%.10f\n",ans);
			
		}
	}


	static boolean Wcheck(int ctime){  //曜日チェック
		//System.out.println(ctime);
		int ch=ctime/1440;
		if(ch >= 7)ch-=7;
		if("All".equals(week))return true;
		if(ctime > 10080)return false;
		if(week.equals(WEEK[ch])){
			return true;
		}else{
			return false;
		}
	}
	
	static double probab(int c){
		if(c==0)return 0;
		double sum=(p-1.0)/p;
		for(int i=0;i<(int)n*c-1.0;i++){
			sum*=(p-1.0)/p;
		}
		return 1.0-sum;
	}
}