这道题其实找到规律之后其实不难,和破损的键盘一样,都有点递推转移的感觉

题意:

你可以进行这样一次操作:选一个点,然后把这个点横切竖切直到正对角线上面的点,全部翻转过来,问你要进行多少次操作才能把所有的点都翻转过来

思路:

多次模拟之后可以发现最右上方的点仅能是选择自己才能翻转,之后与这个相邻的点变成了两个最右上方,而这两个点和刚才那个点一样仅能由自己翻转

还有一个要注意的这个只能影响对角线一侧的

所以只要在对角线一侧一直从最右边上到下遍历翻转就好了

Description

After years of hard work scientists invented an absolutely new e-reader display. The new display has a larger resolution, consumes less energy and its production is cheaper. And besides, one can bend it. The only inconvenience is highly unusual management.
For that very reason the developers decided to leave the e-readers' software to programmers.

The display is represented by n × n square of pixels, each of which can be either black or white. The display rows are numbered with integers from 1 to n upside
down, the columns are numbered with integers from 1 to n from the left to the right. The display can perform commands like "x, y".
When a traditional display fulfills such command, it simply inverts a color of (x, y), where x is the row number and y is
the column number. But in our new display every pixel that belongs to at least one of the segments (x, x) - (x, y)and (y, y) - (x, y) (both
ends of both segments are included) inverts a color.

For example, if initially a display 5 × 5 in size is absolutely white, then the sequence of commands (1, 4), (3, 5), (5, 1), (3, 3)leads
to the following changes:

You are an e-reader software programmer and you should calculate minimal number of commands needed to display the picture. You can regard all display pixels as initially white.

Input

The first line contains number n (1 ≤ n ≤ 2000).

Next n lines contain n characters each: the description of the picture that needs to be shown. "0"
represents the white color and "1" represents the black color.

Output

Print one integer z — the least number of commands needed to display the picture.

Sample Input

Input
5
01110
10010
10001
10011
11110
Output
4
<pre name="code" class="cpp">#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<queue>
#include<cstdlib>
#include<algorithm>
#include<stack>
#include<map>
#include<queue>
#include<vector>
using namespace std;
char mp[2048][2048];
int flagr[2048],flagc[2048];
int n,cnt;
void print(){
for(int i=0;i<n;i++)
cout<<mp[i]<<endl;
cout<<"*****************"<<endl;
cout<<endl;
}
void search(){ // print();
for(int i=0;i<n;i++){
for(int j=n-1;j>i;j--){
if((mp[i][j]-'0'+flagr[i]+flagc[j])&1){
mp[i][j]='0';
flagc[j]++,flagr[i]++,cnt++;
}
mp[i][j]='0';
}
} // 0 -> 1, 1 -> 0, '0' = 48;
// (mp[i][i] - '0' + flagr[i] +flagc[i] )%2
for(int i=0;i<n;i++){
mp[i][i]=(mp[i][i] - '0' + flagr[i] +flagc[i] )%2 +48;
}
memset(flagr,0,sizeof flagr);
memset(flagc,0,sizeof flagc);
for(int i=n-1;i>=0;i--){
for(int j=0;j<i;j++){
if((mp[i][j]-'0'+flagr[i]+flagc[j])&1){
// print();
flagc[j]++,flagr[i]++,cnt++;
}
mp[i][j]='0';
}
}
for(int i=0;i<n;i++)
if((mp[i][i] - '0' + flagr[i] +flagc[i] )%2) cnt++;
}
int main(){
//freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
cin>>n;
for(int i = 0;i < n;i++){
scanf("%s",mp[i]);
}
search();
printf("%d\n",cnt);
return 0;
}


