250pt:

题目:有一些盒子(不大于50个),每个盒子里有一些大理石(最多50种颜色),然后给定每个盒子里每种颜色大理石的个数(没有为0),求最少操作几步满足:

1:最多只能一个盒子里有多种颜色,叫做jaker

2:每种颜色最多位于一个一个非jaker的盒子里,且每个非jaker的盒子最多只含有一种颜色:

移动一步可以移动一个盒子任意个石头到另外一个。。

思路:如果我们枚举哪个是jaker,那么对于剩下来的盒子,就剩下要不要移动到jaker里的抉择了。。而且:

1: 如果该盒子有多种颜色,那么一定要移动,全部移动到jaker里就行

2: 如果该盒子有只有一种颜色,那么该颜色用过(就是在前面也有一个只有该颜色的)则必须移动,否者不移动

3:空盒子不移动

code:

  1. // BEGIN CUT HERE
  2. /*
  3.  
  4. */
  5. // END CUT HERE
  6. #line 7 "MarblesRegroupingEasy.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. #define M0(a) memset(a, 0, sizeof(a))
  31. using namespace std;
  32.  
  33. #define PB push_back
  34. #define MP make_pair
  35.  
  36. #define REP(i,n) for(i=0;i<(n);++i)
  37. #define FOR(i,l,h) for(i=(l);i<=(h);++i)
  38. #define FORD(i,h,l) for(i=(h);i>=(l);--i)
  39.  
  40. typedef vector<int> VI;
  41. typedef vector<string> VS;
  42. typedef vector<double> VD;
  43. typedef long long LL;
  44. typedef pair<int,int> PII;
  45.  
  46. int vis[], n, m;
  47. vector<string> a;
  48. int work(int nt){
  49. M0(vis);
  50. int ret = ;
  51. for (int i = ; i < n; ++i)
  52. if (i != nt){
  53. int cnt = , p = -;
  54. for (int j = ; j < m; ++j)
  55. if (a[i][j] != '') ++cnt, p = j;
  56. if (cnt == ) continue;
  57. else if (cnt > ) ret ++;
  58. else {
  59. if (!vis[p]) vis[p] = ;
  60. else ++ret;
  61. }
  62. }
  63. return ret;
  64. }
  65.  
  66. class MarblesRegroupingEasy
  67. {
  68. public:
  69. int minMoves(vector <string> b)
  70. {
  71. n = b.size();
  72. m = b[].size();
  73. a = b;
  74. int ret = ;
  75. for (int i = ; i < n; ++i)
  76. ret = min(ret, work(i));
  77. return ret;
  78. }
  79.  
  80. // BEGIN CUT HERE
  81. public:
  82. void run_test(int Case) { if ((Case == -) || (Case == )) test_case_0(); if ((Case == -) || (Case == )) test_case_1(); if ((Case == -) || (Case == )) test_case_2(); if ((Case == -) || (Case == )) test_case_3(); if ((Case == -) || (Case == )) test_case_4(); }
  83. private:
  84. 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(); }
  85. 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; } }
  86. void test_case_0() { string Arr0[] = {"",
  87. ""}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, minMoves(Arg0)); }
  88. void test_case_1() { string Arr0[] = {"",
  89. "",
  90. ""}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, minMoves(Arg0)); }
  91. void test_case_2() { string Arr0[] = {"",
  92. "",
  93. "",
  94. ""}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, minMoves(Arg0)); }
  95. void test_case_3() { string Arr0[] = {"",
  96. "",
  97. "",
  98. "",
  99. "",
  100. ""}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, minMoves(Arg0)); }
  101. void test_case_4() { string Arr0[] = {"",
  102. "",
  103. "",
  104. "",
  105. "",
  106. "",
  107. "",
  108. "",
  109. "",
  110. "",
  111. ""}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, minMoves(Arg0)); }
  112.  
  113. // END CUT HERE
  114.  
  115. };
  116.  
  117. // BEGIN CUT HERE
  118. int main()
  119. {
  120. MarblesRegroupingEasy ___test;
  121. ___test.run_test(-);
  122. // system("pause");
  123. return ;
  124. }
  125. // END CUT HERE

