poj1703 Lost Cows

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

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

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

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

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 using namespace std;
 5 const int maxn = 8e3 + 10;
 6 int n;
 7 struct Point{
 8     int id, idx;
 9 }a[maxn];
10
11 bool cmp(Point x, Point y) { return x.idx < y.idx; }
12
13 int main(){
14     freopen("in.txt", "r", stdin);
15     while(~scanf("%d", &n)){
16         for(int i = 1; i <= n; i++) a[i].id = i;
17         a[1].idx = 1;
18         for(int i = 2, t; i <= n; i++){
19             scanf("%d", &t);
20             if(t + 1 == i) a[i].idx = i;
21             else{
22                 for(int j = i; j > t + 1; j--) a[j].idx = a[j - 1].idx;
23                 a[t + 1].idx = i;
24             }
25         }
26         sort(a + 1, a + n + 1, cmp);
27         for(int i = 1; i <= n; i++) printf("%d\n", a[i].id);
28     }
29     return 0;
30 }

时间: 2024-12-14 00:30:54

poj1703 Lost Cows的相关文章

3381: [Usaco2004 Open]Cave Cows 2 洞穴里的牛之二

3381: [Usaco2004 Open]Cave Cows 2 洞穴里的牛之二 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 21  Solved: 18[Submit][Status][Discuss] Description 洞窟里有一道长长的通道.它由N(1≤N≤25000)段道尾相连构成,编号分别为1到N.每个通道有一个阈值,其范围在[1,10^9]依次通过i..j的通道,那奶牛的体重指数就不能超过i..j通道中阈值的最小值.贝茜有Q

POJ——T2186 Popular Cows || 洛谷——P2341 [HAOI2006]受欢迎的牛

http://poj.org/problem?id=2186 || https://www.luogu.org/problem/show?pid=2341 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 33470   Accepted: 13634 Description Every cow's dream is to become the most popular cow in the herd. In a herd

[USACO08NOV]奶牛混合起来Mixed Up Cows

题目描述 Each of Farmer John's N (4 <= N <= 16) cows has a unique serial number S_i (1 <= S_i <= 25,000). The cows are so proud of it that each one now wears her number in a gangsta manner engraved in large letters on a gold plate hung around her

POJ 3348 Cows [凸包 面积]

Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9022   Accepted: 3992 Description Your friend to the south is interested in building fences and turning plowshares into swords. In order to help with his overseas adventure, they are f

POJ 2186 Popular Cows(Targin缩点)

传送门 Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 31808   Accepted: 12921 Description Every cow's dream is to become the most popular cow in the herd. In a herd of N (1 <= N <= 10,000) cows, you are given up to M (1 <=

Poj2186Popular Cows

Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 31533   Accepted: 12817 Description Every cow's dream is to become the most popular cow in the herd. In a herd of N (1 <= N <= 10,000) cows, you are given up to M (1 <= M &

POJ2186 Popular Cows

Description Every cow's dream is to become the most popular cow in the herd. In a herd of N (1 <= N <= 10,000) cows, you are given up to M (1 <= M <= 50,000) ordered pairs of the form (A, B) that tell you that cow A thinks that cow B is popula

Bzoj 1703: [Usaco2007 Mar]Ranking the Cows 奶牛排名 传递闭包,bitset

1703: [Usaco2007 Mar]Ranking the Cows 奶牛排名 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 323  Solved: 238[Submit][Status][Discuss] Description 农夫约翰有N(1≤N≤1000)头奶牛,每一头奶牛都有一个确定的独一无二的正整数产奶率.约翰想要让这些奶牛按产奶率从高到低排序.    约翰已经比较了M(1≤M≤10000)对奶牛的产奶率,但他发现,他还需要再做一

Lettcode_299_Bulls and Cows

本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/50768550 You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a g