Balloons

Balloons

Num : 3

Time Limit : 1000ms

Memory Limit : 65536K

description

Both Saya and Kudo like balloons. One day, they heard that in the central park, there will be thousands of people fly balloons to pattern a big image.
They were very interested about this event, and also curious about the image.
Since there are too many balloons, it is very hard for them to compute anything they need. Can you help them?
You can assume that the image is an N*N matrix, while each element can be either balloons or blank.
Suppose element A and element B are both balloons. They are connected if:
i) They are adjacent;
ii) There is a list of element C1, C2, … , Cn, while A and C1 are connected, C1 and C2 are connected …Cn and B are connected.
And a connected block means that every pair of elements in the block is connected, while any element in the block is not connected with any element out of the block.
To Saya, element A(xa,ya)  and B(xb,yb)  is adjacent if |xa-xb|+|ya-yb|<=1 ;
But to Kudo, element A(xa,ya) and element B(xb,yb)  is adjacent if |xa-xb|<=1   and  |ya-yb|<=1;
They want to know that there’s how many connected blocks with there own definition of adjacent?

input

The input consists of several test cases.
The first line of input in each test case contains one integer N (0 < N ≤ 100), which represents the size of the matrix.
Each of the next N lines contains a string whose length is N, represents the elements of the matrix. The string only consists of 0 and 1, while 0 represents a block and 1represents balloons.
The last case is followed by a line containing one zero.

output

For each case, print the case number (1, 2 …) and the connected block’s numbers with Saya and Kudo’s definition. Your output format should imitate the sample output. Print a blank line after each test case.

sample_input

5
11001
00100
11111
11010
10010

0

sample_output

Case 1: 3 2

hint

 

source


代码如下:

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
char data1[102][102];
char data2[102][102];
int f1x[4]={1,-1,0,0};
int f1y[4]={0,0,1,-1};
int f2x[8]={1,1,1,-1,-1,-1,0,0};
int f2y[8]={0,-1,1,0,-1,1,1,-1};
int n;
void find1(int x,int y)
{
    if(x<0||x>n-1||y<0||y>n-1)
    return ;
    if(data1[x][y]=='0')
    return ;
    data1[x][y]='0';
    int xx=0,yy=0;
    for(int m=0;m<4;m++)
    {
        xx=x+f1x[m];
        yy=y+f1y[m];
        find1(xx,yy);
    }
}
void find2(int x,int y)
{
    if(x<0||x>n-1||y<0||y>n-1)
     return ;
    if(data2[x][y]=='0')
    return ;
    data2[x][y]='0';
    int xx=0,yy=0;
    for(int m=0;m<8;m++)
    {
        xx=x+f2x[m];
        yy=y+f2y[m];
        find2(xx,yy);
    }
}
int main()
{
    int k=1;
    while(scanf("%d",&n)!=EOF)
    {
        if(n==0)
        break;
        for(int i=0;i<n;i++)
        {
            scanf("%s",data1[i]);
            strcpy(data2[i],data1[i]);
        }
        int ans1=0,ans2=0;
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                if(data1[i][j]=='1')
                {
                    find1(i,j);
                    ans1++;
                }
            }
        }
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                if(data2[i][j]=='1')
                {
                    find2(i,j);
                    ans2++;
                }
            }
        }
        printf("Case %d: %d %d\n",k,ans1,ans2);
        printf("\n");
        k++;
    }
    //cout << "Hello world!" << endl;
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Based on the given specifications, here is a sample implementation in Java using JavaFX library: ```java import javafx.animation.AnimationTimer; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.image.Image; import javafx.scene.layout.Pane; import javafx.scene.paint.Color; import javafx.scene.shape.Circle; import javafx.stage.Stage; import java.util.Random; public class BalloonGame extends Application { private static final int WINDOW_WIDTH = 500; private static final int WINDOW_HEIGHT = 500; private static final Color BACKGROUND_COLOR = Color.BLACK; private static final int MIN_BALLOON_RADIUS = 20; private static final int MAX_BALLOON_RADIUS = 40; private static final double BALLOON_APPEAR_TIME = 2.0; private static final double INITIAL_SPEED = 1.0; private static final int MAX_Y_VELOCITY = 100; private static final Random RANDOM = new Random(); private Pane gamePane; private double lastBalloonTime = 0.0; private double speed = INITIAL_SPEED; @Override public void start(Stage primaryStage) throws Exception { gamePane = new Pane(); gamePane.setPrefSize(WINDOW_WIDTH, WINDOW_HEIGHT); gamePane.setStyle("-fx-background-color: black;"); AnimationTimer gameLoop = new AnimationTimer() { @Override public void handle(long now) { update(now); } }; gameLoop.start(); Scene scene = new Scene(gamePane, WINDOW_WIDTH, WINDOW_HEIGHT); primaryStage.setScene(scene); primaryStage.show(); } private void update(long now) { double elapsedTime = (now - lastBalloonTime) / 1_000_000_000.0; if (elapsedTime >= BALLOON_APPEAR_TIME / speed) { createBalloon(); lastBalloonTime = now; } for (Circle balloon : gamePane.getChildren()) { double yVelocity = MAX_Y_VELOCITY + speed * 50; double y = balloon.getCenterY() + yVelocity * elapsedTime; balloon.setCenterY(y); if (y - balloon.getRadius() > WINDOW_HEIGHT) { gamePane.getChildren().remove(balloon); } } speed = (now / 1_000_000_000.0) / 10.0 + INITIAL_SPEED; } private void createBalloon() { int radius = RANDOM.nextInt(MAX_BALLOON_RADIUS - MIN_BALLOON_RADIUS + 1) + MIN_BALLOON_RADIUS; double x = RANDOM.nextInt(WINDOW_WIDTH - radius * 2) + radius; double y = -radius; Color color = RANDOM.nextBoolean() ? Color.RED : Color.GREEN; Circle balloon = new Circle(x, y, radius, color); gamePane.getChildren().add(balloon); } public static void main(String[] args) { launch(args); } } ``` This implementation uses JavaFX to create the game window and handle the animation loop. It creates balloons as Circle shapes with random radius, position, and color. The balloons move down the screen with a constant y velocity that increases with the game speed. The game speed is determined by the time since the game started, and affects the time between balloons appearing and the y velocity of the balloons.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值