いろいろがんばりたいブログ

情報科学科の人がいろいろ書きます。

ICPC2013国内模擬予選

A 王様の視察

がんばればできます。回すのをどうやるかは割と好みです。

#include <iostream>
#include <vector>
#include <string>

using namespace std;

int onebefore(char c){
    if(c == 'a') return 'Z';
    if(c == 'A') return 'z';
    return c-1;
}

int before(char c,int n){
    for(int i=0;i<n;i++){
        c = onebefore(c);
    }
    return c;
}


int main(){
    while(true){
        int n;
        cin >> n;
        if(n == 0) break;
        vector<int> OK(n);
        for(int i=0;i<n;i++) cin >> OK[i];
        vector<int> K(100*n);

        for(int i=0;i<100;i++){
            for(int j=0;j<n;j++){
                K[n*i+j] = OK[j];
            }
        }

        string s;
        cin >> s;
        for(int i=0;i<s.length();i++){
            s[i] = before(s[i],K[i]);
        }
        cout << s << endl;
    }
    return 0;
}

B 動物の盛り

問題の読解が難しかったようです。個人的にはそうでもありませんでした。修正されたことに気づかないときびしかったかもしれません。 卵は突然変異を起こす条件は、卵が存在している間、条件を恒等的に満たしていることです。 すこしでも条件を満たさない瞬間があれば、卵は突然変異を起こしません。 解法は、全探索です。すべての場合を試して、突然変異を起こす可能性のある卵の数を数えます。 その判定は、s<= 500であることを利用すると楽にできます。なぜなら、朝も夜も、6時間=720であり、朝,夜の期間すべてを跨ぐ、ということはありえないからです。 (朝ステージがはじまり、夜を挟んで、朝孵化することはありえない。) 同様に、曜日を1つ挟むということもありません。 よって、最初と最後のみを確かめればよいことになります。

#include <iostream>
#include <cassert>
#include <vector>
#include <cmath>
#include <iomanip>

using namespace std;

typedef long double ldouble;

ldouble calc(int n,int p){
    ldouble p1 = ((ldouble)1)/p;
    return 1 - pow(1-p1,n);
}

//{All, Sun, Mon, Tue, Wed, Thu, Fri, Sat}
int str_to_week(string weekday){
    if(weekday == "All") return 7;
    if(weekday == "Sun") return 0;
    if(weekday == "Mon") return 1;
    if(weekday == "Tue") return 2;
    if(weekday == "Wed") return 3;
    if(weekday == "Thu") return 4;
    if(weekday == "Fri") return 5;
    if(weekday == "Sat") return 6;

    assert(false);
}

string int_to_time(int x){
    if(60*6 <= x and x < 60 * 18) return "Day";
    else return "Night";
}

const int oneday = 60*24;

int main(){
    while(true){
        int s,n,t,p,m;
        string weekday,time;
        cin >> s >> n >> t >> weekday >> time >> p >> m;
        if(s == 0) break;
        int myweek = str_to_week(weekday);

        int maxcnt = 0;
        for(int start_time = 0;start_time<oneday;start_time++){
            for(int week = 0;week<7;week++){
                int cnt = 0;
                int nowtime = start_time;
                int nowweek = week;
                for(int stage=0;stage<m;stage++){
                    bool ok = true;
                    if(!(time == "All" or int_to_time(nowtime) == time)) ok = false;
                    if(!(myweek == 7 or nowweek == myweek)) ok = false;
                    int hukatime = nowtime + s;
                    int hukaweek = nowweek;
                    if(hukatime >= 60*24){
                        hukatime %= 60*24;
                        hukaweek = (hukaweek + 1) % 7;
                    }
                    if(!(time == "All" or int_to_time(hukatime) == time)) ok = false;
                    if(!(myweek == 7 or hukaweek == myweek)) ok = false;
                    if(ok) cnt += n;
                    nowtime += t;
                    if(nowtime >= 60*24){
                        nowtime %= 60*24;
                        nowweek = (nowweek+1) % 7;
                    }
                }
                maxcnt = max(cnt,maxcnt);
            }
        }
        cout << fixed << setprecision(10);
        cout << calc(maxcnt,p) << endl;
    }
    return 0;
}