Wow! Such City! 最短路问题
Doge, tired of being a popular image on internet, is considering moving to another city for a new way of life.
In his country there are N (2 ≤N≤ 1000) cities labeled 0 . . . N - 1. He is currently in city 0. Meanwhile, for each pair of cities, there exists a road connecting them, costing C i, j (a positive integer) for traveling from city i to city j. Please note that C i, j may not equal to C j, i for any given i ≠ j.
Doge is carefully examining the cities: in fact he will divide cities (his current city 0 is NOT included) into M (2 ≤ M ≤ 10 6) categories as follow: If the minimal cost from his current city (labeled 0) to the city i is Di, city i belongs to category numbered Di mod M.Doge wants to know the “minimal” category (a category with minimal number) which contains at least one city.
For example, for a country with 4 cities (labeled 0 . . . 3, note that city 0 is not considered), Doge wants to divide them into 3 categories. Suppose category 0 contains no city, category 1 contains city 2 and 3, while category 2 contains city 1, Doge consider category 1 as the minimal one.
Could you please help Doge solve this problem?
Note:
C i, j is generated in the following way:
Given integers X 0, X 1, Y 0, Y 1, (1 ≤ X 0, X 1, Y 0, Y 1≤ 1234567), for k ≥ 2 we have
Xk = (12345 + X k-1 * 23456 + X k-2 * 34567 + X k-1 * X k-2 * 45678) mod 5837501
Yk = (56789 + Y k-1 * 67890 + Y k-2 * 78901 + Y k-1 * Y k-2 * 89012) mod 9860381
The for k ≥ 0 we have
Z k = (X k * 90123 + Y k ) mod 8475871 + 1
Finally for 0 ≤ i, j ≤ N - 1 we have
C i, j = Z i*n+j for i ≠ j
C i, j = 0 for i = j
Input
There are several test cases. Please process till EOF.
For each test case, there is only one line containing 6 integers N,M,X 0,X 1,Y 0,Y 1.See the description for more details.
Output
For each test case, output a single line containing a single integer: the number of minimal category.
Sample Input
3 10 1 2 3 4
4 20 2 3 4 5
Sample Output
1
10
For the first test case, we have
0 1 2 3 4 5 6 7 8
X 1 2 185180 788997 1483212 4659423 4123738 2178800 219267
Y 3 4 1633196 7845564 2071599 4562697 3523912 317737 1167849
Z 90127 180251 1620338 2064506 625135 5664774 5647950 8282552 4912390
the cost matrix C is
0 180251 1620338
2064506 0 5664774
5647950 8282552 0
Hint
So the minimal cost from city 0 to city 1 is 180251, while the distance to city 2 is 1620338.
Given M = 10, city 1 and city 2 belong to category 1 and 8 respectively.
Since only category 1 and 8 contain at least one city,
the minimal one of them, category 1, is the desired answer to Doge’s question.
题目的数据比较奇怪,先给X0,X1,Y0,Y1,然后在这个基础上用给的式子,求出剩下的点,再根据X和Y,求出点之间的距离Z,再将Z转化为二维的表,之后用迪杰斯特拉算法算就好了,主要在于数据类型的选择,数组要选择long long int 不然会超限。
AC代码
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int N,M;
long long int X[1000005],Y[1000005],Z[1000005];
long long int dist[1000005];
long long int Map[1005][1005];
int vis[1005];
int INF=9999999;
int FindMinDist()
{int min=-1;int mindist=INF;for(int i=1;i<N;i++)if(mindist>dist[i]&&vis[i]==0){mindist=dist[i];min=i;}if(mindist<INF)return min;elsereturn -1;
}
void Dijkstra()
{for(int i=1;i<N;i++)dist[i]=Map[0][i];vis[0]=1;while(1){int temp=FindMinDist();if(temp==-1) break;vis[temp]=1;for(int i=1;i<N;i++)if(dist[i]>dist[temp]+Map[temp][i]&&Map[temp][i]!=INF)dist[i]=dist[temp]+Map[temp][i]; }
}
int main()
{while(cin>>N>>M>>X[0]>>X[1]>>Y[0]>>Y[1]){memset(dist,0,sizeof(dist));memset(vis,0,sizeof(vis));for(int k=2;k<N*N;k++){X[k] = (12345 + X[k-1] * 23456 + X[k-2] * 34567 + X[k-1] * X[k-2] * 45678)%5837501;Y[k] = (56789 + Y[k-1] * 67890 + Y[k-2] * 78901 + Y[k-1] * Y[k-2] * 89012)%9860381;}for(int k=0;k<N*N;k++)Z[k] = (X[k] * 90123 + Y[k] ) %8475871 + 1 ;for(int i=0;i<N;i++)for(int j=0;j<N;j++){if(i==j)Map[i][j]=0;else Map[i][j]=Z[i*N+j];}Dijkstra();long long int ans=INF;for(int i=1;i<N;i++)ans=min(ans,dist[i]%M); cout<<ans<<endl;}return 0;
}
Wow! Such City! 最短路问题相关推荐
- HDU4809 Wow! Such City! Dijkstra算法
点击打开链接 Wow! Such City! Time Limit: 15000/8000 MS (Java/Others) Memory Limit: 102400/102400 K (Jav ...
- 2014西安全国邀请赛
陪人训练,只A了四个题,赛后五分钟AC J,难受 写题解的时候有点困,语言组织有点问题,有时间再更新 sorry A - Wow! Such Doge! 题意:就给你一堆字符串,然后问你"d ...
- first season seventh episode,The entire city is blacked out!(全城大停电,Chandler有好事???)
[Scene: Central Perk, Rachel is introducing Phoebe, who is playing her guitar for the crowd.] Rachel ...
- ue4商城素材 Cyberpunk City / Recife Environment 赛博朋克城市场景
ue4商城素材 Cyberpunk City / Recife Environment 赛博朋克城市场景 ue4商城素材 Cyberpunk City / Recife Environment 赛博朋 ...
- 3 css 奖品出现弹出动画_【技术】nuxt中引入wow和animate.css 页面随滚动条出现动画...
1. 通过nodejs安装 cnpm install wowjs --save-dev 安装成功后在"package.json: "wowjs": "^1.1. ...
- 多尺度的CityNeRF: Building NeRF at City Scale
作者丨黄浴@知乎 来源丨https://zhuanlan.zhihu.com/p/450671684 编辑丨3D视觉工坊 arXiv在2021年12月17日上传论文"CityNeRF: Bu ...
- 车辆计数--FCN-rLSTM: Deep Spatio-Temporal Neural Networks for Vehicle Counting in City Cameras
FCN-rLSTM: Deep Spatio-Temporal Neural Networks for Vehicle Counting in City Cameras ICCV2017 https: ...
- 对WoW Shader文件的分析
Wow的渲染引擎是同时支持固定渲染管线渲染和Shader渲染管线渲染的. bls文件是wow的shader文件,分析它的实现可以学习引擎是怎样渲染的,以及如何做一个兼容固定管线和Shader管线的引擎 ...
- 【LibreOJ】#6395. 「THUPC2018」城市地铁规划 / City 背包DP+Prufer序
[题目]#6395. 「THUPC2018」城市地铁规划 / City [题意]给定n个点要求构造一棵树,每个点的价值是一个关于点度的k次多项式,系数均为给定的\(a_0,...a_k\),求最大价值 ...
最新文章
- 我们究竟应不应该使用框架?
- CVPR 2020 | 以局部焦点进行渐进式面部表情编辑
- C语言链表的来源分析
- Halcon学习笔记——机器视觉应用工程开发思路及相机标定
- 【OpenCV 例程200篇】89. 带阻滤波器的传递函数
- 【C语言】第四章 逻辑判断与选择结构 题解
- 【脑电信号】基于matlab HMM睡眠状态检测【含Matlab源码 050期】
- 大学生简单个人静态HTML网页设计作品 DIV布局个人介绍网页模板代码 DW学生个人网站制作成品下载
- dtft频移性质_08 DTFT变换的性质
- Java机器学习实战——SVD(奇异值分解)完整设计
- pdf照片显示正常打印时被翻转_现场确认完没事了?准考证打印要注意哪些细节!...
- 魔兽世界资料片:燃烧的远征
- 一个非常不错的JQ 插件库
- kb mac压缩图片大小_Mac系统怎么压缩图片
- 生活常用的塑料材质1到7
- 深入了解JVM之线上问题排查及工具使用(五)
- ISP流程Gamma校正思路
- 计算机科学与技术论文摘要范文,计算机科学与技术论文范文两篇(2)
- CK-FR08-E01与恩基士PLC配置指南
- Java实现将数字转换成中文大写