SRM 601(1-250pt,500pt)
DIV1 250pt
题意:有很多袋子,里面装有苹果和橘子(也可能没有),给出每个袋子里有多少个苹果,多少个橘子。如果每个袋子里含有水果的总数都不小于x个,则可以从每个袋子里都拿出x个水果(拿出苹果和橘子的总数为x),将所有拿出的水果混合成一份礼物,问可能混合出的礼物的种数。
最多50个袋子,每个袋子里的苹果和橘子的数量 <= 10^6。
解法:枚举即可,枚举从每个袋子里拿出的水果的数量x,然后求出,拿出总数是x的情况下,苹果最多能拿多少个,最少能拿多少个,相减即可。
至于怎么求最多和最少,由于最多50个袋子,所以暴力即可。比赛的时候我很傻逼地用了更快的递推来求,然后赋值初始化写错了,喜大普奔。。。。。。。。。。
tag:brute-force
- // BEGIN CUT HERE
- /*
- */
- // END CUT HERE
- #line 7 "WinterAndPresents.cpp"
- #include <cstdlib>
- #include <cctype>
- #include <cstring>
- #include <cstdio>
- #include <cmath>
- #include <algorithm>
- #include <vector>
- #include <iostream>
- #include <sstream>
- #include <set>
- #include <queue>
- #include <fstream>
- #include <numeric>
- #include <iomanip>
- #include <bitset>
- #include <list>
- #include <stdexcept>
- #include <functional>
- #include <string>
- #include <utility>
- #include <map>
- #include <ctime>
- #include <stack>
- using namespace std;
- #define clr0(x) memset(x, 0, sizeof(x))
- #define clr1(x) memset(x, -1, sizeof(x))
- #define pb push_back
- #define mp make_pair
- #define sz(v) ((int)(v).size())
- #define out(x) cout<<#x<<":"<<(x)<<endl
- #define tst(a) cout<<#a<<endl
- #define CINBEQUICKER std::ios::sync_with_stdio(false)
- typedef vector<int> VI;
- typedef vector<string> VS;
- typedef vector<double> VD;
- typedef long long int64;
- const double eps = 1e-;
- const double PI = atan(1.0)*;
- const int inf = / ;
- inline int MyMod( int a , int b ) { return (a%b+b)%b;}
- int num[];
- int num2[];
- int64 max(int x, int64 y)
- {
- return x > y ? x : y;
- }
- class WinterAndPresents
- {
- public:
- long long getNumber(vector <int> an, vector <int> on){
- clr0 (num); clr0 (num2);
- int n = sz(an);
- for (int i = ; i < n; ++ i){
- ++ num[an[i]];
- ++ num2[on[i]];
- }
- int pos = ;
- for (int i = ; i < n; ++ i)
- if (an[pos] + on[pos] > an[i] + on[i]) pos = i;
- int64 up = an[pos] + on[pos], cnt = ;
- int64 ret = , sum = n - num[], maxx = ;
- int64 ts = n - num2[], minn = ;
- while (cnt <= up){
- maxx += sum;
- minn += ts;
- ret += maxx - max(, cnt*n-minn) + ;
- sum -= num[cnt];
- ts -= num2[cnt];
- //out (cnt); out (ret); out (sum); out (ts);
- ++ cnt;
- }
- return ret;
- }
- // BEGIN CUT HERE
- public:
- 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(); }
- //void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0();}
- 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 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; } }
- 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)); }
- 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)); }
- 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)); }
- 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)); }
- 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)); }
- // END CUT HERE
- };
- //by plum rain
- // BEGIN CUT HERE
- int main()
- {
- //freopen( "a.out" , "w" , stdout );
- WinterAndPresents ___test;
- ___test.run_test(-);
- return ;
- }
- // 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
- // BEGIN CUT HERE
- /*
- * Author: plum rain
- * score :
- */
- /*
- */
- // END CUT HERE
- #line 11 "WinterAndSnowmen.cpp"
- #include <sstream>
- #include <stdexcept>
- #include <functional>
- #include <iomanip>
- #include <numeric>
- #include <fstream>
- #include <cctype>
- #include <iostream>
- #include <cstdio>
- #include <vector>
- #include <cstring>
- #include <cmath>
- #include <algorithm>
- #include <cstdlib>
- #include <set>
- #include <queue>
- #include <bitset>
- #include <list>
- #include <string>
- #include <utility>
- #include <map>
- #include <ctime>
- #include <stack>
- using namespace std;
- #define clr0(x) memset(x, 0, sizeof(x))
- #define clr1(x) memset(x, -1, sizeof(x))
- #define pb push_back
- #define sz(v) ((int)(v).size())
- #define all(t) t.begin(),t.end()
- #define zero(x) (((x)>0?(x):-(x))<eps)
- #define out(x) cout<<#x<<":"<<(x)<<endl
- #define tst(a) cout<<a<<" "
- #define tst1(a) cout<<#a<<endl
- #define CINBEQUICKER std::ios::sync_with_stdio(false)
- typedef vector<int> VI;
- typedef vector<string> VS;
- typedef vector<double> VD;
- typedef pair<int, int> pii;
- typedef long long int64;
- const double eps = 1e-;
- const double PI = atan(1.0)*;
- const int inf = / ;
- const int mod = ;
- int n, m;
- int d[][][];
- int gao(int r)
- {
- clr0 (d);
- d[][][] = ;
- int cur = , tmp = << ;
- for (int i = ; i <= min(n, m); ++ i){
- cur ^= ;
- int flag = ((i & (<<r)) > );
- for (int j = ; j < tmp; ++ j)
- for (int k = ; k < ; ++ k){
- d[cur][j][k] = (d[cur^][j][k] + d[cur^][j^i][k]) % mod;
- d[cur][j][k] = (d[cur][j][k] + d[cur^][j^i][k^flag]) % mod;
- }
- }
- if (n > m)
- for (int i = m+; i <= n; ++ i){
- cur ^= ;
- int flag = ((i & (<<r)) > );
- for (int j = ; j < tmp; ++ j)
- for (int k = ; k < ; ++ k)
- d[cur][j][k] = (d[cur^][j][k] + d[cur^][j^i][k^flag]) % mod;
- }
- if (n < m)
- for (int i = n+; i <= m; ++ i){
- cur ^= ;
- for (int j = ; j < tmp; ++ j)
- for (int k = ; k < ; ++ k)
- d[cur][j][k] = (d[cur^][j][k] + d[cur^][j^i][k]) % mod;
- }
- int ret = ;
- for (int j = ; j < tmp; ++ j)
- if ((j >> r) == ) ret = (ret + d[cur][j][]) % mod;
- return ret;
- }
- class WinterAndSnowmen
- {
- public:
- int getNumber(int N, int M){
- n = N; m = M;
- int ans = ;
- for (int i = ; i < ; ++ i)
- ans = (ans + gao(i)) % mod;
- return ans;
- }
- // BEGIN CUT HERE
- public:
- 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(); }
- 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 Arg0 = ; int Arg1 = ; int Arg2 = ; verify_case(, Arg2, getNumber(Arg0, Arg1)); }
- void test_case_1() { int Arg0 = ; int Arg1 = ; int Arg2 = ; verify_case(, Arg2, getNumber(Arg0, Arg1)); }
- void test_case_2() { int Arg0 = ; int Arg1 = ; int Arg2 = ; verify_case(, Arg2, getNumber(Arg0, Arg1)); }
- void test_case_3() { int Arg0 = ; int Arg1 = ; int Arg2 = ; verify_case(, Arg2, getNumber(Arg0, Arg1)); }
- void test_case_4() { int Arg0 = ; int Arg1 = ; int Arg2 = ; verify_case(, Arg2, getNumber(Arg0, Arg1)); }
- // END CUT HERE
- };
- // BEGIN CUT HERE
- int main()
- {
- // freopen( "a.out" , "w" , stdout );
- WinterAndSnowmen ___test;
- ___test.run_test(-);
- return ;
- }
- // END CUT HERE
SRM 601(1-250pt,500pt)的更多相关文章
- SRM 601 DIV1
A 枚举x , 然后对于确定的x , 最后总的apple数对应了唯一的orange数,因此问题转化为求apple的取值范围; apple的取值范围: max为每个bag取最多的apple , min为 ...
- Topcoder SRM 601 div1题解
日常TC计划- Easy(250pts): 题目大意:有n个篮子,每个篮子有若干个苹果和橘子,先任取一个正整数x,然后从每个篮子中选出x个水果,把nx个水果放在一起,输出一共有多少种不同的组成方案.其 ...
- SRM475 - SRM479(1-250pt,500pt)
SRM 475 DIV1 300pt 题意:玩游戏.给一个棋盘,它有1×n(1行n列,每列标号分别为0,1,2..n-1)的格子,每个格子里面可以放一个棋子,并且给定一个只含三个字母WBR,长度为n的 ...
- SRM468 - SRM469(1-250pt, 500pt)
SRM 468 DIV1 250pt 题意:给出字典,按照一定要求进行查找. 解法:模拟题,暴力即可. tag:water score: 0.... 这是第一次AC的代码: /* * Author: ...
- SRM470 - SRM474(1-250pt,500pt)(471-500pt为最短路,474-500pt未做)
SRM 470 DIV1 250pt 题意:有n个房间排成一排,相邻两个房间之间有一扇关闭着的门(共n-1扇),每个门上都标有‘A’-‘P’的大写字母.给定一个数n,表示第n个房间.有两个人John和 ...
- 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)数列所有 ...
- SRM593(1-250pt,500pt)
SRM 593 DIV1 250pt 题意:有如下图所示的平面,每个六边形有坐标.将其中一些六边形染色,要求有边相邻的两个六边形不能染同一种颜色.给定哪些六边形需要染色,问最少需要多少种颜色. 解法: ...
- 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 ...
- SRM 358(1-250,500pt)
DIV1 250pt 题意:电视目前停留在第100台,有一个遥控器,可以向上或向下换台(需要按键一次),也可以按一些数字,然后直接跳到该台(需要按键次数等于数字数,不需要按确定键).但是,这个遥控一些 ...
随机推荐
- Maven3(笔记二)
笔记本二 在Eclipse 中使用Maven 第一节:m2eclipse 插件安装 打开Eclipse,点击菜单Help - > Install New Software 点击Add 按钮N ...
- iOS 身份证最后一位是X,输入17位后自动补全X(转)
非原创,转载自http://blog.csdn.net/l2i2j2/article/details/51542028如果身份证最后一位是X,输入17位后自动补全X// textField代理方法 - ...
- 禁用UITextField复制粘贴等方法
要实现此功能只需创建一个继承自UITextField的子类,重写以下方法即可. - (BOOL)canPerformAction:(SEL)action withSender:(id)sender{ ...
- php多线程即时通讯
即时通讯:推送消息http://www.workerman.net/
- 字符串copy
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> #include<string. ...
- SpringMVC源码阅读(一)
DispatcherServlet是整个SpringMVC初始化和处理请求的重要类,作为一个servlet,拥有 public void init(ServletConfig config) thro ...
- 简单易懂, JUnit 框架问答
本文算是一个关于Junit4相关的知识分享,但是不同于网上大段的源码分析,模式学习文章,我想通过问答的形式,引出代码来简明阐述JUnit4是如何实现需要的功能的. 考虑到任何一个框架,都是为了解决问题 ...
- C#错误与异常处理
C# 提供了几个关键字(try.catch 和 finally),程序可以用这些关键字检测异常.处理异常并继续运行.这些关键字是让应用程序更可靠的非常有用的工具. class tryAndCatch ...
- [BZOJ 1004] [HNOI2008] Cards 【Burnside引理 + DP】
题目链接:BZOJ - 1004 题目分析 首先,几个定义和定理引理: 群:G是一个集合,*是定义在这个集合上的一个运算. 如果满足以下性质,那么(G, *)是一个群. 1)封闭性,对于任意 a, b ...
- 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 ...