ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1642. 1D Maze

wa #13 ПОЧЕМУУУУУУУУ
Posted by Лерник Казарян 30 Nov 2013 21:08
#include<iostream>
#include<vector>
using namespace std;
int main()
{
int n,x,m=0,k=0,g;
cin>>n>>x;
vector<int> a(n);
if(n==1)
{
cin>>g;
if(g<0&&x>0)
{
cout<<x<<" "<<-2*g+x;
}
else if(g>0&&x<0)
{
cout<<2*g-x<<" "<<-x;
}
else
cout<<"Impossible";
}
else
{
for(int i=0;i<n;i++)
{
cin>>a[i];
if(a[i]<x&&m==0)
m=a[i];
else if(a[i]<x&&a[i]>m&&m!=0)
m=a[i];
else if(a[i]>x&&k==0)
k=a[i];
else if(a[i]>x&&k!=0&&a[i]<k)
k=a[i];
}
if(m<0&&k>0)
{
if(x<0)
cout<<2*k-x<<" "<<-x;
else
cout<<x<<" "<<-2*m+x;
}
else if(m<0&&k==0&&x>0)
{
cout<<x<<" "<<2*x-m;
}
else if(k>0&&m==0&&x<0)
{
cout<<2*k-x<<" "<<-x;
}
else
cout<<"Impossible";
}

return 0;
}
Re: wa #13 ПОЧЕМУУУУУУУУ
Posted by Vanakals 4 Apr 2014 17:37
И у меня так же (((

#include<iostream>
#include<vector>
using namespace std;
int main()
{
int n,p,c,nmc=-1,nbmc=1;

cin>>n>>p;
int *mas=new int [n];
for(int i(0); i<n; i++)
cin>>mas[i];
for (c = 0; c < n; ++c) if ( mas[c] < 0 && (nmc == -1 || mas[c] > mas[nmc]) ) nmc = c;
for (c = 0; c < n; ++c) if ( mas[c] > 0 && (nbmc == 1 || mas[c] < mas[nbmc]) ) nbmc = c;
if(p>0 && n!=1)
{
if (mas[nbmc]<p)
cout<<"Impossible"<<endl;
else
cout<<p<<' '<<(2*(abs(mas[nmc])))+p<<endl;

}
if(p<0 && n!=1)
{
if(mas[nmc]>p)
cout<<"Impossible"<<endl;
else
cout<<(2*(mas[nbmc]))-p<<' '<<-p<<endl;

}
if(n==1)
for(int i(0); i<n; i++)
{
if(mas[i]<0&&p>0)
{
cout<<p<<" "<<-2*(mas[i])+p;
}
else if(mas[i]>0&&p<0)
{
cout<<2*(mas[i])-p<<" "<<-p;
}
else
cout<<"Impossible";
}
cout<<endl;
/*cout<<mas[nmc]<<' '<<mas[nbmc]<<endl;*/
return 0;
}