bzoj3048+3049+3050
这套月赛题不是特别难
T1:离散化+单调队列,队列里出现数的种类不超过K+1,找最大的num[a[i]]
T2:一眼可以看出BFS+状压DP,还要SPFA预处理出各个块之间的dis
T3:线段树,没什么难度
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
;
int n,K,a[maxn],b[maxn],m,ans,head,tail,q[maxn],vis[maxn],cnt;
int main(){
scanf("%d%d", &n, &K);
; i<=n; i++) scanf("%d", &b[i]),a[i]=b[i];
sort(b+,b++n);
m=unique(b+,b++n)-b-;
; i<=n; i++) a[i]=lower_bound(b+,b++m,a[i])-b;
//for (int i=1; i<=n; i++) printf("%d\n", a[i]);
head=tail=cnt=;
; i<=n; i++){
if (!vis[a[i]]) cnt++;
vis[a[i]]++; q[tail++]=i;
){
vis[a[q[head]]]--; ) cnt--;
head++;
}
ans=max(ans,vis[a[q[tail-]]]);
}
printf("%d\n", ans);
;
}
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
;
]={,,,-};
]={,-,,};
struct node{
int x,y;
node(int _x, int _y):x(_x),y(_y){}
};
<<][],dis[][],id[maxn][maxn],vis[maxn][maxn],cnt,stx[],sty[],N;
char s[maxn][maxn];
bool check(int x, int y){
|| y< || x>n || y>m) ; ;
}
void bfs(int sx, int sy, int num){
queue<node> Q;
Q.push(node(sx,sy)); id[sx][sy]=num;
vis[sx][sy]=;
while (!Q.empty()){
int x=Q.front().x, y=Q.front().y; Q.pop();
; k<; k++){
int tx=x+dx[k], ty=y+dy[k];
if (check(tx,ty) && !vis[tx][ty] && s[tx][ty]=='X'){
vis[tx][ty]=; id[tx][ty]=num;
Q.push(node(tx,ty));
}
}
}
}
void find_land(){
cnt=;
; i<=n; i++)
; j<=m; j++)
if (s[i][j]=='X' && !vis[i][j]){
bfs(i,j,++cnt);
stx[cnt]=i; sty[cnt]=j;
}
// for (int i=1; i<=cnt; i++) printf(" %d %d\n", stx[i], sty[i]);
}
void spfa(int sx, int sy, int num){
queue<node> Q;
int next,cost; memset(d,0x3f,sizeof(d));
memset(dis[num],0x3f,sizeof(dis[num]));
Q.push(node(sx,sy)); d[sx][sy]=; vis[sx][sy]=; dis[num][num]=;
while (!Q.empty()){
int x=Q.front().x, y=Q.front().y; Q.pop();
; k<; k++){
int tx=x+dx[k], ty=y+dy[k];
if (!check(tx,ty) || s[tx][ty]=='.') continue;
cost=(s[tx][ty]=='S');
if (d[tx][ty]>d[x][y]+cost){
d[tx][ty]=d[x][y]+cost;
){
vis[tx][ty]=;
Q.push(node(tx,ty));
}
}
if ((s[tx][ty]=='X') && ((next=id[tx][ty])!=num)) dis[num][next]=min(dis[num][next],d[tx][ty]);
}
vis[x][y]=;
}
}
void dp(){
N=(<<cnt);
memset(f,0x3f,sizeof(f));
; i<=cnt; i++) f[(<<(i-))][i]=;
; s<N; s++){
; i<=cnt; i++) <<(i-)))
; j<=cnt; j++) <<(j-))))
f[s^(<<(j-))][j]=min(f[s^(<<(j-))][j],f[s][i]+dis[i][j]);
}
int ans=0x7fffffff;
; i<=cnt; i++) ans=min(ans,f[N-][i]);
printf("%d\n", ans);
}
int main(){
scanf("%d%d", &n, &m);
; i<=n; i++){
scanf();
}
find_land();
; i<=cnt; i++)
spfa(stx[i],sty[i],i);
dp();
;
}
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
;
struct node{
int l,r,len,lz,lm,rm,mx;
}t[maxn*],now;
int n,m,x,y,ans;
];
void pushup(int x){
t[x].lm=t[x<<].lm;
].lm==t[x<<].len) t[x].lm=t[x<<].len+t[x<<|].lm;
t[x].rm=t[x<<|].rm;
|].rm==t[x<<|].len) t[x].rm=t[x<<|].len+t[x<<].rm;
t[x].mx=max(t[x<<].rm+t[x<<|].lm,max(t[x<<].mx,t[x<<|].mx));
}
void pushdown(int x){
){ //涂色
t[x<<].lz=; t[x<<|].lz=;
t[x<<].lm=t[x<<].rm=t[x<<].mx=;
t[x<<|].lm=t[x<<|].rm=t[x<<|].mx=;
}
){ //不涂色
t[x<<].lz=; t[x<<|].lz=;
t[x<<].lm=t[x<<].rm=t[x<<].mx=t[x<<].len;
t[x<<|].lm=t[x<<|].rm=t[x<<|].mx=t[x<<|].len;
}
t[x].lz=;
}
node query(int x, int p){
int l=t[x].l, r=t[x].r;
pushdown(x);
].mx>=p) ,p);
].rm+t[x<<|].lm>=p){
node ret;
ret.l=t[x<<].r-t[x<<].rm+;
ret.r=ret.l+p-;
return ret;
}|,p);
}
void update(int a, int b, int x, int c){
int l=t[x].l, r=t[x].r;
if (l==a && r==b){
){
t[x].lz=;
t[x].lm=t[x].rm=t[x].mx=;
}
){
t[x].lz=;
t[x].lm=t[x].rm=t[x].mx=t[x].len;
}
return;
}
;
pushdown(x);
,c);
|,c);
,c),update(mid+,b,x<<|,c);
pushup(x);
}
void build(int l, int r, int x){
t[x].l=l; t[x].r=r; t[x].len=r-l+;
if (l==r){
t[x].lz=; t[x].lm=t[x].rm=t[x].mx=;
return;
}
;
build(l,mid,x<<);
build(mid+,r,x<<|);
pushup(x);
}
int main(){
scanf("%d%d", &n, &m);
build(,n,);
//printf("%d\n", t[1].mx);
while (m--){
scanf("%s", opt);
]=='A'){
scanf("%d", &x);
].mx<x) ans++;
else{
now=query(,x);
//printf(" %d %d\n", now.l, now.r);
update(now.l,now.r,,);
}
}else{
scanf("%d%d", &x, &y);
update(x,y,,);
}
}
printf("%d\n", ans);
;
}
bzoj3048+3049+3050的更多相关文章
- Bzoj索引
1001 : http://ideone.com/4omPYJ1002 : http://ideone.com/BZr9KF1003 : http://ideone.com/48NJNh1004 : ...
- Hsql中In没有1000的限制
SELECT * FROM user , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ...
- 存储过程数据insert into select
create or replace procedure PRO_K3_CZZH (org_name in varchar2, --财政专户名称 opertype in varchar2, --操作类型 ...
- jqu
1 /*2 * 说明:3 * 本源代码的中文注释乃Auscarlin呕心沥血所作.旨在促进jQuery的传播以及向广大jQuery爱好者提供一个进阶4 *的途径,以让各位更加深入地了解jQuery,学 ...
- 7.12归来赛_B
Prime Judge 时间限制 1000 ms 内存限制 65536 KB 题目描写叙述 众所周知.假设一个正整数仅仅能被1和自身整除,那么该数被称为素数.题目的任务非常easy.就是判定一个数是否 ...
- 【8.0.0_r4】AMS分析(十六)(ActivityManagerService.java上)
代码位于frameworks/base/services/core/java/com/android/server/am/,一共有七十个文件. Java源码位于package com.android. ...
- POJ -3050 Hopscotch
http://poj.org/problem?id=3050 给定一个5×5矩阵,问选6个数的不同排列总数是多少! 二维的搜索,注意要判重,数据量很小,直接用map就好. #include<cs ...
- hdu - 3049 - Data Processing(乘法逆元)
题意:N(N<=40000)个数n1, n2, ..., nN (ni<=N),求(2 ^ n1 + 2 ^ n2 + ... + 2 ^nN) / N % 1000003. 题目链接:h ...
- LOJ 3049: 洛谷 P5284: 「十二省联考 2019」字符串问题
题目传送门:LOJ #3049. 题意简述: 给定一个长度为 \(n\) 的母串 \(S\). 有 \(n_a\) 个 A 类串,都是 \(S\) 的子串,以区间的形式给出. 有 \(n_b\) 个 ...
随机推荐
- 第三天--html区块
<!Doctype html><html> <head> <meta charset="utf-8"> ...
- Top 命令详解
Top 命令详解 先感受一下top命令的执行结果吧!哈哈-- top - 17:32:34 up 3 days, 8:04, 5 users, load average: 0.09, 0.12, 0. ...
- iOS推送小结(证书的生成、客户端的开发、服务端的开发)
1.推送过程简介 1.1.App启动过程中,使用UIApplication::registerForRemoteNotificationTypes函数与苹果的APNS服务器通信,发出注册远程推送的申请 ...
- Blender 之 Splash 代码分析
注:以下内容基于 Blender 2.7x 版本工程,其它低版本可能有改动. Blender启动完成时,会出现一个画面,英文叫Splash.默认是打开的,可以在设置里关闭.在文件菜单里点击用户首选项( ...
- PLSQL操作excel
一.plsql数据库操作: 删除数据前备份一张表: create table plat_counter_def_bf as select * from plat_monitor_counter_def ...
- (转) Wp7 list 中列表项多样化的解决方案-Custom DataTemplateSelector
本文转自: http://www.cnblogs.com/sonyye/archive/2012/03/03/2378825.html 在这篇文章中,我将解释如何在Windows Phone 7中创建 ...
- CozyRSS2开发记录0-win10开坑
1.回顾 距离上一篇<CozyRSS1.0 - 有可用性版本>,恰好两个月整.在初步完成CozyRSS的WPF桌面版后,按照设想的,开始搞一个手机版的CozyRSS.由于种种原因,并没有使 ...
- 关于 js 一些基本的东西
r.js 可以打包(可以实现前端文件的压缩与合并). 客户端尽量遵循 amd 规范. 推荐使用 requirejs 规范. requirejs 简单教程: http://www.runoob.com/ ...
- 【iOS Instrument性能优化集】
iOS Instrument性能优化集 1.UIImage缓存取舍 在项目代码中看到大量使用如下代码: UIImage使用 在Main Thread中发现不同动画场景中Image IO 开销和耗时所占 ...
- 【iOS自定义键盘及键盘切换】详解
[iOS自定义键盘]详解 实现效果展示: 一.实现的协议方法代码 #import <UIKit/UIKit.h> //创建自定义键盘协议 @protocol XFG_KeyBoardDel ...