【codechef】Lazy Players
来源:互联网 发布:新域名多长时间生效 编辑:程序博客网 时间:2024/05/21 20:21
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 150 2 3 3 22 0 3 2 33 3 0 2 23 2 2 0 32 3 2 3 0Output: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");elseprintf("IMPOSSIBLE");return 0;}
- 【codechef】Lazy Players
- CodeChef
- CodeChef
- CodeChef
- CodeChef
- (CodeChef
- CodeChef
- CodeChef
- CodeChef
- CodeChef
- CodeChef
- CodeChef
- lazy
- lazy
- Experiences of Warcraft players 1
- Experiences of Warcraft players 2
- NBA Palace for Basketball Players
- NBA Palace for Basketball Players
- hdoj 2841 Visible Trees 【容斥原理】
- poj 3620 dfs 水
- 怎样改变小农经济思维
- MySQL之视图(View)
- Linux高级编程 第六章 进程控制 信号 定时器 信号操作 信号屏蔽
- 【codechef】Lazy Players
- 程序员的开始
- VC写的仿App风格桌面软件
- 网络流初步 最大流
- 对C++中类模板的认识
- 玩玩linux下的errno, perror, strerror
- Spring AOP 切入点常用表达式
- Play1.2.7导入Eclipse
- 【BNU】40719 Arithmetic Progressions【分块+FFT】