zoukankan      html  css  js  c++  java
  • 杭电 acm 2053 ( Switch Game )

    这题思路:
    一开始有n盏灯,且全部为关闭状态,都记为 0  就是  The initial condition :      0 0 0 0 0 …
    然后之后进行i操作就是对这些灯以是否能被i整除,进行改变状态,如将 0 改为 1 或 将 1 改为 0
    正如提醒里的
    After the first operation :  1 1 1 1 1 … 
    After the second operation : 1 0 1 0 1 … 
    After the third operation :  1 0 0 0 1 … 
    After the fourth operation : 1 0 0 1 1 … 
    After the fifth operation :  1 0 0 1 0 … 
    然后题目的输出是 第i次操作的第i个的状态,正如上面红色标记的
     
    代码如下:
    #include<stdio.h> 
    int count(int n
    { 
       int i,j=0; 
       for(i=1;i<=n;i++) 
       { 
           if(n%i==0) 
              j++; 
       } 
       return j
    } 
    int main() 
    { 
        int n; 
        while(~scanf("%d",&n)) 
        { 
            printf("%d ",count(n)%2); 
        } 
        return 0
    }
     
    这题还有规律:
    我们把前10个写出来就知道了
    1.  1 1 1 1 1 1 1 1 1 1 1 1 1
    2.  1 0 1 0 1 0 1 0 1 0 1 0 1 
    3.  1 0 0 0 1 1 1 0 0 0 1 1 1
    4.  1 0 0 1 1 1 1 1 0 0 1 0 1
    5.  1 0 0 1 0 1 1 1 0 1 1 0 1
    6.  1 0 0 1 0 0 1 1 0 1 1 1 1
    7.  1 0 0 1 0 0 0 1 0 1 1 1 1
    8.  1 0 0 1 0 0 0 0 0 1 1 1 1
    9.  1 0 0 1 0 0 0 0 1 1 1 1 1
    10. 1 0 0 1 0 0 0 0 1 0 1 1 1
     
    从这里我们就可以规律了,就是除了 n*n 是 1 ,其余的都是 0 
     
    代码如下:
    #include<stdio.h> 
    #include<string.h> 
    int main() 
    { 
        int n,a[100001],i; 
        memset(a,0,sizeof(a)); 
        for(i=1;i*i<=100000;i++) 
            a[i*i]=1; 
        while(~scanf("%d",&n)) 
        { 
            if(n<0||n>100000) 
            break; 
            printf("%d ",a[n]);
        }
        return 0;
    }

     

  • 相关阅读:
    截取表单提交的字符串信息转换成对象 -- 前端面试题(一)
    HTML5 简单归纳 -- 前端知识 (二)
    02_安装Linux
    01_Linux 简介
    Mysql学习笔记八:Mysql操作
    Mysql学习笔记七:常用SQL语句
    Mysql学习笔记六:事务
    Mysql学习笔记五:修改
    Mysql学习笔记四:查询
    Mysql学习笔记二:主键、外键
  • 原文地址:https://www.cnblogs.com/ghostTao/p/3849514.html
Copyright © 2011-2022 走看看