题目: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的更多相关文章

  1. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it

    链接:https://www.nowcoder.com/acm/contest/163/F 来源:牛客网 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it 时间限制:C ...

  2. 2018 ACMICPC上海大都会赛重现赛 H - A Simple Problem with Integers (线段树,循环节)

    2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 H - A Simple Problem with Integers (线段树,循环节) 链接:https://ac.nowcoder.co ...

  3. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it (扫描线)

    2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it (扫描线) 链接:https://ac.nowcoder.com/acm/contest/163/F来源:牛客网 时间 ...

  4. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP)

    2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP) 链接:https://ac.nowcoder.com/acm/contest/163/ ...

  5. 2018 ICPC上海大都会赛重现赛 D Thinking-Bear magic (几何)

    2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 D Thinking-Bear magic (几何) 链接:https://ac.nowcoder.com/acm/contest/163/ ...

  6. 计蒜客 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. ...

  7. 计蒜客 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  ...

  8. 2019中山大学程序设计竞赛(重现赛) Clumsy Keke

    Problem Description Keke is currently studying engineering drawing courses, and the teacher has taug ...

  9. 吉首大学2019年程序设计竞赛(重现赛)D - 数列求和(嘤雄难度)

    链接:https://ac.nowcoder.com/acm/contest/992/D $a_{i}=\dfrac {3a_{i-1}-a_{i-2}}{2}+i+1$ 移项再化一下 $a_{i}- ...

随机推荐

  1. AJ学IOS 之ipad开发Popover的基本使用

    AJ分享,必须精品 一:效果图 二:注意 对于方法[UIPopoverController dealloc] reached while popover is still visible. 当popo ...

  2. ORA-0245

    经常有客户报错ORA-0245 1.11.2 rac环境, rman存在snap控制文件路径,默认是文件系统[非共享,导致备份控制文件报错] 解决方法:将snap路径配置到ASM磁盘组共享路径[nfs ...

  3. Java数组模拟环形队列

    2.环形队列 (上一篇队列:https://www.cnblogs.com/yxm2020/p/12676323.html) 百度百科 1.假溢出 ​ 系统作为队列用的存储区还没有满,但队列却发生了溢 ...

  4. API联调神器PostMan使用详解

    简介 创建 + 测试:创建和发送任何的HTTP请求,请求可以保存到历史中再次执行 Organize:使用Postman Collections为更有效的测试及集成工作流管理和组织APIs docume ...

  5. 学习Python爬虫的4幅思维导图

    这次给大家带来的是4 幅思维导图,梳理了 Python 爬虫部分核心知识点:网络基础知识,Requests,BeautifulSoup,urllib 和 Scrapy 爬虫框架. 爬虫是一个非常有趣的 ...

  6. Spark SQL源码解析(三)Analysis阶段分析

    Spark SQL原理解析前言: Spark SQL源码剖析(一)SQL解析框架Catalyst流程概述 Spark SQL源码解析(二)Antlr4解析Sql并生成树 Analysis阶段概述 首先 ...

  7. Junit借助Groboutils Core进行并发测试

    本文参考:http://www.voidcn.com/article/p-ybnvuffh-ke.html:转载请注明出处 junit是无法进行并发测试,但是又有需要并发测试的场景怎么办呢?此时可以借 ...

  8. Task启动方式及源码探究

    启动Task有几种方式: 1.Task.Run() 2.new TaskFactory.StartNew() 3.var t=new Task();  t.start(); 平时用的最多是第一和第二种 ...

  9. Docker help详细帮助

    常用的 docker 命令 docker # docker 命令帮助 Commands: attach Attach to a running container # 当前 shell 下 attac ...

  10. 2019-2020-1 20199325《Linux内核原理与分析》第二周作业

    冯诺依曼计算机硬件框图: 下面是一个简单的程序example.c. intadd_a_and_b(int a,int b){returna+b;}intmain(){returnadd_a_and_b ...