题意:       给你一个无向图,然后给了一个起点s和终点e,然后问从s到e的最短路是多少,中途有一个限制,那就是必须走k条边,路径可以反复走. 思路:       感觉很赞的一个题目,据说证明是什么国家队集训队论文什么的,自己没去看那个论文,就说下我自己的理解吧,对于这个题目,我们首先分析下Floyd,那个算法的过程中是在更新的dis[i][j]上再更新,再更新...,是想一下,我们每次都把更新的结果存下来,就是每次答案数组初始化全是INF,然后用当前的dis数组和原始的map来更新,那么更…
A*算法是一类贪心算法,其可以用于寻找最优路径.我们可以利用A*算法来求第k短路径. 一条路径可以由两部分组成,第一部分是一个从出发到达任意点的任意路径,而第二部分是从第一部分的末端出发,到终点的最短路径.两部分正好可以组成一条路径,且每一条路径都可以分解这两部分(允许任意一部分为空).因此当我们已知第一部分的路径A时,设第二部分为B,我们可以尝试预估完整的路径A+B的费用(距离),我们将公式定义为:f(A)=g(A)+h(A).其中g(A)表示第一部分A的已知长度,而h(A)表示路径A到终点的…
Cow Relays   Description For their physical fitness program, N (2 ≤ N ≤ 1,000,000) cows have decided to run a relay race using the T (2 ≤ T ≤ 100) cow trails throughout the pasture. Each trail connects two different intersections (1 ≤ I1i ≤ 1,000; 1…
!:自环也算一条路径 矩阵快速幂,把矩阵乘法的部分替换成Floyd(只用一个点扩张),这样每"乘"一次,就是经过增加一条边的最短路,用矩阵快速幂优化,然后因为边数是100级别的,所以把点hash一下最多剩下200个 #include<iostream> #include<cstdio> #include<algorithm> using namespace std; const int N=205,inf=1e9; int n,m,s,t,g[N],…
Sumdiv Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 1845 Appoint description:   System Crawler  (2015-05-27) Description Consider two natural numbers A and B. Let S be the sum of all natural…
http://poj.org/problem?id=1995 简单的快速幂问题 要注意num每次加过以后也要取余,否则会出问题 #include<iostream> #include<cstdio> using namespace std; typedef long long ll; ll mod_pow(ll x,ll n,ll mod) { ll res=; ) { ) res=res*x%mod; x=x*x%mod; n>>=; } return res; }…
一.Description Stockbrokers are known to overreact to rumours. You have been contracted to develop a method of spreading disinformation amongst the stockbrokers to give your employer the tactical edge in the stock market. For maximum effect, you have…
题意:给出A1,…,AH,B1,…,BH以及M,求(A1^B1+A2^B2+ … +AH^BH)mod M. 思路:快速幂 实例 3^11  11=2^0+2^1+2^3    => 3^1*3^2*3^8=3^11 实现代码: int solve(int a,int b) { int ans=1;          while(b){ if(b&1)  ans=ans*a;   a=a*a;  b>>=1;} } 解释一下代码:b&1即二进制表达式的最后一位,  11二…
Raising Modulo Numbers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5934   Accepted: 3461 Description People are different. Some secretly read magazines full of interesting girls' pictures, others create an A-bomb in their cellar, oth…
Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 31490   Accepted: 10150 Description Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sitting on another stone. He plans to visit her,…
Description People are different. Some secretly read magazines full of interesting girls' pictures, others create an A-bomb in their cellar, others like using Windows, and some like difficult mathematical games. Latest marketing research shows, that…
题目链接:http://poj.org/problem?id=1797 题意:给出两只青蛙的坐标A.B,和其他的n-2个坐标,任一两个坐标点间都是双向连通的.显然从A到B存在至少一条的通路,每一条通路的元素都是这条通路中前后两个点的距离,这些距离中又有一个最大距离.现在要求求出所有通路的最大距离,并把这些最大距离作比较,把最小的一个最大距离作为青蛙的最小跳远距离. 有一个明显的方法就是dfs一遍但是肯定会te,所以可以考虑一下用dp的思想. 类似记忆化搜索的思想,由于数据比较小所以不用记忆化搜索…
http://poj.org/problem?id=3641 练手用,结果念题不清,以为是奇偶数WA了一发 #include<iostream> #include<cstdio> #include<cmath> using namespace std; typedef long long ll; bool judge_prime(ll k) { ll i; ll u=int(sqrt(k*1.0)); ;i<=u;i++) { ) ; } ; } ll mod_p…
find the safest road Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7845    Accepted Submission(s): 2786 Problem Description XX星球有非常多城市.每一个城市之间有一条或多条飞行通道,可是并非全部的路都是非常安全的,每一条路有一个安全系数s,s是在 0 和…
#include <cstring> #include <cstdio> #include <iostream> #include <cmath> #include <algorithm> using namespace std; #define LL long long LL p,res,a; bool judge_prime(LL k) { LL i; LL u=int(sqrt(k*1.0)); ;i<=u;i++) { ) ; }…
Description Fermat's theorem states that for any prime number p and for any integer a > 1, ap = a (mod p). That is, if we raise a to the pth power and divide by p, the remainder is a. Some (but not very many) non-prime values of p, known as base-a ps…
题意:(中问题,题意很简单 思路:a走k步到b,其实就是A^k,ans.mat[a][b]就是答案. 其实就是离散的邻接矩阵那个P(不想证明,逃 #include<cstdio> #include<cmath> #include<iostream> #include<algorithm> #include<vector> #include<stack> #include<cstring> #include<queue…
题目抽象出来就是有一些告诉坐标的通信站,还有一些卫星,这些站点需要互相通信,其中拥有卫星的任意两个站可以不用发射器沟通,而所有站点的发射器要都相同,但发射距离越大成本越高. 输入的数据意思: 实例个数 卫星个数   站点个数 每个站点的坐标 输出的意思: 发射器最小是多少,保留两位小数 注意事项: 其中卫星数量少于站点,存边的数组下标从0开始的,还有一个坑坑,输出用的.2f,而喜欢用.2lf的我错了四发才发现.... 代码如下: #include <stdio.h> #include <…
For their physical fitness program, N (2 ≤ N ≤ 1,000,000) cows have decided to run a relay race using the T (2 ≤ T ≤ 100) cow trails throughout the pasture. Each trail connects two different intersections (1 ≤ I1i ≤ 1,000; 1 ≤ I2i ≤ 1,000), each of w…
http://poj.org/problem?id=3613 题意: 求经过k条路径的最短路径. 思路: 如果看过<矩阵乘法在信息学的应用>这篇论文就会知道 现在我们在邻接矩阵中保存距离,那么按照上面计算,不就是k路径的最短路径了吗? 每次用folyd去最小值,至于k次就是相乘,用快速幂. #include<iostream> #include<algorithm> #include<cstring> #include<cstdio> #incl…
Description FJ的N(2 <= N <= 1,000,000)头奶牛选择了接力跑作为她们的日常锻炼项目.至于进行接力跑的地点 自然是在牧场中现有的T(2 <= T <= 100)条跑道上. 农场上的跑道有一些交汇点,每条跑道都连结了两个不同的交汇点 I1_i和I2_i(1 <= I1_i <= 1,000; 1 <= I2_i <= 1,000).每个交汇点都是至少两条跑道的端点. 奶牛们知道每条跑道的长度length_i(1 <= len…
题意:就是输入一个数组,这个数组在不断滚动,而且每滚动一次后都要乘以一个数,用公式来说就是a[i] = a[i-1] * k;然后最后一位的滚动到第一位去. 解题报告:因为题目中的k要乘很多次,达到了10^9级别,所以,这题其实就是一个二分快速幂,先求出k的t次方,然后只要注意下输出时不一定是从数组的第一个数开始输出就是 了. #include<cstdio> #include<cstring> #include<iostream> #include<algori…
http://poj.org/problem?id=3613 s->t上经过k条边的最短路 先把1000范围的点离散化到200中,然后使用最短路可以使用floyd,由于求的是经过k条路的最短路,跑k-1次"floyd"即可(使用矩阵快速幂的思想). 把给定的图转为邻接矩阵,即A(i,j)=1当且仅当存在一条边i->j.令C=A*A,那么C(i,j)=ΣA(i,k)*A(k,j),实际上就等于从点i到点j恰好经过2条边的路径数(枚举k为中转点).类似地,C*A的第i行第j列就…
For their physical fitness program, N (2 ≤ N ≤ 1,000,000) cows have decided to run a relay race using the T (2 ≤ T ≤ 100) cow trails throughout the pasture. Each trail connects two different intersections (1 ≤ I1i ≤ 1,000; 1 ≤ I2i ≤ 1,000), each of w…
题目描述 For their physical fitness program, N (2 ≤ N ≤ 1,000,000) cows have decided to run a relay race using the T (2 ≤ T ≤ 100) cow trails throughout the pasture. Each trail connects two different intersections (1 ≤ I1i ≤ 1,000; 1 ≤ I2i ≤ 1,000), each…
题目大意: 求刚好经过K条路的最短路 我们知道假设一个矩阵A[i][j] 表示表示 i-j 是否可达 那么 A*A=B  B[i][j]  就表示   i-j 刚好走过两条路的方法数 那么同理 我们把i-j 的路径长度存到A 中. 在A*A的过程中,不断取小的.那么最后得到的也就是i - j 走过两条路的最短路了. 当然也是利用到了floyd的思想. 然后要求出K次的最短路.那么就是矩阵高速幂的工作了. 注意要离散化.用map #include <cstdio> #include <io…
解题报告 感觉这道题gyz大佬以前好像讲过一道差不多的?然鹅我这个蒟蒻发现矩阵快速幂已经全被我还给老师了...又恶补了一遍,真是恶臭啊. 题意 给定一个T(2 <= T <= 100)条边的无向图,求S到E恰好经过N(2 <= N <= 1000000)条边的最短路. Idea 用Floyd和矩阵快速幂优化的产物.具体等咱下了课再好好说... 用一个矩阵a(i, j)来表示i到j经过若干条边的最短路,初始化a为i到j边的长度,没有则是正无穷. 然后重载*运算符,比如a矩阵表示经过n…
Cow Relays Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7825   Accepted: 3068 Description For their physical fitness program, N (2 ≤ N ≤ 1,000,000) cows have decided to run a relay race using the T (2 ≤ T ≤ 100) cow trails throughout…
题目链接:https://vjudge.net/problem/POJ-2778 题意:输入n和m表示n个病毒,和一个长为m的字符串,里面只可以有'A','C','G','T' 这四个字符,现在问这个长为m的字符串里面不可以出现任何病毒的情况有多少. 参考的两篇博客: http://www.cnblogs.com/LQLlulu/p/9344774.html https://blog.csdn.net/morgan_xww/article/details/7834801 上面的博客写得很好,可以…
题目:http://poj.org/problem?id=3613 题意就是求从起点到终点的一条恰好经过k条边的最短路: floyd+矩阵快速幂,矩阵中的第i行第j列表示从i到j的最短路,矩阵本身代表一个边数状态: 所以矩阵相乘就是floyd算法,两个矩阵相乘就得到它们所代表的边数相加边数的状态矩阵: 原始矩阵自乘k-1次,过程中取min,就得到答案: 因为只是自乘,所以可以使用快速幂. 代码如下: #include<iostream> #include<cstdio> #incl…