Concerned with the fitness levels of the players in the National Team, the coach decides to carry out a running drill in the next training session. So, he sets up checkpoints in the training ground at different positions.
After evaluating each player’s fitness, the coach asks each player to cover a certain minimum distance while completing all checkpoints (Suppose a players starts at checkpoint 2, then he must cover all checkpoints and finish at checkpoint 2).
Players being lazy want to finish the drill in exact distance that the coach assigns them. Is it possible?
Input
Input description.
- First line with two space separated integers N and L , the number of checkpoints and the minimum distance that coach asks the player to cover, respectively
- Then N lines containing N space separated integers each. The jth integer on the ith line, dij, denotes the distance between checkpoint point i and j (dij for i != j, and dii = 0). For all 1 ≤ i, j, k ≤ N it is the case that dij = dji and dij ≤ dik + dkj.
Output
For each test case, output a single line containing the answer i.e. POSSIBLE or IMPOSSIBLE.
Constraints
- 1 ≤ N ≤ 14
- 1 ≤ L ≤ 1014
- 1 ≤ dij ≤ L
Example
Input: 5 15 0 2 3 3 2 2 0 3 2 3 3 3 0 2 2 3 2 2 0 3 2 3 2 3 0 Output:POSSIBLE
http://www.codechef.com/problems/LAZY01
Dij表示i到j的距离。经过每个点后的总距离能否刚好等于15
#include<bits/stdc++.h> using namespace std; int main(){ int n,l,sum; int a[14][14],i,j,k; cin>>n>>l; for(i=0;i<n;i++) for(j=0;j<n;j++) cin>>a[i][j]; for(i=0;i<n;i++){ sum=0; for(j=0;j<n;j++){ for(k=0;k<n;k++){ if(sum<l){ sum+=a[i][k]+a[k][j]; //有点类似floyd,不过很巧妙的方法 } } } if(sum==l){ printf("POSSIBLE\n"); break; } } if(i==n) printf("IMPOSSIBLE\n"); return 0; }#include <stdio.h> int main(void) { int a,b,i,j,max=0,sum=0; scanf("%d%d",&a,&b); int arr[a][a]; for(i=0;i<a;i++) { for(j=0;j<a;j++) { scanf("%d",&arr[i][j]); } } for(i=0;i<a;i++) { for(j=i+1;j<a;j++) { if(arr[i][j]>max) { max=arr[i][j]; } } sum+=max; } if(sum>=b) printf("POSSIBLE"); else printf("IMPOSSIBLE"); return 0; }

为了提升国家队球员的体能水平,教练决定在下次训练中引入跑步训练,并设置不同检查点。每名球员需从某个检查点开始,跑过所有检查点并返回起点,同时覆盖教练指定的最小距离。本文探讨了如何通过输入检查点之间的距离,判断球员是否有可能在不超距的情况下完成任务。
4826

被折叠的 条评论
为什么被折叠?



