首页 > 其他分享 >CodeForces - 1701C Schedule Management

CodeForces - 1701C Schedule Management

时间:2023-01-08 13:56:54浏览次数:62  
标签:std Management const int 1701C ll CodeForces mid mp

CodeForces - 1701C Schedule Management

题解:二分答案

很显然如果你给的时间越长,所有工作就越容易被完成,所以时间存在二分性,我们直接二分时间

但是我们现在需要解决一个问题:

1.check函数怎么写,也就是如何判断一个答案的合法性:首先我们肯定是让所有人去做他所精通的工作,如果在给出的mid时间中,他把自己精通的工作做完了,那么我们直接看他能不能帮别人做别人做不完的任务,如果他做不完,他只能等待别人帮忙,所以我们去记录每次没有完成任务的数量,如果有任务没有完成,答案就是不合法的

#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 long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-9;
const int N = 2e5 + 10;
ll a[N];
int n, m;
map<int, int> mp;
bool check(int mid)
{
    ll cnt = 0;                             //代表没有做完的任务的数量,记得开longlong,寄了
    for (int i = 1; i <= n; ++i)
    {
        if (mp[i] > mid)                    //自己完不成自己精通的所有任务
            cnt += mp[i] - mid;
        else
            cnt -= (mid - mp[i]) / 2;       //自己有空余时间就去帮别人做
    }
    if (cnt > 0)
        return 0;
    else
        return 1;
}
int main(void)
{
    Zeoy;
    int t = 1;
    cin >> t;
    while (t--)
    {
        mp.clear();
        cin >> n >> m;
        for (int i = 1; i <= m; ++i)
        {
            cin >> a[i];
            mp[a[i]]++;                     //记录每个人精通任务的数量
        }
        int l = 0, r = 1e9;
        while (l <= r)
        {
            int mid = l + r >> 1;
            if (check(mid))
                r = mid - 1;
            else
                l = mid + 1;
        }
        cout << l << endl;
    }
    return 0;
}

标签:std,Management,const,int,1701C,ll,CodeForces,mid,mp
From: https://www.cnblogs.com/Zeoy-kkk/p/17034591.html

相关文章

  • CodeForces - 1730B Meeting on the Line
    CodeForces-1730BMeetingontheLine题解:思维,找货舱位置/二分答案首先直接来引理,假设现在一个数轴上有许多点,那么一个点到这些点距离最短之和的点肯定在数轴最左端......
  • Codeforces Round #842 (Div. 2)
    D-LuckyPermutation(置换环)题目大意给定一个数组,该数组为1到n的全排列。可以交换数组中两个不同元素的位置(无需相邻)要使该数组的逆序对恰好为1,最少要多少次交换?......
  • Educational Codeforces Round 14
    EducationalCodeforcesRound14https://codeforces.com/contest/6914/6:ABCD(C是恶心人的模拟分类讨论,写了巨久导致没时间看EF)这场没有红题,应该是可以补完的。A.Fas......
  • Codeforces Round #839 (Div. 3) A-E
    CodeforcesRound#839(Div.3)A-Ehttps://codeforces.com/contest/1772之前打的一场忘记记录了,题也没补,今天想起来E博弈没过补一下,FG不想看了好长qwq做太久已经忘了......
  • CodeForces - 1760F Quests
    CodeForces-1760FQuests题解:二分答案首先我们来分析一题目,如果说K越大,我们在d天里很有可能得不到C个硬币,所以K的最大值一定在合法答案和不合法答案的临界点,并且这些......
  • 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;......
  • 论文笔记:Access Path Selection in a Relational Database Management System
    论文笔记:AccessPathSelectioninaRelationDatabaseManagementSystem这篇文章是1979年由IBM发表的。主要介绍了System-R查询优化器的设计。Processingofan......
  • 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/......