想了解EducationalCodeforcesRound60(RatedforDiv.2)D.MagicGems的新动态吗?本文将为您提供详细的信息,此外,我们还将为您介绍关于Educational
想了解Educational Codeforces Round 60 (Rated for Div. 2) D. Magic Gems的新动态吗?本文将为您提供详细的信息,此外,我们还将为您介绍关于Educational Codeforces Round 33 (Rated for Div. 2)、Educational Codeforces Round 35 (Rated for Div. 2) A-D、Educational Codeforces Round 35 (Rated for Div. 2)A,B,C,D、Educational Codeforces Round 36 (Rated for Div. 2) A-C的新知识。
本文目录一览:- Educational Codeforces Round 60 (Rated for Div. 2) D. Magic Gems
- Educational Codeforces Round 33 (Rated for Div. 2)
- Educational Codeforces Round 35 (Rated for Div. 2) A-D
- Educational Codeforces Round 35 (Rated for Div. 2)A,B,C,D
- Educational Codeforces Round 36 (Rated for Div. 2) A-C
Educational Codeforces Round 60 (Rated for Div. 2) D. Magic Gems
time limit per test3 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Reziba has many magic gems. Each magic gem can be split into
M
M
normal gems. The amount of space each magic (and normal) gem takes is
1
1
unit. A normal gem cannot be split.
Reziba wants to choose a set of magic gems and split some of them,so the total space occupied by the resulting set of gems is
N
N
units. If a magic gem is chosen and split,it takes
M
M
units of space (since it is split into
M
M
gems); if a magic gem is not split,it takes
1
1
unit.
How many different configurations of the resulting set of gems can Reziba have,such that the total amount of space taken is
N
N
units? Print the answer modulo
1000000007
1000000007
(
10
9
+7
109+7
). Two configurations are considered different if the number of magic gems Reziba takes to form them differs,or the indices of gems Reziba has to split differ.
Input
The input contains a single line consisting of
2
2
integers
N
N
and
M
M
(
1≤N≤
10
18
1≤N≤1018
,
2≤M≤100
2≤M≤100
).
Output
Print one integer,the total number of configurations of the resulting set of gems,given that the total amount of space taken is
N
N
units. Print the answer modulo
1000000007
1000000007
(
10
9
+7
109+7
).
Examples
Input
copy
4 2
Output
copy
5
Input
copy
3 2
Output
copy
3
Note
In the first example each magic gem can split into
2
2
normal gems,and we kNow that the total amount of gems are
4
4
.
Let
1
1
denote a magic gem,and
0
0
denote a normal gem.
The total configurations you can have is:
1111
1111
(None of the gems split);
0011
0011
(First magic gem splits into
2
2
normal gems);
1001
1001
(Second magic gem splits into
2
2
normal gems);
1100
1100
(Third magic gem splits into
2
2
normal gems);
0000
0000
(First and second magic gems split into total
4
4
normal gems).
Hence,answer is
5
5
.
题解:有一些魔法宝石,魔法宝石可以分成m个普通宝石,每个宝石(包括魔法宝石)占用1个空间,让你求占用n个空间的方法有几种,有不同数量的魔法宝石和不同分法的方法算不同的方法,
根据样例可得递推式:f[n]=f[n-1]+f[n-m],最后一个不分加上最后一个分.
因为n比较大,可以用矩阵快速幂来求,这里当n<m,只有一种方法,n==m时有2种方法.
#include <bits/stdc++.h> const int MOD=1e9+7; const int M=105; using namespace std; typedef long long ll; struct matrix{ ll m[M][M]; }ans,res; matrix mul(matrix a,matrix b,int n){ matrix tmp; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) tmp.m[i][j]=0; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) for(int k=1;k<=n;k++){ tmp.m[i][j]+=a.m[i][k]*b.m[k][j]; tmp.m[i][j]%=MOD; } return tmp; } void quickpower(ll n,int m){ for(int i=1;i<=m;i++){ res.m[i+1][i]=1; for(int j=1;j<=m;j++){ if(i==j) ans.m[i][j]=1; else ans.m[i][j]=0; } } res.m[1][m]=1;res.m[m][m]=1; while(n){ if(n&1){ ans=mul(ans,res,m); } res=mul(res,m); n>>=1; } } int main(){ ll n; int m; scanf("%I64d%d",&n,&m); if(n<m){ printf("1\n"); return 0; } matrix a; for(int i=1;i<m;i++) a.m[1][i]=1; a.m[1][m]=2; quickpower(n-m,m); a=mul(a,ans,m); printf("%I64d\n",a.m[1][m]); //cout << "Hello World!" << endl; return 0; }
Educational Codeforces Round 33 (Rated for Div. 2)
总结
以上是小编为你收集整理的Educational Codeforces Round 33 (Rated for Div. 2)全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
Educational Codeforces Round 35 (Rated for Div. 2) A-D
总结
以上是小编为你收集整理的Educational Codeforces Round 35 (Rated for Div. 2) A-D全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
Educational Codeforces Round 35 (Rated for Div. 2)A,B,C,D
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 = 1100000002,a[200000];
cin>>n;
for(int i = 0;i < n;i ++){
cin>>a[i];
minn = min(minn , a[i]);
}
int flag = 0;
int maxx = 1100000002,ans=1;
for(int i = 0;i < n;i ++){
if(a[i] == minn){
if(flag)
maxx = min(ans,maxx);
flag = 1;
ans = 1;
}
else ans++;
}
cout<<maxx<<endl;
}
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 = 0;
for(int i = 1;i <= n-1;i++){
ans = max(ans,min(a/i,b/(n-i)));
}
cout<<ans<<endl;
}
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 = 2; i * i <= n; ++i) {
if (n % i == 0) return 0;
}
return 1;
}
int main()
{
int a[5];
double ans = 0;
for(int i = 0;i < 3;i ++)
cin>>a[i];
sort(a,a+3);
for(int i = 2;i <= 1500;i++){
if(isPrime(i)){
ans = 0;
for(int j = 0;j < 3;j ++){
if(a[j]==1){
cout<<"YES"<<endl; return 0;
}
if(a[j]%i==0){
ans += 1.0/a[j];
}
if(ans == 1){
cout<<"YES"<<endl;return 0;}
}
}
}
cout<<"NO"<<endl;
}
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+100;
int a[M],t[M];
void merge_sort(int x, int y, int & ans){
if(y-x>1){
int m = x+(y-x)/2;
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 = 0;i < n; i++){
cin>>a[i];
}
int ans = 0;
merge_sort(0,n,ans);
if(ans % 2 == 0)
ans = 0;
else
ans = 1;
cin>>q;
while(q--){
cin>>l>>r;
int len = r - l + 1;
len/=2;
if(len % 2 == 0){
if(ans == 0) cout<<"even"<<endl;
else cout<<"odd"<<endl;
}
else{
if(ans == 0){ ans = 1; cout<<"odd"<<endl;}
else{ ans = 0; cout<<"even"<<endl;}
}
}
return 0;
}
Educational Codeforces Round 36 (Rated for Div. 2) A-C
总结
以上是小编为你收集整理的Educational Codeforces Round 36 (Rated for Div. 2) A-C全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
关于Educational Codeforces Round 60 (Rated for Div. 2) D. Magic Gems的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于Educational Codeforces Round 33 (Rated for Div. 2)、Educational Codeforces Round 35 (Rated for Div. 2) A-D、Educational Codeforces Round 35 (Rated for Div. 2)A,B,C,D、Educational Codeforces Round 36 (Rated for Div. 2) A-C的相关知识,请在本站寻找。
本文标签: