Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. int main(){
  5. int k, lim;
  6. cin>>k>>lim;
  7. double distatual=0; // a distância do mafioso no laço
  8. int tmp=0; // um auxiliar pra pegar o valor que ele andou n,s,l,o
  9. int v=0,h=0; // vertical e horizontal
  10. int cnt=0; //contador (usar distância de manhattan em 1 dimensão)
  11. for(int i=0;i<k;i++){
  12. char tmp2; //Um char pra saber aonde alocar a entrada
  13. cin>>tmp2>>tmp; // digito as entradas
  14. if(tmp>lim){ //Se a entrada > limite, aumento contador (distância de manhattan 1d)
  15. cnt++;
  16. }
  17. if(tmp2=='N'){
  18. v+=tmp; //pegando as entradas com um char
  19. }
  20. if(tmp2=='S'){
  21. v+=-tmp;
  22. }
  23. if(tmp2=='L'){
  24. h+=tmp;
  25. }
  26. if(tmp2=='O'){
  27. h+=-tmp;
  28. }
  29. if(h<0){
  30. h*=-1;
  31. }
  32. if(v<0){
  33. v*=-1;
  34. }
  35. if(cnt>0){
  36. cout<<1;
  37. return 0; // se contador tiver maior que 1, ele andou 1d > lim
  38. }
  39. distatual=sqrt(h*h+v*v);
  40. if(distatual>lim){
  41. cout<<1<<endl;
  42. return 0;
  43. }
  44. }
  45. cout<<0<<endl;
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement