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 ...
随机推荐
- 【JavaScript 6连载】五、继承的概念
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- ymPrompt,jcs缓存架构
jcs.auxiliary.LTCP=org.apache.jcs.auxiliary.lateral.socket.tcp.LateralTCPCacheFactory#jcs.auxiliary. ...
- cookie 和 session 的一些事 中间件
cookie 和 session cookie 1. 保存在浏览器上一组组键值对,服务器让浏览器进行设置. 2. 为什么要用cookie? HTTP协议是无状态.使用cookie保存状态. 3. dj ...
- ul点击li,增加样式
用户首次绑定后,需要选择一款头像 <!--imgList头像列表--><el-row class="regModel1"> <el-col :span ...
- Redis内存分析方法
一般会采用 bgsave 生成 dump.rdb 文件,再结合 redis-rdb-tools 和 sqlite 来进行静态分析. BGSAVE:在后台异步(Asynchronously)保存当前数据 ...
- 利用Oracle GoldenGate记录源系统所有表的操作
通过goldengate,可以实现目标表和源表不同结构之间的实时复制,包括记录源系统所有表的变更操作,供ETL或其它审计系统使用. 记录信息包括表名.操作时间.操作SCN,事务标记,操作类型到一个流水 ...
- 用Intellij IDEA建mybatis案例
用IDEA建mybatis案例 环境准备: 首先,建库建表(最好用navicat或sqlpro直接导) 然后打开IDEA, 1. java--->javaEE---> java app-- ...
- QT---实现舒尔特方格(零基础入门)
按照之前说的,加上舒尔特方格,读者还可以自行将此游戏做成APP放到手机上,后面还有贪吃蛇,Java版的飞机大战,五子棋,各类游戏会不断加上来的,当然,会免费附加源代码! 读者可以去4399去玩一下,可 ...
- App Store 审核指南
App Store 审核指南 https://developer.apple.com/app-store/review/guidelines/cn/ https://developer.apple.c ...
- django使用session缓存Redis
首先安装redis包 pip install django-redis-sessions 然后在settings中设置 SESSION_ENGINE = 'redis_sessions.session ...