2015 Xiangtan University Program Design Competition (Internet)--e question--annoying XOR

Source: Internet
Author: User

Annoying XOR or
Accepted:27 submit:102
Time limit:5000 MS Memory limit:65536 KB
Title Description

For example, there is a n*m table, and each lattice has a number. We define the rectangle that the primary rectangle determines for the given pair of coordinates (which is always a pair of vertex coordinates of a rectangle). It produces up to 4 sub-rectangles, which are determined by the vertices and table boundaries of the main rectangle. What we need is the XOR value of the number of all the shaded parts.

X1=3,y1=3,x2=4,y2=4, so the answer is A11^A12^A21^A22^A15^A16^A25^A26^A33^A34^A43^A44^A51^A52^A61^A62^A55^A56^A65^A66. Where ' ^ ' represents the XOR symbol, AIJ represents the number in the square of row I, column J.

Input

The first line is an integer T (t≤10) that represents the number of test data groups. The first row of each group of data three integer n,m,q (0<n,m≤1000,q≤500000), q indicates that there is a Q group to ask. Then enter n rows, each with m digits, indicating the number in the table (non-negative integer, not greater than 109). Finally there is Q line, which indicates Q query, each line contains 4 positive integers x1,y1,x2,y2 (1≤x1≤x2≤n,1≤y1≤y2≤m).

Output

For each query, output a line that represents an XOR or result.

Sample input
14 4 31 0 2 10 2 1 12 1 1 01 1 0 22 2 2 22 2 3 32 2 4 4
Sample output
000
Tips

A large number of input and output, please use C-style input and output;

1=2^3^4^ Whole;

#include <iostream>#include<stdio.h>#include<string.h>#include<algorithm>#defineN 1050using namespacestd;intMaps[n][n],a[n][n];intMain () {intn,t,m,k,i,j,a,b,c,d,e; intX,y,x0,y0,x1,y1,x2,y2; scanf ("%d",&T);  while(t--) {memset (A,0,sizeof(a)); memset (Maps,0,sizeof(maps)); scanf ("%d%d%d",&n,&m,&k);  for(i=1; i<=n;i++)        {             for(j=1; j<=m;j++) {scanf ("%d",&Maps[i][j]); A[I][J]=a[i-1][j]^a[i][j-1]^a[i-1][j-1]^Maps[i][j]; }        }         for(i=0; i<k;i++) {scanf ("%d %d%d%d",&x,&y,&x0,&y0); X1=min (x,x0); Y1=min (y,y0); X2=Max (x,x0); Y2=Max (Y,Y0); A=a[x1-1][y1-1]; B=a[x1-1][m]^a[x1-1][y2]; C=a[n][y1-1]^a[x2][y1-1]; D=a[n][m]^a[x2][m]^a[n][y2]^A[x2][y2]; E=a[x2][y2]^a[x1-1][y2]^a[x2][y1-1]^a[x1-1][y1-1]; printf ("%d\n", a^b^c^d^d); }    }    return 0;}

2015 Xiangtan University Program Design Competition (Internet)--e question--annoying XOR

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.