HDU 5455 Fang Fang(模拟)
2016-09-01 21:21
274 查看
思路:直接模拟就好了,注意全是f的情况
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const double eps = 1e-9;
const int maxn = 1000000 + 100;
char s[maxn];
int pos[maxn];
int main()
{
int T, cas=1, n;
scanf("%d", &T);
while(T--)
{
int f=1, cn=0;
scanf("%s", s);
n = strlen(s);
for(int i=0;s[i];++i)
{
if(s[i]=='c') pos[cn++]=i;
if(s[i]!='c'&&s[i]!='f'){
f=0; break;
}
}
printf("Case #%d: ", cas++);
if(!f) puts("-1");
else
{
if(cn==0)
{
printf("%d\n", n/2+n%2);
continue;
}
for(int i=0;i<cn-1;++i)
{
if(pos[i+1]-pos[i]<3)
{
f=0; break;
}
}
if(n-pos[cn-1] + pos[0] < 3) f=0;
if(!f) puts("-1");
else printf("%d\n", cn);
}
}
return 0;
}
Description
Fang Fang says she wants to be remembered.
I promise her. We define the sequence
of
strings.
Write down a serenade as a lowercase string
in
a circle, in a loop that never ends.
Spell the serenade using the minimum number of strings in
,
or nothing could be done but put her away in cold wilderness.
Input
An positive integer
,
indicating there are
test
cases.
Following are
lines,
each line contains an string
as
introduced above.
The total length of strings for all test cases would not be larger than
.
Output
The output contains exactly
lines.
For each test case, if one can not spell the serenade by using the strings in
,
output
.
Otherwise, output the minimum number of strings in
to
split
according
to aforementioned rules. Repetitive strings should be counted repeatedly.
Sample Input
Sample Output
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const double eps = 1e-9;
const int maxn = 1000000 + 100;
char s[maxn];
int pos[maxn];
int main()
{
int T, cas=1, n;
scanf("%d", &T);
while(T--)
{
int f=1, cn=0;
scanf("%s", s);
n = strlen(s);
for(int i=0;s[i];++i)
{
if(s[i]=='c') pos[cn++]=i;
if(s[i]!='c'&&s[i]!='f'){
f=0; break;
}
}
printf("Case #%d: ", cas++);
if(!f) puts("-1");
else
{
if(cn==0)
{
printf("%d\n", n/2+n%2);
continue;
}
for(int i=0;i<cn-1;++i)
{
if(pos[i+1]-pos[i]<3)
{
f=0; break;
}
}
if(n-pos[cn-1] + pos[0] < 3) f=0;
if(!f) puts("-1");
else printf("%d\n", cn);
}
}
return 0;
}
Description
Fang Fang says she wants to be remembered.
I promise her. We define the sequence
of
strings.
Write down a serenade as a lowercase string
in
a circle, in a loop that never ends.
Spell the serenade using the minimum number of strings in
,
or nothing could be done but put her away in cold wilderness.
Input
An positive integer
,
indicating there are
test
cases.
Following are
lines,
each line contains an string
as
introduced above.
The total length of strings for all test cases would not be larger than
.
Output
The output contains exactly
lines.
For each test case, if one can not spell the serenade by using the strings in
,
output
.
Otherwise, output the minimum number of strings in
to
split
according
to aforementioned rules. Repetitive strings should be counted repeatedly.
Sample Input
8 ffcfffcffcff cffcfff cffcff cffcf ffffcffcfff cffcfffcffffcfffff cff cffc
Sample Output
Case #1: 3 Case #2: 2 Case #3: 2 Case #4: -1 Case #5: 2 Case #6: 4 Case #7: 1 Case #8: -1
相关文章推荐
- Integer的缓存(-128到127)
- 操作系统
- C++函数指针数组
- [bzoj 3251]树上三角形
- Android面试题(5)
- 字符串加密问题
- iOS开发——UIImageView的contentMode、裁剪和layer属性详解
- Java数组简单知识点应用
- 堆和栈的区别
- Max-Min算法实现
- Android面试题(4)
- 为什么说绝大多数人都是“低品质勤奋者”?
- 和为S的两个数字
- Linux命令之远程下载命令:wget
- 大数运算(6)——大数阶乘(求位数)
- iOS开发——响应链(Responder Chain)的深入理解和代码示例(二)
- HDU 5461 Largest Point(水)
- 关于LinearLayout 布局中layout_gravity 属性和gravity 属性的异同。
- MFC 用进度条在状态栏显示某个按钮响应函数的过程,并用多线程实时更新
- HDU3980 Paint Chain SG函数