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; }
相关文章推荐
- Hoj 2064 Journey to Tibet
- HOJ2064 - Journey to Tibet - 并查集+暴力
- HOJ 2064 Journey to Tibet (DFS)
- 并查集 HOJ 2064 Journey to Tibet
- HOJ Journey to Tibet(小毛病大问题,下标搞混了,导致很严重的后果)
- c++ error 2064: term does not evaluate to a function taking 1 arguments解决方法
- ZOJ 3223 Journey to the Center of the Earth 【二维最短路】
- Journey from a Python noob to a Kaggler on Python (从Python数据分析菜鸟到专家)
- Problem J. Journey to the “The World’s Start”
- 【2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest J】【二分答案+multiset】Journey to the “The World’
- php进行递归时出现Call to a member function 方法() on null的原因以及解决方案
- hackerrank Journey to the Moon(并查集)
- HOJ 12926 Janeway’s Journey(斜率排序)
- ZOJ 3223 Journey to the Center of the Earth
- Hoj 2047 106 miles to Chicago
- [递归理解/记忆化] HDU/HOJ 1331 Function Run Fun
- [Algorithms, C] long2char: 自己用C写来玩玩的整形转化为字符串函数 (递归和迭代两种实现): void long2char(long from, char *to, int n);
- leetcode 108. Convert Sorted Array to Binary Search Tre 详细分析 和 递归参数确定
- CodeForces - 758D Ability To Convert(模拟,递归)
- bfs hoj Going to know him