zoukankan      html  css  js  c++  java
  • 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 = 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++) ;  //去前导0
            len = 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;
    }
  • 相关阅读:
    Kafka实战-简单示例
    Kafka实战-Kafka Cluster
    Kafka实战-入门
    高可用Hadoop平台-Hue In Hadoop
    apt-get install 出问题怎么办?
    E: Unable to locate package clang-7 E: Unable to locate package clang++-7 E: Couldn't find any package by regex 'clang++-7'
    LaTeX多图合并代码示例(subfigure)
    Pytorch--Dropout笔记
    命令行神器之argparse使用笔记
    【转载】PyTorch系列 (二):pytorch数据读取
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4711757.html
Copyright © 2011-2022 走看看