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的方格子组成的.迷宫上有各种记号,这些记号表达着能走的方向.当且仅当 ...
随机推荐
- RAP开发入门-开发笔记
一.发布/运行 每次项目发布时需要在MANIFEST.MF->bulid中勾选依赖包.文件.代码等,避免报错 部署时项目可能会报一个baseline的错误,window->preferen ...
- jquery 简单弹出层
预定义html代码:没有 所有代码通过js生成和移除. 预定义css .z-popup-overlay{ width:100%; min-height: 100%; height:800px; pos ...
- centos php-fpm nginx配置
移除旧的软件包:yum remove httpd* php* 安装:yum install php php-fpm yum install php-gd php-mysql php-mbstring ...
- Android编程: 调试方法
学习知识:Android的调试方法 ====调试方法==== 前提: IDE环境为Android Studio,熟悉LogCat,知道如何查看日志信息 工具: Android DDMS调试工具,一般点 ...
- Labview实现脉波调制( PDM )
Labview实现脉波调制( PDM ) 根据定义为脉冲宽度调制 生成一个正弦信号,得到其幅值输入给一个方波信号的占空比 由于方波信号的占空比里面含有正弦信号的信息 因此通过滤出方波信号的占空比信息则 ...
- 零基础学习Linux(三)linux与windows文件共享
上次的博文零基础学习Linux(一)环境搭建中我们已经将linux环境部署完毕了,接下来我们就可以在linux上进行软件的安装和环境的配置.但在进行这些操作之前,我们还需要解决一个问题——Linux与 ...
- Mysql的相关命令
1.登录服务器 mysql -h host -u user -p mysql -h host -u user -p 数据库 2.使用SHOW语句找出服务器上当前存在什么数据库:mysql> SH ...
- 数据类型 swift
1整形 Int,Int8,Int16,Int32,Int64 UInt,UInt8,UInt16,UInt32,UInt64 其中Int,UInt始终和当前平台的原生字长相同(32位机,64位机) 查 ...
- [shell基础]——tr命令
(1) tr 字符替换 测试文本内容 # cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4. ...
- Spark系列—01 Spark集群的安装
一.概述 关于Spark是什么.为什么学习Spark等等,在这就不说了,直接看这个:http://spark.apache.org, 我就直接说一下Spark的一些优势: 1.快 与Hadoop的Ma ...