A. Nearest Minimums
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard 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<bits/stdc++.h>
using namespace std;
int main()
{
int n,minn = ,a[];
cin>>n;
for(int i = ;i < n;i ++){
cin>>a[i];
minn = min(minn , a[i]);
}
int flag = ;
int maxx = ,ans=;
for(int i = ;i < n;i ++){
if(a[i] == minn){
if(flag)
maxx = min(ans,maxx);
flag = ;
ans = ;
}
else ans++;
}
cout<<maxx<<endl;
}
B. Two Cakes
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard 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 pieces.

Ivan knows that there will be n people at the celebration (including himself), so Ivan has set n plates for the cakes. Now he is thinking about how to distribute the cakes between the plates. Ivan wants to do it in such a way that all following conditions are met:

  1. Each piece of each cake is put on some plate;
  2. Each plate contains at least one piece of cake;
  3. 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 pieces of cake.

Help Ivan to calculate this number x!

Input

The first line contains three integers na 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 pieces of cake.

Examples
input
5 2 3
output
1
input
4 7 10
output
3
Note

In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it.

In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3.

思路:

水题

实现代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,a,b;
cin>>n>>a>>b;
int ans = ;
for(int i = ;i <= n-;i++){
ans = max(ans,min(a/i,b/(n-i)));
}
cout<<ans<<endl;
}
C. Three Garlands
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard 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 xx + kix + 2kix + 3ki and so on.

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) at least one garland will be lit.

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
Note

In the first example Mishka can choose x1 = 1, x2 = 2, x3 = 1. The first garland will be lit during seconds 1, 3, 5, 7, ..., the second — 2, 4, 6, 8, ..., which already cover all the seconds after the 2-nd one. It doesn't even matter what x3 is chosen. Our choice will lead third to be lit during seconds 1, 4, 7, 10, ..., though.

In the second example there is no way to choose such moments of time, there always be some seconds when no garland is lit.

思路:

1 = 1/2 + 1/2 ,1 = 1/2+1/4+1/4,差不多就这意思

实现代码:

#include<bits/stdc++.h>
using namespace std;
int isPrime(int n) {
int i;
for (i = ; i * i <= n; ++i) {
if (n % i == ) return ;
}
return ;
}
int main()
{
int a[];
double ans = ;
for(int i = ;i < ;i ++)
cin>>a[i];
sort(a,a+);
for(int i = ;i <= ;i++){
if(isPrime(i)){
ans = ;
for(int j = ;j < ;j ++){
if(a[j]==){
cout<<"YES"<<endl; return ;
}
if(a[j]%i==){
ans += 1.0/a[j];
}
if(ans == ){
cout<<"YES"<<endl;return ;}
}
}
}
cout<<"NO"<<endl;
}
D. Inversion Counting
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard 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 liri (1 ≤ li ≤ ri ≤ n) denoting that i-th query is to reverse a segment [li, ri] of the permutation. All queries are performed one after another.

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 otherwise.

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
Note

The first example:

  1. after the first query a = [2, 1, 3], inversion: (2, 1);
  2. after the second query a = [2, 3, 1], inversions: (3, 1), (3, 2).

The second example:

  1. a = [1, 2, 4, 3], inversion: (4, 3);
  2. a = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3);
  3. a = [1, 2, 4, 3], inversion: (4, 3);
  4. a = [1, 4, 2, 3], inversions: (3, 2), (4, 2).

思路:和l,r的值没关系,只和他们之间的距离有关系

实现代码:

