CF_127E reader Display
2015-09-09 00:39
323 查看
这道题其实找到规律之后其实不难,和破损的键盘一样,都有点递推转移的感觉
题意:
你可以进行这样一次操作:选一个点,然后把这个点横切竖切直到正对角线上面的点,全部翻转过来,问你要进行多少次操作才能把所有的点都翻转过来
思路:
多次模拟之后可以发现最右上方的点仅能是选择自己才能翻转,之后与这个相邻的点变成了两个最右上方,而这两个点和刚才那个点一样仅能由自己翻转
还有一个要注意的这个只能影响对角线一侧的
所以只要在对角线一侧一直从最右边上到下遍历翻转就好了
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
Output
题意:
你可以进行这样一次操作:选一个点,然后把这个点横切竖切直到正对角线上面的点,全部翻转过来,问你要进行多少次操作才能把所有的点都翻转过来
思路:
多次模拟之后可以发现最右上方的点仅能是选择自己才能翻转,之后与这个相邻的点变成了两个最右上方,而这两个点和刚才那个点一样仅能由自己翻转
还有一个要注意的这个只能影响对角线一侧的
所以只要在对角线一侧一直从最右边上到下遍历翻转就好了
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; }
相关文章推荐
- 笔记-大话设计模式-20 迭代器模式
- 创业的第三十五天
- [LinkerScript.14] SECTION命令: Output Section Description
- 如何使用v7新控件RecyclerView
- 解决Win7&Win8 64位下Source Insight提示未完整安装的问题
- 速达3000 数据库备份文件分析
- centos7 修改selinux 开机导致 faild to load SELinux policy freezing 错误
- linux 计划任务
- C/C++基本数据类型及字长 (经常忘)
- 我就攒着几个网站(吃饱了就会更新)
- 【Unity3D_常用模块】 事件管理器
- 笔记-大话设计模式-19 组合模式
- jquery 简单实用的Tab切换
- windows下mysql5.1忘记root密码解决方法[win7]
- 加速Android Studio/Gradle构建
- hashCode
- Linq 杂记(读书笔记)
- Android采用ListView实现数据列表显示1-使用SimpleCursorAdapter进行数据绑定
- unity3d插件
- Unity 模型的制作规范