最短路 西北大学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}- ...
随机推荐
- HttpClient之Get请求和Post请求示例
HttpClient之Get请求和Post请求示例 博客分类: Java综合 HttpClient的支持在HTTP/1.1规范中定义的所有的HTTP方法:GET, HEAD, POST, PUT, ...
- vueCli 运行报错
error 如下: npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! shopping@0.1.0 serve: `vue-cli-service ...
- [算法]素数筛法(埃氏筛法&线性筛法)
目录 一.素数筛的定义 二.埃氏筛法(Eratosthenes筛法) 三.线性筛法 四.一个性质 一.素数筛的定义 给定一个整数n,求出[1,n]之间的所有质数(素数),这样的问题为素数筛(素数的筛选 ...
- Linux终端命令格式
01.终端命令格式 command [-options] [parameter] 说明: command:命令名,响应功能的英文单词或单词的缩写 [-options]:选项,可用来对命令进行控制,也可 ...
- Extjs更新grid
基于Extjs4.2 原理是创建一个新的store,来覆盖原有的store. //创建数据 var newdatas = { name: "ly", age: 17, adress ...
- Daily Scrum 12/21/2015
Process: Zhaoyang: Integrate the oxford Speech API Code to the IOS client and do some UI optimizatio ...
- Daily Scrum 12/17/2015
Process: Zhaoyang:完成了相册图片的异步加载. Yandong&Dong: 对Azure的体系架构进行学习和相应的编程. Fuchen: 对Oxford计划中的NLP接 ...
- Obtain The String CodeForces - 1295C binary_search+思维
妈耶,,,被B题卡到哭,C题一发就过了... 字符串问题.首先用vector记录每个字符出现的位置,然后对字符串t的每个字符,用二分查找函数查找,注意用upper_bound查找,对于字符i,首先用变 ...
- HBase BucketAllocatorException 异常剖析
近日,观察到HBase集群出现如下WARN日志: 2020-04-18 16:17:03,081 WARN [regionserver/xxx-BucketCacheWriter-1] bucket. ...
- 学习笔记-CTF密码相关
RSA共模攻击 RSA基本原理 ① 选择两个大的质数p和q,N=pq: ② 根据欧拉函数,求得r=(p-1)(q-1): ③ 选一个小于r的整数e,求得e关于模r的模反元素d: ④ 将p和q的 ...