[构造] SRM 689 div1 MultiplicationTable3
来源:互联网 发布:程序员 博客 平台 编辑:程序博客网 时间:2024/05/18 02:31
构造一个
n∗n 的数组gi,j 。
一个集合S 是好的当且仅当对于集合中的任意两个数x ,y ,gx,y 也在S 中。
请构造一个数组使得好的集合个数恰好为K ,n≤20 。
考虑经典套路 构造
- 对于
2x ,新加元素p ,使得gp,i=gi,p=i ,那么p 可选可不选 - 对于
x+1 ,新加p ,gp,i=gp,i=i−1 ,那么选了p 之后 得把所有的元素都选上
// BEGIN CUT HERE #include<conio.h>#include<sstream>// END CUT HERE #include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<iostream>#include<algorithm>#include<vector>#include<map>#include<string>#include<set>#define pb push_back#define cl(x) memset(x,0,sizeof(x))using namespace std;typedef long long ll;const int N=25; int p;int g[N][N];inline void Solve(int x){ if (x==2){ ++p,g[1][1]=1; return; } if (~x&1){ Solve(x>>1); ++p; for (int i=1;i<=p;i++) g[i][p]=g[p][i]=i; }else{ Solve(x-1); ++p; g[1][p]=g[p][1]=1; for (int i=2;i<=p;i++) g[i][p]=g[p][i]=i-1; }}vector<int> ans;class MultiplicationTable3{public: vector <int> construct(int x){ x++; p=0; Solve(x); ans.clear(); for (int i=1;i<=p;i++) for (int j=1;j<=p;j++) ans.pb(g[i][j]-1); return ans; } // BEGIN CUT HEREpublic: 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(); }private: 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(); } void verify_case(int Case, const vector <int> &Expected, const vector <int> &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; } } void test_case_0() { int Arg0 = 2; int Arr1[] = {1, 1, 1, 1 }; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); verify_case(0, Arg1, construct(Arg0)); } void test_case_1() { int Arg0 = 3; int Arr1[] = {0, 1, 0, 1 }; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); verify_case(1, Arg1, construct(Arg0)); } void test_case_2() { int Arg0 = 6; int Arr1[] = {0, 1, 1, 0, 1, 2, 0, 1, 2 }; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); verify_case(2, Arg1, construct(Arg0)); } void test_case_3() { int Arg0 = 31; int Arr1[] = {0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4 }; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); verify_case(3, Arg1, construct(Arg0)); } void test_case_4() { int Arg0 = 1; int Arr1[] = {0 }; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); verify_case(4, Arg1, construct(Arg0)); } // END CUT HERE};// BEGIN CUT HEREint main(){ MultiplicationTable3 ___test; ___test.run_test(-1); getch() ; return 0;}// END CUT HERE
0 0
- [构造] SRM 689 div1 MultiplicationTable3
- [构造 二分图] SRM 693 div1 BipartiteConstruction
- [贪心 构造] SRM 717 div1 ScoresSequence
- TopCoder SRM 658 Div1 300 - OddEvenTree (树的性质 + 构造)
- [构造 哈密顿路径] SRM 704 div1 HamiltonianConstruction
- SRM 465(DIV1 DIV2)
- SRM 465(DIV1 DIV2)
- SRM 144 DIV1 second
- SRM 507 DIV1 B
- SRM 513 DIV1 C
- SRM 500 DIV1 B
- 1-SRM 144 DIV1
- TC SRM 559 DIV1
- SRM 195 Div1 总结
- SRM 497 DIV1 550
- SRM 450 div1(practice)
- SRM 449 div1 (practice)
- SRM 448 div1(practice)
- |poj 3678|2-SAT|Katu Puzzle
- 面对强大的Visual Studio C++,你能整明白各自的关系吗
- OkHttpUtils使用
- 排序算法----桶排序
- 使用dir数组检查相邻方格
- [构造] SRM 689 div1 MultiplicationTable3
- Python——条件过滤
- A. Display Size
- ==和===区别
- 将java源码打成jar包
- 京东 淘宝 的图片放大镜功能
- 软件版本更新
- poj2559 Largest Rectangle in a Histogram
- LintCode-二叉树的中序遍历