Codeforces Round #621 (Div. 1 + Div. 2)B Cow and Friend

第一感觉最小步数只和移动距离的最大值有关

对于任一移动距离a,水平移动距离范围0~a   而跳两步水平移动距离范围0~2a 且两步对称 就能回到x轴  这样就和纵坐标无关了

贪心策略:水平跳动amax,直到剩下距离amax<res<2amax或为0,显然可以两步到达

证明:水平跳动显然amax最优,对于剩下的距离只用amax需要两步 其他移动距离或组合也至少需要两步 因为amax<res<2amax 而amax又是最大移动距离

此时答案$max(2,ceil(\frac{a}{b}))$ 当然还存在一些可行解对于前一部分采取的策略可能是水平跳动其他距离或组合 代入前面的式子 显然不会比amax更优

注意:需要特判一步就能到的

官方:

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=105;
int a[N];
int main(){
    int T;
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>T;
    while(T--){
        int n,d;
        cin>>n>>d;
        for(int i=1;i<=n;i++)cin>>a[i];
        int ans=a[1];
        for(int i=2;i<=n;i++)
         if((i-1)*a[i]<=d){
             d-=(i-1)*a[i];
             ans+=a[i];
         }
         else{
           ans+=d/(i-1);break;

         }
        cout<<ans<<endl;
    }
    return 0;
}

原文地址:https://www.cnblogs.com/wyh447154317/p/12334120.html

时间: 2024-08-30 14:21:35

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

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>

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