Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int main(){
- int k, lim;
- cin>>k>>lim;
- double distatual=0; // a distância do mafioso no laço
- int tmp=0; // um auxiliar pra pegar o valor que ele andou n,s,l,o
- int v=0,h=0; // vertical e horizontal
- int cnt=0; //contador (usar distância de manhattan em 1 dimensão)
- for(int i=0;i<k;i++){
- char tmp2; //Um char pra saber aonde alocar a entrada
- cin>>tmp2>>tmp; // digito as entradas
- if(tmp>lim){ //Se a entrada > limite, aumento contador (distância de manhattan 1d)
- cnt++;
- }
- if(tmp2=='N'){
- v+=tmp; //pegando as entradas com um char
- }
- if(tmp2=='S'){
- v+=-tmp;
- }
- if(tmp2=='L'){
- h+=tmp;
- }
- if(tmp2=='O'){
- h+=-tmp;
- }
- if(h<0){
- h*=-1;
- }
- if(v<0){
- v*=-1;
- }
- if(cnt>0){
- cout<<1;
- return 0; // se contador tiver maior que 1, ele andou 1d > lim
- }
- distatual=sqrt(h*h+v*v);
- if(distatual>lim){
- cout<<1<<endl;
- return 0;
- }
- }
- cout<<0<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement