E - charge-station

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Appoint description:

Description

There are n cities in M^3's empire. M^3 owns a palace and a car and the palace resides in city 1. One day, she wants to travel around all the cities from her palace and finally back to her home. However, her car has limited energy and can only travel by no more than D meters. Before it was run out of energy, it should be charged in some oil station. Under M^3's despotic power, the judge is forced to build several oil stations in some of the cities. The judge must build an oil station in city 1 and building other oil stations is up to his choice as long as M^3 can successfully travel around all the cities.
Building an oil station in city i will cost 2 i-1 MMMB. Please help the judge calculate out the minimum cost to build the oil stations in order to fulfill M^3's will.
 

Input

There are several test cases (no more than 50), each case begin with
two integer N, D (the number of cities and the maximum distance the car
can run after charged, 0 < N ≤ 128).

Then follows N lines and line i will contain two numbers x, y(0 ≤ x, y ≤ 1000), indicating the coordinate of city i.

The distance between city i and city j will be ceil(sqrt((xi - xj)
2 + (yi - yj)
2)). (ceil means rounding the number up, e.g. ceil(4.1) = 5)
 

Output

For each case, output the minimum cost to build the oil stations in the binary form without leading zeros.

If it's impossible to visit all the cities even after all oil stations are build, output -1 instead.
 

Sample Input

3 3
0 0
0 3
0 1

3 2
0 0
0 3
0 1

3 1
0 0
0 3
0 1

16 23
30 40
37 52
49 49
52 64
31 62
52 33
42 41
52 41
57 58
62 42
42 57
27 68
43 67
58 48
58 27
37 69

 

Sample Output

11
111
-1
10111011

Hint

 In case 1, the judge should select (0, 0) and (0, 3) as the oil station which result in the visiting route: 1->3->2->3->1. And the cost is 2^(1-1) + 2^(2-1) = 3.
大概提议就是给出n和d,下面分别给出n个点的坐标,汽车一次加油可以行使长度为d的距离。但是中途可以加油,问在哪些地方加油可以使得汽车行使完整个来回路程,并且要求建立加油站花费的金额最小,
输出就是二进制判断,1为建立,0为不建立
 #include<stdio.h>
#include<iostream>
#include<string.h>
#include<queue>
#include<math.h>
#include<algorithm>
using namespace std;
const int maxn=;
const int inf=;
int map[maxn][maxn];
int n,d;
double x[maxn],y[maxn];
int dis[maxn];
bool vis[maxn]; int ans[maxn]; int check(){
memset(vis,false,sizeof(vis));
for(int i=;i<=n;i++){
if(ans[i])
dis[i]=;
else
dis[i]=inf;
}
queue<int>que;
que.push();
vis[]=true;
while(!que.empty()){
int u=que.front();
que.pop();
for(int i=;i<=n;i++){
if(!vis[i]&&map[u][i]<=d){
dis[i]=min(dis[i],dis[u]+map[u][i]);
if(ans[i]){
vis[i]=true;
que.push(i);
}
}
}
}
for(int i=;i<=n;i++){
if(ans[i]==&&!vis[i])
return false;
else if(ans[i]==&&dis[i]*>d)
return false;
}
return true; } int main(){
while(scanf("%d%d",&n,&d)!=EOF){
memset(map,,sizeof(map));
for(int i=;i<=n;i++){
scanf("%lf%lf",&x[i],&y[i]);
}
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
map[i][j]=ceil(sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])));
}
}
for(int i=;i<=n;i++){
ans[i]=;
}
if(!check()){
printf("-1\n");
continue;
} for(int i=n;i>=;i--){
ans[i]=;
if(!check())
ans[i]=;
}
int i;
for( i=n;i>=;i--){
if(ans[i]==)
break;
}
for(int j=i;j>=;j--)
printf("%d",ans[j]);
printf("\n");
}
return ;
}

最新文章

  1. Android XML中引用自定义内部类view的四个why
  2. validate jquery 注册页面使用实例 详解
  3. 读书笔记-js
  4. SpringMVC学习系列(6) 之 数据验证
  5. 《C语言入门1.2.3—一个老鸟的C语言学习心得》—清华大学出版社炮制的又一本劣书及伪书
  6. sublime 安装常用插件
  7. div+css的前端工程师的价值体现在哪些方面?
  8. .net闭包的应用
  9. 最简单理解CGI,FastCGI,WSGI
  10. 201521123017 《Java程序设计》第1周学习总结
  11. C++ 设计模式 依赖倒置原则 简单示例
  12. Java爬虫框架WebMagic——入门(爬取列表类网站文章)
  13. django-Ajax发送POST请求(csrf跨站请求的三种方式),文件的上传
  14. SQL 中如何删除重复(每列数据都重复)的记录,只保留一行?
  15. SAP MM 公司间STO里交货单PGI之后自动触发内向交货单功能的实现
  16. 通过LRU实现通用高效的超时连接探测
  17. java0426 wen IO2
  18. Kubernetes Ingress 学习
  19. Java之扫描目录,修改文件内容
  20. [转载]8 种提升 ASP.NET Web API 性能的方法

热门文章

  1. [BZOJ 1797][AHOI2009]最小割(最小割关键边的判断)
  2. Mysql 调优小技巧
  3. 每天一个linux命令(21):tar命令
  4. android文件上传到服务器
  5. tomcat 简介
  6. 可视化HTML编辑器
  7. firefox与chrome中对select下拉框中的option支持问题
  8. xbz分组题B 吉利数字 数位dp入门
  9. [IOS UIalert模版]
  10. UVA1629Cake slicing(记忆化搜索)