青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

ArcTan

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

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 閱讀(215) 評論(0)  編輯 收藏 引用 所屬分類: Topcoder

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            亚洲国产欧美另类丝袜| 亚洲天堂第二页| 欧美日韩精品久久| 欧美日韩国产电影| 国产精品成人免费| 国产一区二区久久精品| 伊人久久大香线蕉综合热线| 亚洲春色另类小说| 亚洲天堂第二页| 久久久久亚洲综合| 最新日韩欧美| 亚洲欧美日韩国产综合| 老司机免费视频久久| 欧美日韩蜜桃| 午夜日韩电影| 久久综合色婷婷| 国产精品久久7| 亚洲激情自拍| 午夜天堂精品久久久久| 美女国产精品| 亚洲一区二区三区四区视频| 欧美一区国产一区| 欧美破处大片在线视频| 国产专区欧美专区| 亚洲一区二区影院| 欧美成人三级在线| 亚洲视频1区2区| 男女激情视频一区| 国产一区二区三区的电影 | 在线观看国产精品淫| 99一区二区| 欧美1区2区| 欧美一区免费| 国产精品久久毛片a| 亚洲精品视频在线观看网站| 欧美一区二区三区视频在线观看| 亚洲成人自拍视频| 久久国产精品免费一区| 欧美先锋影音| 99视频精品全部免费在线| 噜噜噜噜噜久久久久久91| 亚洲男人第一av网站| 欧美日本国产| 亚洲免费观看| 亚洲国产一区二区三区高清| 久久精品亚洲| 精品白丝av| 久久亚洲精品一区二区| 亚洲你懂的在线视频| 国产精品高潮久久| 亚洲欧美另类综合偷拍| 夜夜嗨av一区二区三区四区 | 国产视频精品免费播放| 中文亚洲字幕| 一区二区三区导航| 国产精品久久久久aaaa樱花| 亚洲一区二区三区免费在线观看| 亚洲精品久久久久久久久久久| 久久综合激情| 日韩视频第一页| 一本大道av伊人久久综合| 欧美日韩一区二区三区免费看| 亚洲精品欧美专区| 亚洲日本一区二区| 国产精品xxxxx| 欧美一区二区在线视频| 欧美制服丝袜第一页| 精品不卡一区| 91久久久久久久久| 欧美三级不卡| 国产亚洲欧洲997久久综合| 欧美自拍偷拍| 久久久一区二区三区| 亚洲福利视频专区| 91久久精品网| 国产精品免费观看在线| 久久久www成人免费毛片麻豆| 久久精品成人欧美大片古装| 亚洲成人在线观看视频| 亚洲精品久久久久久一区二区| 欧美日韩成人激情| 香蕉成人伊视频在线观看| 欧美在线影院| 一区二区高清在线观看| 亚洲综合日韩| 亚洲精品视频一区二区三区| 一区二区三区视频在线看| 国产欧美在线| 亚洲三级网站| 狠狠色伊人亚洲综合网站色| 亚洲欧洲另类| 国产亚洲综合在线| 亚洲免费成人av| 尤物在线观看一区| 日韩写真视频在线观看| 黄页网站一区| 一区二区三区三区在线| 亚洲国产mv| 午夜精品久久| 一区二区高清视频| 噜噜噜久久亚洲精品国产品小说| 在线一区二区视频| 久久久久久9999| 欧美一级一区| 欧美日韩精品欧美日韩精品 | 日韩网站在线观看| 久久久www成人免费精品| 宅男精品视频| 米奇777超碰欧美日韩亚洲| 午夜精品视频一区| 欧美另类变人与禽xxxxx| 久久久久久久久综合| 国产精品成人一区二区三区吃奶| 欧美成人精品三级在线观看| 国产欧美大片| 亚洲一级一区| 亚洲欧美第一页| 欧美日本国产精品| 亚洲国产欧美日韩| 亚洲国产精品一区二区久| 欧美在线三级| 久久久噜噜噜久噜久久| 国产精品日日摸夜夜摸av| 亚洲免费观看高清完整版在线观看熊| 黄色成人免费观看| 欧美一区二区在线免费播放| 篠田优中文在线播放第一区| 国产精品扒开腿爽爽爽视频| 亚洲国产视频直播| 亚洲精品国产精品乱码不99按摩 | 1024国产精品| 免费国产自线拍一欧美视频| 国产欧美精品一区二区色综合| 日韩一级二级三级| 一区二区精品在线观看| 蜜桃av一区二区| 欧美激情精品久久久| 亚洲狠狠婷婷| 蜜桃av噜噜一区| 亚洲国产你懂的| 中国成人在线视频| 国产精品国产a| 亚洲午夜精品17c| 午夜精品久久久久久久99黑人| 国产精品劲爆视频| 午夜在线成人av| 欧美.www| 一本久久a久久精品亚洲| 欧美日韩精品一区二区| 日韩一级大片在线| 欧美中文字幕精品| 亚洲二区精品| 欧美日韩成人在线播放| 一区二区三区毛片| 久久精品亚洲精品国产欧美kt∨| 国产真实乱偷精品视频免| 久久久久久久久伊人| 亚洲国产日韩欧美综合久久| 99国内精品| 国产精品视频内| 久久夜色精品一区| 一本色道久久99精品综合| 久久精品国产第一区二区三区| 红桃视频欧美| 欧美日本中文字幕| 欧美一区二区三区在线观看| 欧美r片在线| 欧美一级二区| 亚洲免费观看视频| 国产日韩欧美日韩| 欧美激情一区二区三区在线| 亚洲女与黑人做爰| 亚洲国产日韩欧美在线图片 | 久久精品亚洲精品国产欧美kt∨| 很黄很黄激情成人| 欧美日韩国产欧| 久久国产福利| 一区二区三区精品国产| 欧美凹凸一区二区三区视频| 亚洲永久精品大片| 亚洲人久久久| 黄色工厂这里只有精品| 欧美三级网址| 免费不卡亚洲欧美| 亚洲欧美在线免费观看| 日韩亚洲欧美一区二区三区| 免费在线视频一区| 久久国产福利国产秒拍| 日韩一区二区精品在线观看| 国内精品久久久久影院色| 国产精品高精视频免费| 欧美精品久久久久久| 久久久水蜜桃| 欧美一区二区三区免费在线看| 日韩一区二区精品视频| 欧美激情aaaa| 欧美电影电视剧在线观看| 久久精品国产v日韩v亚洲| 亚洲欧美电影在线观看| 中文精品视频一区二区在线观看|