您的位置:首页 > 其它

Hoj 2064 Journey to Tibet(递归)

2014-07-31 23:00 288 查看
原文:点击打开链接
//题目链接:http://acm.hit.edu.cn/hoj/problem/view?id=2064
//(代码含全角空格,你懂的)
#include
#include
#include
#include
using namespace std;
const int N=1010;
struct vil{
int x,y,m;
bool vis;
};

int dis(vil a,vil b){
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
vil v
;
int n,temp,best,ans;

void dfs(int s){
for(int i=0;i
if(!v[i].vis&&dis(v[i],v[s])<=900){
v[i].vis=true;
temp+=v[i].m;
dfs(i);
//v[i].vis=false;避免重复访问
}
}
int main(){
while(cin>>n&&n){
for(int i=0;i
cin>>v[i].x>>v[i].y>>v[i].m;
}
ans=-1;best=0;
for(int i=0;i
for(int j=0;j
v[i].vis=true;
temp=v[i].m;
dfs(i);
if(temp>ans) {ans=temp;best=i;}
//v[i].vis=false;避免重复访问
}
cout<<best+1<<' '<<ans<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  dfs 递归