• Hdu2053


    Switch Game HDU - 2053

    Time limit1000 msMemory limit32768 kB

    There are many lamps in a line. All of them are off at first. A series of operations are carried out on these lamps. On the i-th operation, the lamps whose numbers are the multiple of i change the condition ( on to off and off to on ).

    InputEach test case contains only a number n ( 0< n<= 10^5) in a line.
    OutputOutput the condition of the n-th lamp after infinity operations ( 0 - off, 1 - on ).Sample Input

    1
    5

    Sample Output

    1
    0


    首先我们得知道,第n次开关改变n的倍数的灯,那么前n盏灯的状态不再改变。所以要知道无限次操作后第n盏灯的状态,只需计算n盏灯n次操作后的状态。
    一开始想到的是模拟。时限是一秒,1秒大概能做10^8次操作,而题目的范围是10^10,不出意外TLE了。
     1 #include <cstdio>
     2 #include <iostream>
     3 #include <queue>
     4 #include <vector>
     5 #include<string.h>
     6 #include<map>
     7 #include<bits/stdc++.h>
     8 #define LL long long
     9 #define maxn 100005
    10 using namespace std;
    11 int a[maxn];
    12 int n;
    13 int main()
    14 {
    15     while(scanf("%d",&n)!=EOF)
    16     {
    17      memset(a,0,sizeof a);
    18      for(int i=1;i<=n;i++)
    19      {
    20          for(int j=1;j<=n;j++)
    21          {
    22              if((j%i)==0)
    23                 a[j]=!a[j];
    24          }
    25      }
    26      printf("%d
    ",a[n]);
    27     }
    28     return 0;
    29 }

    接着,想到第n盏的开关实际决定与它因数的个数,偶数个因数-0,奇数个因数-1.

     1 #include <cstdio>
     2 #include <iostream>
     3 #include <queue>
     4 #include <vector>
     5 #include<string.h>
     6 #include<map>
     7 #include<bits/stdc++.h>
     8 #define LL long long
     9 #define maxn 100005
    10 using namespace std;
    11 int n,ans;
    12 int main()
    13 {
    14     while(scanf("%d",&n)!=EOF)
    15     {
    16         ans=0;//记得初始化
    17         for(int i=1;i<=n;i++)
    18         if((n%i)==0)
    19             ans++;
    20         if(ans&1)printf("1
    ");
    21         else printf("0
    ");
    22     }
    23     return 0;
    24 }




  • 相关阅读:
    数组作为方法参数时的一些意外情况
    pack://application:,,,/
    WPF 使用WinForm Chart控件
    WPF 后台绑定样式
    在转换为 UTC 时大于 DateTime.MaxValue 或小于 DateTime.MinValue 的 DateTime 值无法系列化为 JSON
    LINQ_to_SQL语法及实例大全
    C#编码好习惯,献给所有热爱c#的同学
    C#中OpenFileDialog的使用
    NET 2.0(C#)调用ffmpeg处理视频的方法
    SQLite Mysql 模糊查找(like)
  • 原文地址:https://www.cnblogs.com/zuiaimiusi/p/10896211.html
Copyright © 2020-2023  润新知