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

【题意】

火车从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. IE6的3像素BUG产生条件及解决方法

    1.IE6中第一个元素浮动第二个元素不浮动,这两个元素之间就会产生3像素BUG 2.解决方案: 2.1若若宽度一定则给第二个元素添加 float 样式即可: 2.2若宽度自适应: 2.2.1  _ma ...

  2. bzoj4506: [Usaco2016 Jan]Fort Moo(暴力)

    4506: [Usaco2016 Jan]Fort Moo Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 145  Solved: 104[Submi ...

  3. 公司4:JrVue主题定制

    JrVue是我们基于element重新封装的一套组件库;  具体组件使用方法可以mnote->研发小组查看; 这里我们定制了一套主题色, 具体变动如下: 1.主题色变动: mfront有蓝.紫. ...

  4. 乐搏讲自动化测试- Python自动化测试前景怎么样(4)

    Python言语还能够写爬虫,但仅仅只是爬虫的入门罢了.通过Python入门爬虫比较简略易学,不需要在一开始把握太多太根底太底层的常识就能够很快上手,而且很快能够做出成果,十分合适小白一开始想做出点看 ...

  5. 【原创】Eclipse实现图形化界面插件-vs4e

    vs4e插件下载地址:http://visualswing4eclipse.googlecode.com/files/vs4e_0.9.12.I20090527-2200.zip 下载完成后,解压,然 ...

  6. 2、ipconfig命令

    该命令能够显示出正在使用的计算机的IP信息情况.这些信息包括IP地址.子网掩码.默认网关(连接本地计算机与Internet的计算机).通过IP地址可以进行扫描.远程管理.入侵检测等.ipconfig命 ...

  7. jQuery学习笔记(2)-选择器的使用

    一.选择器是什么 有了jQuery的选择器,我们几乎可以获取页面上任意一个或一组对象 二.Dom对象和jQuery包装集 1.Dom对象 JavaScript中获取Dom对象的方式 <div i ...

  8. CF861B Which floor?

    思路: 暴力枚举. 实现: #include <bits/stdc++.h> using namespace std; int n, m, x, y; bool check(int x, ...

  9. python自动化--模块操作之re、MySQL、Excel

    一.python自有模块正则 import re # re.match只匹配字符串的开始,如果字符串开始不符合正则表达式,则匹配失败,函数返回None print(re.match("www ...

  10. 【译】x86程序员手册25-7.1任务状态段

    7.1 Task State Segment 任务状态段 All the information the processor needs in order to manage a task is st ...