2019.4.30 WAGV CF Team replay

前言
4月30号的2小时CF重现赛,基本都是DIV2的水题,目标是训练CF题目的题感来上分,主要是读英文题有困难,对题意理解困难…
比赛地址:https://cn.vjudge.net/contest/298841#status/499170967/H/0/
密码:wagv18
(CF的题复制过来根本没法读…没办法了,要看题目只能去原网址查看,以下有原网址)

A
Codeforces 1139B Chocolates
You went to the store, selling
n
n
types of chocolates. There are
a
i
ai
chocolates of type
i
i
in stock.
You have unlimited amount of cash (so you are not restricted by any prices) and want to buy as many chocolates as possible. However if you buy
x
i
xi
chocolates of type
i
i
(clearly,
0≤
x
i

a
i
0≤xi≤ai
), then for all
1≤j<i
1≤j<i
at least one of the following must hold:
x
j
=0
xj=0
(you bought zero chocolates of type
j
j
)
x
j
<
x
i
xj<xi
(you bought less chocolates of type
j
j
than of type
i
i
)
For example, the array
x=[0,0,1,2,10]
x=[0,0,1,2,10]
satisfies the requirement above (assuming that all
a
i

x
i
ai≥xi
), while arrays
x=[0,1,0]
x=[0,1,0]
,
x=[5,5]
x=[5,5]
and
x=[3,2]
x=[3,2]
don’t.
Calculate the maximum number of chocolates you can buy.
Input
The first line contains an integer
n
n
(
1≤n≤2⋅
10
5
1≤n≤2⋅105
), denoting the number of types of chocolate.
The next line contains
n
n
integers
a
i
ai
(
1≤
a
i

10
9
1≤ai≤109
), denoting the number of chocolates of each type.
Output
Print the maximum number of chocolates you can buy.
Examples
Input
Copy
5
1 2 1 3 6
Output
Copy
10
Input
Copy
5
3 2 5 4 10
Output
Copy
20
Input
Copy
4
1 1 1 1
Output
Copy
1
Note
In the first example, it is optimal to buy:
0+0+1+3+6
0+0+1+3+6
chocolates.
In the second example, it is optimal to buy:
1+2+3+4+10
1+2+3+4+10
chocolates.
In the third example, it is optimal to buy:
0+0+0+1
0+0+0+1
chocolates.
问题链接: http://codeforces.com/problemset/problem/1139/B
问题简述: 给定一个n长度的序列,每次买巧克力只能比前一次买巧克力的个数多,求最多能买多少个巧克力
问题分析: 贪心水过。从数组最后一个数据开始判断,如果上一个购买的个数比这个数数的还要小,就让ans加上这个值,如果大于等于这个数,就买这个数减一的巧克力数。
AC通过的C++语言程序如下:

#include <algorithm>
#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <climits>
#include <iomanip>
#include <queue>
#include <map>
#include<vector>
#define ll long long
using namespace std;

ll a[1000000];

int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    ll ans=0;
    ll minn=999999999999;
    for(int i=n;i>0;i--)
    {
        if(minn-1<a[i])
            minn=minn-1>0?minn-1:0;
        else minn=a[i];
        ans+=minn;
    }
    cout<<ans;
    return 0;
}

B
CodeForces - 1140A Detective Book

Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The
i
i
-th page contains some mystery that will be explained on page
a
i
ai
(
a
i
≥i
ai≥i
).
Ivan wants to read the whole book. Each day, he reads the first page he didn’t read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page
i
i
such that Ivan already has read it, but hasn’t read page
a
i
ai
). After that, he closes the book and continues to read it on the following day from the next page.
How many days will it take to read the whole book?
Input
The first line contains single integer
n
n
(
1≤n≤
10
4
1≤n≤104
) — the number of pages in the book.
The second line contains
n
n
integers
a
1
,
a
2
,…,
a
n
a1,a2,…,an
(
i≤
a
i
≤n
i≤ai≤n
), where
a
i
ai
is the number of page which contains the explanation of the mystery on page
i
i
.
Output
Print one integer — the number of days it will take to read the whole book.
Example
Input
Copy
9
1 3 3 6 7 6 8 8 9
Output
Copy
4
Note
Explanation of the example test:
During the first day Ivan will read only the first page. During the second day Ivan will read pages number
2
2
and
3
3
. During the third day — pages
4
4

