View Code

 1 #include<stdio.h> 2 #include<string.h> 3 int main() 4 { 5     long i,j,n,g,s,t,a[1001],b[1001]; 6     char str[8001];//这里数组开大一点 第一次RT了 数比较大 7     while(scanf("%ld", &n)&&n) 8     { 9         s = 0;10         t = 0;11         int flag = 1;12         scanf("%d", &a[0]);13         for(i = 1 ; i < n ; i++)14             {15                 scanf("%ld",&a[i]);16                 b[i] = a[i]-a[i-1];17             }18         for(g = 2 ; g <= n ; g++)19         {                20             scanf("%d", &a[0]);            21             for(j = 1  ;j < n ; j++)22             {23                 scanf("%d", &a[j]);24                 if(b[j]!=a[j]-a[j-1])25                 {26                     flag = 0;27                     goto in;28                 }29             }30         }31 in:{32        for(i = g ; i <= n  ;i++)33            gets(str);34    }35         if(flag == 1)36             printf("homogeneous\n");37         else38             printf("not homogeneous\n");39     }40     return 0;41 }

这个题很容易TLE 从网上搜了下题解 找了篇比较好的 自己按照思想敲了一遍 搬这里了 也忘记出处了 就不贴原创了

Homogeneous squares

Time Limit: 1000MS Memory limit: 65536K

题目描述

Assume you have a square of size n that is divided into n×n positions just as a checkerboard. Two positions (x1,y1) and (x2,y2), where 1 ≤ x1,y1,x2,y2 ≤ n, are called "independent" if they occupy different rows and different columns, that is, x1≠x2 and y1≠y2. More generally, n positions are called independent if they are pairwise independent. It follows that there are n! different ways to choose n independent positions.

Assume further that a number is written in each position of such an n×n square. This square is called "homogeneous" if the sum of the numbers written in n independent positions is the same, no matter how the positions are chosen. Write a program to determine if a given square is homogeneous!

输入

The input contains several test cases. 
The first line of each test case contains an integer n (1 ≤ n ≤ 1000). Each of the next n lines contains n numbers, separated by exactly one space character. Each number is an integer from the interval [-1000000,1000000]
The last test case is followed by a zero.

输出

For each test case output whether the specified square is homogeneous or not. Adhere to the format shown in the sample output.

示例输入

2
1 2
3 4
3
1 3 4
8 6 -2
-3 4 0
0

示例输出

homogeneous
not homogeneous
 

转载于:https://www.cnblogs.com/shangyu/archive/2012/03/25/2416277.html

POJ2941 SDUT2371Homogeneous squares相关推荐

  1. R语言层次聚类:通过内平方和(Within Sum of Squares, WSS)选择最优的聚类K值、以内平方和(WSS)和K的关系并通过弯头法(elbow method)获得最优的聚类个数

    通过内平方和(Within Sum of Squares, WSS)选择最佳的聚类K值.以内平方和(WSS)和K的关系并通过弯头法(elbow method)获得最佳的聚类个数 目录

  2. R构建加权最小二乘回归模型(Weighted Least Squares Regression)

    R构建加权最小二乘回归模型(Weighted Least Squares Regression) 目录 R构建加权最小二乘回归模型(Weighted Least Squares Regression)

  3. 数学知识--Methods for Non-Linear Least Squares Problems(第三章)

    Methods for Non-Linear Least Squares Problems 非线性最小二乘问题的方法 2nd Edition, April 2004 K. Madsen, H.B. N ...

  4. 数学知识--Methods for Non-Linear Least Squares Problems(第二章)

    Methods for Non-Linear Least Squares Problems 非线性最小二乘问题的方法 2nd Edition, April 2004 K. Madsen, H.B. N ...

  5. 数学知识--Methods for Non-Linear Least Squares Problems(第一章)

    Methods for Non-Linear Least Squares Problems 非线性最小二乘问题的方法 2nd Edition, April 2004 K. Madsen, H.B. N ...

  6. [LeetCode]Perfect Squares

    题目链接:Perfect Squares 题目内容: Given a positive integer n, find the least number of perfect square numbe ...

  7. 4kyu Sums of Perfect Squares

    4kyu Sums of Perfect Squares 题目背景: The task is simply stated. Given an integer n (3 < n < 109) ...

  8. POJ - 2002 Squares 数正方形【二分】【哈希表】

    Squares POJ - 2002 题意 平面上有N个点,任取4个点,求能组成正方形的不同组合方式有多少种:相同的四个点,不同顺序构成的正方形视为同一正方形 分析 做法1 先枚举两个点,通过计算得到 ...

  9. OpenCV长方形squares探测器的实例(附完整代码)

    OpenCV长方形squares探测器的实例 OpenCV长方形squares探测器的实例 OpenCV长方形squares探测器的实例 #include "opencv2/core.hpp ...

最新文章

  1. 爬虫之requests模块在headers参数中携带cookie发送请求
  2. 返璞归真的Open×××的p2p模式
  3. linux安装篇之mongodb安装及服务自启动配置
  4. 设置UITextField占位符的颜色和字体
  5. import cv2时ImportError: libjasper.so.1: cannot open shared object file: No such file or directory
  6. lseek函数的使用
  7. python读取matlab数据_详解如何在python中读写和存储matlab的数据文件(*.mat)
  8. 前端见微知著AngularJS备忘篇:温故而知新,可以为师矣
  9. FFmpeg总结(六)AV系列结构体之AVPacket
  10. 高等代数(邱维声):高等代数的研究对象
  11. 搭建自己的服务器代理 yyds
  12. python爬取加密qq空间_Python爬取qq空间说说
  13. 现货交易、远期合同交易和期货交易
  14. 一个优秀的UI界面应该是什么样的
  15. stm32f103VCT6全新机器 做stm32开发板 原理图以及主要器件规格书
  16. MAYA打造复古风书房一角场景模型-3D建模场景模型教程
  17. 这 30 款 IDEA 宝贝插件 yyds
  18. 北京,有2000万人假装在生活
  19. postman项目接口文档和登录步骤原理
  20. 机器人关节角qq评估关节角速度qv---高增益观测器

热门文章

  1. python socket多线程 获取朋友列表_python socket多线程通讯实例分析(聊天室)
  2. php 链接文件名_7、php-fpm进程管理
  3. 16进制数组转成10进制 qt_QT 十六进制字符串转化为十六进制编码
  4. mysql 分词搜索_实战 | canal 实现Mysql到Elasticsearch实时增量同步
  5. ggplot2中显示坐标轴_R可视化08|ggplot2图层标度图层(scale layer)图例篇
  6. python逐行写入excel_快来看看Python如何玩转Excel
  7. unsafehelper java_Java 9中将移除 Sun.misc.Unsafe
  8. 【渝粤题库】陕西师范大学202011 微观经济学 作业 (专升本、高起本)
  9. 单片机、ARM、DSP与CPU之间的关系大揭秘
  10. ZigBee网络架构详解