题意

有个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=; i<=n; i++)
{
for(int j=; j<=n; j++)
{
scanf("%lld",&a);
sum[i].v+=a;
}
sum[i].id=i;
}
sort(sum+,sum++n,cmp);
for(int i=; i<=n; i++)
r[sum[i].id]=i;
for(int i=; i<=n; i++)
printf("%lld ",r[i]);
return ;
}

【CodeForces 618B】Guess the Permutation的更多相关文章

  1. 【codeforces 785E】Anton and Permutation

    [题目链接]:http://codeforces.com/problemset/problem/785/E [题意] 给你一个初始序列1..n顺序 然后每次让你交换任意两个位置上面的数字; 让你实时输 ...

  2. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  3. 【40.17%】【codeforces 569B】Inventory

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. 【codeforces 757C】Felicity is Coming!

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【codeforces 760C】Pavel and barbecue

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【codeforces 602E】Kleofáš and the n-thlon

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. 【25.00%】【codeforces 584E】Anton and Ira

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  8. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  9. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

随机推荐

  1. mac os下得pycharm怎么设置mercurial?

    捣鼓了一会儿,最终搞定了. 先把链接贴上来:https://www.jetbrains.com/pycharm/help/mercurial.html 如果你发现你的pycharm在设置mercuri ...

  2. POJ 1195 Mobile Phones

    树状数组,开始的时候wa了,后来看看,原来是概率论没学好,以为求(L,B) - (R,T) 矩阵内的和只要用sum(R+1,T+1) - sum(L,B) 就行了,.傻x了.. 必须 sum(R,T) ...

  3. Android配置----adb工具的使用

    Adb(android debug bridge):android 调试桥,用于将本地的文件 push 到环境中,或者从手机环境中 pull 文件到本地. 一.ADB的主要功能: · 运行设备的she ...

  4. UltraISO制作U盘启动盘安装Win7/10系统攻略

    UltraISO制作U盘启动盘安装Win7/9/10系统攻略 U盘安装好处就是不用使用笨拙的光盘,光盘还容易出现问题,无法读取的问题.U盘体积小,携带方便,随时都可以制作系统启动盘. U盘建议选择8G ...

  5. 如何用chrome插件使上网生活更美好-持续更新

    所有插件都可以到Chrome Web Store搜索下载 1.Read Later Fast v-1.6.8 ***刷网页的时候,有很多值得我们阅览但当时木有时间看怎么办? --加可书签啊! ***可 ...

  6. BZOJ 3572: [Hnoi2014]世界树

    BZOJ 3572: [Hnoi2014]世界树 标签(空格分隔): OI-BZOJ OI-虚数 OI-树形dp OI-倍增 Time Limit: 20 Sec Memory Limit: 512 ...

  7. git review报错一例

    在线上修改代码,最后使用git review提交代码审核的时候出现报错如下:[wangshibo@115~]$ vim testfile           #修改代码[wangshibo@115~] ...

  8. iOS开发——网络编程Swift篇&Alamofire详解

    Alamofire详解 预览图 Swift Alamofire 简介 Alamofire是 Swift 语言的 HTTP 网络开发工具包,相当于Swift实现AFNetworking版本. 当然,AF ...

  9. Linux 下安装 jdk步骤:

    一:在安装自己下载的jdk之前,要先看看新安装的CentOS 6.4系统自带的jdk版本,如果存在最好是卸载掉,然后再安装自己下载的jdk版本,如何卸载linux系统自带的jdk网上有很多例子,相信大 ...

  10. ls -F一种非常有用的ls格式

    ls -F一种非常有用的ls格式  tz/y/yupeng > ls -F#q#           News/         doc/          images/       mbox ...