• 原题如下:

    Angry Birds is a mobile game of a big craze all over the world. You were convinced that it was a waste of time to play the game, so you decided to create an automatic solver.

    You are describing a routine that optimizes the white bird's strategy to defeat a pig (enemy) by hitting an egg bomb. The white bird follows a parabolic trajectory from the initial position, and it can vertically drop egg bombs on the way.

    In order to make it easy to solve, the following conditions hold for the stages.

    • N obstacles are put on the stage.
    • Each obstacle is a rectangle whose sides are parallel to the coordinate axes.
    • The pig is put on the point (X, Y).
    • You can launch the white bird in any direction at an initial velocity V from the origin.
    • If the white bird collides with an obstacle, it becomes unable to drop egg bombs.
    • If the egg bomb collides with an obstacle, the egg bomb is vanished.

    The acceleration of gravity is 9.8 {\rm m/s^2}. Gravity exerts a force on the objects in the decreasing direction of y-coordinate.

    Input

    A dataset follows the format shown below:

    NVXY
    L_1B_1R_1T_1
    ...
    L_NB_NR_NT_N

    All inputs are integer.

    • N: the number of obstacles
    • V: the initial speed of the white bird
    • XY: the position of the pig

    (0 \leq N \leq 500 \leq V \leq 500 \leq X, Y \leq 300X \neq 0)

    for 1 \leq i \leq N,

    • L_i: the x-coordinate of the left side of the i-th obstacle
    • B_i: the y-coordinate of the bottom side of the i-th obstacle
    • R_i: the x-coordinate of the right side of the i-th obstacle
    • T_i: the y-coordinate of the top side of the i-th obstacle

    (0 \leq L_i, B_i, R_i, T_i \leq 300)

    It is guaranteed that the answer remains unaffected by a change of L_iB_iR_i and T_i in 10^{-6}.

    Output

    Yes/No

    You should answer whether the white bird can drop an egg bomb toward the pig.

    Sample Input 1

    0 7 3 1
    

    Output for the Sample Input 1

    Yes
    

    Sample Input 2

    1 7 3 1
    1 1 2 2

    Output for the Sample Input 2

    No
    

    Sample Input 3

    1 7 2 2
    0 1 1 2

    Output for the Sample Input 3

    No
  • 题解:最后的限制条件常常会在几何问题中附带出现,根据这一点就无需考虑只有通过像穿过针孔一样的唯一线路才能让卵击中猪的情况了。首先,让我们考虑一下如何判断以某个角度射出的鸟是否可以产卵击中猪。只要射出的鸟在撞到障碍物之前能够从猪的正上方飞过,并且此时与猪之间没有障碍物的话,在正上方产卵就可以击中猪了。判断白鸟是否撞到障碍物,就是判断抛物线和长方形是否相交(如果将长方形分解为线段,只判断抛物线是否同各条线段相交,就可能无法很好地处理抛物线恰好经过长方形的顶点的情况)。接下来,思考一下如何枚举所有关键射出角度,假设以某个角度射出时不会遇到障碍物,我们逐渐降低这个角度,直到某出变成
    ① 恰好经过(X,Y)
    ② 恰好经过某个障碍物的左上角或右上角
    就不能再降低了。虽然作为解的角度可能有无穷多个,但因为无论哪个都可以不断降低直至变为1或2的情况,所以只要检查这些角度就足够了。
  • 代码:
     #include <cstdio>
    #include <cmath> using namespace std; const double EPS=1e-;
    const int MAX_N=;
    const double g=9.8;
    int N,V,X,Y;
    int L[MAX_N], B[MAX_N], R[MAX_N], T[MAX_N]; double calc(double vy, double t)
    {
    return vy*t-g*t*t/;
    } int cmp(double lb, double ub, double a)
    {
    return a<lb+EPS ? - : a>ub-EPS ? : ;
    } bool check(double qx, double qy)
    {
    double a=g*g/, b=g*qy-V*V, c=qx*qx+qy*qy;
    double D=b*b-*a*c;
    if (D< && D>-EPS) D=;
    if (D<) return false;
    for (int d=-; d<=; d+=)
    {
    double t2=(-b+d*sqrt(D))/(*a);
    if (t2<=) continue;
    double t=sqrt(t2);
    double vx=qx/t, vy=(qy+g*t*t/)/t;
    double yt=calc(vy, X/vx);
    if (yt<Y-EPS) continue;
    bool ok=true;
    for (int i=; i<N; i++)
    {
    if (L[i]>=X) continue;
    if (R[i]==X && Y<=T[i] && B[i]<=yt) ok=false;
    int yL=cmp(B[i], T[i], calc(vy, L[i]/vx));
    int yR=cmp(B[i], T[i], calc(vy, R[i]/vx));
    int xH=cmp(L[i], R[i], vx*(vy/g));
    int yH=cmp(B[i], T[i], calc(vy, vy/g));
    if (xH== && yH>= && yL<) ok=false;
    if (yL*yR<=) ok=false;
    }
    if (ok) return true;
    }
    return false;
    } int min(int x, int y)
    {
    if (x<y) return x;
    return y;
    } int main()
    {
    scanf("%d %d %d %d", &N, &V, &X, &Y);
    for (int i=; i<N; i++)
    {
    scanf("%d %d %d %d", &L[i], &B[i], &R[i], &T[i]);
    }
    for (int i=; i<N; i++)
    {
    R[i]=min(R[i], X);
    }
    bool ok=check(X,Y);
    for (int i=; i<N; i++)
    {
    ok |= check(L[i], T[i]);
    ok |= check(R[i], T[i]);
    }
    puts(ok ? "Yes" : "No");
    }

