http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3347
Picture Handling Time Limit: 1 Second Memory Limit: 32768 KBXiaoyao likes to play with pictures very much. When he got a picture, he will use rectangle selection tool to select an area ((x1, y1) to (x2, y2), inclusively) and perform these operations:
After several operations, Xiaoyao wonders what value a pixel at specified position is. Could you tell him?
Input
There are multi cases (no more than 5). Please proceed to the end of input. Each case is like below:
The first line contains two integers W and H, indicating the width and height of the picture. W and H are both between 1 and 255, inclusively.
Following H lines, each line contains W integers, indicating the value of pixels. The first integer of the first line in these H lines is the value of pixel at (0, 0) and the last integer is the value of pixel at (W-1, H-1). All these values are between -105 and 105, inclusively.
Then, a line with one integer M(0 <= M <= 105).
Following M lines, each line contains 5 integers: x1 y1 x2 y2 op, indicating the selected area and the operation. (0 <= x1 <= x2 < W, 0 <= y1 <= y2 < H, 1 <= op <= 5). If op is 1, it means Invert operation. If op is 2, it means Lighten operation. The others follow by analogy. You should follow the order of the input to perform operations.
Finally, there is a line with two integers x and y. (0 <= x < W, 0 <= y < H) Your task is to output the value of pixel at (x, y) after performing above operations.
Output
For each case, output a single line containing one integer which is the value of pixel at (x, y) at last.
Sample Input
3 2
1 2 3
4 5 6
2
0 0 1 1 1
1 0 2 1 4
2 1
Sample Output
-5
题意:给你一系列对矩阵子阵的操作,包括negative, –, ++, 水平翻转和垂直翻转。最后问某个位置的元素的值。
分析:由于只问一个位置的元素的值,所以只要简单的对其进行模拟操作就可以了,注意这个位置是最终位置,不是初始位置,所以操作的时候要逆序。
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> using namespace std; const int maxn=100010; struct node{ int op; int x1,y1; int x2,y2; }t[maxn]; int a[300][300]; int m,h,k; int main() { int x,y; while(scanf("%d %d",&m,&h) != EOF) { memset(t,0,sizeof(t)); for(int i=0;i<h;i++) for(int j=0;j<m;j++) scanf("%d",&a[i][j]); scanf("%d",&k); for(int i=1;i<=k;i++) scanf("%d %d %d %d %d",&t[i].x1,&t[i].y1,&t[i].x2,&t[i].y2,&t[i].op); scanf("%d %d",&x,&y); int fu=1; int num=0; for(int i=k;i>=1;i--) { if(x>=t[i].x1 && x<=t[i].x2 && y>=t[i].y1 && y<=t[i].y2){ if(t[i].op==1) { fu = -fu; num = -num; } else if(t[i].op==2) { num++; } else if(t[i].op==3){ num--; } else if(t[i].op==4){ x=t[i].x1+t[i].x2-x; } else{ y=t[i].y1+t[i].y2-y; } } } printf("%d\n",fu*(a[y][x]+num)); } return 0; }