Codeforces
来源:互联网 发布:美工素材网站有哪些 编辑:程序博客网 时间:2024/06/18 10:14
B. The Festive Evening
题目链接
分类:思维、模拟
1.题意概述
- 有A~Z的26个入口,现在有n位客人轮流从这些入口进入,同一时刻不会有超过一位客人进入,每个客人进固定的入口,一个入口在第一位客人来的时候打开,在最后一位客人进入之后关闭,一个入口如果是打开的就需要一个守卫,共有k个守卫,问是否存在某个时间段有某个入口开放但没有守卫?
2.解题思路
- 这题的实质就是给你一堆区间,问你相交的区间是否大于k,我们记录每个字符开始的位置和结束的位置,然后去模拟,当是开始位置时候k-1,在结束位置k-1,每一次操作结束去判断k是否都合法(大于等于0)即可。
3.AC代码
#include <bits/stdc++.h>using namespace std;#define lson root << 1#define rson root << 1 | 1#define lent (t[root].r - t[root].l + 1)#define lenl (t[lson].r - t[lson].l + 1)#define lenr (t[rson].r - t[rson].l + 1)#define eps 1e-6#define e exp(1.0)#define pi acos(-1.0)#define fi first#define se second#define pb push_back#define mp make_pair#define SZ(x) ((int)(x).size())#define All(x) (x).begin(),(x).end()#define rep(i,a,n) for (int i=a;i<n;i++)#define per(i,a,n) for (int i=n-1;i>=a;i--)#define Close() ios::sync_with_stdio(0),cin.tie(0)#define INF 0x3f3f3f3f#define maxn 1000010#define N 1111typedef vector<int> VI;typedef pair<int, int> PII;typedef long long ll;typedef unsigned long long ull;const int mod = 1e9 + 7;/* head */char s[1000010];int fst[30], lst[30], n, m;int main() { scanf("%d%d", &n, &m); scanf("%s", s + 1); for (int i = 1; i <= n; i++) { if (!fst[s[i] - 'A' + 1])fst[s[i] - 'A' + 1] = i; } for (int i = n; i >= 1; i--) { if (!lst[s[i] - 'A' + 1])lst[s[i] - 'A' + 1] = i; } for (int i = 1; i <= n; i++) { int now = s[i] - 'A' + 1; if (fst[now] == i)m--; if (m < 0) { puts("YES"); return 0; } if (lst[now] == i)m++; } puts("NO");}
阅读全文
0 0
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Hibernate入门(一)
- 数论初级
- 【HDU2504】又见GCD(gcd)
- 关于几个小问题
- 2017多校联合第三场 1005题 hdu 6060 RXD and dividing (超详细!!!)构造
- Codeforces
- Tensorflow一些常用基本概念与函数(2)
- php升级到5.6
- Qt界面添加菜单,工具栏以及状态栏
- 新手最强权限管理框架——Shiro的简易说明与开发配置
- CodeForces-814B An express train to reveries 解题报告
- hibernate入门(二)Query初步学习
- Java finalize方法使用
- HDU 3016 Man Down(线段树+离散化+dp)