随笔分类 - 优化技巧
摘要:2957: 楼房重建 Description 小A的楼房外有一大片施工工地,工地上有N栋待建的楼房。每天,这片工地上的房子拆了又建、建了又拆。他经常无聊地看着窗外发呆,数自己能够看到多少栋房子。 为了简化问题,我们考虑这些事件发生在一个二维平面上。小A在平面上(0,0)点的位置,第i栋楼房可以用一条
阅读全文
摘要:4883: [Lydsy1705月赛]棋盘上的守卫 Description 在一个n*m的棋盘上要放置若干个守卫。对于n行来说,每行必须恰好放置一个横向守卫;同理对于m列来说,每列 必须恰好放置一个纵向守卫。每个位置放置守卫的代价是不一样的,且每个位置最多只能放置一个守卫,一个守卫 不能同时兼顾行列
阅读全文
摘要:题意:给定A,B长度相同的字符串,Q次操作,修改操作位单个字符修改,查询操作为询问从某点开始有多少连续相同的字符。 思路:我们把不相同的设为1,相同的设为0,那么询问就是找下一个为1的为位置,可以用线段树解决,可以用set的lower_bound解决,这里用bitset的Find_next函数,效率
阅读全文
摘要:Collecting one's own plants for use as herbal medicines is perhaps one of the most self-empowering things a person can do, as it implies that they hav
阅读全文
摘要:题意:给出,三个函数,h,b,a,然后T次询问,每次给出n,求sqrt(an); 思路:不会推,但是感觉a应该是线性的,这个时候我们就可以用BM线性递推,自己求出前几项,然后放到模板里,就可以求了。 数据范围在1e15,1000组都可以秒过。 ( 那么主要的问题就是得确保是线性的,而且得求出前几项。
阅读全文
摘要:Yellowstar likes integers so much that he listed all positive integers in ascending order,but he hates those numbers which can be written as a^b (a, b
阅读全文
摘要:There are n numbers 3^0, 3^1, . . . , 3^n-1. Each time you can choose a subset of them (may be empty), and then add them up. Count how many numbers ca
阅读全文
摘要:There is a tree having N vertices. In the tree there are K monkeys (K <= N). A vertex can be occupied by at most one monkey. They want to remove some
阅读全文
摘要:Give an array A, the index starts from 1. Now we want to know B i =max i∤j A j Bi=maxi∤jAj , i≥2 i≥2 . InputThe first line of the input gives the numb
阅读全文
摘要:Little Ruins is playing a number game, first he chooses two positive integers yy and KK and calculates f(y,K)f(y,K), here f(y,K)=∑z in every digits of
阅读全文
摘要:有M个球,一开始每个球均有一个初始标号,标号范围为1~N且为整数,标号为i的球有ai个,并保证Σai = M。 每次操作等概率取出一个球(即取出每个球的概率均为1/M),若这个球标号为k(k < N),则将它重新标号为k + 1;若这个球标号为N,则将其重标号为1。(取出球后并不将其丢弃) 现在你需
阅读全文
摘要:A cellular automaton is a collection of cells on a grid of specified shape that evolves through a number of discrete time steps according to a set of
阅读全文
摘要:One day Natalia was walking in the woods when she met a little mushroom gnome. The gnome told her the following story: Everybody knows that the mushro
阅读全文
摘要:Little Artem has invented a time machine! He could go anywhere in time, but all his thoughts of course are with computer science. He wants to apply th
阅读全文
摘要:Factorial numbers are getting big very soon, you'll have to compute the number of divisors of such highly composite numbers. Input The first line cont
阅读全文
摘要:You are given N(1<=N<=100000) integers. Each integer is square free(meaning it has no divisor which is a square number except 1) and all the prime fac
阅读全文
摘要:We already know of the large corporation where Polycarpus works as a system administrator. The computer network there consists of n computers and m ca
阅读全文
摘要:Mad scientist Mike has constructed a rooted tree, which consists of n vertices. Each vertex is a reservoir which can be either empty or filled with wa
阅读全文
摘要:描述 给定N个正整数A1, A2, ... AN。 小Hi希望你能从中选出M个整数,使得它们的乘积末尾有最多的0。 输入 第一行包含两个个整数N和M。 第二行包含N个整数A1, A2, ... AN。 对于30%的数据,1 ≤ M ≤ N ≤ 12 对于100%的数据,1 ≤ M ≤ N ≤ 100
阅读全文
摘要:Recently in school Alina has learned what are the persistent data structures: they are data structures that always preserves the previous version of i
阅读全文