题意&题解:

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(搜索+贪心)的更多相关文章

  1. [CQOI2012]模拟工厂 题解(搜索+贪心)

    [CQOI2012]模拟工厂 题解(搜索+贪心) 标签:题解 阅读体验:https://zybuluo.com/Junlier/note/1327574 链接题目地址:洛谷P3161 BZOJ P26 ...

  2. HDU 6034---Balala Power!(搜索+贪心)

    题目链接 Problem Description Talented Mr.Tang has n strings consisting of only lower case characters. He ...

  3. [NOIP 2010]饮水入城 搜索+贪心

    考试的时候写了个dfs找出来了,最后处理的时候想到了贪心,但是正确性没有想通.然后想了想动规,也没想通.最后没办法,用状态的话用了个状压,弄了40分. 正解是bfs+贪心.Dfs也有过的. 下面题解引 ...

  4. 洛谷 2668&2540 斗地主——搜索+贪心+dp

    题目:https://www.luogu.org/problemnew/show/P2540 发现如果没有顺子,剩下的可以贪心.所以搜索顺子怎么出,然后贪心. 这样只能过不加强版.原因是贪心的时候难以 ...

  5. SPOJ:Strange Waca(不错的搜索&贪心&剪枝)

    Waca loves maths,.. a lot. He always think that 1 is an unique number. After playing in hours, Waca ...

  6. 洛谷 P2668 & P2540 [ noip 2015 ] 斗地主 —— 搜索+贪心

    题目:https://www.luogu.org/problemnew/show/P2668   https://www.luogu.org/problemnew/show/P2540 首先,如果没有 ...

  7. hdu 5335 Walk Out 搜索+贪心

    Walk Out Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total S ...

  8. Gas Station|leetcode 贪心

    贪心:尽量将gas[i]-cost[i]>0的放在前面,gas[i]-cost[i]<0的放在后面.(路程的前面有汽油剩下,耗汽油的放在路程的后面). 能否全程通过的 条件 是:sum(g ...

  9. 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 ...

随机推荐

  1. 李洪强iOS开发本人集成环信的经验总结_03_注册

    李洪强iOS开发本人集成环信的经验总结_03_注册 环信一共提供了三种注册的方法:  01 同步注册:  02 异步注册:  03 - 使用代理回调进行注册,但是3.0没有了,3.0之前有  调用注册 ...

  2. MyBatis的动态SQL操作--删除

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUYAAAC/CAIAAAANX+LCAAAYvElEQVR4nO2dWWycV9nHDyC6UEGBGy

  3. ZOJ1204——Additive equations(DFS)

    Additive equations Description We all understand that an integer set is a collection of distinct int ...

  4. node.js模块值formidable

    模块地址:https://github.com/felixge/node-formidable var formidable = require('formidable'), http = requi ...

  5. hdu4630No Pain No Game (多校3)(树状数组)

    http://acm.hdu.edu.cn/showproblem.php?pid=4630 给的题解没看懂..搜解题报告看 了N久  终于在cui大神的指点下 搞明白咋回事了 将1-N中的每个数ai ...

  6. BZOJ2668: [cqoi2012]交换棋子

    题解: 可以戳这里:http://www.cnblogs.com/zig-zag/archive/2013/04/21/3033485.html 其实自己yy一下就知道这样建图的正确性了. 感觉太神奇 ...

  7. I.MX6 Android i2c-tools porting

    /************************************************************************** * I.MX6 Android i2c-tool ...

  8. can't able to update the design capacity in bq27441-G1

    /*************************************************************************** * can't able to update ...

  9. python20151125

    python exit() python test.py 输入输出 print('2\n2') print(1, 2, 3) name = input() print(':', name) 数据类型和 ...

  10. andori 动画验证必填项

    android项目开发过程中,都会碰到必填项的校验,最简单的就是利用Toast对用进行提示,感觉这种提示太不够人性化了,那么今天就来个带动画的,并可以将光标定位到必填项中. andorid动画Anim ...