2019.4.30 WAGV CF teamplay two

前言:4月30號 CF DIV2水題隊內重現賽,(選題不注意,混入了一道愚人節題目嗚)
比賽地址:https://cn.vjudge.net/contest/298751#problem/D
密碼:wagv18

A
CodeForces - 1150A Stock Arbitraging
Welcome to Codeforces Stock Exchange! We’re pretty limited now as we currently allow trading on one stock, Codeforces Ltd. We hope you’ll still be able to make profit from the market!
In the morning, there are
n
n
opportunities to buy shares. The
i
i
-th of them allows to buy as many shares as you want, each at the price of
s
i
si
bourles.
In the evening, there are
m
m
opportunities to sell shares. The
i
i
-th of them allows to sell as many shares as you want, each at the price of
b
i
bi
bourles. You can’t sell more shares than you have.
It’s morning now and you possess
r
r
bourles and no shares.
What is the maximum number of bourles you can hold after the evening?
Input
The first line of the input contains three integers
n,m,r
n,m,r
(
1≤n≤30
1≤n≤30
,
1≤m≤30
1≤m≤30
,
1≤r≤1000
1≤r≤1000
) — the number of ways to buy the shares on the market, the number of ways to sell the shares on the market, and the number of bourles you hold now.
The next line contains
n
n
integers
s
1
,
s
2
,…,
s
n
s1,s2,…,sn
(
1≤
s
i
≤1000
1≤si≤1000
);
s
i
si
indicates the opportunity to buy shares at the price of
s
i
si
bourles.
The following line contains
m
m
integers
b
1
,
b
2
,…,
b
m
b1,b2,…,bm
(
1≤
b
i
≤1000
1≤bi≤1000
);
b
i
bi
indicates the opportunity to sell shares at the price of
b
i
bi
bourles.
Output
Output a single integer — the maximum number of bourles you can hold after the evening.
Examples
Input
3 4 11
4 2 5
4 4 5 4
Output
26
Input
2 2 50
5 7
4 2
Output
50
Note
In the first example test, you have
11
11
bourles in the morning. It’s optimal to buy
5
5
shares of a stock at the price of
2
2
bourles in the morning, and then to sell all of them at the price of
5
5
bourles in the evening. It’s easy to verify that you’ll have
26
26
bourles after the evening.
In the second example test, it’s optimal not to take any action.
問題鏈接: http://codeforces.com/problemset/problem/1150/A
問題簡述: 給定n個白天的股票價格,m個晚上的股票價格以及持有金額r,一下有n個序列an以及m個序列bm,求白天買進股票,晚上賣出股票後,能持有的最大金額數量
問題分析: 我開始題目沒有讀懂orz,以爲有n天,每天都能買進賣出股票,寫得很複雜一代碼…嗚嗚嗚,結果只是找最大值與最小值的水題,模擬水過
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[1000],g[1000];

bool cmp(int x,int y)
{
    return x>y;
}

int main()
{
    ios::sync_with_stdio(false);
    int n,m,r;
    cin>>n>>m>>r;
    for(int i=0;i<n;i++)
        cin>>k[i];
    for(int i=0;i<m;i++)
        cin>>g[i];
    sort(k,k+n);
    sort(g,g+m,cmp);
    int ans=r-r/k[0]*k[0]+r/k[0]*g[0];
    cout<<max(ans,r);
    return 0;
}

B
CodeForces - 1150B Tiling Challenge
One day Alice was cleaning up her basement when she noticed something very curious: an infinite set of wooden pieces! Each piece was made of five square tiles, with four tiles adjacent to the fifth center tile:
在這裏插入圖片描述
By the pieces lay a large square wooden board. The board is divided into
n
2
n2
cells arranged into
n
n
rows and
n
n
columns. Some of the cells are already occupied by single tiles stuck to it. The remaining cells are free.
Alice started wondering whether she could fill the board completely using the pieces she had found. Of course, each piece has to cover exactly five distinct cells of the board, no two pieces can overlap and every piece should fit in the board entirely, without some parts laying outside the board borders. The board however was too large for Alice to do the tiling by hand. Can you help determine if it’s possible to fully tile the board?
Input
The first line of the input contains a single integer
n
n
(
3≤n≤50
3≤n≤50
) — the size of the board.
The following
n
n
lines describe the board. The
i
i
-th line (
1≤i≤n
1≤i≤n
) contains a single string of length
n
n
. Its
j
j
-th character (
1≤j≤n
1≤j≤n
) is equal to “.” if the cell in the
i
i
-th row and the
j
j
-th column is free; it is equal to “#” if it’s occupied.
You can assume that the board contains at least one free cell.
Output
Output YES if the board can be tiled by Alice’s pieces, or NO otherwise. You can print each letter in any case (upper or lower).
Examples
Input
3
#.#

#.#
Output
YES
Input
4
##.#
#…

##.#
Output
NO
Input
5
#.###
…#
#…
###.#

Output
YES
Input
5
#.###
…#
#…
…#
#…##
Output
NO
Note
The following sketches show the example boards and their tilings if such tilings exist:
在這裏插入圖片描述
問題鏈接: http://codeforces.com/problemset/problem/1150/B
問題簡述: 一種瓷磚鋪開只能以題目中給出的方式擺放,求給出的n×n方陣能否被瓷磚鋪滿,#表示已被佔據,.則表示需要鋪瓷磚
問題分析: 按照題目給的鋪開方式直接兩個循環搜索找到空格鋪上,再循環一次判斷有沒有鋪滿即可,模擬水過
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[100][100];
int n;

bool checkedge(int x,int y)
{
    if(x>=0&&x<n&&x+1>=0&&x+1<n&&x+2>=0&&x+2<n&&y-1>=0&&y-1<n&&y>=0&&y<n&&y+1>=0&&y+1<n)
        return 1;
    return 0;
}