8
8
. During the fourth (and the last) day Ivan will read remaining page number
9
9
.
问题链接: http://codeforces.com/problemset/problem/1140/A
问题简述: 给定一个n的数列An,每天一定要读到第Ai页才能停下来,问多少天能读完
问题分析: 模拟水过,每天找到最大的页数,跳到那一天,累加天数,到终止条件退出即可。
AC通过的C++语言程序如下:

#include <algorithm>
#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <climits>
#include <iomanip>
#include <queue>
#include <map>
#include<vector>
#define ll long long
using namespace std;

int page[10000];

int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>page[i];
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        ans++;
        int maxx=page[i];
        int flag=0;
        for(int j=i;j<=maxx;j++)
        {
            if(j==n)
            {
                flag=1;
                break;
            }
            maxx=max(maxx,page[j]);
        }
        i=maxx;
        if(flag==1)
            break;
    }
    cout<<ans;
    return 0;
}

E
CodeForces - 1141A Game 23
Polycarp plays “Game 23”. Initially he has a number
n
n
and his goal is to transform it to
m
m
. In one move, he can multiply
n
n
by
2
2
or multiply
n
n
by
3
3
. He can perform any number of moves.
Print the number of moves needed to transform
n
n
to
m
m
. Print -1 if it is impossible to do so.
It is easy to prove that any way to transform
n
n
to
m
m
contains the same number of moves (i.e. number of moves doesn’t depend on the way of transformation).
Input
The only line of the input contains two integers
n
n
and
m
m
(
1≤n≤m≤5⋅
10
8
1≤n≤m≤5⋅108
).
Output
Print the number of moves to transform
n
n
to
m
m
, or -1 if there is no solution.
Examples
Input
120 51840
Output
7
Input
42 42
Output
0
Input
48 72
Output
-1
Note
In the first example, the possible sequence of moves is:
120→240→720→1440→4320→12960→25920→51840.
120→240→720→1440→4320→12960→25920→51840.
The are
7
7
steps in total.
In the second example, no moves are needed. Thus, the answer is
0
0
.
In the third example, it is impossible to transform
48
48
to
72
72
.
问题链接: http://codeforces.com/problemset/problem/1141/A
问题简述: 给定两个数a,b,a能乘与2或者3,求a到b要成2或3的次数,如果a不能转化到b,输出-1.
问题分析: 模拟水过,令k=a/b,如果k能被3整除,就让k一直除与3,如果能被2整除就一直除与2,如果最后k不等于1或者a无法被b整除,亦或者n>m,则输出-1,否则输出除3或2的次数即可
AC通过的C++语言程序如下:

#include <algorithm>
#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <climits>
#include <iomanip>
#include <queue>
#include <map>
#include<vector>
#define ll long long
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    int k=m/n;
    int ans=0;
    if(k%3==0)
    {
        while(k%3==0)
        {
            k/=3;
            ans++;
        }
    }
    if(k%2==0)
    {
        while(k%2==0)
        {
            k/=2;
            ans++;
        }
    }
    if(k!=1||n>m||m%n!=0)
        cout<<-1;
    else cout<<ans;
    return 0;
}

