import java.util.Scanner; public class Main6 { public static void main(String[] args){ Scanner in = new Scanner(System.in); while(in.hasNext()){ char[] cs = in.nextLine().toCharArray(); int n = cs.length; System.out.println(minPaint(cs, 0, n-1)); } } static int minPaint(char[] cs ,Integer start,int end){ int left = 0; int right = 0; int minLeft = 0; int minRight = 0; while(cs[start]=='R'&&start<end){ start++; } while(cs[end]=='G'&&end>start){ end--; } if(start>=end){ return 0; } while(cs[start+left]=='G'){ left++; } minLeft = left+minPaint(cs, start+left,end); while(cs[end-right]=='R'){ right++; } minRight = right+minPaint(cs, start, end-right); return Math.min(minLeft, minRight); } }
点赞 7

相关推荐

肥肠椒绿:双非本可不就犯天条了,双非本就应该打入无间地狱
点赞 评论 收藏
分享
FightingNa...:小厂不喜欢离毕业还远的。培养你三个月小半年,你又回去上学,你丰富简历爽歪歪,小厂啥也得不到。大厂兴许愿意培养你,可以试试大厂,准备下不黑了就行。
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务