DIV1 250pt

题意:有很多袋子,里面装有苹果和橘子(也可能没有),给出每个袋子里有多少个苹果,多少个橘子。如果每个袋子里含有水果的总数都不小于x个,则可以从每个袋子里都拿出x个水果(拿出苹果和橘子的总数为x),将所有拿出的水果混合成一份礼物,问可能混合出的礼物的种数。

   最多50个袋子,每个袋子里的苹果和橘子的数量 <= 10^6。

解法:枚举即可,枚举从每个袋子里拿出的水果的数量x,然后求出,拿出总数是x的情况下,苹果最多能拿多少个,最少能拿多少个,相减即可。

   至于怎么求最多和最少,由于最多50个袋子,所以暴力即可。比赛的时候我很傻逼地用了更快的递推来求,然后赋值初始化写错了,喜大普奔。。。。。。。。。。

tag:brute-force

  1. // BEGIN CUT HERE
  2. /*
  3.  
  4. */
  5. // END CUT HERE
  6. #line 7 "WinterAndPresents.cpp"
  7. #include <cstdlib>
  8. #include <cctype>
  9. #include <cstring>
  10. #include <cstdio>
  11. #include <cmath>
  12. #include <algorithm>
  13. #include <vector>
  14. #include <iostream>
  15. #include <sstream>
  16. #include <set>
  17. #include <queue>
  18. #include <fstream>
  19. #include <numeric>
  20. #include <iomanip>
  21. #include <bitset>
  22. #include <list>
  23. #include <stdexcept>
  24. #include <functional>
  25. #include <string>
  26. #include <utility>
  27. #include <map>
  28. #include <ctime>
  29. #include <stack>
  30.  
  31. using namespace std;
  32.  
  33. #define clr0(x) memset(x, 0, sizeof(x))
  34. #define clr1(x) memset(x, -1, sizeof(x))
  35. #define pb push_back
  36. #define mp make_pair
  37. #define sz(v) ((int)(v).size())
  38. #define out(x) cout<<#x<<":"<<(x)<<endl
  39. #define tst(a) cout<<#a<<endl
  40. #define CINBEQUICKER std::ios::sync_with_stdio(false)
  41.  
  42. typedef vector<int> VI;
  43. typedef vector<string> VS;
  44. typedef vector<double> VD;
  45. typedef long long int64;
  46.  
  47. const double eps = 1e-;
  48. const double PI = atan(1.0)*;
  49. const int inf = / ;
  50.  
  51. inline int MyMod( int a , int b ) { return (a%b+b)%b;}
  52.  
  53. int num[];
  54. int num2[];
  55.  
  56. int64 max(int x, int64 y)
  57. {
  58. return x > y ? x : y;
  59. }
  60.  
  61. class WinterAndPresents
  62. {
  63. public:
  64. long long getNumber(vector <int> an, vector <int> on){
  65. clr0 (num); clr0 (num2);
  66. int n = sz(an);
  67. for (int i = ; i < n; ++ i){
  68. ++ num[an[i]];
  69. ++ num2[on[i]];
  70. }
  71. int pos = ;
  72. for (int i = ; i < n; ++ i)
  73. if (an[pos] + on[pos] > an[i] + on[i]) pos = i;
  74. int64 up = an[pos] + on[pos], cnt = ;
  75. int64 ret = , sum = n - num[], maxx = ;
  76. int64 ts = n - num2[], minn = ;
  77. while (cnt <= up){
  78. maxx += sum;
  79. minn += ts;
  80. ret += maxx - max(, cnt*n-minn) + ;
  81. sum -= num[cnt];
  82. ts -= num2[cnt];
  83. //out (cnt); out (ret); out (sum); out (ts);
  84. ++ cnt;
  85. }
  86. return ret;
  87. }
  88.  
  89. // BEGIN CUT HERE
  90. public:
  91. 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(); }
  92. //void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0();}
  93. private:
  94. 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(); }
  95. void verify_case(int Case, const long long &Expected, const long long &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } }
  96. 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[]))); long long Arg2 = 3LL; verify_case(, Arg2, getNumber(Arg0, Arg1)); }
  97. 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[]))); long long Arg2 = 0LL; verify_case(, Arg2, getNumber(Arg0, Arg1)); }
  98. 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[]))); long long Arg2 = 16LL; verify_case(, Arg2, getNumber(Arg0, Arg1)); }
  99. 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[]))); long long Arg2 = 46LL; verify_case(, Arg2, getNumber(Arg0, Arg1)); }
  100. 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[]))); long long Arg2 = 1000002000000LL; verify_case(, Arg2, getNumber(Arg0, Arg1)); }
  101.  
  102. // END CUT HERE
  103.  
  104. };
  105. //by plum rain
  106. // BEGIN CUT HERE
  107. int main()
  108. {
  109. //freopen( "a.out" , "w" , stdout );
  110. WinterAndPresents ___test;
  111. ___test.run_test(-);
  112. return ;
  113. }
  114. // END CUT HERE

