题目:在网格某一处填入一个正整数,使得网格每行,每列以及两条主对角线的和都相等 题目链接:http://codeforces.com/contest/711/problem/B 分析:题目不难,找到要填的那个数填进去,然后循环比较每行每列以及对角线的和是否相等,题目提交上去卡了几次要注意几点 注意:1.答案数据范围$1\leq x \leq 1e18$,要用 long long 2.特殊情况,$n \equiv 1$时,由于一定有要填的数,所以一定有解 3.反正就是要注意看清楚题目和数据边界情况…
题目链接: B. Chris and Magic Square 题意: 问在那个空位子填哪个数可以使行列对角线的和相等,就先找一行或者一列算出那个数,再验证是否可行就好; AC代码: #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <bits/stdc++.h> #includ…
[题目链接]:http://codeforces.com/contest/711/problem/B [题意] 让你在矩阵中一个空白的地方填上一个正数; 使得这个矩阵两个对角线上的和; 每一行的和,每一列的和都相同; [题解] 对于n=1的情况,任意输出一个数字就好; 对于n>1的情况; 先算出不包括空白格子的行的所有元素的和->he; 然后对于其他的可行的行和列,算出它们的和; 一旦与he不一样,直接输出-1无解; 然后包括空白格子的行和列,它们除了那个空白格子的和也要相同->设为sp…
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/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…
题目链接: http://codeforces.com/problemset/problem/711/B 题目大意: N*N的矩阵,有且只有一个0,求要把这个矩阵变成幻方要填什么正数.无解输出-1.幻方是每一行每一列和两条主对角线的和都相等. 题目思路: [模拟] 题目没看清外加爆intWA了好多次..罪过. 求出每一行每一列和对角线的和,为0的那个用随意一行的和扣去0的那一行就可以得到.只要验证其余的是否都相等即可. // //by coolxxx //#include<bits/stdc++…
题意:给定n*n个矩阵,其中只有一个格子是0,让你填上一个数,使得所有的行列的对角线的和都相等. 析:首先n为1,就随便填,然后就是除了0这一行或者这一列,那么一定有其他的行列是完整的,所以,先把其他的算出来,然后再作差就算这个数了, 然后再去验证其他的对不对就好了.除了n为1,其他的都是唯一解应该.或者没有. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #i…
简单题. 找一个不存在$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…
挺简单的一道题,但是做的时候没想好就开始写代码了,导致迷之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…
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…
题目链接:http://www.codeforces.com/problemset/problem/1/A题意:至少用多少块边长为a的方块铺满NxM的矩形区域.C++代码: #include <iostream> using namespace std; int main() { long long n, m, a; cin >> n >> m >> a; cout << ((n+a-)/a) * ((m+a-)/a); ; } C++…
题目链接:https://cn.vjudge.net/problem/CodeForces-894B Ralph has a magic field which is divided into n × m blocks. That is to say, there are n rows and m columns on the field. Ralph can put an integer in each block. However, the magic field doesn't alway…
894B - Ralph And His Magic Field 思路: 当k为1时,如果n和m奇偶性不同,那么没有答案. 可以证明,在其他情况下有答案,且答案为2^(n-1)*(m-1),因为前n-1行和m-1列确定后,最后一列和最后一行可以确定,且确定的最后一格不矛盾. 可以采用在全为1的格子中把一些1换成-1的方法来证明以上两条结论. 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define…
从今天開始.就要在Codeforces里有一个新的開始了,貌似任务非常重的说~~ Codeforces专题我将会记录全部通过的题目,事实上仅仅要通过的题目都是水题啊!. 题目大意: 依照要求计算须要多少flagstone. 以下是代码: #include <stdio.h> int main() { long long n,m,a,r,c; scanf("%I64d%I64d%I64d",&n,&m,&a); r=n/a; if(n%a)r++; c…
[题目链接]:http://codeforces.com/problemset/problem/255/D [题意] 给你一个n*n的方框; 给你一个方块;(以下说的方块都是单位方块) 每一秒钟,可以沿着当前有方块的地方往4个方向扩展一个方块; 问你最少要多少秒钟,平面上会有c个方块; [题解] 画几张图可以发现,图形都是类似一个十字架的几何图案; 设a[n]表示第n-1秒时有多少个方块; 则有a[n] = a[n-1]+n*4 (a[1]=1) 递推一下能求出 a[n] = 2∗n 2 −2∗…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output And while Mishka is enjoying her trip- Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are to…
可以用状压dp,也可以用线型基,但是状压dp没看台懂... 线型基的重要性质 性质一:最高位1的位置互不相同 性质二:任意一个可以用这些向量组合出的向量x,组合方式唯一 性质三:线性基的任意一个子集异或和不为0. 详细见:线型基介绍 题意:给一个数组,找相乘起来是完全平方数的所有组数 解法:先打70的素数表,对每一个数的素数因子个数%2之后进行压位,为什么要这样做呢,是因为,相乘之后如果是素数那么一定能分解成偶数个素数因子相乘,那么就可以转化成求亦或起来是0的组数,用线型基处理,对于不在线型基中…
time limit per test 2 second memory limit per test 256 megabytes input standard inputoutput standard output You a captain of a ship. Initially you are standing in a point (x1,y1)(x1,y1) (obviously, all positions in the sea can be described by cartesi…
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…
A. Little Elephant and Chess 模拟. B. Little Elephant and Magic Square 枚举左上角,计算其余两个位置的值,在\(3\times 3\)判断是否符合题意. C. Little Elephant and Bits 去掉最前面的0,可以使后面的1往前移. D. Little Elephant and Elections 对于选中的数,我们只关心其中的lucky number个数,容易想到用数位dp来求,结果用\(c_i\)表示有\(i\…
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…