CF_127E reader Display的更多相关文章

  1. 设备管理 USB ID

    发现个USB ID站点,对于做设备管理识别的小伙伴特别实用 http://www.linux-usb.org/usb.ids 附录: # # List of USB ID's # # Maintain ...

  2. Display PDF in browser | Acrobat, Reader XI

    点这个链接查看详细的解决办法 http://helpx.adobe.com/acrobat/using/display-pdf-browser-acrobat-xi.html When you cli ...

  3. TRichTextBox – A universal RichTextBox which can display animated images and more

    TRichTextBox – A universal RichTextBox which can display animated images and more trestan, 7 Dec 201 ...

  4. RFID 读写器 Reader Writer Cloner

    RFID读写器的工作原理 RFID的数据采集以读写器为主导,RFID读写器是一种通过无线通信,实现对标签识别和内存数据的读出和写入操作的装置. 读写器又称为阅读器或读头(Reader).查询器(Int ...

  5. [CareerCup] 8.5 Online Book Reader System 在线读书系统

    8.5 Design the data structures for an online book reader system. 这道题OOB的题让我们设计一个在线读书系统,还是没有任何提示,所以发挥 ...

  6. RFID Reader 线路图收集

    This 125 kHz RFID reader http://www.serasidis.gr/circuits/RFID_reader/125kHz_RFID_reader.htm http:// ...

  7. RFIDler - An open source Software Defined RFID Reader/Writer/Emulator

    https://www.kickstarter.com/projects/1708444109/rfidler-a-software-defined-rfid-reader-writer-emul h ...

  8. Drag & Drop and File Reader

    参考 : http://www.html5rocks.com/zh/tutorials/file/dndfiles/ http://blog.csdn.net/rnzuozuo/article/det ...

  9. Adobe® Reader®.插件开发

    Thank you for your interest in developing a plug-in for Adobe® Reader®. To build an Adobe Reader plu ...

随机推荐

  1. Java + selenium window()接口方法介绍

    在浏览器启动的代码中,有一段关于window接口的调用,这篇文章就是来解释介绍这个接口的.代码如下 driver.manage().window().maxmize(); window接口主要是用来控 ...

  2. python学习那点事---列表生成式实现大小写字母相互转换

    题目: 已知列表list=["pYTHON","iS",eASY],要求使用列表生成式实现,生成一个新的列表,要求将大写字母转换为小写字母,小写字母转换为大写字 ...

  3. lr 计算字符串长度

    sizeof求后面的内容or表达式所占用的字节数 strlen求字符串的有效长度,只要遇到'\0'就认为字符串结束 字符串转化为int型变量 Action2() { int j = 0; j = at ...

  4. python字符串有多少字节

    是否有一些函数可以告诉我字符串在内存中占用多少字节? 我需要设置套接字缓冲区的大小,以便一次传输整个字符串. 解决方案 import sys sys.getsizeof(s) # getsizeof( ...

  5. 北京邀请赛 B. Beautiful Garden

    题意:给你坐标和n个点,求最少移动的点使得n个点成等差数列 思路:既然要成等差数列,那么最起码有两个点是不动的,然后枚举这两个点中间的点的个数,近期水的要死,看了队友的代码做的 #include &l ...

  6. ASP.NET Core 2.1 JWT token (一) - 简书

    原文:ASP.NET Core 2.1 JWT token (一) - 简书 JwtBearer认证是一种标准的,通用的,无状态的,与语言无关的认证方式.Bearer验证属于HTTP协议标准验证. 如 ...

  7. 自编shell脚本合集(完善中)

    1.数据库备份 #!/bin/bash user="root" psword="root" bakdir="/data/mysqlbak" ...

  8. L2Dwidget

    只需要在[页首html代码]中引入L2Dwidget.js即可.<!-- 右下角live2d效果 --> <script src="https://eqcn.ajz.mie ...

  9. 2019HDU多校第一场 String 贪心

    题意:给你一个字符串,问是否存在一个长度为m的子序列,子序列中对应字符的数目必须在一个范围内,问是否存在这样的字符串?如果存在,输出字典序最小的那个. 思路:贪心,先构造一个序列自动机,序列自动机指向 ...

  10. Python第一章概述与环境安装

    Python简介 Python是一种计算机程序设计语言.是一种动态的.面向对象的脚本语言,最初被设计用于编写自动化脚本(shell),随着版本的不断更新和语言新功能的添加,越来越多被用于独立的.大型项 ...