Inversion
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 810 Accepted Submission(s): 450

Problem Description
Let { A1,A2,…,An } be a permutation of the set{ 1,2,…, n}. If i < j and Ai > Aj then the pair (Ai,Aj) is called an “inversion” of the permutation. For example, the permutation {3, 1, 4, 2} has three inversions: (3,1), (3,2) and (4,2).
The inversion table B1,B2,…,Bn of the permutation { A1,A2,…,An } is obtained by letting Bj be the number of elements to the left of j that are greater than j. (In other words, Bj is the number of inversions whose second component is j.) For example, the permutation:
{ 5,9,1,8,2,6,4,7,3 }
has the inversion table
2 3 6 4 0 2 2 1 0
since there are 2 numbers, 5 and 9, to the left of 1; 3 numbers, 5, 9 and 8, to the left of 2; etc.
Perhaps the most important fact about inversions is Marshall Hall’s observation that an inversion table uniquely determines the corresponding permutation. So your task is to convert a permutation to its inversion table, or vise versa, to convert from an inversion table to the corresponding permutation.

Input
The input consists of several test cases. Each test case contains two lines.
The first line contains a single integer N ( 1 <= N <= 50) which indicates the number of elements in the permutation/invertion table.
The second line begins with a single charactor either ‘P’, meaning that the next N integers form a permutation, or ‘I’, meaning that the next N integers form an inversion table.

Output
For each case of the input output a line of intergers, seperated by a single space (no space at the end of the line). If the input is a permutation, your output will be the corresponding inversion table; if the input is an inversion table, your output will be the corresponding permutation.

Sample Input
9
P 5 9 1 8 2 6 4 7 3
9
I 2 3 6 4 0 2 2 1 0
0

Sample Output
2 3 6 4 0 2 2 1 0
5 9 1 8 2 6 4 7 3

Source
Zhejiang University Local Contest 2002, Preliminary

问题链接:HDU1320 ZOJ1201 Inversion
问题简述:给定一个序列,求其倒置表。
问题分析:简单问题,不解释。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* HDU1320 ZOJ1201 Inversion */#include <bits/stdc++.h>using namespace std;const int INF = 0x3F3F3F3F;
const int N = 50 + 1;
int p[N], ix[N];
char s[2];int main()
{int n;while (~scanf("%d", &n) && n) {scanf("%s", s);if (s[0] == 'P') {for (int i = 1; i <= n; i++) scanf("%d", &p[i]);for (int i = 1; i <= n; i++) {int cnt = 0;for (int j = 1; j <= n; j++)if (p[j] == i) break;else if (p[j] > i) cnt++;ix[i] = cnt;}for (int i = 1; i < n; i++)printf("%d ", ix[i]);printf("%d\n", ix[n]);} else {for (int i = 1; i <= n; i++) {scanf("%d", &ix[i]);p[i] = INF;}for (int i = 1; i <= n; i++) {int cnt = 0;for (int j = 1; j <= n; j++)if (p[j] > i) {if (cnt == ix[i]) {p[j] = i;break;} elsecnt++;}}for (int i = 1; i < n; i++)printf("%d ", p[i]);printf("%d\n", p[n]);}}return 0;
}

HDU1320 ZOJ1201 Inversion【水题】相关推荐

  1. 水题/poj 1852 Ants

    1 /* 2 PROBLEM:poj1852 3 AUTHER:Nicole 4 MEMO:水题 5 */ 6 #include<cstdio> 7 using namespace std ...

  2. HDU2673-shǎ崽(水题)

    如果不能够直接秒杀的题,就不算水题.又应证了那句话,有时候,如果在水题上卡住,那么此题对于你来说,也就不算是水题了额~~ 刚睡醒,迷迷糊糊. 题目的意思很简单,求一个最大的,再求一个最小的.几乎是什么 ...

  3. 图论刷水题记录(二)(最短路-----SPFA算法)

    继第一篇的后续,又来刷水题了,写的是SPFA算法,这个算法的复杂度比较玄学,感觉能不用就不用了,但是他的好处就是可以判断负圈. 3月26日: 1.POJ 1847 Tram 题意:在一个交通网络上有N ...

  4. 图论刷水题记录(一)(最短路-----dijkstra算法)

    最近实在不知道干些什么,感觉自己除了水题什么都不会做,算了去刷一刷图论的水题吧本来想合起来一起发,想了想太长的话以后看起来也不方便,题目所以今天晚上就先发了dij部分,由上到下由易变难. 1.POJ ...

  5. hdu 2041:超级楼梯(水题,递归)

    超级楼梯Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissio ...

  6. HDU2568 前进【水题】

    前进 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...

  7. CF Round #426 (Div. 2) The Useless Toy 思维 水题

    题目链接: http://codeforces.com/contest/834/problem/A 题目描述: 输入起始状态和结束状态和数列长度, 判断旋转方向是顺时针逆时针还是不合理 解题思路: 长 ...

  8. NUC1312 Sum【水题+数学题】

    Sum 时间限制: 1000ms 内存限制: 65536KB 通过次数: 1总提交次数: 1 问题描述 认为自然数是从1-N.将每个数和+或-联系起来,然后计算这个表达式的值我们得到一个和S.这个问题 ...

  9. Codeforces 864 A Fair Game 水题

    题目链接: http://codeforces.com/problemset/problem/864/A 题目描述: 看不是是不是一串数中只有两种数且这两种数字的数量是相同的 解题思路: 水题, 水过 ...

最新文章

  1. Oracle:递归查询(树形结构数据)
  2. 十大最急需IT技术人才榜:Java开发人员领跑
  3. 猎豹移动(金山网络)2015校园招聘(c++project师)
  4. 无法解析类型 java.lang.Object。从必需的 .class 文件间接引用了它
  5. [pytorch、学习] - 5.8 网络中的网络(NiN)
  6. @Deprecated 注解 (@Documented 、@Retention、@Target)
  7. mysql多个外键删除设置_Mysql在删除集上使用多个外键创建表
  8. 4服务器内存和普通内存_Java服务器内存过高CPU过高问题排查
  9. 拓端tecdat|数据盘点高校新生录取情况
  10. pycharm ubuntu 安装_pycharm使用远程python解释器
  11. OpenGL超级宝典第7版 配置环境第一个程序
  12. 实习周记---20180527
  13. 计算机应用技术ps考证,2017计算机等级考试一级Photoshop应用试题及答案
  14. linux文件操作命令包括,学习Linux命令之最基本的文件操作
  15. 集美大学第七届团体程序设计天梯赛第二场排位赛题解
  16. 2022爱分析・数据库厂商全景报告 | 爱分析报告
  17. LATEX公式下标短横线过长
  18. Apache POI 设置Excel单元格的宽度和高度
  19. 实现一个简单的压测工具
  20. 圣天诺LDK - HL

热门文章

  1. 【我的相册】2018.2.15-年夜饭
  2. 使用GDAL将下载的Google卫星图像转为带坐标的tif
  3. Arcgis javascript那些事儿(十七)——地理编码服务的发布与使用
  4. 树莓派上搭建ActiveMQ
  5. SVN Cleanup失败解决方法
  6. C#访问和操作MYSQL数据库
  7. flex blazeds java spring_Flex+Java+Spring+BlazeDS 配置篇说明
  8. HelloKafka入门 helloKafka
  9. 一、RabbitMQ安装
  10. 设计模式(四)行为型模式