500pt:

题目:给定一些一维坐标里的线段,问把他们可以分成多少个子集,每个,子集符合下面情况:

1:任意一个不再子集里的线段与子集相交

2.子集元素都不相交

思路:

因为坐标最大才100,所以以坐标进行统计(类似dp思想)

   直接看代码吗,

不然不好说清楚,代码还是很短的。。

  1. // BEGIN CUT HERE
  2. /*
  3.  
  4. */
  5. // END CUT HERE
  6. #line 7 "IntervalSubsets.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. #define M0(a) memset(a, 0, sizeof(a))
  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. int f[];
  45.  
  46. class IntervalSubsets
  47. {
  48. public:
  49. int numberOfSubsets(vector <int> start, vector <int> finish)
  50. {
  51. int n = start.size();
  52. M0(f);
  53. f[] = ;
  54. for (int i = ; i <= ; ++i){
  55. int L = -;
  56. for (int j = ; j < n; ++j)
  57. if (finish[j] <= i) L = max(start[j], L);
  58. if (L == -)
  59. f[i] = f[i - ];
  60. else
  61. for (int j = ; j < n; ++j)
  62. if (finish[j] >= L && finish[j] <= i) f[i] += f[start[j] - ];
  63. }
  64. return f[];
  65. }
  66.  
  67. // BEGIN CUT HERE
  68. public:
  69. void run_test(int Case) { if ((Case == -) || (Case == )) test_case_0(); if ((Case == -) || (Case == )) test_case_1(); if ((Case == -) || (Case == )) test_case_2(); if ((Case == -) || (Case == )) test_case_3(); if ((Case == -) || (Case == )) test_case_4(); }
  70. private:
  71. 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(); }
  72. 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; } }
  73. void test_case_0() { int Arr0[] = {,}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arr1[] = {,}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[]))); int Arg2 = ; verify_case(, Arg2, numberOfSubsets(Arg0, Arg1)); }
  74. void test_case_1() { int Arr0[] = {,,}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arr1[] = {,,}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[]))); int Arg2 = ; verify_case(, Arg2, numberOfSubsets(Arg0, Arg1)); }
  75. void test_case_2() { int Arr0[] = {,,,,}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arr1[] = {,,,,}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[]))); int Arg2 = ; verify_case(, Arg2, numberOfSubsets(Arg0, Arg1)); }
  76. void test_case_3() { int Arr0[] = {,,,,,,,,}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arr1[] = {,,,,,,,,}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[]))); int Arg2 = ; verify_case(, Arg2, numberOfSubsets(Arg0, Arg1)); }
  77. void test_case_4() { int Arr0[] = {, , , }; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arr1[] = {, , , }; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[]))); int Arg2 = ; verify_case(, Arg2, numberOfSubsets(Arg0, Arg1)); }
  78.  
  79. // END CUT HERE
  80.  
  81. };
  82.  
  83. // BEGIN CUT HERE
  84. int main()
  85. {
  86. IntervalSubsets ___test;
  87. ___test.run_test(-);
  88. // system("pause");
  89. return ;
  90. }
  91. // END CUT HERE

