HDU 5386 Cover (brute force solution + idea problem)

Source: Internet
Author: User

Test instructions

There are two kinds of actions:
Operation L x y, put the current x, this column is all Y
Operation H x Y, put the current, this line is all set to Y.
Now for You n? N The initial matrix, and n? N The target matrix
Now give you M operation (composed of the above two operations), ask how to sort the M operation, in order to make, the initial matrix, through the operation of the order, to form the target matrix.
The output sort scheme.

Analytical:

Reverse thinking,
Enumerates each operation and then determines whether the operation is the last action. (Like a tear tape, one strip of Peel)
The last way to determine whether or not to do this is:
Remove the points that have been used, and if a row equals the color of the current operation, that is the last action. Then mark the points that have been manipulated and repeat m times.
The ID of the last reverse output record.

y code

#include <cstdio>#include <cstring>#include <algorithm>using namespace STD;Const intINF =0x3f3f3f3f;Const intM =505;Const intN = the;intTar[n][n];structOper {intx, color, id; Oper () {} Oper (intXintColorintID): x (x), color (color), ID (ID) {}} H[m], l[m];intNH, NL, N, M;intORDER[M];BOOLVISH[M], visl[m];intCheckintXintColorCharType) {if(Type = =' H ') { for(inti =1; I <= N; i++) {if(Tar[x][i] = = INF)Continue;if(tar[x][i]! = color)return false; }    }Else{ for(inti =1; I <= N; i++) {if(Tar[i][x] = = INF)Continue;if(tar[i][x]! = color)return false; }    }return true;}voidSetColor (intXCharType) {if(Type = =' H ') { for(inti =1; I <= N;        i++) Tar[x][i] = INF; }Else{ for(inti =1; I <= N;    i++) tar[i][x] = INF; }}voidSolve () {intCNT =0; while(CNT < m) { for(inti =0; I < NH; i++) {if(Vish[i])Continue;if(Check (h[i].x, H[i].color,' H ') {SetColor (h[i].x,' H '); Vish[i] =true;            order[cnt++] = h[i].id; }        } for(inti =0; I < NL; i++) {if(Visl[i])Continue;if(Check (l[i].x, L[i].color,' L ') {SetColor (l[i].x,' L '); Visl[i] =true;            order[cnt++] = l[i].id; }        }    }}intMain () {intTscanf("%d", &t); while(t--) {scanf("%d%d", &n, &m);inttmp for(inti =1; I <= N; i++) for(intj =1; J <= N; J + +)scanf("%d", &tmp); for(inti =1; I <= N; i++) for(intj =1; J <= N; J + +)scanf("%d", &tar[i][j]);memset(Vish,false,sizeof(Vish));memset(VISL,false,sizeof(VISL)); NH = NL =0;Charoper[5];intx, color; for(inti =1; I <= m; i++) {scanf("%s%d%d", Oper, &x, &color);if(oper[0] ==' H ') h[nh++] = Oper (x, color, i);Elsel[nl++] = Oper (x, color, i); } solve ();printf("%d", order[m-1]); for(inti = m2; I >=0; i--)printf("%d", Order[i]);puts(""); }return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 5386 Cover (brute force solution + idea problem)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.