CodeForces 289B Polo the Penguin and Matrix (数学,中位数)
The and 数学 Codeforces matrix 中位数
2023-09-11 14:17:19 时间
题意:给定 n * m 个数,然后每次只能把其中一个数减少d, 问你能不能最后所有的数相等。
析:很简单么,首先这个矩阵没什么用,用一维的存,然后找那个中位数即可,如果所有的数减去中位数,都能整除d,那就是可以,并且记录数据。
代码如下:
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int maxn = 500 + 5; const int INF = 0x3f3f3f3f; const int dr[] = {0, 0, 1, -1}; const int dc[] = {1, -1, 0, 0}; int a[maxn*maxn]; int main(){ int n, m, d; cin >> n >> m >> d; int cnt = 0; for(int i = 0; i < n * m; ++i) cin >> a[cnt++]; sort(a, a+cnt); int x = a[cnt/2]; int ans = 0; for(int i = 0; i < cnt; ++i){ if(abs(a[i] - x) % d){ printf("-1\n"); return 0; } ans += abs(a[i] - x) / d; } cout << ans << endl; return 0; }
相关文章
- 配置log4j2日志报错 Cannot find the declaration of element 'Configuration'
- [Javascript] ES6 Class Constructors and the Super Keyword
- [RxJS 6] The Catch and Rethrow RxJs Error Handling Strategy and the finalize Operator
- [Vue] Lazy Load a Route by using the Dynamic Import in Vue.js
- [React] Write a stateful Component with the React useState Hook and TypeScript
- [Javascript] Validate Data with the Every() Method
- [AngularJS] Using the Angular scope $destroy event and method
- [AngularJS]16. Using ReviewController to handle the everything, ng-submit
- 关于COMMIT WORK and COMMIT WORK AND WAIT在SAT中的讨论
- IBase component cannot be created and deleted in the same second
- The data replication requires the processing of single BDoc instances
- Unexpected XML declaration. The XML declaration must be the first node in the document and no white
- The Smart Field Service Prototype powered by SAP FSM and Wechat
- 已解决The method is not allowed for the requested URL.
- 已解决FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future
- WARNING: The scripts f2py, f2py3 and f2py3.9 are installed in ‘/home/ubuntu/.local/bin‘ which is no
- What is the reason for - java.security.spec.InvalidKeySpecException: Unknown KeySpec type: java.security.spec.ECPublicKeySpec
- 什么是 Web3?解读未来的去中心化网络:The Decentralized Internet of the Future Explained
- JVM 语言的兴衰 【The Rise and Fall of JVM Languages】
- 【错误记录】Android Studio 真机运行 Apk 应用报错 ( The application could not be installed: SHELL_UNRESPONSIVE )
- The big deffrence between ($(du * )) and $(du *)
- POJ 1556 The Doors(计算几何+最短路)
- [TroubleShootin]The backup set holds a backup of a database other than the existing 'xxdb' database.
- the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
- `Warning: The default method for RunUMAP has changed from calling Python UMAP via reticulate to the
- 解决办法:The name 'Response' does not exist in the current context
- RuntimeError: You called this URL via POST, but the URL doesn‘t end in a slash and you have APPEND_S