poj 3623 Best Cow Line, Gold 暴力枚举
2014-02-24 16:58
369 查看
题目地址:poj 3623
题目大意:可以从串的两端选取,求尽可能字典序小的串
直接暴力 ,关键是两端的字符相同的情形,这个时候要用快排那样的扫描方法。
一旦扫到了head 和tail 相遇甚至是穿过了还是没有找到不同的,这说明是对称的,随便先移除前面 后面 都行。
再就是注意一下输出 每80个换行 而且最后一行如果不是刚换过行了还是要换行
代码:
题目大意:可以从串的两端选取,求尽可能字典序小的串
直接暴力 ,关键是两端的字符相同的情形,这个时候要用快排那样的扫描方法。
一旦扫到了head 和tail 相遇甚至是穿过了还是没有找到不同的,这说明是对称的,随便先移除前面 后面 都行。
再就是注意一下输出 每80个换行 而且最后一行如果不是刚换过行了还是要换行
代码:
#include<iostream> #include<string> #include<algorithm> using namespace std; char s[30005]; int main() { int n; cin>>n; char ch; for(int i=0;i<n;i++) cin>>s[i]; int count=0; int ii=0,jj=n-1; while(ii<=jj) { int flag=0; for(int l=0;l+ii<=jj-l;l++) { if(s[ii+l]<s[jj-l]) { flag=0; break; } else if(s[ii+l]>s[jj-l]) { flag=1; break; } } if(flag==0) { cout<<s[ii]; ii++; } else { cout<<s[jj]; jj--; } count++; if(count%80==0) cout<<endl; } if(count%80!=0) cout<<endl; }
相关文章推荐
- poj 3623 Best Cow Line, Gold 暴力枚举
- poj 3623 Best Cow Line, Gold
- POJ 题目3623 Best Cow Line, Gold(后缀数组rank简单应用)
- POJ 3623 Best Cow Line, Gold(贪心)
- poj 3623 Best Cow Line, Gold (题意和3617一样只要代码中的范围改一下)
- poj 3623 Best Cow Line, Gold
- poj 3623 Best Cow Line, Gold(贪心)
- POJ 3623 Best Cow Line, Gold
- POJ 3623 Best Cow Line, Gold(贪心)
- POJ-3623-Best Cow Line, Gold
- 【POJ 3623】 Best Cow Line, Gold (后缀数组)
- POJ 3623 Best Cow Line, Gold(模拟)
- [贪心+后缀数组] poj 3623 Best Cow Line, Gold
- POJ 3623 Best Cow Line, Gold(模拟)
- 【bzoj 1692】【bzoj 1640】【poj 3617】【poj 3623】Best Cow Line 好牛队 双倍经验水水水
- PKU 3623 Best Cow Line, Gold
- P2870 (poj 3617) [USACO07DEC]最佳牛线,黄金Best Cow Line, Gold 可爱的贪心
- HDU 3623 Best Cow Line, Gold(模拟,注意思路,简单)
- 【bzoj 1692】【bzoj 1640】【poj 3617】【poj 3623】Best Cow Line 好牛队 双倍经验水水水
- POJ——3617 Best Cow Line