AOJ 0513
単なるシミュレーション。去年はこれ出来なかった記憶がある。
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<queue> | |
using namespace std; | |
int main(void){ | |
queue<int> a,b,d; | |
int n, m, k; | |
cin >> n; | |
for(int i = 0; i < 2 * n; i++){ | |
d.push(i + 1); | |
} | |
cin >> m; | |
for(int x = 0; x < m; x++){ | |
cin >> k; | |
if(k == 0){ | |
for(int i = 0; i < n; i++){ | |
a.push(d.front()); | |
d.pop(); | |
} | |
for(int i = 0; i < n; i++){ | |
b.push(d.front()); | |
d.pop(); | |
} | |
for(int i = 0; i < n; i++){ | |
d.push(a.front()); | |
a.pop(); | |
d.push(b.front()); | |
b.pop(); | |
} | |
} | |
else{ | |
for(int i = 0; i < k; i++){ | |
a.push(d.front()); | |
d.pop(); | |
} | |
while(!a.empty()){ | |
d.push(a.front()); | |
a.pop(); | |
} | |
} | |
} | |
while(!d.empty()){ | |
cout << d.front() << endl; | |
d.pop(); | |
} | |
return 0; | |
} |
普通に配列使ってもいいけど、キュー使うとpopとかあって書きやすいんじゃないだろうか。
char形の配列使ってもいいかもしれない。
AOJ 0514
貪欲法というか、テストに成功しているところを先に処理して、その後に確定できるところを確定していく。
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<vector> | |
#include<queue> | |
using namespace std; | |
int main(void){ | |
int a,b,c, t, n; | |
while(cin >> a >> b >> c, a + b + c !=0){ | |
vector<int> h; | |
vector<int> p; | |
queue< vector<int> > que; | |
p.push_back(-1); | |
for(int i = 0; i < a + b + c; i++) | |
p.push_back(2); | |
cin >> n; | |
for(int i = 0; i < n; i++){ | |
h.clear(); | |
cin >> a >> b >> c >> t; | |
if(t == 1){ | |
p[a] = p[b] = p[c] = 1; | |
} | |
else{ | |
h.push_back(a); | |
h.push_back(b); | |
h.push_back(c); | |
h.push_back(t); | |
que.push(h); | |
} | |
} | |
while(!que.empty()){ | |
a = que.front()[0]; | |
b = que.front()[1]; | |
c = que.front()[2]; | |
if(p[a] == 2 && p[b] == 1 && p[c] == 1) | |
p[a] = 0; | |
if(p[a] == 1 && p[b] == 2 && p[c] == 1) | |
p[b] = 0; | |
if(p[a] == 1 && p[b] == 1 && p[c] == 2) | |
p[c] = 0; | |
que.pop(); | |
} | |
for(int i = 1; i < p.size(); i++) | |
cout << p[i] << endl; | |
} | |
return 0; | |
} |
queue< vector<int> > なんていうものをはじめて使った。
0 件のコメント:
コメントを投稿