Skip to content

Instantly share code, notes, and snippets.

@meooow25
Created Feb 26, 2019
Embed
What would you like to do?
// CLTNIS
// Tester: avijit_agarwal
import java.io.*;
import java.text.DecimalFormat;
class CLTNIS
{
public static void main(String[] args)throws IOException
{
FastReader in=new FastReader(System.in);
StringBuilder sb=new StringBuilder();
DecimalFormat df=new DecimalFormat("#.#######");
int MAXN=50;
double bounds[]=new double[MAXN];
double ball[]=new double[MAXN];
double vel[]=new double[MAXN];
double chef[]=new double[MAXN];
int i,t,n,f;
double cos_alpha,cos_beta,sin_alpha,t_exit,ans;
t=in.nextInt();
while(t-->0)
{
n=in.nextInt();
f=0;
double BE=0,BC=0,CE=0,velocity=0;
for(i=0;i<n;i++)
bounds[i]=in.nextInt();
for(i=0;i<n;i++)
ball[i]=in.nextInt();
for(i=0;i<n;i++)
vel[i]=in.nextInt();
for(i=0;i<n;i++)
chef[i]=in.nextInt();
t_exit=bounds[0]/vel[0];
for(i=1;i<n;i++)
{
if(vel[i]>0)
t_exit=Math.min(t_exit,(bounds[i]-ball[i])/vel[i]);
else if(vel[i]<0)
t_exit=Math.min(t_exit,-1*(ball[i]/vel[i]));
}
for(i=0;i<n;i++)
{
BE+=Math.pow(vel[i]*t_exit,2);
BC+=Math.pow(chef[i]-ball[i],2);
CE+=Math.pow(ball[i]-chef[i]+vel[i]*t_exit,2);
velocity+=Math.pow(vel[i],2);
if(chef[i]!=ball[i])
f=1;
}
velocity=Math.pow(velocity,0.5);
cos_alpha=(BE+BC-CE)/(2*Math.pow(BE*BC,0.5));
cos_beta=(BC+CE-BE)/(2*Math.pow(BC,0.5)+Math.pow(CE,0.5));
if(f==0)
ans=0;
else if(cos_alpha<=0 || cos_beta>=0)
ans=Math.pow(CE,0.5)/t_exit;
else
{
cos_alpha=Math.min(1,cos_alpha);
sin_alpha=Math.sin(Math.acos(cos_alpha));
ans=velocity*sin_alpha;
}
sb.append(df.format(ans)).append("\n");
}
System.out.print(sb);
}
}
class FastReader {
byte[] buf = new byte[2048];
int index, total;
InputStream in;
FastReader(InputStream is) {
in = is;
}
int scan() throws IOException {
if (index >= total) {
index = 0;
total = in.read(buf);
if (total <= 0) {
return -1;
}
}
return buf[index++];
}
String next() throws IOException {
int c;
for (c = scan(); c <= 32; c = scan());
StringBuilder sb = new StringBuilder();
for (; c > 32; c = scan()) {
sb.append((char) c);
}
return sb.toString();
}
String nextLine() throws IOException {
int c;
for (c = scan(); c <= 32; c = scan());
StringBuilder sb = new StringBuilder();
for (; c !=10 && c!=13; c = scan()) {
sb.append((char) c);
}
return sb.toString();
}
char nextChar() throws IOException{
int c;
for (c = scan(); c <= 32; c = scan());
return (char)c;
}
int nextInt() throws IOException {
int c, val = 0;
for (c = scan(); c <= 32; c = scan());
boolean neg = c == '-';
if (c == '-' || c == '+') {
c = scan();
}
for (; c >= '0' && c <= '9'; c = scan()) {
val = (val << 3) + (val << 1) + (c & 15);
}
return neg ? -val : val;
}
long nextLong() throws IOException {
int c;
long val = 0;
for (c = scan(); c <= 32; c = scan());
boolean neg = c == '-';
if (c == '-' || c == '+') {
c = scan();
}
for (; c >= '0' && c <= '9'; c = scan()) {
val = (val << 3) + (val << 1) + (c & 15);
}
return neg ? -val : val;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment