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 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
#include<cstdio>
#include<algorithm>
using namespace std; struct na{
int y,z,ne;
na(){
ne=;
}
};
struct dui{
int v,n;
};
const int INF=;
int n,c,m,l[],r[],x,y,z,pp,num=,p[],nu,dis[],an=;
bool ans[];
na b[];
dui d[];
char cc;
int read(){
int a=;
cc=getchar();
while(cc<''||cc>'') cc=getchar();
while(cc>=''&&cc<='') a=a*+cc-,cc=getchar();
return a;
}
void in(int x,int y,int z){
num++;
if (l[x]==) l[x]=num;else b[r[x]].ne=num;
b[num].y=y;b[num].z=z;
r[x]=num;
}
void sw(int a,int b){
swap(p[d[a].n],p[d[b].n]);
swap(d[a],d[b]);
}
void utz(int x){
while(x>&&d[x].v<d[x>>].v) sw(x,x>>),x>>=;
}
void dtz(int j){
j=j*;
while(j<=nu){
if (j<nu&&d[j].v>d[j+].v) j++;
sw(j>>,j);
j*=;
}
sw(j>>,nu);
p[d[nu].n]=;
nu--;
}
int main(){
n=read();pp=read();m=read();c=read();
nu=n;
for (int i=;i<=pp;i++){
x=read();y=read();z=read();
in(x,y,z);in(y,x,z);
}
for (int i=;i<=n;i++) dis[i]=d[i].v=INF,d[i].n=i,p[i]=i;
d[].v=;
for (int i=;i<=n;i++){
x=d[].n;
if (d[].v>c) break;
dis[x]=d[].v;
dtz();
for (int j=l[x];j;j=b[j].ne)
if (p[b[j].y]&&d[p[b[j].y]].v>dis[x]+b[j].z&&dis[x]+b[j].z<=c){
d[p[b[j].y]].v=dis[x]+b[j].z;
utz(p[b[j].y]);
}
}
for (int i=;i<=m;i++){
x=read();
if (dis[x]<=c)an++,ans[i]=;
}
printf("%d\n",an);
for (int i=;i<=m;i++)
if (ans[i]) printf("%d\n",i);
}
bzoj:1681 [Usaco2005 Mar]Checking an Alibi 不在场的证明的更多相关文章
- 【BZOJ】1681: [Usaco2005 Mar]Checking an Alibi 不在场的证明(spfa)
http://www.lydsy.com/JudgeOnline/problem.php?id=1681 太裸了.. #include <cstdio> #include <cstr ...
- 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 c ...
- 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 点和一个 ...
- BZOJ 1738: [Usaco2005 mar]Ombrophobic Bovines 发抖的牛
Description 约翰的牛们非常害怕淋雨,那会使他们瑟瑟发抖.他们打算安装一个下雨报警器,并且安排了一个撤退计划.他们需要计算最少的让所有牛进入雨棚的时间. 牛们在农场的F(1≤F≤200 ...
- BZOJ 1682: [Usaco2005 Mar]Out of Hay 干草危机
Description 牛们干草要用完了!贝茜打算去勘查灾情. 有N(2≤N≤2000)个农场,M(≤M≤10000)条双向道路连接着它们,长度不超过10^9.每一个农场均与农场1连通.贝茜要走遍每一 ...
- BZOJ 1680 [Usaco2005 Mar]Yogurt factory:贪心【只用考虑上一个】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1680 题意: 在接下来的n周内,第i周生产一吨酸奶的成本为c[i],订单为y[i]吨酸奶. ...
- bzoj 1680: [Usaco2005 Mar]Yogurt factory【贪心】
贪心,一边读入一边更新mn,用mn更新答案,mn每次加s #include<iostream> #include<cstdio> using namespace std; in ...
- bzoj 1682: [Usaco2005 Mar]Out of Hay 干草危机【并查集+二分】
二分答案,把边权小于mid的边的两端点都并起来,看最后是否只剩一个联通块 #include<iostream> #include<cstdio> using namespace ...
随机推荐
- 链表创建和链表遍历算法的演示_C语言
今天搞了一个多小时,头是疼的,应该是没休息好吧,学习了数据结构这一节,感觉收益良多,下面贴上代码和心得: /*24_链表创建和链表遍历算法的演示*/ # include <stdio.h> ...
- dropout理解:1神带9坑
Dropout是深度学习中防止过拟合的一项非常常见的技术,是hinton大神在12年提出的一篇论文里所采用的方法.有传言hinton大神的数学功底不是很好,所以他所提出的想法背后的数学原理并不是很复杂 ...
- mysql TIMESTAMP与DATATIME的区别---转载加自己的看法
from:http://lhdeyx.blog.163.com/blog/static/318196972011230113645715/ from:http://blog.csdn.NET/zht6 ...
- bat获取系统时间修改系统密码
@echo off %1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe&q ...
- Android模拟器
一.Genymotion 1.下载安装:https://www.genymotion.com/download/ (注:安装前需要先注册) 因为Genymotion运行需要VirtualBox,如果 ...
- Maven安装教程
一.安装Maven及配置环境变量 1.Maven官网地址:http://maven.apache.org/download.cgi 下载apache-maven-3.5.0-bin.zip文件 2. ...
- PHP动态图像处理
相关代码见:https://www.github.com/lozybean/learn_www/ 目录 1. 画布管理: imagecreate():创建一个基于调色板的画布,指定画布的长.宽 ...
- leetcode — reorder-list
/** * Source : https://oj.leetcode.com/problems/reorder-list/ * * Given a singly linked list L: L0→L ...
- SQL Server CPU
解决数据库系统的性能问题可能是一项艰巨的任务.了解如何找到问题很重要,但是了解系统对特定请求作出特定反应的原因更加重要.影响数据库服务器上的 CPU 利用率 的因素有很多:SQL 语句的编译和重新编译 ...
- MicroPython-GPS教程之TPYBoardv702控制5110显示当前经纬度
一.关于TPYBoardV702 TPYBoardV702是目前市面上唯一支持通信定位功能的MicroPython开发板:支持Python3.0及以上版本直接运行.支持GPS+北斗双模定位.GPRS通 ...