首页 > 其他分享 >CodeForces - 1760F Quests

CodeForces - 1760F Quests

时间:2023-01-08 11:33:59浏览次数:53  
标签:std const int ll CodeForces 答案 Quests 1760F sum

CodeForces - 1760F Quests

题解:二分答案

首先我们来分析一题目,如果说K越大,我们在d天里很有可能得不到C个硬币,所以K的最大值一定在合法答案和不合法答案的临界点,并且这些答案是单调的,所以我们直接考虑二分答案;

1.考虑不可能的情况:当K=0时,那么我们D天每天都去做获得硬币最多的工作,如果连这都满足不了C的条件,说明绝对答案不存在

2.考虑K趋于无穷大的情况:如果说K现在取无穷大,那就说明在D天里每个任务只能做一次,所以我们首先确定能做多少个任务,肯定是\(min(d,n)\),然后按照价值大到价值小的顺序做任务,得出sum,如果sum>=c,代表K可以取无穷大

3.其余情况直接二分答案,那么其实我们会发现一个规律,比如说d=5,k=5,a:4 2

天数1 2 3 4 5
4 2 0 0 4

我们会发现天数和数组a的小标会有一个这样的规律:\((i-1)mod(k+1)+1\)第i天取到的数组a元素下标

#include <bits/stdc++.h>
#define Zeoy std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0)
#define all(x) (x).begin(), (x).end()
#define endl '\n'
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-9;
const int N = 2e5 + 10;
ll n, c, d;
ll a[N];
bool check(int k)
{
    ll sum = 0;
    for (int i = 1; i <= d; ++i)
    {
        int x;
        if ((i - 1) % (k + 1) + 1 > n)		//如果超出数组a大小,x=0,没有贡献
            x = 0;
        else
            x = a[(i - 1) % (k + 1) + 1];
        sum += x;
    }
    if (sum >= c)
        return 1;
    else
        return 0;
}
int main(void)
{
    Zeoy;
    int t = 1;
    cin >> t;
    while (t--)
    {
        cin >> n >> c >> d;
        ll maxx = -1;
        for (int i = 1; i <= n; ++i)
            cin >> a[i];
        sort(a + 1, a + n + 1, greater<ll>());
        ll sum = 0;
        ll pre = 0;
        for (int i = 1; i <= d; ++i)
            sum += a[1];
        for (int i = 1; i <= min(n, d); ++i)
            pre += a[i];
        if (sum < c)
        {
            cout << "Impossible\n";
            continue;
        }
        if (pre >= c)
        {
            cout << "Infinity\n";
            continue;
        }
        int l = 0, r = d;
        while (l <= r)
        {
            int mid = l + r >> 1;
            if (check(mid))
            {
                l = mid + 1;
            }
            else
                r = mid - 1;
        }
        cout << r << endl;
    }
    return 0;
}

标签:std,const,int,ll,CodeForces,答案,Quests,1760F,sum
From: https://www.cnblogs.com/Zeoy-kkk/p/17034305.html

相关文章

  • Codeforces - 1656E - Equal Tree Sums(构造 + 树论 + 图论 + 搜索、结论题、*2200)
    1656E-EqualTreeSums(⇔源地址)目录1656E-EqualTreeSums(⇔源地址)tag题意思路AC代码错误次数:0tag⇔*2200、⇔构造、⇔树论、⇔图论、⇔搜......
  • 1.7 vp Codeforces Round #839 (Div. 3)
    A-A+B?题意:给出两个0~9的数字和一个加号。要求输出数字相加的和思路:用字符串输入,第一位和第三位相加减去两个字符0即为数字和。voidsolve(){ strings; cin>>s;......
  • 2023/1/6/冬令营codeforces比赛复盘
    #I.TheHumanoid(人形生物)##[原题传送通道](https://codeforces.com/group/L9GOcnr1dm/contest/418722/problem/I)##思路:1.将各个宇航员a[i]从小到大sort排序,减小Huma......
  • Educational Codeforces Round 13
    EducationalCodeforcesRound13https://codeforces.com/contest/6784/6:ABCD(1h)前4题都很简单,E应该是个撞鸭dp但是我想不出来A.JohnyLikesNumbers#include<bits/......
  • Codeforces Round #648 (Div. 2) A-D,补E
    A.MatrixGame题意:一个矩阵初始状态有些位置是1表示该位置对应的行和列都已经被占用。现在两人轮流选一个未被占用的位置标记,A是先手,谁动不了了谁就输了,输出赢家。......
  • Codeforces CF255C Almost Arithmetical Progression
    链接难度:\(1500\)有一个序列\(b_{1\simn}\)。你需要从中选出一个长度最长的子序列\(p_{1\simk}\),使其满足\(p_1=p_3=...=p_{\lceil\frac{k}{2}\rceil-1},p_2=p_4=......
  • 2023.1.6 (Codeforces Round #842 (Div. 2))
    A.GreatestConvexLinkhttps://codeforces.com/contest/1768/problem/ADescription求出最大的\(x(1\leqx<k)\),使得\(x!+(x-1)!\)是\(k\)的倍数。Soluti......
  • Codeforces Round #842 (Div. 2)
    CodeforcesRound#842(Div.2)https://codeforces.com/contest/1768好困,放完代码就跑路。A.GreatestConvex#include<bits/stdc++.h>usingnamespacestd;void......
  • Codeforces Round #842 (Div. 2)
    Preface唉现在这是是做稍微难点的SB题(指Div2正常场的CD难度)总是要犯病因此Rating上不去不说,比赛的时候连EF题面都没机会看一眼这场先是C交上去忘记本机调试的时候把数组......
  • Codeforces Round 842
    目录写在前面ABCDE写在最后写在前面仁王真好玩大太刀真好玩下辈子我还要玩大太刀[](https://pic.imgdb.cn/item/63b7fdb4be43e0d30ec2dccd.jpg)顺带吐槽一下,这什么排......