Tuesday, September 29, 2015

UVa 11055 - Homogeneous squares

Accepted date: 2015-09-29
Ranking (as of 2015-09-29): 10 out of 412
Language: C++

/*
  UVa 11055 - Homogeneous squares

  To build using Visual Studio 2012:
    cl -EHsc -O2 UVa_11055_Homogeneous_squares.cpp
*/

#include <cstdio>

const int n_max = 1000;
int diffs[n_max];

int main()
{
  while (true) {
    int n;
    scanf("%d", &n);
    if (!n)
      break;
    bool homogeneous = true;
    int i, j, k, pk;
    for (j = 0; j < n; j++, pk = k) {
      scanf("%d", &k);
      if (j)
        diffs[j] = k - pk;
    }
    for (i = 1; i < n; i++) {
      for (j = 0; j < n && homogeneous; j++, pk = k) {
        scanf("%d", &k);
        if (j && k - pk != diffs[j])
          homogeneous = false;
      }
      for ( ; j < n; j++)
        scanf("%*d");
    }
    puts((homogeneous) ? "homogeneous" : "not homogeneous");
  }
  return 0;
}

No comments:

Post a Comment