FJNU摸底赛_acdream1681(bfs)
来源:互联网 发布:郝斌c语言笔记 编辑:程序博客网 时间:2024/05/20 21:20
题意:
要从这边岸,踩着石头跳到那边岸;
给出对岸的距离y0,石头的数量n ,和一次最多跳多远d;
然后给出n块石头的横纵坐标;
问能不能跳到对岸,能输出YES和最少跳几次;
不能输出NO和离对岸最近的距离是多少;
思路:
bfs,先把第一次能跳到的放进队列,再把第二次能跳到的放进队列,一直找到最后;
#include<cstdio>#include<cstring>#include<queue>#include<algorithm>using namespace std;const int N = 1005;struct point {int x,y;int step;}p[N];int n,y0,d;int getdis(point a, point b) {return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);}void bfs() {queue<point> q;int dis = y0;while(!q.empty())q.pop();for(int i = 0; i < n; i++) {if(p[i].y <= d) {dis = min(dis, y0 - p[i].y);p[i].step = 1;q.push(p[i]);}}while(!q.empty()) {point a = q.front();q.pop();if(y0 - a.y <= d) {printf("YES\n%d\n",a.step + 1);return;}for(int i = 0; i < n; i++) {if(getdis(a,p[i]) <= d * d && p[i].step == -1) {dis = min(dis, y0 - p[i].y);p[i].step = a.step + 1;q.push(p[i]);}}}printf("NO\n%d\n",dis);return;}int main() {int t;scanf("%d",&t);while(t--) {scanf("%d%d%d",&y0, &n, &d);for(int i = 0; i < n; i++) {scanf("%d%d",&p[i].x, &p[i].y);p[i].step = -1;}if(y0 <= d) {printf("YES\n1\n");}else {bfs();}}}
0 0
- FJNU摸底赛_acdream1681(bfs)
- FJNU摸底赛_acdream1680(水题)
- FJNU摸底赛_acdream1682(dp)
- FJNU摸底赛_acdream1683(KMP)
- FJNU摸底赛_acdream1684(博弈)
- FJNU摸底赛_acdream1686(数学)
- FJNU摸底赛_acdream1685(并查集)
- 摸底
- XMUT新生摸底训练赛
- GWXZ摸底考模拟赛
- FJNU校赛B题(dfs + bfs)
- ACdreamXMUT新生摸底训练赛C
- FJNU
- nyoj809摸底
- nyoj 摸底
- ACM学习感悟——摸底赛(并查集)
- nyoj-809-摸底
- FJNU字符串
- 点击按钮,变换颜色
- JAVA通过HTTP访问:Post+Get方式
- U3D批处理的静态与动态问题
- mysql dbi 操作<1>
- 『大型网站技术架构:核心原理与案例分析』(一)
- FJNU摸底赛_acdream1681(bfs)
- 计算器(1)
- linux测试noatime对文件访问时间的影响
- 计算器(2)
- 大型网站技术架构』(二):高性能架构
- velocity模板引挚
- 几种常见取石子模型
- Rendering Problems Exception raised during rendering: action_bar.
- linux命令之mv&cp&ls