CF1129A2 Toy Train

news/2025/2/12 3:29:10/

当一个车站如果有最多的糖果数x,那么跑x-1圈就能让前面x-1个糖果放到相应的地方,如果想让这时候跑的站数最少,那么最后一个应该放最近的糖果。

如果当前这个车站a并不是最多的糖果数,但是要跑的最少站数取决于拥有最多糖果数的站点b。(只有最多糖果数的站点跑完了才能全部跑完)

所以我们先让a到b就可以了。(也就是加上a-b的距离)

最后我们枚举每个车站作为起始点,再枚举这个车站到另一个车站的距离,最后每次取最大输出

#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=6e3;
typedef long long LL;
vector<LL>candy[maxn];
LL dis[maxn]; 
LL n,m;
int main(void)
{cin.tie(0);std::ios::sync_with_stdio(false);cin>>n>>m;memset(dis,0x3f,sizeof(dis));for(LL i=1;i<=m;i++) {LL a,b;cin>>a>>b;candy[a].push_back(b);dis[a]=min(dis[a],(b-a+n)%n);}for(LL i=1;i<=n;i++){LL sum=0;LL ans=0;for(LL j=1;j<=n;j++){if(candy[j].size()==0) continue;sum=(j-i+n)%n+(candy[j].size()-1)*n+dis[j]; ans=max(ans,sum);}cout<<ans<<" ";}    cout<<endl;
return 0;
}

http://www.ppmy.cn/news/536264.html

相关文章

JS12

12 BOM Broswer Object Model 12.1 常用对象 window&#xff08;窗口&#xff09;&#xff0c;浏览器的窗口 var a 1; function test(){ var a 2; alert(a); alert(window.a); } 全局变量window的属性&#xff0c;全局函数window的方法 浏览器body的宽度&a…

js2c#

http://www.m2h.nl/files/js_to_c.php

CF12B Correct Solution?

题目描述 One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alices turn, she told the number nn to Bob and said: —Shuffle the digits in this num…

C1.2

任务内容 规划⼀个C类IP地址&#xff0c;例如使用子网掩码将IP地址192.168.99.0&#xff5e;192.168.99.255划分成四个子网&#xff08;可以从8位主机号中借用几位作为子网号&#xff09;&#xff0c;并使之能互联互通 解答&#xff1a;由于给的网络地址是C类地址&#xff0c…

ccy

start12345 asdfghj wwww end67890

Product of Three Numbers(CF-1294C)

Problem Description You are given one integer number n. Find three distinct integers a,b,c such that 2≤a,b,c and a⋅b⋅cn or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. …

CF1042C Array Product

原题链接&#xff1a;http://codeforces.com/contest/1042/problem/C Array Product You are given an array a a a consisting of n n n integers. You can perform the following operations with it: Choose some positions i i i and j ( 1 ≤ i , j ≤ n , i ≠ j )…