【CodeForces 618B】Guess the Permutation
The Codeforces Permutation
2023-09-11 14:19:25 时间
题意
有个1到n的一个全排列,告诉你第i个数和全部n个数相比的较小数是多少,和自己相比时为0,于是有个主对角线为0的矩阵,求原数列
分析
我的想法是,给我们的每一行之和按大小排一下,就知道第i个数是数列里第几大的了。因为是n的全排列,所以第几大就是几。
按sum排完序后,r[sum[i].id]=i;这句表示原来在id位置的数是现在第i大的,所以r就是要求的全排列了。
代码
#include <stdio.h> #include <algorithm> #define N 60 using namespace std; long long n,ans,a,r[N]; struct x { int v,id; } sum[N]; int cmp(x a,x b) { return a.v<b.v; } int main() { scanf("%lld",&n); for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) { scanf("%lld",&a); sum[i].v+=a; } sum[i].id=i; } sort(sum+1,sum+1+n,cmp); for(int i=1; i<=n; i++) r[sum[i].id]=i; for(int i=1; i<=n; i++) printf("%lld ",r[i]); return 0; }
相关文章
- MacOS安装Eclipse后启动报错:The JVM shared library "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/../lib/server/libjvm.dylib" does not contain the JNI_CreateJavaVM symbol.
- 新建maven指定jdk版本-eclipse新建maven项目报错The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path的解决方案
- The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
- node - DeprecationWarning: Mongoose: `findOneAndUpdate()` and `findOneAndDelete()` without the `use
- [RxJS 6] The Catch and Rethrow RxJs Error Handling Strategy and the finalize Operator
- Caused by: org.xml.sax.SAXParseException: The reference to entity "characterEncoding" must end with the ';' delimiter.
- [RxJS 6] The Catch and Rethrow RxJs Error Handling Strategy and the finalize Operator
- [Python] Create a minimal website in Python using the Flask Microframework
- [React + Mobx] Mobx and React intro: syncing the UI with the app state using observable and observer
- [Redux] Normalizing the State Shape
- The CPU Costing Model: A Few Thoughts Part IV (Map of the Problematique)
- Oracle 11g RAC INS-06006 Passwordless SSH connectivity not set up between the following node(s) 解决方法
- whether logo retrieval will block the application
- 【Codeforces 1083A】The Fair Nut and the Best Path
- 【Codeforces Round #459 (Div. 2) C】The Monster
- 【87.65%】【codeforces 731A】Night at the Museum
- 【36.86%】【codeforces 558B】Amr and The Large Array
- 【codeforces 782B】The Meeting Place Cannot Be Changed
- 【Codeforces Round #437 (Div. 2) A】Between the Offices
- 【Codeforces Round #427 (Div. 2) B】The number on the board
- 【Codeforces Round #426 (Div. 2) C】The Meaningless Game
- 【codeforces 505C】Mr.Kitayuta,the Treasure Hunter
- Pape之DL之CNN:2019《A Survey of the Recent Architectures of Deep Convolutional Neural Networks》翻译并解读第四章
- The current user does not have write permissions to the target environment.
- The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
- 005-SpringBoot2.x整合Security5(解决 There is no PasswordEncoder mapped for the id "null")
- `Warning: The default method for RunUMAP has changed from calling Python UMAP via reticulate to the
- PAT The Best Rank[未作]
- java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
- VirtualBox Host-only Adapter,Failed to create the host-only adapter 转
- 【2023年4月美赛加赛】Z题:The Future of the Olympics 思路、建模方案、数据来源、相关资料
- The Introduction of Shell Script
- (六)Jenkins部署项目报错The username you provided is not allowed to use the text-based Tomcat Manager (error
- Accidental override: The following declarations have the same JVM signature (getWindow()Landroid/vie