D - Postcards and photos
来源:互联网 发布:大学生网络创业培训 编辑:程序博客网 时间:2024/06/05 13:24
Polycarpus has postcards and photos hung in a row on the wall. He decided to put them away to the closet and hang on the wall a famous painter's picture. Polycarpus does it like that: he goes from the left to the right and removes the objects consecutively. As Polycarpus doesn't want any mix-ups to happen, he will not carry in his hands objects of two different types. In other words, Polycarpus can't carry both postcards and photos simultaneously. Sometimes he goes to the closet and puts the objects there, thus leaving his hands free. Polycarpus must put all the postcards and photos to the closet. He cannot skip objects. What minimum number of times he should visit the closet if he cannot carry more than 5 items?
The only line of the input data contains a non-empty string consisting of letters"С" and"P" whose length does not exceed100 characters. If thei-th character in the string is the letter"С", that means that thei-th object (the numbering goes from the left to the right) on Polycarpus' wall is a postcard. And if thei-th character is the letter"P", than the i-th object on the wall is a photo.
Print the only number — the minimum number of times Polycarpus has to visit the closet.
CPCPCPC
7
CCCCCCPPPPPP
4
CCCCCCPPCPPPPPPPPPP
6
CCCCCCCCCC
2
In the first sample Polycarpus needs to take one item to the closet 7 times.
In the second sample Polycarpus can first take 3 postcards to the closet; then 3 more. He can take the 6 photos that are left in the similar way, going to the closet twice.
In the third sample Polycarpus can visit the closet twice, both times carrying 3 postcards. Then he can take there 2 photos at once, then one postcard and finally, he can carry the last 10 photos if he visits the closet twice.
In the fourth sample Polycarpus can visit the closet twice and take there all 10 postcards (5 items during each go).
题意:从墙上取下明信片或照片,规定按从左到右顺序每回只能取下一种(要么是明信片,要么是照片),且所取下的某种东西不能超过五个(即最多5个)。
### 注意:ave 应为 实数型,应为sum/n 可能为实数,开始时我就定义成int型了,然后 WA 了。
法 1.#include<stdio.h>#include<string.h>int main(){int i, j, len, count, num;char str[102], t; scanf("%s", str); num = 1;count = 0; t = str[0]; len = strlen(str); for(j=1; j<len; j++){ if(t == str[j]){count++; if(count == 5){num++;count = 0;}}else{t = str[j];num++;count = 0;}} printf("%d\n", num); return 0;}
法 2.
#include <stdio.h>#include <string.h>int main(){ int i,n=0; char s[103]; int c; scanf("%s",s); int l=strlen(s); i=0; int j=0; for(i=0;i<l;){ for(j=i+1;j<=i+4;j++){ if(s[i]!=s[j]) break; } n++; i=j; } printf("%d\n",n); return 0;}第二个为同学的代码,也挺好的,所以贴出来。
法 3.(这也是一种很好的思路,不用考虑ave 的类型了)
#include<stdio.h>int main(){ int a[200005],b[200005],n,sum=0,num=0,i; scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d",&a[i]); sum+=a[i]; } for(i=1;i<=n;i++) { if(a[i]*n==sum) { b[++num]=i; } } printf("%d\n",num); if(num==0) return 0; for(i=1;i<=num;i++) { if(i==1)printf("%d",b[i]); else printf(" %d",b[i]); } printf("\n"); return 0;}
- D - Postcards and photos
- A. Postcards and photos
- CodeForces-137A Postcards and photos
- Codeforces 137A-Postcards and photos(模拟+贪心)
- Codeforces Beta Round #98 (Div. 2) / 137A Postcards and photos (模拟)
- Postcards
- [codeforces761F] Dasha and Photos
- iOS<Photos/Photos.h>与<AssetsLibrary/AssetsLibrary.h>and 相机
- photos
- CodeForces 761F. Dasha and Photos
- Codeforces Round 761F - Dasha and Photos
- [Codeforces Round #394 DIV2F (CF761F)] Dasha and Photos
- Foreign Postcards Gym
- Turn Photos Into 3D Models With Autodesk 123D Catch [Currently Only Windows]
- Simple Computer Transfer and Backup: Don't Lose your Music and Photos
- Gym 101190F Foreign Postcards
- iOS 9人机界面指南:iOS 技术 (3D Touch、Live Photos、Wallet以及Apple Pay)
- Use advanced interactive viewer to move, zoom and record photos, producing a unique sightline flash
- Java编程优化之旅(二) String类型知多少
- cgroups
- 《程序员的职业修养》读后感--系列文章
- 【Qt编程】Qt学习之状态栏
- matlab自带滤波器函数小结(图像处理)
- D - Postcards and photos
- 八圆包,九块九包邮的小而美生活集市
- 编辑文章 - 博客频道 - CSDN.NET
- 因为爱你 索尼对你不离不弃
- 正则表达式
- 打太极和学编程
- 麻将番数
- EXC_BAD_ACCESS异常 调试过程
- 敏捷开发 PK 瀑布模型