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);
}
因为不熟悉竞技场的使用,也没弄明白具体形式,顺利秃了。
折腾一次,算是懂了如何参与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);
}
相关文章推荐
- JNI.h文件浅析
- 基于XMPP协议的及时通讯
- LinearLayout android:divider属性
- vtkActor在Render中移动的方法
- 人生第一场SRM SRM695 Div.2
- MFC显示图片
- 观察者模式I
- android studio jni.h 红色报错
- 基于粒子群算法的最小二乘支持向量机实现多分类(PSO_LSSVM)
- C#值类型和引用类型的深入理解
- C#值类型和引用类型的深入理解
- C#值类型和引用类型的深入理解
- C#值类型和引用类型的深入理解
- C#值类型和引用类型的深入理解
- C#值类型和引用类型的深入理解
- C#值类型和引用类型的深入理解
- C#值类型和引用类型的深入理解
- C#值类型和引用类型的深入理解
- C#值类型和引用类型的深入理解
- C#值类型和引用类型的深入理解