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;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章