codeforces C. Inna and Huge Candy Matrix】的更多相关文章

http://codeforces.com/problemset/problem/400/C 题意:给你一个n*m的矩阵,然后在矩阵中有p个糖果,给你每个糖果的初始位置,然后经过x次顺时针反转,y次旋转,z次逆时针反转,问最后每个糖果的位置. 思路:推出顺时针反转.旋转.逆时针反转的坐标的变化即可. #include <cstdio> #include <cstring> #include <cmath> #include <iostream> #defin…
题目链接:http://codeforces.com/problemset/problem/400/C 题目意思:给出一个n行m列的矩阵,问经过 x 次clockwise,y 次 horizontal rotate 和z次counterclockwise 之后,原来在n行m列的矩阵的坐标去到哪个位置. 题目意思很容易看懂.易知,对于clockwise,counterclockwise的次数,mod 4 == 0 相当于没有改变!而对于 horizontal rotate,mod 2 == 0 也…
#include <iostream> #include <vector> #include <algorithm> #include <utility> using namespace std; typedef pair<int,int> Point; int n,m; void clockwise_rotate(Point &cell, int x){ ; i < x; ++ i){ int tmp = cell.first;…
题意:给出一个矩形的三种操作,顺时针旋转,逆时针旋转,对称,给出原始坐标,再给出操作数,问最后得到的坐标 画一下模拟一下操作就可以找到规律了 #include<iostream> #include<cstdio> #include<cstring> #include <cmath> #include<stack> #include<vector> #include<map> #include<set> #inc…
本题的主要算法就是区间更新和区间求和: 可以用线段树和树状数组来做: 感觉线段树写的太麻烦了,看到官方题解上说可以用树状数组做,觉得很神奇,以前用过的树状数组都是单点维护,区间求和的: 其实树状数组还可以区间维护,单点求值:和区间维护,区间求和的: 详情请见博客. #include<cstdio> #include<cstring> #include<cmath> #include<iostream> #define maxn 4000010 #define…
树状数组仅仅能实现线段树区间改动和区间查询的功能,能够取代不须要lazy tag的线段树.且代码量和常数较小 首先定义一个数组 int c[N]; 并清空 memset(c, 0, sizeof c); 1.单点改动 : c[x] += y; 相应的函数是 change(x, y); 2.求前缀和 :  相应的函数是 int sum(x) 两种操作的复杂度都是O(logn) 模板例如以下: int c[N], maxn; inline int Lowbit(int x){return x&(-x…
题目链接:点击打开链接 题意:给定n*m的二维平面 w个操作 int mp[n][m] = { 0 }; 1.0 (x1,y1) (x2,y2) value for i : x1 to x2 for j : y1 to y2 mp[i][j] += value; 2.1 (x1, y1) (x2 y2) ans1 = 纵坐标在 y1,y2间的总数 ans2 = 横坐标不在x1,x2间的总数 puts(ans1-ans2); more format: for i : 1 to n for j :…
几个小结论: 1.路径长度=i+j-1; 2.最简单的走法是先横走再竖着走或者先竖着走再横着走 #include<cstdio> #include<cstring> using namespace std; void print(int x,int y) { ; i<=y; i++) printf("(1,%d) ",i); ; i<=x; i++) printf("(%d,%d) ",i,y); printf("\n&…
这个题目看似不是很好下手,不过很容易发现每次询问的时候总是会问到第r个盒子是否有糖果: 这样的话就很好办事了: 维护两个数组: 一个sum数组:累加和: 一个in数组:如果i位是1的话,in[i]=in[i-k]+1;否则不加1,很好理解: 然后利用in数组可以找到本来应该有糖果的但是没有糖果的箱子的数目: 然后结合sum数组就可以的出结果: #include<cstdio> #include<cstring> #define maxn 100005 using namespace…
题目链接:http://codeforces.com/problemset/problem/374/A 题目意思:给出一个 n 行  m 列 的棋盘,要将放置在坐标点为(i, j)的 candy 移动到四个角落(1,1),(1,m),(n, 1),(n, m) 中的其中一个.假设当前在位置(x, y),规定每次移动遵循,(x+a, y+b) . (x+a, y-b). (x-a, y+b).(x-a, y-b).求最小的移动次数. 求出 (i, j) 到每个角落的距离diff_x, diff_y…