[贪心 构造] SRM 717 div1 ScoresSequence
来源:互联网 发布:淘宝怎么下架商品 编辑:程序博客网 时间:2024/05/18 02:44
首先他保证图唯一确定,那么可以把图给构出来
类似这个题,按照出度从大到小排序,出度最大那个点怎么分配,类似无向图可图判定,应该是向出度小的点连,使得出度大的向他连,让出度大的出度减小
// 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 cl(x) memset(x,0,sizeof(x))using namespace std;typedef long long ll;typedef pair<int,int> abcd;const int N=105;int n;abcd a[N];int f[N][N];class ScoresSequence{public: int count(vector <int> s){ n=s.size(); for (int i=1;i<=n;i++) a[i]=abcd(s[i-1],i); cl(f); for (int i=1;i<=n;i++) f[i][i]=1; int t=n; while (t){ sort(a+1,a+t+1); if (a[t].first==0) break; for (int i=1;i<=a[t].first;i++) f[a[t].second][a[i].second]=1; for (int i=a[t].first+1;i<t;i++) f[a[i].second][a[t].second]=1,a[i].first--; t--; } for (int k=1;k<=n;k++) for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) f[i][j]|=f[i][k]&f[k][j]; int ans=0; for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) ans+=f[i][j]; 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 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; } } void test_case_0() { int Arr0[] = {2, 0, 1}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 6; verify_case(0, Arg1, count(Arg0)); } void test_case_1() { int Arr0[] = {1, 0, 2}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 6; verify_case(1, Arg1, count(Arg0)); } void test_case_2() { int Arr0[] = {1, 1, 1}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 9; verify_case(2, Arg1, count(Arg0)); } void test_case_3() { int Arr0[] = {0, 2, 8, 4, 3, 9, 1, 5, 7, 6}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 55; verify_case(3, Arg1, count(Arg0)); } void test_case_4() { int Arr0[] = {22,20,14,13,17,15,12,18,23,15,21,26,33,5,19,9,37,0,25,28,4,12,35,32,25,7,31,6,2,29,10,33,36,27,39,28,40,3,8,38,3}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 1422; verify_case(4, Arg1, count(Arg0)); } // END CUT HERE};// BEGIN CUT HEREint main(){ ScoresSequence ___test; ___test.run_test(-1); getch() ; return 0;}// END CUT HERE
阅读全文
0 0
- [贪心 构造] SRM 717 div1 ScoresSequence
- [构造] SRM 689 div1 MultiplicationTable3
- [构造 二分图] SRM 693 div1 BipartiteConstruction
- 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)
- DAY33继承实现原理、子类调用父类的方法、封装
- LeetCode#6 ZigZag Conversion
- python3.5 安装python3-tk
- BottomNavigationBar底部导航栏
- Windows13
- [贪心 构造] SRM 717 div1 ScoresSequence
- Windows14
- 工厂方法模式
- Windows下的Django安装与环境配置
- UVA 230
- jni方法的注册和调用
- MVP的实践
- 3174: [Tjoi2013]拯救小矮人
- [awk]练习2