给原排列 求 其前面有多少个数比他大。

给每一个数1...2..n前面有多少个数比他大,求原序列

第一个直接统计

第二个从1開始找出第inv【i】+1个空位置放进去就好

printf里的format 原来能够用if表达式 - -

#include <bits/stdc++.h>

using namespace std;
int n;
void Gao()
{
int a[100],b[100]={0};
char ch;
getchar();
ch=getchar();
if (ch=='P')
{
for (int i=0;i<n;i++)
scanf("%d",a+i);
for (int i=0;i<n;i++)
for (int j=0;j<i;j++)
if (a[i]<a[j])
b[a[i]]++;
for (int i=0;i<n;i++)
printf(i==0?"%d":" %d",b[i+1]);
cout<<endl;
}
else
{
for (int i=0;i<n;i++)
scanf("%d",a+i);
for (int i=0;i<n;i++)
{
int need=0;
for(int j=0;j<n;j++)
{
if (b[j]==0) need++;
if ((need==(a[i]+1))&&(b[j]==0))
{
b[j]=i+1;
break;
}
}
}
for (int i=0;i<n;i++)
printf(i==0?"%d":" %d",b[i]);
cout<<endl;
}
}
int main()
{
// freopen("a.in","r",stdin);
while (cin>>n && n)
Gao();
return 0;
}

[水]ZOJ1201的更多相关文章

  1. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  2. Openjudge 1.13-21:最大质因子序列(每日两水)

    总时间限制:  1000ms 内存限制:  65536kB 描述 任意输入两个正整数m, n (1 < m < n <= 5000),依次输出m到n之间每个数的最大质因子(包括m和n ...

  3. [LeetCode] Container With Most Water 装最多水的容器

    Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...

  4. 如何装最多的水? — leetcode 11. Container With Most Water

    炎炎夏日,还是呆在空调房里切切题吧. Container With Most Water,题意其实有点噱头,简化下就是,给一个数组,恩,就叫 height 吧,从中任选两项 i 和 j(i <= ...

  5. Codeforces 刷水记录

    Codeforces-566F 题目大意:给出一个有序数列a,这个数列中每两个数,如果满足一个数能整除另一个数,则这两个数中间是有一条边的,现在有这样的图,求最大联通子图. 题解:并不需要把图搞出来, ...

  6. Bzoj3041 水叮当的舞步

    Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 132  Solved: 75 Description 水叮当得到了一块五颜六色的格子形地毯作为生日礼物 ...

  7. ACM :漫漫上学路 -DP -水题

    CSU 1772 漫漫上学路 Time Limit: 1000MS   Memory Limit: 131072KB   64bit IO Format: %lld & %llu Submit ...

  8. bzoj2002弹(dan)飞绵羊 分块水过

    据说是道lct求深度的题 但是在小猫大的指点下用分块就n^1.5水过了 = =数据忘记加强系列 代码极其不美观,原因是一开始是听小猫大讲的题意,还以为是弹到最前面... #include <cs ...

  9. bzoj1103树状数组水题

    (卧槽,居然规定了修改的两点直接相连,亏我想半天) 非常水的题,用dfs序(而且不用重复,应该是直接规模为n的dfs序)+树状数组可以轻松水 收获:树状数组一遍A(没啥好骄傲的,那么简单的东西) #i ...

随机推荐

  1. HDU 3792 素数打表

    Description If we define dn as: dn = pn+1-pn, where pi is the i-th prime. It is easy to see that d1 ...

  2. zabbix3.4 源码部署

    centos6.8  系统    zabbix3.4.9   msyql5.7.22   php5.6.24  在centos6上面源码部署zabbix.3.4 问题比较多,需要花不少时间去解决,建议 ...

  3. react 当中当组件抛出的dom元素最外层不止一个的时候的写法

    在react16当中,对一个组件抛出多个dom进行了支持,写法 以数组形式抛出

  4. redux使用需要注意的地方

    1. react和redux没有直接联系,当react需要结合redux使用的时候,需要引入 react-redux ,该插件提供了connet等方法使得react可以注入redux属性. 2. re ...

  5. pat 甲级 1009. Product of Polynomials (25)

    1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

  6. github 获取repo 发布的版本号

    获取最新版本 https://api.github.com/repos/nickchou/paopao/releases/latest 获取版本列表 https://api.github.com/re ...

  7. LeetCode OJ-- Longest Common Prefix

    https://oj.leetcode.com/problems/longest-common-prefix/ 在多个string的集合中,找出所有string的最长公共前缀. 从头开始 index ...

  8. CString 转换为 char*

    CString str="这是一个测试"; char* str_0=str.GetBuffer(0);

  9. extern "C"解析

    转自大牛的解析(非常具体详细)http://www.cnblogs.com/skynet/archive/2010/07/10/1774964.html 我做个简单的标注方便以后自己查看: 在用C++ ...

  10. ansible 2.7.1 常见错误总结

    1.RequestsDependencyWarning (refer to http://blog.51cto.com/mjunetwslinux/2177727?source=dra) python ...