书山有径勤为路>>>>>>>>

<<<<<<<<学海无涯苦作舟!

Floyd算法解决 Jump

Description

There is n pillar, their heights are (A1,A2,A3,…An).you can jump at the top of the pillars. But you will lose abs(a[j]-a[i])*abs(j-i) power when you jump from i-th pillar to j-th pillar. At first you have m power. Can you jump from s-th pillar to e-th pillar.

Input

 

The input consists of several test cases.

every test case is two integer n(2<=n<200),q(1=<q<=10000).

The second line contain n integer A1,A2,A3,..An.

The next q line contain there integer s,e,m.

 

Output

If you can jump from s to e, with less or equal m power output “Yes”, else output “No”

Sample Input

3 3
1 2 3
1 3 2
1 2 1
1 3 1

Sample Output

Yes
Yes
No

这里的能量就相当于距离了。

复制代码
View Code
#include "iostream"
using namespace std;
#define size 201
int abs(int x)
{
    return x>=0?x:-x;
}
int main()
{
    int n, q, f[size][size];
    while(cin>>n>>q)
    {
        int i, j, k;
        int p[size];
        for(i=0; i<n; i++)
            cin>>p[i];
        for(i=0; i<n; i++)
            for(j=0; j<n; j++)
                f[i][j] = abs(p[i]-p[j])*abs(i-j);
        for(k=0; k<n; k++)
            for(i=0; i<n; i++)
                for(j=0; j<n; j++)
                    if(f[i][k]+f[k][j]<f[i][j])
                        f[i][j] = f[i][k]+f[k][j];
        while(q--)
        {
            int s, e, m;
            cin>>s>>e>>m;
            if(f[s-1][e-1]<=m)
                cout<<"Yes"<<endl;
            else
                cout<<"No"<<endl;
        }
    }
    return 0;
}
复制代码

 

 

posted on   More study needed.  阅读(271)  评论(0编辑  收藏  举报

编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
< 2011年10月 >
25 26 27 28 29 30 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

书山有径勤为路>>>>>>>>

<<<<<<<<学海无涯苦作舟!

点击右上角即可分享
微信分享提示