White Bird(AOJ 2308)的更多相关文章

  1. 用Phaser实现Flappy Bird 游戏

    How to Make a Flappy Bird in HTML5 With Phaser - Part 1 Flappy Bird is a nice little game with easy ...

  2. 140行Python代码实现Flippy Bird

    140行代码实现Flippy Bird 话说这游戏中文名叫什么来着,死活想不起来了,算了话不多说,140行实现小游戏系列第二章,依然是简单小游戏,与数独游戏相比,在游戏界面显示上更难一些,但是在逻辑方 ...

  3. canvas小游戏——flappy bird

    前言 如果说学编程就是学逻辑的话,那锻炼逻辑能力的最好方法就莫过于写游戏了.最近看了一位大神的fly bird小游戏,感觉很有帮助.于是为了寻求进一步的提高,我花了两天时间自己写了一个canvas版本 ...

  4. Flappy Bird 源码走读

    参考:https://github.com/kirualex/SprityBird 该项目基于spritekit,代码的结构很清楚,感觉用来学习spritekit非常不错. 1.项目只有一个viewC ...

  5. canvas 制作flappy bird(像素小鸟)全流程

    flappy bird制作全流程: 一.前言 像素小鸟这个简单的游戏于2014年在网络上爆红,游戏上线一段时间内appleStore上的下载量一度达到5000万次,风靡一时, 近年来移动web的普及为 ...

  6. AOJ 0121: Seven Puzzle【BFS】

    From: AOJ 0121 思路:与前几题的bfs不同,这次的bfs没有明确的移动对象,看似任意一个数都可以当成对象移动.这时我们只需要抓住一个格子就行,比如我们把0作为移动对象,那么0在地图中漫游 ...

  7. fly bird

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  8. 谢欣伦 - 原创软件 - 游戏专题 - 操蛋的小鸟Fucking Bird

    前段时间朋友介绍了一个最近很火的游戏<Flappy Bird>.在工作之余,我用了三天时间做了一个类似的游戏<Fucking Bird>.一开始分享给了两个女同事,发现她们玩嗨 ...

  9. 自己动手写游戏:Flappy Bird

    START:最近闲来无事,看了看一下<C#开发Flappy Bird游戏>的教程,自己也试着做了一下,实现了一个超级简单版(十分简陋)的Flappy Bird,使用的语言是C#,技术采用了 ...

随机推荐

  1. 阿里云日志服务SLS

    前言: 刚入职实习了几天,我发现我的任务就是学习阿里云日志服务这块业务内容,这个功能和mysql一样,但是速度和视觉却是甩mysql这类数据库几条街. 当得知公司没人会这项技术后(在这之前我也没听过, ...

  2. unity探索者之微信分享所有流程,非第三方插件

    版权声明:本文为原创文章,转载请声明http://www.cnblogs.com/unityExplorer/p/7560575.html 很久没有写新博客了,前段时间有些忙,这几天趟了几个微信分享的 ...

  3. springMVC入门(六)------json交互与RESTFul风格支持

    简介 JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.由于其简单易用,目前常用来通过AJAX与后台进行交互.springMVC对于接收.发送JSON数据也 ...

  4. undertow配置

    # 设置IO线程数, 它主要执行非阻塞的任务,它们会负责多个连接, 默认设置每个CPU核心一个线程 # 不要设置过大,如果过大,启动项目会报错:打开文件数过多 #server.undertow.io- ...

  5. 第4篇 Scrum 冲刺博客(专✌️团队)

    一.站立式会议 1.1会议图片 1.2成员完成情况 成员 昨天完成的任务 今天计划完成的任务 工作中的困难 陈忠明 按下载热度返回歌曲信息,与前端尝试交互 歌曲信息的上传/下载包 前后端交互问题 吴茂 ...

  6. Lua语言15分钟快速入门

    转载自: https://blog.csdn.net/qq_15437667/article/details/75042526 -- 单行注释 --[[ [多行注释] --]] ---------- ...

  7. 消息型中间件之RabbitMQ基础使用

    1.概念 RabbitMQ是AMQP(高级消息队列协议)协议的实现主要功能用于分布式应用当中的各组件间解耦.在传统C/S架构中,如果客户端发送一个请求消息,服务端必须得在线,有了中间件,客户端不是非得 ...

  8. 字段在class文件中的存在形式——FieldInfo

    每个字段(Field)都有field_info结构所定义,一个class文件中,不会有两个字段同时具有相同的名字和描述符 name_index:值为一个整数(常量池表中的有效索引),例如name_in ...

  9. C/C++ MFC

    C++ & MFC(转载)   C++是一种静态数据类型检查的.支持多重编程范式的程序设计语言,支持过程化程序设计.数据抽象.面向对象程序设计.制作图标等泛型程序设计的多种程序设计风格. MF ...

  10. Qt 怎样生成带图标的exe

    一.问题描述 当我们在 Windows 下用 VS 生成 exe 程序时,如果窗口程序指定了图标,那么生成的 exe 程序便是指定的图标模样. 但是,当使用 Qt Creator 编译程序却不同.即使 ...