HDU 4849-Wow! Such City!(最短路)
Wow! Such City!
Time Limit: 15000/8000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)
Total Submission(s): 824 Accepted Submission(s): 310
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 Ci,j (a positive integer) for traveling from city i to city
j. Please note that Ci,j may not equal to Cj,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 ≤ 106) 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:
Ci,j is generated in the following way:
Given integers X0, X1, Y0, Y1, (1 ≤ X0, X1, Y0, Y1≤ 1234567), for k ≥ 2 we have
Xk = (12345 + Xk-1 * 23456 + Xk-2 * 34567 + Xk-1 * Xk-2 * 45678) mod 5837501
Yk = (56789 + Yk-1 * 67890 + Yk-2 * 78901 + Yk-1 * Yk-2 * 89012) mod 9860381
The for k ≥ 0 we have
Zk = (Xk * 90123 + Yk ) mod 8475871 + 1
Finally for 0 ≤ i, j ≤ N - 1 we have
Ci,j = Zi*n+j for i ≠ j
Ci,j = 0 for i = j
For each test case, there is only one line containing 6 integers N,M,X0,X1,Y0,Y1.See the description for more details.
3 10 1 2 3 4
4 20 2 3 4 5
1
10头一次遇到区域赛的最短路的题目。。 尽管不是纯最短路(只是也差点儿相同了。。)权值由递推公式(题目中已给出)生成,然后跑一遍dijkstra,起点为1,求dis[i]%m的最小值。权值注意超出int范围要用lld#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define inf 0x3f3f3f3f
#define ll long long
using namespace std;
ll dis[1010],v[1010];
ll map[1010][1010];
int x0,x1,y0,y1,n,m;
void dijkstra()
{
int minx,k=0;
for(int i=0; i<=n; i++)
{
dis[i]=map[0][i];;
v[i]=0;
}
dis[0]=0;
for(int j=0; j<n; j++)
{
minx=inf;
for(int i=0; i<n; i++)
{
if(v[i]==0&&minx>dis[i])
{
minx=dis[i];
k=i;
}
}
v[k]=1;
for(int i=0; i<n; i++)
{
if(v[i]==0&&dis[i]>dis[k]+map[k][i])
{
dis[i]=dis[k]+map[k][i];
}
}
}
return ;
}
ll xx[1002000],yy[1002000],zz[1002000];
int main()
{
while(scanf("%d%d%d%d%d%d",&n,&m,&x0,&x1,&y0,&y1)!=EOF)
{
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
{
map[i][j]=inf;
}
map[i][i]=0;
}
xx[0]=x0;xx[1]=x1;
yy[0]=y0;yy[1]=y1;
for(int i=2; i<=n*(n-1)+n; i++)
{
xx[i]=(12345+xx[i-1]*23456+xx[i-2]*34567+xx[i-1]*xx[i-2]*45678)%5837501;
yy[i]=(56789+yy[i-1]*67890+yy[i-2]*78901+yy[i-1]*yy[i-2]*89012)%9860381;
}
for(int i=0; i<=n*(n-1)+n; i++)
{
zz[i]=(xx[i]*90123+yy[i])%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]=zz[i*n+j];
}
}
dijkstra();
ll minn=inf;
for(int i=1; i<n; i++)
{
minn=min(minn,dis[i]%m);
}
printf("%lld\n",minn);
}
return 0;
}
HDU 4849-Wow! Such City!(最短路)的更多相关文章
- HDU 4849 Wow! Such City!陕西邀请赛C(最短路)
HDU 4849 Wow! Such City! 题目链接 题意:依照题目中的公式构造出临接矩阵后.求出1到2 - n最短路%M的最小值 思路:就依据题目中方法构造矩阵,然后写一个dijkstra,利 ...
- HDU 4849 - Wow! Such City!
Time Limit: 15000/8000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others) Input There ar ...
- HDU-4849 Wow! Such City!,最短路!
Wow! Such City! 题意:题面很难理解,幸亏给出了提示,敲了一发板子过了.给出x数组y数组和z数组的求法,并给出x.y的前几项,然后直接利用所给条件构造出z数组再构造出C数组即可,C ...
- hdu4849 Wow! Such City!(最短路dijkstra)
转载请注明出处:http://blog.csdn.net/u012860063? viewmode=contents 题目链接:pid=4849">http://acm.hdu.edu ...
- hdu 4850 Wow! Such String! 欧拉回路
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4080264.html 题目链接:hdu 4850 Wow! Such String! 欧拉回 ...
- hdu 4893 Wow! Such Sequence!(线段树)
题目链接:hdu 4983 Wow! Such Sequence! 题目大意:就是三种操作 1 k d, 改动k的为值添加d 2 l r, 查询l到r的区间和 3 l r. 间l到r区间上的所以数变成 ...
- Hdu 5352 MZL's City (多重匹配)
题目链接: Hdu 5352 MZL's City 题目描述: 有n各节点,m个操作.刚开始的时候节点都是相互独立的,一共有三种操作: 1:把所有和x在一个连通块内的未重建过的点全部重建. 2:建立一 ...
- HDU 4850 Wow! Such String!(欧拉道路)
HDU 4850 Wow! Such String! 题目链接 题意:求50W内的字符串.要求长度大于等于4的子串,仅仅出现一次 思路:须要推理.考虑4个字母的字符串,一共同拥有26^4种,这些由这些 ...
- hdu 4849 最短路 西安邀请赛 Wow! Such City!
http://acm.hdu.edu.cn/showproblem.php?pid=4849 会有非常多奇怪的Wa的题.当初在西安就不知道为什么wa,昨晚做了,由于一些Sb错误也wa了非常久.这会儿怎 ...
- HDU-4849 Wow! Such City! (单源最短路)
Problem Description Doge, tired of being a popular image on internet, is considering moving to anoth ...
随机推荐
- POJ 3007 Organize Your Train part II(哈希链地址法)
http://poj.org/problem?id=3007 题意 :给你一个字符串,让你无论从什么地方分割,把这个字符串分成两部分s1和s2,然后再求出s3和s4,让你进行组合,看能出来多少种不同的 ...
- maven 项目编译时候提示:Error building POM (may not be this project's POM).
编译时候提示Error building POM (may not be this project's POM)的错误,具体信息如下: [0] 'dependencies.dependency.ver ...
- 一个字 word 是16位, 一个字由两个字节组成 , 字节=byte ,一个字节8位, 位=bit 如果没有特殊说明kb 就是指 k*bit
一个字 word 是16位, 一个字由两个字节组成 , 字节=byte,,一个字节8位, 位=bit 如果没有特殊说明kb 就是指 k*bit kbyte= k*byte
- 李洪强漫谈iOS开发[C语言-017]-printf函数
- asp.net 简单实现禁用或启用页面中的某一类型的控件
我们在提交一个表单的时候,可能由于网络或服务器的原因,处理很慢,而用户在处理结果出来之前反复点击按钮提交.这样很容易造成不必要的麻烦甚至是错误.说了这么多,其实就是要实现一个禁用某些控件的一种功能.好 ...
- UDP模块(黑胶体)
UDP模块是采用PIP封装技术的U盘半成品模块,直接加上外壳,就是成品U盘. 它有以下特点: 防水.防尘.防震. 一体WAFER封装技术. 薄.轻.时尚. 产品装配方便.简单. 产品标准化,适合客户在 ...
- tlplayer for android V2.7(支持变速不变调) 2014-07-20更新
2014-07-20新版本已经修复部分视频倾斜问题,已经更新到服务器,需要的朋友自行下载. 此版本修正了倾斜问题,增加水印等功能.可以动态添加水印. tlplayer for android V2.6 ...
- usaco4.12Fence Rails(迭代加深)
为了这题还去学了下迭代加深 回来还是不会写 只好参考各大神的代码及题解了 二分枚举最大可以切的块数 然后就是各种分析及优化 USACO题解里写了7个优化.. 问题分析 抽象一下就可以发现,算法的本质是 ...
- C#程序中访问配置文件
在C#编程中,有时候会用到配置文件,那么该如何在程序中获取或修改配置文件中的相关数据呢?下面采用一个简单的C#控制台程序来说明. 新建一个C#控制台程序,打开“解决方案资源管理器”,如下图: 可以看到 ...
- c#执行Dos命令
一个执行Dos命令的窗口程序,与各位分享. 效果图: 具体实现在代码中有详细的注释,请看代码. 实现执行CMD命令的核心代码(Cmd.cs): [csharp] using S ...