# Winning an Auction

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 47    Accepted Submission(s): 3

Problem Description
Alice and Bob play an auction game. Alice has A dollars and Bob has B dollars initially. There are N items on sale. In each round, an item will be sold by the following way. Alice writes down an integer a (0 ≤ a ≤ A) and Bob writes down an integer b (0 ≤ b ≤ B), which are the amount of dollars they want to pay for the item. If a > b, then Alice gets the item and pays a dollars to the seller. If a < b, then Bob gets the item and pays b dollars to the seller. If a = b, then for the 1st, 3rd, 5th, 7th ... round, Alice gets the item and pays a dollars; for the 2rd, 4th, 6th, 8th ... round, Bob gets the item and pays b dollars. Since all the items have the same value, the goal of the auction game is to get as many items as possible. Both Alice and Bob know the values of N,A and B. Your task is to calculate how many items they will get if both of them play optimally.

Input
The first line is the number of test cases. Each test case contains 3 integers N,A and B, which are no larger than 255.

Output
For each test case, output the number of items Alice and Bob will get if both of them play optimally.

Sample Input
3 1 1 2 2 4 2 3 3 3

Sample Output
Alice 0 Bob 1 Alice 1 Bob 1 Alice 2 Bob 1

Source

//http://blog.csdn.net/snowy_smile/article/details/52981616
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
#define MS(x, y) memset(x, y, sizeof(x))
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b > a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b < a)a = b; }
const int N = 256, M = 0, Z = 1e9 + 7, inf = 0x3f3f3f3f;
template <class T1, class T2>inline void gadd(T1 &a, T2 b) { a = (a + b) % Z; }
int casenum, casei;
int n, A, B;
short f[2][N][N][N];
void DP()
{
for (int o = 0; o < 2; ++o)
{
for (int a = 0; a <= 255; ++a)
{
for (int b = 0; b <= 255; ++b)
{
if (a > b)f[o][1][a][b] = 1;
else if (b > a)f[o][1][a][b] = 0;
else f[o][1][a][b] = o == 1 ? 1 : 0;
}
}
}
for (int o = 0; o < 2; ++o)
{
for (int p = 2; p <= 255; ++p)
{
for (int a = 0; a <= 255; ++a)
{
for (int b = 0; b <= 255; ++b)
{
if (a == b)
{
if (p & 1)f[o][p][a][b] = p / 2 + (o == 1);
else f[o][p][a][b] = p / 2;
continue;
}
if ((o - p + 1) & 1)//Alice占据优势
{
int va = f[o][p - 1][a][b] + 1;                            //初始a买的状态
int vb;
for (int u = 1; ; ++u)
{
if (b < u || (vb = f[o][p - 1][a][b - u]) >= va)    //b多花钱没意义
{
f[o][p][a][b] = va;
break;
}
if (a < u || (va = f[o][p - 1][a - u][b] + 1) <= vb)//a多花钱没意义
{
f[o][p][a][b] = vb;
break;
}
}
}
else//Bob占据优势
{
int vb = f[o][p - 1][a][b];                                //初始b买的状态
int va;
for (int u = 1; ; ++u)
{
if (a < u || (va = f[o][p - 1][a - u][b] + 1) <= vb)//a多花钱没意义
{
f[o][p][a][b] = vb;
break;
}
if (b < u || (vb = f[o][p - 1][a][b - u]) >= va)    //b多花钱没意义
{
f[o][p][a][b] = va;
break;
}
}
}
}
}
}
}
}
int main()
{
DP();
scanf("%d", &casenum);
for (casei = 1; casei <= casenum; ++casei)
{
scanf("%d%d%d", &n, &A, &B);
int Alice = f[n & 1][n][A][B];
int Bob = n - Alice;
printf("Alice %d Bob %d\n", Alice, Bob);
}
return 0;
}
/*
【trick&&吐槽】
1，记忆化搜索是比DP慢一些，甚至可能达到2倍常数，所以记忆化搜索这里会TLE儿DP可以AC
2，使用short类型才可以满足这种做法的空间要求
3，如果离线询问的话是可以对空间再次降低一半的

【题意】
http://acm.hdu.edu.cn/showproblem.php?pid=5951

【分析】

……

【时间复杂度&&优化】
O(2 * n ^ 3 * k)

*/


• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120