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 ...
随机推荐
- php:PHPExcel导出excel表格
一.动态生成的内容如何能当成文件来下载呢? 方法:1.将Content-Type设置成application/octet-stream就可以了,即[header('Content-Type: appl ...
- Tomcat类加载器机制
Tomcat为什么需要定制自己的ClassLoader: 1.定制特定的规则:隔离webapp,安全考虑,reload热插拔 2.缓存类 3.事先加载 要说Tomcat的Classloader机制,我 ...
- 使用pgbench测试PostgreSQL
pgbench –help 初始化选项: -i 调用初始化模式 -F NUM 填充因子 -s NUM 规模因子(与产生数据量大小有关) Benchmarking选项: -c ...
- Lintcode: Median
Given a unsorted array with integers, find the median of it. A median is the middle number of the ar ...
- Shiro--权限控制
来自: http://m.oschina.net/blog/92003 1.applicationContext-shiro.xml配置:实现认证和授权 <!-- shiro start --& ...
- Android -- 自定义View小Demo,绘制钟表时间(一)
1,昨天刚看了hongyang大神推荐的自定义时钟效果(传动门:http://www.jianshu.com/users/a45d19d680af/),效果还是不错的,自己又在github上找了找,发 ...
- 有关dwr推送的笔记
想做一个web推送相关的东东,昨天搞了一天,终于把这些杂乱的配制弄清了,今天写出来方便以后记住,也方便大家看一下吧 1:引入dwr包,我用的是maven <dependency> < ...
- 夺命雷公狗ThinkPHP项目之----企业网站8之栏目的添加完善(无限极分类的完成)
我们刚才只是完成了添加的一部分,但是我们的上级分类也不能永远都是只有一个死的嘛,所以我们需要对她进行修改: 我们先将add方法里面的数据查出来再说: 然后在模板页进行遍历: 展示效果如下所示: 虽然是 ...
- [php] 使用IDE的正则搜索代码
([^a-zA-Z_=$0-9/\[\>])('|"|,)?(\s*)store_banner(\s*)('|"|,)?([^a-zA-Z_=$0-9\/\(\]:]) 用在 ...
- update表关联
第一种: update student set student.age =(select `user`.age from user where id=student.id ) where studen ...