Cards
Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86686#problem/K

Description

You have N cards with different numbers on them. Your goal is to find a card with a maximal number. At the beginning all cards are put into the hat. You start getting them one by one and look at the numbers on them. After each card you can select it and stop the process. If it is really the card with the maximal number you win otherwise you lose. Also you can skip the current card and continue process. Fortunately you have a friend who helps with a good strategy: you pull X cards and memorize their values. Then you continue the process and select as answer the first card with value greater than the maximal value you memorized. Unfortunately you don't know the value of Xthat maximizes you chances of winning. Your task is to find X.

Input

Single line containing one number: N (5 ≤ N ≤ 100).

Output

Single line containing one number: value of X that maximizes you chances of winning.

Sample Input

5

Sample Output

2

HINT

题意

有n张牌,一开始可以先摸前x张牌,然后记住里面的最大数,然后扔掉,如果后面摸牌遇到比这个数大的情况就停止

如果这个数是最大的数的话,就赢了,否则就输了

问你X取何值,能够有最大可能的胜率

题解

推出一个谁都能推出来的暴力算所有组合的公式,然后再直接暴力打表……

由于要爆longlong,所以我的打表是用高精度跑的

打表打了半小时= =

代码:

打表程序:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <string>
#include <ctime>
#include <list>
typedef unsigned char byte;
#define pb push_back
#define input_fast std::ios::sync_with_stdio(false);std::cin.tie(0)
#define local freopen("in.txt","r",stdin)
#define pi acos(-1) using namespace std;
const int MAXN = ; struct bign
{
int len, s[MAXN];
bign ()
{
memset(s, , sizeof(s));
len = ;
}
bign (int num) { *this = num; }
bign (const char *num) { *this = num; }
bign operator = (const int num)
{
char s[MAXN];
sprintf(s, "%d", num);
*this = s;
return *this;
}
bign operator = (const char *num)
{
for(int i = ; num[i] == ''; num++) ; //去前导0
len = strlen(num);
for(int i = ; i < len; i++) s[i] = num[len-i-] - '';
return *this;
}
bign operator + (const bign &b) const //+
{
bign c;
c.len = ;
for(int i = , g = ; g || i < max(len, b.len); i++)
{
int x = g;
if(i < len) x += s[i];
if(i < b.len) x += b.s[i];
c.s[c.len++] = x % ;
g = x / ;
}
return c;
}
bign operator += (const bign &b)
{
*this = *this + b;
return *this;
}
void clean()
{
while(len > && !s[len-]) len--;
}
bign operator * (const bign &b) //*
{
bign c;
c.len = len + b.len;
for(int i = ; i < len; i++)
{
for(int j = ; j < b.len; j++)
{
c.s[i+j] += s[i] * b.s[j];
}
}
for(int i = ; i < c.len; i++)
{
c.s[i+] += c.s[i]/;
c.s[i] %= ;
}
c.clean();
return c;
}
bign operator *= (const bign &b)
{
*this = *this * b;
return *this;
}
bign operator - (const bign &b)
{
bign c;
c.len = ;
for(int i = , g = ; i < len; i++)
{
int x = s[i] - g;
if(i < b.len) x -= b.s[i];
if(x >= ) g = ;
else
{
g = ;
x += ;
}
c.s[c.len++] = x;
}
c.clean();
return c;
}
bign operator -= (const bign &b)
{
*this = *this - b;
return *this;
}
bign operator / (const bign &b)
{
bign c, f = ;
for(int i = len-; i >= ; i--)
{
f = f*;
f.s[] = s[i];
while(f >= b)
{
f -= b;
c.s[i]++;
}
}
c.len = len;
c.clean();
return c;
}
bign operator /= (const bign &b)
{
*this = *this / b;
return *this;
}
bign operator % (const bign &b)
{
bign r = *this / b;
r = *this - r*b;
return r;
}
bign operator %= (const bign &b)
{
*this = *this % b;
return *this;
}
bool operator < (const bign &b)
{
if(len != b.len) return len < b.len;
for(int i = len-; i >= ; i--)
{
if(s[i] != b.s[i]) return s[i] < b.s[i];
}
return false;
}
bool operator > (const bign &b)
{
if(len != b.len) return len > b.len;
for(int i = len-; i >= ; i--)
{
if(s[i] != b.s[i]) return s[i] > b.s[i];
}
return false;
}
bool operator == (const bign &b)
{
return !(*this > b) && !(*this < b);
}
bool operator != (const bign &b)
{
return !(*this == b);
}
bool operator <= (const bign &b)
{
return *this < b || *this == b;
}
bool operator >= (const bign &b)
{
return *this > b || *this == b;
}
string str() const
{
string res = "";
for(int i = ; i < len; i++) res = char(s[i]+'') + res;
return res;
}
}; istream& operator >> (istream &in, bign &x)
{
string s;
in >> s;
x = s.c_str();
return in;
} ostream& operator << (ostream &out, const bign &x)
{
out << x.str();
return out;
} bign val[]; bign Caculate(int x,int y)
{
bign res = ;
if (x == y && x == )
{
bign rea = ;
return rea;
}
if (x < y) return res;
return val[x] / val[x-y];
} int main(int argc,char *argv[])
{
val[] = ;
freopen("out.txt","w",stdout);
for(int i = ; i <= ; ++ i) val[i] = val[i-] * i;
for(int n = ; n <= ; ++ n)
{
bign MAX = ;
int ans;
bign check = ;
for(int x = ; x <= n- ; ++ x)
{
check = ;
for(int j = x + ; j <= n ; ++ j)
for(int t = x ; t <= n- ; ++ t)
{
check = check + Caculate(n-j,n-t-) * Caculate(x,) * Caculate(t-,t-);
}
if (check > MAX)
{
MAX = check;
ans = x;
}
}
cout << "a[" << n <<"] = " << ans << ";" << endl;
}
return ;
}

正解:

#include <iostream>
#include <cstring>
using namespace std;
int a[];
long long f[][][]; int main()
{
memset(f,,sizeof(f));
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
int n;
cin >> n;
cout << a[n] <<endl;
return ;
}

最新文章

  1. 如何处理CSS3属性前缀
  2. iOS应用之间调用
  3. spring框架设计理念(上)
  4. 边工作边刷题:70天一遍leetcode: day 71-2
  5. POJ 2828Buy Tickets
  6. jquery实现页面局部刷新
  7. TOMCAT内存大小调整
  8. opencv Iplimage结构简介
  9. WPF程序长时间无人操作
  10. easyui tree 的数据格式转换
  11. Swift Array copy 的线程安全问题
  12. Linux系统安装建议
  13. JAVA三大特性之二——继承
  14. 9.Smarty的循环
  15. ul中li居中显示的table方法
  16. Unity3D学习笔记(三)Unity的C#基础
  17. 手眼标定eye-to-hand 示例:handeye_stationarycam_calibration
  18. htmlunit 校验验证码
  19. CentOS6.8下实现配置配额
  20. 深入理解java虚拟机---Class文件(二十)

热门文章

  1. CSS HACK区别IE6、IE7、IE8、Firefox兼容性
  2. 【转】http-equiv的含义
  3. 如何合并IP网段
  4. [Papers]NSE, $\pi$, Lorentz space [Suzuki, NA, 2012]
  5. Linux 系统编程
  6. IOS AsyncSocket
  7. Clang Language Extensions
  8. Javascript——说说js的调试
  9. 【和我一起学python吧】Python安装、配置图文详解
  10. windows下安装和配置Weka