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

            ArcTan

            dfs
            隨筆 - 16, 文章 - 117, 評論 - 6, 引用 - 0
            數據加載中……

            SRM 150 DIV 2 1000pt(模擬)

            Problem Statement

                

            You are given a rectangular map in which each space is marked with one of three characters: '.' (open), 'B' (a brick), or '#' (an indestructible block). Walls made of indestructible blocks surround the field on all sides, but are not shown on the map. A ball is bouncing around this map, destroying bricks, and your task is determine how long it takes the ball to destroy all the bricks.

            The top left space of the map is always open, and this is where the ball begins. More specifically, the ball begins at time 0 in the middle of the top edge of this space (see the diagram in Example 0). The ball is traveling diagonally down and to the right at a speed of half a meter per second vertically, and half a meter per second horizontally. Each space is 1 meter square, so the ball crosses half a space vertically and half a space horizontally each second.

            Whenever the ball strikes the edge of an obstacle--either a brick or an indestructible block--it bounces off at an angle perpendicular to its incoming path. The ball will never hit two obstacles simultaneously. Whenever the ball bounces off a brick, the brick is destroyed and removed from the map.

            Your method should return the time at which the last brick is destroyed. If one or more bricks will never be destroyed, return -1.

            Definition

                
            Class: BrickByBrick
            Method: timeToClear
            Parameters: vector <string>
            Returns: int
            Method signature: int timeToClear(vector <string> map)
            (be sure your method is public)
                

            Constraints

            - map contains between 1 and 15 elements, inclusive.
            - All elements of map contain the same number of characters (between 1 and 15, inclusive).
            - All elements of map contain only the characters '.', 'B', and '#'.
            - The top left corner of map (that is, the first character of the first element) is '.'.
            - map contains at least one 'B'.

            Examples

            0)
                
            { ".B",   "BB" }
            Returns: 6
            The following diagram illustrates the path of the ball.
                 __0________     | / \ |     |     |/   \|     |     3  .  1  B  |     |\   /|\    |     | \ / | \   |     |--2--|--6--|     |     |     |     |     |     |     |  B  |  B  |     |     |     |     |_____|_____|
            The ball begins at point 0, traveling down and to the right. It bounces off the first brick at time 1, and off the second brick at time 2. At time 3, it bounces off the left wall, and at time 4 it bounces off the upper wall at the same place it started. At time 6, the ball destroys the third and final brick, so the method returns 6.
            1)
                
            { ".BB",   "BBB",   "BBB" }
            Returns: -1
            The ball will never hit the brick in the bottom right corner.
            2)
                
            { "......B",   "###.###",   "B.....B" }
            Returns: 35

            3)
                
            { "..BBB...",   ".#BB..#.",   "B.#B.B..",   "B.B.....",   "##.B.B#.",   "#BB.#.B.",   "B..B.BB.",   "#..BB..B",   ".B....#." }
            Returns: -1

            4)
                
            { ".BB..BBB.B...",   "B.B...B..BB..",   "#B...B#B.....",   "B#B.B##...##B",   "BB.B#.B##B.B#",   "B.B#.BBB.BB#B",   "B#BBB##.#B#B.",   "B#BB.BBB#BB.#" }
            Returns: 3912

            5)
                
            { ".BBBBBBBBBBBBBB",   "##############B",   "BBBBBBBBBBBBBBB",   "B##############",   "BBBBBBBBBBBBBBB",   "##############B",   "BBBBBBBBBBBBBBB",   "B##############",   "BBBBBBBBBBBBBBB",   "##############B",   "BBBBBBBBBBBBBBB",   "B##############",   "BBBBBBBBBBBBBBB",   "##############B",   "BBBBBBBBBBBBBBB" }
            Returns: 31753

            This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.




            題意:就像是那個啥游戲,看了那個圖就挺好理解的了。
                     注意方向變換。
             
            寫了好久好久啊,
            404PT:
            #include<stdio.h>
            #include
            <fstream>
            #include
            <string>
            #include
            <vector>
            #include
            <algorithm>
            using namespace std;

            class BrickByBrick
            {
            public:
                
            int timeToClear(vector <string> map)
                {
                    
            int time=0;
                    
            int bricks=0;
                    
            int impactTime=0;

                    
            float x,y,dirX,dirY,newX,newY;

                    
            for (int i=0; i<map.size(); i++)
                    {
                        map[i].insert(
            0,sizeof(char),'#');
                        map[i].push_back(
            '#');
                    }

                    
            string s;
                    
            for (int i=0; i<map[0].length(); i++)
                        s.push_back(
            '#');

                    map.insert(map.begin(),s);
                    map.push_back(s);


                    
            for (int i=0; i<map.size(); i++)
                        bricks
            +=count(map[i].begin(),map[i].end(),'B');

                    x
            =1.5;
                    y
            =1;
                    dirX
            =dirY=0.5;

                    
            while (bricks && impactTime <1000)
                    {
                        impactTime
            ++;
                        x
            +=dirX;
                        y
            +=dirY;

                        
            if (dirX==0.5 && dirY==0.5)
                        {
                            
            if ((int)x==x)
                            {
                                newX
            =(int)x;
                                newY
            =(int)y;
                            }
                            
            else if ((int)y==y)
                            {
                                newX
            =(int)x;
                                newY
            =(int)y;
                            }
                        }
                        
            if (dirX==-0.5 && dirY==-0.5)
                        {
                            
            if ((int)x==x)
                            {
                                newX
            =(int)x-1;
                                newY
            =(int)y;
                            }
                            
            else if ((int)y==y)
                            {
                                newX
            =(int)x;
                                newY
            =(int)y-1;
                            }
                        }
                        
            if (dirX==-0.5 && dirY==0.5)
                        {
                            
            if ((int)x==x)
                            {
                                newX
            =(int)x-1;
                                newY
            =(int)y;
                            }
                            
            else if ((int)y==y)
                            {
                                newX
            =(int)x;
                                newY
            =(int)y;
                            }
                        }
                        
            if (dirX==0.5 && dirY==-0.5)
                        {
                            
            if ((int)x==x)
                            {
                                newX
            =(int)x;
                                newY
            =(int)y;
                            }
                            
            else if ((int)y==y)
                            {
                                newX
            =(int)x;
                                newY
            =(int)y-1;
                            }
                        }
                        
            if (map[newY][newX]!='.')
                        {
                            
            if ((int)x==x)
                            {
                                
            if (dirX==0.5 && dirY==0.5)
                                {
                                    dirX
            =-0.5;
                                    dirY
            =0.5;
                                }
                                
            else if (dirX==-0.5 && dirY==-0.5)
                                {
                                    dirX
            =0.5;
                                    dirY
            =-0.5;
                                }
                                
            else if (dirX==-0.5 && dirY==0.5)
                                {
                                    dirX
            =0.5;
                                    dirY
            =0.5;
                                }
                                
            else if (dirX==0.5 && dirY==-0.5)
                                {
                                    dirX
            =-0.5;
                                    dirY
            =-0.5;
                                }
                            }
                            
            if ((int)y==y)
                            {
                                
            if (dirX==0.5 && dirY==0.5)
                                {
                                    dirX
            =0.5;
                                    dirY
            =-0.5;
                                }
                                
            else if (dirX==0.5 && dirY==-0.5)
                                {
                                    dirX
            =0.5;
                                    dirY
            =0.5;
                                }
                                
            else if (dirX==-0.5 && dirY==0.5)
                                {
                                    dirX
            =-0.5;
                                    dirY
            =-0.5;
                                }
                                
            else if (dirX==-0.5 && dirY==-0.5)
                                {
                                    dirX
            =-0.5;
                                    dirY
            =0.5;
                                }
                            }
                        }
                        
            if (map[newY][newX]=='B')
                        {
                            map[newY][newX]
            ='.';
                            time
            +=impactTime;
                            impactTime
            =0;
                            bricks
            --;
                        }
                    }
                    
            if (impactTime==1000)
                        
            return -1;
                    
            return time;
                }
            };


             

            posted on 2012-07-15 22:01 wangs 閱讀(207) 評論(0)  編輯 收藏 引用 所屬分類: Topcoder

            久久99国产综合精品| 99国内精品久久久久久久| 久久天天躁狠狠躁夜夜躁2014| 一级a性色生活片久久无 | 嫩草影院久久国产精品| 99久久婷婷国产一区二区| 久久婷婷国产剧情内射白浆| 成人久久精品一区二区三区 | 无码AV波多野结衣久久| 久久天天躁狠狠躁夜夜96流白浆| 美女写真久久影院| 国内高清久久久久久| 久久高潮一级毛片免费| 久久棈精品久久久久久噜噜| 久久久久亚洲AV无码专区桃色| 人妻丰满AV无码久久不卡| 久久久久亚洲精品天堂久久久久久| 久久亚洲中文字幕精品有坂深雪| 久久久国产精品| 日韩美女18网站久久精品| 日日噜噜夜夜狠狠久久丁香五月| 99久久国产热无码精品免费久久久久| 久久久久无码精品国产| 亚洲国产成人乱码精品女人久久久不卡 | 热久久视久久精品18| 99久久亚洲综合精品网站| 99久久成人国产精品免费| 亚洲精品午夜国产VA久久成人| 亚洲一区精品伊人久久伊人| 狠狠综合久久综合中文88| 久久国产成人精品麻豆| 狠狠久久亚洲欧美专区| 国产精品青草久久久久婷婷| 久久久亚洲欧洲日产国码aⅴ| 久久精品国产亚洲av麻豆图片| 美女久久久久久| 日批日出水久久亚洲精品tv| 国产高清美女一级a毛片久久w| 精品国产一区二区三区久久| 99国产精品久久久久久久成人热| 国产人久久人人人人爽|