A. Telephone Number

A telephone number is a sequence of exactly 11 digits, where the first digit is 8. For example, the sequence 80011223388 is a telephone number, but the sequences 70011223388 and 80000011223388 are not.

You are given a string ss of length nn, consisting of digits.

In one operation you can delete any character from string ss. For example, it is possible to obtain strings 112, 111 or 121 from string 1121.

You need to determine whether there is such a sequence of operations (possibly empty), after which the string ss becomes a telephone number.

Input

The first line contains one integer tt (1≤t≤1001≤t≤100) — the number of test cases.

The first line of each test case contains one integer nn (1≤n≤1001≤n≤100) — the length of string ss.

The second line of each test case contains the string ss (|s|=n|s|=n) consisting of digits.

Output

For each test print one line.

If there is a sequence of operations, after which ss becomes a telephone number, print YES.

Otherwise, print NO.

Example
input

Copy
2
13
7818005553535
11
31415926535
output

Copy
YES
NO
Note

In the first test case you need to delete the first and the third digits. Then the string 7818005553535 becomes 88005553535.

这个分一下是否满足11位,如果大于11位,只需要判断除去后10位前面是否有8即可

代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<vector> const int maxn=1e5+;
typedef long long ll;
using namespace std; int main()
{
int T;
cin>>T;
string str;
int n;
while(T--)
{
cin>>n;
cin>>str;
int len=str.length();
if(len>)
{
int flag=;
for(int t=len-;t>=;t--)
{
if(str[t]=='')
{
flag=;
break;
}
}
if(flag)
{
cout<<"YES"<<endl;
}
else
{
cout<<"NO"<<endl;
}
}
else if(len==)
{
if(str[]=='')
{
cout<<"YES"<<endl;
}
else
{
cout<<"NO"<<endl;
}
}
else
{
cout<<"NO"<<endl;
}
}
return ;
}

C. News Distribution

In some social network, there are nn users communicating with each other in mm groups of friends. Let's analyze the process of distributing some news between users.

Initially, some user xx receives the news from some source. Then he or she sends the news to his or her friends (two users are friends if there is at least one group such that both of them belong to this group). Friends continue sending the news to their friends, and so on. The process ends when there is no pair of friends such that one of them knows the news, and another one doesn't know.

For each user xx you have to determine what is the number of users that will know the news if initially only user xx starts distributing it.

Input

The first line contains two integers nn and mm (1≤n,m≤5⋅1051≤n,m≤5⋅105) — the number of users and the number of groups of friends, respectively.

Then mm lines follow, each describing a group of friends. The ii-th line begins with integer kiki (0≤ki≤n0≤ki≤n) — the number of users in the ii-th group. Then kiki distinct integers follow, denoting the users belonging to the ii-th group.

It is guaranteed that ∑i=1mki≤5⋅105∑i=1mki≤5⋅105.

Output

Print nn integers. The ii-th integer should be equal to the number of users that will know the news if user ii starts distributing it.

Example
input

Copy
7 5
3 2 5 4
0
2 1 2
1 1
2 6 7
output

Copy
4 4 1 4 4 2 2 
裸的并查集
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<map>
#include<cmath> const int maxn=5e5+;
typedef long long ll;
using namespace std;
int pre[maxn];
int find(int x)
{
if(x==pre[x])
{
return x;
}
else
{
return pre[x]=find(pre[x]);
}
}
void Merge(int x,int y)
{
int xx=find(x);
int yy=find(y);
if(xx!=yy)
{
pre[xx]=yy;
} }
int a[maxn];
int main()
{
int n,m;
cin>>n>>m;
int x;
for(int t=;t<=n;t++)
{
pre[t]=t;
}
int s1,s2;
for(int t=;t<m;t++)
{
scanf("%d",&x);
if(x!=)
scanf("%d",&s1);
for(int j=;j<x;j++)
{
scanf("%d",&s2);
Merge(s1,s2);
s1=s2;
}
} int ans=;
memset(a,,sizeof(a));
for(int t=;t<=n;t++)
{ a[find(t)]++;
}
for(int t=;t<=n;t++)
{
printf("%d ",a[find(t)]);
} return ;
}

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

A string is called bracket sequence if it does not contain any characters other than "(" and ")". A bracket sequence is called regular(shortly, RBS) if it is possible to obtain correct arithmetic expression by inserting characters "+" and "1" into this sequence. For example, "", "(())" and "()()" are RBS and ")(" and "(()" are not.

We can see that each opening bracket in RBS is paired with some closing bracket, and, using this fact, we can define nesting depth of the RBS as maximum number of bracket pairs, such that the 22-nd pair lies inside the 11-st one, the 33-rd one — inside the 22-nd one and so on. For example, nesting depth of "" is 00, "()()()" is 11 and "()((())())" is 33.

Now, you are given RBS ss of even length nn. You should color each bracket of ss into one of two colors: red or blue. Bracket sequence rr, consisting only of red brackets, should be RBS, and bracket sequence, consisting only of blue brackets bb, should be RBS. Any of them can be empty. You are not allowed to reorder characters in ss, rr or bb. No brackets can be left uncolored.

Among all possible variants you should choose one that minimizes maximum of rr's and bb's nesting depth. If there are multiple solutions you can print any of them.

Input

The first line contains an even integer nn (2≤n≤2⋅1052≤n≤2⋅105) — the length of RBS ss.

The second line contains regular bracket sequence ss (|s|=n|s|=n, si∈{si∈{"(", ")"}}).

Output

Print single string tt of length nn consisting of "0"-s and "1"-s. If titi is equal to 0 then character sisi belongs to RBS rr, otherwise sisi belongs to bb.

Examples
input

Copy
2
()
output

Copy
11
input

Copy
4
(())
output

