Baidu Astar Contest 2013-04-13 Regional (Guangzhou)

来源:互联网 发布:香港研究生网络面试 编辑:程序博客网 时间:2024/06/10 15:56

2013年4月13日竞赛题目一


du熊的机器人
Description
du熊正在玩一个别人刚送给它的机器人。这个机器人只能在一个棋盘中行走,棋盘的左上角格子为(0, 0),右下角格子为(X, Y)。
du熊控制这个机器人从棋盘的左上角,走到右下角,再从右下角回到左上角。当机器人从左上角走到右下角的过程中,如果它当前所在格子为(x, y),则它只能走到(x+1, y)或(x, y+1)的格子;当机器人从右下角走回左上角的过程中,如果它当前所在的格子为(x, y),则它只能走到(x-1, y)或(x, y-1)的格子。并且du熊要求机器人从左上角走到右下角再走回左上角的整个过程中,最多经过同一个格子一次。
请你帮du熊计算出这个机器人一共有多少种不同的路线。
 
Input
输入的第一行为一个正整数T(0<T<=50),表示数据组数。
接下来的T行,每行有两个整数,分别表示X和Y。(1<=X,Y<=1000)
 
Output
对每组输入数据,输出一个整数,表示机器人不同的路线数量。
 
Sample Input
3
1 1
1 1000
3 4
 
Sample Output
2
2
100



Analysis: High precision DP, no idea about the output range, set MAXLEN = 10000 may be too small for complete answer, but may be too large to successfully compile (when MAXLEN is 100, default compiler handles it properly).

BTW: Baidu's contest platform really sucks!

#include <cstring>#include <iostream>using namespace std;const int MAXLEN = 10000;class BigInteger {public:        int len, s[MAXLEN];        BigInteger() { (*this) = 0; };        BigInteger(int inte) { (*this) = inte; };                friend ostream& operator<<(ostream &cout, const BigInteger &x);        BigInteger operator=(int inte);        BigInteger operator*(const BigInteger &b);        BigInteger operator+(const BigInteger &b);};ostream& operator<<(ostream &cout, const BigInteger &x) {        for (int i = x.len; i >= 1; --i)                cout << x.s[i];        return cout;}BigInteger BigInteger::operator=(int inte ){        if (inte == 0) {                len = 1;                s[1] = 0;                return (*this);        };        for (len = 0; inte > 0; ) {                s[++len] = inte % 10;                inte /= 10;        };        return (*this);}BigInteger BigInteger::operator+(const BigInteger &b){        int i;        BigInteger c;        c.s[1] = 0;        for (i = 1; i <= len || i <= b.len || c.s[i]; i++) {                if (i <= len) c.s[i] += s[i];                if (i <= b.len) c.s[i] += b.s[i];                c.s[i+1] = c.s[i] / 10;                c.s[i] %= 10;        }        c.len = i - 1;        if (c.len == 0) c.len=1;        return c;}BigInteger BigInteger::operator*(const BigInteger &b){        int i ,j;        BigInteger c;        c.len = len + b.len;        for (i = 1; i <= c.len; ++i) c.s[i] = 0;        for (i = 1; i <= len ; ++i)                for (j = 1; j <= b.len ; ++j)                        c.s[i + j - 1] += s[i] * b.s[j] ;        for (i = 1; i < c.len; ++i) {                c.s[i + 1] += c.s[i] / 10;                c.s[i] %= 10;        }        while(c.s[i]) {                c.s[i + 1] = c.s[i] / 10;                c.s[i] %= 10;                ++i;        }        while(i >1 && !c.s[i] ) --i;        c.len=i ;        return c ;}BigInteger dp[2][1001][1001];int main() {        int T;        cin >> T;        while (T--) {                int x, y;                cin >> x >> y;                memset(dp, 0, sizeof(dp));                int n = x + y;                int t = 0;                dp[0][0][0] = 1;                for (int step = 1; step <= n; ++step) {                        int k = step%2;                        int start = (step <= x) ? 0 : (step - x);                        int end = (start + x <= y) ? start + x : y;                        for (int i = start; i <= end; ++i) {                                for (int j = i; j <= end; ++j) {                                        if (step != n && i == j) {                                                dp[k][i][j] = 0;                                                continue;                                        }                                        dp[k][i][j] = dp[t][i][j];                                        if (i > 0)                                                dp[k][i][j] = dp[k][i][j] + dp[t][i - 1][j];                                        if (j > 0)                                                dp[k][i][j] = dp[k][i][j] + dp[t][i][j - 1];                                        if (i > 0 && j > 0)                                                dp[k][i][j] = dp[k][i][j] + dp[t][i - 1][j - 1];                                }                        }                        t = k;                }                cout << dp[t][y][y] * 2 << '\n';        }        return 0;}





2013年4月13日竞赛题目二

乘法测试
问题描述
CYL决定要教导du熊学习乘法。于是CYL需要生成两个整数来让du熊做乘法。于是CYL找到了他在镜面世界中的朋友------LYC来帮忙。CYL有m根现状标有数字的棍子,一个在左边一个在右边。而LYC有n根这样的根子,而镜面世界中的某些棍子和现实世界中的某些棍子存在着某种神秘相连的关系。
 
CYL通过以下方式来生成两个数字:
 
一开始,CYL初始化两个累加器A和B为0,然后重复以下步骤:
 
CYL首先选取一根现实世界中的棍子,暂且称之为棍子X。然后助手LYC会选取一根与X存在神秘相连关系的棍子Y,如果LYC找不到任何一根与X神秘相连的棍子则本次过程跳过然后算法结束。否则棍子X左边的数字会加入到A中,右边的数字加入到B中,而棍子Y左边的数字会加入到B中,右边的数字加入A中。
 
最终算法结束的时候CYL就得到了两个整数A和B。
 
为了考验du熊,CYL和LYC将会选取尽量多的棍子,即如果最多可以选取10根棍子,那么CYL和LYC将不会考虑导致最后只能选取少于10根棍子的选取方式。
 
由于镜面世界中没有熊ud,所以可怜的du熊没有助手,于是它只能算出所有可能的A*B值中最小的一个。
 
现在要求你找出du熊可以算出来的唯一结果。
 
输入格式
第一行一个整数T,代表测试数据个数。
 
接下来每个测试数据开头是两个整数m和n(1<m,n<=30),然后接下来一行共有2*m个整数,第i对整数分别代表现实世界中第i根棍子对应的左边和右边的数字 。
接下来一行通过同样的格式给出了镜面世界中n根棍子上左边和右边的数字。
 
之后一个整数C(0<=C<=500)表示共有C个相连关系,接着C行每行包含两个整数:a和b,表示现实世界中第a+1根棍子和镜面世界中第b+1根棍子间存在相连关系(显然a的范围是0..m-1,依此类推)。
 
输出格式
对于每个测试数据输出一行,表求du熊可以求出的乘法结果。
 
样例输入
2
2 2
1 2 1 3
2 2 2 3
2
0 1
1 0
3 3
1 2 3 1 4 3
2 2 3 3 4 4
5
0 0
1 0
1 1
1 2
2 0
 
样例输出
63
72
 
 
提示
在第一个测试数据中,CYL和LYC可以选取所有的棍子
在第二个测试数据中,只有当cyl先取第1和第2根棍子,而LYC对应选取第0和第1根棍子的时候,du熊才可以算出结果,其它的选取方法得到的数对于du熊来说都太大了。