HDU 3328 Flipper
5689 ワード
Description
N枚の札、正面のUあるいは反対側のDは上に並んで2種類の操作Lを並べて最も左の1山を反転してそれの右側のあの山のRを最も右の1山を反転してそれの左のあの山の例に置きます:A B C D E FはL操作を実行した後にC B A D E Fになります
Algorithm
表を正数、裏を負数と表記してシミュレーションすれば良い
コードの書くのはきわめて詰めて(2016年3月19日の私にとって)初めてSTL listを使って、しかもlistセットlistを使ってそれから私はAを書き終わって実はこのようにする必要がないことを発見して、配列は処理することができてとても良くて、私が思った奇抜な問題はありません.naïve; しかしlistの反復器は基本的に把握しています.少し収穫があった
Code
N枚の札、正面のUあるいは反対側のDは上に並んで2種類の操作Lを並べて最も左の1山を反転してそれの右側のあの山のRを最も右の1山を反転してそれの左のあの山の例に置きます:A B C D E FはL操作を実行した後にC B A D E Fになります
Algorithm
表を正数、裏を負数と表記してシミュレーションすれば良い
コードの書くのはきわめて詰めて(2016年3月19日の私にとって)初めてSTL listを使って、しかもlistセットlistを使ってそれから私はAを書き終わって実はこのようにする必要がないことを発見して、配列は処理することができてとても良くて、私が思った奇抜な問題はありません.naïve; しかしlistの反復器は基本的に把握しています.少し収穫があった
Code
#include <cstdio>
#include <iostream>
#include <list>
using namespace std;
const int maxn = 100 + 9;
void solve()
{
string s;
cin >> s;
list< list<int> > l;
for (int i = 0; i < s.size(); i++)
{
list<int> t;
if (s[i] == 'U') t.push_back(i + 1); else
t.push_back(- (i + 1));
l.push_back(t);
}
cin >> s;
for (int i = 0; i < s.size(); i++)
if (s[i] == 'R')
{
list<int> t = l.back();
l.pop_back();
for (list<int>::reverse_iterator tit = t.rbegin(); tit != t.rend(); tit++)
{
int x = - *tit;
list<int> tt = *l.rbegin();
tt.push_back(x);
*l.rbegin() = tt;
}
}else
{
list<int> t = l.front();
l.pop_front();
for (list<int>::reverse_iterator tit = t.rbegin(); tit != t.rend(); tit++)
{
int x = - *tit;
list<int> tt = *l.begin();
tt.push_back(x);
*l.begin() = tt;
}
}
list<int> t = l.front();
int ans[maxn] = {0};
for (list<int>::reverse_iterator tit = t.rbegin(); tit != t.rend(); tit++)
{
ans[0]++;
ans[ans[0]] = *tit;
}
int m;
cin >> m;
for (int i = 0; i < m; i++)
{
int q;
cin >> q;
cout << "Card " << q << " is a face ";
if (ans[q] > 0) cout << "up " << ans[q] << ".
"; else cout << "down " << -ans[q] << ".
";
}
}
int n;
int main()
{
//freopen("input.txt", "r", stdin);
for (int i = 1; ; i++)
{
cin >> n;
if (n == 0) break;
cout << "Pile " << i << endl;
solve();
}
}