SDUT 2022 summer team contest 4th

F - Air Conditioned Minions

反思:这题一开始我的思路错啦 浅浅的耽误了一把时间 但是好在xy老师及时修正过来了 最后也是很顺利的a掉了 最后补题的时候仔细看了看发现还是读题的问题

思路:题意是每个仆从都有自己喜好的温度区间 但是每个屋子只能是任意的一个温度但容纳的人数不限制 问最少需要多少房间。那就和贪心的活动选择有点类似了 先将所有区间的左端进行排序 根据右端来维护一个共同的区间 如果不满足就另开新的区间 

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define PII pair<int, int>
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define mem(a, b) memset(a, b, sizeof a);
#define pi acos(-1)
const int N = 210;
const int inf = 0x3f3f3f3f;
struct node
{
    int l,r;
}a[N];
bool cmp(node a,node b)
{
    return a.l<b.l;
}
int n;
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i].l>>a[i].r;
    }
    sort(a,a+n,cmp);
    int kr=a[0].r,kl=a[0].l;
    int ans=1;
    for(int i=1;i<n;i++)
    {
        if(a[i].l>kr)
        {
            ans++;
            kr=a[i].r;
            kl=a[i].l;
        }
        else
        {
            if(a[i].l>kl) kl=a[i].l;
            if(a[i].r<kr) kr=a[i].r;
        }
    }
    cout<<ans<<endl;
    return 0;
}

G - Association for the Country of Mububa

反思:当时这道题做的很吃力啦~ 其实是有想到问题所在的 就是当前选择的这个可能和之前的区间结合会降低下一个的标准 但是最后也没有思考出解决方案 实在是菜菜~

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define PII pair<int, int>
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define mem(a, b) memset(a, b, sizeof a);
#define pi acos(-1)
const int N = 3e3+10;
const int inf = 0x3f3f3f3f;
ll n;
ll sum[N],res[N],a[N],ans[N];
int main()
{
    cin>>n;
    ll x;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        sum[i]=sum[i-1]+x;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=i-1;j>=0;j--)
        {
            if(sum[i]-sum[j]>=res[j])
            {
                res[i]=sum[i]-sum[j];
                ans[i]=ans[j]+1;
                break;
            }
        }
    }
    cout<<ans[n]<<endl;
    return 0;
}

C - Association for Control Over Minds

反思:一个简单的带权并查集 当时最后被初始化的0-N卡了好久 事实证明还是要好好读题 虽然最后收获了很珍贵的队内文化 但是还是要注意啦~

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define PII pair<int, int>
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define mem(a, b) memset(a, b, sizeof a);
#define pi acos(-1)
const int N = 5e5 + 10;
const int inf = 0x3f3f3f3f;
vector<int> g;
int n, sizes[N], pre[N];
int find(int x)
{
    if (pre[x] != x)
        pre[x] = find(pre[x]);
    return pre[x];
}
void Insert(int x, int y)
{
    int xx = find(x);
    int yy = find(y);
    if (xx != yy)
    {
        pre[yy] = xx;
        sizes[xx] += sizes[yy];
    }
}
int main()
{
    cin >> n;
    for (int i = 0; i < N; i++)
    {
        pre[i] = i;
        sizes[i] = 1;
    }
    int ans=0;
    for (int i = 0; i < n; i++)
    {
        g.clear();
        int t;
        cin >> t;
        for (int j = 0; j < t; j++)
        {
            int x;
            cin >> x;
            g.push_back(find(x));
        }
        sort(g.begin(), g.end());
        g.erase(unique(g.begin(), g.end()), g.end());   
        int cnt = 0;
        int len = g.size();
        for (int j = 0; j < len; j++)
        {
            cnt += sizes[g[j]];
            //cout<<sizes[g[j]]<<endl;
        }
        //cout<<cnt<<' '<<t<<endl;
        if (cnt == t)
        {
            ans++;
            for (int j = 0; j < len; j++)
            {   
                Insert(g[0], g[j]);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

 总结

总结反思的太晚了 已经不知道当时特别注意的点是什么了 还是继续努力吧~ 

 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值