• <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>

            Timus 1087(recursion game)

            1087. The Time to Take Stones

            Time Limit: 1.0 second
            Memory Limit: 16 MB
            You probably know the game where two players in turns take 1 to 3 stones from a pile. Looses the one who takes the last stone. We'll generalize this well known game. Assume that both of the players can take not 1, 2 or 3 stones, but k1, k2, …, km ones. Again we'll be interested in one question: who wins in the perfect game. It is guaranteed that it is possible to make next move irrespective to already made moves.

            Input

            The first line contains two integers: n and m (1 ≤ n ≤ 10000; 1 ≤ m ≤ 50) — they are an initial amount of stones in the pile and an amount of numbers k1, …, km. The second line consists of the numbers k1, …, km, separated with a space (1 ≤ kin).

            Output

            Output 1, if the first player (the first to take stones) wins in a perfect game. Otherwise, output 2.

            Sample

            input output
            17 3
                        1 3 4
                        
            2
                        
            Problem Author: Anton Botov
            Problem Source: The 3rd high school children programming contest, USU, Yekaterinburg, Russia, March 4, 2001



            /*
            "Looses the one who takes the last stone" —— the one takes the last 
            stone loses the game ! 
            */ 
            #include 
            <stdio.h>
            #include 
            <memory>
            #include 
            <iostream>
            #include 
            <algorithm>
            #include 
            <cstring>
            #include 
            <vector>
            #include 
            <map>
            #include 
            <cmath>
            #include 
            <set>
            #include 
            <queue>
            #include 
            <time.h> 
            #include 
            <limits>
            using namespace std; 
            #define N 10005
            #define M 55
            int step[M], n, m; 
            bool state[N]; 
            bool input(){
                
            if(scanf("%d%d"&n, &m) == EOF) return false
                
            int i; 
                
            for(i = 0; i < m; i++) scanf("%d", step+i);
                
            return true
            }
            void solve(){
                memset(state, 
            0sizeof(bool* (n+1)); 
                
            int i, j, u; 
                
            for(i = 1; i <= n; i++){
                    
            for(j = 0; j < m; j++){
                        
            if((u = i - step[j]) >= 0){
                            
            if(u == 0){
                                state[i] 
            = false
                            }
            else{
                                
            if(!state[u]){
                                    state[i] 
            = true
                                    
            break
                                }
                            }
                        }
                    }
                }
                
            //for(i = 0; i <= n; i++) printf("s[%d]=%d\n", i, state[i]);
                if(state[n]) printf("1\n");
                
            else printf("2\n");
            }
            int main(){
            #ifndef ONLINE_JUDGE
                freopen(
            "in.txt""r", stdin); 
                
            //freopen("out.txt", "w", stdout); 
            #endif 
                
            while(input()) solve(); 
                
            return 0;
            }

            posted on 2011-01-18 15:23 tw 閱讀(137) 評論(0)  編輯 收藏 引用 所屬分類: Timus題解

            <2025年6月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            293012345

            導航

            統計

            常用鏈接

            留言簿

            文章分類

            文章檔案

            搜索

            最新評論

            亚洲午夜精品久久久久久浪潮| 成人资源影音先锋久久资源网| 国产成人精品久久| 亚洲精品无码久久久| 亚洲愉拍99热成人精品热久久| 久久狠狠爱亚洲综合影院| 久久天堂AV综合合色蜜桃网 | 伊人久久综合无码成人网| 一本一道久久综合狠狠老| 成人久久久观看免费毛片| 久久国产精品无| 精品久久久久久久无码| 尹人香蕉久久99天天拍| 国产成人久久AV免费| 久久久久久综合网天天| 99久久国产综合精品五月天喷水 | 久久亚洲国产精品一区二区| 怡红院日本一道日本久久| 欧美久久久久久午夜精品| 久久婷婷国产综合精品| 日本五月天婷久久网站| 国产精品久久久久久久午夜片| 久久亚洲精品国产精品| 综合久久一区二区三区 | 久久精品欧美日韩精品| 开心久久婷婷综合中文字幕| 亚洲精品国产成人99久久| 久久久久久国产精品无码超碰| 伊人久久大香线蕉综合热线| 精品久久久久久国产牛牛app| .精品久久久麻豆国产精品| yy6080久久| 国产成人精品三上悠亚久久| 久久99精品国产麻豆蜜芽| 久久精品国产半推半就| 国产91色综合久久免费| 国产精品久久久久久| 国产一久久香蕉国产线看观看| 国产精品久久久久影视不卡| 精品久久久久久久无码| 久久亚洲精品中文字幕三区|