bzoj1681[Usaco2005 Mar]Checking an Alibi 不在场的证明
Description
A crime has been comitted: a load of grain has been taken from the barn by one of FJ's cows. FJ is trying to determine which of his C (1 <= C <= 100) cows is the culprit.
Fortunately, a passing satellite took an image of his farm M (1 <= M <= 70000) seconds before the crime took place, giving the location of all of the cows. He wants to know which cows had time to get to the barn to steal the grain. Farmer John's farm comprises
F (1 <= F <= 500) fields numbered 1..F and connected by P (1 <= P <= 1,000) bidirectional paths whose traversal time is in the range 1..70000 seconds (cows walk very slowly). Field 1 contains the barn. It takes no time to travel within a field (switch paths).
Given the layout of Farmer John's farm and the location of each cow when the satellite flew over, determine set of cows who could be guilty. NOTE: Do not declare a variable named exactly 'time'. This will reference the system call and never give you the results
you really want.
Input
* Line 1: Four space-separated integers: F, P, C, and M * Lines 2..P+1: Three space-separated integers describing a path: F1, F2, and T. The path connects F1 and F2 and requires T seconds to traverse.
* Lines P+2..P+C+1: One integer per line, the location of a cow. The first line gives the field number of cow 1, the second of cow 2, etc.
第1行输入四个整数F,只C,和M;
接下来P行每行三个整数描述一条路,起点终点和通过时间.
Output
* Line 1: A single integer N, the number of cows that could be guilty of the crime.
* Lines 2..N+1: A single cow number on each line that is one of the cows that could be guilty of the crime. The list must be in ascending order.
Sample Input
1 4 2
1 2 1
2 3 6
3 5 5
5 4 6
1 7 9
1
4
5
3
7
Sample Output
1
2
3
4
HINT
因为数据实在太弱,各种最短路都能过……
写了个floyd
#include<cstring>
#include<cstdio>
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
inline int min(int a,int b) {if(a<b)return a;else return b;}
int n,m,c,t,len;
int dist[1001][1001];
int ans[1001];
int main()
{
n=read();
m=read();
c=read();
t=read();
memset(dist,127/3,sizeof(dist));
for (int i=1;i<=n;i++)dist[i][i]=0;
for(int i=1;i<=m;i++)
{
int x=read(),y=read(),z=read();
if (z<=t)
{
dist[x][y]=min(dist[x][y],z);
dist[y][x]=dist[x][y];
}
}
for (int k=1;k<=n;k++)
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++)
if (i!=j)
if (dist[i][k]+dist[k][j]<dist[i][j])
dist[i][j]=dist[i][k]+dist[k][j];
for (int i=1;i<=c;i++)
{
int x=read();
if (dist[x][1]>t) continue;
ans[++len]=i;
}
for (int i=1;i<len;i++)
for (int j=i+1;j<=len;j++)
if(ans[i]>ans[j])
{
int t=ans[i];
ans[i]=ans[j];
ans[j]=t;
}
printf("%d\n",len);
for (int i=1;i<=len;i++)
printf("%d\n",ans[i]);
}
bzoj1681[Usaco2005 Mar]Checking an Alibi 不在场的证明的更多相关文章
- bzoj:1681 [Usaco2005 Mar]Checking an Alibi 不在场的证明
Description A crime has been comitted: a load of grain has been taken from the barn by one of FJ's c ...
- 【BZOJ】1681: [Usaco2005 Mar]Checking an Alibi 不在场的证明(spfa)
http://www.lydsy.com/JudgeOnline/problem.php?id=1681 太裸了.. #include <cstdio> #include <cstr ...
- BZOJ1680: [Usaco2005 Mar]Yogurt factory
1680: [Usaco2005 Mar]Yogurt factory Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 106 Solved: 74[Su ...
- BZOJ 1739: [Usaco2005 mar]Space Elevator 太空电梯
题目 1739: [Usaco2005 mar]Space Elevator 太空电梯 Time Limit: 5 Sec Memory Limit: 64 MB Description The c ...
- BZOJ 1738: [Usaco2005 mar]Ombrophobic Bovines 发抖的牛( floyd + 二分答案 + 最大流 )
一道水题WA了这么多次真是.... 统考终于完 ( 挂 ) 了...可以好好写题了... 先floyd跑出各个点的最短路 , 然后二分答案 m , 再建图. 每个 farm 拆成一个 cow 点和一个 ...
- 1740: [Usaco2005 mar]Yogurt factory 奶酪工厂
1740: [Usaco2005 mar]Yogurt factory 奶酪工厂 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 119 Solved: ...
- 1682: [Usaco2005 Mar]Out of Hay 干草危机
1682: [Usaco2005 Mar]Out of Hay 干草危机 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 391 Solved: 258[ ...
- bzoj1682[Usaco2005 Mar]Out of Hay 干草危机*
bzoj1682[Usaco2005 Mar]Out of Hay 干草危机 题意: 给个图,每个节点都和1联通,奶牛要从1到每个节点(可以走回头路),希望经过的最长边最短. 题解: 求最小生成树即可 ...
- bzoj1680[Usaco2005 Mar]Yogurt factory*&&bzoj1740[Usaco2005 mar]Yogurt factory 奶酪工厂*
bzoj1680[Usaco2005 Mar]Yogurt factory bzoj1740[Usaco2005 mar]Yogurt factory 奶酪工厂 题意: n个月,每月有一个酸奶需求量( ...
随机推荐
- Solr初步学习
Solr采用Lucene搜索库为核心,提供全文索引和搜索开源企业平台,提供REST的HTTP/XML和JSON的API,如果你是Solr新手,那么就和我一起来入门吧!本教程以solr4.8作为测试环境 ...
- Wamp集成环境安装
一.Wamp下载 点我下载WampServer2.1a-x32 二.Wamp安装步骤 三.修改语言为汉语 四.查看测试页面
- (转)OS X Mountain Lion 系统配置 Apache+Mysql+PHP 详细教程
如果你是一名 Web 开发者,很多时候都需要在本地搭建服务器测试环境,比如 Apache+Mysql+PHP 这样的环境.事实上 Mac OS X 中想要搭建这样的环境很简单,本文我们就会将详细的教程 ...
- ruby gems安装镜像
由于每一个月都要升级两台gitlab server, ruby安装的源老是被墙,痛苦无比. 所以须要使用国内的镜像 在/home/git/gitlab/Gemfile文件里第一行改动为: # sour ...
- [ES6] for..in && for..of
var ary = [ { id: 1, name: "Zhentian" }, { id: 2, name: "Alice" } ]; for..in Pri ...
- Android学习之多点触摸并不神秘
最近研究了一下多点触摸,写了个利用多点触摸来控制图片大小和单点触摸控制图片移动的程序,和大家分享分享. Android中监听触摸事件是onTouchEvent方法,它的参数为MotionEvent,下 ...
- mysql主从监控
要求:检测myslq从库状态,跳过固定的错误号,每隔30秒检测一次,如果符合条件自动跳过或者是重启从库 1)取出mysql从库的关键字 [root@localhost scripts]# mysql ...
- Entrez检索实例 - NCBI
题目:已知来豆荚斑驳病毒(bean pod mottle virus,BPMV)的名字,查询BPMV基因组信息.核酸序列信息.蛋白序列信息和结构信息 解答: 1.直接搜索,点genome,即可看到病毒 ...
- 基于java callable及future接口解决生产者消费者问题
这两天复习java线程时,把java里面的线程基本知识点与jdk1.5以后新添加的一些类的使用都了解了一下,借用生产者消费者的问题来将他们实践一下. 题目:(题目在csdn一大牛的空间找的) 生产者- ...
- foreach遍历扩展(二)
一.前言 假设存在一个数组,其遍历模式是根据索引进行遍历的:又假设存在一个HashTable,其遍历模式是根据键值进行遍历的:无论哪种集合,如果它们的遍历没有一个共同的接口,那么在客户端进行调用的时候 ...