zoukankan      html  css  js  c++  java
  • codeforces 1151 B

    codeforces 1151  B

    codeforces 1151  B  1600fen

    题意:n*m的矩阵,问能否从n行中每行选一个数 异或 大于0

    解析:刚开始看没思路,想用dfs跑一遍,看到500的时候打消了这个念头(500^500),

    其实很简单,随便找一组数据,让他们异或好,结果是零的话,只要存在每行存在与挑选的那个数不相等的就可以了(不相等的数异或不为0)

     1 #include <iostream>
     2 #include <cmath>
     3 #include <cstdio>
     4 #include <cstring>
     5 #include <string>
     6 #include <map>
     7 #include <iomanip>
     8 #include <algorithm>
     9 #include <queue>
    10 #include <stack>
    11 #include <set>
    12 #include <vector>
    13 const int maxn = 500+5;
    14 #define ll long long
    15 #define MAX INT_MAX
    16 #define FOR(i,a,b) for( int i = a;i <= b;++i)
    17 using namespace std;
    18 int n,m,temp,ki,kj;
    19 int a[maxn][maxn];
    20 int main()
    21 {
    22 //    freopen("D:\common_text\code_stream\in.txt","r",stdin);
    23 //    freopen("D:\common_text\code_stream\out.txt","w",stdout);
    24     cin>>n>>m;
    25     for(int i=1;i<=n;++i)
    26     {
    27         for(int j=1;j<=m;++j)
    28         {
    29             cin>>a[i][j];
    30         }
    31     }
    32     temp=a[1][1];
    33     for(int i=2;i<=n;++i)
    34     {
    35         temp^=a[i][1];
    36     }
    37     if(temp>0)
    38     {
    39         cout<<"TAK"<<endl;
    40         FOR(i,1,n)
    41         {
    42             cout<<1<<" ";
    43         }
    44         return 0;
    45     }
    46     else
    47     {
    48         for(int i=1;i<=n;i++)
    49         {
    50             for(int j=2;j<=m;++j)
    51             {
    52                 if(a[i][j]!=a[i][1])
    53                 {
    54                     ki=i;
    55                     kj=j;
    56                     cout<<"TAK"<<endl;
    57                     for(int i=1;i<=n;++i)
    58                     {
    59 
    60                         if(i==ki)
    61                             cout<<kj<<" ";
    62                         else cout<<1<<" ";
    63 
    64                     }
    65                     return 0;
    66                 }
    67 
    68             }
    69 
    70         }
    71         cout<<"NIE"<<endl;
    72     }
    73 }
  • 相关阅读:
    hdu2653 Waiting ten thousand years for Love
    Request
    freetextbox 使用方法+下载
    格式化字符串 GridView DataFormatString
    GridView 中的button LinkButton 事件 CommandName
    Response 缓存
    Windows 7下VS2008升级
    ASP.NET中备份SQL Server数据库的方法
    asp.net和c#实现定时备份数据库(SQL Server2000)
    asp.net 中保存 数据库几种对象
  • 原文地址:https://www.cnblogs.com/jrfr/p/10786819.html
Copyright © 2011-2022 走看看