hdu4435-charge-station(搜索+贪心)

时间:2021-12-01 22:52:24

题意&题解:

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. &lbrack;CQOI2012&rsqb;模拟工厂 题解&lpar;搜索&plus;贪心&rpar;

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

  2. HDU 6034---Balala Power&excl;(搜索&plus;贪心)

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

  3. &lbrack;NOIP 2010&rsqb;饮水入城 搜索&plus;贪心

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

  4. 洛谷 2668&amp&semi;2540 斗地主——搜索&plus;贪心&plus;dp

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

  5. SPOJ&colon;Strange Waca&lpar;不错的搜索&amp&semi;贪心&amp&semi;剪枝&rpar;

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

  6. 洛谷 P2668 &amp&semi; P2540 &lbrack; noip 2015 &rsqb; 斗地主 —— 搜索&plus;贪心

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

  7. hdu 5335 Walk Out 搜索&plus;贪心

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

  8. Gas Station&vert;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. CUnit的用法

    转自:http://blog.csdn.net/scucj/article/details/4385630/ CUnit下载地址: http://sourceforge.net/projects/cu ...

  2. An Easy C Program Problem

    找幸运数 题目描述 数字8最多的那个数为幸运数. 输入n和n个整数,找这n个数中的幸运数.在主函数中调用ndigit函数,判断某个整数x含数字8的个数.如果有多个幸运数输出第一个幸运数,如果所有的数中 ...

  3. Hibernate检索方式 分类: SSH框架 2015-07-10 22&colon;10 4人阅读 评论&lpar;0&rpar; 收藏

    我们在项目应用中对数据进行最多的操作就是查询,数据的查询在所有ORM框架中也占有极其重要的地位.那么,如何利用Hibernate查询数据呢?Hibernate为我们提供了多种数据查询的方式,又称为Hi ...

  4. 30 分钟 Java Lambda 入门教程

    Lambda简介 Lambda作为函数式编程中的基础部分,在其他编程语言(例如:Scala)中早就广为使用,但在Java领域中发展较慢,直到java8,才开始支持Lambda. 抛开数学定义不看,直接 ...

  5. 自顶向下分析Binder【1】—— Binder实例篇

    欢迎转载,转载请注明:http://blog.csdn.net/zhgxhuaa 一个Binder实例 我们Binder的学习将从以下的一个实例開始.依据Android文档中的描写叙述,创建一个Bin ...

  6. Python各种花式截图工具,截到你手软

    前言: 最近,项目中遇到了一个关于实现通过给定URL,实现对网页屏幕进行截图的一个功能,前面代码中已经用python的第三方库实现了截图功能,但在上线以后出现了一些bug,所以就改bug的任务就落在了 ...

  7. matlab字符串操作

    字符串转换函数 abs        字符串到ASCII转换dec2hex        十进制数到十六进制字符串转换fprintf        把格式化的文本写到文件中或显示屏上hex2dec   ...

  8. html入门第一天(知识总结)。

    一文本标签:----------双标签.<b>标签 <strong>标签,文本呈现粗体(Html5中建议用strong,strong语义更强)<i>标签 <e ...

  9. jmeter打开图形化界面时指定代理

    \apache-jmeter-4.0\bin>jmeter -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=8888 如果不想在每个请求里面指定代理的话可 ...

  10. easyui-switchbutton js判断是否启动

    <input class="easyui-switchbutton" id="statusId" name="status" onTe ...