#include <iostream> using namespace std; int min(int a, int b){ if(a<b){ return a; } else{ return b; } } int max(int a, int b){ if(a>b){ return a; } else{ return b; } } int maximum(int tab[], int l){ int result = tab[1]; for(int i = 2; i<l; i++){ if(result<tab[i]){ result = tab[i];} } return result; } int swap(int &a, int &b){ int tmp = a; a = b; b = tmp; } int main(){ int n, w, h; cin>>n>>w>>h; const int h1 = h; int map[w][h]; int colors[w*h*4 + 1]; for(int i = 0; i<w*h*4+1; i++){ colors[i] = 0; } colors[1] = w*h; for(int i = 0; i<w; i++){ for(int j=0; j<h; j++){ map[i][j] = 1; } } for(int sth = 0; sth < n; sth++){ int x1, x2, y1, y2; cin>>x1>>y1>>x2>>y2; if(x1 != min(x1,x2)){ swap(x1,x2);} if(y1 != min(y1,y2)){ swap(y1,y2);} for(int i = 0; i<w; i++){ for(int j=0; j<h; j++){ if(x1<=i && i<x2 && y1<=j && j<y2){ colors[map[i][j]]--; map[i][j] = (map[i][j]*4 - 1)%(w*h*4) + 1; colors[map[i][j]]++; continue; } if((i<x1 || x2<=i) && y1<=j && j<y2){ colors[map[i][j]]--; map[i][j] = (map[i][j]*4)%(w*h*4) + 1; colors[map[i][j]]++; continue; } if(x1<=i && i<x2 && (j<y1 || y2<=j)){ colors[map[i][j]]--; map[i][j] = (map[i][j]*4 + 1)%(w*h*4) + 1; colors[map[i][j]]++; continue; } if((i<x1 || x2<=i) && (j<y1 || y2<=j)){ colors[map[i][j]]--; map[i][j] = (map[i][j]*4 + 2)%(w*h*4) + 1; colors[map[i][j]]++; continue; } } } } cout<<maximum(colors, w*h*4 + 1)<<endl; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | #include <iostream> using namespace std; int min(int a, int b){ if(a<b){ return a; } else{ return b; } } int max(int a, int b){ if(a>b){ return a; } else{ return b; } } int maximum(int tab[], int l){ int result = tab[1]; for(int i = 2; i<l; i++){ if(result<tab[i]){ result = tab[i];} } return result; } int swap(int &a, int &b){ int tmp = a; a = b; b = tmp; } int main(){ int n, w, h; cin>>n>>w>>h; const int h1 = h; int map[w][h]; int colors[w*h*4 + 1]; for(int i = 0; i<w*h*4+1; i++){ colors[i] = 0; } colors[1] = w*h; for(int i = 0; i<w; i++){ for(int j=0; j<h; j++){ map[i][j] = 1; } } for(int sth = 0; sth < n; sth++){ int x1, x2, y1, y2; cin>>x1>>y1>>x2>>y2; if(x1 != min(x1,x2)){ swap(x1,x2);} if(y1 != min(y1,y2)){ swap(y1,y2);} for(int i = 0; i<w; i++){ for(int j=0; j<h; j++){ if(x1<=i && i<x2 && y1<=j && j<y2){ colors[map[i][j]]--; map[i][j] = (map[i][j]*4 - 1)%(w*h*4) + 1; colors[map[i][j]]++; continue; } if((i<x1 || x2<=i) && y1<=j && j<y2){ colors[map[i][j]]--; map[i][j] = (map[i][j]*4)%(w*h*4) + 1; colors[map[i][j]]++; continue; } if(x1<=i && i<x2 && (j<y1 || y2<=j)){ colors[map[i][j]]--; map[i][j] = (map[i][j]*4 + 1)%(w*h*4) + 1; colors[map[i][j]]++; continue; } if((i<x1 || x2<=i) && (j<y1 || y2<=j)){ colors[map[i][j]]--; map[i][j] = (map[i][j]*4 + 2)%(w*h*4) + 1; colors[map[i][j]]++; continue; } } } } cout<<maximum(colors, w*h*4 + 1)<<endl; return 0; } |