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 |
#include <iostream> #include <algorithm> #include <queue> #include <vector> #include <cstdlib> #include <cstdio> #include <string> #include <cstring> #include <ctime> #include <iomanip> #include <cmath> #include <set> using namespace std; #define MAXN 1000 bool board[MAXN][MAXN]; void outputBoard(){ int res = 0; for (int x = 0; x < MAXN-1; x++) { for (int y = 0; y< MAXN;y++){ if (board[y][x]) { res++; } } } cout << res << endl; memset(board, 0, sizeof(board)); } int main(){ memset(board, 0, sizeof(board)); int startx = 0,starty = 0,endx = 0,endy = 0; while (cin >> startx >> starty >> endx >> endy){ if (endx < startx) { swap(startx, endx); } if (endy < starty) { swap(starty, endy); } if (startx == -1 && starty == -1 && endx == -1 && endy == -1) { outputBoard(); continue; } if (startx == -2 && starty == -2 && endx == -2 && endy == -2) { outputBoard(); break; } for (int x = startx; x <= endx-1; x++) { for (int y = starty; y<= endy-1;y++){ board[y][x] = true; } } } } |
两个对角线坐标的先后顺序不一定要自己判断,不好好看题谁也救不了。。。