The scientists working at the Family Genetics Institute are tracing the spread of a hereditary disease through family trees. They have started by listing the family members that have the disease,
大体思路:
用pos数组来记录每个数出现的最后的位置
然后遍历每一个数组元素,如果当前元素已经被标记过了(已经被使用),那么就跳过这次循环
设遍历数组元素的时候,将这个数组的下标记为 i ,值的大小为 x
当栈里面有元素,并且栈顶的元素大于x,并且栈顶这个数最后出现的位置大于当前这个数最后出现的位置 i ,那么说明栈里面这一数列就不是最优的,就可以将当前的元素x替换掉栈顶元素,先pop(),然后将这个数标记为 0 ,–>未使用
如果当上述条件一直满足的时候,可以一直进行上面的操作
知道不满足题意,然后讲当前这个数放到栈的顶端
题目描述
In a 10-dollar shop, everything is worthy 10 dollars or less. In order to serve customers more effectively at the cashier, change needs to be provided in the minimum number of coins.
In this problem, you are going to provide a given value of the change in different coins.
已知:
gcd(a,b) = n
lcm(a,b) = m
求min(a,b)是多少
通过gcd的了解我们可以知道,两个数a == k1 * n以及b == k2 * n并且gcd(k1,k2) == 1
ab == n * m
m == a * b/n
ab == k1 * k2 * n * n
于是可以得到 m == k1 * k2 * n
将n除到左边,可以得出m/n == k1 * k2
于是k1 和 k2 都是 m / n的因子
这样就可以以根号的复杂度找出这两个因子,并判断k1 和 k2 是否是互质的
a + b == (k1 + k2 ) * n
所以说代码:
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are given an array a consisting of n integers. In one move, you can jump from the position i to the position i−ai (if 1≤i−ai) or to the position i+ai (if i+ai≤n).
You are asked to watch your nephew who likes to play with toy blocks in a strange way.
He has n boxes and the i-th box has ai blocks. His game consists of two steps:
he chooses an arbitrary box i;
he tries to move all blocks from the i-th box to other boxes.
Eggfruit Cake
时间限制: 1 Sec 内存限制: 128 MB
题目描述
Today is Jaime’s birthday and, to celebrate, his friends ordered a cake decorated with eggfruits and persimmons. When the cake arrived, to their surprise, they noticed that the bakery didn’t use equal amounts of eggfruits and persimmons,
Game on a Tree
时间限制: 1 Sec 内存限制: 1024 MB
题目描述
Alice and Bob play a game on a tree. Initially, all nodes are white.
Alice is the first to move. She chooses any node and put a chip on it. The node becomes black. After that players take turns.
题目描述
Our world has been invaded by shapeshifting aliens that kidnap people and steal their identities.You are an inspector from a task force dedicated to detect and capture them. As such, you were given special tools to detect aliens and differentiate them from real humans.
BerPhone X is almost ready for release with n applications being preinstalled on the phone. A category of an application characterizes a genre or a theme of this application (like “game”, “business”, or “education”). The categories are given as integers between 1 and n, inclusive;
You are given a tree consisting exactly of n vertices. Tree is a connected undirected graph with n−1 edges. Each vertex v of this tree has a value av assigned to it.
Let dist(x,y) be the distance between the vertices x and y.
Lucy likes letters. She studied the definition of the lexicographical order at school and plays with it.
At first, she tried to construct the lexicographically smallest word out of given letters. It was so easy! Then she tried to build multiple words and minimize one of them. This was much harder!
Description
Elves are very peculiar creatures. As we all know, they can live for a very long time and their magical prowess are not something to be taken lightly. Also, they live on trees. However, there is something about them you may not know. Although delivering stuffs through magical
题目描述
Alice and Bob decide to share a chocolate bar, which is an n by m rectangular grid of chocolate cells. They decide that Alice should get a < n·m pieces and that Bob should get b = n·m − a pieces. To split the chocolate bar, they repeatedly take a single piece of chocolate and break it either
问题 D: Eeny Meeny
时间限制: 2 Sec 内存限制: 128 MB
题目描述
“Eeny meeny miny moe” is a well-known nursery rhyme in English, used (among other things) by kids to “randomly” select members of a team. It exists in many variations, one of which goes like this:
Eeny, meeny, miny, moe,
Catch a tiger by the toe.
题目描述
When Mr. B, Mr. G and Mr. M were preparing for the 2012 ACM-ICPC World Final Contest, Mr. B had collected a large set of contest problems for their daily training. When they decided to take training, Mr. B would choose one of them from the problem set.
问题 J:Contest Print Server
时间限制: 1 Sec 内存限制: 128 MB
题目描述
In ACM/ICPC on-site contests ,3 students share 1 computer,so you can print your source code any time. Here you need to write a contest print server to handle all the requests.