这题解法怎么说呢,由于我是把行数逐步除以2暴力得到的答案,所以有点二分的意思,可是昨天琦神说是有点像分治的意思。反正总的来说:就是从大逐步细化找到最优答案。

可是昨晚傻B了。靠!

多写了点东西,然后就错了,刚才一练习,拿昨晚的代码一看,就把6行代码删去就过了。靠!昨晚应该是脑子进水了!!!!!

昨晚的代码:

#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#define PI acos(-1.0)
#define mem(a,b) memset(a,b,sizeof(a))
#define sca(a) scanf("%d",&a)
#define sc(a,b) scanf("%d%d",&a,&b)
#define pri(a) printf("%d\n",a)
#define lson i<<1,l,mid
#define rson i<<1|1,mid+1,r
#define MM 4105
#define MN 105
#define INF 100004
#define eps 1e-7
using namespace std;
typedef long long ll;
int n,m,i,j,k,a[MN][MN];
string s,ss;
int main()
{
sc(n,m);
for(i=0; i<n; i++)
for(j=0; j<m; j++) sca(a[i][j]);
if(n&1) cout<<n<<endl;
else
{
int r=n/2,flag=1,ff=1;
int aa=a[0][0];
for(i=1; i<n; i++) //就是这个多推断了,由于自己给出的样列是1列。所以……靠。本来在以下的sum值那里已经处理了,然后忘了把这删了,所以就在第一列同样的时候出错了,导致昨晚没debug出来!嘛嘛呀。。!。
if(aa!=a[i][0])
{
ff=0;
break;
}
if(ff) cout<<1<<endl;
else
{
int sum=0;
while(r&&flag)
{
for(i=0; i<n&&flag; i+=r*2)
{
for(j=i,k=i+r+r-1; j<k&&flag; j++,k--)
{
for(int p=0; p<m&&flag; p++)
if(a[j][p]!=a[k][p])
flag=0;
}
}
if(flag&&(r%2==0)) r/=2;
if(flag&&(r&1)) sum++;
if(sum>3) break;
//cout<<"--"<<flag<<' '<<r<<endl;
}
if(!flag) cout<<r*2<<endl;
else cout<<r<<endl;
}
}
return 0;
}

AC代码:

#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#define PI acos(-1.0)
#define mem(a,b) memset(a,b,sizeof(a))
#define sca(a) scanf("%d",&a)
#define sc(a,b) scanf("%d%d",&a,&b)
#define pri(a) printf("%d\n",a)
#define lson i<<1,l,mid
#define rson i<<1|1,mid+1,r
#define MM 4105
#define MN 105
#define INF 100004
#define eps 1e-7
using namespace std;
typedef long long ll;
int n,m,i,j,k,a[MN][MN];
string s,ss;
int main()
{
sc(n,m);
for(i=0; i<n; i++)
for(j=0; j<m; j++) sca(a[i][j]);
if(n&1) cout<<n<<endl;
else
{
int r=n/2,flag=1,ff=1;
int sum=0;
while(r&&flag)
{
for(i=0; i<n&&flag; i+=r*2)
{
for(j=i,k=i+r+r-1; j<k&&flag; j++,k--)
{
for(int p=0; p<m&&flag; p++)
if(a[j][p]!=a[k][p])
flag=0;
}
}
if(flag&&(r%2==0)) r/=2;
if(flag&&(r&1)) sum++;
if(sum>3) break;
//cout<<"--"<<flag<<' '<<r<<endl;
}
if(!flag) cout<<r*2<<endl;
else cout<<r<<endl;
}
return 0;
}