DIV1 500pt

题意:给出整数n和m,{1,2,3....n}的一个子集a,{1,2,3...m}的一个子集b,要求a和b满足两个条件:1、a和b的元素无交集;2、a中所有元素异或得到的值小于b中所有元素异或得到的值。求这样的集合对(a, b)有多少对。

解法:首先,设a异或的值为x,b异或的值为y,由于x小于y,所以在二进制形式中,一定存在某一位r,在r位之前x和y相同,第r位x为0,y为1。枚举r。

   设d[i][j][k]表示前i个数,放进a或b中的所有元素的异或值为j,x第r位为k(0或1)的状态下,一共有多少个这样的集合对。然后只要取d[max(n,m)][t][0]即可,其中t满足的条件是(t >> r) == 1。注意到,本题的两个关键点,一个是用异或值为1表示,前r位x和y相同,第r位不同;另一个是,只要把一个数放进集合a或b都把它和j与一下,然后,因为在比r位高的位a和b两个集合的异或值相同,所以j的这些位异或值为0。

   虽然这是一个dp,但是关键的那点还是很难想到的。。。。

tag:dp, think, good

  1. // BEGIN CUT HERE
  2. /*
  3. * Author: plum rain
  4. * score :
  5. */
  6. /*
  7.  
  8. */
  9. // END CUT HERE
  10. #line 11 "WinterAndSnowmen.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-;
  55. const double PI = atan(1.0)*;
  56. const int inf = / ;
  57. const int mod = ;
  58.  
  59. int n, m;
  60. int d[][][];
  61.  
  62. int gao(int r)
  63. {
  64. clr0 (d);
  65. d[][][] = ;
  66. int cur = , tmp = << ;
  67. for (int i = ; i <= min(n, m); ++ i){
  68. cur ^= ;
  69. int flag = ((i & (<<r)) > );
  70. for (int j = ; j < tmp; ++ j)
  71. for (int k = ; k < ; ++ k){
  72. d[cur][j][k] = (d[cur^][j][k] + d[cur^][j^i][k]) % mod;
  73. d[cur][j][k] = (d[cur][j][k] + d[cur^][j^i][k^flag]) % mod;
  74. }
  75. }
  76. if (n > m)
  77. for (int i = m+; i <= n; ++ i){
  78. cur ^= ;
  79. int flag = ((i & (<<r)) > );
  80. for (int j = ; j < tmp; ++ j)
  81. for (int k = ; k < ; ++ k)
  82. d[cur][j][k] = (d[cur^][j][k] + d[cur^][j^i][k^flag]) % mod;
  83. }
  84. if (n < m)
  85. for (int i = n+; i <= m; ++ i){
  86. cur ^= ;
  87. for (int j = ; j < tmp; ++ j)
  88. for (int k = ; k < ; ++ k)
  89. d[cur][j][k] = (d[cur^][j][k] + d[cur^][j^i][k]) % mod;
  90. }
  91. int ret = ;
  92. for (int j = ; j < tmp; ++ j)
  93. if ((j >> r) == ) ret = (ret + d[cur][j][]) % mod;
  94. return ret;
  95. }
  96.  
  97. class WinterAndSnowmen
  98. {
  99. public:
  100. int getNumber(int N, int M){
  101. n = N; m = M;
  102. int ans = ;
  103. for (int i = ; i < ; ++ i)
  104. ans = (ans + gao(i)) % mod;
  105. return ans;
  106. }
  107.  
  108. // BEGIN CUT HERE
  109. public:
  110. 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(); }
  111. private:
  112. 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(); }
  113. 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; } }
  114. void test_case_0() { int Arg0 = ; int Arg1 = ; int Arg2 = ; verify_case(, Arg2, getNumber(Arg0, Arg1)); }
  115. void test_case_1() { int Arg0 = ; int Arg1 = ; int Arg2 = ; verify_case(, Arg2, getNumber(Arg0, Arg1)); }
  116. void test_case_2() { int Arg0 = ; int Arg1 = ; int Arg2 = ; verify_case(, Arg2, getNumber(Arg0, Arg1)); }
  117. void test_case_3() { int Arg0 = ; int Arg1 = ; int Arg2 = ; verify_case(, Arg2, getNumber(Arg0, Arg1)); }
  118. void test_case_4() { int Arg0 = ; int Arg1 = ; int Arg2 = ; verify_case(, Arg2, getNumber(Arg0, Arg1)); }
  119.  
  120. // END CUT HERE
  121.  
  122. };
  123.  
  124. // BEGIN CUT HERE
  125. int main()
  126. {
  127. // freopen( "a.out" , "w" , stdout );
  128. WinterAndSnowmen ___test;
  129. ___test.run_test(-);
  130. return ;
  131. }
  132. // END CUT HERE

