博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
bzoj 3540: [Usaco2014 Open]Fair Photography
阅读量:5272 次
发布时间:2019-06-14

本文共 2689 字,大约阅读时间需要 8 分钟。

3540: [Usaco2014 Open]Fair Photography

Description

FJ's N cows (2 <= N <= 100,000) are standing at various positions along a long one-dimensional fence. The ith cow is standing at position x_i (an integer in the range 0...1,000,000,000) and is either a plain white cow or a spotted cow. No two cows occupy the same position, and there is at least one white cow. FJ wants to take a photo of a contiguous interval of cows for the county fair, but in fairness to his different cows, he wants to ensure there are equal numbers of white and spotted cows in the photo. FJ wants to determine the maximum size of such a fair photo, where the size of a photo is the difference between the maximum and minimum positions of the cows in the photo. To give himself an even better chance of taking a larger photo, FJ has with him a bucket of paint that he can use to paint spots on an arbitrary subset of his white cows of his choosing, effectively turning them into spotted cows. Please determine the largest size of a fair photo FJ can take, given that FJ has the option of painting some of his white cows (of course, he does not need to paint any of the white cows if he decides this is better).

可以先任意把0染成1.

区间长度定义为,[L,R]中最右和最左的数的差的绝对值.

求一个最长区间,满足区间中所有数0和1的个数相同.

Input

 * Line 1: The integer N.

* Lines 2..1+N: Line i+1 contains x_i and either W (for a white cow) or S (for a spotted cow). 

Output

* Line 1: The maximum size of a fair photo FJ can take, after possibly painting some of his white cows to make them spotted.

Sample Input

5
8 W
11 S
3 W
10 W
5 S
INPUT DETAILS: There are 5 cows. One of them is a white cow at position 8, and so on.

Sample Output

7
OUTPUT DETAILS: FJ takes a photo of the cows from positions 3 to positions 10.
There are 4 cows in this range -- 3 white and 1 spotted -- so he needs to paint one
of the white cows to make it spotted.
题解:
其实题目说白了就是找一个区间,使得区间长度为偶数且区间里白牛的数量不少于花牛。
我是用二维树状数组,以为表示i%2,另一维是白牛减花牛,然后就很简单了。。。
#include
#include
#include
using namespace std;const int N=100005;struct node{ int a,b;}p[N];char s[2];int n,i,ans,x,y,t[2][N<<1];bool cmp(const node&x,const node&y){ return x.a
0) { ans=min(ans,t[x][y]); y-=y&-y; } return ans;}int main(){ scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d%s",&p[i].a,s); p[i].b=(s[0]=='S'); } sort(p+1,p+n+1,cmp); for(i=1;i<=n<<1;i++) t[0][i]=t[1][i]=2e9; for(i=1;i<=n;i++) { if(p[i].b==0) x++;else y++; ans=max(ans,p[i].a-solve((i%2)^1,x-y+n)); update(i%2,x-y+n,p[i].a); } cout<

 

 

转载于:https://www.cnblogs.com/lwq12138/p/5632545.html

你可能感兴趣的文章
重新学习python系列(二)? WTF?
查看>>
SSH框架整合配置所需JAR包(SSH整合)
查看>>
shell脚本统计文件中单词的个数
查看>>
SPCE061A学习笔记
查看>>
sql 函数
查看>>
hdu 2807 The Shortest Path 矩阵
查看>>
熟悉项目需求,要知道产品增删修改了哪些内容,才会更快更准确的在该项目入手。...
查看>>
JavaScript 变量
查看>>
java实用类
查看>>
smarty模板自定义变量
查看>>
研究称90%的癌症由非健康生活习惯导致
查看>>
命令行启动Win7系统操作部分功能
查看>>
排序sort (一)
查看>>
Parrot虚拟机
查看>>
Teamcenter10 step-by-step installation in Linux env-Oracle Server Patch
查看>>
他看了几千份技术简历,愿意把技术简历的秘籍传授给你
查看>>
Struts2学习(三)
查看>>
使用电子邮件模板
查看>>
Callable和Runnable和FutureTask
查看>>
GitHub 多人协作开发 三种方式:
查看>>