Best Cow Line (POJ 3617)】的更多相关文章

题目: 给定长度为N的字符串S,要构造一个长度为N的字符串T.起初,T是一个空串,随后反复进行下列任意操作. ·从S的头部删除一个字符,加到T的尾部 ·从S的尾部删除一个字符,加到T的尾部 目标是要构造字典序尽可能小的字符串T. #include "iostream" #include "cstring" #include "vector" using namespace std; #define MAX_N 1000 void solve(in…
带来两题贪心算法的题. 1.给定长度为N的字符串S,要构造一个长度为N的字符串T.起初,T是一个空串,随后反复进行下面两个操作:1.从S的头部删除一个字符,加到T的尾部.2.从S的尾部删除一个字符,加到T的尾部.求你任意采取这两个步骤后能得到的最小字符串T 2.直线上有N个点,点i的位置是xi,这N个点中选择若干个做上标记,对于每个点,在他们距离为R的区域内必须带有标记点,求在满足这个条件的情况下,所需要标记点的最少个数. 1.POJ 3617 Best Cow Line http://poj.…
问题: 链接:http://poj.org/problem?id=3617 思路: 按照字典序比较S和将S反转后的字符串S' 如果S较小,就从S的开头取出一个字符,加到T的末尾(更新下标值) 如果S’较小,从S’的末尾取出一个字符,加到T的末尾(更新下标值) 代码: # include <iostream> # include <string> using namespace std; int N; ]; ]; int main() { cin>>N; ; i <…
给定长度为N的字符串S,要构造一个长度为N的字符串T,起初,T是一个空串,随后反复进行下列任意操作. *从S的头部删除一个字符,加到T的尾部 *从S的尾部删除一个字符,加到T的尾部 目标是要构造字典序尽可能小的字符串T 模拟情景,想出来一个有意思的比喻,写出来程序,俩个推土机开始在互相看不到对方的直线工作推物品,每个人每次走一步,并且先将物品重量较小的先推走, 由于没有手机,只能通过副驾驶通信员互相沟通,谁的前方物品较轻先推走,于是通信员下车检查,物品,当A,B通信员发现一方较轻时,就全部回各自…
POJ 3617 Best Cow Line Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] FJ is about to take his N (1 ≤ N ≤ 2,000) cows to the annual "Farmer of the Year" competition. In this contest every farmer arranges his cows in a line and herds…
P2870 [USACO07DEC]最佳牛线,黄金Best Cow Line, Goldpoj 3617 http://poj.org/problem?id=3617 题目描述FJ is about to take his N (1 ≤ N ≤ 500,000) cows to the annual”Farmer of the Year” competition. In this contest every farmer arranges his cows in a line and herds…
Best Cow Line   Time Limit: 1000MS      Memory Limit: 65536K Total Submissions: 16104    Accepted: 4547 Description FJ is about to take his N (1 ≤ N ≤ 2,000) cows to the annual"Farmer of the Year" competition. In this contest every farmer arrang…
Best Cow Line Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30684   Accepted: 8185 Description FJ is about to take his N (1 ≤ N ≤ 2,000) cows to the annual"Farmer of the Year" competition. In this contest every farmer arranges his…
Best Cow Line Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9284   Accepted: 2826 Description FJ is about to take his N (1 ≤ N ≤ 2,000) cows to the annual"Farmer of the Year" competition. In this contest every farmer arranges his…
Best Cow Line Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 26670   Accepted: 7226 Description FJ is about to take his N (1 ≤ N ≤ 2,000) cows to the annual"Farmer of the Year" competition. In this contest every farmer arranges his…
Best Cow Line Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 42701   Accepted: 10911 Description FJ is about to take his N (1 ≤ N ≤ 2,000) cows to the annual"Farmer of the Year" competition. In this contest every farmer arranges hi…
康托展开 裸的康托展开&逆康托展开 康托展开就是一种特殊的hash,且是可逆的…… 康托展开计算的是有多少种排列的字典序比这个小,所以编号应该+1:逆运算同理(-1). 序列->序号:(康托展开) 对于每个数a[i],数比它小的数有多少个在它之前没出现,记为b[i],$ans=1+\sum b[i]* (n-i)!$ 序号->序列:(逆康托展开) 求第x个排列所对应的序列,先将x-1,然后对于a[i],$\left\lfloor \frac{x}{(n-i)!} \right\rflo…
题目 POJ 3617 和 这道题题目一样,只是范围稍稍再小一点. //模拟试试 #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; ][]; bool bijiao(int st,int ed) { if(st==ed) return true; ]<s[ed][]) return true; ]>s[ed][]) return false; else…
3403: [Usaco2009 Open]Cow Line 直线上的牛 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 48  Solved: 41[Submit][Status] Description 题目描述     约翰的N只奶牛(编为1到N号)正在直线上排队.直线上开始的时候一只牛也没有.接下来发生了S(1≤S≤100000)次事件,一次事件可能是以下四种情况之一:   .一只奶牛加入队伍的左边(输入“AL”).   .一只奶牛加入队伍的…
3301: [USACO2011 Feb] Cow Line Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 67  Solved: 39[Submit][Status] Description The N (1 <= N <= 20) cows conveniently numbered 1...N are playing yet another one of their crazy games with Farmer John. The co…
1640: [Usaco2007 Nov]Best Cow Line 队列变换 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 493  Solved: 253[Submit][Status] Description FJ打算带着他可爱的N (1 ≤ N ≤ 2,000)头奶牛去参加”年度最佳老农”的比赛.在比赛中,每个农夫把他的奶牛排成一列,然后准备经过评委检验. 比赛中简单地将奶牛的名字缩写为其头字母(the initial letter of e…
直接用STL的的deque就好了... ---------------------------------------------------------------------- #include<cstdio> #include<algorithm> #include<cstring> #include<iostream> #include<deque>   #define rep( i , n ) for( int i = 0 ; i &l…
3301: [USACO2011 Feb] Cow Line Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 82  Solved: 49[Submit][Status][Discuss] Description The N (1 <= N <= 20) cows conveniently numbered 1...N are playing yet another one of their crazy games with Farmer Joh…
3403: [Usaco2009 Open]Cow Line 直线上的牛 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 71  Solved: 62[Submit][Status] Description 题目描述     约翰的N只奶牛(编为1到N号)正在直线上排队.直线上开始的时候一只牛也没有.接下来发生了S(1≤S≤100000)次事件,一次事件可能是以下四种情况之一:   .一只奶牛加入队伍的左边(输入“AL”).   .一只奶牛加入队伍的…
1640: [Usaco2007 Nov]Best Cow Line 队列变换 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 543  Solved: 278[Submit][Status] Description FJ打算带着他可爱的N (1 ≤ N ≤ 2,000)头奶牛去参加”年度最佳老农”的比赛.在比赛中,每个农夫把他的奶牛排成一列,然后准备经过评委检验. 比赛中简单地将奶牛的名字缩写为其头字母(the initial letter of e…
如果在阅读本文之前对于康托展开没有了解的同学请戳一下这里:  简陋的博客    百度百科 题目描述 N(1<=N<=20)头牛,编号为1...N,正在与FJ玩一个疯狂的游戏.奶牛会排成一行(牛线),问FJ此时的行号是多少.之后,FJ会给牛一个行号,牛必须按照新行号排列成线. 行号是通过以字典序对行的所有排列进行编号来分配的.比如说:FJ有5头牛,让他们排为行号3,排列顺序为: 1:1 2 3 4 5 2:1 2 3 5 4 3:1 2 4 3 5 因此,牛将在牛线1 2 4 3 5中. 之后,…
P2870 [USACO07DEC]最佳牛线,黄金Best Cow Line, Gold我比赛的时候A了,luogu上25分,QAQ,又憨又傻的200+代码,我为什么要干电脑干的事情,无语了.如果左边<右边,取左如果右边<左边,取右如果相等,就向中间找,直到找到第一个不同的,然后给电脑指明下一步是取队首或队尾取就行了. AC代码: #include<iostream> #include<cstdio> #include<queue> #include<…
P2870 [USACO07DEC]最佳牛线,黄金Best Cow Line, Gold 题意 给一个字符串,每次可以从两边中的一边取一个字符,要求取出的字符串字典序最小 可以Hash+二分 也可以SA 首先贪心选字典序小的 然后遇到相等的了比Rank数组,把原串倍长一下就可以比了. Code: #include <cstdio> #include <algorithm> const int N=6e4+10; char s[N],ans[N]; int sa[N],Rank[N]…
康托展开 康托展开为全排列到一个自然数的映射, 空间压缩效率很高. 简单来说, 康托展开就是一个全排列在所有此序列全排列字典序中的第 \(k\) 大, 这个 \(k\) 即是次全排列的康托展开. 康托展开是这样计算的: 对于每一位, 累计除了前面部分, 字典序小于本位的排列总数, 即 LL cantor(){ LL ans = 0; for(LL i = 1;i <= num;i++){ LL cnt = 0; for(LL j = i + 1;j <= num;j++){ if(ask[j]…
https://www.luogu.org/problem/show?pid=3014 题目描述 The N (1 <= N <= 20) cows conveniently numbered 1...N are playing yet another one of their crazy games with Farmer John. The cows will arrange themselves in a line and ask Farmer John what their line…
P2952 [USACO09OPEN]牛线Cow Line 题目描述 Farmer John's N cows (conveniently numbered 1..N) are forming a line. The line begins with no cows and then, as time progresses, one by one, the cows join the line on the left or right side. Every once in a while, s…
http://www.lydsy.com/JudgeOnline/problem.php?id=3301 其实这一题很早就a过了,但是那时候看题解写完也是似懂非懂的.... 听zyf神犇说是康托展开,然后拖到今天才来看看... sad.. 从不知道那里来的文档里边抄的: 康托展开就是一种特殊的哈希函数,它的使用范围是对于n个数的排列进行状态的压缩和存储.X=a[n]*(n-1)!+a[n-1]*(n-2)!+…+a[i]*(i-1)!+…+a[2]*1!+a[1]*0! 其中,a为整数,并且0<…
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u012515223/article/details/37909933 最好牛线(Best Cow Line) 代码(C) 本文地址: http://blog.csdn.net/caroline_wendy 题目: 给定长度为N的字符串S, 要构造一个长度为N的字符串T. 重复进行例如以下随意操作. 从S的头部删除一个字符, 放入T的尾部; 从S的尾部删除一个字符, 放入T的尾部; 目标是要构造字典…
Best Cow Line Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 32687   Accepted: 8660 Description FJ is about to take his N (1 ≤ N ≤ 2,000) cows to the annual"Farmer of the Year" competition. In this contest every farmer arranges his…
Portal Description 给出一个字符串\(s(|s|\leq3\times10^4)\),每次从\(s\)的开头或结尾取出一个字符接在新字符串\(s'\)的末尾.求字典序最小的\(s'\). Solution 设当前剩余的字符串为\(t\),将其翻转得到\(t'\).则\(t<t'\)时取开头,否则取结尾. 令\(p=lcp(t,t')\),则有\(t<t' \Leftrightarrow t[1..p]=t'[1..p],t[p+1]<t'[p+1]\).那么最优的取法必…