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

            導航

            統計

            常用鏈接

            留言簿

            文章分類

            文章檔案

            搜索

            最新評論

            精产国品久久一二三产区区别| 久久久精品国产sm调教网站| 99久久国产热无码精品免费久久久久 | 久久久无码精品午夜| 久久久久无码国产精品不卡| 欧美激情精品久久久久久| 无码人妻久久一区二区三区免费丨 | 亚洲国产精品婷婷久久| 香蕉久久永久视频| 国产午夜精品久久久久免费视| 久久99精品九九九久久婷婷| 中文字幕亚洲综合久久菠萝蜜| 久久久久久午夜成人影院 | 亚洲精品tv久久久久久久久久| 色综合久久久久无码专区| 精品人妻伦九区久久AAA片69| 狠狠精品久久久无码中文字幕| 色综合久久综合网观看| 久久精品国产男包| 国产成人精品久久一区二区三区av| 国产偷久久久精品专区| 久久国产成人午夜AV影院| 国内精品九九久久久精品| 久久久久99这里有精品10| 国产精品xxxx国产喷水亚洲国产精品无码久久一区| 久久亚洲中文字幕精品一区| 亚洲国产精品久久| 国产日产久久高清欧美一区| 国产色综合久久无码有码| 偷窥少妇久久久久久久久| 久久综合精品国产一区二区三区| 久久国产一区二区| 97久久超碰国产精品旧版| 久久久久亚洲AV无码永不| 久久精品www人人爽人人| 日韩久久久久久中文人妻| 婷婷综合久久中文字幕蜜桃三电影| 久久天天躁狠狠躁夜夜2020老熟妇| 国产精品VIDEOSSEX久久发布| 91精品婷婷国产综合久久| 91久久国产视频|