CF:Problem 426B - Sereja and Mirroring 二分或者分治的更多相关文章

  1. Codeforces Round #243 (Div. 2) Problem B - Sereja and Mirroring 解读

    http://codeforces.com/contest/426/problem/B 对称标题的意思大概是.应当指出的,当线数为奇数时,答案是线路本身的数 #include<iostream& ...

  2. B. Sereja and Mirroring

    B. Sereja and Mirroring time limit per test 1 second memory limit per test 256 megabytes input stand ...

  3. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案 - 动态规划

    There are n people and k keys on a straight line. Every person wants to get to the office which is l ...

  4. fzu Problem - 2232 炉石传说(二分匹配)

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=2232 Description GG学长虽然并不打炉石传说,但是由于题面需要他便学会了打炉石传说.但是传统的炉石 ...

  5. CF 483B. Friends and Presents 数学 (二分) 难度:1

    B. Friends and Presents time limit per test 1 second memory limit per test 256 megabytes input stand ...

  6. CF 314 E. Sereja and Squares

    E. Sereja and Squares http://codeforces.com/contest/314/problem/E 题意: 给你一个擦去了部分左括号和全部右括号的括号序列,括号有25种 ...

  7. Problem: Query on the tree(二分+划分树)

    题目链接: Problem: Query on the tree Time limit: 1s     Mem limit: 64 MB      Problem Description There ...

  8. CF 551E. GukiZ and GukiZiana [分块 二分]

    GukiZ and GukiZiana 题意: 区间加 给出$y$查询$a_i=a_j=y$的$j-i$最大值 一开始以为和论文CC题一样...然后发现他带修改并且是给定了值 这样就更简单了.... ...

  9. CF 1073C Vasya and Robot(二分答案)

    C. Vasya and Robot time limit per test 1 second memory limit per test 256 megabytes input standard i ...

随机推荐

  1. AFNetworking 2.0 Tutorial

    Update 1/18/2014: Fully updated for iOS 7 and AFNetworking 2.0 (original post by Scott Sherwood, upd ...

  2. Multithreading and Grand Central Dispatch on iOS for Beginners Tutorial

    Have you ever written an app where you tried to do something, and there was a long pause while the U ...

  3. Android开发中多进程共享数据

    # 背景 最近在工作中遇到一个需求,需要在接收到推送的时候将推送获得的数据存起来,以供app启动时使用.我们会认为这不是So easy吗?只要把数据存到SharedPreferences中,然后让ap ...

  4. 学号20175313 《数据库MySQL(课下作业,必做)》第十周

    目录 一.题目要求 二.需求分析 三.关键代码以及运行结果截图 任务一 任务二 任务三 任务四 四.代码实现过程中遇到的问题及其解决方法 五.码云链接 六.心得体会 一.题目要求 下载附件中的worl ...

  5. eclipse 启动报错 java was started but returned code=13

    eclipse启动不了,出现“Java was started but returned exit code=13......”对话框如下 我的解决方法是:去控制面板--程序--卸载程序和功能下面查看 ...

  6. hdu2846 Repository

    //--------------------------------------------------------------- /*---字典树应用问题.考虑到要查询的次数在10^6,显然直接插入 ...

  7. zabbix_sender高效模式

    1.zabbix_sender介绍 zabbix获取key值有超时时间,如果自定义的key脚本一般需要执行很长时间,这根本没法去做监控,获取数据有超时时间,如果一些数据需要执行比较长的时间才能获取的话 ...

  8. [SCSS] Create a gradient with a Sass loop

    In this lesson, you will learn how to iteratively generate CSS selectors and attributes using Sass l ...

  9. 安装openstack 时 遇见的一些问题及解决方法!

    感谢朋友支持本博客,欢迎共同探讨交流.因为能力和时间有限,错误之处在所难免.欢迎指正! 假设转载.请保留作者信息. 博客地址:http://blog.csdn.net/qq_21398167 原博文地 ...

  10. Git版本管理

    1.显示当前工作目录 pwd 2.把当前目录初始化为git可以管理的仓库 git init 3.把文件添加到仓库 git add xxx.txt 4.告诉git,把文件提交到仓库 .-m后面输入的是本 ...