SRM387 div1的更多相关文章

  1. CF#345 (Div1)

    论蒟蒻如何被cf虐 以下是身败名裂后的题解菌=========== Div1 A.Watchmen 有n个点,每个点有一个坐标.求曼哈顿距离=欧几里得距离的点对数量. 只需要统计x或y一样的点对数量. ...

  2. 图论 SRM 674 Div1 VampireTree 250

    Problem Statement      You are a genealogist specializing in family trees of vampires. Vampire famil ...

  3. jq对象转为dom对象:$(".div1")[0] dom对象转为jq对象:$(dom对象)

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...

  4. 第一次div1做出3道题

    第一次div1做出3道题! 再接再厉! 哈利路亚!

  5. 第一次进div1了

    第一次进div1~好激动啊! 上帝依旧那么眷顾我!

  6. TopCoder 649 div1 & div2

    最近一场TC,做得是在是烂,不过最后challenge阶段用一个随机数据cha了一个明显错误的代码,最后免于暴跌rating,还涨了一点.TC题目质量还是很高的,非常锻炼思维,拓展做题的视野,老老实实 ...

  7. SRM DIV1 500pt DP

    SRM 501 DIV1 500pt SRM 502 DIV1 500pt SRM 508 DIV1 500pt SRM 509 DIV1 500pt SRM 511 DIV1 500pt SRM 5 ...

  8. codeforces #305 div1 done

    总算搞定了这一场比赛的题目,感觉收获蛮大 其中A,B,C都能通过自己的思考解决掉 D题思路好神,E题仔细想想也能想出来 以后坚持每两天或者一天做一场CF的div1的全套题目 除非有实在无法做出来的题目 ...

  9. [Codeforces Round #254 div1] C.DZY Loves Colors 【线段树】

    题目链接:CF Round #254 div1 C 题目分析 这道题目是要实现区间赋值的操作,同时还要根据区间中原先的值修改区间上的属性权值. 如果直接使用普通的线段树区间赋值的方法,当一个节点表示的 ...

随机推荐

  1. N! (大数,优化)

    Problem Description 输出N的阶乘.(注意时间限制150ms&&注意不能打表后输出) 打表的定义:在本地主机预先计算出了每个值对应的答案,并把输入和输出的映射直接写入 ...

  2. 图片延时加载原理 和 使用jquery实现的一个图片延迟加载插件(含图片延迟加载原理)

    图片加载技术分为:图片预加载和图片延时加载. javascript图片预加载和延时加载的区别主要体现在图片传输到客户端的时机上,都是为了提升用户体验的,延时加载又叫懒加载.两种技术的本质:两者的行为是 ...

  3. BZOJ 1977[BeiJing2010组队]次小生成树 Tree - 生成树

    描述: 就是求一个次小生成树的边权和 传送门 题解 我们先构造一个最小生成树, 把树上的边记录下来. 然后再枚举每条非树边(u, v, val),在树上找出u 到v 路径上的最小边$g_0$ 和 严格 ...

  4. python基础之Day4

    流程判断 一.if 1.语法一 各条件都执行 if条件1: if条件2: if条件3: 2.语法二 if多分支,自上而下执行,一旦满足条件,后面代码即使满足条件也不会执行 if条件1: elif条件2 ...

  5. libpcap 库使用(一)

    参考资料: http://www.tcpdump.org/ DESCRIPTION The Packet Capture library provides a high level interface ...

  6. MySQL 检索数据及提高检索速度的方法

    检索数据 mysql> SELECT [DISTINCT] 表名.列名,表名.列名,表名.列名 -- 使用通配符*表示所有列 DISTINCT表示返回不同的值 -> FROM 数据库名.表 ...

  7. [Hbase]Hbase技术方案

    HBase架构简介 HBase在完全分布式环境下,由Master进程负责管理RegionServers集群的负载均衡以及资源分配,ZooKeeper负责集群元数据的维护并且监控集群的状态以防止单点故障 ...

  8. 一台老服务器的升级日志(PHP4.4.9+MySQL5.1)升级MySQL5.6

    1.备份数据库 mysqldump -uroot -p --all-databases > databases.sql 2.停止mysql服务 service mysqld stop 3.卸载旧 ...

  9. Windows 平台 (UWP)应用设计

    Make Your Apps Cooperate with Cross-App Communication :  https://rewards.msdn.microsoft.com/Challeng ...

  10. win8 本地化

    先看个简单的案例:新时尚Windows8开发(6):资源 & 本地化 http://www.silverlightchina.net/html/windows8/study/2012/0902 ...