Gym 101617J Treasure Map(bfs暴力)
http://codeforces.com/gym/101617/attachments
题意:
给出一个图,每个顶点代表一个金矿,每个金矿有g和d两个值,g代表金矿初始的金子量,d是该金矿每天的金子量会减少d。顶点与顶点之间存在边,意思是从一个金矿到另一个金矿需要花费的天数。现在有个人一开始在1金矿,问最多能挖到多少金矿,注意,不能在一个金矿连续挖几天。
思路:
bfs求解,但是需要剪枝,用二位数组d[v][day]记录第day天时在v金矿所能获得的最大值。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
const int maxn = +; int tot,n,m,mx,ans;
int head[maxn];
int g[maxn],d[maxn];
int dis[maxn][maxn]; struct Node
{
int v,w,next;
}e[*maxn]; struct node
{
int id;
int val;
int day;
bool operator< (const node& rhs) const
{
return day>rhs.day;
}
}; void addEdge(int u,int v,int w)
{
e[tot].v = v;
e[tot].w = w;
e[tot].next = head[u];
head[u] = tot++;
} void bfs()
{
memset(dis,,sizeof(dis));
priority_queue<node> q;
node p;
p.id = ;
p.val = g[];
p.day = ;
q.push(p);
ans = g[]; dis[][] = g[];
while(!q.empty())
{
p = q.top(); q.pop();
int u = p.id; for(int i=head[u];i!=-;i=e[i].next)
{
int v = e[i].v;
int w = e[i].w;
node tmp = p;
tmp.id = v;
tmp.val += max(,g[v]-d[v]*(p.day+w-));
tmp.day = p.day + w;
if(tmp.day>mx) continue;
if(tmp.val<=dis[v][tmp.day]) continue;
dis[v][tmp.day] = tmp.val;
q.push(tmp);
ans = max(ans,tmp.val);
} }
} int main()
{
//freopen("in.txt","r",stdin);
while(~scanf("%d%d",&n,&m))
{
mx = ;
tot = ;
memset(head,-,sizeof(head));
for(int i=;i<=n;i++)
{
scanf("%d%d",&g[i],&d[i]);
mx = max(mx,g[i]/d[i]+);
}
while(m--)
{
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
addEdge(u,v,w);
addEdge(v,u,w);
}
bfs();
printf("%d\n",ans);
}
return ;
}
Gym 101617J Treasure Map(bfs暴力)的更多相关文章
- Gym 100971A Treasure Island BFS 思维题
A - Treasure Island Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64 ...
- ZOJ 3209 Treasure Map (Dancing Links)
Treasure Map Time Limit: 2 Seconds Memory Limit: 32768 KB Your boss once had got many copies of ...
- ZOJ 3209 Treasure Map (Dancing Links)
Treasure Map Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit S ...
- (简单) ZOJ 3209 Treasure Map , DLX+精确覆盖。
Description Your boss once had got many copies of a treasure map. Unfortunately, all the copies are ...
- ZOJ 3209 Treasure Map(精确覆盖)
Treasure Map Time Limit: 2 Seconds Memory Limit: 32768 KB Your boss once had got many copies of ...
- 2017年上海金马五校程序设计竞赛:Problem K : Treasure Map (蛇形填数)
Description There is a robot, its task is to bury treasures in order on a N × M grids map, and each ...
- ZOJ3209 Treasure Map —— Danc Links 精确覆盖
题目链接:https://vjudge.net/problem/ZOJ-3209 Treasure Map Time Limit: 2 Seconds Memory Limit: 32768 ...
- hdoj5024【BFS/暴力】
题意: 在可以行走的区域内,只能转一次90度的弯,问你最长这条路可以多长. 思路: 我们可以看到 /* 123 8 4 765 */ 转90度的路径会是横竖,也就是1-3-5-7; 还有斜的:2-4- ...
- Codeforces gym 100685 F. Flood bfs
F. FloodTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/F Desc ...
随机推荐
- sqoop从hive导入数据到mysql时出现主键冲突
今天在将一个hive数仓表导出到mysql数据库时出现进度条一直维持在95%一段时间后提示失败的情况,搞了好久才解决.使用的环境是HUE中的Oozie的workflow任何调用sqoop命令,该死的o ...
- Firefox 功能笔记
1.复制标签 说明:复制标签功能即新开一个与当前页一样的标签页,这个功能在Chrome中点击标签右键复制即可,但是在firefox中没有 Firefox中实现:Ctrl+拖动标签页
- c# Applicatcontext类
Application类(位于System.Windows.Forms命名空间)公开了Run方法,可以调用该方法来调度应用程序进入消息循环.Run方法有三个重载 1.第一个重载版本不带任何参数,比较少 ...
- 如何使用Linux 命令more 查看文本文件
Linux 下有很多实用工具可以让你在终端界面查看文本文件.其中一个就是 more. more 跟我之前另一篇文章里写到的工具 —— less 很相似.它们之间的主要不同点在于 more 只允许你向前 ...
- 前端框架VUE----es6简单介绍
1.ECMAScript 6 简介 ECMAScript 6.0(以下简称 ES6)是 JavaScript 语言的下一代标准,已经在 2015 年 6 月正式发布了.它的目标,是使得 JavaScr ...
- Mac配置java运行环境的步骤
官网下载地址:jdk1.8版本的 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.htm ...
- P2233 [HNOI2002]公交车路线
洛咕原题 dp->矩阵乘法 首先我们可以得出一个状态转移方程 f[i][j]=f[i-1][j-1]+f[i-1][j+1] 蓝后发现,我们可以把这转化为一个8*8的转移矩阵 然后跑一遍矩阵快速 ...
- mysql Out of range value adjusted for column导致Warning(1265)Data truncated for column 'column_name' at row 1
今天下午,我们的一个开发来找我,说线上有个环境报了"Warning(1265)Data truncated for column 'column_name' at row 1",定 ...
- 【题解】 Luogu P4312 / SP4155 [COCI 2009] OTOCI / 极地旅行社
原题地址:P4312 [COCI 2009] OTOCI / 极地旅行社/SP4155 OTOCI - OTOCI lct入门难度的题,十分弱智(小蒟蒻说lct是什么,能吃吗?) bridge操作判联 ...
- Tree Implementation with Python
Tree Implementation with Python List of List 代码如下: def binary_tree(val): return [val, [], []] def in ...