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

            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿

            文章分類(lèi)

            文章檔案

            搜索

            最新評(píng)論

            国产精品久久久久久久久鸭| 怡红院日本一道日本久久| 久久久久免费视频| 日韩人妻无码一区二区三区久久99| 亚洲国产精品久久久久网站| 亚洲狠狠久久综合一区77777 | 免费精品国产日韩热久久| 青青久久精品国产免费看| 久久夜色精品国产噜噜亚洲a | 99久久人妻无码精品系列蜜桃| 久久久久久综合一区中文字幕 | 亚洲欧美精品一区久久中文字幕 | 久久久久综合国产欧美一区二区| 欧洲国产伦久久久久久久| 久久亚洲精品国产亚洲老地址| 伊人久久久AV老熟妇色| 欧美伊香蕉久久综合类网站| 亚洲国产欧洲综合997久久| 国产精品久久精品| 麻豆一区二区99久久久久| 精品熟女少妇aⅴ免费久久| 国产91色综合久久免费分享| 亚洲国产精品无码久久一区二区| 久久精品亚洲男人的天堂| 996久久国产精品线观看| 美女久久久久久| 18岁日韩内射颜射午夜久久成人| 精品一区二区久久| 午夜久久久久久禁播电影| 2021久久精品免费观看| 欧美国产成人久久精品| 欧美精品一区二区久久| 品成人欧美大片久久国产欧美...| 国产成人精品久久二区二区 | www亚洲欲色成人久久精品| 精品久久久久久久国产潘金莲| 久久久久久久91精品免费观看| 久久精品国产精品亚洲人人 | 成人久久久观看免费毛片| 久久精品无码专区免费东京热| 中文字幕无码免费久久|