Codeforces Round #621 A-D题解

A Cow and Haybales

求D天后最左最大值。
贪心,每次从左到右挪能挪的第一块。

#include 
using namespace std;
const int nmax=111;
int a[nmax];
int n,d;

void trymove(){
    for(int i=2;i<=n;i++){
        if(a[i]){
            a[i-1]++;
            a[i]--;
            break;
        }
    }
}

int main(){
    int t;
    cin>>t;
    while(t--){
        cin>>n>>d;
        for(int i=1;i<=n;i++)
            cin>>a[i];
        if(n==1){
            cout<

B Cow and Friend

问最少几步,根据三角形定理知道若以a为步长,跳两步可组成(0,2a]之间任意值。
1.a<=x时
如果是x%a==0单独考虑,答案为x/a
否则x/a+1(最后两步可以跳到,因为a+x%a<2a)。
2.a>x时
还有一种特殊情况要考虑,最大的a超过了x,那么答案可能是2。

#include 
using namespace std;
const int nmax=1e5+50;
int t,n,x;
int a,ans;
const int inf=1e9;

int main(){
    cin>>t;
    while(t--){
        cin>>n>>x;
        int ok=0,flag=0;
        for(int i=1;i<=n;i++){
            cin>>a;
            if(a>x){
                flag=1;
            }
            else{
                ok=max(ok,a);
            }
        }
        ans=inf;
        if(ok){
            ans=x/ok;
            if(x%ok)ans++;
        }
        if(flag)ans=min(ans,2);
        cout<

C Cow and Message

1.出现次数最多的是长度为1子序列。
2.出现次数最多的是长度为2子序列。
3.如果出现次数最多的是长度为3的子序列,那么该序列中长度为2的子序列一定出现了。因此只要看12两种情况。

#include 
using namespace std;
const int nmax=1e5+10;
int sum[nmax][27],len;
string s;
int main(){
    cin>>s;
    len=s.length();
    for(int i=0;i

D Cow and Fields

在special node a,b之间连线后,1经过a,b到n的距离为:
min(dis(1,a)+1+dis(b,n),dis(1,b)+1,dis(a,n))
为了不重复计算(a,b)对,不妨设min=dis(1,a)+1+dis(b,n)
即dis(1,a)+1+dis(b,n) dis(1,a)-dis(a,n) 目标是让min最大:
对于每个a,取后缀dis(b,n)的最大值

#include 
using namespace std;
const int nmax=2e5+10;
const int inf=1e9;
vector G[nmax];
int n,m,k;
int x,y,ans;
int d[2][nmax];/*d[0]:点到1的距离,d[1]:点到n的距离*/
int suffix_maxb[nmax];

struct SpeNode
{
    int d1,dn;
    int id;
    SpeNode(int a,int b=inf,int c=inf)
    {
        id=a,d1=b,dn=c;
    }
};
vectorspe_node;
bool cmp(SpeNode a, SpeNode b)
{
    return a.d1-a.dn q;
    q.push(st);
    d[flag][st]=0;
    while(!q.empty())
    {
        int now = q.front();
        q.pop();
        for(int i=0; id[flag][now]+1)
            {
                d[flag][nex]=d[flag][now]+1;
                q.push(nex);
            }
        }
    }
}

void sort_spe()
{
    for(int i=0; i=0; i--)
    {
        suffix_maxb[i]=max(suffix_maxb[i+1],spe_node[i].dn);
    }
    int dd = 0, ans = d[0][n];
    for(int i=0; i+1

废话日记
以为这么久没搞肯定凉,没想到还up了一点点。后面再补题补起来。
自娱自乐8吼吼~~
Codeforces Round #621 A-D题解_第1张图片

你可能感兴趣的:(codeforces,解题报告,2020spring)