2015 ICPC 沈阳站M题
Time Limit:6000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
cid=113817#status//M/0" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" style="display:inline-block;padding:0px;margin-right:.1em;vertical-align:middle;overflow:visible;text-decoration:none;font-family:Verdana, Arial, sans-serif;font-size:1em;border:1px solid rgb(211,211,211);color:rgb(85,85,85);">Status Practice HDU
5521
System Crawler (2016-04-18)
Description
fences they were separated into different blocks. John's farm are divided into
rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .003em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" /> blocks
labelled from
rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .06em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" /> to .
Bessie lives in the first block while Elsie lives in the -th
one. They have a map of the farm
which shows that it takes they minutes
to travel from a block in to
another block
in where
rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .06em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" />
rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .117em 0px 0px;min-width:0px;min-height:0px;vertical-align:-3px;display:inline !important;float:none !important;" /> is
a set of blocks. They want to know how soon they can meet each other
and which block should be chosen to have the meeting.
Input
rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px -.111em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" />
rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px -.111em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" />
rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .117em 0px 0px;min-width:0px;min-height:0px;vertical-align:-3px;display:inline !important;float:none !important;" />
rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .117em 0px 0px;min-width:0px;min-height:0px;vertical-align:-5px;display:inline !important;float:none !important;" />,
the number of test cases. Then
rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px -.111em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" /> test
cases
follow.
The first line of input contains and
.
rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .06em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" />
rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .003em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" />
rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .117em 0px 0px;min-width:0px;min-height:0px;vertical-align:-3px;display:inline !important;float:none !important;" />
rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .06em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" />
rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .06em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" />.
The following lines
describe the sets
rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .003em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" />
rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .288em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" />
rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .117em 0px 0px;min-width:0px;min-height:0px;vertical-align:-3px;display:inline !important;float:none !important;" />
rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .117em 0px 0px;min-width:0px;min-height:0px;vertical-align:-3px;display:inline !important;float:none !important;" />.
Each line will contain two integers
rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .06em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" />
rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .06em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" />
rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .06em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" /> and
rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .06em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" />
rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px -.054em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" />
rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .06em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" /> firstly.
Then integer
follows which are the labels of blocks in .
It is guaranteed that
rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .003em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" />
rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .06em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" />
rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .06em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" />
rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .117em 0px 0px;min-width:0px;min-height:0px;vertical-align:-3px;display:inline !important;float:none !important;" />
rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .06em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" />.
Output
Otherwise, output two lines. The first line contains an integer, the time it takes for they to meet.
The second line contains the numbers of blocks where they meet. If there are multiple
optional blocks, output all of them in ascending order.
Sample Input
5 4
1 3 1 2 3
2 2 3 4
10 2 1 5
3 3 3 4 5
3 1
1 2 1 2
Sample Output
3 4
Case #2: Evil John
Hint
- In the first case, it will take Bessie 1 minute travelling to the 3rd block, and it will take Elsie 3 minutes travelling to the 3rd block. It will take Bessie 3 minutes travelling to the 4th block, and it will take Elsie 3 minutes travelling to the 4th block. In the second case, it is impossible for them to meet.
题意
有 N个点 n<=100000 ,m《=10000个集合。在同一个集合中的人意两个点的距离都相等,不同的集合时间不一定同样。 一个人从1 出发,一个人从n出发求 二人相遇的最时间
思路:
假设按普通的写法 则须要建立非常多的边。边太多是存不下的,所以要缩图,缩图的方法
这样就能够了 。保证了集合内的点人意点都是time 哈
可是 使用普通的SPFA 就会超时!!QAQ
须要是用 dijktra + 优先队列
套了个最短路优化模版 就能够了
- #include <queue>
- #include <vector>
- #include <cstdio>
- #include <cstring>
- #include <iostream>
- #include <algorithm>
- #define pb push_back
- #define mp make_pair
- #define sz(x) ((int)(x).size())
- using namespace std;
- const int N = 1000100*2;
- const long long INF = 1e18;
- int n, m;
- long long dis[N];
- long long dis1[N];
- long long dis2[N];
- long long f[N];
- bool vis[N];
- struct Node
- {
- long long d;
- int e;
- bool operator < (const Node x) const
- {
- return x.d < d;
- }
- Node(long long d, int e):d(d), e(e) {}
- };
- vector<pair<int,long long > > V[N];
- void dijkstra(int s)
- {
- priority_queue<Node> q;
- fill(dis + 1, dis + n+2*m + 1, INF);
- fill(vis + 1, vis + n+2*m + 1, false);
- q.push(Node(0, s));
- dis[s] = 0;
- while(!q.empty())
- {
- Node deq = q.top();
- q.pop();
- if(vis[deq.e])
- continue;
- vis[deq.e] = true;
- for(int i = 0; i < sz(V[deq.e]); i++)
- {
- int e = V[deq.e][i].first;
- long long w = V[deq.e][i].second;
- if(dis[deq.e] < dis[e] - w)
- {
- dis[e] = dis[deq.e] + w;
- q.push(Node(dis[e], e));
- }
- }
- }
- }
- void add_edge(int a,int b,long long c)
- {
- V[a].push_back(make_pair(b, c));
- }
- long long max(long long a,long long b)
- {
- if(a>b)
- return a;
- return b;
- }
- long long min(long long a,long long b)
- {
- if(a>b)return b;
- return a;
- }
- int main()
- {
- int T;
- scanf("%d",&T);
- int CASE=1 ;
- while(T--)
- {
- scanf("%d%d",&n,&m);
- int fc = n+1;
- for(int i = 1; i<=n+m*2+1; i++)
- V[i].clear();
- long long time ;
- int y;
- for(int i = 1; i<=m; i++)
- {
- scanf("%lld%d",&time,&y);
- int temp ;
- for(int j = 1; j<=y; j++)
- {
- scanf("%d",&temp);
- add_edge(temp,fc,0);
- add_edge(fc+1,temp,0);
- }
- add_edge(fc,fc+1,time);
- fc+=2;
- }
- dijkstra(1);
- memcpy(dis1,dis,sizeof(dis));
- dijkstra(n);
- memcpy(dis2,dis,sizeof(dis));
- long long minv = INF;
- for(int i =1 ; i<=n; i++)
- {
- f[i] = max(dis1[i],dis2[i]);
- minv = min(minv,f[i]);
- }
- printf("Case #%d: ",CASE++);
- if(minv>=INF)
- {
- printf("Evil John\n");
- }
- else
- {
- printf("%lld\n",minv);
- int flagc = 0;
- for(int i = 1; i<=n; i++)
- {
- if(f[i]==minv)
- {
- if(!flagc)
- {
- printf("%d",i);
- flagc = 1;
- }
- else
- printf(" %d",i);
- }
- }
- printf("\n");
- }
- }
- return 0;
- }
2015 ICPC 沈阳站M题的更多相关文章
- 2016 ICPC青岛站---k题 Finding Hotels(K-D树)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5992 Problem Description There are N hotels all over ...
- 2015 ACM-ICPC 沈阳站
题目链接 2015 ACM-ICPC Shenyang Problem A Problem B Problem C Problem D 签到题,所有gcd的倍数都可以被写出来. 那么判断一下这类数的 ...
- 2016 ACM/ICPC 沈阳站 小结
铜铜铜…… 人呐真奇怪 铁牌水平总想着运气好拿个铜 铜牌水平总想着运气好拿个银 估计银牌的聚聚们一定也不满意 想拿个金吧 这次比赛挺不爽的 AB两道SB题,十分钟基本全场都过了 不知道出这种题有什么意 ...
- 2020ICPC沈阳站C题 Mean Streets of Gadgetzan
大致题意 原题链接 翻译 \(有n个逻辑变量 请你分别对它们赋值 使其满足m个命题\) \(命题有四种格式:\) 单独数字x 表示第x个逻辑变量为真 ! + 数字x 表示第x个逻辑变量为假 若干个数字 ...
- 2020 ICPC 沈阳站 I - Rise of Shadows 题解
题面看这里 \(PS\):符号 \([\ \rm P\ ]\) 的意义是:当表达式 \(\rm P\) 为真则取值为 \(1\),为假则取值为 \(0\). 题目大意 给你一个一天有 \(H\) ...
- 2016 ICPC大连站---F题 Detachment
题意:输入一个x,将x拆分成一些小的数(这些数不能相同,即x=a1+a2+...... ai!=aj when i!=j),然后这些数相乘得到一个成积(s=a1*a2*......),求最大的乘积 ...
- HDU 5950Recursive sequence ICPC沈阳站
Recursive sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- 2016ACM/ICPC亚洲区沈阳站-重现赛赛题
今天做的沈阳站重现赛,自己还是太水,只做出两道签到题,另外两道看懂题意了,但是也没能做出来. 1. Thickest Burger Time Limit: 2000/1000 MS (Java/Oth ...
- HDU 5948 Thickest Burger 【模拟】 (2016ACM/ICPC亚洲区沈阳站)
Thickest Burger Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
随机推荐
- 解决CDH的web界面使用nginx代理一些静态文件无法加载
vim /opt/cm-/share/cmf/webapp/WEB-INF/spring/mvc-config.xml .... 注释此行 <bean class="com.cloud ...
- Git Bash 将本地代码提交到Github
前提:已拥有Token,并且把本地的Token配置到了自己的Github里面(没有Token的自行去百度如何配置Token) 测试一下自己的连接 ssh -T git@github.com 本地操作: ...
- 【概率dp】【滚动数组】CDOJ1652 都市大飙车
转移方程很显然. 因为是多段图模型,所以可以滚动数组优化一维空间. #include<cstdio> #include<cstring> using namespace std ...
- UVA 12284 Digital Matrix
思路:这个分清楚情况就很好做了. 注意一点当A的转置等于B的时候(对角线除外),记录A的下三角(或上三角)有cnt个的数与B不同,如果cnt>1则 不需要额外的步数就可以了,否则当k==2时结果 ...
- Token-Pasting Operator (##) and Stringizing Operator (#)
Token-Pasting Operator (##)The double-number-sign or “token-pasting” operator (##), which is sometim ...
- mongodb安装和配置,遇到问题和解决方法
自己不知道怎么的,心血来潮想重新来安装和配置一下mongodb,之前自己也是按照别人的来整的,印象不深刻.第二遍安装配置遇到很多问题. 弄了两个多小时,期间遇到很多问题: 遇到的主要问题 1.拒绝访问 ...
- Educational Codeforces Round 9 D. Longest Subsequence dp
D. Longest Subsequence 题目连接: http://www.codeforces.com/contest/632/problem/D Description You are giv ...
- java多线程处理导入数据拆分List集合 同步处理插入数据
原文:https://www.2cto.com/kf/201612/581174.html import org.apache.log4j.Logger; import org.apache.poi. ...
- cmd复制粘贴
右击菜单栏,选择“快速编辑模式” 复制:选择文本后按回车,然后就可以去其他地方粘贴了 粘贴:右击鼠标就可以粘贴内容 简单到都不好意思发布出来了....
- this和$(this)的关系
环境关键字this引用的是DOM元素 $(this)是jQuery对象 下面点击按钮分别alert一下 alert(this); alert($(this)); 获取DOM对象的属性id,可以 $(t ...