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 HDU5521
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 ...
随机推荐
- Linux命令之rlogin
rlogin [-8EKLdx] [-e char] [-l username] host rlogin在远程主机host上开始一个终端会话. (1).选项 -8 选项允许进行8位的输入数据传送:否则 ...
- NGUI EventDelagate事件委托
using System.Collections; using System.Collections.Generic; using UnityEngine; public class BUttonCl ...
- 安卓 内存泄漏 MemoryAnalyzer
韩梦飞沙 yue31313 韩亚飞 han_meng_fei_sha 313134555@qq.com 需要 获取 root 权限 步骤: 1,使用eclipse 自带的 DDMS 工具分析各线程的内 ...
- 输入sql语句,将结果写入到xml文件
import java.io.FileOutputStream; import java.sql.Connection; import java.sql.DriverManager; import j ...
- css3背景属性 background-size 对背景图进行缩小放大
background-size需要两个值,它的类型可以是像素(px).百分比(%)或是auto,还可以是cover和contain.第一个值为背景图的width,另外一个值用于指定背景图上的heigh ...
- ps制作导航条 分割线技巧
1 用矩形工具画一个像素的矩形(注意不是路径) 2给矩形添加蒙版,用渐变工具对其进行渐变,达到两头渐隐藏的效果. 制作按钮技巧 用矩形工具画出矩形 然后给矩形添加 内发光 渐变叠加 光泽 描边等操作 ...
- 新浪微博(t.sina)简单授权代码及API测试
http://www.eoeandroid.com/thread-53701-1-1.html package mobson.weiboku.view; import java.util.ArrayL ...
- WPF中的动画——(五)关键帧动画
与 From/To/By 动画类似,关键帧动画以也可以以动画形式显示目标属性值. 和From/To/By 动画不同的是, From/To/By 动画只能控制在两个状态之间变化,而关键帧动画则可以在多个 ...
- TSynAuthentication SESSION验证
TSynAuthentication SESSION验证 服务端维护的SESSIONS,实质上是一个array of integer,保存的是客户端的SESSIONID. SESSIONID可以由客户 ...
- 16.同步类容器Collections.synchronized
voctor动态数组.同步类容器,底层实现基于:Collections.synchronized package demo5; import java.util.ArrayList; import j ...