SRM 406(1-250pt, 1-500pt)
DIV1 250pt
题意:有几家宠物店,vecort<int>A表示每家宠物店含有小狗占小狗总数的百分比。现在要做扇形统计图统计每家店的小狗百分比,如下图,问作出来的扇形统计图中最多含有多少对半径夹角为180度。(左图两对,右图一对) (A.size() <= 8)
解法:因为A.size() <= 8,所以直接暴力枚举A中元素的全排列就好了。我的代码又写复杂了。。。一是枚举全排列可以用next_permutation()函数,另一个是对每个排列统计数量的时候写复杂了,不需要算j < i的情况,只要不除以2就行了。
tag:brute-force
1 // BEGIN CUT HERE 2 /* 3 * Author: plum rain 4 * score : 5 */ 6 /* 7 8 */ 9 // END CUT HERE 10 #line 11 "SymmetricPie.cpp" 11 #include <sstream> 12 #include <stdexcept> 13 #include <functional> 14 #include <iomanip> 15 #include <numeric> 16 #include <fstream> 17 #include <cctype> 18 #include <iostream> 19 #include <cstdio> 20 #include <vector> 21 #include <cstring> 22 #include <cmath> 23 #include <algorithm> 24 #include <cstdlib> 25 #include <set> 26 #include <queue> 27 #include <bitset> 28 #include <list> 29 #include <string> 30 #include <utility> 31 #include <map> 32 #include <ctime> 33 #include <stack> 34 35 using namespace std; 36 37 #define clr0(x) memset(x, 0, sizeof(x)) 38 #define clr1(x) memset(x, -1, sizeof(x)) 39 #define pb push_back 40 #define sz(v) ((int)(v).size()) 41 #define all(t) t.begin(),t.end() 42 #define zero(x) (((x)>0?(x):-(x))<eps) 43 #define out(x) cout<<#x<<":"<<(x)<<endl 44 #define tst(a) cout<<a<<" " 45 #define tst1(a) cout<<#a<<endl 46 #define CINBEQUICKER std::ios::sync_with_stdio(false) 47 48 typedef vector<int> VI; 49 typedef vector<string> VS; 50 typedef vector<double> VD; 51 typedef pair<int, int> pii; 52 typedef long long int64; 53 54 const double eps = 1e-8; 55 const double PI = atan(1.0)*4; 56 const int inf = 2139062143 / 2; 57 58 int n, ans; 59 VI an, dn; 60 bool mp[10]; 61 int sum[10]; 62 63 void dfs(int x) 64 { 65 if (x == n){ 66 clr0 (sum); sum[0] = dn[an[0]]; 67 for (int i = 1; i < n; ++ i) 68 sum[i] = sum[i-1] + dn[an[i]]; 69 70 int cnt = 0; 71 for (int i = 0; i < n; ++ i) 72 for (int j = 0; j < n; ++ j){ 73 int tmp = j > i ? sum[j] - sum[i] : sum[n-1] - sum[i] + sum[j]; 74 if (tmp == 50) ++ cnt; 75 } 76 ans = max(ans, cnt/2); 77 return ; 78 } 79 80 for (int i = 0; i < n; ++ i) if (!mp[i]){ 81 an.pb (i); mp[i] = 1; 82 dfs (x + 1); 83 an.pop_back(); mp[i] = 0; 84 } 85 } 86 87 class SymmetricPie 88 { 89 public: 90 int getLines(vector <int> D){ 91 dn = D; 92 ans = 0; n = sz(dn); 93 clr0 (mp); an.clear(); 94 dfs (0); 95 return ans; 96 } 97 98 // BEGIN CUT HERE 99 public: 100 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(); } 101 private: 102 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(); } 103 void verify_case(int Case, const int &Expected, const int &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } } 104 void test_case_0() { int Arr0[] = {10,40,10,40}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 2; verify_case(0, Arg1, getLines(Arg0)); } 105 void test_case_1() { int Arr0[] = {10,50,40}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 1; verify_case(1, Arg1, getLines(Arg0)); } 106 void test_case_2() { int Arr0[] = {50,50}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 1; verify_case(2, Arg1, getLines(Arg0)); } 107 void test_case_3() { int Arr0[] = {1,48,1,1,48,1}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 3; verify_case(3, Arg1, getLines(Arg0)); } 108 void test_case_4() { int Arr0[] = {2,2,96}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 0; verify_case(4, Arg1, getLines(Arg0)); } 109 110 // END CUT HERE 111 112 }; 113 114 // BEGIN CUT HERE 115 int main() 116 { 117 // freopen( "a.out" , "w" , stdout ); 118 SymmetricPie ___test; 119 ___test.run_test(-1); 120 return 0; 121 } 122 // END CUT HERE
DIV1 500pt
题意:有一张纸,纸上有n * m格,每个格子上有一个数字。若将纸折叠(可以不对折,但是折痕只能在格与格之间,不能穿过格子。),折叠后重合的两个格子原先的值之和即为现在的值,比如1*2的纸含有两个数字1,2,折叠后含有一个数字3。折叠完成后,最终纸上所有数字中最大的为max。问随意折叠多少次,求max最大为多少。n <= 12,m <= 12,-100 <= A[i][j] <= 100
解法:也是暴力,只不过要预处理+暴力。只是开始我想到暴力的时候觉得这样不好写,而且感觉好慢可能不行,就没有细想了。。。所以也没有做出来。暴力的方法是,先预处理哪些列最终可能折叠在一起,再预处理哪些行最终可能会折叠在一起,然后对于处理出来的东西枚举就好了。我看了官方题解也没想好怎么写,然后又看了它推荐的代码才弄懂。
tag:brute-force
1 // BEGIN CUT HERE 2 /* 3 * Author: plum rain 4 * score : 5 */ 6 /* 7 8 */ 9 // END CUT HERE 10 #line 11 "FoldThePaper.cpp" 11 #include <sstream> 12 #include <stdexcept> 13 #include <functional> 14 #include <iomanip> 15 #include <numeric> 16 #include <fstream> 17 #include <cctype> 18 #include <iostream> 19 #include <cstdio> 20 #include <vector> 21 #include <cstring> 22 #include <cmath> 23 #include <algorithm> 24 #include <cstdlib> 25 #include <set> 26 #include <queue> 27 #include <bitset> 28 #include <list> 29 #include <string> 30 #include <utility> 31 #include <map> 32 #include <ctime> 33 #include <stack> 34 35 using namespace std; 36 37 #define clr0(x) memset(x, 0, sizeof(x)) 38 #define clr1(x) memset(x, -1, sizeof(x)) 39 #define pb push_back 40 #define sz(v) ((int)(v).size()) 41 #define all(t) t.begin(),t.end() 42 #define zero(x) (((x)>0?(x):-(x))<eps) 43 //#define out(x) cout<<#x<<":"<<(x)<<endl 44 //#define tst(a) cout<<a<<" " 45 //#define tst1(a) cout<<#a<<endl 46 #define CINBEQUICKER std::ios::sync_with_stdio(false) 47 48 typedef vector<int> vi; 49 typedef vector<string> vs; 50 typedef vector<double> vd; 51 typedef pair<int, int> pii; 52 typedef long long int64; 53 54 const double eps = 1e-8; 55 const double PI = atan(1.0)*4; 56 const int inf = 2139062143 / 2; 57 58 int n, m; 59 int an[55][55]; 60 bool can[1<<12]; 61 vector<vi> row, col; 62 63 vi getvec(int x, int f) 64 { 65 vi v; 66 for (int i = 0; i < (f ? m : n); ++ i) 67 if (x & (1<<i)) v.pb (i); 68 return v; 69 } 70 71 void rec(vi v){ 72 //for (int i = 0; i < sz(v); ++ i) 73 //tst (v[i]); 74 //cout << endl; 75 int n = sz(v); 76 for (int i = 0; i < n; ++ i) 77 can[v[i]] = 1; 78 for (int i = 1; i < n; ++ i){ 79 vi nv(max(i, n-i)); 80 if (i <= n/2){ 81 for (int j = i; j < n; ++ j) 82 nv[j-i] = v[j]; 83 for (int j = 0, k = i-1; j < i; ++ j, -- k) 84 nv[j] |= v[k]; 85 } 86 else{ 87 for (int j = 0; j < i; ++ j) 88 nv[j] = v[j]; 89 for (int j = i, k = i-1; j < n; ++ j, -- k) 90 nv[k] |= v[j]; 91 } 92 rec(nv); 93 } 94 } 95 96 class FoldThePaper 97 { 98 public: 99 int getValue(vector <string> pap){ 100 n = sz(pap); 101 stringstream stm; 102 for (int i = 0; i < n; ++ i){ 103 stm << pap[i]; m = 0; 104 while (stm >> an[i][m]) ++ m; 105 stm.clear(); 106 } 107 clr0 (can); 108 vi v; 109 for (int i = 0; i < n; ++ i) v.pb (1<<i); 110 rec(v); 111 row.clear(); 112 for (int i = 0; i < (1<<n); ++ i) if (can[i]) 113 row.pb (getvec(i, 0)); 114 115 v.clear(); clr0 (can); 116 for (int i = 0; i < m; ++ i) v.pb (1<<i); 117 rec(v); 118 col.clear(); 119 for (int i = 0; i < (1<<m); ++ i) if (can[i]) 120 col.pb (getvec(i, 1)); 121 122 int ans = -inf; 123 for (int i = 0; i < sz(row); ++ i) 124 for (int j = 0; j < sz(col); ++ j){ 125 int tmp = -inf; 126 for (int t = 0; t < sz(row[i]); ++ t) 127 for (int k = 0; k < sz(col[j]); ++ k){ 128 if (tmp == -inf) tmp = an[row[i][t]][col[j][k]]; 129 else tmp += an[row[i][t]][col[j][k]]; 130 } 131 ans = max(tmp, ans); 132 } 133 return ans; 134 } 135 136 // BEGIN CUT HERE 137 public: 138 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(); } 139 private: 140 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(); } 141 void verify_case(int Case, const int &Expected, const int &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } } 142 void test_case_0() { string Arr0[] = { 143 "1 1 1", 144 "1 1 1" 145 }; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 6; verify_case(0, Arg1, getValue(Arg0)); } 146 void test_case_1() { string Arr0[] = { 147 "1 -1", 148 "1 -1" 149 }; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 2; verify_case(1, Arg1, getValue(Arg0)); } 150 void test_case_2() { string Arr0[] = { 151 "1 -1 -1 1", 152 "-1 -1 -1 -1", 153 "-1 -1 -1 -1", 154 "1 -1 -1 1" 155 }; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 4; verify_case(2, Arg1, getValue(Arg0)); } 156 void test_case_3() { string Arr0[] = { 157 "20 13 -2 100", 158 "-12 0 4 -3", 159 "4 1 -36 21" 160 }; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 131; verify_case(3, Arg1, getValue(Arg0)); } 161 void test_case_4() { string Arr0[] = { 162 "0" 163 }; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 0; verify_case(4, Arg1, getValue(Arg0)); } 164 165 // END CUT HERE 166 167 }; 168 169 // BEGIN CUT HERE 170 int main() 171 { 172 // freopen( "a.out" , "w" , stdout ); 173 FoldThePaper ___test; 174 ___test.run_test(-1); 175 return 0; 176 } 177 // END CUT HERE
------------------------------------------------------------------
现在的你,在干什么呢?
你是不是还记得,你说你想成为岩哥那样的人。
现在的你,在干什么呢?
你是不是还记得,你说你想成为岩哥那样的人。