poj1703 Lost Cows
给定集合{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的更多相关文章
- [LeetCode] Bulls and Cows 公母牛游戏
You are playing the following Bulls and Cows game with your friend: You write a 4-digit secret numbe ...
- POJ 2186 Popular Cows(Targin缩点)
传送门 Popular Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 31808 Accepted: 1292 ...
- POJ 2387 Til the Cows Come Home(最短路 Dijkstra/spfa)
传送门 Til the Cows Come Home Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 46727 Acce ...
- LeetCode 299 Bulls and Cows
Problem: You are playing the following Bulls and Cows game with your friend: You write down a number ...
- [Leetcode] Bulls and Cows
You are playing the following Bulls and Cows game with your friend: You write a 4-digit secret numbe ...
- 【BZOJ3314】 [Usaco2013 Nov]Crowded Cows 单调队列
第一次写单调队列太垃圾... 左右各扫一遍即可. #include <iostream> #include <cstdio> #include <cstring> ...
- POJ2186 Popular Cows [强连通分量|缩点]
Popular Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 31241 Accepted: 12691 De ...
- Poj2186Popular Cows
Popular Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 31533 Accepted: 12817 De ...
- [poj2182] Lost Cows (线段树)
线段树 Description N (2 <= N <= 8,000) cows have unique brands in the range 1..N. In a spectacula ...
随机推荐
- JDK里的设计模式
一.Creational patterns 创建模式 Abstract factory (recognizeable by creational methods returning the facto ...
- 编写简单的Mapreduce程序并部署在Hadoop2.2.0上运行
今天主要来说说怎么在Hadoop2.2.0分布式上面运行写好的 Mapreduce 程序. 可以在eclipse写好程序,export或用fatjar打包成jar文件. 先给出这个程序所依赖的Mave ...
- DNS域名解析
之前用的是DNSPOD.CN的解析,没什么问题. 因为想根据不同国家做服务器解析(欧洲,亚洲,美国) 然后就转到DNSPOD.com里面有按国家来分的. 但是欧洲那边反应,每天断断续续会不能访问网站. ...
- 转:Python requests 快速入门
迫不及待了吗?本页内容为如何入门Requests提供了很好的指引.其假设你已经安装了Requests.如果还没有, 去 安装 一节看看吧. 首先,确认一下: ·Requests 已安装 ·Reques ...
- Opencv读取各种格式图片,在TBitmap上面重绘
//opencv读取图片 cv::Mat image; //const char *fileName = "HeadImage-UI/Photo-001.bmp"; const c ...
- .NET: WPF Data Binding
WPF是分离UI和Logic的最佳工具,不同于Window Form的事件驱动原理,WPF采用的是数据驱动,让UI成为了Logic的附属,达到分离的效果. 本篇主要讲讲wpf的精华:data bind ...
- Windows平台上安装搭建iPhone/iPad的开发环境
http://www.cnblogs.com/hanxianlong/archive/2015/09/20/4824227.html http://blog.csdn.net/yahohi/artic ...
- java冒泡排序算法
/** * 冒泡排序算法:每次 * @author shaobn * @description 每次都会确定一个最大的值 即固定了,所以会每次-i; */ public class Test1 { p ...
- 夺命雷公狗—angularjs—1—三种数据版定方式
我们在实际开发中几乎都是脱离不掉数据绑定方式的,绑定方法如下所示: <!DOCTYPE html> <html lang="en" ng-app> < ...
- 夺命雷公狗---DEDECMS----2快速入门之玩转dede四大表之间的关系
比如一个小说网站,网站里面有很多类型让我们的小说网他里面有很多种分类,如: 玄幻....奇幻....仙侠....武侠....文学....异界....都市....军事....历史....灵异....悬疑 ...