给定集合{1,2,...,n}的一个置换,指定每个位置上在其左方且比其小的数的个数,求该置换。

这题我目前还只会O(n^2)的做法。

以后再用更高效的算法解决。

http://poj.org/problem?id=2182

 #include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 8e3 + ;
int n;
struct Point{
int id, idx;
}a[maxn]; bool cmp(Point x, Point y) { return x.idx < y.idx; } int main(){
freopen("in.txt", "r", stdin);
while(~scanf("%d", &n)){
for(int i = ; i <= n; i++) a[i].id = i;
a[].idx = ;
for(int i = , t; i <= n; i++){
scanf("%d", &t);
if(t + == i) a[i].idx = i;
else{
for(int j = i; j > t + ; j--) a[j].idx = a[j - ].idx;
a[t + ].idx = i;
}
}
sort(a + , a + n + , cmp);
for(int i = ; i <= n; i++) printf("%d\n", a[i].id);
}
return ;
}

poj1703 Lost Cows的更多相关文章

  1. [LeetCode] Bulls and Cows 公母牛游戏

    You are playing the following Bulls and Cows game with your friend: You write a 4-digit secret numbe ...

  2. POJ 2186 Popular Cows(Targin缩点)

    传送门 Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 31808   Accepted: 1292 ...

  3. POJ 2387 Til the Cows Come Home(最短路 Dijkstra/spfa)

    传送门 Til the Cows Come Home Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 46727   Acce ...

  4. LeetCode 299 Bulls and Cows

    Problem: You are playing the following Bulls and Cows game with your friend: You write down a number ...

  5. [Leetcode] Bulls and Cows

    You are playing the following Bulls and Cows game with your friend: You write a 4-digit secret numbe ...

  6. 【BZOJ3314】 [Usaco2013 Nov]Crowded Cows 单调队列

    第一次写单调队列太垃圾... 左右各扫一遍即可. #include <iostream> #include <cstdio> #include <cstring> ...

  7. POJ2186 Popular Cows [强连通分量|缩点]

    Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 31241   Accepted: 12691 De ...

  8. Poj2186Popular Cows

    Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 31533   Accepted: 12817 De ...

  9. [poj2182] Lost Cows (线段树)

    线段树 Description N (2 <= N <= 8,000) cows have unique brands in the range 1..N. In a spectacula ...

随机推荐

  1. 刷新本地的DNS缓存

    用“WIN +R”快捷键打开运行窗口,输入“cmd”命令,进行命令行窗口.

  2. Groupon面经Prepare: Max Cycle Length

    题目是遇到偶数/2,遇到奇数 *3 + 1的题目,然后找一个range内所有数字的max cycle length.对于一个数字,比如说44,按照题目的公式不停计算,过程是 44, 22, 11, 8 ...

  3. SQL 分组查询 group by

    select * from emp --deptno 为部门号 --输出每个部门的编号 和 该部门的平均工资 --group by deptno; 通过deptno分组 select deptno, ...

  4. ngrok外网登录本地Web服务器

    首先在网上下载ngrok软件,然后cmd到其目录下,运行ngrok http 80即可打开服务器,然后自动生成外网连接,然后C:\inetpub\wwwroot下放置html网页,在公网即可打开

  5. 树形DP 2013多校8(Terrorist’s destroy HDU4679)

    题意: There is a city which is built like a tree.A terrorist wants to destroy the city's roads. But no ...

  6. [转]怎样解决Myeclipse内存溢出?

    在用myeclipes10 开发 遇到了 内存溢出问题,百度了很久,这篇比较完善. 总结起来三个方面去检查 1)myeclipes的配置:myeclipes 10 的安装路径下 的myeclipse. ...

  7. c++之路起航——指针

    c++一阶指针 定义 存储类型名 数据类型 * 指针变量名: Eg:int *a://定义了一个指向整型的指针 a: 指针使用方法 int a,*b; b=&a;//表明将a的地址赋值给b: ...

  8. Android测试AsyncTask下载图片

    package com.example.myact8_async; import org.apache.http.HttpEntity; import org.apache.http.HttpResp ...

  9. oracle 的索引

    一.索引分类      按逻辑分: 单列索引(Single column):  单列索引是基于单列所创建的索引 复合(多列)索引(Concatenated ): 复合索引是基于两列或者多列所创建的索引 ...

  10. PIC18F中断定时器

    //基于MCC18编译器,使用HI-PICC不可用 //-------------------------------------------- #include <p18F452.h> ...