您的位置:首页 > 其它

Single Round Match 695

2016-07-19 21:04 411 查看
第一次打Topcoder,好久没写类了,竟然在成员函数里又写了cin………

因为不熟悉竞技场的使用,也没弄明白具体形式,顺利秃了。

折腾一次,算是懂了如何参与TC的SRM了。以下为250points的题解。

给出每段位移,然后给出方向,最后从终点直线回到起点,return总距离。

如:

131

NES

return 8即可。

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
class BearNSWE {
public:
double totalDistance (vector <int>, string);
};
double BearNSWE::totalDistance (vector <int> a, string dir) {
int ans=0,x=0,y=0;
int len=dir.length();
for (int i=0; i<len; i++) {ans+=a[i];}
for (int i=0; i<len; i++) {
if (dir[i]=='N') {y+=a[i];}
else if (dir[i]=='S') {y-=a[i];}
else if (dir[i]=='W') {x+=a[i];}
else if (dir[i]=='E') {x-=a[i];}
}
return ans+sqrt (x*x+y*y);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: