Educational Codeforces Round 35 (Rated for Div. 2)A,B,C,D
2 seconds
256 megabytes
standard input
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.
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.
Print the only number — distance between two nearest minimums in the array.
2
3 3
1
3
5 6 5
2
9
2 1 3 5 4 1 2 3 1
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;
}
1 second
256 megabytes
standard input
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:
- 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 pieces of cake.
Help Ivan to calculate this number x!
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.
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.
5 2 3
1
4 7 10
3
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;
}
2 seconds
256 megabytes
standard input
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 x, x + ki, x + 2ki, x + 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!
The first line contains three integers k1, k2 and k3 (1 ≤ ki ≤ 1500) — time intervals of the garlands.
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.
2 2 3
YES
4 2 3
NO
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;
}
2 seconds
256 megabytes
standard input
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.
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] of the permutation. All queries are performed one after another.
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.
3
1 2 3
2
1 2
2 3
odd
even
4
1 2 4 3
4
1 1
1 4
1 4
2 3
odd
odd
odd
even
The first example:
- after the first query a = [2, 1, 3], inversion: (2, 1);
- after the second query a = [2, 3, 1], inversions: (3, 1), (3, 2).
The second example:
- a = [1, 2, 4, 3], inversion: (4, 3);
- a = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3);
- a = [1, 2, 4, 3], inversion: (4, 3);
- 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的更多相关文章
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
- Educational Codeforces Round 72 (Rated for Div. 2)-D. Coloring Edges-拓扑排序
Educational Codeforces Round 72 (Rated for Div. 2)-D. Coloring Edges-拓扑排序 [Problem Description] 给你 ...
- 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 ...
- 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 ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- 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 ...
- 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 ...
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
- 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 < ...
随机推荐
- CAN设计与应用指南
CAN设计与应用指南 0.前言 这是我为公司写的一个关于CAN总线的入门文章,对全面理解CAN总线特性很有帮助,拿出来分享给大家. 1. 简介 CAN总线由德国BOSCH公司开发,最高速率可达到1Mb ...
- 查看历史命令 history
生产上有文件被清空了,想查查是谁操作的? 通过history查看历史命令: $history |more 也可以通过文件查看历史命令: $vi ~/.bash_history 只显示历史命令,像查一查 ...
- Flutter - 添加从左向右滑动,返回上一个页面
很多App比如微信.IT之家等都支持从屏幕左侧向右滑动,来返回上一个页面. 很多iOS上的App也都支持. 那么这个神奇的手势滑动是怎么实现的呢? 其实非常简单,只需要添加一句话即可. platfor ...
- 20155317王新玮《网络对抗技术》实验9 web安全基础实践
20155317王新玮<网络对抗技术>实验9 web安全基础实践 一.实验准备 1.0 实验目标和内容 Web前端HTML.能正常安装.启停Apache.理解HTML,理解表单,理解GET ...
- 记一次SpringMVC碰到的坑
在SpringMVC中,我们Controller中接收比如表单的参数,只要保证方法的形参的名字和表单中input元素的的name一样就可以接收到参数. 但是,我开发的一 ...
- Promise 执行顺序
加深印象 setTimeout(function() { console.log("timeout-start"); }, 200) // 改为100呢 console.log(& ...
- 如何写论文的introduction
重要的是写Introduction.写Introduction就和写童话一样.(转自知乎珵cici) 1. 有一条巨龙抓走了公主 (介绍你的问题为什么值得研究) 2. 巨龙是多么多么多么难打(强调你的 ...
- Jmeter(十八)_Ubuntu部署jmeter与ant
Docker部署接口自动化持续集成环境第三步,容器化Jmeter与ant! 接上文:Docker_容器化jenkins 为了整合接口自动化的持续集成工具,我将jmeter与ant都部署在了Jenkin ...
- Jq_select的操作
jQuery获取Select选择的Text和Value: 语法解释: $("#select_id").change(function(){//code...}); //为Selec ...
- BUGKU--刷题
刷题 一.BUGKU WEB 1. 变量1 知识点php两个$$是 可变变量,就是一个变量的变量名可以动态的设置和使用 $GLOBALS一个包含了全部变量的全局组合数组.变量的名字就是数组的键 < ...