hdu2687

Matrix Rotation

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 512    Accepted Submission(s): 247


Problem Description
Give you a n*n matrix, if you rotate it 90 degrees, we call it 1-Matrix, if you rotate it 180 degrees, we call it 2-Matrix, etc … This is said if you rotate the Matrix 90*k degrees, then we call it k-Matrix. Now, your task is to calculate all the sum of i-Matrix (0<= i<= k).
 

Input
There multiple test cases. Each test case begins with one integer n(1 <= n <= 10), following n lines, each line contains n integers, describe the original matrix, then a single line contains a k
(1 <= k <= 10^8)described above. Process to end of file.
 

Output
For each case, output the sum of all the i-Matrix (0<= i<= k) in n lines.
Each line there are n integers separated by one space.
Note that there is no extra space at the end of each line.
 

Sample Input
  
  
3 1 2 3 2 3 4 3 4 5 10
 

Sample Output
  
  
33 32 31 34 33 32

35 34 33

参考代码:

#include <stdio.h> #include<cstdio> #include<algorithm> #include <iostream> using namespace std; const int maxn=100001; int n,m; int s[maxn<<2],sl[maxn<<2],sr[maxn<<2],ss[maxn<<2]; void pushup(int rt) {         s[rt]=s[rt<<1]+s[rt<<1|1];         sl[rt]=max(s[rt<<1|1]+sl[rt<<1],sl[rt<<1|1]);         sr[rt]=max(s[rt<<1]+sr[rt<<1|1],sr[rt<<1]);         ss[rt]=max(ss[rt<<1],ss[rt<<1|1]);         ss[rt]=max(ss[rt],sl[rt<<1]+sr[rt<<1|1]); } void init(int rt,int l,int r) {         int m=(l+r)>>1;         if(l!=r)         {                 init(rt<<1,l,m);                 init(rt<<1|1,m+1,r);                 pushup(rt);         }         else         {                 scanf("%d",&s[rt]);                 sl[rt]=sr[rt]=ss[rt]=s[rt];         } } void change(int rt,int l,int r,int t,int tt) {         if(l==t&&r==t)         {                 sl[rt]=sr[rt]=ss[rt]=s[rt]=tt;         }         else         {                 int m=(l+r)>>1;                 if(m>=t)                         change(rt<<1,l,m,t,tt);                 else                         change(rt<<1|1,m+1,r,t,tt);                 pushup(rt);         } } int main() {         int t,tt;         while(scanf("%d%d",&n,&m)!=EOF)         {                 init(1,1,n);                 while(m--)                 {                         scanf("%d%d",&t,&tt);                         change(1,1,n,t,tt);                         printf("%d\n",ss[1]);                 }         } }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值