zoukankan      html  css  js  c++  java
  • 2012年软件大赛校内选拔赛

    1、(10分)求20+21+22+23+…+2n的和,n=20。

     1 //刚开始想一个一个算再加一块,后来想到了求和公式 
     2  #include <iostream>
     3  #include <cstring>
     4  using namespace std;
     5  
     6  int fun(int a,int b)//或者直接(2<<20-1或者1<<21-1) 
     7  {
     8      int temp,ans;
     9      if(0==b)
    10          return 1;
    11      temp = fun(a,b/2);
    12      ans = temp*temp;
    13      if(b&1)
    14          return ans*a;
    15      else
    16          return ans;
    17  }
    18  
    19  int main()
    20  {
    21      int i,j,k;
    22      int ans = fun(2,21) - 1;
    23      cout<<ans<<endl;
    24      //while(1);
    25      return 0;
    26  }

    2、(10分)1、6、9三个数字,排列组合后能产生多少个平方数(例如:3的平方为9,则9为平方数)?用程序判断并将结果打印输出。

     1 #include <iostream>
     2  #include <algorithm>
     3  #include <cmath>
     4  using namespace std;
     5  
     6  const double eps = 0.0000000000001;// 1e-8,中间不可有乘号,阶码必须是整数 ,double后的小数点可为15位 
     7  
     8  int main()
     9  {
    10      int i,j,k;
    11      int cnt = 0;
    12      int a[] = {1,6,9};
    13      sort(a,a+3);
    14      do
    15      {
    16          //cout<<a[0]<<a[1]<<a[2]<<endl;
    17          int temp = a[0]*100 + a[1]*10 + a[2];
    18          double temp1 = sqrt(temp);
    19          //cout<<temp<<"  "<<temp1<<endl;
    20          //if(fabs(temp1*temp1-temp)<eps)//这种方法不对,肯定输出总的全排列个数 
    21              //cnt++;
    22          double temp2 = (double)((int)temp1);
    23          if(fabs(temp1 - temp2)<eps)//若是平方数,则开放的数没有小数部分 
    24              cnt++;
    25      }while(next_permutation(a,a+3));
    26      cout<<cnt<<endl;
    27     // while(1);
    28      return 0;
    29  }

    3、(20分)Excel 表格中, 第12 行 4 列可表示为 R12C4, 第5 行 255 列可表示为 R5C255,还有另一种表示方式为 D12,IU5,输入 RC 格式转化为另一个种格式。

    例:

    INPUT:

    2

    R12C4

    R5C255

    OUTPUT:

    D12

    IU5

    编程实现两种表示方法间的转化(第二行输入的2表示有两条RC格式需要转换)。

     1 //这道题费了些神,以前也遇到过类似的但没做出来,今天我思量主要是我把自己搞得太疲惫啦 
     2  //行号直接输出就好啦,列数用栈处理下 
     3  #include <iostream>
     4  #include <algorithm>
     5  #include <cmath>
     6  #include <stack>
     7  #include <cstring>
     8  using namespace std;
     9  
    10  char str[20];
    11  int temp1 = 0,temp2 = 0;
    12  stack <int > s;
    13  
    14  void fun()
    15  {
    16      int i,j;
    17      int len = strlen(str);
    18      temp1 = temp2 = 0;
    19      for(i=1; i<len; i++)
    20      {
    21          if(isdigit(str[i]))
    22              temp1 = temp1*10 + str[i] - '0';
    23          else
    24              break;
    25      }
    26      for(j=i+1; j<len; j++)//注意j是从(i+1)开始的,不是i 
    27      {
    28          if(isdigit(str[j]))//原来直接复制过来啦,里面的i没改成j 
    29              temp2 = temp2*10 + str[j] - '0';
    30      }
    31      while(temp2>0)
    32      {
    33          int temp = temp2%26;
    34          s.push(temp);
    35          temp2 /= 26;
    36      }
    37  }
    38  
    39  int main()
    40  {
    41      int i,j,k;
    42      int T;
    43      cin>>T;
    44      while(T--)
    45      {
    46          temp1 = temp2 = 0;
    47          memset(str,0,sizeof(str));
    48         // while(!s.empty())
    49          //    s.pop();
    50          cin>>str;
    51          fun();
    52         // for(i=0; i<s.size(); i++)
    53         while(!s.empty())
    54          {
    55              char ch = (char)(s.top() + 64);
    56              cout<<ch;
    57              s.pop();
    58          }
    59          cout<<temp1<<endl;
    60      }
    61      return 0;
    62  }

    4、(30分)有 3 枚骰子,玩家可押 1-6 中的一个数

    1) 如果有 1 个数相同,则庄家 1:1 赔偿

    2) 如果有 2 个数相同,则庄家 1:2 赔偿

    3) 如果有 3 个数相同,则庄家 1:6 赔偿

    4) 如果押的点数与其中一个骰子的乘积,等于另外两个数的乘积,则拿回自己的本钱,即庄家不赚不赔

    5) 如果上述 4 种情况均满足,则选择最佳的方式

    实践证明,不管怎么样,庄家都是获利的,请模拟 50 万次,假设每次押注都是 1 元,求庄家的盈利率(赚的钱/总押注金额)。

    5、(30分)ABCDE 五人安排工作日程,每人每星期工作 5 天休息 2 天

    1) 必须有 3 天所有人都要上班

    2) 每个人连续上班不超过 3 天,周日到周一是连续工作

    3) A、C 星期三必须上班

    4) B、D、E 星期天都不上班

    5) A、C 一星期至少见 4 次

    6) A、B、C、D 中每天必须至少有 2 人上班,输出所有从星期一到星期天可能的情况,每种情况间用空行隔开,0 代表不

    上班,1 代表上班。

    例:

    1 0 1 1 1 0 1

    1 1 0 1 1 1 0

    1 0 1 1 1 0 1

    1 1 0 1 1 1 0

    1 1 0 1 1 1 0

  • 相关阅读:
    day79——基础知识复习3(django)
    day78——基础知识复习2
    bjday5——组件的嵌套与传值
    drfday2——序列化组件serializer
    drfday5——权限,频率,异常处理
    drfday1——入门规范
    ElasticSearch基本查询使用(2)
    RocketMQ(2) 消息的生产和存储
    ElasticSearch基础介绍(1)
    RocketMQ(3) 根据消息key查询功能的实现: indexFile
  • 原文地址:https://www.cnblogs.com/hxsyl/p/2809785.html
Copyright © 2011-2022 走看看