CF 711B - Chris and Magic Square】的更多相关文章

挺简单的一道题,但是做的时候没想好就开始写代码了,导致迷之WA,还是要多练习啊. #include <iostream> #include <cstdio> #include <algorithm> #include <queue> #include <set> #define LL long long int using namespace std; LL Map[][]; int main() { cin.sync_with_stdio(fa…
题目链接:http://codeforces.com/problemset/problem/711/B 题目大意: 输入 n ,输入 n*n 的矩阵,有一个占位 0 , 求得将 0 位置换成其他的整数 使得矩阵 行列斜 和全部相等. 代码状态: 一把辛酸泪 2016.09.24 8:14 再次更新  DOWN [昨天晚上的‘杯具’要谨记,做题要看懂题,看清题的要求再做,切记.切记.切记] 补解题思路: 1. 1.1 先特殊判断 n 是否==1,如果等于 1 则直接输出 1 即可 1.2 如果 n…
题意:给定n*n个矩阵,其中只有一个格子是0,让你填上一个数,使得所有的行列的对角线的和都相等. 析:首先n为1,就随便填,然后就是除了0这一行或者这一列,那么一定有其他的行列是完整的,所以,先把其他的算出来,然后再作差就算这个数了, 然后再去验证其他的对不对就好了.除了n为1,其他的都是唯一解应该.或者没有. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #i…
题目链接: http://codeforces.com/problemset/problem/711/B 题目大意: N*N的矩阵,有且只有一个0,求要把这个矩阵变成幻方要填什么正数.无解输出-1.幻方是每一行每一列和两条主对角线的和都相等. 题目思路: [模拟] 题目没看清外加爆intWA了好多次..罪过. 求出每一行每一列和对角线的和,为0的那个用随意一行的和扣去0的那一行就可以得到.只要验证其余的是否都相等即可. // //by coolxxx //#include<bits/stdc++…
简单题. 找一个不存在$0$的行,计算这行的和(记为$sum$),然后就可以知道$0$那个位置应该填的数字(记为$x$). 如果$x<=0$,那么无解,否则再去判断每一行,每一列以及两个斜对角的和是否均为$sum$.需要注意的是$n=1$的时候,直接输出$1$就可以了. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #in…
题目大意:在num[i][j]==0处填一个数使每行,每列,对角线的和相同,若果有多种答案输出一种. 题目思路:模拟 #include<iostream> #include<algorithm> #include<cstring> #include<vector> #include<stdio.h> #include<stdlib.h> #include<queue> #include<math.h> #inc…
题目链接: B. Chris and Magic Square 题意: 问在那个空位子填哪个数可以使行列对角线的和相等,就先找一行或者一列算出那个数,再验证是否可行就好; AC代码: #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <bits/stdc++.h> #includ…
B. Chris and Magic Square 题目连接: http://www.codeforces.com/contest/711/problem/B Description ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a n × n magic grid on the entrance which is filled with integers. Chris notice…
Chris and Magic Square 题目链接: http://codeforces.com/contest/711/problem/B Description ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a n × n magic grid on the entrance which is filled with integers. Chris noticed that…
ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a n × n magic grid on the entrance which is filled with integers. Chris noticed that exactly one of the cells in the grid is empty, and to enter Udayland, they need to fi…
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output   ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a n × n magic grid on the entrance which is filled with in…
[题目链接]:http://codeforces.com/contest/711/problem/B [题意] 让你在矩阵中一个空白的地方填上一个正数; 使得这个矩阵两个对角线上的和; 每一行的和,每一列的和都相同; [题解] 对于n=1的情况,任意输出一个数字就好; 对于n>1的情况; 先算出不包括空白格子的行的所有元素的和->he; 然后对于其他的可行的行和列,算出它们的和; 一旦与he不一样,直接输出-1无解; 然后包括空白格子的行和列,它们除了那个空白格子的和也要相同->设为sp…
题目:在网格某一处填入一个正整数,使得网格每行,每列以及两条主对角线的和都相等 题目链接:http://codeforces.com/contest/711/problem/B 分析:题目不难,找到要填的那个数填进去,然后循环比较每行每列以及对角线的和是否相等,题目提交上去卡了几次要注意几点 注意:1.答案数据范围$1\leq x \leq 1e18$,要用 long long 2.特殊情况,$n \equiv 1$时,由于一定有要填的数,所以一定有解 3.反正就是要注意看清楚题目和数据边界情况…
Xtreme8.0 - Magic Square 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/magic-square Description Johnny designed a magic square (square of numbers with the same sum for all rows, columns and diagonals i.e. both the main di…
Little Elephant loves magic squares very much. A magic square is a 3 × 3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square,…
Magic Square Time Limit: 2 Seconds      Memory Limit: 65536 KB In recreational mathematics, a magic square of n-degree is an arrangement of n2 numbers, distinct integers, in a square, such that the n numbers in all rows, all columns, and both diagona…
  Little Elephant loves magic squares very much. A magic square is a 3 × 3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic squar…
Olya and magical square - 竞赛题解 借鉴了一下神犇tly的博客QwQ(还是打一下广告) 终于弄懂了 Codeforces 传送门 『题目』(直接上翻译了) 给一个边长为 \(2^n(n>0)\) 的正方形,你需要对它进行恰好 \(k(k>0)\) 次"剪切","剪切"的方法是:选取一个边长不为 \(1\) 的正方形,将它剪成 \(4\) 个大小相同的正方形,不能挪动位置. 要求在 \(k\) 次操作后存在一条路径:从左下角的正方…
题目链接:http://codeforces.com/problemset/problem/366/E 题意:给出一个n*m的数字矩阵A,每个矩阵元素的范围[1,K].给出一个长度为s的数字串B,B的每个元素的范围[1,K].将B中的每个元素t用A中的一个位置(i,j)代替,满足A[i][j]=B[t].这样就得到一个长度为s的位置序列.定义相邻两个位置的距离为曼哈顿距离,定义序列的最大距离为每两个相邻元素距离最大值.求一种替换方案使得序列的最大距离最大. 思路:最后转化成两个位置集合S1,S2…
http://codeforces.com/contest/366/problem/E |x1-x2|+|y1-y2|有四种情况 1.-(x1-x2)+(y1-y2); 2.(x1-x2)-(y1-y2); 3.-(x1-x2)-(y1-y2); 4.(x1-x2)+(y1-y2); 可以先把没一个数的坐标分为上面的四种情况存起来,然后在S序列相邻的两个数的曼哈顿距离最大就是两个数中的一个数的四种情况最大值减去另一个数的最小值. #include <cstdio> #include <c…
题目:http://codeforces.com/problemset/problem/366/E 事实上就是找 n * m 矩阵中数字 x 和 数字 y 的最远距离. 方法參照武森的论文<浅谈信息学中的"0"和"1"> 先约定符号:xi,xj  (i,j)是x的下标,当然.矩阵中的值是能够反复的 上面是武森的论文原文.加上我之前的符号约定,我在做点解释: 事实上那个max={四种可能}  更好的写法是: |xi-yi|+|xj-yj|=max((1),…
A. Bus to Udayland time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The…
Problem Description There is a matrix of size R rows by C columns. Each element in the matrix is either '0' or '1'. A square is called magic square if it meets the following three conditions.The elements on the four borders are all '1'.Inside the squ…
A 3 x 3 magic square is a 3 x 3 grid filled with distinct numbers from 1 to 9 such that each row, column, and both diagonals all have the same sum. Given an grid of integers, how many 3 x 3 "magic square" subgrids are there?  (Each subgrid is co…
A 3 x 3 magic square is a 3 x 3 grid filled with distinct numbers from 1 to 9 such that each row, column, and both diagonals all have the same sum. Given an grid of integers, how many 3 x 3 "magic square" subgrids are there?  (Each subgrid is co…
A 3 x 3 magic square is a 3 x 3 grid filled with distinct numbers from 1 to 9 such that each row, column, and both diagonals all have the same sum. Given an grid of integers, how many 3 x 3 "magic square" subgrids are there?  (Each subgrid is co…
开头 这是每周比赛中的第一道题,博主试了好几次坑后才勉强做对了,第二道题写的差不多结果去试时结果比赛已经已经结束了(尴尬),所以今天只记录第一道题吧 题目原文 Magic Squares In Grid A 3 x 3 magic square is a 3 x 3 grid filled with distinct numbers from 1 to 9 such that each row, column, and both diagonals all have the same sum.…
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3752 访问. 3 x 3 的幻方是一个填充有从 1 到 9 的不同数字的 3 x 3 矩阵,其中每行,每列以及两条对角线上的各数之和都相等. 给定一个由整数组成的 m * n 矩阵,其中有多少个 3 × 3 的 "幻方" 子矩阵?(每个子矩阵都是连续的). 输入: [[4,3,8,4],       [9,5,1,9],       [2,7,6,2]…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 利用河图规律 暴力解法 日期 题目地址:https://leetcode.com/problems/magic-squares-in-grid/description/ 题目描述 A 3 x 3 magic square is a 3 x 3 grid filled with distinct numbers from 1 to 9 such tha…
A ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has nrows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chr…