Codeforces Round #283 (Div. 2) C

Source: Internet
Author: User

/** *  @brief  Codeforces Round  #283   (div. 2)  c *  @file   c.cpp *  @author  mianma *  @created  2014/12/22 13:38 *  @edited   2014/12/22 13:38 *  @type  greedy *  @time  cost time o (M *n)  *  @mem   cost mem  2*MAXN^2 + 2*MAXN *  @note  */ #include  <fstream> #include  <iostream> #include  <cstring> #include  < vector>using namespace std; #define &NBSP;MAX (a, b)    ((a)  >  (b)  ?   (a)  :  (b)) #define &NBSP;MIN (A, b)    ((a)  >  (b)  ?  (b)   :  (a))   #define &NBSP;ABS (a)       ((a)  >  0     (a)  :  (0 -  (a))) #define &NBSP;CLR (VEC)    memset (vec, 0,  sizeof (VEC)) #ifdef  debugifstream in;ofstream out; #define  cin in#define cout out#else#define cin  cin#define COUT cout#endif#define MAXN 110char table[MAXN][MAXN];      /*store input string*/int record[maxn][maxn];     /* record row status */int status1[maxn];           /*curr row ' s substring is the same with the prev row* /int status2[maxn];               int n, m;int ans = 0;int *curr = status1;int *old  =  status2;int main (void) {#ifdef  debug    freopen ("./in",  "R",  stdin)     freopen ("./out",  "W",  stdout); #endif     scanf ("%d %d ",  &n, &m);     for (int i = 0; i < n; i++)     &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SCANF ("%s",  table[i]);     for (int i = 1;  i < n; i++)         for (int j =  0; j < m; j++)              record[i][j] = table[i][j] - table[i - 1][j];    for (int  col = 0; col < m; col++) {         int fail = 0;        for (int row =  1; row < n; row++) {             /*substring is the same with the prev row*/             if (0 == old[row]) {                 if (record[row][col] > 0)                          curr[row] = 1;                 else if (record[row][col] < 0) {                         fail =  1;                         break;                 }else                     curr[row] = 0;             }else                     curr[row] = 1;        }         if (!fail) {#ifdef  DEBUG         printf ("col %d insert\n",  col);         printf ("bmp new:\n");         for (int j = 1; j  < n; j++)             printf ("%d   ",  curr[j]);         printf (" \ n "); #endif              int * tmp = curr;             curr = old;             old = tmp;            ++ans;         }    }    printf ("%d\n ",  m - ans);     return 0;}


Codeforces Round #283 (Div. 2) C

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.