Floyd算法解决 Jump
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 2011-10-18 11:03 More study needed. 阅读(270) 评论(0) 编辑 收藏 举报