【贪心】Gym - 100507H - Pair: normal and paranormal
2017-01-31 21:02
513 查看
每次取相邻的两个可以射击的从序列中删除,重复n次。
可以看作括号序列的匹配。
可以看作括号序列的匹配。
#include<cstdio> #include<vector> using namespace std; struct data { char c; int p; data(){} data(const char &cc,const int &pp) { c=cc; p=pp; } }; vector<data>a; typedef vector<data>::iterator ITER; int n,shoot[5010]; char s[10010]; int main() { //freopen("h.in","r",stdin); int p1=0,p2=0; scanf("%d%s",&n,s); for(int i=0;i<n*2;++i) { if(s[i]>='A' && s[i]<='Z') { ++p1; a.push_back(data(s[i],p1)); } else { ++p2; a.push_back(data(s[i],p2)); } } for(int i=0;i<n;++i) { bool flag=0; ITER k=a.begin(); ++k; for(ITER j=a.begin();k!=a.end();++j,++k) if((*j).c==(*k).c-32) { shoot[(*j).p]=(*k).p; ++k; a.erase(j,k); flag=1; break; } else if((*j).c-32==(*k).c) { shoot[(*k).p]=(*j).p; ++k; a.erase(j,k); flag=1; break; } if(!flag) { puts("Impossible"); return 0; } } for(int i=1;i<n;++i) printf("%d ",shoot[i]); printf("%d\n",shoot ); return 0; }
相关文章推荐
- Gym - 100507H H. Pair: normal and paranormal 栈
- Gym 100507H - Pair: normal and paranormal
- Gym 100507H Pair: normal and paranormal (贪心)
- URAL 2019 Pair: normal and paranormal (贪心) -GDUT联合第七场
- URAL 2019 Pair: normal and paranormal (STL栈)
- ural 2019 Pair: normal and paranormal
- Pair: normal and paranormal 栈的应用
- H - Pair: normal and paranormal URAL - 2019
- URAL 2019 Pair: normal and paranormal 暴力?
- URAL 2019 Pair: normal and paranormal
- URAL 2019. Pair: normal and paranormal(***栈模拟)
- 【贪心】【字典树】Gym - 101466A - Gaby And Addition
- 巧妙地利用STL map set pair 贪心+排序 Codeforces Round #331 (Div. 2)C. Wilbur and Points
- The difference between PASV FTP and Normal FTP
- hdoj 4268 Alice and Bob 【贪心 + set】
- GYM 101142 B.Boys and Girls(构造)
- C - Dean and Schedule --贪心
- Codeforces Round #393 (Div. 2) -B. Frodo and pillows(贪心)
- Gym - 100623K-贪心&进制
- 贪心 Gym 100502E Opening Ceremony