题目链接: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. IBM开发者 JSON 教程

    在异步应用程序中发送和接收信息时,可以选择以纯文本和 XML 作为数据格式.掌握 Ajax 的这一期讨论另一种有用的数据格式 JavaScript Object Notation(JSON),以及如何 ...

  2. PHP JS HTML ASP页面跳转代码 延时跳转代码

    1.PHP延时跳转代码 //跳转到浏览界面 header("Refresh:1;url=machine_list.php"); //不延时 <?php header(&quo ...

  3. 開賣!下集 -- ASP.NET 4.5 專題實務(II)-範例應用與 4.5新功能【VB/C# 雙語法】

    開賣!下集 -- ASP.NET 4.5 專題實務(II)-範例應用與 4.5新功能[VB/C# 雙語法] 我.....作者都沒拿到書呢! 全台灣最專業的電腦書店 -- 天瓏書局 已經開賣了! 感謝天 ...

  4. 正确打印含unicode字符的dict

    python中,dict 对象转换为类似为 \UXXXX 的格式:这种格式英文称为 code point,完全看不懂:当然,也可以通过这个网站来转换 http://rishida.net/tools/ ...

  5. Requests:Python HTTP Module学习笔记(二)(转)

    在上一篇日志中对Requests做了一个整体的介绍,接来下再介绍一些高级的用法,主要资料还是翻译自官网的文档,如有错漏,欢迎指正. 参考资料:http://docs.python-requests.o ...

  6. sublime text 3 设置

    最近开始用sublime text 3,查资料总结了一下常用的设置,记录下以备用,同时也希望能改大家带来方便 0.使用package control安装,点前边超链接,复制左侧代码到console,回 ...

  7. WPF动画 storyboard

    <Window x:Class="StoryBoard.MainWindow" xmlns="http://schemas.microsoft.com/winfx/ ...

  8. Java入门到精通——调错篇之解决MyEclipse 输入注册码后:Enter or update your subscription information.问题

    这几天,我用MyEclipse做例子的时候总是出现下面图上面的提示: 不用看就是注册码到期了要注册.找了好几个注册码总是出现Enter or update your subscription info ...

  9. Linux内核学习笔记——VFS

    概念: ①硬链接:若一个 inode 号对应多个文件名,则称这些文件为硬链接.即硬链接就是同一个文件使用了多个别名.硬链接可由命令 link 或 ln 创建. 其特性: 文件有相同的 inode 及 ...

  10. android 连续点击退出程序

    package com.test.twiceexit; import java.util.Timer; import android.app.Activity;import android.os.Bu ...