zoukankan      html  css  js  c++  java
  • Codeforces 758B. Blown Garland

    题目大意:

    四种颜色的灯排成一排,一些灯的颜色是已知的,另外的灯已损坏。并且知道每连续的四个灯中一定有四种颜色。问每种颜色的灯有多少个是已经损坏的.

    题解:

    这道题是那种看着高端大气上档次,画一个样例就变成sb题的那种题。
    我们发现,这个序列肯定是一个长度为4的子序列不断重复得来的序列。。
    并且...并且什么,这就够了.

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    typedef long long ll;
    inline void read(int &x){
    	x=0;char ch;bool flag = false;
    	while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
    	while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
    }
    inline int cat_max(const int &a,const int &b){return a>b ? a:b;}
    inline int cat_min(const int &a,const int &b){return a<b ? a:b;}
    const int maxn = 128;
    char s[maxn];
    int ans[maxn];
    int main(){
    	scanf("%s",s+1);
    	int n = strlen(s+1);
    	int a,b,c,d;
    	for(int i=1;i<=n;++i){
    		switch(s[i]){
    			case 'R':a = i%4;break;
    			case 'B':b = i%4;break;
    			case 'Y':c = i%4;break;
    			case 'G':d = i%4;break;
    			case '!':ans[i%4]++;break;
    		}
    	}
    	printf("%d %d %d %d
    ",ans[a],ans[b],ans[c],ans[d]);
    	getchar();getchar();
    	return 0;
    }
      
    
  • 相关阅读:
    datalist的用法
    SQL级联删除——删除主表同时删除从表——同时删除具有主外键关系的表
    js
    回调机制
    JS原型链
    多线程请求乌云链接
    Python高频技巧总结[基础篇]
    批量文本读取URL获取正常访问且保留对应IP
    Django基础之视图
    Django框架简介
  • 原文地址:https://www.cnblogs.com/Skyminer/p/6357668.html
Copyright © 2011-2022 走看看