标签:style blog http color io os ar for div
250:乱搞。
1 // BEGIN CUT HERE 2 /* 3 4 */ 5 // END CUT HERE 6 #line 7 "Target.cpp" 7 #include <cstdlib> 8 #include <cctype> 9 #include <cstring> 10 #include <cstdio> 11 #include <cmath> 12 #include <algorithm> 13 #include <vector> 14 #include <string> 15 #include <iostream> 16 #include <sstream> 17 #include <map> 18 #include <set> 19 #include <queue> 20 #include <stack> 21 #include <fstream> 22 #include <numeric> 23 #include <iomanip> 24 #include <bitset> 25 #include <list> 26 #include <stdexcept> 27 #include <functional> 28 #include <utility> 29 #include <ctime> 30 using namespace std; 31 32 #define PB push_back 33 #define MP make_pair 34 35 #define REP(i,n) for(i=0;i<(n);++i) 36 #define FOR(i,l,h) for(i=(l);i<=(h);++i) 37 #define FORD(i,h,l) for(i=(h);i>=(l);--i) 38 39 typedef vector<int> VI; 40 typedef vector<string> VS; 41 typedef vector<double> VD; 42 typedef long long LL; 43 typedef pair<int,int> PII; 44 45 46 class Target 47 { 48 public: 49 vector <string> draw(int n) 50 { 51 vector <string> fuck; 52 string a; 53 a.clear(); 54 for(int i = 0;i < n;i ++) 55 a.push_back(‘#‘); 56 fuck.push_back(a); 57 for(int i = 1;i < n/2 + 1;i ++) 58 { 59 for(int j =0 ;j < n ;j ++) 60 a[j] = ‘ ‘; 61 //cout << a <<endl; 62 63 for(int j = 0;j < i;j += 2 ) 64 { 65 a[j] = a[n-j -1] = ‘#‘; 66 } 67 if(i % 2 == 0 ) 68 { 69 for(int j = i;j <= n-i -1;j ++) 70 a[j] = ‘#‘; 71 } 72 73 fuck.push_back(a); 74 //cout << a << endl; 75 // printf("%d\n",fuck.size()); 76 77 } 78 for(int i= n/2 +1;i < n;i ++) 79 { 80 string temp = fuck[n-i-1]; 81 fuck.push_back(temp); 82 } 83 84 85 return fuck; 86 87 } 88 89 // BEGIN CUT HERE 90 public: 91 void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); if ((Case == -1) || (Case == 3)) test_case_3(); } 92 private: 93 template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << ‘\"‘ << *iter << "\","; os << " }"; return os.str(); } 94 void verify_case(int Case, const vector <string> &Expected, const vector <string> &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: " << print_array(Expected) << endl; cerr << "\tReceived: " << print_array(Received) << endl; } } 95 void test_case_0() { int Arg0 = 5; string Arr1[] = {"#####", "# #", "# # #", "# #", "#####" }; vector <string> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); verify_case(0, Arg1, draw(Arg0)); } 96 void test_case_1() { int Arg0 = 9; string Arr1[] = {"#########", "# #", "# ##### #", "# # # #", "# # # # #", "# # # #", "# ##### #", "# #", "#########" }; vector <string> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); verify_case(1, Arg1, draw(Arg0)); } 97 void test_case_2() { int Arg0 = 13; string Arr1[] = {"#############", "# #", "# ######### #", "# # # #", "# # ##### # #", "# # # # # #", "# # # # # # #", "# # # # # #", "# # ##### # #", "# # # #", "# ######### #", "# #", "#############" }; vector <string> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); verify_case(2, Arg1, draw(Arg0)); } 98 void test_case_3() { int Arg0 = 17; string Arr1[] = {"#################", "# #", "# ############# #", "# # # #", "# # ######### # #", "# # # # # #", "# # # ##### # # #", "# # # # # # # #", "# # # # # # # # #", "# # # # # # # #", "# # # ##### # # #", "# # # # # #", "# # ######### # #", "# # # #", "# ############# #", "# #", "#################" }; vector <string> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); verify_case(3, Arg1, draw(Arg0)); } 99 100 // END CUT HERE 101 102 }; 103 104 // BEGIN CUT HERE 105 int main() 106 { 107 Target ___test; 108 ___test.run_test(-1); 109 return 0; 110 } 111 // END CUT HERE
500:二维平面内,给你规定的步数和每步的步长,要你求最后是否能走到指定点。
思路:算出能到达的范围就行 ,最开始 用的是 be(左端点) = min(abs(be - a[i]),abs(en-a[i])),发现有问题,在 a[i] <= en && a[i] >= be 的时候 be可以等于0.
1 // BEGIN CUT HERE 2 /* 3 4 */ 5 // END CUT HERE 6 #line 7 "Jumping.cpp" 7 #include <cstdlib> 8 #include <cctype> 9 #include <cstring> 10 #include <cstdio> 11 #include <cmath> 12 #include <algorithm> 13 #include <vector> 14 #include <string> 15 #include <iostream> 16 #include <sstream> 17 #include <map> 18 #include <set> 19 #include <queue> 20 #include <stack> 21 #include <fstream> 22 #include <numeric> 23 #include <iomanip> 24 #include <bitset> 25 #include <list> 26 #include <stdexcept> 27 #include <functional> 28 #include <utility> 29 #include <ctime> 30 using namespace std; 31 32 #define PB push_back 33 #define MP make_pair 34 35 #define REP(i,n) for(i=0;i<(n);++i) 36 #define FOR(i,l,h) for(i=(l);i<=(h);++i) 37 #define FORD(i,h,l) for(i=(h);i>=(l);--i) 38 39 typedef vector<int> VI; 40 typedef vector<string> VS; 41 typedef vector<double> VD; 42 typedef long long LL; 43 typedef pair<int,int> PII; 44 45 46 class Jumping 47 { 48 public: 49 int ABS(int x) 50 { 51 if(x < 0) 52 return -x; 53 else return x; 54 } 55 string ableToGet(int x, int y, vector <int>a) 56 { 57 double p = sqrt((x*x) + (y*y) * 1.0); 58 int len = a.size(); 59 int be ; 60 int en; 61 be = 0 ; 62 en = 0 ; 63 for(int i = 0 ;i < len;i ++) 64 { 65 if(a[i] <= en && a[i] >= be) 66 be = 0 ; 67 else { 68 be = min(ABS(en -a[i]),ABS(be -a[i])); 69 } 70 en = en + a[i]; 71 //printf("%d %d %lf\n",be,en,p); 72 } 73 if(p + 1e-10 >= be && p - 1e-10 <= en) 74 { 75 return "Able"; 76 } 77 return "Not able"; 78 79 } 80 81 // BEGIN CUT HERE 82 public: 83 void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); if ((Case == -1) || (Case == 3)) test_case_3(); if ((Case == -1) || (Case == 4)) test_case_4(); if ((Case == -1) || (Case == 5)) test_case_5(); if ((Case == -1) || (Case == 6)) test_case_6(); } 84 private: 85 template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << ‘\"‘ << *iter << "\","; os << " }"; return os.str(); } 86 void verify_case(int Case, const string &Expected, const string &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << ‘\"‘ << endl; cerr << "\tReceived: \"" << Received << ‘\"‘ << endl; } } 87 void test_case_0() { int Arg0 = 5; int Arg1 = 4; int Arr2[] = {2, 5}; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); string Arg3 = "Able"; verify_case(0, Arg3, ableToGet(Arg0, Arg1, Arg2)); } 88 void test_case_1() { int Arg0 = 3; int Arg1 = 4; int Arr2[] = {4}; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); string Arg3 = "Not able"; verify_case(1, Arg3, ableToGet(Arg0, Arg1, Arg2)); } 89 void test_case_2() { int Arg0 = 3; int Arg1 = 4; int Arr2[] = {6}; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); string Arg3 = "Not able"; verify_case(2, Arg3, ableToGet(Arg0, Arg1, Arg2)); } 90 void test_case_3() { int Arg0 = 0; int Arg1 = 1; int Arr2[] = {100, 100}; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); string Arg3 = "Able"; verify_case(3, Arg3, ableToGet(Arg0, Arg1, Arg2)); } 91 void test_case_4() { int Arg0 = 300; int Arg1 = 400; int Arr2[] = {500}; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); string Arg3 = "Able"; verify_case(4, Arg3, ableToGet(Arg0, Arg1, Arg2)); } 92 void test_case_5() { int Arg0 = 11; int Arg1 = 12; int Arr2[] = {1,2,3,4,5,6,7,8,9,10}; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); string Arg3 = "Able"; verify_case(5, Arg3, ableToGet(Arg0, Arg1, Arg2)); } 93 void test_case_6() { int Arg0 = 11; int Arg1 = 12; int Arr2[] = {1,2,3,4,5,6,7,8,9,100}; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); string Arg3 = "Not able"; verify_case(6, Arg3, ableToGet(Arg0, Arg1, Arg2)); } 94 95 // END CUT HERE 96 97 }; 98 99 // BEGIN CUT HERE 100 int main() 101 { 102 int x, y,temp ; 103 vector<int> a; 104 scanf("%d %d",&x,&y); 105 106 while(scanf("%d",&temp) != EOF) 107 { 108 a.push_back(temp); 109 getchar(); 110 } 111 Jumping xx; 112 xx.ableToGet(x,y,a); 113 return 0; 114 } 115 // END CUT HERE
标签:style blog http color io os ar for div
原文地址:http://www.cnblogs.com/zyue/p/3978478.html