#include<bits/stdc++.h>
using namespace std;
const int M = 2e5+;
int a[M],t[M];
void merge_sort(int x, int y, int & ans){
if(y-x>){
int m = x+(y-x)/;
int p=x, q=m, i=x;
merge_sort(x, m, ans);
merge_sort(m ,y, ans);
while(p<m || q<y){
if(q>=y || p<m && a[p]<=a[q]){
t[i++] = a[p++];
}
else{
t[i++] = a[q++];
ans += m-p;
}
}
for(int j=x; j<y; j++){
a[j] = t[j];
}
}
} int main(){
int n,q,l,r;
cin>>n;
for(int i = ;i < n; i++){
cin>>a[i];
}
int ans = ;
merge_sort(,n,ans);
if(ans % == )
ans = ;
else
ans = ;
cin>>q;
while(q--){
cin>>l>>r;
int len = r - l + ;
len/=;
if(len % == ){
if(ans == ) cout<<"even"<<endl;
else cout<<"odd"<<endl;
}
else{
if(ans == ){ ans = ; cout<<"odd"<<endl;}
else{ ans = ; cout<<"even"<<endl;}
}
}
return ;
}

Educational Codeforces Round 35 (Rated for Div. 2)A,B,C,D的更多相关文章

  1. Educational Codeforces Round 35 (Rated for Div. 2)

    Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...

  2. Educational Codeforces Round 72 (Rated for Div. 2)-D. Coloring Edges-拓扑排序

    Educational Codeforces Round 72 (Rated for Div. 2)-D. Coloring Edges-拓扑排序 [Problem Description] ​ 给你 ...

  3. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  4. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

  5. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

  6. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  7. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...

  8. Educational Codeforces Round 63 (Rated for Div. 2) 题解

    Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...

  9. Educational Codeforces Round 39 (Rated for Div. 2) G

    Educational Codeforces Round 39 (Rated for Div. 2) G 题意: 给一个序列\(a_i(1 <= a_i <= 10^{9}),2 < ...

随机推荐

  1. C# 取两个集合的交集\并集\差集

    交集:Intersect 并集:Union 差集:Except , , , , , }; , , , ,,, }; var C= A.Intersect(B); //交集 { 3, 4, 5, 6 } ...

  2. 一个struts2程序

    1.index.jsp 2.struts.xml 3.Loginaction.java package action; import java.io.File; import java.io.File ...

  3. excel的宏与VBA入门(二)——数据类型与变量

    一.属性与方法 1.属性 上面单击对象,下面即显示对应的属性: 2.方法 双击左上的对象,即可看到相应的方法: 二.数据类型 到 Boolean True 或 False , 到 , ,,, 到 ,, ...

  4. vb用createprocess启动其他应用程序

    Option Explicit Private Type PROCESS_INFORMATION hProcess As Long hThread As Long dwProcessId As Lon ...

  5. 20155216 Exp8 WEB基础实践

    Exp8 WEB基础实践 实践内容 Apache环境配置 apache是kali下的web服务器,通过访问 ip地址+端口号+文件名称 打开对应的网页. 输入命令 vi /etc/apache2/po ...

  6. CS229笔记:分类与逻辑回归

    逻辑回归 对于一个二分类(binary classification)问题,\(y \in \left\{0, 1\right\}\),如果直接用线性回归去预测,结果显然是非常不准确的,所以我们采用一 ...

  7. libgdx学习记录19——图片动态打包PixmapPacker

    libgdx中,opengl 1.x要求图片长宽必须为2的整次幂,一般有如下解决方法 1. 将opengl 1.x改为opengl 2.0.(libgdx 1.0版本后不支持1.x,当然不存在这个问题 ...

  8. Vue.js动态组件

    动态组件: 1.定义: 几个组件放在同一个挂载点下,然后根据父组件的某个变量来决定显示哪个,或者都不显示. 2.动态切换原理: 在挂载点使用<component>标签,然后使用v-bind ...

  9. C# Language Specification 5.0 (翻译)第六章 转换

    转换使表达式可以当做一个明确的类型来加以处理.转换使得所给定类型的表达式以不同类型来处理,或使得没有某个类型的表达式获得该类型.转换可以是显式或隐式的,而这决定了是否需要显式地强制转换.比方说,从类型 ...

  10. [转载]windows下PHP + Nginx curl访问本地地址超时卡死问题的解决方案

    原因: windows 下 nginx+php环境,不支持并发. 解决方案: 1.在配置nginx vhost时,需要同时运行的网站设置不同的fastcgi_pass的端口号 server { ser ...