CF:Problem 426B - Sereja and Mirroring 二分或者分治
这题解法怎么说呢,由于我是把行数逐步除以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 二分或者分治的更多相关文章
- Codeforces Round #243 (Div. 2) Problem B - Sereja and Mirroring 解读
http://codeforces.com/contest/426/problem/B 对称标题的意思大概是.应当指出的,当线数为奇数时,答案是线路本身的数 #include<iostream& ...
- B. Sereja and Mirroring
B. Sereja and Mirroring time limit per test 1 second memory limit per test 256 megabytes input stand ...
- 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 ...
- fzu Problem - 2232 炉石传说(二分匹配)
题目链接:http://acm.fzu.edu.cn/problem.php?pid=2232 Description GG学长虽然并不打炉石传说,但是由于题面需要他便学会了打炉石传说.但是传统的炉石 ...
- CF 483B. Friends and Presents 数学 (二分) 难度:1
B. Friends and Presents time limit per test 1 second memory limit per test 256 megabytes input stand ...
- CF 314 E. Sereja and Squares
E. Sereja and Squares http://codeforces.com/contest/314/problem/E 题意: 给你一个擦去了部分左括号和全部右括号的括号序列,括号有25种 ...
- Problem: Query on the tree(二分+划分树)
题目链接: Problem: Query on the tree Time limit: 1s Mem limit: 64 MB Problem Description There ...
- CF 551E. GukiZ and GukiZiana [分块 二分]
GukiZ and GukiZiana 题意: 区间加 给出$y$查询$a_i=a_j=y$的$j-i$最大值 一开始以为和论文CC题一样...然后发现他带修改并且是给定了值 这样就更简单了.... ...
- CF 1073C Vasya and Robot(二分答案)
C. Vasya and Robot time limit per test 1 second memory limit per test 256 megabytes input standard i ...
随机推荐
- 设计模式之建造者模式(php实现)
github地址:https://github.com/ZQCard/design_pattern/** * 建造者模式 * 将一个复杂对象的建造与调用者分离.调用者只需要给出指定对象的类型和内容,建 ...
- JavaScript入门:006—JS函数的定义
JS函数的声明. 声明函数的格式例如以下: function 函数名(參数列表){ //函数语句: return 返回值; } 来看详细的函数声明.1.普通函数 <script type=&qu ...
- hibernate的 lazy 和 fetch 一般配置
fetch 和 lazy 配置用于数据的查询 lazy 参数值常见有 false 和 true,Hibernate3 映射文件中默认lazy = true : fetch 指定了关联对象抓取的方式,参 ...
- 【AS3 Coder】任务五:Flash 2D游戏的第二春(中)
在上一节中,我们介绍了如何构建我们小小的90度角RPG游戏的背景,在这一节中我将为列位带来重头戏部分,隆重介绍我们的主角及NPC登场,噔噔噔噔……掌声在哪里?! 额,没听到掌声,罢了,直接开场吧. 本 ...
- 获取本机IP,用户代理
1.获取本机IP:http://httpbin.org/ip 2.获取用户代理 https://httpbin.org/user-agent https://httpbin.org/ httpbin( ...
- 2017.7.25 jqGrid在编辑态无法获取数据,得到的是html代码
页面如下: 勾选555之后,点击下方的删除按钮,调用如下代码: 最终调用的是jqGrid的getRowData()方法: 但是运行时发现,无法获取key的值,也就无法正确删除了.获取到的是html代码 ...
- Ubuntu启动sshd服务
1.Ubuntu主机安装ssh相关服务 openssh-client openssh-server 方法: sudo apt-get install openssh-client openssh-se ...
- [Unit Testing] Mock a Node module's dependencies using Proxyquire
Sometimes when writing a unit test, you know that the module you're testing imports a module that yo ...
- Android中IntentService详解
简单说,IntentService是继承于Service并处理异步请求的一个类,在IntentService内有一个工作线程来处理耗时操作,启动IntentService的方式和启动传统Service ...
- 倍福TwinCAT(贝福Beckhoff)基础教程2.1 TwinCAT常见类型简介
常见数据类型可以参考EXCEL表格的内容,在准备值中输入非法数据,然后回车会有错误提示(例如BYTE数据输入256) 右击可以切换二进制或十进制显示,wData5可以被挨个采集每个位上的数据,也可 ...