// CODEIT 2018 // ~ marathon 3 ~ // by: Nikola Maximov #include #include #include #include #include #include #include #include #define endl "\n" using namespace std; ifstream fin("drawing.in"); ofstream fout("drawing.out"); bool done=false; //double timer; const int n=300; const double INF=1000000.0; int C; struct commandInfo { short type, c1, c2, c3, c4; }; vector output; struct colour { double R, G, B; bool operator < (const colour & blah) const { return R < blah.R; } }; int k; vector palette; colour white; colour drawing[n+1][n+1], canvas[n+1][n+1], activeColour; void printSolution() { fout<>N>>k; colour newColour; for(int i=0; i>newColour.R>>newColour.G>>newColour.B; palette.push_back(newColour); } for(int i=0; i>drawing[i][j].R; for(int i=0; i>drawing[i][j].G; for(int i=0; i>drawing[i][j].B; white.R=225; white.G=225; white.B=225; for(int i=0; i & bestMatch) { bestMatch.second= -1; double minDistance=INF; for(int i=0; i & bestMatch) { bestMatch.second= -1; double minDistance=INF; for(int i=0; i mem; /*double findBestMatch_FromDrawing_Command3(int x, int y, pair & bestMatch) { mem.clear(); double minDistance=INF; for(int i=0; i & bestMatch) { mem.clear(); double minDistance=INF; for(int i=0; i p[n+1][n+1]; void findBestMatch(int i, int j) { double r5=calculateDistance(drawing[i][j], canvas[i][j]); if(r5>0.000001) { // to-do: r6, using the current activeColour pair p1; double r1=findBestMatch_FromPalette_Command3(i, j, p1); pair p2; double r2=findBestMatch_FromPalette_Command4(i, j, p2); double r3=calculateDistance(drawing[i][j], activeColour); double r4=calculateDistance(drawing[i][j], mix(activeColour, canvas[i][j])); /*pair p3; double r3=findBestMatch_FromDrawing_Command3(i, j, p3); pair p4; double r4=findBestMatch_FromDrawing_Command4(i, j, p4);*/ double best=min(min(min(min(r1, r2), r5), r3), r4); if(best==r5) { command[i][j]=0; } else if(best==r1) { command[i][j]=1; p[i][j]=p1; } else if(best==r2) { command[i][j]=2; p[i][j]=p2; } else if(best==r3) { command[i][j]=3; } else { command[i][j]=4; } } else { command[i][j]=0; p[i][j]=make_pair(-1, -1); } } bool beenThere[n+1][n+1]; /*void R4(int i, int j) { //fout<<4<200) { y--; w-=(x-i+1); } int p1=p[i][j].first, p2=p[i][j].second; if(C+2>90000) printSolution(); C+=2; commandInfo thisCommand; thisCommand.type=1; thisCommand.c1=p1; thisCommand.c2=p2; output.push_back(thisCommand); thisCommand.type=4; thisCommand.c1=i; thisCommand.c2=j; thisCommand.c3=x; thisCommand.c4=y; output.push_back(thisCommand); activeColour=mix(activeColour, canvas[p1][p2]); for(int ii=i; ii<=x; ii++) { for(int jj=j; jj<=y; jj++) { beenThere[ii][jj]=true; colour result=mix(canvas[ii][jj], activeColour); canvas[ii][jj]=result; } } } void R3(int i, int j) { //fout<<3<200) { y--; w-=(x-i+1); } int p1=p[i][j].first, p2=p[i][j].second; if(C+2>90000) printSolution(); C+=2; commandInfo thisCommand; thisCommand.type=1; thisCommand.c1=p1; thisCommand.c2=p2; output.push_back(thisCommand); thisCommand.type=3; thisCommand.c1=i; thisCommand.c2=j; thisCommand.c3=x; thisCommand.c4=y; output.push_back(thisCommand); activeColour=mix(activeColour, canvas[p1][p2]); for(int ii=i; ii<=x; ii++) { for(int jj=j; jj<=y; jj++) { beenThere[ii][jj]=true; canvas[ii][jj]=activeColour; } } }*/ void R4(int i, int j) { int x=i, y=j; findBestMatch(x+1, j); while(x=200) { y--; w-=(x-i+1); } if(w>=200) { y--; w-=(x-i+1); } if(C+1>90000) { printSolution(); done=true; } else { C++; commandInfo thisCommand; if(x<=0) x=i; if(y<=0) y=j; thisCommand.type=4; thisCommand.c1=i; thisCommand.c2=j; thisCommand.c3=x; thisCommand.c4=y; output.push_back(thisCommand); for(int ii=i; ii<=x; ii++) { for(int jj=j; jj<=y; jj++) { beenThere[ii][jj]=true; colour result=mix(canvas[ii][jj], activeColour); canvas[ii][jj]=result; } } //printSolution(); } } void R3(int i, int j) { int x=i, y=j; findBestMatch(x+1, j); while(x=200) { y--; w-=(x-i+1); } if(w>=200) { y--; w-=(x-i+1); } if(C+1>90000) { printSolution(); done=true; } else { C++; commandInfo thisCommand; if(x<=0) x=i; if(y<=0) y=j; thisCommand.type=3; thisCommand.c1=i; thisCommand.c2=j; thisCommand.c3=x; thisCommand.c4=y; output.push_back(thisCommand); for(int ii=i; ii<=x; ii++) { for(int jj=j; jj<=y; jj++) { beenThere[ii][jj]=true; canvas[ii][jj]=activeColour; } } //printSolution(); } } void R2(int i, int j) { //fout<<2<=200) { y--; w-=(x-i+1); } if(w>=200) { y--; w-=(x-i+1); } int p1=p[i][j].first, p2=p[i][j].second; if(C+2>90000) { printSolution(); done=true; } else { C+=2; commandInfo thisCommand; thisCommand.type=1; thisCommand.c1=p1; output.push_back(thisCommand); if(x<=0) x=i; if(y<=0) y=j; thisCommand.type=4; thisCommand.c1=i; thisCommand.c2=j; thisCommand.c3=x; thisCommand.c4=y; output.push_back(thisCommand); activeColour=mix(activeColour, palette[p1]); for(int ii=i; ii<=x; ii++) { for(int jj=j; jj<=y; jj++) { beenThere[ii][jj]=true; colour result=mix(canvas[ii][jj], activeColour); canvas[ii][jj]=result; } } //printSolution(); } } void R1(int i, int j) { int x=i, y=j; findBestMatch(x+1, j); while(x=200) { y--; w-=(x-i+1); } if(w>=200) { y--; w-=(x-i+1); } int p1=p[i][j].first, p2=p[i][j].second; if(C+2>90000) { printSolution(); done=true; } else { C+=2; if(x<=0) x=i; if(y<=0) y=j; commandInfo thisCommand; thisCommand.type=1; thisCommand.c1=p1; output.push_back(thisCommand); thisCommand.type=3; thisCommand.c1=i; thisCommand.c2=j; thisCommand.c3=x; thisCommand.c4=y; output.push_back(thisCommand); activeColour=mix(activeColour, palette[p1]); for(int ii=i; ii<=x; ii++) { for(int jj=j; jj<=y; jj++) { beenThere[ii][jj]=true; canvas[ii][jj]=activeColour; } } } } void paint() { for(int i=0; i=4.75) printSolution();*/ } } } } int main() { ios::sync_with_stdio(false); fin.tie(NULL); fout.tie(NULL); //timer=clock(); init(); while(!done) { paint(); } fin.close(); fout.close(); //return 0; // end }