QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#548220 | #4688. Window Manager | PhantomThreshold# | WA | 0ms | 3564kb | C++20 | 7.3kb | 2024-09-05 16:27:23 | 2024-09-05 16:27:24 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1000;
const int inf = 1e9+5;
struct node
{
int x,y,w,h;
}a[maxn]; int n;
int W,H;
int intersect(int l,int r,int x,int y)
{
if( l>x ) swap(l,x),swap(r,y);
// l<=x
return r>=x;
}
int intersect(node k1,node k2)
{
return intersect(k1.x,k1.x+k1.w-1,k2.x,k2.x+k2.w-1) && intersect(k1.y,k1.y+k1.h-1,k2.y,k2.y+k2.h-1);
}
int vis[maxn];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>W>>H;
string ty;
int cmd=0;
while(cin>>ty)
{
++cmd;
if(ty=="OPEN")
{
int x,y,w,h; cin>>x>>y>>w>>h;
node temp= (node){x,y,w,h};
int ok=1;
for(int i=1;i<=n;i++) if( intersect(a[i],temp) )
{
ok=0;
break;
}
if(ok) a[++n]=temp;
else //error
cout<<"Command "<<cmd<<": "<<"OPEN - "<<"window does not fit\n";
}
else if(ty=="CLOSE")
{
int x,y; cin>>x>>y;
node temp= (node){x,y,1,1};
int id=0;
for(int i=1;i<=n;i++) if( intersect(a[i],temp) )
{
id=i;
break;
}
if(id)
{
for(int i=id;i<n;i++) a[i]=a[i+1];
n--;
}
else //error
cout<<"Command "<<cmd<<": "<<"CLOSE - "<<"no window at given position\n";
}
else if(ty=="RESIZE")
{
int x,y,w,h; cin>>x>>y>>w>>h;
node temp= (node){x,y,1,1};
int id=0;
for(int i=1;i<=n;i++) if( intersect(a[i],temp) )
{
id=i;
break;
}
if(id)
{
temp=(node){a[id].x,a[id].y,w,h};
int ok=1;
for(int i=1;i<=n;i++) if(i!=id)
{
if(intersect(temp,a[i]))
{
ok=0;
break;
}
}
if(ok) a[id]=temp;
else
{
cout<<"Command "<<cmd<<": "<<"RESIZE - "<<"window does not fit\n";
}
}
else //error
cout<<"Command "<<cmd<<": "<<"RESIZE - "<<"no window at given position\n";
}
else //MOVE
{
int x,y,dx,dy; cin>>x>>y>>dx>>dy;
node temp= (node){x,y,1,1};
int id=0;
for(int i=1;i<=n;i++) if( intersect(a[i],temp) )
{
id=i;
break;
}
if(id)
{
if(dy==0) //dx
{
int now=0, sig= dx>0 ? 1 : -1;
dx=abs(dx);
for(int i=1;i<=n;i++) vis[i]=0;
vis[id]=1;
while(dx!=0)
{
int nex=inf;
vector<int>V;
for(int i=1;i<=n;i++) if(vis[i])
{
int dis= sig>0 ? W-(a[i].x+a[i].w-1) : a[i].x;
if(nex>dis) nex=dis;
}
for(int i=1;i<=n;i++) if(vis[i]) for(int j=1;j<=n;j++) if(!vis[j])
{
if( intersect(a[i].y,a[i].y+a[i].h-1,a[j].y,a[j].y+a[j].h-1) )
{
int dis= sig>0 ? a[j].x-(a[i].x+a[i].w-1)-1 : a[i].x-(a[j].x+a[j].w-1)-1;
if(dis>=0)
{
if(dis<nex) nex=dis,V.clear(),V.push_back(j);
else if(dis==nex) V.push_back(j);
}
}
}
if(nex>=dx)
{
now+=dx;
for(int i=1;i<=n;i++) if(vis[i])
a[i].x+=dx*sig;
dx=0;
break;
}
else
{
now+=nex;
for(int i=1;i<=n;i++) if(vis[i])
a[i].x+=nex*sig;
for(auto i:V) vis[i]=1;
dx-=nex;
if(V.empty()) break;
}
}
if(dx!=0)
cout<<"Command "<<cmd<<": "<<"MOVE - "<<"moved "<<now<<" instead of "<<(now+dx)<<"\n";
}
else //dy
{
int now=0, sig= dy>0 ? 1 : -1;
dy=abs(dy);
for(int i=1;i<=n;i++) vis[i]=0;
vis[id]=1;
while(dy!=0)
{
int nex=inf;
vector<int>V;
for(int i=1;i<=n;i++) if(vis[i])
{
int dis= sig>0 ? H-(a[i].y+a[i].h-1) : a[i].y;
if(nex>dis) nex=dis;
}
for(int i=1;i<=n;i++) if(vis[i]) for(int j=1;j<=n;j++) if(!vis[j])
{
if( intersect(a[i].x,a[i].x+a[i].w-1,a[j].x,a[j].x+a[j].w-1) )
{
int dis= sig>0 ? a[j].y-(a[i].y+a[i].h-1)-1 : a[i].y-(a[j].y+a[j].h-1)-1;
if(dis>=0)
{
if(dis<nex) nex=dis,V.clear(),V.push_back(j);
else if(dis==nex) V.push_back(j);
}
}
}
if(nex>=dy)
{
now+=dy;
for(int i=1;i<=n;i++) if(vis[i])
a[i].y+=dy*sig;
dy=0;
break;
}
else
{
now+=nex;
for(int i=1;i<=n;i++) if(vis[i])
a[i].y+=nex*sig;
for(auto i:V) vis[i]=1;
dy-=nex;
if(V.empty()) break;
}
}
if(dy!=0)
cout<<"Command "<<cmd<<": "<<"MOVE - "<<"moved "<<now<<" instead of "<<(now+dy)<<"\n";
}
}
else //error
cout<<"Command "<<cmd<<": "<<"MOVE - "<<"no window at given position\n";
}
}
cout<<n<<" window(s):\n";
for(int i=1;i<=n;i++) cout<<a[i].x<<' '<<a[i].y<<' '<<a[i].w<<' '<<a[i].h<<'\n';
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3536kb
input:
320 200 OPEN 50 50 10 10 OPEN 70 55 10 10 OPEN 90 50 10 10 RESIZE 55 55 40 40 RESIZE 55 55 15 15 MOVE 55 55 40 0 CLOSE 55 55 CLOSE 110 60 MOVE 95 55 0 -100
output:
Command 4: RESIZE - window does not fit Command 7: CLOSE - no window at given position Command 9: MOVE - moved 50 instead of 100 2 window(s): 90 0 15 15 115 50 10 10
result:
ok 6 lines
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3564kb
input:
10 10 OPEN 0 0 8 8 MOVE 0 0 5 0
output:
Command 2: MOVE - moved 3 instead of 5 1 window(s): 3 0 8 8
result:
wrong answer 1st lines differ - expected: 'Command 2: MOVE - moved 2 instead of 5', found: 'Command 2: MOVE - moved 3 instead of 5'