2021.02.17个人赛

C题:https://codeforces.com/contest/1041/problem/C

题目大意:

该题就是一个人想要喝n次咖啡,但是两次喝咖啡的间隔不能小于d,如果不能排上就在另外一天喝,问最少需要几天喝完这些咖啡。

思路:

首先,就想到先排序,然后两两间看差距是否大于d,分成可以排与不可排,而且用一个队列来维护这些排列的当前信息,来进行模拟,这样贪心出来的结果便是最小天数。

解题代码:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
using namespace std;
const long long N = 1e10 + 7;
const int maxn = 2e5 + 5;
const long long INF = 8e18;
typedef long long ll;
#define for0(i,n) for(int i = 0;i < n;i++)
#define for1(i,n) for(int i = 1;i <= n;i++)
struct people{
    int sign;
    int v;
    int num;
}p[200100];
bool cmp1(people a,people b){
    return  a.v < b.v;
}
bool cmp2(people a,people b){
    return  a.sign < b.sign;
}
int main()
{
    int n,m,d;
    cin >> n >> m >> d;
    for1(i,n){
        cin >> p[i].v;
        p[i].sign = i;

    }
    sort(p+1,p+1+n,cmp1);
    p[1].num = 1;
    int w = 1;
    queue<people> q;
    q.push(p[1]);
    for(int i = 2;i <= n;i++){
        if(p[i].v >  q.front().v + d){

            p[i].num = q.front().num;
            q.pop();
            q.push(p[i]);
        }
        else{
            w++;
            p[i].num = w;
            q.push(p[i]);
        }
    }
    sort(p+1,p+1+n,cmp2);
    cout << w << endl;
    for1(i,n){
        if(i == 1){
            cout << p[i].num;
        }
        else
            cout << " " << p[i].num;
    }
    cout << endl;


}

A题:https://codeforces.com/contest/1041/problem/A

题目大意:

n个数字,其中这些数字是一连串的连续数字,缺少了一部分,问缺少的最小数字个数。

思路:

这个肯定就想到最大值与最小值的差+1,便是这一串数字的原本数量,再减去n,便是答案。

解题代码:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
using namespace std;
const long long N = 1e10 + 7;
const int maxn = 2e5 + 5;
const long long INF = 8e18;
typedef long long ll;
#define for0(i,n) for(int i = 0;i < n;i++)
#define for1(i,n) for(int i = 1;i <= n;i++)

int main()
{
    int n;
    cin >> n;
    ll minnum = N,maxnum = -N;
    for0(i,n){
        ll x;
        cin >> x;
        minnum = min(minnum,x);
        maxnum = max(maxnum,x);

    }
    cout << maxnum-minnum-n+1 << endl;

}

B题:https://codeforces.com/contest/1041/problem/B

题目大意:

给了a,b,x,y让你找出有多少组能否符合 h:w = x:y 的搭配,其中h < a, w < b。

思路:

这题其实转换一下就是kx = a , ky = b, 其中x/y要化简,去最小值k即可。

解题代码:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
using namespace std;
const long long N = 1e10 + 7;
const int maxn = 2e5 + 5;
const long long INF = 8e18;
typedef long long ll;
#define for0(i,n) for(int i = 0;i < n;i++)
#define for1(i,n) for(int i = 1;i <= n;i++)

int main()
{
    ll a,b,x,y;
    cin >> a >> b >> x >> y;
    ll temp = __gcd(x,y);
    x /= temp,y /= temp;
    cout << min(a/x,b/y) << endl;
 
}

 

posted @ 2021-02-18 12:37  emhhbw==  阅读(46)  评论(0)    收藏  举报