OPEN、CLOSE、RESIZE操作直接模拟即可。

对于MOVE,设$f_i$表示$i$号矩形的坐标,先无视边界通过DP求出每个矩形的坐标,再根据边界反向用第二次DP求出被移动矩形移动的真实距离,再正着进行一次DP即可。

时间复杂度$O(n^3)$。

#include<cstdio>
#include<algorithm>
#define N 260
#define rep(i) for(int i=1;i<=n;i++)
using namespace std;
int xm,ym,n,remain,cnt,x,y,w,h,dx,dy,p,f[N],v[N];char op[9];
struct P{
int x,y,w,h;bool ex;
P(){}
P(int _x,int _y,int _w,int _h){x=_x,y=_y,w=_w,h=_h,ex=1;}
}a[N];
inline bool between(int a,int b,int c){return a<=c&&c<=b;}
inline bool cross(int a,int b,int c,int d){
if(d<a||c>b)return 0;
return 1;
}
inline int getid(int x,int y){
rep(i)if(a[i].ex&&between(a[i].x,a[i].x+a[i].w-1,x)&&between(a[i].y,a[i].y+a[i].h-1,y))return i;
return 0;
}
inline int Open(int x,int y,int w,int h){
if(x+w>xm||y+h>ym)return 0;
rep(i)if(a[i].ex&&cross(a[i].x,a[i].x+a[i].w-1,x,x+w-1)&&cross(a[i].y,a[i].y+a[i].h-1,y,y+h-1))return 0;
a[++n]=P(x,y,w,h);
remain++;
return 1;
}
inline void Close(int p){
a[p].ex=0;
remain--;
}
inline int Resize(int p,int w,int h){
int x=a[p].x,y=a[p].y;
if(x+w>xm||y+h>ym)return 0;
rep(i)if(i!=p&&a[i].ex&&cross(a[i].x,a[i].x+a[i].w-1,x,x+w-1)&&cross(a[i].y,a[i].y+a[i].h-1,y,y+h-1))return 0;
a[p].w=w,a[p].h=h;
return 1;
}
int dfs11(int x){
if(v[x])return f[x];
v[x]=1;
rep(i)if(a[i].ex&&cross(a[i].y,a[i].y+a[i].h-1,a[x].y,a[x].y+a[x].h-1)&&a[i].x<a[x].x)f[x]=max(f[x],dfs11(i)+a[i].w);
return f[x];
}
int dfs12(int x){
if(!v[x])return f[x];
v[x]=0;
f[x]=min(f[x],xm-a[x].w);
rep(i)if(a[i].ex&&cross(a[i].y,a[i].y+a[i].h-1,a[x].y,a[x].y+a[x].h-1)&&a[i].x>a[x].x)f[x]=min(f[x],dfs12(i)-a[x].w);
return f[x];
}
int dfs21(int x){
if(v[x])return f[x];
v[x]=1;
rep(i)if(a[i].ex&&cross(a[i].y,a[i].y+a[i].h-1,a[x].y,a[x].y+a[x].h-1)&&a[i].x>a[x].x)f[x]=min(f[x],dfs21(i)-a[x].w);
return f[x];
}
int dfs22(int x){
if(!v[x])return f[x];
v[x]=0;
f[x]=max(f[x],0);
rep(i)if(a[i].ex&&cross(a[i].y,a[i].y+a[i].h-1,a[x].y,a[x].y+a[x].h-1)&&a[i].x<a[x].x)f[x]=max(f[x],dfs22(i)+a[i].w);
return f[x];
}
int dfs31(int x){
if(v[x])return f[x];
v[x]=1;
rep(i)if(a[i].ex&&cross(a[i].x,a[i].x+a[i].w-1,a[x].x,a[x].x+a[x].w-1)&&a[i].y<a[x].y)f[x]=max(f[x],dfs31(i)+a[i].h);
return f[x];
}
int dfs32(int x){
if(!v[x])return f[x];
v[x]=0;
f[x]=min(f[x],ym-a[x].h);
rep(i)if(a[i].ex&&cross(a[i].x,a[i].x+a[i].w-1,a[x].x,a[x].x+a[x].w-1)&&a[i].y>a[x].y)f[x]=min(f[x],dfs32(i)-a[x].h);
return f[x];
}
int dfs41(int x){
if(v[x])return f[x];
v[x]=1;
rep(i)if(a[i].ex&&cross(a[i].x,a[i].x+a[i].w-1,a[x].x,a[x].x+a[x].w-1)&&a[i].y>a[x].y)f[x]=min(f[x],dfs41(i)-a[x].h);
return f[x];
}
int dfs42(int x){
if(!v[x])return f[x];
v[x]=0;
f[x]=max(f[x],0);
rep(i)if(a[i].ex&&cross(a[i].x,a[i].x+a[i].w-1,a[x].x,a[x].x+a[x].w-1)&&a[i].y<a[x].y)f[x]=max(f[x],dfs42(i)+a[i].h);
return f[x];
}
inline int Move(int p,int dx,int dy){
if(dx+dy==0)return 0;
int x=a[p].x,y=a[p].y,t;
if(dx>0){
rep(i)v[i]=0,f[i]=a[i].x;
f[p]+=dx;
rep(i)if(a[i].ex)dfs11(i);
t=dfs12(p);
rep(i)v[i]=0,f[i]=a[i].x;
f[p]=t;
rep(i)if(a[i].ex)dfs11(i);
rep(i)if(a[i].ex)a[i].x=f[i];
return f[p]-x;
}else if(dx<0){
rep(i)v[i]=0,f[i]=a[i].x;
f[p]+=dx;
rep(i)if(a[i].ex)dfs21(i);
t=dfs22(p);
rep(i)v[i]=0,f[i]=a[i].x;
f[p]=t;
rep(i)if(a[i].ex)dfs21(i);
rep(i)if(a[i].ex)a[i].x=f[i];
return f[p]-x;
}else if(dy>0){
rep(i)v[i]=0,f[i]=a[i].y;
f[p]+=dy;
rep(i)if(a[i].ex)dfs31(i);
t=dfs32(p);
rep(i)v[i]=0,f[i]=a[i].y;
f[p]=t;
rep(i)if(a[i].ex)dfs31(i);
rep(i)if(a[i].ex)a[i].y=f[i];
return f[p]-y;
}else{
rep(i)v[i]=0,f[i]=a[i].y;
f[p]+=dy;
rep(i)if(a[i].ex)dfs41(i);
t=dfs42(p);
rep(i)v[i]=0,f[i]=a[i].y;
f[p]=t;
rep(i)if(a[i].ex)dfs41(i);
rep(i)if(a[i].ex)a[i].y=f[i];
return f[p]-y;
}
return 0;
}
inline int abs(int x){return x>0?x:-x;}
int main(){
scanf("%d%d",&xm,&ym);
while(~scanf("%s%d%d",op,&x,&y)){
cnt++;
if(op[0]=='O'){
scanf("%d%d",&w,&h);
if(!Open(x,y,w,h))printf("Command %d: OPEN - window does not fit\n",cnt);
}
if(op[0]=='C'){
p=getid(x,y);
if(!p)printf("Command %d: CLOSE - no window at given position\n",cnt);
else Close(p);
}
if(op[0]=='R'){
scanf("%d%d",&w,&h);
p=getid(x,y);
if(!p)printf("Command %d: RESIZE - no window at given position\n",cnt);
else if(!Resize(p,w,h))printf("Command %d: RESIZE - window does not fit\n",cnt);
}
if(op[0]=='M'){
scanf("%d%d",&dx,&dy);
p=getid(x,y);
if(!p)printf("Command %d: MOVE - no window at given position\n",cnt);
else{
p=Move(p,dx,dy);
if(abs(p)!=abs(dx+dy))printf("Command %d: MOVE - moved %d instead of %d\n",cnt,abs(p),abs(dx+dy));
}
}
}
printf("%d window(s):\n",remain);
rep(i)if(a[i].ex)printf("%d %d %d %d\n",a[i].x,a[i].y,a[i].w,a[i].h);
return 0;
}

  

