hdu 2051 Switch Game(模拟/数论)

题目意思:

http://acm.hdu.edu.cn/showproblem.php?pid=2053

给你n个灯,刚开始全灭,问经过无穷多次操作后,求第n个灯的状态。

题目分析:

见代码注释。

AC代码:

/**
  *@xiaoran
  *应该是数论问题,先模拟看看(过了),现在来看这道题
  *题意:给你n个灯,刚开始全灭,问经过无穷多次操作后,第n个灯状态
  *对于第i次操作,改变所有i的倍数的状态
  *发现当操作到n+1次之后肯定不会对n有影响,此题变为操作n次之后的n的状态
  *下面分析:刚开始n的状态为0,如果对第n个灯操作了偶数次,其状态还是0,
  *操作奇数次变为1,现在来分析对于n:如果i是n的约数,就会改变n的状态,但是
  *j=n/i也是n的约数,还会把n的状态改变回来,到这里可以发现当i=n/i的时候,才会
  *对n的状态发生影响,刚开始n状态为0,如果n是个完全平方数,则会变为1.
  */
#include<iostream>
#include<cstdio>
#include<map>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<cstdlib>
#include<cctype>
#include<cmath>
#define LL long long
using namespace std;
int a[100005];
int main()
{
    int n;
    while(cin>>n){
        int k=(int) (sqrt(n)+0.5);
        k*k==n?printf("1\n"):printf("0\n");
        /**模拟
        memset(a,1,sizeof(a));
        for(int i=2;i<=n;i++){
            for(int j=i;j<=n;j+=i){
                a[j]=!a[j];
            }
        }
        if(n==1) printf("1\n");
        else printf("%d\n",a[n]);
        **/
    }
	return 0;
}
时间: 2024-08-04 10:09:06

hdu 2051 Switch Game(模拟/数论)的相关文章

hdu 4944 FSF’s game(数论)

题目链接:hdu 4944 FSF's game 题目大意:给定N,可以用不大于N的长a和宽b,组成N?(N?1)2种不同的矩形,对于每个矩形a?b要计算它的值,K为矩形a,b可以拆分成若干个K?K的正方形.∑a?bgcd(a/k,b/k),输出所有矩形值的和. 解题思路:假设有边a和b,那么k肯定即使a的因子也是b的因子.定义f(n)为矩形最长边等于n的情况下所有矩形值的和.那么f(n)=val(1?n)+val(2?n)+?+val(n?n),枚举n的因子作为k,现在假设有因子k,使得n=k

hdu 1175 连连看(模拟循环队列)

连连看 Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 18149    Accepted Submission(s): 4741 Problem Description "连连看"相信很多人都玩过.没玩过也没关系,下面我给大家介绍一下游戏规则:在一个棋盘中,放了很多的棋子.如果某两个相同的棋子,可以通过一条线连起来(这条

HDU 4608 I-number--简单模拟

I-number Time Limit: 5000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 The I-number of x is defined to be an integer y, which satisfied the the conditions below: 1.  y>x; 2.  the sum of each digit of y(under base 10) is the multiple of 10; 3.  among all

hdu 4831 Scenic Popularity(模拟)

题目链接:hdu 4831 Scenic Popularity 题目大意:略. 解题思路:对于休闲区g[i][0]和g[i][1]记录的是最近的两个景点的id(只有一个最近的话g[i][1]为0),对于景点来说,g[i][0]为-1(表示该id对应的是景点),g[i][1]为该景点的热度值.主要就是模拟,注意一些细节就可以了. #include <cstdio> #include <cstring> #include <cstdlib> #include <alg

hdu 2053 Switch Game 水题一枚,鉴定完毕

Switch Game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10200    Accepted Submission(s): 6175 Problem Description There are many lamps in a line. All of them are off at first. A series of op

hdu 4910 Problem about GCD(数论)

题目连接:hdu 4910 Problem about GCD 题目大意:给定M,判断所有小于M并且和M互质的数的积取模M的值. 解题思路:有个数论的结论,若为偶数,M=M/2. 可以写成M=pk,即只有一种质因子时,答案为M-1,否则为1.特殊情况为4的倍数,不包括4. 首先用1e6以内的素数去试除,如果都不可以为p,那么对大于1e6的情况判断一下是否为素数,是素数也可以(k=1),否则开方计算,因为M最大为1e18,不可能包含3个大于1e6的质因子. #include <cstdio> #

hdu 3125 Slash(模拟)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3125 Problem Description The American English slash (/) is a punctuation mark. In the early modern period, in the Fraktur script, which was widespread through Europe in the Middle Ages, one slash(/) repr

hdu 4858 项目管理(vector模拟)

# include <stdio.h> # include <algorithm> # include <string.h> # include <vector> # define N 100005 using namespace std; vector<int>g[N]; int node[N]; int slove(int x) { int sum=0,i; for(i=0;i<g[x].size();i++) { sum+=node[

hdu 4941 STL HASH 模拟

http://acm.hdu.edu.cn/showproblem.php?pid=4941 比赛的时候现学的map的find...以前都是用下标做的,但是map用下标查询的话,如果查询的元素不存在,会插入一个新的元素. 贴一个map查找元素找到和找不到的模板 map<pair<int,int>,int>::iterator it=poshash.find(tmppos);//pair<int,int>poshash; int pp; if(it == poshash.