zoukankan      html  css  js  c++  java
  • #7 //[CQOI2014]和谐矩阵

    题解:

    bitset优化高斯消元

    无关变量为1

    #include <bits/stdc++.h>
    using namespace std;
    #define eps 1e-9
    #define N 1610
    bitset<N> a[N];
    int n;
    void Gause()
    {
      for (int i=0;i<n;i++)
      {
        int now=i;
        for (int j=i;j<n;j++)
          if (a[j][i]>a[now][i]) now=j;
        if (a[now][i])
        {
          swap(a[i],a[now]);
          for (int j=0;j<n;j++)
            if (j!=i&&a[j][i]) a[j]^=a[i];
        } else
        {
          for (int j=0;j<n;j++)
            if (a[j][i]) a[j][i]=0,a[j][n]=a[j][n]^1;
        }
      }
    }
    #define js(x,y) (x-1)*m1+y-1
    #define pd(x,y) if (x>=1&&x<=n1&&y>=1&&y<=m1)
    int dx[5]={0,1,0,-1,0};
    int dy[5]={0,0,1,0,-1};
    int main()
    {
      freopen("noi.in","r",stdin);
      freopen("noi.out","w",stdout);
      std::ios::sync_with_stdio(false);
      int n1,m1;
      cin>>n1>>m1;
      n=n1*m1;
      for (int i=1;i<=n1;i++)
        for (int j=1;j<=m1;j++)
          for (int k=0;k<=4;k++)
            pd(i+dx[k],j+dy[k])
            {
              a[js(i,j)][js(i+dx[k],j+dy[k])]=1;
            }
      Gause();
      for (int i=1;i<=n1;i++)
      {
        for (int j=1;j<=m1;j++)
        {
          int x=js(i,j);
          if (!a[x][x]|a[x][n]) cout<<1<<" ";
          else cout<<0<<" ";
        }
        cout<<endl;
      }
      return 0;
    }
  • 相关阅读:
    起泡排序引申出的问题
    关于NPC和NP-Hard问题
    我的书单(更新中)
    OpenCV2学习笔记03:Qt中配置OpenCV环境
    Ubuntu 14.04为浏览器添加Flash插件
    CSS3基础
    HTML5进阶
    拖拽上传及读取文件实现
    生产者消费者模型
    进程
  • 原文地址:https://www.cnblogs.com/yinwuxiao/p/8911378.html
Copyright © 2011-2022 走看看