Copy
0101
input

Copy
10
((()())())
output

Copy
0110001111
Note

In the first example one of optimal solutions is s=s= "()()". rr is empty and b=b= "()()". The answer is max(0,1)=1max(0,1)=1.

In the second example it's optimal to make s=s= "(())(())". r=b=r=b= "()()" and the answer is 11.

In the third example we can make s=s= "((()())())((()())())". r=r= "()()()()" and b=b= "(()())(()())" and the answer is 22.

思维,我们维护一下使得两个的深度尽可能的小,也就是当其中一个大的时候,就往另一个补,以此类推

代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<map>
#include<cmath>
const int maxn=2e5+;
typedef long long ll;
using namespace std;
char str[maxn];
int main()
{
int n;
cin>>n;
scanf("%s",str);
int s1=,s2=;
int a[maxn];
for(int t=;t<n;t++)
{
if(str[t]=='(')
{
if(s1<s2)
{
s1++;
a[t]=;
}
else
{
s2++;
a[t]=;
}
}
else
{
if(s1<s2)
{
s2--;
a[t]=;
}
else
{
s1--;
a[t]=;
}
}
}
for(int t=;t<n;t++)
{
printf("%d",a[t]);
}
return ;
}

Educational Codeforces Round 65 (Rated for Div. 2)(ACD)B是交互题,不怎么会的更多相关文章

  1. Educational Codeforces Round 65 (Rated for Div. 2)题解

    Educational Codeforces Round 65 (Rated for Div. 2)题解 题目链接 A. Telephone Number 水题,代码如下: Code #include ...

  2. Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题

    Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题 [Problem Description] ​ 总共两次询 ...

  3. Educational Codeforces Round 65 (Rated for Div. 2) B. Lost Numbers

    链接:https://codeforces.com/contest/1167/problem/B 题意: This is an interactive problem. Remember to flu ...

  4. Educational Codeforces Round 65 (Rated for Div. 2) D. Bicolored RBS

    链接:https://codeforces.com/contest/1167/problem/D 题意: A string is called bracket sequence if it does ...

  5. Educational Codeforces Round 65 (Rated for Div. 2) C. News Distribution

    链接:https://codeforces.com/contest/1167/problem/C 题意: In some social network, there are nn users comm ...

  6. Educational Codeforces Round 65 (Rated for Div. 2) A. Telephone Number

    链接:https://codeforces.com/contest/1167/problem/A 题意: A telephone number is a sequence of exactly 11  ...

  7. Educational Codeforces Round 65 (Rated for Div. 2)B. Lost Numbers(交互)

    This is an interactive problem. Remember to flush your output while communicating with the testing p ...

  8. [ Educational Codeforces Round 65 (Rated for Div. 2)][二分]

    https://codeforc.es/contest/1167/problem/E E. Range Deleting time limit per test 2 seconds memory li ...

  9. Educational Codeforces Round 65 (Rated for Div. 2)

    A:签到. #include<bits/stdc++.h> using namespace std; #define ll long long #define inf 1000000010 ...

随机推荐

  1. 实验03——java十进制转二、八、十六进制;打印'中'的十六进制;进制转换的api

    package cn.tedu.demo; /** * @author 赵瑞鑫 E-mail:1922250303@qq.com * @version 创建时间:2020年7月16日 上午10:22: ...

  2. 04-Thread的生命周期

    图示: 说明: 1.生命周期关注两个概念:状态.相应的方法 2.关注:状态a-->状态b:哪些方法执行了(回调方法) 某个方法主动调用:状态a-->状态b 3.阻塞:临时状态,不可以作为最 ...

  3. 18 . Go之操作Mysql

    安装mysql wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm yum -y localinstall ...

  4. 关于Exceptionless日志收集框架如何关闭磁盘缓存

    问题:在使用Exceptionless的时候,Exception在收集到日志时会默认在appdata里面缓存当条日志的缓存文件,时间久了之后,如果收集到的日志越多磁盘的空间就会不足. 我使用的环境是 ...

  5. Python画各种 3D 图形Matplotlib库

    回顾 2D 作图 用赛贝尔曲线作 2d 图.此图是用基于 Matplotlib 的 Path 通过赛贝尔曲线实现的,有对赛贝尔曲线感兴趣的朋友们可以去学习学习,在 matplotlib 中,figur ...

  6. 博客主题推荐——复杂&简单

    首先感谢原作者cjunn提供的主题autm,以下配置都基于此主题设定.很多小伙伴喜欢现在的样式,分享如下.只需简单几步即可. 如果你想使用本博客主题样式,并希望能得到远程推送更新,只需查看 快速部署. ...

  7. java数组与数组异常

    一 数组的定义 1.第一种定义方法: 格式: 数据类型[] 数组名=new 数据类型[数组长度] 2.第二种定义方法: 格式: 类型[] 数组名 = new 类型[]{元素,元素,.....} 3.第 ...

  8. importTSV工具导入数据到hbase

    1.建立目标表test,确定好列族信息. create'test','info','address' 2.建立文件编写要导入的数据并上传到hdfs上 touch a.csv vi a.csv 数据内容 ...

  9. Android PopupWindow显示之后所在的Activity结束的时候出现短暂黑屏问题

    在当前Activity弹出PopuoWindow后,点击取消弹窗,然后结束当前Activity时会出现短暂黑屏现象.这是由于设置背景透明度时候造成的. //设置添加屏幕的背景透明度 public vo ...

  10. [转]camera教程

    camera教程 Lens一般由几片透镜组成透镜结构,按材质可分为塑胶透镜(plastic)或玻璃透镜(glass),玻璃镜片比树脂镜片贵.塑胶透镜其实是树脂镜片,透光率和感光性等光学指标比不上镀膜镜 ...