50012. Block Mover with Bit Operations

難度:5/5

王八蛋題目。

version 1 (TLE)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
#define ull unsigned long long int

void printBlock(ull *block) {
for(int i = 0; i < 8; i++){
for(int j = 0; j < 8; j++){
printf("%llu", (*block) >> (i * 8 + j) & 1);
}
puts("");
}
}

void initialize(ull *block, int row, int column, int size) {
*block = (ull)0;

for(int i = row; i < (row + size); i++){
for(int j = column; j < (column + size); j++){
(*block) |= (ull)1 << (i * 8 + j);
}
}
}

int moveLeft(ull *block) {
if((*block) & (ull)0x0101010101010101) return 0;
else{
(*block) >>= 1;
return 1;
}
}

int moveRight(ull *block) {
if((*block) & (ull)0x8080808080808080) return 0;
else{
(*block) <<= 1;
return 1;
}

}

int moveUp(ull *block) {
if((*block) & (ull)0x00000000000000FF) return 0;
else{
(*block) >>= 8;
return 1;
}

}

int moveDown(ull *block) {
if((*block) & (ull)0xFF00000000000000) return 0;
else{
(*block) <<= 8;
return 1;
}
}

Verson 60 (AC code modified from Morris.)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <stdio.h>
#define ull unsigned long long int
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
// #define get_bit(x, y) (((x)<<3)|(y))

void printBlock(ull *block) {
for(int i = 0; i < 8; i++){
for(int j = 0; j < 8; j++){
printf("%llu", (*block) >> (i * 8 + j) & 1);
}
puts("");
}
}

void initialize(ull *block, int row, int column, int size) {
ull dummy = (1LLU << size) - 1, square = 0;
for (int i = 0; i < size; i++){
square |= dummy;
dummy <<= 8;
}

*block = square << (row * 8 + column);
}

int moveLeft(ull *block) {
if((*block) & (ull)0x0101010101010101) return 0;
else{
(*block) >>= 1;
return 1;
}
}

int moveRight(ull *block) {
if((*block) & (ull)0x8080808080808080) return 0;
else{
(*block) <<= 1;
return 1;
}

}

int moveUp(ull *block) {
if((*block) & (ull)0x00000000000000FF) return 0;
else{
(*block) >>= 8;
return 1;
}

}

int moveDown(ull *block) {
if((*block) & (ull)0xFF00000000000000) return 0;
else{
(*block) <<= 8;
return 1;
}
}

50012. Block Mover with Bit Operations
https://aaronlin1229.github.io/judgegirl_50012/
Author
Akizumi
Posted on
July 17, 2023
Licensed under