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 ...
随机推荐
- EasyUI学习总结(五)——EasyUI组件使用(转载)
本文转载自:http://www.cnblogs.com/xdp-gacl/p/4084520.html 一.EasyUI组件的简单介绍 easyUI提供了很多组件让我们使用,如下图所示:
- 【BZOJ 1060】 1060: [ZJOI2007]时态同步 (树形DP)
1060: [ZJOI2007]时态同步 Description 小Q在电子工艺实习课上学习焊接电路板.一块电路板由若干个元件组成,我们不妨称之为节点,并将其用数 字1,2,3….进行标号.电路板的各 ...
- rxjava 视频
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha Rxjava-基础篇视频教程-Rxjava框架的使用-麦子学院 它的自我介绍,我们可以理 ...
- css-移动&缩放元素
transform 属性向元素应用 2D 或 3D 转换.该属性允许我们对元素进行旋转.缩放.移动或倾斜. 用法:object.style.transform="rotate(7deg)&q ...
- 【BZOJ 3166】【HEOI 2013】Alo
http://www.lydsy.com/JudgeOnline/problem.php?id=3166 这道题难点在于求能对一个次大值有贡献的区间. 设这个次大值为\(a_i\),\(a_i\)左边 ...
- xtuoj 1233 coins(dp)
Coins Accepted : 120 Submit : 305 Time Limit : 1000 MS Memory Limit : 65536 KB Coins Problem Des ...
- [TCO2013]DirectionBoard
题意:给一个网格,每个格子有一个方向表示在这个格子上要往哪个方向走,你可以改变某些格子的方向,问最少多少次操作使得从任意格子出发都能回到这个格子 woc这都不会我还是回家种田去吧... 题目的要求是改 ...
- 【最大权森林/Kruskal】POJ3723-Conscription
[题目大意] 招募m+n个人每人需要花费$10000,给出一些关系,征募某个人的费用是原价-已招募人中和他亲密值的最大值,求最小费用. [思路] 人与人之间的亲密值越大,花费越少,即求出最大权森林,可 ...
- 查询续与ajax
查询分组 事例:统计不止一个作者的图书:(作者数量大于一) Book.objects.all().values('name').annotate(author_num=Count('authors__ ...
- js知识-进阶
1 DOM 1.1 查找标签 (1)直接查找 document.getElementById(“idname”) // dom对象 document.getElementsByTag ...