Day2-T1
原題目
Describe:貪心,左邊和右邊中選字典序小的
code:
#include<bits/stdc++.h> using namespace std; int n,step,head,tail; char p[50005]; int main() {freopen("bcl.in","r",stdin);freopen("bcl.out","w",stdout);cin>>n;head=1,tail=n;for(int i=1;i<=n;i++)cin>>p[i];while(head<tail){if(p[head]<p[tail])putchar(p[head]),head++;else if(p[head]>p[tail])putchar(p[tail]),tail--;else{int i=head,j=tail;while(i<j&&p[i]==p[j])i++,j--;if(p[i]<p[j])putchar(p[head]),head++;else putchar(p[tail]),tail--;}step++,step%=80;if(!step)puts("");}putchar(p[head]);return 0; }?
轉(zhuǎn)載于:https://www.cnblogs.com/sroht/p/9884987.html
總結(jié)
- 上一篇: 自动驾驶毫米波雷达物体检测技术-算法
- 下一篇: 串行线路上传输数据报的非标准协议:SLI