uva 11657,

來源:互聯網
上載者:User

uva 11657,

題目連結:uva 11657 - Rational Billiard

題目大意:給定一個邊界M,N,以及第一個球和第二個球的位置,第一個球以p,q的方向移動,碰到邊界後被反彈,和光線的路線一致,問有沒有可能集中第二個球。

解題思路:在網上參考別人的思路,首先將橫縱座標擴大相應倍數,保證p,q每移動一次對應在新平面為單位長度,然後只需要考慮橫向移動所需要的步數,減掉縱向移動所需的步數後,剩餘的步數是否滿足周期的倍數即可。考慮四種請況。這題資料非常水,一開始座標寫錯也過了。

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long ll;ll m, n, x0, y0, x1, y1, p, q;ll gcd (ll a, ll b) {    return b == 0 ? a : gcd(b, a % b);}bool judge () {    if (p == 0 || q == 0) {        ll u = p * (y1-y0) - q * (x1-x0);        return u == 0;    }    ll absq = q < 0 ? -q : q;    ll absp = p < 0 ? -p : p;    m *= absq; x0 *= absq; x1 *= absq;    n *= absp; y0 *= absp; y1 *= absp;    p /= absp; q /= absq;    ll d1 = q * (y1-y0) - p * (x1-x0);    ll d2 = q * (y1-y0) - p * (2*m-x1-x0);    ll d3 = q * (2*n-y1-y0) - p * (x1-x0);    ll d4 = q * (2*n-y1-y0) - p * (2*m-x1-x0);    ll g = gcd(2*m, 2*n);    if (d1 % g == 0) return true;    if (d2 % g == 0) return true;    if (d3 % g == 0) return true;    if (d4 % g == 0) return true;    return false;}int main () {    while (scanf("%lld%lld%lld%lld%lld%lld%lld%lld", &m, &n, &x0, &y0, &x1, &y1, &p, &q) == 8) {        if (!(m || n || x0 || y0 || x1 || y1 || p || q))            break;        printf("%s\n", judge() ? "HIT" : "MISS");    }    return 0;}



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.