F
CodeForces - 1141B Maximal Continuous Rest
Each day in Berland consists of
n
n
hours. Polycarp likes time management. That’s why he has a fixed schedule for each day — it is a sequence
a
1
,
a
2
,…,
a
n
a1,a2,…,an
(each
a
i
ai
is either
0
0
or
1
1
), where
a
i
=0
ai=0
if Polycarp works during the
i
i
-th hour of the day and
a
i
=1
ai=1
if Polycarp rests during the
i
i
-th hour of the day.
Days go one after another endlessly and Polycarp uses the same schedule for each day.
What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day.
Input
The first line contains
n
n
(
1≤n≤2⋅
10
5
1≤n≤2⋅105
) — number of hours per day.
The second line contains
n
n
integer numbers
a
1
,
a
2
,…,
a
n
a1,a2,…,an
(
0≤
a
i
≤1
0≤ai≤1
), where
a
i
=0
ai=0
if the
i
i
-th hour in a day is working and
a
i
=1
ai=1
if the
i
i
-th hour is resting. It is guaranteed that
a
i
=0
ai=0
for at least one
i
i
.
Output
Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day.
Examples
Input
5
1 0 1 0 1
Output
2
Input
6
0 1 0 1 1 0
Output
2
Input
7
1 0 1 1 1 0 1
Output
3
Input
3
0 0 0
Output
0
Note
In the first example, the maximal rest starts in last hour and goes to the first hour of the next day.
In the second example, Polycarp has maximal rest from the
4
4
-th to the
5
5
-th hour.
In the third example, Polycarp has maximal rest from the
3
3
-rd to the
5
5
-th hour.
In the fourth example, Polycarp has no rest at all.
问题链接: http://codeforces.com/problemset/problem/1141/B
问题简述: 给定只有0与1的序列n表示一个星期有n天,1代表该天可休息,求最长能够连续休息的天数。(最开始的天数与最后的天数是连续的)
问题分析: 模拟水过,开一个两倍大的数组,输入的时候令a[i+n]=a[i],再用一个循环找到最大天数即可
AC通过的C++语言程序如下:

#include <algorithm>
#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <climits>
#include <iomanip>
#include <queue>
#include <map>
#include<vector>
#define ll long long
using namespace std;

int k[1000000];

int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>k[i];
        k[i+n]=k[i];
    }
    int ans=0;
    int sum=0;
    for(int i=0;i<2*n;i++)
    {
        if(k[i]==1)
        {
            sum++;
        }
        else sum=0;
        ans=max(sum,ans);
    }
    cout<<ans;
    return 0;
}

H
CodeForces - 1139A Even Substrings
You are given a string
s=
s
1
s
2

s
n
s=s1s2…sn
of length
n
n
, which only contains digits
1
1
,
2
2
, …,
9
9
.
A substring
s[l…r]
s[l…r]
of
s
s
is a string
s
l
s
l+1
s
l+2

s
r
slsl+1sl+2…sr
. A substring
s[l…r]
s[l…r]
of
s
s
is called even if the number represented by it is even.
Find the number of even substrings of
s
s
. Note, that even if some substrings are equal as strings, but have different
l
l
and
r
r
, they are counted as different substrings.
Input
The first line contains an integer
n
n
(
1≤n≤65000
1≤n≤65000
) — the length of the string
s
s
.
The second line contains a string
s
s
of length
n
n
. The string
s
s
consists only of digits
1
1
,
2
2
, …,
9
9
.
Output
Print the number of even substrings of
s
s
.
Examples
Input
4
1234
Output
6
Input
4
2244
Output
10
Note
In the first example, the
[l,r]
[l,r]
pairs corresponding to even substrings are:
s[1…2]
s[1…2]
s[2…2]
s[2…2]
s[1…4]
s[1…4]
s[2…4]
s[2…4]
s[3…4]
s[3…4]
s[4…4]
s[4…4]
In the second example, all
10
10
substrings of
s
s
are even substrings. Note, that while substrings
s[1…1]
s[1…1]
and
s[2…2]
s[2…2]
both define the substring “2”, they are still counted as different substrings.
问题链接: http://codeforces.com/problemset/problem/1139/A
问题简述: 给定一个只有数字的string,求边界为偶数的子序列有多少个。
问题分析: 模拟水过,循环判断string的每个数字i是否为偶数,如果是偶数,则答案加上i,(有【1,i】,【2,i】,…,【i,i】一共i个序列)
AC通过的C++语言程序如下:

#include <algorithm>
#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <climits>
#include <iomanip>
#include <queue>
#include <map>
#include<vector>
#define ll long long
using namespace std;

char k[100000];

int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin>>n>>k;
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        if((k[i]-'0')%2==0)
            ans+=i+1;
    }
    cout<<ans;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_44012745/article/details/89882664