Codeforces 758B. Blown Garland

本文介绍了一道关于四种颜色灯排列的问题,并提供了一个简洁的C++代码解决方案。该问题要求确定损坏的各色灯的数量,通过分析已知条件得出序列特征,进而统计不同颜色灯的损坏情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目大意:

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

题解:

这道题是那种看着高端大气上档次,画一个样例就变成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\n",ans[a],ans[b],ans[c],ans[d]);
    getchar();getchar();
    return 0;
}
  

转载于:https://www.cnblogs.com/Skyminer/p/6357668.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值