其他分享
首页 > 其他分享> > Codeforces Round #509 (Div. 2)

Codeforces Round #509 (Div. 2)

作者:互联网

比赛链接: https://codeforces.com/contest/1041

A题:给你n个数,问你最大的和最小的数之间有多少个未写的数,那就找出写的数字然后再减去就好了

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int mmax = -1,mmin = 1e10;
    for(int i = 0,x;i < n;i ++){
        cin >> x;
        mmax = max(mmax,x);
        mmin = min(mmin,x);
    }
    cout << mmax - mmin - n + 1 << endl;
    return 0;
}

B题:找出最大公约数,然后算一下a / x,和b/y哪个小就行

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
    LL a,b,x,y;
    cin >> a >> b >> x >> y;
    
    
    LL t = __gcd(x,y);
    x = x / t;
    y = y / t;
    cout << min(a / x,b/y) << endl;
    
    
    return 0;
}

C题:信息1:就是问最少多长时间能喝完咖啡,每一个想喝咖啡的时间点都得喝咖啡。信息2:给你n个时间点,每天工作m分钟,两次喝咖啡时间大于等于d,问你几天能喝完

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int n,m,d;
const int N = 1e6 + 10;
pair<int,int> a[N];
LL b[N];

int main()
{
    cin >> n >> m >> d;
    d ++;
    for(int i = 1;i <= n;i ++){
        cin >> a[i].first;
        a[i].second = i;
    }
    
    sort(a + 1,a + n + 1);
    
    int day = 0;
    
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>q;
    
    for(int i = 1;i <= n;i ++){
       // cout << i << ' ' << a[i].second << endl;
        if(q.size() == 0){
            q.push({a[i].first + d,++ day});
            b[a[i].second] = 1;
            continue;
        }
        auto t = q.top();
        if(t.first <= a[i].first){
            b[a[i].second] = t.second;
            q.pop();
            q.push({a[i].first + d,t.second});
        }else{
            b[a[i].second] = ++ day;
            q.push({a[i].first + d,day});
        }
    }
    
    cout << day << endl;
    
    for(int i = 1;i <= n;i ++){
        cout << b[i] << ' ';
    }
     
    
    return 0;
}

D题:信息1:有一个玩滑翔伞的,从h高度的地方往下飞,x减一的同时y减一,有些地方有上升气流,他处于这些区域的时候y不变,他可以随意选择一个x往下跳,问飞行的最远距离是多少


#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
const int N = 1e6 + 10;
int sum1[N];
int sum2[N];

int main()
{
    int n,h;
    cin >> n >> h;
    
    int back = 0;
    
    for(int i = 1,l,r;i <= n;i ++){
        cin >> l >> r;
        sum1[i] = sum1[i - 1] + r - l;
        sum2[i] = sum2[i - 1] + l - back;
        back = r;
    }
    int ans = 0;
    for(int i = 1;i <= n;i ++){
        
        int pos = lower_bound(sum2 + 1,sum2 + n + 1,sum2[i] + h) - sum2;
        ans = max(sum1[pos - 1] - sum1[i - 1],ans);
    }
    
    cout << ans + h << endl;
    
    
    return 0;
}

标签:int,LL,Codeforces,long,cin,509,using,Div,include
来源: https://www.cnblogs.com/yjsh/p/14411245.html