Created
October 25, 2017 21:16
-
-
Save eliaperantoni/d047c12580c45f191e583321ee7de3e3 to your computer and use it in GitHub Desktop.
Laser brute force
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <assert.h> | |
#include <vector> | |
#include <time.h> | |
#include <cstdlib> | |
#include <iostream> | |
using namespace std; | |
#define MAXM 30 | |
clock_t tStart; | |
// prints number in matrix, -1 for "no node" | |
void print(FILE *fw, int num) { | |
if (num == -1) fprintf(fw, " . "); | |
else fprintf(fw, "%2d ", num); | |
} | |
double getExecutionTime(){ | |
return (double)(clock() - tStart)/CLOCKS_PER_SEC; | |
} | |
int A[MAXM]; | |
int B[MAXM]; | |
int main() { | |
tStart = clock(); | |
FILE *fr, *fw; | |
int H, W, N, M, i, j; | |
fr = fopen("input.txt", "r"); | |
fw = fopen("output.txt", "w"); | |
assert(4 == fscanf(fr, "%d %d %d %d", &H, &W, &N, &M)); | |
int numList[N]; | |
for(int i=0;i<N;i++){ | |
numList[i] = i; | |
} | |
for (i = 0; i < M; i++) | |
assert(2 == fscanf(fr, "%d %d", &A[i], &B[i])); | |
int matrix[H][W]; | |
while(getExecutionTime() < 3.7){ | |
for (i = 0; i < H; i++) { | |
for (j = 0; j < W; j++) { | |
matrix[i][j] = -1; | |
} | |
} | |
for(int i=0;i<N;i++){ | |
while(true){ | |
int x = rand() % H; | |
int y = rand() % W; | |
if(matrix[x][y]==-1){ | |
matrix[x][y]=i; | |
break; | |
} | |
} | |
} | |
} | |
for (i = 0; i < H; i++) { | |
for (j = 0; j < W; j++) | |
print(fw, matrix[i][j]); | |
fprintf(fw, "\n"); | |
} | |
fclose(fr); | |
fclose(fw); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment