Codeforces Round #773 (Div. 2) A - C

A. Hard Way

题意:给你一个三角形的三个点,问你有多长的边上的点沿着 y = 0 y = 0 y=0 这条线往下走会穿过三角形

做法:其实就是问你这个三角形是否存在一条水平边,且这条边是三角形区域的上边界

#include<bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 100010;
int t, n, m;
 
int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> t;
    while (t--)
    {
        int a, b, c, d, e, f;
        cin >> a >> b >> c >> d >> e >> f;
        if (b == d && f < b) printf("%.12f\n", abs(a - c) * 1.0);
        else if (f == d && b < d) printf("%.12f\n", abs(e - c) * 1.0);
        else if (b == f && d < f) printf("%.12f\n", abs(a - e) * 1.0);
        else printf("0\n");
    }
    return 0;
}

B. Power Walking

题意:给你一个序列,问将这个序列分组,每一次分组的组内不同数字的个数

做法:用 s e t set set 存一下不同数字的个数,如果分组小于 s e t set set 的大小,输出后者,反之输出前者

#include<bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 100010;
int t, n, m;
 
int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> t;
    while (t--)
    {
        cin >> n;
        unordered_map<int, int> mp;
        for (int i = 0; i < n; i++)
        {
            cin >> m;
            mp[m]++;
        }
        for (int i = 1; i <= n; i++)
        {
            if (mp.size() >= i) cout << mp.size() << " " ;
            else cout << i << " " ;
        }
        cout << endl;
    }
    return 0;
}

C. Great Sequence

题意: 给你一个序列和一个倍数,如果序列内两个数存在倍数关系,则配对,问无法配对的数字的个数

做法:略,注意开long long

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 100010;
int t, n, m;
 
int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> t;
    while (t--)
    {
        cin >> n >> m;
        map<LL, int> mp;
        for (int i = 0; i < n; i++)
        {
            LL x;
            cin >> x;
            mp[x]++;
        }
        int res = 0;
        for (auto i : mp)
        {
            LL tt = i.first;
            if (mp[tt] == 0) continue;
            if (mp[tt * m] == 0) res += mp[tt];
            else if (mp[tt] >= mp[tt * m])
            {
                mp[tt] -= mp[tt * m];
                mp[tt * m] = 0;
                res += mp[tt];
            }
            else if (mp[tt] < mp[tt * m])
            {
                mp[tt * m] -= mp[tt];
                mp[tt] = 0;
            }
        }
        cout << res << endl ;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值