A - 君が望むなら世界中全てのたこ焼きを赤と青に染め上げよう
偶数ならBlue、奇数ならRedを出力するだけ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
using namespace std; | |
int main(void){ | |
int n; | |
cin >> n; | |
if(n&1) cout << "Red" << endl; | |
else cout << "Blue" << endl; | |
return 0; | |
} |
瞬殺。
B - あの日したしりとりの結果を僕達はまだ知らない。
しりとり。先手の勝敗を出力する。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<string> | |
#include<vector> | |
using namespace std; | |
vector<string> arr; | |
bool search(string); | |
int main(void){ | |
int n; | |
string str1, str2; | |
cin >> n; | |
cin >> str1; | |
arr.push_back(str1); | |
n--; | |
for(int i = 0; i < n; i++){ | |
cin >> str2; | |
if(str1[str1.length() - 1] != str2[0] || search(str2)){ | |
if(i&1) cout << "LOSE" << endl; | |
else cout << "WIN" << endl; | |
return 0; | |
} | |
arr.push_back(str2); | |
str1 = str2; | |
} | |
cout << "DRAW" << endl; | |
return 0; | |
} | |
bool search(string str){ | |
for(int i = 0; i < arr.size(); i++){ | |
if(arr[i] == str) return true; | |
} | |
return false; | |
} |
Stringの比較とかで詰まったりした挙句、色々とよく分からない手直ししてスパゲティ状態。
一行ずつ入力とって行頭と行末を比較したり、既出の文字列を探したりするだけ。
C - 魂の還る場所
提出できなかったけどね。
両端キューに3色のボールを入れていって、同じ色が2個隣り合ったところが消えるので、残るボールの最小個数を求める。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<deque> | |
#include<queue> | |
using namespace std; | |
deque<char> deq; | |
void check(){ | |
//cout << "check" << endl; | |
deque<char> que; | |
int j = deq.size(); | |
for(int i = 0; i < j; i++){ | |
//cout << deq.front() << ' ' << que.back() << endl; | |
if(que.size() == 0 || deq.front() != que.back()){ | |
que.push_back(deq.front()); | |
deq.pop_front(); | |
} | |
else{ | |
deq.pop_front(); | |
que.pop_back(); | |
} | |
} | |
j = que.size(); | |
for(int i = 0; i < j; i++){ | |
deq.push_back(que.front()); | |
que.pop_front(); | |
} | |
} | |
int main(void){ | |
int n; | |
cin >> n; | |
char str[55]; | |
cin >> str; | |
for(int i = 0; i < n; i++){ | |
if(deq.size() < 2){ | |
deq.push_back(str[i]); | |
}else{ | |
bool b = false; | |
if(str[i] == deq.front()) b = true; | |
else if(str[i] == deq.back()) b = false; | |
else { | |
for(int j = 0; j < deq.size() / 2; j++){ | |
if(deq.at(j) == deq.at(deq.size()-1 - j)) continue; | |
for(int k = i; k < n; k++){ | |
if(str[k] == deq.at(j)){ | |
break; | |
} | |
if(str[k] == deq.at(deq.size()-1 - j)){ | |
b = true; | |
break; | |
} | |
} | |
} | |
} | |
if(b){ | |
deq.push_front(str[i]); | |
}else{ | |
deq.push_back(str[i]); | |
} | |
} | |
//for(int j = 0; j < deq.size(); j++){ | |
// cout << deq.at(j); | |
//} | |
//cout << endl; | |
check(); | |
} | |
cout << deq.size() << endl; | |
return 0; | |
} |
とりあえず貪欲思いついたので書いてみたら、慣れないdequeで詰まるわバグるわ、結局書き終わったのがコンテスト終了の30分後だった。
実際にはどのボールも何らかの方法で消せるので、単純に偶奇取れば良かったらしい。
一応全問一発で通った
0 件のコメント:
コメントを投稿