UVA-1493 Draw a Mess and check set + compress diagram

Source: Internet
Author: User

Title: Give N*m points, can be used in different colors of the stroke rectangle, diamond, isosceles triangle and round, because it is a painting, so some points will be overwritten, the original color will be covered out. Now give the pattern and order of each person, and ask how many points each color takes up at the end.

How to solve the problem: if it's direct violence, it will be tle.
In order to prevent being covered, the painting is inverted, and if the point is possessed, it cannot be drawn again.
We use the and check set to record the points at the right end of each point, put the used points together, and then swipe down from the top

Reference to the code of the seniors ...

#include <cstdio>#include <cstring>#include <algorithm>#include <map>#include <cmath>#include <cstdlib>#define MAXN#define MAXM 50010using namespace STD;intW[MAXN][MAXM], N, M, q;intcolor[Ten]; Map<char, int>Map;structshape{intX, Y, R, W, C, M, Start, End;voidInit () {if(M <2) {Start = max (0, x-r); End = min (N-1, X + R); }Else{R = (R +1) /2-1;            Start = x; End = min (N-1, r + x); }}}S[MAXM];intFindint*f,intx) {returnx = = F[x]? X:F[X] = find (f, f[x]);}voidInit () { for(inti =0; i < N; i++) for(intj =0; J <= M; J + +) w[i][j] = j; for(inti =0; I <Ten; i++) Color[i] =0;Charstr[ -]; for(inti =0; i < Q; i++) {scanf('%s ', str); S[I].M = map[str[0]];if(str[0] !=' R ') {scanf("%d%d%d%d", &s[i].x, &s[i].y, &AMP;S[I].R, &s[i].c);        S[i].init (); }Else{scanf("%d%d%d%d%d", &s[i].x, &s[i].y, &AMP;S[I].R, &AMP;S[I].W, &s[i].c); }    }}intCount_rec (intXintYintRintW) {intCNT =0; for(inti = x; I <= x + R-1&& i < N; i++) {intt = y; while(t = Find (w[i],t),ABS(t-y) < W && T < M) {cnt++; W[i][t] = t +1; }    }returnCNT;}intGet_r (intXintIintRintm) {if(M = =0)return(int)sqrt(1.0* R * R-1.0* (x-i) * (x-i));Else if(M = =1)returnR-ABS(x-i);Else if(M = =2)returnR-(i-x);return 0;}intCount_oth (intXintYintRintMintStart,intEND) {intCNT =0; for(inti = Start; I <= End; i++) {intR = Get_r (x, I, R, M);intt = max (0, y-r); while(t = Find (W[i], T),ABS(t-y) <= R && T < M) {cnt++; W[i][t] = t +1; }    }returnCNT;}voidSolve () { for(inti = q-1; I >=0; i--) {int&col = color[s[i].c];if(S[I].M = =3) col + = Count_rec (s[i].x, S[i].y, S[I].R, S[I].W);ElseCol + = Count_oth (s[i].x, S[i].y, S[I].R, S[i].m,s[i]. Start, S[i].    END); }printf("%d", color[1]); for(inti =2; I <Ten; i++)printf("%d", Color[i]);printf("\ n");}voidBegin () {map[' C '] =0; map[' D '] =1; map[' T '] =2; map[' R '] =3;}intMain () {begin (); while(scanf("%d%d%d", &n, &m, &q)! = EOF) {init ();    Solve (); }return 0;}

UVA-1493 Draw a Mess and check set + compress diagram

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.