10.27 模拟赛
这一次终极被吊打 甚至没进前十 T2 最后改错 T3 没写正解
T1 elim
题目大意:
n 行 m 列的游戏棋盘,一行或一列上有连续 三个或更多的相同颜色的棋子时,这些棋子都被消除
当有多处可以被消除时,这些地方的棋子将同时被消除 求消除后的棋盘
思路:
sb模拟
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cstdlib> 5 #include<cmath> 6 #include<algorithm> 7 #include<queue> 8 #include<vector> 9 #include<map> 10 #define inf 2139062143 11 #define ll long long 12 #define MAXN 510 13 using namespace std; 14 inline int read() 15 { 16 int x=0,f=1;char ch=getchar(); 17 while(!isdigit(ch)) {if(ch=='-')f=-1;ch=getchar();} 18 while(isdigit(ch)) {x=x*10+ch-'0';ch=getchar();} 19 return x*f; 20 } 21 //yyc score=0 22 int n,m,mp[40][40],ans[40][40]; 23 int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1}; 24 inline int ok(int x,int y) {return x&&y&&x<=n&&y<=m;} 25 void work(int x,int y) 26 { 27 for(int i=0;i<4;i++) 28 { 29 for(int j=1;j<=2;j++) 30 if(mp[x][y]!=mp[x+dx[i]*j][y+dy[i]*j]||!ok(x+dx[i]*j,y+dy[i]*j)) goto cont; 31 for(int j=0;j<=2;j++) 32 ans[x+dx[i]*j][y+dy[i]*j]=0; 33 cont:; 34 } 35 } 36 int main() 37 { 38 freopen("elim.in","r",stdin); 39 freopen("elim.out","w",stdout); 40 n=read(),m=read(); 41 for(int i=1;i<=n;i++) 42 for(int j=1;j<=m;j++) ans[i][j]=mp[i][j]=read(); 43 for(int i=1;i<=n;i++) 44 for(int j=1;j<=m;j++) work(i,j); 45 for(int i=1;i<=n;i++,puts("")) 46 for(int j=1;j<=m;j++) printf("%d ",ans[i][j]); 47 }
T2 battleground
题目大意:
n个人在网格图上玩battleground 有f回合
每回合这些人都从上一轮的位置走向目标位置(在该回合毒圈里)
有一些障碍(不能通过且八连块斜着走的时候两边不能有障碍)
所有人每在毒圈外走一步会掉血 求最后所有人的血量
思路:
每次从圆心bfs即可
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cstdlib> 5 #include<cmath> 6 #include<algorithm> 7 #include<queue> 8 #include<vector> 9 #include<map> 10 #define inf 2139062143 11 #define ll long long 12 #define MAXN 100100 13 using namespace std; 14 inline int read() 15 { 16 int x=0,f=1;char ch=getchar(); 17 while(!isdigit(ch)) {if(ch=='-')f=-1;ch=getchar();} 18 while(isdigit(ch)) {x=x*10+ch-'0';ch=getchar();} 19 return x*f; 20 } 21 //yyc score= 0 22 struct player{int x,y,tx,ty,hp;}g[MAXN]; 23 int r,rx,ry,qx[MAXN<<2],qy[MAXN<<2],hd,tl; 24 int n,m,f,e,h,ok[420][420],vis[420][420]; 25 int dx[8]={0,1,1,1,0,-1,-1,-1},dy[8]={1,1,0,-1,-1,-1,0,1}; 26 inline int ing(int x,int y) {return x&&y&&x<=n&&y<=n;} 27 inline int inr(int x,int y) {return (x-rx)*(x-rx)+(y-ry)*(y-ry)<=r*r;} 28 inline void bfs() 29 { 30 qx[hd=tl=1]=rx,qy[1]=ry,vis[rx][ry]=1; 31 int ax,ay,a,b; 32 while(hd<=tl) 33 { 34 ax=qx[hd],ay=qy[hd++]; 35 //cout<<ax-1<<" "<<ay-1<<" "<<vis[ax][ay]<<endl; 36 for(int i=0;i<8;i++) 37 { 38 a=ax+dx[i],b=ay+dy[i]; 39 if(inr(a,b)&&ing(a,b)&&!vis[a][b]) qx[++tl]=a,qy[tl]=b,vis[a][b]=1; 40 } 41 }hd=1; 42 while(hd<=tl) 43 { 44 ax=qx[hd],ay=qy[hd++]; 45 //cout<<ax-1<<" "<<ay-1<<" "<<vis[ax][ay]<<endl; 46 for(int i=0;i<8;i++) 47 { 48 a=ax+dx[i],b=ay+dy[i]; 49 //cout<<ax-1<<" "<<ay-1<<" "<<a-1<<" "<<b-1<<" "<<vis[a][b]<<endl; 50 if(vis[a][b]||!ing(a,b)) continue; 51 qx[++tl]=a,qy[tl]=b; 52 if(i&1) 53 { 54 if(!ok[a][b]&&(!((ok[a][ay]&&!inr(a,ay))&(ok[ax][b]&&!inr(ax,b))))) {vis[a][b]=vis[ax][ay]+1;continue;} 55 } 56 else if(!ok[a][b]) { 57 //cout<<ax-1<<" "<<ay-1<<" "<<a-1<<" "<<b-1<<endl; 58 vis[a][b]=vis[ax][ay]+1;continue;} 59 //cout<<"D: "<<a-1<<" "<<b-1<<endl; 60 //cout<<ax-1<<" "<<ay-1<<" "<<a-1<<" "<<b-1<<endl; 61 tl--;if(ok[a][b]) vis[a][b]=vis[ax][ay]+1; 62 } 63 } 64 } 65 int main() 66 { 67 freopen("battleground.in","r",stdin); 68 freopen("battleground.out","w",stdout); 69 n=read(),m=read(),e=read(),f=read(),h=read(); 70 int a,b; 71 for(int i=1;i<=m;i++) g[i].hp=h; 72 for(int i=1;i<=e;i++) a=read(),b=read(),ok[a+1][b+1]=1; 73 for(int i=1;i<=m;i++) g[i].x=read()+1,g[i].y=read()+1; 74 while(f--) 75 { 76 rx=read()+1,ry=read()+1,r=read(); 77 memset(vis,0,sizeof(vis)); 78 for(int i=1;i<=m;i++) g[i].tx=read()+1,g[i].ty=read()+1; 79 bfs(); 80 for(int i=1;i<=m;i++) g[i].hp-=vis[g[i].x][g[i].y]-1,g[i].x=g[i].tx,g[i].y=g[i].ty; 81 } 82 for(int i=1;i<=m;i++) printf("%d\n",max(0,g[i].hp)); 83 }
T3 greedy
思路:
可以想到模拟
使用可删堆维护即可
(放上石神的用segment tree模拟可删堆)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<algorithm> 2 #include<cmath> 3 #include<cstdio> 4 #include<cstdlib> 5 #include<cstring> 6 #include<ctime> 7 #include<iomanip> 8 #include<iostream> 9 #include<map> 10 #include<queue> 11 #include<stack> 12 #include<vector> 13 #define rep(i,x,y) for(register int i=(x);i<=(y);i++) 14 #define dwn(i,x,y) for(register int i=(x);i>=(y);i--) 15 #define maxn 100010 16 #define maxm 1000010 17 #define ls (u<<1) 18 #define rs (u<<1|1) 19 #define mi (l+r>>1) 20 using namespace std; 21 int read() 22 { 23 int x=0,f=1;char ch=getchar(); 24 while(!isdigit(ch)&&ch!='-')ch=getchar(); 25 if(ch=='-')f=-1,ch=getchar(); 26 while(isdigit(ch))x=(x<<1)+(x<<3)+ch-'0',ch=getchar(); 27 return x*f; 28 } 29 void write(int x) 30 { 31 int f=0;char ch[20]; 32 if(!x){putchar('0'),putchar('\n');return;} 33 if(x<0)x=-x,putchar('-'); 34 while(x)ch[++f]=x%10+'0',x/=10; 35 while(f)putchar(ch[f--]); 36 putchar('\n'); 37 } 38 int mn[maxn<<2],mx[maxn<<2],in[maxn],num[maxn]; 39 int no[maxn],n,m,fir[maxn],nxt[maxm],v[maxm],cnt,now; 40 void ade(int u1,int v1){v[cnt]=v1,nxt[cnt]=fir[u1],fir[u1]=cnt++;} 41 void pumn(int u) 42 { 43 if(!mn[ls]&&!mn[rs]){mn[u]=0;return;} 44 if(!mn[ls]||!mn[rs]){mn[u]=mn[ls]+mn[rs];return;} 45 if(in[mn[ls]]<=in[mn[rs]]){mn[u]=mn[ls];return;} 46 mn[u]=mn[rs];return; 47 } 48 void pumx(int u) 49 { 50 if(!mx[ls]&&!mx[rs]){mx[u]=0;return;} 51 if(!mx[ls]||!mx[rs]){mx[u]=mx[ls]+mx[rs];return;} 52 if(in[mx[ls]]==in[mx[rs]]) 53 { 54 if(num[mx[ls]]>num[mx[rs]]){mx[u]=mx[ls];return;} 55 mx[u]=mx[rs];return; 56 } 57 if(in[mx[ls]]>in[mx[rs]]){mx[u]=mx[ls];return;}; 58 mx[u]=mx[rs];return; 59 } 60 void pu(int u){pumn(u),pumx(u);return;} 61 void build(int u,int l,int r) 62 { 63 if(l==r){mn[u]=mx[u]=l;return;} 64 build(ls,l,mi),build(rs,mi+1,r);return pu(u); 65 } 66 void del(int u,int l,int r,int x) 67 { 68 if(x==l&&r==x){mn[u]=mx[u]=0;return;} 69 if(x<=mi)del(ls,l,mi,x); 70 else del(rs,mi+1,r,x); 71 return pu(u); 72 } 73 void repu(int u,int l,int r,int x) 74 { 75 if(x==l&&r==x){return;} 76 if(x<=mi)repu(ls,l,mi,x); 77 else repu(rs,mi+1,r,x); 78 return pu(u); 79 } 80 int main() 81 { 82 freopen("greedy.in","r",stdin); 83 freopen("greedy.out","w",stdout); 84 memset(fir,-1,sizeof(fir)); 85 n=read(),m=read(); 86 rep(i,1,m){int x=read(),y=read();in[x]++,in[y]++;ade(x,y),ade(y,x);} 87 rep(u,1,n){if(in[u]==2)for(int k=fir[u];k!=-1;k=nxt[k])num[v[k]]++;} 88 build(1,1,n);now=n; 89 while(now>0) 90 { 91 int u=mn[1]; 92 if(!in[u]){write(u),now--,no[u]=1;del(1,1,n,u);continue;} 93 else if(in[u]==1) 94 { 95 write(u); 96 int vv=0; 97 for(int k=fir[u];k!=-1;k=nxt[k])if(!no[v[k]])vv=v[k]; 98 for(int k=fir[vv];k!=-1;k=nxt[k]) 99 { 100 if(no[v[k]])continue; 101 if(in[v[k]]==2)for(int tk=fir[v[k]];tk!=-1;tk=nxt[tk])if(!no[v[tk]])num[v[tk]]--,repu(1,1,n,v[tk]); 102 if(in[vv]==2)num[v[k]]--; 103 in[v[k]]--,repu(1,1,n,v[k]); 104 if(in[v[k]]==2)for(int tk=fir[v[k]];tk!=-1;tk=nxt[tk])if(!no[v[tk]])num[v[tk]]++,repu(1,1,n,v[tk]); 105 } 106 del(1,1,n,u),del(1,1,n,vv),no[u]=no[vv]=1,now-=2; 107 } 108 else 109 { 110 u=mx[1]; 111 for(int k=fir[u];k!=-1;k=nxt[k]) 112 { 113 if(no[v[k]])continue; 114 if(in[v[k]]==2)for(int tk=fir[v[k]];tk!=-1;tk=nxt[tk])if(!no[v[tk]])num[v[tk]]--,repu(1,1,n,v[tk]); 115 if(in[u]==2)num[v[k]]--; 116 in[v[k]]--,repu(1,1,n,v[k]); 117 if(in[v[k]]==2)for(int tk=fir[v[k]];tk!=-1;tk=nxt[tk])if(!no[v[tk]])num[v[tk]]++,repu(1,1,n,v[tk]); 118 } 119 del(1,1,n,u),no[u]=1,now--; 120 } 121 } 122 return 0; 123 }