Problem description.You are given a tree. If we select 2 distinct nodes uniformly at random, what's the probability that the distance between these 2 nodes is a prime number? InputThe first line contains a number N: the number of nodes in this tree. The following N-1 lines contain pairs a[i] and b[i
Description懒得写背景了,给你一个字符串init,要求你支持两个操作 (1):在当前字符串的后面插入一个字符串 (2):询问字符串s在当前字符串中出现了几次?(作为连续子串) 你必须在线支持这些操作。 Input第一行一个数Q表示操作个数 第二行一个字符串表示初始字符串init 接下来Q行,每行2个字符串Type,Str Type是ADD的话表示在后面插入字符串。 Type是QUERY的话表示询问某字符串在当前字符串中出现了几次。 为了体现在线操作,你需要维护一个变量mask,初始值为0 读入串Str之后,使用这个过程将之解码成真
Problem StatementWe have a grid with H rows and W columns of squares. We will represent the square at the i-th row from the top and j-th column from the left as (i, j). Also, we will define the distance between the squares (i1, j1) and (i2,
题目描述A parade of all elephants is to commence soon at the Byteotian zoo. The zoo employees have encouraged these enormous animals to form a single line, as the manager wills it to be the initial figure of the parade. Unfortunately, the manager himself came to the parade and did not quite like what he
题意翻译描述 掷骰子是一种双人游戏,它的结果是完全随机的。最近它在整个Byteotia变得非常流行。在Byteotia的首都甚至有一个特别的掷骰子业余爱好者俱乐部。俱乐部的老主顾们花时间互相聊天并每隔一阵子就和一个随机选择的对手玩这他们最喜欢的游戏。一天中赢得最多游戏的人会得到“幸运者”头衔。有时晚上俱乐部很安静,只有很少的比赛。这是哪怕赢一场也能获得“幸运者”头衔的时间。 很久很久以前有一个很不走运的人,叫Byteasar,赢得了这个光荣的头衔。他被深深地震惊了以至于完全忘了他已经赢了多少场。现在他想知道他有多幸运,以及幸运之神是否最终会向他微笑——也许他的运气会变好?他确切地知道在那个幸运
印尼首都雅加达市有 N" data-mce-tabindex="0">N 座摩天楼,它们排列成一条直线,我们从左到右依次将它们编号为 0" data-mce-tabindex="0">0 到 N−1" data-mce-tabindex="0">N−1。除了这 N" data-mce-tabindex="0">N 座摩天楼外,雅加达市没有其他摩天楼。 有 M" data-mce-tabindex="0">M 只叫做 “doge” 的神秘生物在雅加达市居住
Problem StatementTaichi thinks a binary string X of odd length N is beautiful if it is possible to apply the following operation N−12 times so that the only character of the resulting string is 1 : Choose three consecutive&n
Problem StatementSnuke has a rooted tree with N vertices, numbered 1 through N. Vertex 1 is the root of the tree, and the parent of Vertex i ( 2≤i≤N ) is Vertex Pi ( Pi<i ). There is a number, 0 or 1, writte
Problem Description You may not know this but it's a fact that Xinghai Square is Asia's largest city square. It is located in Dalian and, of course, a landmark of the city. It's an ideal place for outing any time of the year. And now: There are N children from a near
【题目描述】给定一个有n个元素的序列,元素编号为1~n,每个元素有三个属性a,b,c,求序列中满足i<j且ai<aj且bi<bj且ci<cj的数对(i,j)的个数。 【输入格式】第一行一个整数n,表示序列长度。 第二行n个整数,分别表示a1~an。 第三行n个整数,分别表示b1~bn。 第四行n个整数,分别表示c1~cn。 【输出格式】一个整数,表示答案。 【样例输入】5
1 5 3 4 2
2 5 3 4 1
1 2 5 3 4【样例输出】3【样例解释】满足条件的(i,j)共有以下三对: (1,2) (1,3) (1,4) 【数据范围与约定】对于30%的数据,n<