QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#575436 | #3195. Within Arm's Reach | qwqUwU_ | WA | 0ms | 3920kb | C++14 | 1.8kb | 2024-09-19 14:19:04 | 2024-09-19 14:19:08 |
Judging History
answer
#include<bits/stdc++.h>
#define pb push_back
#define P make_pair
#define fi first
#define se second
#define bit(s,x) (((s)>>(x))&1)
#define pnp(s) __builtin_popcountll(s)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
inline ll read(){
ll x=0,f=1,c=getchar();
while(c<'0'||c>'9')f=(c=='-'?-1:1),c=getchar();
while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
const int N=23;
const double eps=1e-8;
int n,id[N];
double a[N],x[N],y[N];
int main() {
//freopen("data.in", "r", stdin);
// freopen("myans.out","w",stdout);
n=read();rep(i,1,n)a[i]=read(),id[i]=i;
sort(id+1,id+n+1,[](int i,int j){return a[i]<a[j];});
double px=read(),py=read(),len=sqrt(px*px+py*py);
double s=0,s2=0;rep(i,1,n)s+=a[i];
double X=0,Y=0;
if(s<=len){
rep(i,1,n){
x[i]=px*(a[i]/len);
y[i]=py*(a[i]/len);
}
}
else{
rep(i,1,n){
int j=id[i];
if(s-s2-2*a[j]>=len){
s2+=a[j];s-=a[j];
x[j]=-px*(a[j]/len);
y[j]=-py*(a[j]/len);
X+=x[j],Y+=y[j];
continue;
}
if(i==n){
x[j]=px*(a[j]/len);
y[j]=py*(a[j]/len);
break;
}
s-=a[j];s2+=len;
double k=py/px;
double c=(a[j]*a[j]+s2*s2-s*s)/(2*a[j]*s2);
double t=sqrt(1-c*c)/c;
double k2=(k+t)/(1-k*t);k2*=k2;
x[j]=a[j]*sqrt(1/(1+k2));
y[j]=a[j]*sqrt(k2/(1+k2));
c=(s2*s2+s*s-a[j]*a[j])/(2*s*s2);
t=sqrt(1-c*c)/c;
k2=(k-t)/(1+k*t);k2*=k2;
rep(j,i+1,n){
int k=id[j];
x[k]=a[k]*sqrt(1/(1+k2));
y[k]=a[k]*sqrt(k2/(1+k2));
}
break;
}
}
rep(i,1,n){
//double len=sqrt(x[i]*x[i]+y[i]*y[i]);
//assert(fabs(len-a[i])<=eps);
x[i]+=x[i-1],y[i]+=y[i-1];
printf("%.6lf %.6lf\n",x[i],y[i]);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3920kb
input:
2 4 2 -8 -3
output:
-3.745317 -1.404494 -5.617975 -2.106741
result:
ok ACCEPTED
Test #2:
score: 0
Accepted
time: 0ms
memory: 3916kb
input:
1 10 10 0
output:
10.000000 0.000000
result:
ok ACCEPTED
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3760kb
input:
1 10 0 0
output:
-nan -nan
result:
wrong output format Expected double, but "-nan" found