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暴力)的更多相关文章

  1. Gym 100971A Treasure Island BFS 思维题

    A - Treasure Island Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64 ...

  2. ZOJ 3209 Treasure Map (Dancing Links)

    Treasure Map Time Limit: 2 Seconds      Memory Limit: 32768 KB Your boss once had got many copies of ...

  3. ZOJ 3209 Treasure Map (Dancing Links)

    Treasure Map Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit S ...

  4. (简单) ZOJ 3209 Treasure Map , DLX+精确覆盖。

    Description Your boss once had got many copies of a treasure map. Unfortunately, all the copies are ...

  5. ZOJ 3209 Treasure Map(精确覆盖)

    Treasure Map Time Limit: 2 Seconds      Memory Limit: 32768 KB Your boss once had got many copies of ...

  6. 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 ...

  7. ZOJ3209 Treasure Map —— Danc Links 精确覆盖

    题目链接:https://vjudge.net/problem/ZOJ-3209 Treasure Map Time Limit: 2 Seconds      Memory Limit: 32768 ...

  8. hdoj5024【BFS/暴力】

    题意: 在可以行走的区域内,只能转一次90度的弯,问你最长这条路可以多长. 思路: 我们可以看到 /* 123 8 4 765 */ 转90度的路径会是横竖,也就是1-3-5-7; 还有斜的:2-4- ...

  9. Codeforces gym 100685 F. Flood bfs

    F. FloodTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/F Desc ...

随机推荐

  1. Linux基础命令---chfn

    chfn chfn指令可以改变通过finger指令查看到的信息.此信息存储在/etc/passwd文件中,并由Finger程序显示.LinuxFinger命令将显示可由chfn更改的四条信息:您的真名 ...

  2. 一个用python简单的封装了aria2的jsonrpc中adduri的脚本

    aria2是一个十分牛逼的下载神器,有时候项目需要一个很牛逼的下载中间件的话,aria2是一个不错的选择.其中支持jsonrpc和websocket的特性尤其诱人.但是python用起来还是有点不爽, ...

  3. django rest framework跨表取值

  4. awk中截取IP字段

    由于文本的特殊性,IP字段可能并不是在特定的字段中. 借助awk的match()函数进行匹配截取 awk --re-interval '($0 ~ "xxx"){match($0, ...

  5. php打乱数组二维数组、多维数组

    //这个是针对二维数组的!下面针对多维数组的乱序方法<?php function shuffle_assoc($list) { if (!is_array($list)) return $lis ...

  6. Spring Boot(六):如何使用mybatis

    Spring Boot(六):如何使用mybatis orm框架的本质是简化编程中操作数据库的编码,发展到现在基本上就剩两家了,一个是宣称可以不用写一句SQL的hibernate,一个是可以灵活调试动 ...

  7. oracle 12cR2 smart flash cache实测

    最近一直在处理新系统的性能优化问题,这两天特地测试了下oracle 11gR2开始引入的smart flash cache. 其介绍参考MOS文档,How To Size the Database S ...

  8. windows 10下oracle相关异常及处理方法

    话说起来,不以oracle性能优化,数据库维护为主业已经有四五年了,这两年基本上以mysql为主. pl/sql登录后提示空白对话框.将ORACLE_HOME设置为oracle 11g的目录. IMP ...

  9. C# 发送16进制串口数据

    一个困扰两天的问题:需要通过串口向设备发送的数据:0A010 7e 08 00 11 00 00 7e 76 7f我先将每个16进制字符转换成10进制,再将其转换成ASCII码对应的字符. /// & ...

  10. JavaBean的getters和setters方法自动生成

    xgClass.java文件: public class XgClass { private String ccCityDerate1000Num; } 添加getter/setter方法: 在代码区 ...