c++编程题目思考1

博弈游戏

题目描述
Here is a simple game. In this game, there are several piles of matches and two players. The two player play in turn. In each turn, one can choose a pile and take away arbitrary number of matches from the pile (Of course the number of matches, which is taken away, cannot be zero and cannot be larger than the number of matches in the chosen pile). If after a player’s turn, there is no match left, the player is the winner. Suppose that the two players are all very clear. Your job is to tell whether the player who plays first can win the game or not.
输入
The input consists of several lines, and in each line there is a test case. At the beginning of a line, there is an integer M (1 <= M <=20), which is the number of piles. Then comes M positive integers, which are not larger than 10000000. These M integers represent the number of matches in each pile.
输出
For each test case, output "Yes" in a single line, if the player who play first will win, otherwise output "No".
样例输入
2 45 45
3 3 6 9
样例输出
No
Yes

#include<stdio.h>
int main()
{
    int   n,i,a[50];
    int temp,ans;
      while(~scanf("%d",&n))
      {
        temp=0;
        ans=-1;
        for(i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            if(i==0)
                ans=a[i];
            else
                ans=ans^a[i];
            if(a[i]>1)
                 temp=1;
        }
        if(temp==0)
        {
            if(n%2==1)
              printf("No\n");
            else
              printf("Yes\n");
        }
        else
        {
            if(ans==0)
              printf("No\n");
            else
              printf("Yes\n");

        }
    }
    return 0;
}

解题思路:http://www.voidcn.com/article/p-ryiojmgj-yc.html

bit

题目描述
Amtel has announced that it will release a 128-bit computer chip by 2010, a 256-bit computer by 2020, and so on, continuing its strategy of doubling the word-size every ten years. (Amtel released a 64-bit computer in 2000, a 32-bit computer in 1990, a 16-bit computer in 1980, an 8-bit computer in 1970, and a 4-bit computer, its first, in 1960.)
Amtel will use a new benchmark - the Factstone - to advertise the vastly improved capacity of its new chips. The Factstone rating is defined to be the largest integer n such that n! can be represented as an unsigned integer in a computer word.
Given a year 1960 ≤ y ≤ 2160, what will be the Factstone rating of Amtel's most recently released chip?
输入
There are several test cases. For each test case, there is one line of input containing y. A line containing 0 follows the last test case.
输出
For each test case, output a line giving the Factstone rating.
样例输入
1960
1981
0
样例输出
3
8

解题:https://www.cnblogs.com/ISGuXing/p/7301064.html

沙子的质量:https://blog.csdn.net/u014493323/article/details/103126478

蚂蚁问题:https://www.cnblogs.com/li-jia-hao/p/12702844.html

字典排序

https://www.cnblogs.com/chailinbo/p/9269210.html

https://www.jianshu.com/p/e0de4c9b73f2

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 我是黑夜里大雨纷飞的人啊 1 “又到一年六月,有人笑有人哭,有人欢乐有人忧愁,有人惊喜有人失落,有的觉得收获满满有...
    陌忘宇阅读 8,603评论 28 53
  • 首先介绍下自己的背景: 我11年左右入市到现在,也差不多有4年时间,看过一些关于股票投资的书籍,对于巴菲特等股神的...
    瞎投资阅读 5,784评论 3 8
  • ![Flask](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAW...
    极客学院Wiki阅读 7,289评论 0 3
  • 不知不觉易趣客已经在路上走了快一年了,感觉也该让更多朋友认识知道易趣客,所以就谢了这篇简介,已做创业记事。 易趣客...
    Physher阅读 3,448评论 1 2