最短路 西北大学2019年春季校赛 ( 重现赛 ) 房间迷宫 求一个数的所有的约数nlogn
题目:https://www.cometoj.com/contest/33/problem/G?problem_id=1461(密码:jwjtxdy)
学习一下 求一个数的约数 复杂度n*logn
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iostream>
#define inf 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 2e5 + ;
struct heapnode
{
int u;
ll d;
heapnode(int u=,ll d=):u(u),d(d){}
bool operator<(const heapnode&a)const
{
return a.d < d;
}
};
vector<int>G[maxn];
vector<int>num[maxn];
ll dis[maxn];
bool vis[maxn];
int a[maxn], b[maxn], c[maxn], n; void dij(int s)
{
for (int i = ; i <= n; i++) dis[i] = inf;
dis[s] = ;
memset(vis, , sizeof(vis));
priority_queue<heapnode>que;
que.push(heapnode(s, ));
while(!que.empty())
{
heapnode x = que.top(); que.pop();
int u = x.u;
if (vis[u]) continue;
vis[u] = ;
for(int i=;i<G[u].size();i++)
{
int now = G[u][i];
if(dis[now]>dis[u]+a[now])
{
dis[now] = dis[u] + a[now];
//printf("www dis[%d]=%lld dis[%d]=%lld\n", now, dis[now],u,dis[u]);
que.push(heapnode(now, dis[now]));
}
}
//printf("c[%d]=%d\n",u, c[u]);
int len = num[c[u]].size();
// printf("%d\n", len);
for(int i=;i<len&&num[c[u]][i]+u<=n;i++)
{
int y = num[c[u]][i] + u;
// printf("y=%d\n", y);
// printf("a[%d]=%d\n", y, a[y]);
if(dis[y]>dis[u]+b[u]+a[y])
{
dis[y] = dis[u] + b[u] + a[y];
// printf("b[%d]=%d a[%d]=%d\n", u, b[u], y, a[y]);
// printf("dis[%d]=%lld dis[%d]=%lld\n", y, dis[y],u,dis[u]);
que.push(heapnode(y, dis[y]));
}
}
}
} int main()
{
for (int i = ; i < maxn; ++i) {
for (int j = i; j < maxn; j += i) {
num[j].push_back(i);//先把每个数的因子有哪些打个表,由调和级数可知复杂度为o(nlog n)
}
}
int v;
scanf("%d", &n);
for(int i=;i<=n;i++)
{
scanf("%d%d%d%d", &a[i], &b[i], &c[i], &v);
G[i].push_back(v);
}
dij();
if (dis[n] >= inf) printf("-1\n");
else printf("%lld\n", dis[n]+a[]);
return ;
}
最短路 西北大学2019年春季校赛 ( 重现赛 ) 房间迷宫 求一个数的所有的约数nlogn的更多相关文章
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it
链接:https://www.nowcoder.com/acm/contest/163/F 来源:牛客网 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it 时间限制:C ...
- 2018 ACMICPC上海大都会赛重现赛 H - A Simple Problem with Integers (线段树,循环节)
2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 H - A Simple Problem with Integers (线段树,循环节) 链接:https://ac.nowcoder.co ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it (扫描线)
2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it (扫描线) 链接:https://ac.nowcoder.com/acm/contest/163/F来源:牛客网 时间 ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP)
2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP) 链接:https://ac.nowcoder.com/acm/contest/163/ ...
- 2018 ICPC上海大都会赛重现赛 D Thinking-Bear magic (几何)
2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 D Thinking-Bear magic (几何) 链接:https://ac.nowcoder.com/acm/contest/163/ ...
- 计蒜客 39280.Travel-二分+最短路dijkstra-二分过程中保存结果,因为二分完最后的不一定是结果 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest M.) 2019ICPC西安邀请赛现场赛重现赛
Travel There are nn planets in the MOT galaxy, and each planet has a unique number from 1 \sim n1∼n. ...
- 计蒜客 39272.Tree-树链剖分(点权)+带修改区间异或和 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest E.) 2019ICPC西安邀请赛现场赛重现赛
Tree Ming and Hong are playing a simple game called nim game. They have nn piles of stones numbered ...
- 2019中山大学程序设计竞赛(重现赛) Clumsy Keke
Problem Description Keke is currently studying engineering drawing courses, and the teacher has taug ...
- 吉首大学2019年程序设计竞赛(重现赛)D - 数列求和(嘤雄难度)
链接:https://ac.nowcoder.com/acm/contest/992/D $a_{i}=\dfrac {3a_{i-1}-a_{i-2}}{2}+i+1$ 移项再化一下 $a_{i}- ...
随机推荐
- shell 数组遍历加引号和不加引号的区别?
前言 shell 是一个比较神奇的国度,里面有太多的坑需要填,今天需要填的坑就是,数组遍历在使用时加了引号和不加引号的区别. 案例 解析: 不加引号,数组中元素间的“空格”就会编程换行符 加引号, ...
- java web之Filter详解
java web之Filter详解 2012-10-20 0 个评论 作者:chenshufei2 收藏 我要投稿 .概念: Filter也称之为过滤器,它是Servlet技术中比较激动人心的技术,W ...
- AJ学IOS(34)UI之Quartz2D画画板的实现
AJ分享,必须精品 效果: 实现过程: 首先用storyboard搭建界面,没有什么好说的. 然后就是注意的功能了,这里用了触摸事件来搭配Quartz2D的路径来画画. 思路就是把路径放到数组中 @p ...
- Crowd 批量添加用户(Postman 数据驱动)
背景 最近公司大量新员工入职,需要批量创建 Crowd 用户.设置密码.分配应用组等机械性重复工作(主要还是懒~),故把这个加餐任务分配给刚来的测试同学去研究. 一是:让他了解下 Postman 的数 ...
- jquery 延迟执行方法
setTimeout方法使用时需注意: //以下两种方式都行: setTimeout(function () { test(); }, ); //或者 setTimeout(); function t ...
- stand up meeting 1/13/2016
part 组员 工作 工作耗时/h 明日计划 工作耗时/h UI 冯晓云 UI测试和调整:与主程序完成合并 6 查漏补缺,扫除UI ...
- stand up meeting 12/22/2015 && 用户体验收录
part 组员 工作 工作耗时/h 明日计划 工作耗时/h UI 冯晓云 完善页面切换,尝试子页面设计 4 完善页面切换和子页面 ...
- 【LeetCode】57. Insert Interval [Interval 系列]
LeetCode中,有很多关于一组interval的问题.大体可分为两类: 1.查看是否有区间重叠: 2.合并重叠区间; 3.插入新的区间: 4. 基于interval的其他问题 [ 做题通用的关键 ...
- [一道蓝鲸安全打卡Web分析] 文件上传引发的二次注入
蓝鲸打卡的一个 web 文件上传引发二次注入的题解和思考 蓝鲸文件管理系统 源代码地址:http://www.whaledu.com/course/290/task/2848/show 首先在设置文件 ...
- Vue【你知道吗?】
前言 Vue的由来 Vue最早发布于2014年左右,作者是美中国学生尤雨溪.Vue 的定位就是为前端开发提供一个低门槛,高效率,但同时又能够伴随用户成长的框架 尤雨溪谈Vue.js :缔造自由与真我 ...