第二十八天(1):熄灯问题 + 讨厌的青蛙

T1

//
//  main.cpp
//  LightOut
//
//  Created by Apple on 2019/9/4.
//  Copyright © 2019 Apple_Lance. All rights reserved.
//

#include <iostream>
#include <stdio.h>

int puzzle[6][8];
int press[6][8];

bool guess(){
    for(int i = 2;i < 6;i++)
        for(int j = 1;j < 7;j++)
            press[i][j] = (puzzle[i-1][j] + press[i-1][j] + press[i-1][j-1] + press[i-1][j+1] + press[i-2][j]) % 2;
    for(int c = 1;c < 7;c++)
        if(puzzle[5][c] != (press[5][c] + press[5][c-1] + press[5][c+1] + press[4][c]) % 2)
            return false;
    return true;
}

void enumenate(){
    for(int c = 0;c < 7;c++)
        press[1][c] = 0;
    while(!guess()){
        int c = 1;
        press[1][1]++;
        while(press[1][c] > 1){
            press[1][c++] = 0;
            press[1][c]++;
        }
        
    }
}
int main(int argc, const char * argv[]) {
    int T;
    scanf("%d", &T);
    for(int i = 0;i < 6;i++)
        press[i][0] = press[i][7] = 0;
    for(int j = 0;j < 7;j++)
        press[0][j] = 0;
    for(int t = 0;t < T;t++){
        for(int i = 1;i < 6;i++)
            for(int j = 1;j < 7;j++)
                scanf("%d", &puzzle[i][j]);
        enumenate();
        printf("PUZZLE #%d", t+1);
        for(int i = 1;i < 6;i++){
            for(int j = 1;j < 7;j++)
                printf("%d ", press[i][j]);
            printf("\n");
        }
    }
            
    
    return 0;
}

T3

讨厌的青蛙

//
//  main.cpp
//  HateFrag
//
//  Created by Apple on 2019/9/4.
//  Copyright © 2019 Apple_Lance. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;

int r, c, n;

struct PLANT{
    int x, y;
};

PLANT plants[5001];
PLANT plant;

int searchPath(PLANT secPlant, int dx, int dy){
    PLANT plant;
    int steps;
    plant.x = secPlant.x + dx;
    plant.y = secPlant.y + dy;
    steps = 2;
    while(plant.x >= 1 && plant.x <= r && plant.y >= 1 &&plant.y <= c){
        if(!binary_search(plants, plants + n, plant)){
            steps = 0;
            break;
        }
        steps++;
        plant.x += dx;
        plant.y += dy;
    }
    return steps;
}

bool operator<(PLANT a, PLANT b){
    if(a.x == b.x)
        return a.y < b.y;
    return a.x < b.x;
}

int main(int argc, const char * argv[]) {
    scanf("%d%d", &r, &c);
    scanf("%d", &n);
    for(int i = 0;i < n;i++)
        scanf("%d%d", plants[i].x, plants[i].y);
    sort(plants, plants + n);
    int dx, dy, px, py, steps, max = 2;
    for(int i = 0;i < n - 1;i++){
        for(int j = i + 1;j < n;j++){
            dx = plants[i].x - plants[j].x;
            dy = plants[i].y - plants[j].y;
            px = plants[i].x - dx;
            py = plants[i].y - dy;
            if(px <= r && px >= 0 && py <= c && py >= 0)
                continue;
            if(plants[i].x + (max - 1) * dx > r)
                break;
            py = plants[i].y + (max - 1) * dy;
            if(py > c || py < 1)
                continue;
            steps = searchPath(plants[j], dx, dy);
            if(steps > max) max = steps;
            if(max == 2)
                max = 0;
            printf("%d\n", max);
            
        }
    }
    
    
    return 0;
}

发布了182 篇原创文章 · 获赞 101 · 访问量 20万+

猜你喜欢

转载自blog.csdn.net/lancecrazy/article/details/100535810