题目链接 首先求出原序列的逆序对个数, 然后考虑每次将目标序列最前面的数放在最后,即最小的数变为最大 设最小数的位置是\(p\),那么逆序对的个数增加了\(n-p\),减少了\(p-1\) #include<iostream> #include<cstring> #include<cstdio> #define int long long using namespace std; const int MAXN=100010; int n,a[MAXN],pos[MAXN…
题目: P2995 [USACO10NOV]牛的照片Cow Photographs P4545 [USACO10NOV]奶牛的图片Cow Photographs SP7809 COWPIC - Cow Photographs 解析: 一个环形的逆序对 最大的数可以放在最小的数的左边而不贡献逆序对 所以就可以在原序列的基础上,从小到大枚举序列中的数,并且让这个数\(+n\),变成最大的数,将某个数加\(n\)后,左边的数就不对它贡献逆序对了,所以逆序对个数减去\((pos[i]-1)\),而其右边…
题目描述 Farmer John希望给他的N(1<=N<=100,000)只奶牛拍照片,这样他就可以向他的朋友炫耀他的奶牛. 这N只奶牛被标号为1..N. 在照相的那一天,奶牛们排成了一排.其中第i个位置上是标号为 ci(1<=ci<=N)c_i(1<=c_i<=N)ci​(1<=ci​<=N) 的奶牛. 对于奶牛的站位,Farmer John有他自己的想法. FJ是这么想的,标号为i(1<=i<=n-1)的奶牛只能站在标号为i+1的奶牛的左边,…
Code: #include<cstdio> #include<algorithm> #include<string> #include<cstring> using namespace std; const int maxn=1000000+4; int n,C[maxn]; struct Data_Structure{ int lowbit(int t){ return t&(-t); } void add(int pos,int delta){…
2058: [Usaco2010 Nov]Cow Photographs Time Limit: 3 Sec  Memory Limit: 64 MBSubmit: 190  Solved: 104[Submit][Status][Discuss] Description 奶牛的图片 Farmer John希望给他的N(1<=N<=100,000)只奶牛拍照片,这样他就可以向他的朋友炫耀他的奶牛.这N只奶牛被标号为1..N. 在照相的那一天,奶牛们排成了一排.其中第i个位置上是标号为c_i(1…
P2853 [USACO06DEC]牛的野餐Cow Picnic 你愿意的话,可以写dj. 然鹅,对一个缺时间的退役选手来说,暴力模拟是一个不错的选择. 让每个奶牛都把图走一遍,显然那些被每个奶牛都走过的点就是符合条件的点. #include<iostream> #include<cstdio> #include<cstring> using namespace std; #define N 1002 int val[N],in[N],k,n,m,ans; bool d…
P2909 [USACO08OPEN]牛的车Cow Cars 显然的贪心. 按速度从小到大排序.然后找车最少的车道,查询是否能填充进去. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define re register using namespace std; ],d[]; int main(){ scanf("%d%d%d%d",&…
P2906 [USACO08OPEN]牛的街区Cow Neighborhoods 考虑维护曼哈顿距离:$\left | x_{1}-x_{2} \right |+\left | y_{1}-y_{2} \right |$ 看起来很难维护的样子,我们尝试转化 设两个点$(x_{1},y_{1}),(x_{2},y_{2})  (x_{1}>=x_{2})$ 那么它们的曼哈顿距离有2种情况 1.$y_{1}>y_{2}:\left | x_{1}-x_{2} \right |+\left | y_…
P1821 [USACO07FEB]银牛派对Silver Cow Party 题目描述 One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X (1 ≤ X ≤ N). A total of M (1 ≤ M ≤ 100,000) unidirectional (one-way roads co…
P2966 [USACO09DEC]牛收费路径Cow Toll Paths 题目描述 Like everyone else, FJ is always thinking up ways to increase his revenue. To this end, he has set up a series of tolls that the cows will pay when they traverse the cowpaths throughout the farm. The cows mo…
---恢复内容开始--- P1522 牛的旅行 Cow Tours189通过502提交题目提供者该用户不存在标签 图论 USACO难度 提高+/省选-提交该题 讨论 题解 记录 最新讨论 输出格式题目描述 农民 John的农场里有很多牧区.有的路径连接一些特定的牧区.一片所有连通的牧区称为一个牧场.但是就目前而言,你能看到至少有两个牧区通过任何路径都不连通.这样,Farmer John就有多个牧场了. John想在牧场里添加一条路径(注意,恰好一条).对这条路径有以下限制: 一个牧场的直径就是牧…
P2971 [USACO10HOL]牛的政治Cow Politics 农夫约翰的奶牛住在N (2 <= N <= 200,000)片不同的草地上,标号为1到N.恰好有N-1条单位长度的双向道路,用各种各样的方法连接这些草地.而且从每片草地出发都可以抵达其他所有草地.也就是说,这些草地和道路构成了一种叫做树的图.输入包含一个详细的草地的集合,详细说明了每个草地的父节点P_i (0 <= P_i <= N).根节点的P_i == 0, 表示它没有父节点.因为奶牛建立了1到K一共K (1…
版权声明:本文为博主原创文章,未经博主同意不得转载. 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的尾部; 目标是要构造字典…
P3080 [USACO13MAR]牛跑The Cow Run 题目描述 Farmer John has forgotten to repair a hole in the fence on his farm, and his N cows (1 <= N <= 1,000) have escaped and gone on a rampage! Each minute a cow is outside the fence, she causes one dollar worth of dam…
P2853 [USACO06DEC]牛的野餐Cow Picnic 题目描述 The cows are having a picnic! Each of Farmer John's K (1 ≤ K ≤ 100) cows is grazing in one of N (1 ≤ N ≤ 1,000) pastures, conveniently numbered 1...N. The pastures are connected by M (1 ≤ M ≤ 10,000) one-way path…
题目描述 Farmer John has forgotten to repair a hole in the fence on his farm, and his N cows (1 <= N <= 1,000) have escaped and gone on a rampage! Each minute a cow is outside the fence, she causes one dollar worth of damage. FJ must visit each cow to i…
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]\).那么最优的取法必…
P2853 [USACO06DEC]牛的野餐Cow Picnic 题目描述 The cows are having a picnic! Each of Farmer John's K (1 ≤ K ≤ 100) cows is grazing in one of N (1 ≤ N ≤ 1,000) pastures, conveniently numbered 1...N. The pastures are connected by M (1 ≤ M ≤ 10,000) one-way path…
P1522 牛的旅行 Cow Tours 题目描述 农民 John的农场里有很多牧区.有的路径连接一些特定的牧区.一片所有连通的牧区称为一个牧场.但是就目前而言,你能看到至少有两个牧区通过任何路径都不连通.这样,Farmer John就有多个牧场了. John想在牧场里添加一条路径(注意,恰好一条).对这条路径有以下限制: 一个牧场的直径就是牧场中最远的两个牧区的距离(本题中所提到的所有距离指的都是最短的距离).考虑如下的有5个牧区的牧场,牧区用"*"表示,路径用直线表示.每一个牧区都…
P1821 [USACO07FEB]银牛派对Silver Cow Party 题目描述 One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X (1 ≤ X ≤ N). A total of M (1 ≤ M ≤ 100,000) unidirectional (one-way roads co…
P3033 [USACO11NOV]牛的障碍Cow Steeplechase 题意 题目描述 --+------- -----+----- ---+--- | | | | --+-----+--+- | | | | | | | --+--+--+-+- | | | | | ---------- ----------- ------- | | | | | | | | | | | | | | | | | | | 给出\(N\)平行于坐标轴的线段,要你选出尽量多的线段使得这些线段两两没有交点(顶点也算…
P2906 [USACO08OPEN]牛的街区Cow Neighborhoods 题目描述 Those Who Know About Cows are aware of the way cows group into 'Cow Neighborhoods'. They have observed Farmer John's N (1 <= N <= 100,000) cows (conveniently numbered 1..N) as they graze, each at her own…
洛谷P1522 [USACO2.4]牛的旅行 Cow Tours 题意: 给出一些牧区的坐标,以及一个用邻接矩阵表示的牧区之间图.如果两个牧区之间有路存在那么这条路的长度就是两个牧区之间的欧几里得距离. 对于一个联通块,称之为一个牧场,也就是说一个牧场内任意一个牧区都可以到达该牧场内的任意的另外一个牧区. 对于一个牧场,它的直径是这个联通块内最短路的最大值. 现在让你在恰当地选择两个牧场,在这两个牧场中各自选一个牧区,在这两个牧区之间建路,要求建路之后所有牧场中最大的直径最小.这里其实如果产生了…
牛的旅行 Cow Tours 目录 牛的旅行 Cow Tours 题目描述 输入格式 输出格式 输入输出样例 输入 #1 输出 #1 解析 代码 题目描述 农民 John的农场里有很多牧区.有的路径连接一些特定的牧区.一片所有连通的牧区称为一个牧场.但是就目前而言,你能看到至少有两个牧区通过任何路径都不连通.这样,Farmer John就有多个牧场了. John想在牧场里添加一条路径(注意,恰好一条).对这条路径有以下限制: 一个牧场的直径就是牧场中最远的两个牧区的距离(本题中所提到的所有距离指…
题目描述 The cows are having a picnic! Each of Farmer John's K (1 ≤ K ≤ 100) cows is grazing in one of N (1 ≤ N ≤ 1,000) pastures, conveniently numbered 1...N. The pastures are connected by M (1 ≤ M ≤ 10,000) one-way paths (no path connects a pasture to…
题目描述 Like everyone else, FJ is always thinking up ways to increase his revenue. To this end, he has set up a series of tolls that the cows will pay when they traverse the cowpaths throughout the farm. The cows move from any of the N (1 <= N <= 250)…
题目描述 Farmer John has hired a professional photographer to take a picture of some of his cows. Since FJ's cows represent a variety of different breeds, he would like the photo to contain at least one cow from each distinct breed present in his herd. F…
题目描述 One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X (1 ≤ X ≤ N). A total of M (1 ≤ M ≤ 100,000) unidirectional (one-way roads connects pairs of farms; road i requires…
题目描述 One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X (1 ≤ X ≤ N). A total of M (1 ≤ M ≤ 100,000) unidirectional (one-way roads connects pairs of farms; road i requires…
https://www.luogu.org/problem/show?pid=3029 题目描述 Farmer John has hired a professional photographer to take a picture of some of his cows. Since FJ's cows represent a variety of different breeds, he would like the photo to contain at least one cow fro…