题目链接: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的更多相关文章

随机推荐

  1. Wordpress模板标签大全

    Wordpress模板基本文件 style.css 样式表文件 index.php 主页文件 single.php 日志单页文件 page.php 页面文件 archvie.php 分类和日期存档页文 ...

  2. 第十八章 数据访问(In .net4.5) 之 I/O操作

    1. 概述 本章内容包括 文件操作.流操作.读写网络数据 以及 异步I/O操作. 2. 主要内容 2.1 文件操作 ① 使用 Drive 和 DriveInfo 访问磁盘信息. DriveInfo[] ...

  3. python去掉空行

    #用strip(),split()两个方法都可以判断空行 infile=open('/.../','r') outfile=open('/.../','w') for li in infile.rea ...

  4. Python学习教程(learning Python)--3.3.1 Python下的布尔表达式

    简单的说就是if要判断condition是真是假,Python和C语言一样非0即真,所以如果if的condition是布尔表达式我们可以用True或者非0数(不可是浮点数)表示真,用False或者0表 ...

  5. book publisher and study

    http://www.apress.com/ https://pragprog.com/ https://www.packtpub.com/ http://www.howzhi.com/

  6. C 封装一个简单二叉树基库

    引文 今天分享一个喜欢佩服的伟人,应该算人类文明极大突破者.收藏过一张纸币类型如下 那我们继续科普一段关于他的简介 '高斯有些孤傲,但令人惊奇的是,他春风得意地度过了中产阶级的一生,而  没有遭受到冷 ...

  7. [转]ORACLE的ProC用法讲解

    pro*c是高级的用法,OCI是oracle的基础用法 如何编译.pc文件: proc code=cpp  parse=none iname=filename.pc oname=filename.cp ...

  8. 1084. Broken Keyboard (20)

    On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters ...

  9. 惊曝6.24AppCan移动开发大会参展名录,现场礼品超多!

    AppCan移动开发者大会召开在即, 诸位参展商准备就绪, 移动圈的半边天都来了, 现场活动和礼品多到爆炸, 请大家一一过目! 排名不分先后,AppCan不偏心! 1.极验验证 首创滑动式拼图验证码. ...

  10. poj 1383 Labyrinth

    题目连接 http://poj.org/problem?id=1383 Labyrinth Description The northern part of the Pyramid contains ...