"Codeforces 618B" Guess the permutation

Source: Internet
Author: User

Problem

Test instructions

There is a 1 to N of a full arrangement, tells you the number of the first and all n the number of the smaller compared to which, compared to their own 0, so there is a main diagonal of 0 matrix, the original sequence

Analysis

My idea is, to give us each row and by the size of a row, we know that the number of numbers is the first in the series. Because it is the whole arrangement of N, so the first few is a few.

After the order of sum, r[sum[i].id]=i; This sentence indicates that the number in the ID location is now the first large, so r is the required full alignment.

Code
#include <stdio.h> #include <algorithm> #define N 60using 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;}

"Codeforces 618B" Guess the permutation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.