当前位置: 代码迷 >> 综合 >> UVA11880 - Ball in a Rectangle
  详细解决方案

UVA11880 - Ball in a Rectangle

热度:15   发布时间:2023-11-24 22:29:24.0

题目链接:点击打开链接

题意一个半径为r的求以大小为v,初速度方向为a在l*w的矩阵中运动,碰撞后无能量损耗,问s秒后球所在位置。

令x-r,y-r,l-2*r,w-2*r,然后矢量分解,x方向总距离sumx = x + v*s*cos(a*180/pi), sumy = y + v*s*sin(a*180/pi),就等价于从(0,0)出发,然后就可以直接计算最终位置了,

注意因为0<=a<360,x<0时直接取正就行,因为从0,0出发往负方向运动会直接反弹。

#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/hash_set>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
#define XINF INT_MAX
#define INF 0x3F3F3F3F
#define MP(X,Y) make_pair(X,Y)
#define PB(X) push_back(X)
#define REP(X,N) for(int X=0;X<N;X++)
#define REP2(X,L,R) for(int X=L;X<=R;X++)
#define DEP(X,R,L) for(int X=R;X>=L;X--)
#define CLR(A,X) memset(A,X,sizeof(A))
#define IT iterator
#define RIT reverse_iterator
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<PII> VII;
typedef vector<int> VI;
typedef tree<PII, null_type, greater<PII>, rb_tree_tag, tree_order_statistics_node_update > rb_tree_set;
typedef tree<PII, PII, greater<PII>, rb_tree_tag, tree_order_statistics_node_update > rb_tree;
#define PQ std::priority_queue
#define HEAP __gnu_pbds::priority_queue
#define X first
#define Y second
#define lson(X) ((X)<<1)
#define rson(X) ((X)<<1|1)
#define EPS 10e-6
#define pi acos(-1)
double judge(double x, double r)
{x = fabs(x);int num = (int)x/(2*r);x = x - 2*r*num;if(x > r)x = r - (x-r);return x;
}
int main()
{double l, w, x, y, r, a, v, s;while(cin>>l>>w>>x>>y>>r>>a>>v>>s, l||w||x||y||r||a||v||s) {l -= 2*r;w -= 2*r;x -= r;y -= r;double tx = v*s;x = x + tx*cos(pi/180*a);y = y + tx*sin(pi/180*a);x = judge(x, l);y = judge(y, w);printf("%.2lf %.2lf\n", x+r, y+r);}return 0;
}


  相关解决方案