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

可是昨晚傻B了。靠!

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

昨晚的代码:

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <fstream>
  4. #include <algorithm>
  5. #include <cmath>
  6. #include <deque>
  7. #include <vector>
  8. #include <queue>
  9. #include <string>
  10. #include <cstring>
  11. #include <map>
  12. #include <stack>
  13. #include <set>
  14. #define PI acos(-1.0)
  15. #define mem(a,b) memset(a,b,sizeof(a))
  16. #define sca(a) scanf("%d",&a)
  17. #define sc(a,b) scanf("%d%d",&a,&b)
  18. #define pri(a) printf("%d\n",a)
  19. #define lson i<<1,l,mid
  20. #define rson i<<1|1,mid+1,r
  21. #define MM 4105
  22. #define MN 105
  23. #define INF 100004
  24. #define eps 1e-7
  25. using namespace std;
  26. typedef long long ll;
  27. int n,m,i,j,k,a[MN][MN];
  28. string s,ss;
  29. int main()
  30. {
  31. sc(n,m);
  32. for(i=0; i<n; i++)
  33. for(j=0; j<m; j++) sca(a[i][j]);
  34. if(n&1) cout<<n<<endl;
  35. else
  36. {
  37. int r=n/2,flag=1,ff=1;
  38. int aa=a[0][0];
  39. for(i=1; i<n; i++) //就是这个多推断了,由于自己给出的样列是1列。所以……靠。本来在以下的sum值那里已经处理了,然后忘了把这删了,所以就在第一列同样的时候出错了,导致昨晚没debug出来!嘛嘛呀。。!。
  40. if(aa!=a[i][0])
  41. {
  42. ff=0;
  43. break;
  44. }
  45. if(ff) cout<<1<<endl;
  46. else
  47. {
  48. int sum=0;
  49. while(r&&flag)
  50. {
  51. for(i=0; i<n&&flag; i+=r*2)
  52. {
  53. for(j=i,k=i+r+r-1; j<k&&flag; j++,k--)
  54. {
  55. for(int p=0; p<m&&flag; p++)
  56. if(a[j][p]!=a[k][p])
  57. flag=0;
  58. }
  59. }
  60. if(flag&&(r%2==0)) r/=2;
  61. if(flag&&(r&1)) sum++;
  62. if(sum>3) break;
  63. //cout<<"--"<<flag<<' '<<r<<endl;
  64. }
  65. if(!flag) cout<<r*2<<endl;
  66. else cout<<r<<endl;
  67. }
  68. }
  69. return 0;
  70. }

AC代码:

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <fstream>
  4. #include <algorithm>
  5. #include <cmath>
  6. #include <deque>
  7. #include <vector>
  8. #include <queue>
  9. #include <string>
  10. #include <cstring>
  11. #include <map>
  12. #include <stack>
  13. #include <set>
  14. #define PI acos(-1.0)
  15. #define mem(a,b) memset(a,b,sizeof(a))
  16. #define sca(a) scanf("%d",&a)
  17. #define sc(a,b) scanf("%d%d",&a,&b)
  18. #define pri(a) printf("%d\n",a)
  19. #define lson i<<1,l,mid
  20. #define rson i<<1|1,mid+1,r
  21. #define MM 4105
  22. #define MN 105
  23. #define INF 100004
  24. #define eps 1e-7
  25. using namespace std;
  26. typedef long long ll;
  27. int n,m,i,j,k,a[MN][MN];
  28. string s,ss;
  29. int main()
  30. {
  31. sc(n,m);
  32. for(i=0; i<n; i++)
  33. for(j=0; j<m; j++) sca(a[i][j]);
  34. if(n&1) cout<<n<<endl;
  35. else
  36. {
  37. int r=n/2,flag=1,ff=1;
  38. int sum=0;
  39. while(r&&flag)
  40. {
  41. for(i=0; i<n&&flag; i+=r*2)
  42. {
  43. for(j=i,k=i+r+r-1; j<k&&flag; j++,k--)
  44. {
  45. for(int p=0; p<m&&flag; p++)
  46. if(a[j][p]!=a[k][p])
  47. flag=0;
  48. }
  49. }
  50. if(flag&&(r%2==0)) r/=2;
  51. if(flag&&(r&1)) sum++;
  52. if(sum>3) break;
  53. //cout<<"--"<<flag<<' '<<r<<endl;
  54. }
  55. if(!flag) cout<<r*2<<endl;
  56. else cout<<r<<endl;
  57. }
  58. return 0;
  59. }

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. [置顶] python3 django models保存filefiled字段统一目录、不修改文件名的方法

    最经编写一个model时处理filefiled,使用post_form.save()进行新增和编辑文件保存位置不统一,如果出现重复文件名重复的话,上传文件名会被改名. 现有代码如下: models.p ...

  2. python获取输入参数

    python获取输入参数 学习了:https://www.cnblogs.com/angelatian/p/5832448.html import sys模块: len(sys.argv)参数个数 s ...

  3. 创建es索引{"acknowledged"=>true, "shards_acknowledged"=>false}

    创建es索引{"acknowledged"=>true, "shards_acknowledged"=>false} [2018-05-19T13: ...

  4. Windows 10 Enterprise LTSB版本

    Windows 10 Enterprise 评估版  |  90 天  Win10 企业版 LTSB版 14393.0.160715-1616.RS1_RELEASE_CLIENTENTERPRISE ...

  5. Spring中如何配置事务

    学过SSH的都知道,整合了SSH之后,SSH的经典增删改查案例业务逻辑层的代码就十分简单.基本上都是一句话的事. public void addUser(Webuserlogin user) { // ...

  6. iOS开发:Framework的创建

    转载自:http://jonzzs.cn/2017/06/01/iOS%20开发笔记/[iOS%20开发]将自己的框架打包成%20Framework%20的方法/ 环境:Xcode 8 创建 Fram ...

  7. R 安装 简单实用

    下载和安装Windows环境的R 1.进入主页,点击 蓝色加粗的 download R 2.随便点击一个镜像,这里点击的是http://mirror.fcaglp.unlp.edu.ar/CRAN/ ...

  8. charles用法详解

    Charles是目前最强大的http调试工具,在界面和功能上远强于Fiddler,同时是全平台支持,堪称圣杯级工具,唯一的缺陷是这货是收费的,而且是要¥50美元大洋…当然网上是有破解版的,鄙视下自己, ...

  9. 程序员必备SQL语句优化技巧

    1.任何地方都不要使用 select * from t ,用具体的字段列表代替"*",不要返回用不到的任何字段. 2.尽量使用数字型字段,字符型会降低查询和连接的性能,并会增加存储 ...

  10. PJISP 修改 消息头Fromto字段

    项目需求,需要修改sip信令消息头中Fromto字段,完成此功能需要修改sip库(PJSIP)源码,具体如下: PJSIP 消息头 Formto  字段默认的格式是sip:平台@平台IP地址,例如si ...