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 ...
随机推荐
- POJ 3792 Area of Polycubes(思维)
点我看题目 题意 : 其实我也说不太清楚题意,就是给你很多方块,每放一块方块,都要和前一块有一个面相接,如果不相接,就输出NO,并输出是第几个方块不相接的.如果满足每一个都和前边相接,那就判断所有没有 ...
- 解决浮层弹出如何加上datepicker,并且浮动在上面
最近在做一个弹出层上弹出的对话框中能弹出一个截止时间的选择框,这个选择框使用datepicker来做. 效果大致是这样的: 但是在做的时候,遇到一个问题,datepicker在弹出层的时候,时间选择框 ...
- ENVI5.1安装破解教程
原文地址: ENVI5.1安装破解_百度经验 http://jingyan.baidu.com/article/020278118b5ded1bcd9ce57a.html ENVI5.1_x86 ...
- 新建arcgis api for android 项目失败
新建ArcGIS Project for Android项目失败解决方案 - skybot的专栏 - 博客频道 - CSDN.NET http://blog.csdn.net/daonidedie/a ...
- 188. Best Time to Buy and Sell Stock IV
题目: 链接: 题解: 测试: Reference:
- umount nfs状态为busy的处理方法
umountall状态为busy的系统: 以下四种情况,文件系统都会显示:umount: file_system_name busy 1 A program is accessing a file o ...
- 在安装ISE的情况下,充分利用ISE的安装目录,查找资料
2013-06-22 11:03:02 在找资料时,通过官网输入关键字的方法找资料,有事会给出很多版本的链接.或者找不到,下面给出一种简便的方法,可以快速找到想要的资料. 如果要找ISE各个工具如pl ...
- JNDI和在tomcat中配置DBCP连接池 元数据的使用 DBUtils框架的使用 多表操作
1 JNDI和在tomcat中配置DBCP连接池 JNDI(Java Naming and Directory Interface),Java命名和目录接口,它对应于J2SE中的javax.namin ...
- Git教程(3)命令行使用git简单示例
基础 Git系统下的的文件有3种状态: 已修改(modified):已修改表示修改了文件,但还没保存到数据库中. 已暂存(staged) : 已暂存表示对一个已修改文件的当前版本做了标记,使之包含在下 ...
- Java面试题-并发容器和框架
1. 如何让一段程序并发的执行,并最终汇总结果? 答:使用CyclicBarrier 和CountDownLatch都可以,使用CyclicBarrier 在多个关口处将多个线程执行结果汇总,Coun ...