BZOJ4118 : [Wf2015]Window Manager的更多相关文章

  1. 图解Android - Android GUI 系统 (2) - 窗口管理 (View, Canvas, Window Manager)

    Android 的窗口管理系统 (View, Canvas, WindowManager) 在图解Android - Zygote 和 System Server 启动分析一 文里,我们已经知道And ...

  2. bug_ _java.lang.IllegalArgumentException: View not attached to window manager 2

    今天遇到一个很奇特的问题,当用户设置了PIN码,在锁屏界面正常解锁PIN码后,进入Launcher时显示com.android.phone 已停止运行.一开始猜想会不会是解锁PIN码的时候处理导致了P ...

  3. bug_ _java.lang.IllegalArgumentException: View not attached to window manager

    ============= 1   view not attached to window manager 转自:http://hi.baidu.com/spare_h/blog/item/7fa3e ...

  4. Android中 View not attached to window manager错误的解决办法

    前几日出现这样一个Bug是一个RuntimeException,详细信息是这样子的:java.lang.IllegalArgumentException: View not attached to w ...

  5. 关于java.lang.IllegalArgumentException: View not attached to window manager 错误的分析

    今天遇到一个很奇特的问题,当用户设置了PIN码,在锁屏界面正常解锁PIN码后,进入Launcher时显示com.android.phone 已停止运行.一开始猜想会不会是解锁PIN码的时候处理导致了P ...

  6. decorview that was originally added here or java.lang.IllegalArgumentException: View not attached to window manager

    使用Dialog的时候,没少出现下面这两个报错 12-11 17:47:49.776: E/WindowManager(11461): android.view.WindowLeaked: Activ ...

  7. 关于dialog引起的 java.lang.IllegalArgumentException: View=com.android.internal.policy.impl.PhoneWindow$DecorView not attached to window manager 错误的分析

    在跑Monkey测试的时候出现了一个比较特别的问题,先来看看Log: // CRASH: com.meizu.media.painter (pid 12491) // Short Msg: java. ...

  8. View not attached to window manager

    java.lang.IllegalArgumentException: View not attached to window manager 在用ProgressDialog的时候,任务结束后Dis ...

  9. View not attached to window manager crash 的解决办法

    View not attached to window manager crash 的解决办法 转自:http://stackoverflow.com/questions/22924825/view- ...

