Codeforces Gym 100418K Cards 暴力打表
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 ;
}
Codeforces Gym 100418K Cards 暴力打表的更多相关文章
- Codeforces Gym 100418K Cards 组合数学
CardsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action? ...
- Codeforces GYM 100114 C. Sequence 打表
C. Sequence Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Description ...
- Codeforces Gym 100531D Digits 暴力
Problem D. Digits 题目连接: http://codeforces.com/gym/100531/attachments Description Little Petya likes ...
- codeforce Gym 100418K Cards (概率,数学)
题意:麦田的故事,n张牌,取x张牌,记住前x张牌最大的值m,继续往后取,遇到第一张比m大的牌就停下来.求一个x使得最后的牌在整副牌里是最大的期望最大. 假设最大的牌是A,A在各种位置出现的概率就是相等 ...
- Codeforces 914 C 数位DP+暴力打表+思维
题意 给出一个二进制数\(n\),每次操作可以将一个整数\(x\)简化为\(x\)的二进制表示中\(1\)的个数,如果一个数简化为\(1\)所需的最小次数为\(k\),将这个数叫做特殊的数, 问从\( ...
- 【Codeforces】Gym 101156G Non-Attacking Queens 打表
题意 求$n\times n$的棋盘上放$3$个皇后使得互相不攻击的方案数 拓展是$m\times n$棋盘上放$k$皇后,暴力打表找到了公式 OEIS 代码 import java.math.Big ...
- Codeforces Gym 101190M Mole Tunnels - 费用流
题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...
- ACM/ICPC 之 暴力打表(求解欧拉回路)-编码(POJ1780)
///找到一个数字序列包含所有n位数(连续)一次且仅一次 ///暴力打表 ///Time:141Ms Memory:2260K #include<iostream> #include< ...
- XTU OJ 1210 Happy Number (暴力+打表)
Problem Description Recently, Mr. Xie learn the concept of happy number. A happy number is a number ...
随机推荐
- Oracle权限一览表
权限 所能实现的操作 分析 ANALYZE ANY 分析数据库中的任何表.簇或索引 审计 AUDIT ANY 审计数据库中的任何模式对象 AUDIT SYSTEM 启用与停用语句和特权的审计选项 ...
- IOS 使用CoreText实现表情文本URL等混合显示控件
实现了一个富文本视图控件.主要针对表情图片,文本字符,URL,等这种类型的文本进行显示. 源码地址 https://github.com/TinyQ/TQRichTextView 实现的效果如下图. ...
- [转] C#操作EXCEL,生成图表的全面应用
gailzhao 原文 关于C#操作EXCEL,生成图表的全面应用 近来我在开发一个运用C#生成EXCEL文档的程序,其中要根据数据生成相应的图表,该图表对颜色和格式都有严格的要求,在百度和谷歌中搜索 ...
- C++ primer里的template用法
来源:http://c.chinaitlab.com/cc/ccjq/200806/752604_2.html -- template 的用法 在程序设计当中经常会出现使用同种数据结构的不同实 ...
- AutoLayout UITableViewCell 动态高度
从这里http://www.cnblogs.com/liandwufan/p/4516956.html?utm_source=tuicool 转载过来的 -(UITableViewCell*)tabl ...
- UITextView 不左上角显示
在Autolayout中 UITextView显示不左上角显示,修改如下 在viewDidLoad里面添加如下代码 if([[[UIDevice currentDevice] systemVersio ...
- 有关SQLite的substr函数的笔记
官方参考文档:SQLite Query Language: Core Functions http://www.sqlite.org/lang_corefunc.html 测试SQL语句: ,) AS ...
- 从python的yield说起
前段时间在读trac 中wiki模块的源码的时候,发现了很多地方都使用了yiled这一关键词, 感觉是在需要返回某个值的地方通过yield来代替return, 不是很明白其用法,所以仔细研究下. 一个 ...
- XNA Game Studio4.0 Programming 随便读,随便记。
一.精灵和2D图形 1.什么是2D ? 2D可以理解为 two-Dimentionanl , 2-dimentional 的缩写. 意就是两维的,比如 数学中的 直角坐标系 所能描述的就是一个2D的 ...
- OpenStack Cinder组件支持的块存储设备表
摘自恒天云官网:http://www.hengtianyun.com/download-show-id-18.html OpenStack的Cinder组件底层可以连接多种存储设备和方案,每一个Ope ...