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