CodeForces 289B Polo the Penguin and Matrix
来源:互联网 发布:static在java中的作用 编辑:程序博客网 时间:2024/04/28 22:48
觉得和矩阵没什么关系,直接看成一个数列,从中位数开始,小的增加d,大的减小d,求操作多少次即可。
如果取余不相等,那肯定不可能转换成同一个数字。
#include<stdio.h>#include<iostream>#include<math.h>#include<string.h>#include<iomanip>#include<stdlib.h>#include<ctype.h>#include<algorithm>#include<deque>#include<functional>#include<iterator>#include<vector>#include<list>#include<map>#include<queue>#include<set>#include<stack>#define CPY(A, B) memcpy(A, B, sizeof(A))typedef long long LL;typedef unsigned long long uLL;const int MOD = 1e9 + 7;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f3f3f3f3f3f3fLL;const double EPS = 1e-9;const double OO = 1e20;const double PI = acos (-1.0);const int dx[] = {-1, 0, 1, 0};const int dy[] = {0, 1, 0, -1};using namespace std;int M[1000010];int main() { int n,m,d,ans=0,i; scanf ("%d%d%d",&n,&m,&d); int num=n*m; for (i=0; i<num; i++) { scanf ("%d",&M[i]); if (M[i]%d!=M[0]%d) {printf ("-1\n"); return 0;}//can not make all matrix elements equal } sort (M,M+num); int mid=M[num/2]; for (i=0; i<num; i++) { ans+=abs (M[i]-mid) /d;// the minimum number of moves } printf ("%d\n",ans); return 0;}
0 0
- codeforces 289 B. Polo the Penguin and Matrix
- Codeforces-289b J Polo the Penguin and Matrix
- CodeForces 289B Polo the Penguin and Matrix
- CodeForces 289B Polo the Penguin and Matrix
- CodeForces 289B Polo the Penguin and Matrix
- B. Polo the Penguin and Matrix
- codeforces#289_B Polo the Penguin and Matrix
- Codeforces-289a I Polo the Penguin and Segments
- CodeForces 289A Polo the Penguin and Segments
- CodeForces 289A Polo the Penguin and Segments
- CodeForces 289BPolo the Penguin and Matrix
- Codeforces Round #177 (Div. 1) B. Polo the Penguin and Houses (组合数学)
- Codeforces Round #177 (Div. 1) B - Polo the Penguin and Houses
- codeforces Polo the Penguin and Strings 思维问题代码链接
- CodeForces 288C - Polo the Penguin and XOR operation
- CodeForces 288C - Polo the Penguin and XOR operation(思维)
- Codeforces 288E Polo the Penguin and Lucky Numbers
- CodeForces 288A Polo the Penguin and Strings
- 字符串匹配各种算法
- laravel的启动过程
- 小白学Tensorflow之多层神经网络
- Ideal+spring boot+thymeleaf 的热部署问题处理
- 工厂模式:简单工厂模式、工厂方法模式、抽象工厂模式
- CodeForces 289B Polo the Penguin and Matrix
- SDKD 2016 Summer Single Contest #12 .F
- 文本居中
- ICCV 2015 揭开152层神经网络的面纱(Deep Residual Learning )
- Beaglebone black-固件更新
- STL之Vector(三):Vector常用函数
- Crashing Robots
- ACM选票统计(C语言)
- MultiPath TCP - Linux Kernel implementation - Google Nexus 5 (Android 4.4)