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

给每一个数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. Python之面向对象:属性

    一.属性定义 1.类属性 类属性定义在类中且在函数体之外:类属性通常不作为实例属性使用:类变量紧接在类名后面定义 类属性的引用:类名.count eg:Employee.count 实例中可以引用类的 ...

  2. 团体天梯赛 L3-001. 凑零钱

    L3-001. 凑零钱 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 韩梅梅喜欢满宇宙到处逛街.现在她逛到了一家火星店里,发现 ...

  3. spring boot 运行jsp原理分析

    Spring-boot运行jsp原理分析   结论: 启动server的时候会创建临时目录 在浏览器中访问jsp文件的时候通过内置Tomcat将jsp转换为java,保存在临时目录中 然后编译为cla ...

  4. 在razor中使用递归,巧用递归

    原文发布时间为:2011-04-20 -- 来源于本人的百度文章 [由搬家工具导入] Learning Razor–Writing an Inline Recursive HTML Helper Wr ...

  5. Day 30 process&thread_2

    进程和线程_2 1.继承类创建线程 import threading,time class Mythread(threading.Thread): #建立类,继承threading.Thread de ...

  6. LeetCode OJ--4Sum *

    https://oj.leetcode.com/problems/4sum/ 在一个数列中,找出所有的4个数,它们的和是target. class Solution { public: vector& ...

  7. python-re之中文匹配

    #coding=utf-8 import re import chardet#检测网页编码形式的模块 p = re.compile(r'\d+') print p.findall('one1two2t ...

  8. Word Pattern - LeetCode

    Given a pattern and a string str, find if str follows the same pattern. Here follow means a full mat ...

  9. 从客户端(ExportContent="...ontinuous <br />Pass Count":13...")中检测到有潜在危险的 Request.Form 值。

    mvc中,用chrome浏览器导出excel提示如题错误的解决办法. <system.web> <httpRuntime requestValidationMode="2. ...

  10. OnTouchListener

    1.布局 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android ...