• LightOJ


    链接:

    https://vjudge.net/problem/LightOJ-1323

    题意:

    You are given a rectangular billiard board, L and W be the length and width of the board respectively. Unlike other billiard boards it doesn't have any pockets. So, the balls move freely in the board. Assume that initially some balls are in the board and all of them are moving diagonally. Their velocities are same but their direction may be different. When one or more balls bounce off, their position changes but their velocity remains same.

    You are given the initial positions of the balls and their directions; your task is to find the position of the balls after K seconds. The board is placed in the 2D plane such that the boundaries are (0, 0), (L, 0), (L, W) and (0, W). The positions of balls are given as 2D co-ordinates and they all lie inside the board. And the directions are given as one of the following {NE, SE, SW, NW}, N, E, S and W denote North, East, South and West respectively. NE means North-East so both x and y are increasing. The balls are so small that their radiuses can be said to be 0. In each second, the balls advance one unit in their direction. Here one unit doesn't mean Euclidean one unit. For example, if the current position of a ball is (x, y) and its direction is NW then in the next second its position will be (x-1, y+1).

    When two or more balls bounce off, they may change their directions as shown in the pictures. You can rotate the pictures to get all possible results. Remember that the balls may bounce at non-integer points.、

    思路:

    因为输出是排序后的,考虑两个球相撞,路径不会改变,改变编号,就可以忽略碰撞。

    代码:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #include<math.h>
    #include<vector>
    #include<map>
    
    using namespace std;
    typedef long long LL;
    const int INF = 1e9;
    
    const int MAXN = 1e6+10;
    const int MOD = 1e9+7;
    
    struct Node
    {
        int x, y;
    }node[1010];
    
    int n;
    int l, w, k;
    
    bool cmp(Node a, Node b)
    {
        if (a.x != b.x)
            return a.x < b.x;
        return a.y < b.y;
    }
    
    int Up(int x, int bor)
    {
        int less = k%(2*bor);
        if (less > (bor-x))
        {
            less = less-(bor-x);
            if (less > bor)
                return less-bor;
            return bor-less;
        }
        else
            return x+less;
    }
    
    int Down(int x, int bor)
    {
        int less = k%(2*bor);
        if (less > x)
        {
            less -= x;
            if (less > bor)
                return bor-(less-bor);
            return less;
        }
        else
            return x-less;
    }
    
    int main()
    {
        int t, cnt = 0;
        scanf("%d", &t);
        while(t--)
        {
            printf("Case %d:", ++cnt);
            scanf("%d%d%d%d", &l, &w, &n, &k);
            int x, y;
            char op[10];
            for (int i = 1;i <= n;++i)
            {
                scanf("%d%d", &x, &y);
                node[i].x = x, node[i].y = y;
                scanf("%s", op);
                if (op[0] == 'N')
                    node[i].y = Up(y, w);
                if (op[0] == 'S')
                    node[i].y = Down(y, w);
                if (op[1] == 'E')
                    node[i].x = Up(x, l);
                if (op[1] == 'W')
                    node[i].x = Down(x, l);
                //cout << node[i].x << ' ' << node[i].y << endl;
            }
            sort(node+1, node+1+n, cmp);
            for (int i = 1;i <= n;i++)
                printf("
    %d %d", node[i].x, node[i].y);
            puts("");
        }
    
        return 0;
    }
    
  • 相关阅读:
    Spring整合JMS-基于activeMQ实现(二)
    iOS 2D绘图详解(Quartz 2D)之概述
    iOS开发UI-利用Quartz2D 实现基本绘图(画三角形、矩形、圆、圆弧)
    Quart 2D 绘制图形简单总结
    IOS用CGContextRef画各种图形(文字、圆、直线、弧线、矩形、扇形、椭圆、三角形、圆角矩形、贝塞尔曲线、图片)
    用 Swift 制作一个漂亮的汉堡按钮过渡动画
    CAShapeLayer和CAGradientLayer
    Swift计算属性
    Swift常用语法示例代码(二)
    Swift 中的指针使用
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11841431.html
Copyright © 2020-2023  润新知