POJ - 1509 Glass Beads
生活随笔
收集整理的這篇文章主要介紹了
POJ - 1509 Glass Beads
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
傳送門
最小表示法模板
//Achen #include<algorithm> #include<iostream> #include<cstring> #include<cstdlib> #include<cstdio> #include<vector> #include<queue> #include<cmath> #include<ctime> const int N=100007; typedef long long LL; using namespace std; int T,n; char s[N]; template<typename T> void read(T &x) {T f=1; x=0; char ch=getchar();while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();if(ch=='-') f=-1,ch=getchar();for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f; }int solve() {int i=0,j=1,k=0;for(;i<n&&j<n&&k<n;) {int t=s[(i+k)%n]-s[(j+k)%n];if(!t) k++;else {if(t>0) i=i+k+1; else j=j+k+1;if(i==j) j++;k=0;}} return min(i,j); }int main() {read(T);while(T--) {scanf("%s",s);n=strlen(s);printf("%d\n",solve()+1);}return 0; } View Code?
轉(zhuǎn)載于:https://www.cnblogs.com/Achenchen/p/8270413.html
總結(jié)
以上是生活随笔為你收集整理的POJ - 1509 Glass Beads的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 单例模式(winform唯一页面)
- 下一篇: Storm中并行度原来是这样计算的(1.