AtCoder Beginner Contest 137 A B C D

A: max(max(a-b,a+b),a*b)

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ios::sync_with_stdio(false);
    int a,b,c;
    cin>>a>>b;
    cout<<max(max(a+b,a-b),a*b);
    return 0;
}

B:输出一下x的左右k个数和x

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    cout<<k-n+1;
    for (int i = k-n+2;i < k+n;i ++)
        cout<<' '<<i;
    return 0;
}

C:对每个字符串排序,记录一下个数遍历一下,会爆int

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    unordered_map<string,int> mp;
    string s;
    ll ans = 0;
    for (int i = 0;i < n;i ++)
    {
        cin>>s;
        sort(s.begin(),s.end());
        if (!mp[s]) mp[s] = 1;
        else mp[s] ++;
    }
    unordered_map<string,int> :: iterator it;
    for (it = mp.begin();it != mp.end();it ++)
    {
        int n = it->second;
        ans += 1LL* n*(n-1)/2;
    }
    cout<<ans<<endl;
    return 0;
}

D:先说题意,一共有n个任务,要在m天完成一些任务,对于这n个任务,每天个已完成一个任务ai,但是要在bi天后才能拿到钱,问最大化能得到多少钱

思路:考虑从最后一天开始做任务,每一天都做得到钱数最多的,优先队列维护(最后一天能领到钱,那么之前的每一天做这个任务,也都能拿到钱)

#include<bits/stdc++.h>
using namespace std;
struct node
{
    int d,x;
}a[100010];
bool cmp(node a,node b)
{
    return a.d<b.d;
}
int main()
{
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    for (int i = 0;i < n;i ++)
        cin>>a[i].d>>a[i].x;
    sort(a,a + n,cmp);//先按天数升序排序
    priority_queue<int> que;
    int ans = 0,pos = 0;
    for (int i = 1;i <= m;i ++)
    {
        for (int j = pos;j <= n;j ++)
        {
            if (a[j].d == i) que.push(a[j].x);
            else if (a[j].d > i)
            {
                pos = j;
                break;
            }
        }
        if (!que.empty())
        {
            ans += que.top();
            que.pop();
        }
    }
    cout<<ans<<'\n';
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值