HDU 4435 charge-station(暴力+判图)
来源:互联网 发布:小白软件管家 编辑:程序博客网 时间:2024/05/23 11:52
题目大意:给你一些点,他们可以连通,如果距离超过了d那么就要经过加油站,建立加油站的费用为第i个点是2^(i-1)。求费用最小,输出二进制表示的最小费用。
费用和sum最坏等于=2^0+2^1+……+2^(n-1)。所以最高位为0这个数字才会最小,从最高位暴力枚举如果删掉这个点之后图是连通的那么就可以删掉,否则不可以。
求图是否连通的时候可以爆搜求解,也可以并查集。
charge-station
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1053 Accepted Submission(s): 554
Problem 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 2i-1 MMMB. Please help the judge calculate out the minimum cost to build the oil stations in order to fulfill M^3's will.
Building an oil station in city i will cost 2i-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)
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.
If it's impossible to visit all the cities even after all oil stations are build, output -1 instead.
Sample Input
3 30 00 30 13 20 00 30 13 10 00 30 116 2330 4037 5249 4952 6431 6252 3342 4152 4157 5862 4242 5727 6843 6758 4858 2737 69
Sample Output
11111-110111011HintIn 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.
Source
2012 Asia Tianjin Regional Contest
#include <algorithm>#include <iostream>#include <stdlib.h>#include <string.h>#include <iomanip>#include <stdio.h>#include <string>#include <queue>#include <cmath>#include <time.h>#include <stack>#include <map>#include <set>#define eps 1e-8///#define LL long long#define LL __int64#define INF 0x3f3f3f#define PI 3.1415926535898#define mod 1000000007using namespace std;const int maxn = 210;bool vis[maxn];int mp[maxn][maxn];struct node{ int x, y;} f[maxn];int n, d;double Dis(int a, int b){ return sqrt(((f[a].x-f[b].x)*(f[a].x-f[b].x) + (f[a].y-f[b].y)*(f[a].y-f[b].y))*1.0);}bool bfs(){ bool flag[maxn]; int dis[maxn]; memset(flag, false, sizeof(flag)); for(int i = 1; i <= n; i++) { if(vis[i]) { dis[i] = 0; continue; } dis[i] = INF; } queue<int> que; que.push(1); flag[1] = true; while(!que.empty()) { int x = que.front(); que.pop(); for(int i = 1; i <= n; i++) { if(flag[i] || mp[x][i] > d) continue; dis[i] = min(dis[i], dis[x]+mp[x][i]); if(vis[i]) { flag[i] = true; que.push(i); } } } for(int i = 1; i <= n; i++) { if(vis[i] && !flag[i]) return false; if(!vis[i] && 2*dis[i] > d) return false; } return true;}int main(){ while(~scanf("%d %d",&n, &d)) { for(int i = 1; i <= n; i++) scanf("%d %d",&f[i].x, &f[i].y); for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) mp[i][j] = ceil(Dis(i, j)); for(int i = 1; i <= n; i++) vis[i] = true; if(!bfs()) { cout<<-1<<endl; continue; } for(int i = n; i >= 1; i--) { vis[i] = false; if(!bfs()) vis[i] = true; } int x = n; while(!vis[x]) x--; for(int i = x; i >= 1; i--) cout<<vis[i]; cout<<endl; } return 0;}
0 0
- HDU 4435 charge-station(暴力+判图)
- hdu 4435 charge-station【暴力+Bfs】
- HDU 4435 charge-station
- hdu 4435 charge-station
- Hdu 4435 charge-station 贪心
- hdu--4435--charge-station+贪心
- HDU 4435 charge-station(12年天津)
- HDU 4435 charge-station(天津现场赛)
- hdu 4435 charge-station ( 贪心+bfs )
- HDU 4435 charge-station (搜索+YY)
- HDU 4435 charge-station - from lanshui_Yang
- hdu 4435 charge-station(几何+bfs)
- Hdu 4435 charge-station(BFS+贪心)
- HDU 4435(charge-station)(BFS+最小花费)
- charge-station HDU
- hdu 4435 charge-station (贪心+图论)
- hdu 4435 charge-station(最短路+思维,5级)
- HDU-4435-charge-station ( 2012 Asia Tianjin Regional Contest )
- servlet JDBC mysql数据库连接池
- 只要一下载大文件,电脑的联网客户端就掉线………………哈哈,已解决!!!
- Block
- 数据库三大范式详解
- USACO: Mother's Milk
- HDU 4435 charge-station(暴力+判图)
- JavaScript中的数据类型知识总结(一定有你不知道的秘密~)
- IOS-Navigation
- ajax 提交form表单
- 这些年自我增值的方法
- Linux内核的代号---有趣
- LeetCode OJ 之 Remove Duplicates from Sorted Array II (删除有序数组中重复的数-二)
- WIFI Basics
- 改变世界的起点是改变自己