2014_GCJ_A
题目链接:http://code.google.com/codejam/contest/2984486/dashboard#s=p0
最想吐槽的是想些DFS过小数据,居然写不出来,不知道我这半年的ACM生活在干嘛?
先不说直接出最有解,但是DFS这基本的还不会,真是,估计快废了!
DFS过小数据的程序:
#include<iostream>//又臭又长,无语
#include<algorithm>
#include<math.h>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<cstdio>
int n,l;
int ans;
using namespace std;
string s[],s1[],tem[];
int b[];
int pan()
{
sort(tem+,tem+n+);
for (int i=;i<=n;i++)
if (s1[i]!=tem[i]) return ;
return ;
} void res(int x)
{
for (int i=;i<=n;i++)
tem[i][x]^=;//PS这里注意一下,字符为‘0’,或者‘1’;可以算出字符'0'^1='1','1'^1='0';
}
void rec(int x)
{
for (int i=;i<=n;i++)
tem[i][x]^=;
} void dfs(int t,int k)
{
if (t==l)
{
if (pan()) ans=min(ans,k);return; }
dfs(t+,k);
res(t);
dfs(t+,k+);
rec(t);
} int main()
{
int t;
freopen("A-small-practice.in","r",stdin);
freopen("out.txt","w",stdout);
cin>>t;
for (int o=;o<=t;o++){
ans=;
memset(b,,sizeof(b));
cout<<"Case #"<<o<<": ";
cin>>n>>l;
for (int i=;i<=n;i++) {cin>>s[i];tem[i]=s[i];}
for (int i=;i<=n;i++) cin>>s1[i];
sort(s1+,s1+n+);
dfs(,);
if (ans<)
cout<<ans<<endl;
else cout<<"NOT POSSIBLE"<<endl;
}
return ;
}
正解是:枚举第I个数,因为存在解的话肯定是A中第I个数与B第一个数相同,然后根据两者数字的不同去跟新其他位数上的数!复杂度大概是O(N*N*L);
部分代码: for (int i=1;i<=n;i++){
for (int j=;j<=n;j++) ss[j]=s[j]; int now=;
for (int j=;j<l;j++)
if (ss[][j]!=s1[i][j]){
for (int k=;k<=n;k++)
ss[k][j]^=;
now++;
} sort(ss+,ss+n+); int flag=;
for (int k=;k<=n;k++)
if (ss[k]!=s1[k]){flag=;break;}
if (!flag) ans=min(ans,now);
}
等下再做做位运算
2014_GCJ_A的更多相关文章
随机推荐
- 开源web终端ssh解决方案-gateone简介
好久都没来写博客,最近忙啥去了呢? 一是忙于saltstack的二次开发,二是云计算的学习研究中,所以就一直没写东西,今天给大家介绍个工具. 1. 首先来说一下为什么要 web ssh? 许多人不是说 ...
- AMD平台下在Windows虚拟机中安装Mac10.8.6【Written By KillerLegend】
我的电脑CPU是AMD,以前在虚拟机中装过Windows操作系统,感觉很简单,这几天想体验一下苹果系统,未来也可能会从事Mac相关软件开发,于是从早上便兴致勃勃的开始了--于是悲剧也开始了,上网各种查 ...
- 合并果子 (codevs 1063) 题解
[问题描述] 在一个果园里,多多已经将所有的果子打了下来,而且按果子的不同种类分成了不同的堆.多多决定把所有的果子合成一堆. 每一次合并,多多可以把两堆果子合并到一起,消耗的体力等于两堆果子的重量之和 ...
- How to display SSRS report based on customer/Vendor specific language [AX2012]
Common requirement is to show the reports in customer’s language. [example : Quotations, sales confi ...
- eclipse代码编辑快捷键
代码提示(代码助手):alt + / 如输入e后按alt+/,则会出现以e开头的相关方法,写代码时经常按按 删除一行代码: 光标移动到该行任意位置,按ctrl+d 剪切:ctrl+x 复制:ctrl ...
- 对Iframe和图表设置高度的优质代码
//对Iframe和图表设置高度 function f() { parent.window.setWinHeight(parent.window.document.getElementById(&qu ...
- 算法系列2《RSA》
1. RSA介绍 RSA公钥加密算法是1977年由Ron Rivest.Adi Shamirh和LenAdleman在(美国麻省理工学院)开发的.RSA取名来自开发他们三者的名字.RSA是目前最有影响 ...
- 同时执行2个存储过程,2个SP中分别有相同的临时表名,会有冲突吗?
同时执行2个存储过程,2个SP中分别有相同的临时表名,会有冲突吗?答案:不会 这就可以在以后写存储过程的时候统一临时表名了. alter procedure sp_01 as begin create ...
- spring 3 的 @value的使用
Spring 3支持@value注解的方式获取properties文件中的配置值,大大简化了我们读取配置文件的代码.使用方式如下: 1.首先必须要配置properties文件的加载bean:在spri ...
- poj 2312 Battle City
题目连接 http://poj.org/problem?id=1840 Battle City Description Many of us had played the game "Bat ...