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)的更多相关文章

  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. 域名解析-delphi 源码

    unit Unit1; interface uses  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, Syste ...

  2. [Twisted] transport和protocol解耦

    Twisted中transport和protocol完全解耦. 这样设计的优点: 1.不同的Protocol协议实现可以重用相同类型的transport. 2.方便测试:假如测试一个协议实现,可以使用 ...

  3. Jmeter软件测试3--发送二进制报文

    一直用Jmeter测试post接口,但报文信息都是明文方式,今天测试兄弟求助二进制报文如何使用Jmeter测试,查看了项目源码,报文中不仅采用二进制,而且还用java.util.zip进行了压缩,从晚 ...

  4. 校省选赛第一场C题解Practice

    比赛时间只有两个小时,我没有选做这题,因为当时看样例也看不懂,比较烦恼. 后来发现,该题对输入输出要求很低.远远没有昨天我在做的A题的麻烦,赛后认真看了一下就明白了,写了一下,一次就AC了,没问题,真 ...

  5. 获取数据后导出Excel

    List<PortResourceInfo> list = getList()//获取数据源 //导出excle Response.Clear(); Response.ContentTyp ...

  6. jQuery 鼠标滑过及选中一行效果

    /******* 表格效果 ********/ $("#gird_tbl tbody tr").live('mouseover', function () { $(this).ad ...

  7. sass用法

    可能刚开始我们学习前端的时候都习惯用html+css.来做网页,但是我们发现css有很多重复的代码或者是你要改里面的图片或者文字还有去诶个的找很麻烦,所以我们就用sass来简化它. 首先我们需要安装一 ...

  8. 一. 什么是ANR?为什么会有ANR发生?

    对于Android平台的工程师来说,ANR应该是每个人都会遇到的问题,因为导致它的原因有很多,例如在主线程进行耗时操作,调用大量cpu资源进行复杂的预算等,并且可能在大多数情况下,这类问题不会发生,只 ...

  9. mysql进阶1

    在我们用php处理数据的时候总会遇到些比较麻烦的事情,比如:两个二维数组,一个装的是文章分类表内容,一个装的是文章列表,有关联字段,完全等值,要求在列表文章的时候同时能在标题的前面显示栏目名称,此时循 ...

  10. Memcache,Redis

    Memcache Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度. ...