最短路 西北大学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}- ...
随机推荐
- 关于TOMCAT中的两个Web.xml
关于TOMCAT中的两个Web.xml (2013-01-19 17:32:57) 转载▼ 标签: 杂谈 初学JAVA web开发.. Servlet定义的时候,我发现在${catalina.ho ...
- 视频图文教学 - 用最快的速度把 DotNet Core Blazor 程序安装到 树莓派中 并且用网页控制 GPIO 闪灯
前言 dotnet core 在3.0时代已经发展得很好. 尤其是在跨平台方面更已经是达到了很实用的阶段. 作为 dotnet 程序员, 应该对 Linux 有充分的了解, 也可以在业余时间玩玩硬件, ...
- [转] Roguelike开发建议
该文所述的Roguelike为典型的Roguelike游戏,而非带着Roguelike元素的游戏. 以下内容为他在今年Roguelike开发者大会上的发言文字版. 引言 几年前召开的首届Rogueli ...
- OSI 七层模型以及TCP/IP模型
OSI 七层模型 定义 OSI(Open System Interconnection)即开放式系统互联通信参考模型.该模型是国际标准化组织(ISO)制定的一个用于计算机或通信系统间互联的标准体系,一 ...
- U - Obtain a Permutation CodeForces - 1294E 思维
题解: 注意每一列与每一列之间互不影响,所以贪心地求出没一列的最小操作值,然后累加起来. 怎么求没一列的最小值呢?维护一个数组same表示其中same[i]=j表示将该序列向上翻滚i次有j个元素归位, ...
- CodeForces - 876B H - 差异的可分割性
现在有n个整数,在这n个数中找出k个数,保证这k个数中任意两个数差的绝对值可以被m整除. Input第一行输入三个整数n,k,m(2<=k<=n<=100000,1<=m< ...
- 数值分析实验之曲线最小二乘拟合含有噪声扰动(python实现)
一.实验目的 掌握最小二乘法拟合离散数据,多项式函数形式拟合曲线以及可以其他可以通过变量变换转化为多项式的拟合曲线目前待实现功能: 1. 最小二乘法的基本实现. 2. 用不同数据量,不同参数,不同的多 ...
- bm25算法和tfidf
- pytorch 中LSTM模型获取最后一层的输出结果,单向或双向
单向LSTM import torch.nn as nn import torch seq_len = 20 batch_size = 64 embedding_dim = 100 num_embed ...
- CG-CTF(3)
CG-CTF https://cgctf.nuptsast.com/challenges#Web 续上~ 第十四题:GBK Injection 是一道注入题: 分析:题目提示了GBK,GBK是一种多字 ...