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 = 240;struct bign
{int len, s[MAXN];bign (){memset(s, 0, sizeof(s));len = 1;}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 = 0; num[i] == '0'; num++) ;  //去前导0len = strlen(num);for(int i = 0; i < len; i++) s[i] = num[len-i-1] - '0';return *this;}bign operator + (const bign &b) const //+
    {bign c;c.len = 0;for(int i = 0, g = 0; 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 % 10;g = x / 10;}return c;}bign operator += (const bign &b){*this = *this + b;return *this;}void clean(){while(len > 1 && !s[len-1]) len--;}bign operator * (const bign &b) //*
    {bign c;c.len = len + b.len;for(int i = 0; i < len; i++){for(int j = 0; j < b.len; j++){c.s[i+j] += s[i] * b.s[j];}}for(int i = 0; i < c.len; i++){c.s[i+1] += c.s[i]/10;c.s[i] %= 10;}c.clean();return c;}bign operator *= (const bign &b){*this = *this * b;return *this;}bign operator - (const bign &b){bign c;c.len = 0;for(int i = 0, g = 0; i < len; i++){int x = s[i] - g;if(i < b.len) x -= b.s[i];if(x >= 0) g = 0;else{g = 1;x += 10;}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 = 0;for(int i = len-1; i >= 0; i--){f = f*10;f.s[0] = 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-1; i >= 0; 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-1; i >= 0; 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 = 0; i < len; i++) res = char(s[i]+'0') + 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[150];bign Caculate(int x,int y)
{bign res = 0;if (x == y && x == 1){bign rea  = 1;return rea;}if (x < y) return res;return val[x] / val[x-y];
}int main(int argc,char *argv[])
{val[0] = 1;freopen("out.txt","w",stdout);for(int i = 1 ; i <= 100 ; ++ i) val[i] = val[i-1] * i;for(int n = 5 ; n <= 100 ; ++ n){bign MAX = 0;int ans;bign check = 0;for(int x = 1 ; x <= n-1 ; ++ x){check = 0;for(int j = x + 1 ; j <= n ; ++ j)for(int t = x ; t <= n-1 ; ++ t){check = check +  Caculate(n-j,n-t-1) * Caculate(x,1) * Caculate(t-1,t-1);}if (check > MAX){MAX = check;ans = x;}}cout << "a[" << n <<"] = " << ans << ";" << endl;}return 0;
}

正解:

#include <iostream>
#include <cstring>
using namespace std;
int a[105];
long long f[70][70][2];int main()
{
memset(f,0,sizeof(f));a[5] = 2;
a[6] = 2;
a[7] = 2;
a[8] = 3;
a[9] = 3;
a[10] = 3;
a[11] = 4;
a[12] = 4;
a[13] = 5;
a[14] = 5;
a[15] = 5;
a[16] = 6;
a[17] = 6;
a[18] = 6;
a[19] = 7;
a[20] = 7;
a[21] = 8;
a[22] = 8;
a[23] = 8;
a[24] = 9;
a[25] = 9;
a[26] = 9;
a[27] = 10;
a[28] = 10;
a[29] = 10;
a[30] = 11;
a[31] = 11;
a[32] = 12;
a[33] = 12;
a[34] = 12;
a[35] = 13;
a[36] = 13;
a[37] = 13;
a[38] = 14;
a[39] = 14;
a[40] = 15;
a[41] = 15;
a[42] = 15;
a[43] = 16;
a[44] = 16;
a[45] = 16;
a[46] = 17;
a[47] = 17;
a[48] = 17;
a[49] = 18;
a[50] = 18;
a[51] = 19;
a[52] = 19;
a[53] = 19;
a[54] = 20;
a[55] = 20;
a[56] = 20;
a[57] = 21;
a[58] = 21;
a[59] = 22;
a[60] = 22;
a[61] = 22;
a[62] = 23;
a[63] = 23;
a[64] = 23;
a[65] = 24;
a[66] = 24;
a[67] = 24;
a[68] = 25;
a[69] = 25;
a[70] = 26;
a[71] = 26;
a[72] = 26;
a[73] = 27;
a[74] = 27;
a[75] = 27;
a[76] = 28;
a[77] = 28;
a[78] = 29;
a[79] = 29;
a[80] = 29;
a[81] = 30;
a[82] = 30;
a[83] = 30;
a[84] = 31;
a[85] = 31;
a[86] = 31;
a[87] = 32;
a[88] = 32;
a[89] = 33;
a[90] = 33;
a[91] = 33;
a[92] = 34;
a[93] = 34;
a[94] = 34;
a[95] = 35;
a[96] = 35;
a[97] = 35;
a[98] = 36;
a[99] = 36;
a[100] = 37;int n;cin >> n;cout << a[n] <<endl;return 0;
}

Codeforces Gym 100418K Cards 暴力打表相关推荐

  1. codeforce Gym 100418K Cards (概率,数学)

    题意:麦田的故事,n张牌,取x张牌,记住前x张牌最大的值m,继续往后取,遇到第一张比m大的牌就停下来.求一个x使得最后的牌在整副牌里是最大的期望最大. 假设最大的牌是A,A在各种位置出现的概率就是相等 ...

  2. [codeforces 1327E] Count The Blocks 打表找规律+根据规律找公式+优化公式

    Educational Codeforces Round 84 (Rated for Div. 2)   比赛人数13522 [codeforces 1327E]  Count The Blocks  ...

  3. [蓝桥杯][2016年第七届真题]冰雹数(暴力打表找规律)

    题目描述 任意给定一个正整数N, 如果是偶数,执行: N / 2 如果是奇数,执行: N * 3 + 1 生成的新的数字再执行同样的动作,循环往复. 通过观察发现,这个数字会一会儿上升到很高, 一会儿 ...

  4. 暴力打表之hdu 2089

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2089 有两种方法: 1.数位DP算法 2.暴力打表--真是个好法子!!! 接下来是注意点: 1.一般这 ...

  5. Codeforces Gym 101173 CERC 16 D BZOJ 4790 Dancing Disks

    Codeforces Gym 101173 CERC 16 D & BZOJ 4790 Dancing Disks 强烈安利这道构造题目,非常有意思. 这里用到的思想是归并排序! 多路归并排序 ...

  6. Codeforces Gym 101086 M ACPC Headquarters : AASTMT (Stairway to Heaven)

    Codeforces Gym 101086 M ACPC Headquarters : AASTMT (Stairway to Heaven) 题目来源: Codeforces 题意: 给出一些比赛, ...

  7. [Codeforces Gym 101651/100725B] Banal Tickets

    Codeforces Gym 100725 题解: 先分两种情况, 积为000与积非0" role="presentation" style="position ...

  8. Codeforces Gym 100513G G. FacePalm Accounting 暴力

    G. FacePalm Accounting Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513 ...

  9. Codeforces Gym 101473D Folding Machine (暴力搜索)

    题目连接: http://codeforces.com/gym/101473/attachments 原先以为按照这个复杂度还要剪一下支,没想到暴力dfs完全可以通过. 代码: #include &l ...

最新文章

  1. 《spring揭秘》读书笔记三
  2. C语言 | 基于51单片机实现MPU6050的卡尔曼滤波算法(代码类2)
  3. hive sql插入一行数据_Hive查询某一重复字段记录第一条数据
  4. 一张大图总结数据结构与算法
  5. 第01课:中文自然语言处理的完整机器处理流程
  6. adf时间作用域_ADF任务流:页面片段的托管bean作用域
  7. LeetCode 880. 索引处的解码字符串(找规律)
  8. lntellijidea怎么创建文件_DBC文件到底是个啥
  9. Lync Server 2013视频会议新功能及配置
  10. Apache OpenNLP
  11. NYOJ770 仿射密码
  12. arduino 下载 https://downloads.arduino.cc/packages/package_index.json error
  13. 坚持分享的魅力,我超越了当年的榜样
  14. 基于SSM实现新闻发布系统
  15. html修改按钮属性,button属性
  16. HTML5期末大作业:关于家乡介绍主题网页设计——云南民族文化(8页) HTML+CSS+JavaScript 期末作业HTML代码 学生网页课程设计期末作业下载 web网页设计制作成品
  17. 计算机放音乐声音小在吗调,用电脑在网上看电影时配乐音量太大,请问怎么只把配乐音量调小,而说话声不调小。...
  18. 图解IE浏览器下,如何保存输入记录
  19. 第十五篇:大球联赛与小球联赛
  20. 什么是单点故障【转载】

热门文章

  1. Qt最新版5.12在Windows环境静态编译安装和部署的完整过程(VS2017)
  2. oracle闪回 分区,Oracle 闪回区(Oracle Flash recovery area)
  3. 2010河北职称计算机考试,2010年河北省职称计算机考试试题..doc
  4. php与nginx链接,Nginx与PHP的交互
  5. Docker(七):Docker build 、Docker Dockerfile 详解
  6. mac下java 开发环境搭建
  7. sqlite3自增key设定(创建自增字段)
  8. OS X 10.11 cocoapods
  9. 服务器安全性文档,Microsoft Web服务器的安全性
  10. 软件测试之功能测试详细过程