bzoj 3540: [Usaco2014 Open]Fair Photography
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
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
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.
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=;
struct node
{
int a,b;
}p[N];
char s[];
int n,i,ans,x,y,t[][N<<];
bool cmp(const node&x,const node&y)
{
return x.a<y.a;
}
void update(int x,int y,int z)
{
while(y<=(n<<))
{
t[x][y]=min(t[x][y],z);
y+=y&-y;
}
}
int solve(int x,int y)
{
int ans=2e9;
while(y>)
{
ans=min(ans,t[x][y]);
y-=y&-y;
}
return ans;
}
int main()
{
scanf("%d",&n);
for(i=;i<=n;i++)
{
scanf("%d%s",&p[i].a,s);
p[i].b=(s[]=='S');
}
sort(p+,p+n+,cmp);
for(i=;i<=n<<;i++)
t[][i]=t[][i]=2e9;
for(i=;i<=n;i++)
{
if(p[i].b==) x++;else y++;
ans=max(ans,p[i].a-solve((i%)^,x-y+n));
update(i%,x-y+n,p[i].a);
}
cout<<ans;
return ;
}
bzoj 3540: [Usaco2014 Open]Fair Photography的更多相关文章
- BZOJ3540: [Usaco2014 Open]Fair Photography
3540: [Usaco2014 Open]Fair Photography Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 72 Solved: 29 ...
- [BZOJ3535][Usaco2014 Open]Fair Photography
[BZOJ3535][Usaco2014 Open]Fair Photography 试题描述 FJ's N cows (1 <= N <= 100,000) are standing a ...
- [Usaco2014 Open]Gold Fair Photography(hash)
最近做了usaco2014 open的金组,果然美帝的题还是没有太简单啊QAQ,被每年的月赛骗了QAQ 不过话说官方题解真心棒(虽然英文的啃得好艰难,我英语渣你们别鄙视我= =),标程超级优美QAQ ...
- BZOJ 3479: [Usaco2014 Mar]Watering the Fields( MST )
MST...一开始没注意-1结果就WA了... ---------------------------------------------------------------------------- ...
- BZOJ 3477: [Usaco2014 Mar]Sabotage( 二分答案 )
先二分答案m, 然后对于原序列 A[i] = A[i] - m, 然后O(n)找最大连续子序列和, 那么此时序列由 L + mx + R组成. L + mx + R = sum - n * m, s ...
- BZOJ 3446: [Usaco2014 Feb]Cow Decathlon( 状压dp )
水状压dp. dp(x, s) = max{ dp( x - 1, s - {h} ) } + 奖励(假如拿到的) (h∈s). 时间复杂度O(n * 2^n) ------------------- ...
- bzoj 3479: [Usaco2014 Mar]Watering the Fields
3479: [Usaco2014 Mar]Watering the Fields Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 174 Solved ...
- P3105 [USACO14OPEN]公平的摄影Fair Photography
题意翻译 在数轴上有 NNN 头牛,第 iii 头牛位于 xi(0≤xi≤109)x_i\:(0\le x_i\le 10^9)xi(0≤xi≤109) .没有两头牛位于同一位置. 有两种牛:白牛 ...
- BZOJ 3445: [Usaco2014 Feb] Roadblock
Description 一个图, \(n\) 个点 \(m\) 条边,求将一条边距离翻倍后使 \(1-n\) 最短路径增加的最大增量. Sol Dijstra. 先跑一边最短路,然后枚举最短路,将路径 ...
随机推荐
- linux内存占用查看
查看内存使用情况 free free -m //显示单位为:兆 查看占用内存最高的5个进程ps aux | sort -k4nr | head -n 5 查看占用CPU最高的5个进程ps aux | ...
- Perl6 Bailador框架(3):路径匹配
use v6; use Bailador; =begin pod 注意的是, 当/:one设置时 虽然你有/admin或/about, 但这个/:one不会跟现有的匹配 只跟没有的匹配: 也就是说, ...
- centos 搭建 ss
download:https://files.cnblogs.com/files/xishaonian/ShadowsocksR-4.7.0-win.7z 使用方法:使用root用户登录,运行以下命令 ...
- Django【设计】settings方案
配置文件: 目标:配置文件,默认配置和手动配置分开,参考django的配置文件方案,默认配置文件放在内部,只让用户做常用配置 /bin/settings.py(手动配置) PLUGIN_ITE ...
- monkey测试===Monkey测试策略(系列二)转
Monkey的测试策略 一. 分类 Monkey测试针对不同的对象和不同的目的采用不同的测试方案,首先测试的对象.目的及类型如下: 测试的类型分为:应用程序的稳定性测试和压力测试 测试对象分为:单一a ...
- [session篇]看源码学习session(一)
假如你是使用过或学习过PHP,你一定觉得很简单.session只不过是$_SESSION就可以搞得,这还不简单只是对一个key-value就能工作了.我觉得可以大多数的phper都是这样的,这是语言本 ...
- Tomcat debug模式下特别慢但是run正常处理方法
转载自:http://blog.csdn.net/builderwfy/article/details/50785749 到网上查资料发现这是由eclipse和tomcat交互时,在debug模式启动 ...
- [ python ] 项目二:主机批量管理程序
开发要求: 1. 对主机进行批量管理 2. 可对单台或主机组批量执行命令 3. 可上传文件到对应的主机或组 4. 使用多线程实现 程序: 1. README # 作者:hkey # ...
- setTimeout(fn,0)
我们都知道setTimeout是一个延迟执行的函数 console.log(); setTimeout(function(){console.log();},); console.log(); 会得到 ...
- scrapy-redis组件的使用
scrapy-redis是一个基于redis的scrapy组件,通过它可以快速实现简单分布式爬虫程序,该组件本质上提供了三大功能: scheduler - 调度器 dupefilter - URL去重 ...