题目链接:http://codeforces.com/problemset/problem/400/C 题目意思:给出一个n行m列的矩阵,问经过 x 次clockwise,y 次 horizontal rotate 和z次counterclockwise 之后,原来在n行m列的矩阵的坐标去到哪个位置. 题目意思很容易看懂.易知,对于clockwise,counterclockwise的次数,mod 4 == 0 相当于没有改变!而对于 horizontal rotate,mod 2 == 0 也…
http://codeforces.com/problemset/problem/400/C 题意:给你一个n*m的矩阵,然后在矩阵中有p个糖果,给你每个糖果的初始位置,然后经过x次顺时针反转,y次旋转,z次逆时针反转,问最后每个糖果的位置. 思路:推出顺时针反转.旋转.逆时针反转的坐标的变化即可. #include <cstdio> #include <cstring> #include <cmath> #include <iostream> #defin…
#include <iostream> #include <vector> #include <algorithm> #include <utility> using namespace std; typedef pair<int,int> Point; int n,m; void clockwise_rotate(Point &cell, int x){ ; i < x; ++ i){ int tmp = cell.first;…
题意:给出一个矩形的三种操作,顺时针旋转,逆时针旋转,对称,给出原始坐标,再给出操作数,问最后得到的坐标 画一下模拟一下操作就可以找到规律了 #include<iostream> #include<cstdio> #include<cstring> #include <cmath> #include<stack> #include<vector> #include<map> #include<set> #inc…
题目链接:http://codeforces.com/problemset/problem/289/B 题目意思:给出一个 n 行 m 列的矩阵和数值 d .通过对矩阵里面的数进行 + d 或者 - d 的操作,是否可以使矩阵上的所有数相等.可以的话输出最少的操作步数,否则输出 -1. 由于矩阵的排列对处理没什么影响,因此不需要用到二维数组存储.接着把矩阵中所有的数从小到大进行排序,要想算出最少的步数,很容易想到应该最中间的数(中位数)靠拢.最关键的是如何判断不能通过对矩阵中的数进行处理使得所有…
[LeetCode]01 Matrix 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/01-matrix/#/description 题目描述: Given a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell. The distance between two adjacent cells is 1. Example:…
[LeetCode]378. Kth Smallest Element in a Sorted Matrix 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix/description/ 题目描述: Given a n x n matrix where each of the rows and columns are sorted in ascen…
题目链接:http://codeforces.com/problemset/problem/313/C 题目意思:给定 4n 个整数(可以组成 2n × 2n 大小的矩阵),问通过对这些整数进行排列,求出 the resulting maximum beauty of the matrix.这个最大值的定义是这样的:先定义m为所有整数中的最大值.如果n = 0,那么,这个beauty 数就是m:否则把2n × 2n 大小的矩阵划分为  2n - 1 × 2n - 1- 大小的子矩阵,那么 bea…
题目链接:http://codeforces.com/problemset/problem/486/B 题目意思:给出一个m行n列的矩阵B(每个元素只由0/1组成),问是否可以利用矩阵B,通过一定的运算逆回来求出矩阵A(行和列数都跟B相同).可以的话输出"YES" 并输出矩阵A,否则输出 "NO".运算如下: 也就是,Bij 是通过 A 矩阵第 i 行中所有的数做 或(|) 运算接着再跟所有第 j 列中所有的数做 或 运算求出来的.or 运算就是除了所有元素都为 0…
题目链接:http://codeforces.com/contest/334/problem/A 题意:有n个人,将1-n袋(第 i  袋共有 i  颗糖果,1<= i  <=n)所有的糖果(n*(n+1)/2)均分到n个人中. 这里要注意的是输出问题,每行中的前n / 2(包括n/2)个数比较容易解决,就是每两个数中相隔n个长度,第n/2个数和第n/2+1个数之间隔了多少个长度,这是值得考虑的问题.我的做法是,由于每个人分到的糖果是 (n / 2) * (n*n+1)  (输出的n个数看成n…