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 ...
随机推荐
- Java基础之读文件——使用通道读二进制数据(ReadPrimes)
控制台程序,本例读取Java基础之写文件部分(PrimesToFile)写入的primes.bin. import java.nio.file.*; import java.nio.*; import ...
- 随机删除数据库N条记录
delete from table where newsID in(select top 50 newsID from table order by newid())
- java-语句
JAVA语句 1.顺序语句(用:结束)(一个分号也是一个语句)(多条语句形成符合语句) 2.分支语句(又称条件语句) 1. if 语句 例: int a=10 if(a>0) {System ...
- poj 1179 Polygon
http://poj.org/problem?id=1179 Polygon Time Limit: 1000MS Memory Limit: 10000K Total Submissions: ...
- javascript创建对象的方法总结
Javascript创建对象 最简单的方法:创建object实例. var person=new Object(); person.name="Joey";person.age=2 ...
- Android中异步类AsyncTask的理解
这里有两种解释的方法,各有侧重点: 第一种解释: Async Task 简介:AsyncTask的特点是任务在主线程之外运行,而回调方法是在主线程中执行,这就有效地避免了使用Handler带来的麻烦 ...
- C++类构造析构调用顺序训练(复习专用)
//对象做函数参数 //1 研究拷贝构造 //2 研究构造函数,析构函数的调用顺序 //总结 构造和析构的调用顺序 #include "iostream" using namesp ...
- paper 54 :图像频率的理解
我一直在思考一个问题,图像增强以后,哪些方面的特征最为显著,思来想去,无果而终!翻看了一篇知网的paper,基于保真度(VIF)的增强图像质量评价,文章中指出无参考质量评价,可以从三个方面考虑:平均梯 ...
- struts拦截器
struts中的拦截器相当于过滤器的作用 一在struts.xml中配置拦截器或拦截器栈 <interceptors>!--全部的拦截器 <interceptor name=&quo ...
- PAT乙级 1011. A+B和C (15)
1011. A+B和C (15) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 HOU, Qiming 给定区间[-231, 231 ...