codeforces 710C C. Magic Odd Square(构造)】的更多相关文章

题目链接: C. Magic Odd Square Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, column and both main diagonals are odd. Input The only line contains odd integer n (1 ≤ n ≤ 49). Output Print n lines with n integers. All the…
Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, column and both main diagonals are odd. Input The only line contains odd integer n (1 ≤ n ≤ 49). Output Print n lines with n integers. All the integers should be differ…
Magic Odd Square Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, column and both main diagonals are odd. Input The only line contains odd integer n (1 ≤ n ≤ 49). Output Print n lines with n integers. All the integers…
C. Magic Odd Square time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, column and both main diagonals are odd.…
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, column and both main diagonals are odd. 输入 The only line contains odd integer n (1 ≤ n ≤ 49). 输出 Print n lines…
题目链接: http://codeforces.com/problemset/problem/710/C 题目大意: 构造一个N*N的幻方.任意可行解. 幻方就是每一行,每一列,两条对角线的和都相等. 题目思路: [模拟] 分为奇幻方.单偶幻方和双偶幻方三种构造. 具体分类可以查看百度.幻方的N种构造方法 // //by coolxxx //#include<bits/stdc++.h> #include<iostream> #include<algorithm> #i…
构造. 先只考虑用$0$和$1$构造矩阵. $n=1$,$\left[ 1 \right]$. $n=3$,(在$n=1$的基础上,最外一圈依次标上$0$,$1$,$0$,$1$......) $\left[ {\begin{array}{*{20}{c}}0&1&0\\1&1&1\\0&1&0\end{array}} \right]$. $n=5$,(在$n=3$的基础上,最外一圈依次标上$1$,$0$,$1$,$0$......) $\left[ {\b…
题意:给它定一个n,让你输出一个n*n的矩阵,使得整个矩阵,每行,每列,对角线和都是奇数. 析:这个题可以用n阶奇幻方来解决,当然也可以不用,如果不懂,请看:http://www.cnblogs.com/dwtfukgv/articles/5797527.html 剩下的就很简单了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <str…
Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, column and both main diagonals are odd. Input The only line contains odd integer n (1 ≤ n ≤ 49). Output Print n lines with n integers. All the integers should be differ…
1 奇数阶幻方构造法 (1) 将1放在第一行中间一列; (2) 从2开始直到n×n止各数依次按下列规则存放:按 45°方向行走,向右上,即每一个数存放的行比前一个数的行数减1,列数加1 (3) 如果行列范围超出矩阵范围,则回绕.例如1在第1行,则2应放在最下一行,列数同样加1; (4) 如果按上面规则确定的位置上已有数,或上一个数是第1行第n列时,则把下一个数放在上一个数的下面. #include<iostream> #include<algorithm> #include<…
Content 构造出一个 \(n\times n\) 的矩阵,使得这个矩阵由 \(1\sim n^2\) 这些数字组成,并且这个矩阵的每行,每列,以及对角线的和都为奇数. 数据范围:\(1\leqslant n\leqslant 49\).\(n\) 为奇数. Solution 这题其实就是 \(\texttt{NOIP2015}\) 提高组的 \(\texttt{D1T1}\),因为--都是奇数幻方,都是要求每行,每列,以及对角线的和都相等.只不过这道题目要求和都为奇数罢了. 但是,只要你利…
C. Magic Odd Square time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, column and both main diagonals are odd.…
题目链接:http://codeforces.com/problemset/problem/710/C 题目大意:输入一个奇数n,则生成n*n矩阵,要求矩阵的行.列还有斜着,所有元素之和为奇数. 解题思路:要符合行.列还有斜着,所有元素之和为奇数,则保证行.列或者斜着,有奇数个奇数 和 偶数个偶数即可. 32 4 8 5 2 4 6 8 10 3 5 7 12 9 11 13 15 17 14 19 21 23 16 18 20 22 24 7 2 4 6 8 10 12 14 16 3 5 7…
K. Perpetuum Mobile Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/K Description The world famous scientist Innokentiy almost finished the creation of perpetuum mobile. Its main part is the energy generator which…
C. Plus and Square Root time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, ' + ' (plus) an…
题目网址:http://codeforces.com/contest/828/problem/B 题目: Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint mini…
Codeforces 1110 E 题意:给定两个数组,从第一个数组开始,每次可以挑选一个数,把它变化成左右两数之和减去原来的数,问是否可以将第一个数组转化成第二个. 思路: 结论:两个数组可以互相转化的充要条件是它们差分后的数组排序后相同并且它们第一个数相同. 证明: 先证明一个引理. 引理:两个数组可以互相转化的必要条件是它们都能转化成同一个数组. 证明:假设A转化成B,C也转化成B,由于操作可逆,于是可以从A转化成B再转化成C.\(\square\) 证明原结论的充分性. 看某一次操作.…
[题目链接] http://codeforces.com/problemset/problem/610/C [题目大意] 构造出2^n个由1和-1组成的串使得其两两点积为0 [题解] 我们可以构造这样一个矩阵,右下角四分之一和其余三个分块相反, 不断扩展这个矩阵即可. [代码] #include <cstdio> #define rep(i,n) for(int i=1;i<=n;i++) using namespace std; const int N=1000; int k,p[N]…
[题目链接] http://codeforces.com/contest/804/problem/E [题目大意] 给出一个1到n的排列,问每两个位置都进行一次交换最终排列不变是否可能, 如果可能输出交换顺序. [题解] 我们发现对于四个一组组内进行六次交换之后可以保证四个数的位置不变, 而对于每组相互之间可以一共进行十六次交换使得两组均不会发生变化 所以如果n能被4整除,那么我们可以4个分组达到目的, 当不能被4整除的时候,我们发现余数为2和3的时候都不能构造出可行解. 在余数为1的时候有一种…
题目链接 http://codeforces.com/contest/1276/problem/C 题解 嗯,比赛结束前3min想到做法然后rush不出来了--比赛结束后又写了15min才过-- 以下是我的做法: 设最优解的行数和列数分别是\(R\)和\(C\), 不妨设\(R\le C\). 那么显然对于每个数我们只能选不超过\(R\)个. 考虑将所有数按出现次数从大到小排序,枚举\(R\), 求出可用的数的个数,设为\(cnt\), 那么显然\(C\le \frac{cnt}{R}\). 我…
A 直接判存不存在连续的三个包含A,B,C就行 /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) using namespace std; typedef long long ll; typedef unsigned long long ull; ][] = {{, }, {, }, {, -}, { -, }, {, }, {, -}, { -, -}, { -, }}; , gakki = +…
原题链接:http://codeforces.com/problemset/problem/848/A 题意:让我们构造一个字符串.这里有一种操作:取走这个字符串的若干部分,分成两部分,然后将这两部分的合并插回字符串中,进行过处理的字符串部分不能再次被单独取出,只能整体取出,直到无法操作后停止.每次这种操作后,消耗, f(s,c)是c字符在s字符串重复的次数. 让我们输出:若干次操作后最小值恰好为k的字符串,不用考虑字符的顺序. 思路:最好怎么简单怎么做.如果我们让字符串中只有一种字符,显然通过…
Codeforces 题面传送门 & 洛谷题面传送门 中规中矩的构造题一道. 首先考虑将两张图都向一个中间状态转化.方便起见我们取所有点都连向 \(1\) 号点的情形作为中间状态. 考虑怎样从初始状态向我们这个中间状态转化.显然我们要将所有不与 \(1\) 相连的对角线都变得与 \(1\) 相连对吧,那我们就考虑从 \(2\) 开始枚举每一个点 \(x\) 以及一个与 \(x\) 相连的边 \((x,y)(x<y)\),满足 \(y\) 与 \(1\) 有边,如果 \(|x-y|>2\…
Codeforces 题面传送门 & 洛谷题面传送门 Yet another immortal D1+D2 I %%%%%% 首先直接统计肯定是非常不容易的,不过注意到这个 \(k\) 非常小,因此考虑对这个 \(k\) 做点文章.我们考虑每个数被执行了多少次 \(-1\) 操作,设第 \(i\) 个数被执行了 \(b_i\) 次 \(-1\) 操作,那么最终的结果就是 \((a_1-b_1)\oplus(a_2-b_2)\oplus\cdots\oplus(a_n-b_n)\).然后就是比较神…
Codeforces 题目传送门 & 洛谷题目传送门 obviously,难度高一点的构造题对我来说都是不可做题 首先考虑将排列拆成一个个置换环,也就是 \(\forall i\) 连边 \(i\to p_i\),显然这样我们可以得到一个个环. 首先考虑怎样同时处理两个置换环,假设有两个环,长度分别为 \(p,q\),元素分别为 \(x_1,x_2,\cdots,x_p;y_1,y_2,\cdots,y_q\).我们考虑以下步骤同时将这两个环中所有元素复位: 交换 \(x_1,y_1\),两个置…
题目链接: B. Dreamoon and Sets time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Dreamoon likes to play with sets, integers and .  is defined as the largest positive integer that divides both a a…
题目链接: E. Points on Plane time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output On a plane are n points (xi, yi) with integer coordinates between 0 and 106. The distance between the two points wi…
题目链接: D. Recover the String time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output For each string s consisting of characters '0' and '1' one can define four integers a00, a01, a10 and a11, where …
H - Football BetsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87493#problem/H Description While traveling to England, it is impossible not to catch the English passion for football. Almost everyon…
题目:http://codeforces.com/problemset/problem/135/B 题意:给8个点 判断能否用 4个点构成正方形,另外4个点构成 矩形. 输出 第一行是正方形 ,第二行是矩形. 我的思路:用了4个for循环 枚举四个点, 用向量判断,四个点构成 六条边,如果这六条边里, 有四条边 与他们垂直的边有两个,就说明是矩形,在这个基础上,有 2条边 与他们垂直的边有一个. 说明是正方形. #include<iostream> #include<cstdio>…