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 ...
随机推荐
- linux 使用文本编辑器编写shell脚本执行权限不够
在linux下,自己编写的脚本需要执行的时候,需要加上执行的权限 解决方式:chmod 777 test.sh
- 李洪强iOS开发之拓展篇—UIDynamic(简单介绍)
iOS开发拓展篇—UIDynamic(简单介绍) 一.简单介绍 1.什么是UIDynamic UIDynamic是从iOS 7开始引入的一种新技术,隶属于UIKit框架 可以认为是一种物理引擎,能 ...
- SaaS系列介绍之四:我国SaaS市场发展
1 引言 那些没有经验的问题解决者们,几乎无一例外,都是去匆忙地寻找解决办法,而不是先给要解决的问题下定义. ...
- *[topcoder]GooseTattarrattatDiv1
http://community.topcoder.com/stat?c=problem_statement&pm=12730&rd=15701 这道题有点意思.首先把字符串变成回文, ...
- maven更新总结与tomcat发布方法总结
这些天来一直为不能直接把项目实时的发布到tomcat而费心思,项目使用了maven来组织,编译和运行,而maven插件的安装曾经有些问题,为此怀疑不能发布项目到tomcat是因为maven有问题,为些 ...
- Java 的 Class Path 和 Package
前言: 由于这两个问题新手问得较多, 且回答比较零散, 很难统一整理, 所以就直接写了一篇, 还请大家见谅. 正文:一, 类路径 (class path) 当你满怀着希望安装好了 java, ...
- Shell中调用、引用、包含另一个脚本文件的三种方法
脚本 first (测试示例1) first#!/bin/bashecho 'your are in first file' 方法一:使用source #!/bin/bashecho 'your ar ...
- node.js模块之Buffer模块
http://nodejs.org/api/buffer.html Pure JavaScript is Unicode friendly but not nice to binary data. W ...
- cmd启动tomcat
1.安装jdk 2.安装tomcat 3.需要配置两个用户环境变量,仅仅配置系统变量没用. a)JAVA_HOME:D:\programing~tools\java~tools\JDK(tm)\jdk ...
- xml--通过jdom解析及生产XML
JDOM是一种使用 XML 的独特 Java 工具包,用于快速开发 XML 应用程序.它的设计包含 Java 语言的语法乃至语义. JAXP (用于 XML 语法分析的 Java API)包含了三个软 ...