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 ...
随机推荐
- Hive复制分区表和数据
1. 非分区表: 复制表结构: create table new_table as select * from exists_table where 1=0; 复制表结构和数据: create tab ...
- iframe使用
iframe是一个前端页面的内联框架(即行内框架),使用很方便, <!--嵌套子页面--> <script type="text/x-template" id=& ...
- v-html对于↵转义的问题
方法1 用pre标签展示 <pre v-html> </pre> 方法2 浏览器处理换行的时候,会进行自动合并 (1)设置 white-space: pre,禁用自动合并: ( ...
- echart中间显示固定的字
- [trick] 玩弄svn的目录结构
今天在使用svn进行版本管理时出现了一个小问题: 原本在s目录下有一个c目录,不知为何被删除了,而svn st命令并没有认为它消失,svn up命令也无法下载回来: 从另一个地方拷贝过来一个c,svn ...
- 栈的压入和弹出序列(剑指Offer)
输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序.假设压入栈的所有数字均不相等.例如序列1,2,3,4,5是某栈的压入顺序,序列4,5,3,2,1是该压栈序列对应的一 ...
- right spindle supply short to gnd-- compact version
hardware guy found that the R1004 lead to this error, but this error should not be checked, because ...
- MySQL SELECT练习题*28
-- (1)用子查询查询员工“张小娟”所做的订单信息. SELECT * FROM order_master WHERE saler_no = ( SELECT employee_no FROM em ...
- 开启redis-server提示 # Creating Server TCP listening socket *:6379: bind: Address already in use--解决方法
在bin目录中开启Redis服务器,完整提示如下: 3496:C 25 Apr 00:56:48.717 # Warning: no config file specified, using the ...
- select2 AJAX获取数据
页面效果: index.html <!DOCTYPE html> <html> <head> <meta charset="utf-8"& ...