【CodeForces 618B】Guess the Permutation
题意
有个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的更多相关文章
- 【codeforces 785E】Anton and Permutation
[题目链接]:http://codeforces.com/problemset/problem/785/E [题意] 给你一个初始序列1..n顺序 然后每次让你交换任意两个位置上面的数字; 让你实时输 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【40.17%】【codeforces 569B】Inventory
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 757C】Felicity is Coming!
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 760C】Pavel and barbecue
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 602E】Kleofáš and the n-thlon
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【25.00%】【codeforces 584E】Anton and Ira
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
随机推荐
- jquery中的each()方法详解
each()方法能使DOM循环结构简洁,不容易出错.each()函数封装了十分强大的遍历功能,使用也很方便,它可以遍历一维数组.多维数组.DOM, JSON 等等在javaScript开发过程中使用$ ...
- uGUI练习(五) Draggable Object
练习目标 学习制作一个可拖动的UI 一.步骤 监听UI的Drag事件,需要我们写一点点的代码. 1.创建一个Panel ,设置size为(100,100) 2.创建DraggableObjectSce ...
- Linux安装Redis
环境:Centos 6.2 redis是当前比较热门的NOSQL系统之一,它是一个key-value存储系统.和Memcached类似,但很大程度补偿了memcached的不足,它支持存储的value ...
- 日期选择器:jquery datepicker的使用
helloweba.com 作者:月光光 时间:2012-04-08 21:05 标签: jquery datepicker jquery ui 在jquery ui中,提供了一个非常实用 ...
- 网站如何启用SSL安全证书?IIS7启用新建Https:/
网站使用SSL,通过SSL证书申请,然后导入之后.我们需要对网站进行设置才能正常使用SSL证书,具体如何操作让网站启用SSL呢,本经验以一个网站添加SSL主机头的方式为例来,网站启用SSL服务器安全证 ...
- GEOS库在windows中的编译和测试(vs2012)
版本:vs2012, geos3.5 一.下载和编译 这类的文章比较,不再具体细说,可以参考 http://blog.csdn.net/wangqinghao/article/details/8201 ...
- [CareerCup] 2.6 Linked List Cycle 单链表中的环
2.6 Given a circular linked list, implement an algorithm which returns the node at the beginning of ...
- LeetCode 笔记27 Two Sum III - Data structure design
Design and implement a TwoSum class. It should support the following operations: add and find. add - ...
- MBProgressHUD框架的使用:https://github.com/jdg/MBProgressHUD
MBProgressHUD是一个开源类库,实现了各种样式的提示框, 下载地址:https://github.com/jdg/MBProgressHUD,然后把两个MBProgressHUD.h和MBP ...
- 20145222黄亚奇《Java程序设计》第4周学习总结
教材学习内容总结 第6章 为了避免重复的行为定义使用继承. 要学会如何正确判断使用继承的时机以及继承之后如何活用多态. 继承的好处之一,就是若你要将name.lexel.blood改为其他名称,那就只 ...