随机推荐

  1. Swift - 推送之本地推送(UILocalNotification)添加Button的点击事件

    上一篇讲到的本地推送是普通的消息推送,本篇要讲一下带按钮动作的推送消息 import UIKit @UIApplicationMain class AppDelegate: UIResponder, ...

  2. php数组的创建及操作

    //数组的创建 //1 $usernames = array('李彦宏','周宏伟','马云','俞敏洪','李开复'); echo $usernames; //array,打印类型 echo '&l ...

  3. js获取缓存数据

    后台:request.setAttribute("type", type); 前台js获取:var type = "${type}";

  4. 很少有人会告诉你的Android开发基本常识

    原文:很少有人会告诉你的Android开发基本常识. 文章介绍了一些关于开发.测试.版本管理.工具使用等方面的知识.

  5. (1)Underscore.js入门

    1. Underscore对象封装 Underscore并没有在原生的JavaScript对象原型中进行扩展,而是像jQuery一样,将数据封装在一个自定义对象中(下文中称"Undersco ...

  6. linux退出vi

    linux退出vi操作,可以先按“esc”,再按“:”,“x”即可,这是要保存退出. 假如是修改过的,不保存,即是:先按  :   ,然后输入  q!  回车 假如未改动,即先按  :   ,然后输入 ...

  7. C#关键字params

    using System; using System.Threading; namespace Test { /// <summary> /// params用法: 1.用来修饰方法的参数 ...

  8. IIS7 经典模式和集成模式的区别(转载)

    转载地址:http://www.poluoluo.com/server/201301/193110.html 升级过程中出现了比较多的问题,前面文章也提到过几个.这次就主要介绍下httpHandler ...

  9. MVC基础知识

    1.View中获取Control和View: //获取控制器名称: ViewContext.RouteData.Values["controller"].ToString(); / ...

  10. poj 1611:The Suspects(并查集,经典题)

    The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 21472   Accepted: 10393 De ...