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 ...
随机推荐
- Druid-目前最好的连接池
https://blog.csdn.net/youanyyou/article/details/78992979 Druid是什么Druid是阿里开源的连接池,是Java语言中最好的数据库连接池.Dr ...
- Python Selenium 常用方法总结
selenium Python 总结一些工作中可能会经常使用到的API. 1.获取当前页面的Url 方法:current_url 实例:driver.current_url 2.获取元素坐标 ...
- vue editorConfig
在文件目录下, indent_size = 2设置为4
- 大数据自学6-Hue集成环境操作Hbase
上一章讲过,Hue集成环境是可以直接操作Hbase,但是公司的环境一直报错,虽然也可以透过写代码访问Hbase,但是看到Hue环境中无法访问,还是觉得不爽,因此决定再花些力气找找原因. 找原因要先查L ...
- Python3 tkinter基础 Listbox for+insert 将list中元素导入listbox中
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python3 tkinter基础 Entry state 不可写 可以选 可复制的输入框
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- 集训总结DAY.1(18.5.22)——KMP
DAY 1——5.22 in the morning 依稀记得我们有一场contest. at night chf大佬讲KMP,先膜一波~~~ luoguP3375KMP模板题 KMP算法,又称模式匹 ...
- POJ 2387 Til the Cows Come Home 【最短路SPFA】
Til the Cows Come Home Description Bessie is out in the field and wants to get back to the barn to g ...
- php编程疑难解决-1
全局变量和超全局变量 如果是php脚本script 或php代码, 一定要放在 php标签内<?php ?> 内. 这样apache才会把他当做php脚本内容来解析, 才会去调用php模块 ...
- luogu1110[ZJOI2007]报表统计
思路 这里的初始化就不讲了,看完操作讲解就应该明白了,再不行就去看代码 对于操作1 由于操作2的需要,vector[n]存下数 对于操作2的维护 查询相邻两个元素的之间差值(绝对值)的最小值 先把所有 ...