codefores 834B The Festive Evening

本文介绍了一个关于守卫如何有效分配的问题,确保每个入口都有足够守卫的情况下,嘉宾可以顺利进入城堡。通过算法实现,验证是否会出现守卫不足的情况。

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

B. The Festive Evening
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in the kingdom of Sweetland in case it turns out to reach the wrong hands. So it's a necessity to not let any uninvited guests in.

There are 26 entrances in Jelly Castle, enumerated with uppercase English letters from A to Z. Because of security measures, each guest is known to be assigned an entrance he should enter the castle through. The door of each entrance is opened right before the first guest's arrival and closed right after the arrival of the last guest that should enter the castle through this entrance. No two guests can enter the castle simultaneously.

For an entrance to be protected from possible intrusion, a candy guard should be assigned to it. There are k such guards in the castle, so if there are more than k opened doors, one of them is going to be left unguarded! Notice that a guard can't leave his post until the door he is assigned to is closed.

Slastyona had a suspicion that there could be uninvited guests at the evening. She knows the order in which the invited guests entered the castle, and wants you to help her check whether there was a moment when more than k doors were opened.

Input

Two integers are given in the first string: the number of guests n and the number of guards k (1 ≤ n ≤ 1061 ≤ k ≤ 26).

In the second string, n uppercase English letters s1s2... sn are given, where si is the entrance used by the i-th guest.

Output

Output «YES» if at least one door was unguarded during some time, and «NO» otherwise.

You can output each letter in arbitrary case (upper or lower).

Examples
input
5 1
AABBB
output
NO
input
5 1
ABABB
output
YES
Note

In the first sample case, the door A is opened right before the first guest's arrival and closed when the second guest enters the castle. The door B is opened right before the arrival of the third guest, and closed after the fifth one arrives. One guard can handle both doors, as the first one is closed before the second one is opened.

In the second sample case, the door B is opened before the second guest's arrival, but the only guard can't leave the door A unattended, as there is still one more guest that should enter the castle through this door.

题意

有n个门,k个守卫,每个门有一个序号,每个嘉宾从特定的门进去

每个门开门到关门之间,必须有一个守卫守候,开门从第一个嘉宾进,最后一个从这个门进的嘉宾进去后关门

问问守卫能不能守住

#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
using namespace std;
struct node
{
    int stat;
    int endd;
} dp[100];
int flag[100];
int main()
{
    int n,k,m,sum,aflag;
    char a[1000006];
    while(scanf("%d%d",&n,&k)!=EOF)
    {
        memset(flag,0,sizeof(flag));
        scanf("%s",a);
        aflag=0;
        sum=0;
        for(int i=0; i<n; i++)
        {
            m=a[i]-'A';
            if(flag[m]==0)
            {
                dp[m].stat=i;
                dp[m].endd=i;//为了这组样例
                              //26 1
                             //ABCDEFGHIJKLMNOPQRSTUVWXYZ
                flag[m]=1;
            }
            else
            {
                    dp[m].endd=i;
            }
        }
        for(int i=0; i<n; i++)
        {
            m=a[i]-'A';
            if(dp[m].stat==i)
            {
                sum++;//开门需要一门守卫
                if(sum>k)
                {
                    aflag=1;
                    break;
                }
                if(dp[m].endd==i)//说明只有一个嘉宾从这个门进
                {
                    sum--;
                }
            }
            else if(dp[m].stat<i&&dp[m].stat>i)
            {
                if(sum>k)
                {
                    aflag=1;
                    break;
                }
            }
            else if(dp[m].endd==i)
            {
                if(sum>k)
                {
                    aflag=1;
                    break;
                }
                else
                {
                    sum--;//说明最后一个嘉宾已经进去了,这个门需要关了,不需要人来守护了
                }
            }
        }
        if(aflag==0)
            printf("NO\n");
        else
            printf("YES\n");
    }
}


在使用OMRON G9SP安全控制进行PNP型安全输入设备的配置时,用户首先需要具备对控制硬件和软件基本操作的了解。通过《OMRON G9SP安全控制软件入门教程》,用户可以学习到如何将安全输入设备接入控制,并确保设备的正确连接。 参考资源链接:[OMRON G9SP安全控制软件入门教程](https://wenku.youkuaiyun.com/doc/646050045928463033ad834b?spm=1055.2569.3001.10343) 首先,根据控制的端子排列,将PNP型安全输入设备的输出连接到G9SP控制的相应输入端子。例如,一个典型的急停开关的PNP输出应连接到控制的特定输入端子。在连接时,务必遵循OMRON的安全连接指南,确保符合安全等级TYPE4的要求。 接下来,在配置软件中,将安全输入设备的图标拖拽到软件界面中的相应位置,并确保其与实际接线一致。软件提供直观的操作界面,方便用户进行配置。同时,用户可以根据需要对设备进行测试脉冲设置,以评估其功能。 在完成配置后,用户应检查I/O状态指示灯,以验证设备是否正常工作。如果所有指示灯显示正常,表明安全输入设备已经成功配置并连接无误。 此外,教程中还会介绍如何进行安全性评估,这是确保系统安全运行的重要步骤。确保信号通过安全评估后,方能被系统接受并进一步处理。 推荐在掌握基础知识后,继续深入学习《OMRON G9SP安全控制软件入门教程》中提供的高级功能和故障排除技巧,以全面提高对OMRON G9SP安全控制的操作能力。 参考资源链接:[OMRON G9SP安全控制软件入门教程](https://wenku.youkuaiyun.com/doc/646050045928463033ad834b?spm=1055.2569.3001.10343)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值