cf div2 238 c
1 second
256 megabytes
standard input
standard output
Little Chris is a huge fan of linear algebra. This time he has been given a homework about the unusual square of a square matrix.
The dot product of two integer number vectors x and y of size n is the sum of the products of the corresponding components of the vectors. The unusual square of an n × n square matrix A is defined as the sum of n dot products. The i-th of them is the dot product of the i-th row vector and the i-th column vector in the matrix A.
Fortunately for Chris, he has to work only in GF(2)! This means that all operations (addition, multiplication) are calculated modulo 2. In fact, the matrix A is binary: each element of A is either 0 or 1. For example, consider the following matrix A:
The unusual square of A is equal to (1·1 + 1·0 + 1·1) + (0·1 + 1·1 + 1·0) + (1·1 + 0·1 + 0·0) = 0 + 1 + 1 = 0.
However, there is much more to the homework. Chris has to process q queries; each query can be one of the following:
- given a row index i, flip all the values in the i-th row in A;
- given a column index i, flip all the values in the i-th column in A;
- find the unusual square of A.
To flip a bit value w means to change it to 1 - w, i.e., 1 changes to 0 and 0 changes to 1.
Given the initial matrix A, output the answers for each query of the third type! Can you solve Chris's homework?
The first line of input contains an integer n (1 ≤ n ≤ 1000), the number of rows and the number of columns in the matrix A. The next nlines describe the matrix: the i-th line contains n space-separated bits and describes the i-th row of A. The j-th number of the i-th lineaij (0 ≤ aij ≤ 1) is the element on the intersection of the i-th row and the j-th column of A.
The next line of input contains an integer q (1 ≤ q ≤ 106), the number of queries. Each of the next q lines describes a single query, which can be one of the following:
- 1 i — flip the values of the i-th row;
- 2 i — flip the values of the i-th column;
- 3 — output the unusual square of A.
Note: since the size of the input and output could be very large, don't use slow output techniques in your language. For example, do not use input and output streams (cin, cout) in C++.
Let the number of the 3rd type queries in the input be m. Output a single string s of length m, where the i-th symbol of s is the value of the unusual square of A for the i-th query of the 3rd type as it appears in the input.
3
1 1 1
0 1 1
1 0 0
12
3
2 3
3
2 2
2 2
1 3
3
3
1 2
2 1
1 1
3
01001 这个题目有个
#include <cstdio> using namespace std; int n,p; int main() {
scanf("%d",&n);
int ans = ;
for(int i = ; i <= n; ++i) {
for(int j = ; j <= n; ++j) {
int v;
scanf("%d",&v);
if(i == j)
ans ^= v;
}
} scanf("%d",&p);
for(int i = ; i <= p; ++i) {
int ch,v;
scanf("%d",&ch);
if(ch == ) {
printf("%d",ans);
}
else {
scanf("%d",&v);
ans ^= ;
}
} return ; }
规律,除了主对角线的元素自己与自己相乘,其他的元素相乘的组合每个都会出现两次,即他们的和必定是0所以只需要考虑主对角线的元素自行相乘的就可以了
cf div2 238 c的更多相关文章
- cf div2 238 D
D. Toy Sum time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- cf div2 234 D
D. Dima and Bacteria time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- 离线dfs CF div2 707 D
http://codeforces.com/contest/707/problem/D 先说一下离线和在线:在线的意思就是每一个询问单独处理复杂度O(多少多少),离线是指将所有的可能的询问先一次都处理 ...
- cf div2 239 D
D. Long Path time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- cf div2 236 D
D. Upgrading Array time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- cf div2 237 D
D. Minesweeper 1D time limit per test 2 seconds memory limit per test 512 megabytes input standard i ...
- cf div2 235 D
D. Roman and Numbers time limit per test 4 seconds memory limit per test 512 megabytes input standar ...
- cf div2 234 E
E. Inna and Binary Logic time limit per test 3 seconds memory limit per test 256 megabytes input sta ...
- CF div2 D BFS
http://codeforces.com/contest/676/problem/D 题目大意: 勇者去迷宫杀恶龙.迷宫是有n*m的方格子组成的.迷宫上有各种记号,这些记号表达着能走的方向.当且仅当 ...
随机推荐
- Map,HashMap
Map(映射),又称为字典(Dictionary),是由关键字(Key)及其对应的元素值(Value)所组成的元素单元(Element)的表单式集合. 通常,对于Map而言,使用给定的Key,可以迅速 ...
- 算法系列1《DES》
1. DES算法简介 DES算法全称为Data Encryption Standard,即数据加密算法,它是IBM公司于1975年研究成功并公开发表的.DES算法的入口参数有三个:Key.Data.M ...
- 教你怎么安装MongoDB
以下命令以root用户运行:#sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10#echo 'deb http://do ...
- C# socket 实现消息中心向消息平台 转发消息 (修改)
using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using ...
- win7 mount到Linux下无法分配内存的问题(Cannot allocate memory)
如题,我在win7系统下共享目录,mount到linux下,进行编译或者某些操作,出现Cannot allocate memory提示. 修改以下两个键值,然后重启server服务,可以解决这个问题: ...
- iOS学习之Object-C语言集合
一.数组类 1.C语言数组的特点:数组是一个有序的集合,用来存储相同数据类型的元素,通过下标访问数组中的元素,下标从0开始. 2.OC中的数组只能存储对象类型(必须是NSObjec ...
- NSAttributedString之设置字间距与行间距
// 调整行间距 NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithSt ...
- Sliverlight Slide 的左右滑动
private void btnPrev_Click(object sender, RoutedEventArgs e) { scrollRule = (scrollRule-) >= ?(sc ...
- C# 字符串转换值类型
bool status = int.TryParse(m_Judge(12)+"ds",out j); int iParse = int.Parse("4"); ...
- [无人值守安装操作系统]__RHEL6__FTP+TFTP+DHCP+Kickstart+PXE
实验环境 1.实验平台:VMware Workstation 10 2.实验OS:RHEL6 3.服务器A: (1) 10.0.10.158 (2) DHCP/FTP/TFTP (3) 有可使用的yu ...