Commit 32bc68e1 authored by royus's avatar royus

fix

parent 255f6279
File added
/* io.c */ /* io.c */
/* Last Change: 2019/05/21 (Tue) 13:57:18. */ /* Last Change: 2019/05/25 (Sat) 18:11:46. */
#include<stdio.h> #include<stdio.h>
#include<limits.h>
#include"io.h" #include"io.h"
short int W=MAXW, H=MAXH; // (問題で設定された) 盤面サイズ上限 short int W=MAXW, H=MAXH; // (問題で設定された) 盤面サイズ上限
...@@ -17,8 +16,8 @@ void reset_parameters(void){ ...@@ -17,8 +16,8 @@ void reset_parameters(void){
for(j=0;j<5;j++) for(j=0;j<5;j++)
for(k=0;k<3;k++) for(k=0;k<3;k++)
block_data[i][j][k]=-1; block_data[i][j][k]=-1;
for(i=0;i<72;i++) for(i=0;i<MAXW;i++)
for(j=0;j<72;j++) for(j=0;j<MAXH;j++)
board_data[i][j]=0; board_data[i][j]=0;
return; return;
} }
...@@ -31,11 +30,11 @@ void read_problem(void){ ...@@ -31,11 +30,11 @@ void read_problem(void){
char c,str[32]; // must be 20 or more char c,str[32]; // must be 20 or more
scanf(" %s",str); //SIZE scanf(" %s",str); //SIZE
scanf(" %hd",&W); scanf(" %hd",&W);
if(W>72||W<=0) if(W>MAXW||W<=0)
printf("Error: width\n"); printf("Error: width\n");
scanf(" %c",&c); //X scanf(" %c",&c); //X
scanf(" %hd",&H); scanf(" %hd",&H);
if(H>72||H<=0) if(H>MAXH||H<=0)
printf("Error: height\n"); printf("Error: height\n");
scanf(" %s",str); //BLOCK_NUM scanf(" %s",str); //BLOCK_NUM
scanf(" %hd",&blocks); scanf(" %hd",&blocks);
...@@ -92,19 +91,6 @@ void read_problem(void){ ...@@ -92,19 +91,6 @@ void read_problem(void){
return; return;
} }
void convert_answer(void){
int i,j;
for(i=0;i<w;i++){
for(j=0;j<h;j++){
if(board_data[i][j]==SHRT_MIN)
board_data[i][j]=0;
else if(board_data[i][j]<0)
board_data[i][j]=-board_data[i][j];
}
}
return;
}
void print_answer(void){ void print_answer(void){
printf("\n --ANSWER-- \n"); //comment out this row printf("\n --ANSWER-- \n"); //comment out this row
int i,j; int i,j;
......
/* io.h */ /* io.h */
/* Last Change: 2019/05/21 (Tue) 14:01:43. */ /* Last Change: 2019/05/21 (Tue) 14:56:05. */
#ifndef _IO_H_ #ifndef _IO_H_
#define _IO_H_ #define _IO_H_
...@@ -24,19 +24,15 @@ short int block_data[MAXBLOCK+1][5][3]; // ブロックの情報 ...@@ -24,19 +24,15 @@ short int block_data[MAXBLOCK+1][5][3]; // ブロックの情報
// block_data[block#][1~4][1] マスの,左上マスからの相対位置 y方向 // block_data[block#][1~4][1] マスの,左上マスからの相対位置 y方向
// block_data[block#][1~4][2] マスの端点情報 (数字がなければ0,モノミノで存在しない場合は-1) // block_data[block#][1~4][2] マスの端点情報 (数字がなければ0,モノミノで存在しない場合は-1)
short int board_data[72][72]; // 盤面情報 short int board_data[MAXW][MAXH]; // 盤面情報
// board_data[x][y] が (x,y) の盤面情報を表わす // board_data[x][y] が (x,y) の盤面情報を表わす
// (0,0),(1,0),(2,0), ... ,(71,0) // (0,0),(1,0),(2,0), ... ,(71,0)
// ... // ...
// (0,71),(1,71), ... ,(71,71) // (0,71),(1,71), ... ,(71,71)
// 基本的には回答フォーマットに沿う形 // 基本的には回答フォーマットに沿う形
// 負の数はconvert_answerでSHRT_MIN->0,その他は自然数に変換される
// (アルゴリズム的に必要であれば使ってください)
// (私は壁(端点ではないマス)をSHRT_MINで,配線を負の数で実装してます)
void reset_parameters(void); // read_problem に内包 void reset_parameters(void); // read_problem に内包
void read_problem(void); void read_problem(void);
void convert_answer(void);
void print_answer(void); void print_answer(void);
#endif // _IO_H_ #endif // _IO_H_
/* main.c */ /* main.c */
/* Last Change: 2019/05/21 (Tue) 14:03:16. */ /* Last Change: 2019/05/21 (Tue) 14:44:03. */
#include"io.h" #include"io.h"
#include"solver.h"
int main(void){ int main(void){
read_problem(); read_problem();
// solver(); solver();
convert_answer();
print_answer(); print_answer();
return 0; return 0;
......
/* solver.c */ /* solver.c */
/* Last Change: 2019/05/21 (Tue) 14:03:02. */ /* Last Change: 2019/05/21 (Tue) 18:09:17. */
#include<stdio.h> #include<limits.h>
#include"solver.h"
#include"io.h"
/* #include<stdio.h> */
/* #include<stdlib.h> */ /* #include<stdlib.h> */
/* #include<string.h> */ /* #include<string.h> */
/* #include<limits.h> */
/* #include<math.h> */ /* #include<math.h> */
/* #include<time.h> */ /* #include<time.h> */
short int connected[MAXLINE]={0}; //if line connected:2, if one end:1, otherwize:0
short int board_beta[MAXSIZE][MAXSIZE]; //big board data
//edge:1~MAXLINE, line:-1~-MAXLINE, none:0, wall:SHRT_MIN
short int rank[MAXBLOCK+1];
void reset_board(void){
int i,j;
for(i=0;i<MAXSIZE;i++)
for(j=0;j<MAXSIZE;j++)
board_beta[i][j]=0;
return;
}
void read_data(void){
return;
}
void translate(void){
int i,j;
int minw=MAXSIZE-1,maxw=0,minh=MAXSIZE-1,maxh=0;
for(i=0;i<MAXSIZE;i++){
for(j=0;j<MAXSIZE;j++){
if(board_beta[i][j]){
if(i>maxw)
maxw=i;
if(i<minw)
minw=i;
if(j>maxh)
maxh=j;
if(j<minh)
minh=j;
if(board_beta[i][j]==SHRT_MIN)
board_beta[i][j]=0;
else if(board_beta[i][j]<0)
board_beta[i][j]=-board_beta[i][j];
}
}
}
for(i=1;i<=blocks;i++){
/* block_data[i][0]-=minw; */
/* block_data[i][1]-=minh; */
}
for(i=0;i<maxw-minw;i++){
for(j=0;j<maxh-minh;j++){
board_data[i][j]=board_beta[i+minw][j+minh];
}
}
return;
}
void solve(void){
return;
}
void solver(void){ void solver(void){
read_data();
solve();
/* shape(); */
translate();
return; return;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment