C. Money Transfers 题目连接: http://www.codeforces.com/contest/675/problem/C Description There are n banks in the city where Vasya lives, they are located in a circle, such that any two banks are neighbouring if their indices differ by no more than 1. Al…
题目链接: http://www.codeforces.com/contest/675/problem/C 题意: 给一个数组,每个数与他相邻的数相连,第一个与最后一个相连,每个数的数值可以左右移动,问最少的移动次数使所有的数都为零. 题解: 把数组分成若干个部分,每个部分和都为0,每部分最多移动len-1,这样分的越多,得到的结果就越优. #include<iostream> #include<cstdio> #include<cstring> #include<…
题目链接:http://codeforces.com/contest/675/problem/C 给你n个bank,1~n形成一个环,每个bank有一个值,但是保证所有值的和为0.有一个操作是每个相邻的bank之间可以转钱,让你用最少的操作使每个bank的值为0. 一开始没什么思路,看了一下别人的题解,果然还是还是native... 要是让操作次数变少,首先划分和为0的区间个数要尽量多,比如一个区间的长度为k,那么他操作次数为k - 1,所以总的操作次数就是(n - 区间的个数). 那么要算出区…
Problems     # Name     A Infinite Sequence standard input/output 1 s, 256 MB    x3509 B Restoring Painting standard input/output 1 s, 256 MB    x2519 C Money Transfers standard input/output 1 s, 256 MB    x724 D Tree Construction standard input/outp…
数学 A - Infinite Sequence 等差数列,公差是0的时候特判 #include <bits/stdc++.h> typedef long long ll; const int N = 1e5 + 5; int main() { int a, b, c; scanf ("%d%d%d", &a, &b, &c); bool flag = true; if (c == 0) { if (a == b) { flag = true; }…
题目链接: http://www.codeforces.com/contest/675/problem/E 题意: 对于第i个站,它与i+1到a[i]的站有路相连,先在求所有站点i到站点j的最短距离之和(1<=i<j<=n) 题解: 这种所有可能都算一遍就会爆的题目,有可能是可以转化为去求每个数对最后答案的贡献,用一些组合计数的方法一般就可以很快算出来. 这里用dp[i]表示第i个站点到后面的所有站的最短距离之和,明显,i+1到a[i]的站,一步就可以到,对于后面的那些点,贪心一下,一定…
题目链接: http://codeforces.com/contest/675/problem/D 题意: 给你一系列点,叫你构造二叉搜索树,并且按输入顺序输出除根节点以外的所有节点的父亲. 题解: n有10^5,如果直接去建树,最会情况会O(n^2)t掉. 因此我们需要利用一些二叉搜索树的性质: 对于当前输入节点v,找出已经输入的最大的l和最小的r使得l<v<r. 由于输入v之前l和r中间是没有数的,所以l和r必定为祖先和后代的关系,如果不是的话,就会导致l和r中间还有数(l和r的公共祖先)…
题目链接:http://codeforces.com/problemset/problem/675/D 给你一个如题的二叉树,让你求出每个节点的父节点是多少. 用set来存储每个数,遍历到a[i]的时候查找比a[i]大的数的位置,然后插入,而父亲就是刚好比a[i]小的数或刚好大的数. 然后讨论是哪一个数. 比如给你3 1 2 ,如图 1的父亲是3 ,2的父亲是1. 那我其实只要找左边或右边出现最晚的数就行了,用pair的first表示a[i],second表示出现的顺序i. #include <…
http://codeforces.com/contest/675/problem/E 题目大意:有n个车站,每个车站只能买一张票,这张票能从i+1到a[i].定义p[i][j]为从i到j所需要买的最小票数.问sigma(p)的和是多少. 思路:感觉我的dp定义能力还是太弱了啊,我刚开始还定义成dp[i]表示1~i-1到i所需要的最小花费和,后来发现这样子我转移不了啊!! 于是重新定义dp[i]表示从i出发到i+1~n所需要的最小票数,然后这样定义就能很好的解决问题啦.然后我们每次贪心的选取j…
E. Trains and Statistic 题目连接: http://www.codeforces.com/contest/675/problem/E Description Vasya commutes by train every day. There are n train stations in the city, and at the i-th station it's possible to buy only tickets to stations from i + 1 to a…
D. Tree Construction 题目连接: http://www.codeforces.com/contest/675/problem/D Description During the programming classes Vasya was assigned a difficult problem. However, he doesn't know how to code and was unable to find the solution in the Internet, so…
B. Restoring Painting 题目连接: http://www.codeforces.com/contest/675/problem/B Description Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he h…
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/675/problem/A Description Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its first element is equal to a (s1 = a), and the difference between…
Tree Construction Problem's Link ---------------------------------------------------------------------------- Mean: 给定n个数,按照构造Binary Search Tree的方式来构造BST树,按顺序输出每一个非root结点的父节点的值. analyse: 构造BST树最坏情况下时间复杂度为O(n),肯定会超时. 注意到只需要输出结点的父节点的值,不需要真的构造BST树. 插到第i…
Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some facts about it. The painting is a…
Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its first element is equal to a (s1 = a), and the difference between any two neighbouring elements is equal to c (si - si - 1 = c). In particular, Vasya won…
弱到只会写div2的A题... 题面: A. Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its fi…
题意:给你n个数字,第一个点作为根节点,然后每次插入一个节点,构建一棵平衡二叉树,并输出插入节点后该节点的父节点的值 #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <vector> #include <queue> #include <stack> #in…
C. Parity Game 题目连接: http://www.codeforces.com/contest/298/problem/C Description You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes…
B. Strings of Power Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/318/problem/C Description Let us call a pair of integer numbers m-perfect, if at least one number in the pair is greater than or equal to m. Thus, the pair…
B. Long Jumps Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/B Description Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorit…
A. Rational Resistance Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343/problem/A Description Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resista…
D. Directed Roads 题目连接: http://www.codeforces.com/contest/711/problem/D Description ZS the Coder and Chris the Baboon has explored Udayland for quite some time. They realize that it consists of n towns numbered from 1 to n. There are n directed roads…
C. Pythagorean Triples 题目连接: http://www.codeforces.com/contest/707/problem/C Description Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers…
D. Remainders Game 题目连接: http://www.codeforces.com/contest/688/problem/D Description Today Pari and Arya are playing a game called Remainders. Pari chooses two positive integer x and k, and tells Arya k but not x. Arya have to find the value . There…
C. Polycarpus' Dice Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/534/problem/C Description Polycarp has n dice d1, d2, ..., dn. The i-th dice shows numbers from 1 to di. Polycarp rolled all the dice and the sum of number…
http://codeforces.com/contest/731/problem/F 注意到一个事实,如果你要找一段区间中(从小到大的),有多少个数是能整除左端点L的,就是[L, R]这样.那么,很明显,把这个区间分段.分成[L, 2 * L - 1],因为这段区间中,都不大于等于L的两倍,这样就使得这段区间的贡献就是sum_number * L了. 就是中间有多少个数,每个数贡献一个L值.然后到枚举[2 * L, 3 * L - 1]这段区间,贡献的值就是sum_number * (2 *…
题目链接: http://codeforces.com/contest/900/problem/D 题意: 给你 \(x\) 和 \(y\),让你求同时满足这两个条件的序列的个数: \(a_1, a_2, ..., a_n (1 ≤ a_i)\). $ 1.$ $gcd(a_1, a_2, ..., a_n) = x $ $ 2.$ \(\sum_{i=1}^{n}a_i = y\) 题解: 可以发现,当\(y\%x!=0\)时,满足条件的序列不存在.让\(f(t)\)表示满足序列和为的 \(t…
链接: https://codeforces.com/contest/1263/problem/A 题意: You have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are r candies in it, the second pile contains only green candies and there are g ca…
链接: https://codeforces.com/contest/1215/problem/A 题意: The final match of the Berland Football Cup has been held recently. The referee has shown n yellow cards throughout the match. At the beginning of the match there were a1 players in the first team…