Day1 - A - Painting the sticks
来源:互联网 发布:mysql查询当前时间 编辑:程序博客网 时间:2024/06/06 04:36
A - Painting the sticks
Time Limit:3000MS MemoryLimit:0KB 64bit IO Format:%lld &%llu
Description
Captain Raylikes sticks and spares no effort to find sticks of various colors. It isreally a tedious work which Ray has been tired of. As the ICPC Regional contestis coming, he has no time to do it. Consequently he orders his teammate Neal todo this work.
Neal does notlike this work either, so he decides just to paint some of the sticks andprovide them for Ray (Of course, he will not let Ray know this,otherwise ... ).
Neal tells Ray that he has found many sticks, all of which contain no more thanthree colors (denoted as 1, 2, 3). Ray divides each stick into n parts( n is no more than 30), and let Neal know exactly the wantedcolor of each part. Neal will paint each stick in several steps with thefollowing rules in each step:
1. He can only paint at most three consecutive blocks at atime. (Each block contains one part or several consecutive parts)
2. The color in the same block must be the same.
3. After Neal finish painting the sticks, the color of thestick must be same as Ray wanted.
Now it is Neal'stime to paint the sticks. To finish this job as soon as possible, he wants tominimize the number of step.
You may assumethat all sticks are of no color at the beginning.
Input
The input filecontains multiple test cases. For each test case, there is a positive integer n ,described above, on the first line. Then nnumbers (each number is1, 2, or 3) come in the second line indicating the colors of n parts.Proceed to the end of the file.
Output
For each testcase, output the least number of steps that Neal needs to paint a stick. Pleaseoutput the results as in the Sample Output.
Sample Input
2
1 2
3
1 2 3
Sample Output
Case 1: 1
Case 2: 1
题目大意
给你一个颜色序列,需要你来涂色,连续且有相同颜色的可以作为一个块来涂色,每次最多可以涂3个块的颜色,问对于给定的序列,最少的涂色步骤。
题目分析
简单的线性分析,统计有多少的颜色块,3块一组,计算多少组即可O(n)的算法。
AC代码
#include <iostream>using namespace std;int main(){ int n,T=1; while (cin>>n && n) { int i,j=0,t,ans=0; for (i=1;i<=n;i++) { cin>>t; if(t!=j) { j=t; ans++; } } if(ans%3==0) cout<<"Case "<<T<<": "<<ans/3<<endl; else cout<<"Case "<<T<<": "<<ans/3+1<<endl; T++; } return 0;}
- Day1 - A - Painting the sticks
- Painting the Web
- sgu183 Painting the balls_dp
- [cf398B]Painting The Wall
- HNU13383:The Big Painting
- Painting The Wall CodeForces
- Painting A Board poj1691
- POJ1691--Painting A Board
- poj1691 Painting A Board
- zoj1424 Painting A Board
- POJ1691-Painting A Board
- Painting A Board----DFS
- POJ 1691 Painting A Board
- poj 1691 Painting A Board
- poj 1691 Painting A Board
- POJ 1691 Painting A Board
- POJ 1691 Painting A Board
- 【poj 1691】Painting A Board
- ubuntu升级firefox
- 一键获取所有网址前面的小标志
- Android app 升级:android:versionCode和android:versionName
- Linux下MySQL 5.5.11源码编译安装笔记
- POJ 3278: Catch That Cow
- Day1 - A - Painting the sticks
- PHP学习实例—5(日历类的编写)
- error: invalid symbol: 'switch'
- 通向架构师的道路(第五天)之tomcat集群-群猫乱舞
- Socket.io信息传输各种方法
- poj 1001
- Solr In Action 中文版 第一章(四、五)
- 物联网时代的领导者---天津泰林科技发展有限公司
- C++ 虚函数表解析