Codeforces Round #621 (Div. 1 + Div. 2)

Codeforces Round #621 (Div. 1 + Div. 2)

A. Cow and Haybales

贪心,移到第一堆的代价即为与第一堆的距离。

#include <bits/stdc++.h>
using namespace std;
void solve(){
    int n,d;cin>>n>>d;
    int sum;cin>>sum;
    for(int i=1;i<n;i++){
        int t;cin>>t;
        if(d>0){
            sum+=min(t,d/i);
            d-=t*i;
        }
    }
    cout<<sum<<"\n";
}
int main()
{
    int t;cin>>t;
    while(t--)
        solve();
    return 0;
}

B. Cow and Friend

贪心,考虑能跳的最远距离mx,2*mx内最多跳两次,再加上移动到2*mx内最少需要多少次。

#include <bits/stdc++.h>
using namespace std;
void solve(){
    int n,x;cin>>n>>x;
    int a[n];for(int &i:a) cin>>i;
    int mx=*max_element(a,a+n);
    int dis=x,cnt=0;
    if(dis>2*mx) cnt+=(dis-2*mx-1)/mx+1;
    dis-=cnt*mx;
    if(find(a,a+n,dis)!=a+n) cout<<cnt+1<<"\n";
    else cout<<cnt+2<<"\n";
}
int main()
{
    int t;cin>>t;
    while(t--)
        solve();
    return 0;
}

C. Cow and Message

长为3的组合不会多于1或2的,更长同理,所以只需考虑长为1和2的最多组合。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    string s;cin>>s;
    ll arr1[26]={0},arr2[26][26]={0};
    for(char c:s){
        int i=c-‘a‘;
        for(int j=0;j<26;j++)
            arr2[j][i]+=arr1[j];
        ++arr1[i];
    }
    cout<<max(*max_element(arr1,arr1+26),*max_element(*arr2,*arr2+26*26))<<"\n";
    return 0;
}

D. Cow and Fields

还是不太明白为什么要前后缀距离作差排序,待填。

原文地址:https://www.cnblogs.com/Kanoon/p/12571204.html

时间: 2024-11-08 11:25:53

Codeforces Round #621 (Div. 1 + Div. 2)的相关文章

Educational Codeforces Round 36 (Rated for Div. 2)

Educational Codeforces Round 36 (Rated for Div. 2) F. Imbalance Value of a Tree You are given a tree T consisting of n vertices. A number is written on each vertex; the number written on vertex i is ai. Let's denote the function I(x,?y) as the differ

Educational Codeforces Round 36 (Rated for Div. 2) 题解

Educational Codeforces Round 36 (Rated for Div. 2) 题目的质量很不错(不看题解做不出来,笑 Codeforces 920C 题意 给定一个\(1\)到\(n\)组成的数组,只可以交换某些相邻的位置,问是否可以将数组调整为升序的 解题思路 首先如果每个数都能通过交换到它应该到的位置,那么就可以调整为升序的. 但实际上交换是对称的,如果应该在的位置在当前位置前方的数都交换完成,那么整体就是排好序的,因为不可能所有不在相应位置的数都在相应位置的后方.

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://codeforces.com/contest/985/problem/E Description Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome w

Educational Codeforces Round 55 (Rated for Div. 2)

Educational Codeforces Round 55 (Rated for Div. 2) 链接 A Vasya and Book 傻逼题..注意判边界. #include<cstdio> #include<cstring> #include<algorithm> #include<queue> #include<set> #include<map> #include<vector> #include<cm

Educational Codeforces Round 57 (Rated for Div. 2)

get人生第二场CF! 成绩:(exACM) rank858 AC3/7 Penalty57 rating1648(+52) 题目:Educational Codeforces Round 57 (Rated for Div. 2) 错题题解: D. Easy Problem E. The Top Scorer F. Inversion Expectation G. Lucky Tickets 原文地址:https://www.cnblogs.com/xht37/p/10198321.html

Educational Codeforces Round 58 (Rated for Div. 2)(待更新)

get人生第七场CF! 成绩:(exACM) rank AC3/7 Penalty104 rating() 题目:Educational Codeforces Round 58 (Rated for Div. 2) 错题题解: C. Division and Union 原文地址:https://www.cnblogs.com/xht37/p/10260260.html

Educational Codeforces Round 59 (Rated for Div. 2) DE题解

Educational Codeforces Round 59 (Rated for Div. 2) D. Compression 题目链接:https://codeforces.com/contest/1107/problem/D 题意: 给出一个n*(n/4)的矩阵,这个矩阵原本是一些01矩阵,但是现在四个四个储存进二进制里面,现在给出的矩阵为0~9以及A~F,表示0~15. 然后问这个矩阵能否压缩为一个(n/x)*(n/x)的矩阵,满足原矩阵中大小为x*x的子矩阵所有数都相等(所有子矩阵构

Codeforces Round #503 (by SIS, Div. 2)

Codeforces Round #503 (by SIS, Div. 2) https://codeforces.com/contest/1020 A 1 #include <iostream> 2 #include <cstring> 3 #include <cmath> 4 #include <algorithm> 5 #include <cstdio> 6 #include <cstdlib> 7 #include <s

Educational Codeforces Round 62 (Rated for Div. 2)

layout: post title: Educational Codeforces Round 62 (Rated for Div. 2) author: "luowentaoaa" catalog: true tags: mathjax: true - codeforces - dp --- " target="_blank" style="font-size:24px;">传送门 D - Minimum Triangulat