c语言sscanf函数的用法是什么
292
2022-08-28
Educational Codeforces Round 35 (Rated for Div. 2) A B C D
A. Nearest Minimums
time limit per test
memory limit per test
input
output
You are given an array of n integer numbers a0, a1, ..., an - 1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times.
Input
The first line contains positive integer n (2 ≤ n ≤ 105) — size of the given array. The second line contains n integers a0, a1, ..., an - 1 (1 ≤ ai ≤ 109) — elements of the array. It is guaranteed that in the array a minimum occurs at least two times.
Output
Print the only number — distance between two nearest minimums in the array.
Examples
Input
2 3 3
Output
1
Input
3 5 6 5
Output
2
Input
9 2 1 3 5 4 1 2 3 1
Output
3
思路:输入的时候搜一下最小值并记录一下位置,然后再找出最小位置
#include B. Two Cakes time limit per test memory limit per test input output It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into a pieces, and the second one — into b Ivan knows that there will be n people at the celebration (including himself), so Ivan has set n Each piece of each cake is put on some plate;Each plate contains at least one piece of cake;No plate contains pieces of both cakes. To make his guests happy, Ivan wants to distribute the cakes in such a way that the minimum number of pieces on the plate is maximized. Formally, Ivan wants to know the maximum possible number x such that he can distribute the cakes according to the aforementioned conditions, and each plate will contain at least x Help Ivan to calculate this number x! Input The first line contains three integers n, a and b (1 ≤ a, b ≤ 100, 2 ≤ n ≤ a + b) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively. Output Print the maximum possible number x such that Ivan can distribute the cake in such a way that each plate will contain at least x Examples Input 5 2 3 Output 1 Input 4 7 10 Output 3 思路:按题目要求搜索一下 代码: #include C. Three Garlands time limit per test memory limit per test input output Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on. When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if i-th garland is switched on during x-th second, then it is lit only during seconds x, x + ki, x + 2ki, x + 3ki Mishka wants to switch on the garlands in such a way that during each second after switching the garlands on there would be at least one lit garland. Formally, Mishka wants to choose three integers x1, x2 and x3 (not necessarily distinct) so that he will switch on the first garland during x1-th second, the second one — during x2-th second, and the third one — during x3-th second, respectively, and during each second starting from max(x1, x2, x3) Help Mishka by telling him if it is possible to do this! Input The first line contains three integers k1, k2 and k3 (1 ≤ ki ≤ 1500) — time intervals of the garlands. Output If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES. Otherwise, print NO. Examples Input 2 2 3 Output YES Input 4 2 3 Output NO 思路:找规律,一共四种情况 代码: #include D. Inversion Counting time limit per test memory limit per test input output A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j and ai < aj. For example, a permutation [4, 1, 3, 2] contains 4 inversions: (2, 1), (3, 1), (4, 1), (4, 3). You are given a permutation a of size n and m queries to it. Each query is represented by two indices l and r denoting that you have to reverse the segment [l, r] of the permutation. For example, if a = [1, 2, 3, 4] and a query l = 2, r = 4 is applied, then the resulting permutation is [1, 4, 3, 2]. After each query you have to determine whether the number of inversions is odd or even. Input The first line contains one integer n (1 ≤ n ≤ 1500) — the size of the permutation. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ n) — the elements of the permutation. These integers are pairwise distinct. The third line contains one integer m (1 ≤ m ≤ 2·105) — the number of queries to process. Then m lines follow, i-th line containing two integers li, ri (1 ≤ li ≤ ri ≤ n) denoting that i-th query is to reverse a segment [li, ri] Output Print m lines. i-th of them must be equal to odd if the number of inversions in the permutation after i-th query is odd, and even Examples Input 3
1 2 3
2
1 2
2 3 Output odd
even Input 4
1 2 4 3
4
1 1
1 4
1 4
2 3 Output odd
odd
odd
even 思路:先算一下逆序数的个数,然后交换的数的顺序必改变。然后输出即可,刚开始用了树状数组,麻烦了 代码: #include
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~