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 ...
随机推荐
- 洛谷——P1346 电车
P1346 电车 题目描述 在一个神奇的小镇上有着一个特别的电车网络,它由一些路口和轨道组成,每个路口都连接着若干个轨道,每个轨道都通向一个路口(不排除有的观光轨道转一圈后返回路口的可能).在每个路口 ...
- 洛谷——P1680 奇怪的分组
P1680 奇怪的分组 题目背景 终于解出了dm同学的难题,dm同学同意帮v神联络.可dm同学有个习惯,就是联络同学的时候喜欢分组联络,而且分组的方式也很特别,要求第i组的的人数必须大于他指定的个数c ...
- 子查询在DELETE语句中的应用
子查询在DELETE 中唯一可以应用的位置就是WHERE 子句,使用子查询可以完成复杂的数据删除控制.其使用方式与SELECT 语句中的子查询基本相同,而且也可以使用相关子查询等高级的特性.下面的SQ ...
- 【POJ 2409】 Let it Bead(置换、burnside引理)
Let it Bead "Let it Bead" company is located upstairs at 700 Cannery Row in Monterey, CA. ...
- 【BZOJ 1901】【ZJU 2112】Dynamic Rankings
http://www.lydsy.com/JudgeOnline/problem.php?id=1901 重新用整体二分写了一下. 整体二分的思想详见论文. 貌似带修区间k大和静态区间k大都是\(O( ...
- 【UOJ #279】【UTR #2】题目交流通道
http://uoj.ac/problem/279 先判断答案为0的情况,\(d(i,i)\neq 0\),\(d(i,j)\neq d(j,i)\),\(d(i,j)>d(i,k)+d(k,j ...
- 【计算几何】【分类讨论】Gym - 101173C - Convex Contour
注意等边三角形的上顶点是卡不到边界上的. 于是整个凸包分成三部分:左边的连续的三角形.中间的.右边的连续的三角形. 套个计算几何板子求个三角形顶点到圆的切线.三角形顶点到正方形左上角距离啥的就行了,分 ...
- Java异步编程——深入源码分析FutureTask
Java的异步编程是一项非常常用的多线程技术. 之前通过源码详细分析了ThreadPoolExecutor<你真的懂ThreadPoolExecutor线程池技术吗?看了源码你会有全新的认识&g ...
- Mysql五种时间格式
YEAR [字节数]:1 [取值范围]:1901~2155 [赋值]: 4位数字 2位字符串:'00'~'69'相当于2000~2069:'70'~'99'相当于1970~1999 2位数字:与2位数 ...
- win7 64位 php环境开启curl服务Call to undefined function
无法使用curl_init(),一般情况问题可能出在没有去加载php的扩展文件php_curl.dll(windows操作系统),但是检查了一下系统配置,发现,环境下已经将php.ini文件里 ;ex ...