Codeforces Round 542 (Div. 2)
layout: post
title: Codeforces Round 542 (Div. 2)
author: "luowentaoaa"
catalog: true
tags:
mathjax: true
- codeforces
- 并查集
---
傳送門
前三題太簡單不寫
D.Toy Train (貪心)
題意
有n個車站,按照環(huán)前進,有m條要求從x送到y(tǒng),每次從x最多能拿一個糖,輸出在第i個車站出發(fā)最少需要多少時間完成所有要求 (注意車的容量無窮)
思路
所以我們直接枚舉每個點就行了啊。。。找到一個花費最多的點 把他送完答案就出來了 當然在送他的時候順便把其它的都送了所以貪心的策略就是最后送少的。
#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll mod=1e9+7; const int maxn=5e4+50; const ll inf=0x3f3f3f3f3f3f3f3fLL; ll num[maxn],len[maxn]; int main() {std::ios::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0);ll n,m;cin>>n>>m;fill(len,len+maxn,inf);while(m--){ll a,b;cin>>a>>b;num[a]++;if(a<b)len[a]=min(len[a],b-a);else len[a]=min(len[a],n-a+b);}for(int i=1;i<=n;i++){if(num[i]==0)len[i]=0;}for(int i=1;i<=n;i++){ll ans=0;for(int j=1;j<=n;j++){ll dis=(j>=i)?j-i:n-i+j;dis+=(num[j]-1ll)*n+len[j];ans=max(ans,dis);}cout<<ans<<" ";}return 0; }E.Wrong Answer
題意
構造題,這里有一段代碼:它只會記錄和為非負數(shù)的一段數(shù)乘以其區(qū)間長度的最大值,但我們現(xiàn)在要求的是sum{ai}*(r-l+1),l<=i<=r,很明顯這段代碼是有錯誤的。
然后會輸入一個k,你構造一組數(shù)據(jù),使得正解和這段代碼給出的答案相差k。最后輸出你給出的數(shù)據(jù)。
思路
假設前面1998個a[i]的值為0,倒二的值為-p,最后一個的值為d+p;然后正解的答案是2000*d
題目的答案的d+p 相差為2000d-(d+p)=K;
1999d=k+p;
d=(k+p)/1999
令d=1999-k%19;
轉(zhuǎn)載于:https://www.cnblogs.com/luowentao/p/10434582.html
總結
以上是生活随笔為你收集整理的Codeforces Round 542 (Div. 2)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: .NET MVC 学习笔记(一)— 新建
- 下一篇: WinForm -- 为TextBox文