• <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 閱讀(139) 評(píng)論(0)  編輯 收藏 引用 所屬分類(lèi): Timus題解

            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿

            文章分類(lèi)

            文章檔案

            搜索

            最新評(píng)論

            无码人妻久久一区二区三区免费丨 | 久久免费视频一区| 久久久久亚洲精品中文字幕| 亚洲v国产v天堂a无码久久| 久久精品成人欧美大片| 精品久久久久久久| 欧美激情精品久久久久久| 欧美大香线蕉线伊人久久| 久久亚洲色一区二区三区| 精品久久久无码21p发布| 精品久久久久中文字幕一区| 精品熟女少妇AV免费久久| 四虎国产永久免费久久| 一本色道久久HEZYO无码| 国产精品综合久久第一页| 亚洲综合精品香蕉久久网| 久久无码国产| 91精品国产91久久久久久蜜臀| 久久天天躁狠狠躁夜夜avapp | 亚洲国产小视频精品久久久三级| 色偷偷久久一区二区三区| 香蕉久久影院| 久久国产视频99电影| 超级碰久久免费公开视频| 久久久免费精品re6| 亚洲人成伊人成综合网久久久| 久久久久久av无码免费看大片| 99久久国产免费福利| 国产欧美久久久精品| 国产午夜精品久久久久免费视| 久久人做人爽一区二区三区| 久久九九兔免费精品6| 亚洲国产精品无码久久久久久曰| 国产午夜福利精品久久| 91精品国产色综久久| 久久精品国产99久久香蕉| 国产伊人久久| 婷婷久久综合| 久久精品久久久久观看99水蜜桃| 中文字幕久久亚洲一区| 久久天天躁狠狠躁夜夜不卡|