int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            cin>>k[i][j];
        }
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(checkedge(i,j)&&k[i][j]=='.'&&k[i+1][j]=='.'&&k[i+1][j-1]=='.'&&k[i+1][j+1]=='.'&&k[i+2][j]=='.')
            {
                k[i][j]='#';
                k[i+1][j]='#';
                k[i+1][j-1]='#';
                k[i+1][j+1]='#';
                k[i+2][j]='#';
            }
        }
    }
    int flag=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(k[i][j]=='.')
                flag=1;
        }
    }
    if(flag)
    {
        cout<<"NO";
    }
    else cout<<"YES";
    return 0;
}

C
CodeForces - 1151A Maxim and Biology
Today in the scientific lyceum of the Kingdom of Kremland, there was a biology lesson. The topic of the lesson was the genomes. Let’s call the genome the string “ACTG”.
Maxim was very boring to sit in class, so the teacher came up with a task for him: on a given string
s
s
consisting of uppercase letters and length of at least
4
4
, you need to find the minimum number of operations that you need to apply, so that the genome appears in it as a substring. For one operation, you can replace any letter in the string
s
s
with the next or previous in the alphabet. For example, for the letter “D” the previous one will be “C”, and the next — “E”. In this problem, we assume that for the letter “A”, the previous one will be the letter “Z”, and the next one will be “B”, and for the letter “Z”, the previous one is the letter “Y”, and the next one is the letter “A”.
Help Maxim solve the problem that the teacher gave him.
A string
a
a
is a substring of a string
b
b
if
a
a
can be obtained from
b
b
by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.
Input
The first line contains a single integer
n
n
(
4≤n≤50
4≤n≤50
) — the length of the string
s
s
.
The second line contains the string
s
s
, consisting of exactly
n
n
uppercase letters of the Latin alphabet.
Output
Output the minimum number of operations that need to be applied to the string
s
s
so that the genome appears as a substring in it.
Examples
Input
4
ZCTH
Output
2
Input
5
ZDATG
Output
5
Input
6
AFBAKC
Output
16
Note
In the first example, you should replace the letter “Z” with “A” for one operation, the letter “H” — with the letter “G” for one operation. You will get the string “ACTG”, in which the genome is present as a substring.
In the second example, we replace the letter “A” with “C” for two operations, the letter “D” — with the letter “A” for three operations. You will get the string “ZACTG”, in which there is a genome.
問題鏈接: http://codeforces.com/problemset/problem/1151/A
問題簡述: 求一個字符串其中任意4個字符轉換成ACTG的次數(一次轉換隻能把一個字母轉換到相鄰字母,Z與A相鄰)
問題分析: 模擬水過,一個循環找到轉換到ACTG次數最少的4個字母,輸出轉換次數即可
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[100];
int sum[100];

int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>k[i];
    }
    int minn=99999999;
    for(int i=0;i<n-3;i++)
    {
        char a=k[i],b=k[i+1],c=k[i+2],d=k[i+3];
        if(a<='N') sum[i]+=a-'A';
        else sum[i]+='Z'-a+1;
        if(b<='P') sum[i]+=abs(b-'C');
        else sum[i]+='Z'-b+3;
        if(c>='G') sum[i]+=abs('T'-c);
        else sum[i]+=c-'A'+7;
        if(d<='T') sum[i]+=abs(d-'G');
        else sum[i]+='Z'-d+7;
        minn=min(sum[i],minn);
    }
    cout<<minn;
    return 0;
}

F
CodeForces - 1146B Hate "A"
Bob has a string
s
s
consisting of lowercase English letters. He defines
s

s′
to be the string after removing all “a” characters from
s
s
(keeping all other characters in the same order). He then generates a new string
t
t
by concatenating
s
s
and
s

s′
. In other words,
t=s+
s

t=s+s′
(look at notes for an example).
You are given a string
t
t
. Your task is to find some
s
s
that Bob could have used to generate
t
t
. It can be shown that if an answer exists, it will be unique.
Input
The first line of input contains a string
t
t
(
1≤|t|≤
10
5
1≤|t|≤105
) consisting of lowercase English letters.
Output
Print a string
s
s
that could have generated
t
t
. It can be shown if an answer exists, it is unique. If no string exists, print “?” (without double quotes, there is no space between the characters).
Examples
Input
Copy
aaaaa
Output
Copy
aaaaa
Input
Copy
aacaababc
Output
Copy
?
Input
Copy
ababacacbbcc
Output
Copy
ababacac
Input
Copy
baba
Output
Copy
?
Note
In the first example, we have
s=
s=
“aaaaa”, and
s

=
s′=
“”.
In the second example, no such
s
s
can work that will generate the given
t
t
.
In the third example, we have
s=
s=
“ababacac”, and
s

=
s′=
“bbcc”, and
t=s+
s

=
t=s+s′=
“ababacacbbcc”.
問題鏈接: http://codeforces.com/problemset/problem/1146/B
問題簡述: 給定一個字符串k,判斷取出所有’a’的字符串k加上有’a’的另一個字符串加起來能否與k相等
問題分析: 模擬水過,循環k,如果不是’a’,則將改字符加到u後,把每個字符都加到v,如果u+v長度大於等於k的長度,退出循環,判斷k與u+v是否相等即可
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);
    string a;
    string s="",s1="";
    cin>>a;
    int len=a.length();
    for(int i=0;i<len;i++)
    {
        s+=a[i];
        if(a[i]!='a') s1+=a[i];
        if(s.length()+s1.length()>=len)
            break;
    }
    if(s+s1==a)
        cout<<s;
    else cout<<":(";
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章