CDOJ 486 Good Morning 傻逼题
Good Morning
Time Limit: 20 Sec
Memory Limit: 256 MB
題目連接
http://acm.uestc.edu.cn/#/problem/show/486
Description
Sam loves Lily very much that he shows his love to her through all kinds of ways. This morning, Lily received an e-mail from Sam. Lily knows that Sam hided “good morning” in this mail. Lily tried several ways to resort the letters (including the space ' ') so that more “good morning"s could be found. The number of “good morning” appeared in a specified string equals the number of positions from which Lily could see a consecutive string “good morning”.
With so many letters, Lily is about to be dizzy. She asks you to tell her what is the maximum number of “good morning"s appear in this mail after rearranged in some way.
Input
First an integer $T$ ($T \leq 20$), indicates there are $T$ test cases.
Every test case begins with a single line consist of only lowercase letters and space which is at most $1000$ characters.
Output
For every test case, you should output Case #k: first, where $k$ indicates the case number and starts at $1$. Then output an integer indicating the answer to this test case.
Sample Input
2
gninrom doog
ggoooodd mmoorrnniinngg
Sample Output
Case #1: 1
Case #2: 2
HINT
?
題意
讓你重新排列,使得出現最多的goodmorning
題解:
注意goodmorningoodmorning這個數據,這個數據輸出應該是2
代碼
#include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> #include <map> #include <stack> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define test freopen("test.txt","r",stdin) const int maxn=202501; #define mod 1000000007 #define eps 1e-9 const int inf=0x3f3f3f3f; const ll infll = 0x3f3f3f3f3f3f3f3fLL; inline ll read() {ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f; } //*************************************************************************************int a[30]; char s[maxn]; int main() {//この戦い終わった、故郷に帰って結婚するだん!!! ??\cout<<"please hack me"<<endl;int t=read();for(int cas=1;cas<=t;cas++){memset(a,0,sizeof(a));gets(s);for(int i=0;i<strlen(s);i++){if(s[i]<='z'&&s[i]>='a')a[s[i]-'a']++;}int num=inf;num=min(num,a['g'-'a']-1);num=min(num,a['o'-'a']/3);num=min(num,a['d'-'a']);num=min(num,a['m'-'a']);num=min(num,a['r'-'a']);num=min(num,a['n'-'a']/2);num=min(num,a['i'-'a']);printf("Case #%d: %d\n",cas,num);} }?
轉載于:https://www.cnblogs.com/qscqesze/p/4678380.html
總結
以上是生活随笔為你收集整理的CDOJ 486 Good Morning 傻逼题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何做到长时间(4 个小时以上)精神专注
- 下一篇: Android开源项目整理:个性化空间V