SRM 601(1-250pt,500pt)的更多相关文章

  1. SRM 601 DIV1

    A 枚举x , 然后对于确定的x , 最后总的apple数对应了唯一的orange数,因此问题转化为求apple的取值范围; apple的取值范围: max为每个bag取最多的apple , min为 ...

  2. Topcoder SRM 601 div1题解

    日常TC计划- Easy(250pts): 题目大意:有n个篮子,每个篮子有若干个苹果和橘子,先任取一个正整数x,然后从每个篮子中选出x个水果,把nx个水果放在一起,输出一共有多少种不同的组成方案.其 ...

  3. SRM475 - SRM479(1-250pt,500pt)

    SRM 475 DIV1 300pt 题意:玩游戏.给一个棋盘,它有1×n(1行n列,每列标号分别为0,1,2..n-1)的格子,每个格子里面可以放一个棋子,并且给定一个只含三个字母WBR,长度为n的 ...

  4. SRM468 - SRM469(1-250pt, 500pt)

    SRM 468 DIV1 250pt 题意:给出字典,按照一定要求进行查找. 解法:模拟题,暴力即可. tag:water score: 0.... 这是第一次AC的代码: /* * Author: ...

  5. SRM470 - SRM474(1-250pt,500pt)(471-500pt为最短路,474-500pt未做)

    SRM 470 DIV1 250pt 题意:有n个房间排成一排,相邻两个房间之间有一扇关闭着的门(共n-1扇),每个门上都标有‘A’-‘P’的大写字母.给定一个数n,表示第n个房间.有两个人John和 ...

  6. SRM144 - SRM 148(少144-DIV1-LV3,147-DIV2-LV3)

    SRM 144 DIV 1 500pt tag:组合 题意:彩票中奖.给定n, m,从1-n中选择m个数组成数列a1, a2, a3...am.对于数列{am}分别满足以下条件的概率: (1)数列所有 ...

  7. SRM593(1-250pt,500pt)

    SRM 593 DIV1 250pt 题意:有如下图所示的平面,每个六边形有坐标.将其中一些六边形染色,要求有边相邻的两个六边形不能染同一种颜色.给定哪些六边形需要染色,问最少需要多少种颜色. 解法: ...

  8. 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 ...

  9. SRM 358(1-250,500pt)

    DIV1 250pt 题意:电视目前停留在第100台,有一个遥控器,可以向上或向下换台(需要按键一次),也可以按一些数字,然后直接跳到该台(需要按键次数等于数字数,不需要按确定键).但是,这个遥控一些 ...

随机推荐

  1. Maven3(笔记二)

    笔记本二   在Eclipse 中使用Maven 第一节:m2eclipse 插件安装 打开Eclipse,点击菜单Help - > Install New Software 点击Add 按钮N ...

  2. iOS 身份证最后一位是X,输入17位后自动补全X(转)

    非原创,转载自http://blog.csdn.net/l2i2j2/article/details/51542028如果身份证最后一位是X,输入17位后自动补全X// textField代理方法 - ...

  3. 禁用UITextField复制粘贴等方法

    要实现此功能只需创建一个继承自UITextField的子类,重写以下方法即可. - (BOOL)canPerformAction:(SEL)action withSender:(id)sender{ ...

  4. php多线程即时通讯

    即时通讯:推送消息http://www.workerman.net/

  5. 字符串copy

    #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> #include<string. ...

  6. SpringMVC源码阅读(一)

    DispatcherServlet是整个SpringMVC初始化和处理请求的重要类,作为一个servlet,拥有 public void init(ServletConfig config) thro ...

  7. 简单易懂, JUnit 框架问答

    本文算是一个关于Junit4相关的知识分享,但是不同于网上大段的源码分析,模式学习文章,我想通过问答的形式,引出代码来简明阐述JUnit4是如何实现需要的功能的. 考虑到任何一个框架,都是为了解决问题 ...

  8. C#错误与异常处理

    C# 提供了几个关键字(try.catch 和 finally),程序可以用这些关键字检测异常.处理异常并继续运行.这些关键字是让应用程序更可靠的非常有用的工具. class tryAndCatch ...

  9. [BZOJ 1004] [HNOI2008] Cards 【Burnside引理 + DP】

    题目链接:BZOJ - 1004 题目分析 首先,几个定义和定理引理: 群:G是一个集合,*是定义在这个集合上的一个运算. 如果满足以下性质,那么(G, *)是一个群. 1)封闭性,对于任意 a, b ...

  10. 7 Tools for Data Visualization in R, Python, and Julia

    7 Tools for Data Visualization in R, Python, and Julia Last week, some examples of creating visualiz ...