题意

有个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. 基础KMP两道

    1. HDU 1711 Number Sequence 代码: #include <iostream> #include <cstdio> #include <cstri ...

  2. UESTC 1237 质因子分解

    水题一枚.. #include<iostream> #include<cstdio> #include<cstring> #include<cmath> ...

  3. 服务器操作系统应该选择 Debian/Ubuntu 还是 CentOS?

    来自 http://www.zhihu.com/question/19599986 服务器操作系统应该选择 Debian/Ubuntu 还是 CentOS? 想选择一个 Linux 发行版作为服务器. ...

  4. Android Activity的生命周期

    一.为什么要了解Activity的生命周期 activity is directly affected by its association withother activities, its tas ...

  5. R 语言assign 和get 函数用法

    assign函数在循环时候,给变量赋值,算是比较方便 1.给变量赋值 for (i in 1:(length(rowSeq)-1)){ assign(paste("nginx_server_ ...

  6. HYSBZ 2145 悄悄话

    2145: 悄悄话 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 271  Solved: 104[Submit][Status][Discuss] ...

  7. POJ 1141 Brackets Sequence

    Brackets Sequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 29502   Accepted: 840 ...

  8. 【转】【MMX】 基于MMX指令集的程序设计简介

    (一) MMX技术简介 Intel 公司的MMX™(多媒体增强指令集)技术可以大大提高应用程序对二维三维图形和图象的处理能力.Intel MMX技术可用于对大量数据和复杂数组进行的复杂处理,使用MMX ...

  9. VisualStudio2013+EF6+MySql5.5环境下配置

    看院子里对EF框架和MySql的配置文章不少,但是几乎出自一篇文章的转载,而且这篇转载的文章的也比较坑爹,下面我将介绍一下我的配置过程: 第一步:安装mysql-connector-net-6.9.9 ...

  10. oracle学习之表空间

    一.oracle当中的dual表 注意:sql语句一定要有一个 : 结尾,不然会报错. Oracle数据库内种特殊表DualDual表Oracle实际存表任何用户均读取用没目标表SelectDual表 ...