• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            ACM___________________________

            ______________白白の屋
            posts - 182, comments - 102, trackbacks - 0, articles - 0
            <2010年10月>
            262728293012
            3456789
            10111213141516
            17181920212223
            24252627282930
            31123456

            常用鏈接

            留言簿(24)

            隨筆分類(lèi)(332)

            隨筆檔案(182)

            FRIENDS

            搜索

            積分與排名

            最新隨筆

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            HDOJ HDU 2053 Switch Game ACM 2053 IN HDU

            Posted on 2010-08-07 15:20 MiYu 閱讀(670) 評(píng)論(0)  編輯 收藏 引用 所屬分類(lèi): ACM ( 模擬 )ACM ( 水題 )
            MiYu原創(chuàng), 轉(zhuǎn)帖請(qǐng)注明 : 轉(zhuǎn)載自 ______________白白の屋

            題目地址:
                     http://acm.hdu.edu.cn/showproblem.php?pid=2053
            題目描述:
            Problem Description
            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 ).
             

            Input
            Each test 
            case contains only a number n ( 0< n<= 10^5in a line.
             

            Output
            Output the condition of the n
            -th lamp after infinity operations ( 0 - off, 1 - on ).
             

            Sample Input
            1
            5
             

            Sample Output
            1
            0

            Hint
            hint
             

            Consider the second test 
            case:

            The initial condition       : 
            0 0 0 0 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 …

            The later operations cannot change the condition of the fifth lamp any more. So the answer 
            is 0.

            題目分析:
            毫無(wú)疑問(wèn) , 從后面的 Consider the second test case 可以看出, 這是一道模擬題, 根據(jù)題意直接模擬即可!

            代碼如下:
            MiYu原創(chuàng), 轉(zhuǎn)帖請(qǐng)注明 : 轉(zhuǎn)載自 ______________白白の屋

            #include 
            <iostream>
            #include 
            <string.h>
            using namespace std;
             
            int arr[100001];
             
            int main()
            {
                
            int n;
                
            while(scanf("%d"&n) != EOF)
                {
                    memset(arr, 
            0sizeof(arr));
                    
            for(int i=1; i<=n; ++i)
                        
            for(int j=1; j<=n&&j*i<=n; ++j)
                            arr[j
            *i] = !arr[j*i];
                    printf(
            "%d\n", arr[n]);
                }
                
            return 0;
            }

            但是這樣非常耗時(shí),  有沒(méi)更簡(jiǎn)單的方法? 當(dāng)然有!  在草稿紙上模擬后得出: 只要是平方數(shù)就是 "1" ,否則為"0" , 所以
            直接哈希,0MS過(guò).

            代碼如下:
            MiYu原創(chuàng), 轉(zhuǎn)帖請(qǐng)注明 : 轉(zhuǎn)載自 ______________白白の屋

            #include 
            <iostream>
            using namespace std;
            int F[100001= { 11 };
            int main ()
            {
                
            for ( int i = 2; i * i <= 100000 ; ++ i )
                {
                      F[ i 
            * i ] = 1;
                }
                
            int N;
                
            while ( cin >> N )
                {
                      puts ( F[N] 
            ? "1" : "0" ); 
                }
                
            return 0
            }
            97久久超碰国产精品2021| 久久99精品久久久久久噜噜| 亚洲精品无码久久久久sm| 久久婷婷五月综合97色一本一本 | 97久久综合精品久久久综合| 亚洲一本综合久久| 人妻无码αv中文字幕久久琪琪布| 国产成人无码久久久精品一| 亚洲精品美女久久久久99小说| 久久99国产综合精品女同| 国产叼嘿久久精品久久| 久久精品国产精品国产精品污| 久久亚洲春色中文字幕久久久| 国产精品日韩欧美久久综合| 蜜臀av性久久久久蜜臀aⅴ麻豆| 狠狠久久综合伊人不卡| 99国产欧美精品久久久蜜芽| 欧美与黑人午夜性猛交久久久| 国产精品伦理久久久久久| 久久综合给合久久国产免费| 久久久久国产| 99久久国产热无码精品免费 | 国产精品欧美久久久天天影视| 久久综合九色综合欧美就去吻 | 久久久黄色大片| 欧洲国产伦久久久久久久| 一本色道久久88加勒比—综合| 久久精品无码一区二区无码| 九九久久99综合一区二区| 久久精品国产99国产精品亚洲| 亚洲女久久久噜噜噜熟女| 亚洲人成网站999久久久综合| 精品久久人人妻人人做精品| 老司机国内精品久久久久| 久久久久国产一级毛片高清板| 久久综合狠狠综合久久激情 | 久久精品视频网| 精品人妻伦一二三区久久| 久久久久18| 国产精品久久新婚兰兰| 国产精品久久久久久一区二区三区|