hdu4435-charge-station(搜索+贪心)
题意&题解:
http://www.cnblogs.com/wuminye/p/3245546.html
说实话看了题解觉得很简单,但是比赛的时候真的是毫无头绪。
然而印象中做过一道类似的二进制贪心的题目。竟然……没想到……sigh……太弱辣!!!
应该思考题目为什么要给2^i,而不是轻易的认为是为了增加难度= =
笨死了555~
//补题
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iostream>
using namespace std;
typedef long long ll; const int N = ;
const int INF = 0x5f5f5f5f;
const int MOD = ; int n, d;
int x[N], y[N];
int dis[N][N];
bool ans[N];
bool vis[N]; int get_dis(int a, int b) {
return ceil( sqrt( (x[a]-x[b])*(x[a]-x[b]) + (y[a]-y[b])*(y[a]-y[b]) ) );
} bool ok() {
memset(vis, false, sizeof vis);
vis[] = true;
queue<int> q;
q.push();
while(q.size()) {
int top = q.front(); q.pop();
for (int i = ; i < n; ++i) {
if (vis[i]) continue;
if (dis[top][i] <= d && ans[i]) {
vis[i] = true;
q.push(i);
} else if (dis[top][i] * <= d) {
vis[i] = true;
}
}
}
for (int i = ; i < n; ++i) if (!vis[i]) return false;
return true;
} int main()
{
//freopen("in.txt", "r", stdin);
while (~scanf("%d%d", &n, &d)) {
for (int i = ; i < n; ++i) {
scanf("%d%d", x+i, y+i);
}
if (n <= ) {
printf("%d\n", n);
continue;
}
for (int i = ; i < n; ++i) {
for (int j = ; j < n; ++j) {
dis[i][j] = get_dis(i, j);
}
}
memset(ans, true, sizeof ans);
if (!ok()) {
printf("-1\n");
continue;
}
for (int i = n-; i >= ; --i) {
ans[i] = false;
//printf("%d:%d\n", i, ok());
if (!ok()) ans[i] = true;
}
bool f = true;
for (int i = n-; i >= ; --i) {
if (f && !ans[i]) continue;
if (ans[i]) f = false;
printf("%d", ans[i]);
}
printf("\n");
}
return ;
}
hdu4435-charge-station(搜索+贪心)的更多相关文章
- [CQOI2012]模拟工厂 题解(搜索+贪心)
[CQOI2012]模拟工厂 题解(搜索+贪心) 标签:题解 阅读体验:https://zybuluo.com/Junlier/note/1327574 链接题目地址:洛谷P3161 BZOJ P26 ...
- HDU 6034---Balala Power!(搜索+贪心)
题目链接 Problem Description Talented Mr.Tang has n strings consisting of only lower case characters. He ...
- [NOIP 2010]饮水入城 搜索+贪心
考试的时候写了个dfs找出来了,最后处理的时候想到了贪心,但是正确性没有想通.然后想了想动规,也没想通.最后没办法,用状态的话用了个状压,弄了40分. 正解是bfs+贪心.Dfs也有过的. 下面题解引 ...
- 洛谷 2668&2540 斗地主——搜索+贪心+dp
题目:https://www.luogu.org/problemnew/show/P2540 发现如果没有顺子,剩下的可以贪心.所以搜索顺子怎么出,然后贪心. 这样只能过不加强版.原因是贪心的时候难以 ...
- SPOJ:Strange Waca(不错的搜索&贪心&剪枝)
Waca loves maths,.. a lot. He always think that 1 is an unique number. After playing in hours, Waca ...
- 洛谷 P2668 & P2540 [ noip 2015 ] 斗地主 —— 搜索+贪心
题目:https://www.luogu.org/problemnew/show/P2668 https://www.luogu.org/problemnew/show/P2540 首先,如果没有 ...
- hdu 5335 Walk Out 搜索+贪心
Walk Out Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total S ...
- Gas Station|leetcode 贪心
贪心:尽量将gas[i]-cost[i]>0的放在前面,gas[i]-cost[i]<0的放在后面.(路程的前面有汽油剩下,耗汽油的放在路程的后面). 能否全程通过的 条件 是:sum(g ...
- Codeforces 799D Field expansion - 搜索 - 贪心
In one of the games Arkady is fond of the game process happens on a rectangular field. In the game p ...
随机推荐
- Connect to the mysql dataase from remote server
Make sure that the firewall is closed!!!!!!!!! shell command should be like is: mysql -u username -p ...
- C++智能指针(auto_ptr)详解
智能指针(auto_ptr) 这个名字听起来很酷是不是?其实auto_ptr 只是C++标准库提供的一个类模板,它与传统的new/delete控制内存相比有一定优势,但也有其局限.本文总结的8个问题足 ...
- 1058-Tom and Jerry
描述 Tom和Jerry在10*10的方格中: *...*..... ......*... ...*...*.. .......... ...*.C.... *.....*... ...*...... ...
- android应用崩溃的调试方法(c++ lib so文件库崩溃)
android调试工具addr2line使用: 1.将ndk中的arm-linux-androideabi-addr2line可执行文件的路径加入配置文件~/.bashrc中,例如: export P ...
- [itint5]棋盘漫步
要注意dp[0][0]要初始化为1. int totalPath(vector<vector<bool> > &blocked) { int m = blocked.s ...
- redis的key过期时间
public void set(String key,String value,int liveTime){ this.set(key, value); this.getJedis().expire( ...
- DELPHI下API简述(1800个API)
DELPHI下API简述 http://zero.cnbct.org/show.asp?id=144 auxGetDevCaps API 获取附属设备容量 auxGetNumDevs API 返回附属 ...
- yii2的安装
yii2也是依赖于composer, 就像laravel, 所以先安装composer, 如果安装不上composer可以看laravel安装的文章. 安装好composer之后安装一个插件 comp ...
- Git教程之远程仓库(9)
有个叫GitHub的神奇的网站,呵呵,从名字就可以看出,这个网站就是提供Git仓库托管服务的,所以,只要注册一个GitHub账号,就可以免费获得Git远程仓库. 由于本地Git仓库和GitHub仓库之 ...
- Task-based Asynchronous Pattern (TAP)
The Task-based Asynchronous Pattern (TAP) is based on the System.Threading.Tasks.Task and System.Thr ...