Hello XTCPC
生活随笔
收集整理的這篇文章主要介紹了
Hello XTCPC
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
http://acm.hdu.edu.cn/showproblem.php?pid=6536
題意:不重復(fù)元素,求子串為xtCpc的數(shù)量最大
題解:這是一道很簡(jiǎn)單的貪心題目,因?yàn)閤tCpc這5個(gè)字母各不相同,所以直接采取貪心的策略,對(duì)于所有的“x”,“t”,“C”,”p”,”c”按照字母不同分別建立一個(gè)隊(duì)列,每次貪心的從隊(duì)列中找到最前面的沒(méi)有使用過(guò)的字母,直到有一個(gè)隊(duì)列為空。
C++版本一
/* *@Author: STZG *@Language: C++ */ #include <bits/stdc++.h> #include<iostream> #include<algorithm> #include<cstdlib> #include<cstring> #include<cstdio> #include<string> #include<vector> #include<bitset> #include<queue> #include<deque> #include<stack> #include<cmath> #include<list> #include<map> #include<set> //#define DEBUG #define RI register int #define endl "\n" using namespace std; typedef long long ll; //typedef __int128 lll; const int N=200000+10; const int M=100000+10; const int MOD=1e9+7; const double PI = acos(-1.0); const double EXP = 1E-8; const int INF = 0x3f3f3f3f; int t,n,m,k,p,l,r,u,v; int ans,cnt,flag,temp,sum;string str; struct node{}; int main() { #ifdef DEBUGfreopen("input.in", "r", stdin);//freopen("output.out", "w", stdout); #endif//ios::sync_with_stdio(false);//cin.tie(0);//cout.tie(0);//scanf("%d",&t);//while(t--){while(~scanf("%d",&n)){ans=0;cin>>str;queue<int>q[5];for(int i=0;i<n;i++){if(str[i]=='x'){q[0].push(i);}else if(str[i]=='t'){q[1].push(i);}else if(str[i]=='C'){q[2].push(i);}else if(str[i]=='p'){q[3].push(i);}else if(str[i]=='c'){q[4].push(i);}}while(!q[0].empty()){int pos=q[0].front();q[0].pop();flag=1;for(int i=1;i<5;i++){while(!q[i].empty()&&pos>q[i].front())q[i].pop();if(q[i].empty()){flag=0;break;}pos=q[i].front();q[i].pop();}if(!flag)break;ans++;}cout<<ans<<endl;}//}#ifdef DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC); #endif//cout << "Hello world!" << endl;return 0; } 與50位技術(shù)專(zhuān)家面對(duì)面20年技術(shù)見(jiàn)證,附贈(zèng)技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的Hello XTCPC的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Chika and Friendly P
- 下一篇: SSY and JLBD