NOIP模拟:裁剪表格(链表)
来源:互联网 发布:python 异步网络框架 编辑:程序博客网 时间:2024/05/22 23:27
题意:
给一个
题解:
链表。
%%%凯爷把链表玩得如此之6.
考虑建立一个二维链表,记录右边的位置和下面的位置,每次修改只用改四周链表的指向就好了。时间复杂度
(还有,平衡树被暴力踩了也是很服气)。
#include<bits/stdc++.h>using namespace std;inline int read(){ char ch=getchar();int i=0,f=1; while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();} while(isdigit(ch)){i=(i<<1)+(i<<3)+ch-'0';ch=getchar();} return i*f;}const int Maxn=1e3+50;struct node{ node *right,*down; int val;}Pool[Maxn*Maxn],*pool=Pool,*pos[Maxn][Maxn];inline node* newnode(int val){ ++pool; pool->right=pool->down=NULL; pool->val=val; return pool;}int n,m,q;inline node* findpos(int x,int y){ node *now=pos[0][0]; for(register int i=1;i<=x;i++)now=now->down; for(register int i=1;i<=y;i++)now=now->right; return now;}inline void W(int x){ static int buf[50]; if(!x){putchar('0');return;} if(x<0){putchar('-');x=-x;} while(x){buf[++buf[0]]=x%10;x/=10;} while(buf[0])putchar(buf[buf[0]--]+'0');}int main(){ n=read(),m=read(),q=read(); pos[0][0]=newnode(0); for(register int i=1;i<=m;i++){ pos[0][i]=newnode(0); pos[0][i-1]->right=pos[0][i]; } for(register int i=1;i<=n;i++){ pos[i][0]=newnode(0); pos[i-1][0]->down=pos[i][0]; for(register int j=1;j<=m;j++){ pos[i][j]=newnode(read()); pos[i-1][j]->down=pos[i][j]; pos[i][j-1]->right=pos[i][j]; } } for(register int i=1;i<=q;i++){ int dx1=read(),dy1=read(),dx2=read(),dy2=read(),h=read(),w=read(); node *lup1=findpos(dx1-1,dy1),*lup2=findpos(dx2-1,dy2); node *lup3=findpos(dx1,dy1-1),*lup4=findpos(dx2,dy2-1); node *ldown1=findpos(dx1+h-1,dy1),*ldown2=findpos(dx2+h-1,dy2); node *rup1=findpos(dx1,dy1+w-1),*rup2=findpos(dx2,dy2+w-1); for(register int j=1;j<=w;j++){ swap(lup1->down,lup2->down); lup1=lup1->right,lup2=lup2->right; } for(register int j=1;j<=h;j++){ swap(lup3->right,lup4->right); lup3=lup3->down,lup4=lup4->down; } for(register int j=1;j<=w;j++){ swap(ldown1->down,ldown2->down); ldown1=ldown1->right,ldown2=ldown2->right; } for(register int j=1;j<=h;j++){ swap(rup1->right,rup2->right); rup1=rup1->down,rup2=rup2->down; } } for(register int i=1;i<=n;i++){ node *p=pos[i][0]; for(register int j=1;j<=m;j++){ p=p->right; W(p->val);putchar(' '); } putchar('\n'); }}
阅读全文
1 0
- NOIP模拟:裁剪表格(链表)
- NOIP模拟 裁剪表格【链表】
- [NOIP模拟][链表]裁剪表格
- NOIP模拟(10.20)T3 裁剪表格
- [NOIP2017模拟]裁剪表格
- [NOIP模拟赛]填充表格
- NOIP模拟 JZOI5428 查询 【链表】
- NOIP模拟 门票(dfs)
- NOIP模拟:Subset(分块)
- 【NOIP 模拟题】[T1]return(模拟)
- (noip 模拟 化简)<惊天大模拟>
- 【JZOJ5343】【NOIP模拟】健美猫(模拟)
- Noip模拟
- 【NOIP模拟】20151004模拟
- 【NOIP模拟】 20151005模拟
- 【NOIP模拟】 20151006模拟
- 【NOIP模拟】 20151007模拟
- 【NOIP模拟】20151014模拟
- Hadoop Yarn Capacity调度器之ACL的一个坑
- B
- 关于echart在隐藏与显示轮替中的div加载显示为空的原因分析
- ubuntu 安装notepad
- BZOJ
- NOIP模拟:裁剪表格(链表)
- sql varrchar 排序 DetachedCriteria 实现
- Apache DbUtils应用实例
- 常用命令:ls/alias & 目录结构、文件类型
- URL编码的原因及场景
- netty的编解码器介绍
- Linux添加定时服务
- 困难代码
- 第二章 Nginx服务器的安装部署【上】