Last active
July 29, 2016 13:02
-
-
Save algon-320/b30dda75efbd35a1b5cfc24b0d16f796 to your computer and use it in GitHub Desktop.
SRM 695 easy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
typedef pair<int,int> pii; | |
typedef long long ll; | |
#define ITR(i,c) for(auto i=begin(c);i!=end(c);i++) | |
#define FORE(x,arr) for(auto &x:arr) | |
#define FOR(i,a,n) for(int i=a;i<(int)(n);i++) | |
#define REP(i,n) FOR(i,0,n) | |
#define ALL(c) begin(c),end(c) | |
const int DX[4]={0,1,0,-1}, DY[4]={-1,0,1,0}; | |
const int INF = 1e9; | |
struct BearNSWE { | |
double totalDistance(vector<int> a, string dir) { | |
double ans = 0; | |
int x=0,y=0; | |
REP(i,dir.size()) { | |
if(dir[i]=='N') y+=a[i]; | |
else if(dir[i]=='E') x+=a[i]; | |
else if(dir[i]=='S') y-=a[i]; | |
else x-=a[i]; | |
ans += a[i]; | |
} | |
ans += sqrt(x*x+y*y); | |
return ans; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment