Codeforces854D Jury Meeting

本文介绍了一种解决旅行者问题的算法,通过将路径分为两类并分别处理,使用动态规划方法来确定最少花费及最短停留时间。文章详细阐述了算法实现思路与步骤,并提供了完整的代码示例。

题意:告诉你有n+1个城市,标号0-n,0号是个中心,然后其他n个点每个有一个智障他们都要到0点然后他们n个智障需要在0点至少共同py k天,然后再各自飞回各自原来的城市,飞机要么从0飞到一个城市,要么从一个城市飞到0
题解:我觉得我已经彻底咸鱼了,,,C做了贼久还是队友点了一下才觉得那么简单,,看D的时候已经有点放弃了=-=看题就在瞎看没看到加粗的那句话,感觉血崩。。其实已经想到了相当于两个过程,一个是从0到各个点,还有一个是从各个点到0,那么我们把边分成两类,一个是去0的一个是从0出来的。
那么很明显我们对两类边分别操作就好了。其实我也想到了遍历天数然后把两部分接起来但是。。。我也不造我在想什么反正混了最后20分钟QWQ
那么我们来总结一下QWQ
首先我们把变分成两类,一类是从其他城市到0的另一类是从0到其他城市的。我们先把每类边按照日期排序。设dp[i]是到如果第i天人到齐所需要的最小花费。这个dp[i]有两个要求,第一个是人到齐,第二个是最小。那么我们便利时间然后如果当前这个边的日期是当前日期的,那么我们进行判断,这个点有没有到过0,没有到过说明从这天以后可以到的人又多了一个,如果这个人到过,那么判断这个的人开销有没有变,如果变小了,更新一下这个人的开销,保证dp[i]里面的值是最小的。
那么我们发现从其他城市到0这个过程和从0到其它城市这个过程是相似的,只要倒着扫一遍就行了。那么我们用另一个数组存,之后我们的最终答案关注两个时间点第一个是第i天,这天是人到齐的天,第二个是i+k+1天这个天是开始有人走的天。如果第i天可以到齐并且第i+k+1天开始走可以走完那么我们更新一次答案。
我们设dp[i][0] 是第i天人到齐所需要的最小费用
dp[i][1]是第i天人开始走所需要的最小费用

#include<bits/stdc++.h>
using namespace std;

//thanks to pyf ...
//thanks to qhl ...
const int N = 1e6 + 7;
struct Edge
{
    int d, u, c;
    bool operator < (const Edge &rhs) const
    {
        return d < rhs.d;
    }
};
vector<Edge> from0, to0;
long long dp[N][2];
long long cost[N];
int main()
{
    ios :: sync_with_stdio(false);
    int n, m, k;
    while (cin >> n >> m >> k)
    {
        from0.clear(), to0.clear();
        memset(dp, -1, sizeof(dp));
        for (int i = 0; i < m; i++)
        {
            int d, f, t, c;
            cin >> d >> f >> t >> c;
            if (f == 0)
                from0.push_back({d, t, c});
            else
                to0.push_back({d, f, c});
        }
        sort(from0.begin(), from0.end());
        sort(to0.begin(), to0.end());
        memset(cost, -1, sizeof(cost));
        int l = 0;
        long long temp = 0;
        int sz = 0;
        for (int i = 1; i <= 1e6; i++)
        {
            while (l < to0.size() && to0[l].d == i)
            {
                int u = to0[l].u, c = to0[l].c;
                if (cost[u] == -1)
                {
                    sz ++ ;
                    cost[u] = c;
                    temp += c;
                }
                else if (cost[u] > c)
                {
                    temp -= (cost[u] - c);
                    cost[u] = c;
                }
                l ++ ;
            }
            if (sz == n)
                dp[i][0] = temp;
        }
        l = from0.size() - 1, sz = 0;
        temp = 0;
        memset(cost, -1, sizeof(cost));
        for (int i = 1e6; i >= 1; i--)
        {
            while (l >= 0 && from0[l].d == i)
            {
                int u = from0[l].u , c = from0[l].c;
                if (cost[u] == -1)
                {
                    sz ++;
                    cost[u] = c;
                    temp += c;
                }
                else if (cost[u] > c)
                {
                    temp -= (cost[u] - c);
                    cost[u] = c;
                }
                l --;
            }
            if (sz == n)
                dp[i][1] = temp;
        }
        long long ans = -1;
        for (int i = 1; i <= 1e6; i++)
        {
            if (dp[i][0] != -1 && i + k + 1 <= 1e6 && dp[i + k + 1][1] != -1)
            {
                if (ans == -1)
                    ans = dp[i][0] + dp[i + k + 1][1];
                else
                    ans = min(ans, dp[i][0] + dp[i + k + 1][1]);
            }
        }
        printf("%lld\n", ans);
    }
}
### Codeforces 1487D Problem Solution The problem described involves determining the maximum amount of a product that can be created from given quantities of ingredients under an idealized production process. For this specific case on Codeforces with problem number 1487D, while direct details about this exact question are not provided here, similar problems often involve resource allocation or limiting reagent type calculations. For instance, when faced with such constraints-based questions where multiple resources contribute to producing one unit of output but at different ratios, finding the bottleneck becomes crucial. In another context related to crafting items using various materials, it was determined that the formula `min(a[0],a[1],a[2]/2,a[3]/7,a[4]/4)` could represent how these limits interact[^1]. However, applying this directly without knowing specifics like what each array element represents in relation to the actual requirements for creating "philosophical stones" as mentioned would require adjustments based upon the precise conditions outlined within 1487D itself. To solve or discuss solutions effectively regarding Codeforces' challenge numbered 1487D: - Carefully read through all aspects presented by the contest organizers. - Identify which ingredient or component acts as the primary constraint towards achieving full capacity utilization. - Implement logic reflecting those relationships accurately; typically involving loops, conditionals, and possibly dynamic programming depending on complexity level required beyond simple minimum value determination across adjusted inputs. ```cpp #include <iostream> #include <vector> using namespace std; int main() { int n; cin >> n; vector<long long> a(n); for(int i=0;i<n;++i){ cin>>a[i]; } // Assuming indices correspond appropriately per problem statement's ratio requirement cout << min({a[0], a[1], a[2]/2LL, a[3]/7LL, a[4]/4LL}) << endl; } ``` --related questions-- 1. How does identifying bottlenecks help optimize algorithms solving constrained optimization problems? 2. What strategies should contestants adopt when translating mathematical formulas into code during competitive coding events? 3. Can you explain why understanding input-output relations is critical before implementing any algorithmic approach? 4. In what ways do prefix-suffix-middle frameworks enhance model training efficiency outside of just tokenization improvements? 5. Why might adjusting sample proportions specifically benefit models designed for tasks requiring both strong linguistic comprehension alongside logical reasoning skills?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值