【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; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
随机推荐
- UVA 12723 Dudu, the Possum --数学期望
题意不说了,概率和期望值要分开处理. 方法1:可以先算出到达每层的概率,然后再乘以每层的期望,每层的期望是固定的. 方法二:也可以从后往前直接推期望.为什么从后往前呢?因为第i层的时候,它可以跳到的层 ...
- UESTC 288 青蛙的约会 扩展GCD
设两只青蛙跳了t步,则此时A的坐标:x+mt,B的坐标:y+nt.要使的他们在同一点,则要满足: x+mt - (y+nt) = kL (p是整数) 化成: (n-m)t + kL = x-y (L ...
- 定制你的Unity编辑器
Unity的编辑器可以通过写脚本进行界面定制,包括添加功能菜单,今天写游戏Demo用到了记录一下. 为Unity添加子菜单 示例程序 [AddComponentMenu("Defend Ho ...
- Eclipse打开xml文件报校验错误解决办法
XML文件在Eclipse中报校验错误: The content of element type "web-app" must match "(icon?,display ...
- javascript之享元模式
实现享元模式的一般步骤: 1.将所有外在数据从目标类中剥离.具体做法是尽可能多的删除该类的属性,所删除的应该是那种因实例而异的属性.构造函数的参数也要这样处理,这些参数应该被添加到该类的各个方法. 这 ...
- 八、Foundation -常用结构体
一.NSRange 在foundation/NSRange.h中对NSRange的定义 typedef struct _NSRange{ NSUInteger location; NSUInteger ...
- 四、Protocol 类似java的接口
概念:是一系列方法的列表,其中声明的方法可以被任意类实现.这种模式称为代理.和JAVA接口不同的是,Protocol可以不用被实现所有的方法. 使用场景:想要监听一些按钮的操作 1声明一个协议 //& ...
- BIO、NIO与NIO.2的区别与联系
BIO.NIO.NIO.2之间的区别主要是通过同步/异步.阻塞/非阻塞来进行区分的 同步: 程序与操作系统进行交互的时候采取的是问答的形式 异步: 程序与操作系统取得连接后,操作系统会主动通知程序消息 ...
- Android 判断现在系统存储器是“手机存储”还是“SD存储”
import android.os.storage.StorageManager; String fileDir = null; StorageManager storageMa ...
- U3D事件系统总结
事件系统有三个要素:发送者,接收者, 转发者. 发送者有两种,一是相机,二是画布.发送者是事件的管理者,发起者,它们使用射线发射器来检测点击事件: 相机的physics Raycaster. 画面的C ...