Matrix
来源:互联网 发布:rbac php 编辑:程序博客网 时间:2024/05/22 13:22
Matrix
题目:
查看武森路文。
算法:
用二维数状水过。模板题。
/* 浅谈信息学竞赛中的 “0” 和“1” 二进制思想在信息学竞赛中的应用*/#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>using namespace std;#define lowbit(x)(x&-x)const int MAXN = 1000 + 10;int n,c[MAXN][MAXN];void add(int x,int y,int val){ while(x <= n){ int i = y; while(i <= n){ c[x][i] += val; i += lowbit(i); } x += lowbit(x); }}int sum(int x,int y){ int res = 0; while(x > 0){ int i = y; while(i > 0){ res += c[x][i]; i -= lowbit(i); } x -= lowbit(x); } return res;}int main(){ int T,Q; scanf("%d",&T); while(T--){ scanf("%d%d",&n,&Q); memset(c,0,sizeof(c)); char ask[3]; int x1,y1,x2,y2; while(Q--){ scanf("%s",ask); if(ask[0] == 'C'){ scanf("%d%d%d%d",&x1,&y1,&x2,&y2); add(x1,y1,1); add(x1,y2 + 1,1); add(x2 + 1,y1,1); add(x2 + 1,y2 + 1,1); } else { scanf("%d%d",&x1,&y1); int ans = sum(x1,y1); printf("%d\n",ans % 2); } } } return 0;}/* 浅谈信息学竞赛中的 “0” 和“1” 二进制思想在信息学竞赛中的应用*/#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>using namespace std;#define lowbit(x)(x&-x)const int MAXN = 1000 + 10;int n,c[MAXN][MAXN];void add(int x,int y,int val){ while(x <= n){ int i = y; while(i <= n){ c[x][i] += val; i += lowbit(i); } x += lowbit(x); }}int sum(int x,int y){ int res = 0; while(x > 0){ int i = y; while(i > 0){ res += c[x][i]; i -= lowbit(i); } x -= lowbit(x); } return res;}int main(){ int T,Q; scanf("%d",&T); while(T--){ scanf("%d%d",&n,&Q); memset(c,0,sizeof(c)); char ask[3]; int x1,y1,x2,y2; while(Q--){ scanf("%s",ask); if(ask[0] == 'C'){ scanf("%d%d%d%d",&x1,&y1,&x2,&y2); add(x1,y1,1); add(x1,y2 + 1,1); add(x2 + 1,y1,1); add(x2 + 1,y2 + 1,1); } else { scanf("%d%d",&x1,&y1); int ans = sum(x1,y1); printf("%d\n",ans % 2); } } } return 0;}
0 0
- 《Matrix》
- Matrix
- Matrix
- Matrix
- Matrix
- Matrix
- Matrix
- mAtrix
- Matrix
- matrix
- Matrix
- Matrix
- Matrix
- Matrix
- Matrix
- Matrix
- Matrix
- Matrix
- STM32 产生随机数
- 前端工程师必备-网址篇
- 机器学习手记[2]---朴素贝叶斯在拼写检查的应用
- PowerDesigner使用教程
- Android里的名词解释及作用(这里指开发过程)
- Matrix
- CSDN编程挑战:3n+1
- 私有属性与封装
- 关于double的输入格式
- Box2D——错误
- 用C++写字符图像类,参考C++沉思录第9、10章
- qsort的用法
- 轻量级研发知识管理--如何帮助研发人员建设过程资产
- 虚拟无线网卡桥接上网