【链接】 我是链接,点我呀:)

【题意】

火车从1,2,3...n->1的方式绕圈走。(即每次从i走到i+1)
有一些点有货物需要装载,但是每个点只能装上去一个货物。
每个货物都有目标点卸货点(卸货的时候不限量)
问你假设火车起点为s(s=1,2,3...n)时,完成所有点的装货卸货任务需要的最小时间。

【题解】

会发现其实每个点出去的任务都是互相独立的。
某个点在做运载任务的时候,其他人也可以同时进行运载任务(路过了就捎上它的运载物就行,反正装运不需要时间)。
那么现在的问题仅仅是,让每个点完成所有任务的时间最短。
然后取所有点完成任务的时间中最长的那个作为答案就好了。
设第i个点的任务个数为cnt[i]
每个点i完成所有任务的时间为
起点s到i所需的时间+n*(cnt[i]-1)+cnt[i]个任务中所需时间最短的那个任务所用时间
前cnt[i]-1个任务肯定要绕cnt[i]-1圈然后回到原来的位置的.
最后一个任务才是关键,我们只要让最后一个任务的时间最短,那么肯定第i个点的所有任务完成的时间也就最短了。

【代码】

#include <bits/stdc++.h>
#define ll long long
using namespace std; const int N = 5000; int n,m;
int mi[N+10],cnt[N+10]; int get_dis(int x,int y){
if (y>=x) return y-x;
else return y+n-x;
} int main(){
ios::sync_with_stdio(0),cin.tie(0);
cin >>n >> m;
for (int i = 1;i <= m;i++){
int x,y;
cin >> x >> y;
cnt[x]++;
if (mi[x]==0)
mi[x]=get_dis(x,y);
else
mi[x] = min(mi[x],get_dis(x,y));
}
for (int i = 1;i <= n;i++){
int ans = 0;
for (int j = 1;j<=n;j++){
ans = max(ans,get_dis(i,j)+n*(cnt[j]-1)+mi[j]);
}
cout<<ans<<" ";
}
return 0;
}

【Codeforces 1129A】Toy Train的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【50.00%】【codeforces 602C】The Two Routes

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. 【33.33%】【codeforces 586D】Phillip and Trains

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  5. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  6. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  7. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  8. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  9. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

随机推荐

  1. Rails5入门

    更新: 2017/05/29 更新: 2017/09/07 补充对ruby自身的扩张的放置位置  配置文件位置  /config/routes.rb  最简单的定义方法  get ('hello/in ...

  2. Python网咯爬虫 — Scrapy框架应用

    Scrapy框架       Scrapy是一个高级的爬虫框架,它不仅包括了爬虫的特征,还可以方便地将爬虫数据保存到CSV.Json等文件中.       Scrapy用途广泛,可以用于数据挖掘.监测 ...

  3. 清北考前刷题da5下午好

    /* (4,1)*(3,1)*(2,1)的话1变成2然后一直是2 2变成1然后变成3 3变成1然后变成4 4变成1 */ #include<iostream> #include<cs ...

  4. 基于.Net Core的API框架的搭建(4)

    6.加入日志功能 日志我们选用log4net,首先引入程序包: 选择2.0.8版本安装.然后在项目根目录新增log4net的配置文件log4net.config: <?xml version=& ...

  5. css为tbody或者li奇数偶数行样式

    <style> table tbody tr:nth-child(odd){ background:#fff; } table tbody tr:nth-child(even){ back ...

  6. SimpleDataFormat详解

    [转]SimpleDateFormat使用详解 public class SimpleDateFormat extends DateFormat SimpleDateFormat 是一个以国别敏感的方 ...

  7. GAN生成图像论文总结

    GAN Theory Modifyingthe Optimization of GAN 题目 内容 GAN   DCGAN   WGAN   Least-square GAN   Loss Sensi ...

  8. docloud后台管理项目(开篇)

    最近朋友做app需要web做后台管理,所以花了一周时间做了这个项目. 废话不多说,开发环境是nginx+php5.3,使用thinkphp框架.是一个医疗器械数据统计的后台,业务功能很简单就是查看用户 ...

  9. HDU_2955_Robberies_01背包

    A - Robberies Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submi ...

  10. 大数除法(除数在int范围内)

    #include<iostream> #include<cstdio> #include<cstring> #define N 1000 using namespa ...