题目大意: 提供n个对象,分别编号为1,...,n.每个对象都可能是某个编号小于自己的对象的特例或是成分.认为某个对象的特例的特例依旧是该对象的特例,即特例关系传递,同样一个对象的成分的成分依旧是该对象的成分.但是还需要注意一个对象的成分是该对象的所有特例的成分.每个对象都不可能是自己的特例或成分.要求解答之后的q个谜题,每个谜题提问两个对象是否是特例关系或成分关系. 输入级别:n,q<1e5 花了一个晚上才想到思路解了题目... 首先我们要先解决一个简单的问题:对于一株多叉树,如何进行预处理,…
题面传送门 首先肯定将所有物品排个序. 考虑暴力做法,对于每个询问,枚举所有物品,能买就买.不过扫一眼就知道无法直接优化. 不妨换个角度,暴力做法是枚举询问,这次我们枚举物品.从左到右依次枚举所有物品,将所有买得起当前物品的询问答案 \(+1\),钱数减去当前物品的价格.这样就貌似与 DS 能够搭得上边了. 于是题目变为:\(n\) 次操作,每次操作将序列所有值 \(\geq c\) 的数减去 \(c\),问每个数被操作了几次. 可还是不好维护啊,平衡树 split 出 \(\geq c\) 的…
题目:在网格某一处填入一个正整数,使得网格每行,每列以及两条主对角线的和都相等 题目链接:http://codeforces.com/contest/711/problem/B 分析:题目不难,找到要填的那个数填进去,然后循环比较每行每列以及对角线的和是否相等,题目提交上去卡了几次要注意几点 注意:1.答案数据范围$1\leq x \leq 1e18$,要用 long long 2.特殊情况,$n \equiv 1$时,由于一定有要填的数,所以一定有解 3.反正就是要注意看清楚题目和数据边界情况…
http://codeforces.com/problemset/problem/558/C 分析:将每一个数在给定范围内(10^5)可变成的数(*2或者/2)都按照广搜的方式生成访问一遍,标记上访问的步数,之后遍历区间找到被访问次数达到n(所有数都可以变成这个数)并且标记的需要步数最少即可. 注意:当是奇数的时候,例如11(11/2=5 5*2=10),按照这么算(除2后再乘2)回重新得到一个新的数 #include <cstdio> #include <cstring> #in…
题目链接:  http://codeforces.com/contest/335/problem/B 分析: 第一眼看上去串的长度为5*10^4, 冒似只能用O(n)的算法可解. 而这样的算法从来没见过...... 其实不然, 注意一个条件"如果有存在长度为100的回文子串则输出长度为100的,否则输出最长的", 可以发现: 一个长度大于100的回文串都可以变成长度为100的 如: 长度为101的只要删除中间的一个就变为长度为100的, 长度为102的删除中间两个也变为长度为100的.…
500pt, 题目链接:http://codeforces.com/problemset/problem/371/A 分析:k-periodic说明每一段长度为k,整个数组被分成这样长度为k的片段,要使得修改最少,求出k长度的片段中每个位置出现次数最多的数就行. 代码: #include <vector> #include <list> #include <map> #include <set> #include <deque> #include…
Description Two soldiers are playing a game. At the beginning first of them chooses a positive integer n and gives it to the second soldier. Then the second one tries to make maximum possible number of rounds. Each round consists of choosing a positi…
B. Anatoly and Cockroaches time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there tog…
B. Code For 1 time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him t…
C. Alyona and Spreadsheet time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit table…
B. Game of Credit Cards time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and deci…
A. Shell Game time limit per test:0.5 seconds memory limit per test:256 megabytes input:standard input output:standard output Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played b…
A. Oath of the Night's Watch time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands,…
C. Did you mean... time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search…
B. Which floor? time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how…
B. Gleb And Pizza time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on…
A. Kirill And The Game time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characteriz…
A. Theatre Square time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the occasion of the ci…
E. Mother of Dragons time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output There are n castles in the Lannister's Kingdom and some walls connect two castles, no two castles are connected by more…
C. Journey time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other…
B. Game of the Rows time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldiers. She wants to brin…
A. Arya and Bran time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies…
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. Anton and Polyhedrons time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:…
A. Buying A House time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us. The gi…
A. Mike and palindrome time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the s…
A. Vicious Keyboard time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Tonio has a keyboard with only two letters, "V" and "K". One day, he has typed out a string s with only t…
A. Taymyr is calling you time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinis…
A. Fake NP time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.…
A. Cutting Banner time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforcesω that takes place on the Miami…