読者です 読者をやめる 読者になる 読者になる

夢追い人

"It takes a dreamer to make a dream come true."―Vincent Willem van Gogh

Div.1Easy修行

FoxMakingDice

NとKの大小関係で場合分けする。
その上で、3つ以上N以下の数字二つでその数を作れる場合の数を計算していく。

class FoxMakingDice {
public:
   long long theCount( int N, int K ) {
       ll res = 0;
       if (N < 6) return res;
       if (N >= K) {
           for (int i=K; i<=N; i++) {
               int tmp;
               if (i%2 == 0) tmp = i/2-1;
               else tmp = i/2;
               if (tmp > 2) {
                   res += tmp*(tmp-1)*(tmp-2)/6*2;
               }
           }
           for (int i=1; i<N; i++) {
               int tmp;
               if ((N-i)%2 == 0) tmp = (N-i)/2;
               else tmp = (N-i)/2+1;
               if (tmp > 2) {
                   res += tmp*(tmp-1)*(tmp-2)/6*2;
               }
           }
       }
       else {
           int dist = K - N;
           for (int i=dist; i<N; i++) {
               int tmp;
               if ((N-i)%2 == 0) tmp = (N-i)/2;
               else tmp = (N-i)/2+1;
               // cout << i << " " << tmp << endl;
               if (tmp > 2) {
                   res += tmp*(tmp-1)*(tmp-2)/6*2;
               }
           }
       }
       return res;
   }
};

PrintScheduler

やるだけ

class PrintScheduler {
public:
   string getOutput( vector <string> threads, vector <string> slices ) {
       string res = "";
       vector<int> npos(threads.size(), 0);
       for (int i=0; i<slices.size(); i++) {
           int nth, time;
           stringstream ss;
           ss.str(slices[i]);
           ss >> nth >> time;
           for (int j=0; j<time; j++) {
               int ad = npos[nth]+j;
               res += threads[nth][ad%threads[nth].length()];
           }
           npos[nth] += time;
       }
       return res;       
   }
};

BusinessTasks

やっぱりやるだけ

class BusinessTasks {
public:
   string getTask( vector <string> list, int n ) {
       int npos = 0;
       for (;;) {
           npos += n-1;
           npos %= list.size();
           vector<string>::iterator it = list.begin();
           for (int i=0; i<npos; i++) it++;
           list.erase(it);
           if (list.size() == 1) break;
       }
       return list[0];
   }
};

PalindromeDecoding

STLゲー

class PalindromeDecoding {
public:
   string decode( string code, vector <int> position, vector <int> length ) {
       for (int i=0; i<position.size(); i++) {
           string str = code.substr(position[i], length[i]);
           reverse(str.begin(), str.end());
           code.insert(position[i]+length[i], str);
       }
       return code;
   }
};

grafixCorrupt

やるだけ

class grafixCorrupt {
public:
   int selectWord( vector <string> dictionary, string candidate ) {
       int m = 0;
       string rstr;
       int rpos = -1;
       for (int i=0; i<dictionary.size(); i++) {
           int same = 0;
           for (int j=0; j<candidate.length(); j++) {
               if (dictionary[i][j] == candidate[j]) same++;
           }
           if (same > m) {
               m = same;
               rstr = dictionary[i];
               rpos = i;
           }
       }
       return rpos;
       
   }
};

RabbitNumbering

やるだけ

class RabbitNumbering {
public:
   int theCount( vector <int> maxNumber ) {
       ll res = 1;
       sort(maxNumber.begin(), maxNumber.end());
       for (int i=0; i<maxNumber.size(); i++) {
           res = res * (maxNumber[i] - i) % MOD;
           cout << res << endl;
       }
       return (int)res;
   }
};

Rochambo

めんどくさい、書くだけ

class Rochambo {
public:
   int wins( string opponent ) {
       int res = 0;
       string me = "RR";
       char one = opponent[0], two = opponent[1];
       for (int i=2; i<opponent.length(); i++) {
           if (one == two) {
               if (one == 'R') me += 'P';
               else if (one == 'P') me += 'S';
               else if (one == 'S') me += 'R';
           }
           else {
               if (one!='R'&&two!='R') me += 'P';
               else if (one!='P'&&two!='P') me += 'S';
               else if (one!='S'&&two!='S') me += 'R';
           }
           one = two;
           two = opponent[i];
       }
       for (int i=0; i<me.length(); i++) {
           if (me[i]=='R'&&opponent[i]=='S') res++;
           else if (me[i]=='P'&&opponent[i]=='R') res++;
           else if (me[i]=='S'&&opponent[i]=='P') res++;
       }
       return res;
   }
};
広告を非表示にする