CF_127E reader Display
这道题其实找到规律之后其实不难,和破损的键盘一样,都有点递推转移的感觉
题意:
你可以进行这样一次操作:选一个点,然后把这个点横切竖切直到正对角线上面的点,全部翻转过来,问你要进行多少次操作才能把所有的点都翻转过来
思路:
多次模拟之后可以发现最右上方的点仅能是选择自己才能翻转,之后与这个相邻的点变成了两个最右上方,而这两个点和刚才那个点一样仅能由自己翻转
还有一个要注意的这个只能影响对角线一侧的
所以只要在对角线一侧一直从最右边上到下遍历翻转就好了
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
5
01110
10010
10001
10011
11110
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的更多相关文章
- 设备管理 USB ID
发现个USB ID站点,对于做设备管理识别的小伙伴特别实用 http://www.linux-usb.org/usb.ids 附录: # # List of USB ID's # # Maintain ...
- Display PDF in browser | Acrobat, Reader XI
点这个链接查看详细的解决办法 http://helpx.adobe.com/acrobat/using/display-pdf-browser-acrobat-xi.html When you cli ...
- 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 ...
- RFID 读写器 Reader Writer Cloner
RFID读写器的工作原理 RFID的数据采集以读写器为主导,RFID读写器是一种通过无线通信,实现对标签识别和内存数据的读出和写入操作的装置. 读写器又称为阅读器或读头(Reader).查询器(Int ...
- [CareerCup] 8.5 Online Book Reader System 在线读书系统
8.5 Design the data structures for an online book reader system. 这道题OOB的题让我们设计一个在线读书系统,还是没有任何提示,所以发挥 ...
- RFID Reader 线路图收集
This 125 kHz RFID reader http://www.serasidis.gr/circuits/RFID_reader/125kHz_RFID_reader.htm http:// ...
- 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 ...
- Drag & Drop and File Reader
参考 : http://www.html5rocks.com/zh/tutorials/file/dndfiles/ http://blog.csdn.net/rnzuozuo/article/det ...
- Adobe® Reader®.插件开发
Thank you for your interest in developing a plug-in for Adobe® Reader®. To build an Adobe Reader plu ...
随机推荐
- Linux目录及说明
Linux目录及说明 [常见目录说明] 目录 /bin 存放二进制可执行文件(ls,cat,mkdir等),常用命令一般都在这里. /etc 存放系统管理和配置文件 /home 存放所有用户文件的根目 ...
- 实验报告(六)&第八周学习总结
班级 计科二班 学号 20188425 姓名 IM 完成时间2019/10/18 评分等级 实验六 Java异常 实验目的 理解异常的基本概念: 掌握异常处理方法及熟悉常见异常的捕获方法. 实验要求 ...
- 【Python—windows 下 virtualEnv 使用】
用pip安装virtualenv pip3 install virtualenv 在相应的文件夹中创建一个独立的Python运行环境,命名为env. 之后会自动创建一个 env 文件夹,有: Incl ...
- 【题解】A Horrible Poem
题目大意 给出一个由小写英文字母组成的字符串 S,再给出 q 个询问,要求回答 S 某个子串的最短循环节. 如果字符串 B 是字符串 A 的循环节,那么 A 可以由 B 重复若干次得到. 输入格式 第 ...
- Mac os x安装IDEAL及配置JDK和Maven
此文章是在已安装好IDEAL前提下进行配置jdk和maven的操作文档. 1. 下载并配置JDK及Maven Mac下载并配置JDK方法: 详见Mac安装JDK和JMeter5-安装JDK Mac下载 ...
- Ubuntu碎碎念
Ubuntu-图形界面和字符界面转换.指定默认启动界面1.按ALT+CTRL+F1切换到字符界面(Linux实体机) 如果是VMware虚拟机安装的Linux系统,则切换到字符界面的时候需要以下操作 ...
- mysql中关于--login-path使用
在控制台登陆数据库,快捷登录 在控制台连接数据库,需要每次输入账号密码,感觉很麻烦,偶然发现可以通过login-path保存信息,实现快捷登录,这里记录下. 保存账号信息 mysql_config_e ...
- Win32 API 多线程编程——一个简单实例(含消息参数传递)
Win32 API进行程序设计具有很多优点:应用程序执行代码小,运行效率高,但是他要求程序员编写的代码较多,且需要管理所有系统提供给程序的资源,要求程序员对Windows系统内核有一定的了解,会占用程 ...
- C#驱动mysql明明数值不为空却一直说DBNull.Value的诡异情况
最近遇见了一个很诡异的情况,就是当我们关联表查询时,副表如果有bit类型的字段的话,C#驱动读取该列时就会抛出“DBNull.Value不能转换为其他类型”的异常,但是我们如果拿出sql语句单独查询的 ...
- jquery实现左侧菜单 效果
html <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <ti ...