CCF 202012-3 带配额的文件系统 CCF 202012-4 食材运输 CCF 202012-5 星际旅行

这篇博客探讨了CCF 202012的三个问题,分别是带配额的文件系统、食材运输和星际旅行。在文件系统问题中,重点解决服务器训练模型时的显存限制;食材运输问题通过枚举和深度优先搜索寻找最优配送方案;星际旅行问题涉及线段树算法的应用。
摘要由CSDN通过智能技术生成

CCF 202012-3 带配额的文件系统

在这里插入图片描述

思路

关于机器学习中使用服务器训练模型时显存消耗过大问题,给每个人限额空间。
给根目录,子目录,文件限制存储空间,执行一些列操作

代码实现

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
typedef long long LL;
const int N = 2000010;

int n;
struct Node
{
   
    string name;
    int id, type;  // type == 0: 文件夹;type == 1:文件
    mutable LL ld, lr;
    mutable LL sd, sr;
    bool operator< (const Node& t) const
    {
   
        return name < t.name;
    }
};
set<Node> son[N];
int idx;
char str[N];
bool F;
int U;
LL SZ;

vector<string> get(char* str)
{
   
    vector<string> res(1, "root");
    for (int i = 0; str[i]; i ++ )
    {
   
        if (str[i] == '/') continue;
        string s;
        int j = i;
        while (str[j] && str[j] != '/') s += str[j ++ ];
        res.push_back(s);
        i = j - 1;
    }

    return res;
}

LL dfs_remove(vector<string>& t, int u, int p)
{
   
    string name = t[u];
    if (!son[p].count({
   name})) return -1;
    auto it = son[p].find({
   name});
    if (u == t.size() - 1)
    {
   
        if (it->type) t[u] = "#file";
        auto sz = it->sr;
        son[p].erase(it);
        return sz;
    }
    if (it->type) return -1;
    auto sz = dfs_remove(t, u + 1, it->id);
    if (sz >= 0)
    {
   
        it->sr -= sz;
        if (t[u + 1] == "#file") it->sd -= sz;
    }
    return sz;
}

bool dfs_create(vector<string>& t, int u, int p, LL sz)
{
   
    string name = t[u];
    if (u == t.size() - 1)
    {
   
        if (son[p].count({
   name}))
        {
   
            auto it = son[p].find({
   name});
            if (it->type == 0) return false;
            SZ = dfs_remove(t, 0, 0);
            Node cur{
   name, ++ idx, 1, 0, 0, 0, sz};
            son[p].insert(cur);
            return true;
        }
        else
        {
   
            Node cur{
   name, ++ idx, 1, 0, 0, 0, sz};
            son[p].insert(cur);
            return true;
        }
    }
    else
    {
   
        if (!son[p].count({
   name}))
        {
   
            if (U == -1) U = u;
            Node cur{
   name, ++ idx, 0, 0, 0, 0, 0};
            son[p].insert(cur);
        }

        auto it = son[p].find({
   name});
        if (it->type) return false;
        auto res = dfs_create(t, u + 1, it->id, sz);
        if (res)
        {
   
            it->sr += sz;
            if (u 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值