Limak is a little bear who learns to draw. People usually start with houses, fences and flowers but why would bears do it? Limak lives in the forest and he decides to draw a tree. Recall that tree is a connected graph consisting of n vertices and n -…
E. Bear and Drawing time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Limak is a little bear who learns to draw. People usually start with houses, fences and flowers but why would bears…
Codeforces 385C Bear and Prime Numbers 其实不是多值得记录的一道题,通过快速打素数表,再做前缀和的预处理,使查询的复杂度变为O(1). 但是,我在统计数组中元素出现个数时使用了map,以至于后面做前缀和的累加时,每次都要对map进行查询,以至于TLE.而自己一直没有发现,以为是欧拉筛对于这道题还不够优,于是上网搜题解,发现别人的做法几乎一样,但是却能跑过,挣扎了许久才想起是map的原因.map的内部实现是一颗红黑树,每次查询的复杂度为O(logN),在本来时…
B. Bear and Friendship Condition time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Bear Limak examines a social network. Its main functionality is that two members can become friends (then th…
A. Bear and Big Brother time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak…
C. Bear and Different Names time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communicati…
B. Bear and Friendship Condition time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Bear Limak examines a social network. Its main functionality is that two members can become friends (then th…
A. Bear and Three Balls time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Limak is a little polar bear. He has n balls, the i-th ball has size ti. Limak wants to give one ball to each of his…
题目链接 F. Bear and Fair Set time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Limak is a grizzly bear. He is big and dreadful. You were chilling in the forest when you suddenly met him. It's v…
Recently, the bear started studying data structures and faced the following problem. You are given a sequence of integers x1, x2, ..., xn of length n and m queries, each of them is characterized by two integers li, ri. Let's introduce f(p) to represe…
Bear and Bowling 4 这也能斜率优化... max[ i ] = a[ i ] - a[ j ] - j * (sum[ i ] - sum[ j ])然后就能斜率优化啦, 我咋没想到, 我好菜啊. 斜率优化最重要的是转换成前缀形式, 我TM又忘了. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pa…
Bear and Contribution 对于对于5余数为, 0, 1, 2, 3, 4的分别处理一次, 用优先队列贪心. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int> #define PII pair<in…
Bear and Square Grid 枚举k * k 的位置, 然后接上它周围白色连通块的数量, 再统计完全在k * k范围里的连通块, 这个只要某个连通块全部的方格 在k * k里面就好, 并且k * k是一行一行移的, 所以可以优化到n ^ 3. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<…
385D - Bear and Floodlight 题目大意:有一个人从( l , 0 ) 想走到 ( r , 0 ),有 n 盏路灯,位置为( xi , yi ),每盏路灯都有一个照射的角度ai 这个角度内的区间都被照亮,问你走之前任意调路灯的方向,这个人只能走路灯照亮的地方,问你他最多能往 r 方向走多少距离. 思路:本来我想的是才20盏灯直接枚举灯的顺序也不会超时的吧,复杂度才20!* 20 (ps:我错了我是猪,20!复杂度很高), 结果GG,T掉了,改成状态压缩就过了,状态压缩也跑了…
385C - Bear and Prime Numbers 思路:记录数组中1-1e7中每个数出现的次数,然后用素数筛看哪些能被素数整除,并加到记录该素数的数组中,然后1-1e7求一遍前缀和. 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mem(a,b) memset((a),(b),sizeof(a)) const int INF=0x3f…
A - Bear and Prime 100 思路:任何一个合数都可以写成2个以上质数的乘积.在2-100中,除了4,9,25,49外都可以写成两个以上不同质数的乘积. 所以打一个质数加这四个数的表:{2,3,4,5,7,9,11,13,17,19,23,25,29,31,37,41,43,47,49},询问19次,如果能被整出两次以上,说明是合数,否则是质数. #include<bits/stdc++.h> using namespace std; #define ll long long…
Bear and Three Balls Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Status Description Limak is a little polar bear. He has n balls, the i-th ball has size ti. Limak wants to give one ball to each of his three fr…
Bear and Forgotten Tree 3 time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A tree is a connected undirected graph consisting of n vertices and n - 1 edges. Vertices are numbered 1 through…
一种巧妙到暴力方式,这题到抽象化:在一个无向图中,找一个度数和最小到三阶到圈. 首先对边进行枚举,这样确定了两个顶点,然后在对点进行枚举,找到一个可以构成三元圈到点,则计算他们到度数和. 最后保存最小到度数和到三元圈即可. Bear and Three Musketeers Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Status Description Do you…