2012年软件大赛校内选拔赛

简介: 1、(10分)求20+21+22+23+…+2n的和,n=20。 1 //刚开始想一个一个算再加一块,后来想到了求和公式 2 #include 3 #include 4 using namespace std; 5 6 int fun(int a,int...

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

目录
相关文章
|
9月前
|
机器学习/深度学习 存储 人工智能
【中国大学生计算机大赛二等奖】智能中医-中e诊简介(一)
【中国大学生计算机大赛二等奖】智能中医-中e诊简介(一)
131 0
|
4月前
|
网络协议 安全 网络安全
第三届陕西省大学生网络安全技能大赛部分WriteUp
发现ctr1 += chr(ord(flag[i]) ^ 5)是个异或,使用工具进行异或即可解出flag 奖状到啦!!奖状到啦!!奖状到啦!!奖状到啦!!奖状到啦!!奖状到啦!!奖状到啦!!奖状到啦!!奖状到啦!!
第三届陕西省大学生网络安全技能大赛部分WriteUp
|
5月前
|
存储 安全 计算机视觉
参加第十二届中国软件杯比赛感想以及经验
今年我作为参赛选手参加了中国软件杯南京线下赛,参加了总决赛答辩环节,下面总结一些参加比赛的经验以及感受
|
5月前
|
开发工具 数据安全/隐私保护
UNCTF2022-校内赛
UNCTF2022-校内赛
33 0
|
XML JSON 程序员
(猿如意)—— 集百家之所长
(猿如意)—— 集百家之所长
(猿如意)—— 集百家之所长
|
测试技术 C++ Windows
2021 第十二届蓝桥杯大赛软件赛决赛, 国赛,C/C++ 大学B 组
2021 第十二届蓝桥杯大赛软件赛决赛, 国赛,C/C++ 大学B 组
114 1
|
安全 测试技术 Linux
2022年“网络安全”赛项驻马店市赛选拔赛 任务书
2022年“网络安全”赛项驻马店市赛选拔赛 任务书
363 0
2022年“网络安全”赛项驻马店市赛选拔赛 任务书
全国3000多名工程师大集结,技术宅要拯救世界?!
随着年岁渐长,我们似乎在漫长、重复的代码工作中,渐渐失去了年少时那些勇气、拼劲和异想天开。但总有些人,活得特别不一样。
896 0