SPOJ AMR12I Saruman of Many Colours 解题报告
来源:互联网 发布:知乎日耳曼和凯尔特 编辑:程序博客网 时间:2024/05/18 02:46
题目
Summer Training 06 - Amritapuri 2012 总结
题意:
一段区间,每次可以选择长度恰好为K的子区间涂色,求涂成目标状态的最少次数,不能的话输出-1.
题解:
仔细想想就发现是全场最水题……显然因为区间是固定的,所以不连续的同一种颜色不可能是同以此涂的。如果一个长度至少为K的同颜色的区间都没有,就是-1.否则就是同一种颜色且长度不超过K的区间数。
//Time:0ms//Memory:3277KB//Length:791B#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <cmath>#include <set>using namespace std;#define MP(x,y) make_pair(x,y)#define MAXN 20010#define MAXM (1<<10)#define FI first#define SE second#define MOD 1000000007char str[MAXN];int main(){ //freopen("/home/moor/Code/input","r",stdin); int ncase,n,k,ans=0,pre; bool flag; scanf("%d",&ncase); while(ncase--) { ans=0; pre=0; flag=0; scanf("%d%d%s",&n,&k,str); for(int i=0;i<n;++i) { if(pre<k&&(!i||str[i]==str[i-1])) ++pre; else ++ans,pre=1; if(pre==k) flag=1; } if(pre>=1) ++ans; printf("%d\n",flag?ans:-1); } return 0;}
- SPOJ AMR12I Saruman of Many Colours 解题报告
- Saruman of Many Colours---题解
- 解题报告:SPOJ
- SPOJ AMR12G The Glittering Caves of Aglarond 解题报告
- SPOJ AMR12K The Loyalty of the Orcs 解题报告
- SPOJ AMR12D The Mirror of Galadriel 解题报告
- Spoj数论专场解题报告
- SPOJ AMR12C Entmoot 解题报告
- How Many Tables(解题报告)
- How Many Tables解题报告
- SPOJ AMR12E Dyslexic Gollum 解题报告
- SPOJ AMR12H Wormtongues Mind 解题报告
- SPOJ AMR12A The Black Riders 解题报告
- SPOJ 694 后缀数组 解题报告
- HDU1213 How Many Tables 解题报告
- HDU - 1213 How Many Tables 解题报告
- hdu1978 How many ways 解题报告
- [fzu2016]How many tuples 解题报告
- WinDbg
- js2dx --- UI
- Maya: 菜单 编辑曲线 > 复制曲面曲线
- Hibernate的Session
- hadoop开发:cenos网络配置
- SPOJ AMR12I Saruman of Many Colours 解题报告
- Maya: 菜单 编辑曲线 > 附加曲线
- WPF MultiBinding 实现控件 Tooltip 多绑定
- C++初步之三 小项目
- Maya: 菜单 编辑曲线 > 分离曲线
- uva 208 Firetruck (DFS + 并查集)
- ios与服务端的交互
- 使用dex2jar来反编译android代码
- [iOS]shell 自动打包工程