B. Ants

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/317/problem/B

Description

It has been noted that if some ants are put in the junctions of the graphene integer lattice then they will act in the following fashion: every minute at each junction (x, y) containing at least four ants a group of four ants will be formed, and these four ants will scatter to the neighbouring junctions (x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1) — one ant in each direction. No other ant movements will happen. Ants never interfere with each other.

Scientists have put a colony of n ants into the junction (0, 0) and now they wish to know how many ants will there be at some given junctions, when the movement of the ants stops.

Input

First input line contains integers n (0 ≤ n ≤ 30000) and t (1 ≤ t ≤ 50000), where n is the number of ants in the colony and t is the number of queries. Each of the next t lines contains coordinates of a query junction: integers xi, yi ( - 109 ≤ xi, yi ≤ 109). Queries may coincide.

It is guaranteed that there will be a certain moment of time when no possible movements can happen (in other words, the process will eventually end).

Output

Print t integers, one per line — the number of ants at the corresponding junctions when the movement of the ants stops.

Sample Input

1 3
0 1
0 0
0 -1

Sample Output

0
1
0

HINT

题意

一个格子中的蚂蚁如果大于等于4个,这四个蚂蚁就会向四周扩散,扩散到(x+1,y),(x-1,y),(x,y+1),(x,y-1)这四个格子

然后q次查询,每次查询(x,y)格子里面有多少个蚂蚁

题解:

蚂蚁最多为30000个,假设所有格子都是4只蚂蚁,那么也就最多30000/4=7500个格子

然后我们直接就好啦~

代码:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 1000
#define mod 10007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;
}
//**************************************************************************************int a[maxn][maxn];
void solve(int x,int y)
{if(a[x][y]<3)a[x][y]++;else{a[x][y]=0;solve(x+1,y);solve(x,y+1);solve(x,y-1);solve(x-1,y);}
}
int main()
{int n=read(),q=read();for(int i=0;i<n;i++)solve(500,500);for(int i=0;i<q;i++){int x=read(),y=read();if(x>100||x<-100||y>100||y<-100)cout<<"0"<<endl;elseprintf("%d\n",a[x+500][y+500]);}
}

Codeforces Round #188 (Div. 1) B. Ants 暴力相关推荐

  1. 暴力+构造 Codeforces Round #283 (Div. 2) C. Removing Columns

    题目传送门 1 /* 2 题意:删除若干行,使得n行字符串成递增排序 3 暴力+构造:从前往后枚举列,当之前的顺序已经正确时,之后就不用考虑了,这样删列最小 4 */ 5 /************* ...

  2. Codeforces Round #743 (Div. 2) E. Paint 区间dp + 暴力

    传送门 文章目录 题意: 思路: 题意: 给你一个有nnn个像素的图像,每个像素都有一个颜色aia_iai​,保证每种颜色的图像不会超过202020个.你现在每次可以选择一个颜色,并选择一段连续的像素 ...

  3. Codeforces Round #588 (Div. 2) E. Kamil and Making a Stream 数学 + 暴力

    传送门 文章目录 题意: 思路: 题意: 给你一颗树,其中根是111,每个点有一个点权,求每个点到根的所有路径的gcdgcdgcd之和. n≤1e5n\le1e5n≤1e5 思路: 一看到以为是个点分 ...

  4. Codeforces Round #593 (Div. 2) D. Alice and the Doll 暴力 + 二分

    传送门 文章目录 题意: 思路: 题意: 思路: 还以为这个题有什么高深的算法,结果就是个暴力. 由于n∗mn*mn∗m达到了1e101e101e10的级别,所以直接暴力肯定是不行的,考虑有很多空格, ...

  5. 暴力 Codeforces Round #183 (Div. 2) A. Pythagorean Theorem II

    题目传送门 1 /* 2 暴力:O (n^2) 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <c ...

  6. Codeforces Round #271 (Div. 2) C. Captain Marmot (暴力枚举+正方形判定)

    题目链接:Codeforces Round #271 (Div. 2) C. Captain Marmot 题意:给4行数据,每行2个点.(x,y).(a,b).意思是(x,y)绕(a,b)逆时针旋转 ...

  7. Codeforces Round #636 (Div. 3) F. Restore the Permutation by Sorted Segments 思维 + 暴力

    传送门 文章目录 题意: 思路: 题意: n≤200n\le200n≤200 思路: 首先关注到rrr从[2,n][2,n][2,n]都出现一次,所以很明显最后一个位置只出现一次,但是这样倒着来不是很 ...

  8. Codeforces Round #635 (Div. 2) D. Xenia and Colorful Gems 暴力 + 二分

    传送门 文章目录 题意: 思路: 题意: 给你三个数组a,b,ca,b,ca,b,c,让你从每个数组中选择一个数x,y,zx,y,zx,y,z,使得(x−y)2+(x−z)2+(y−z)2(x-y)^ ...

  9. Codeforces Round #723 (Div. 2) D. Kill Anton 线段树 + 暴力

    传送门 文章目录 题意: 思路: 题意: 给你一个只有ANTOANTOANTO四个字母的字符串,你每次可以交换相邻两个,花费为111,让后让你打乱字符串,使得将打乱的字符串还原为原来的字符串的花费最小 ...

最新文章

  1. Windows 7安全补丁KB3110329遭遇更新失败 且暂无解决方法
  2. 就业模拟试题_Net(答案)
  3. mysql 主键唯一,MySQL。关键表中的主键。唯一ID还是多个唯一键?
  4. ARM Linux.2.6.34内核移植
  5. ES6——generator与yield
  6. Leetcode每日一题:56. I. 数组中数字出现的次数
  7. 【Python笔记】正则表达式
  8. python 中decorator和property
  9. Security - 轻量级Java身份认证、访问控制安全框架
  10. Excel快速填充列
  11. 编译原理中单线箭头->和双线箭头=>有什么区别
  12. PHP命名空间 namespace 及 use 的用法
  13. 基于GAN的动漫头像生成
  14. centos7 设置网络(静态ip),联网失败,DNS解析失败(被覆盖),虚拟机
  15. php 获取微博cookie,c#获取新浪微博登录cookie
  16. THREEJS相关3d-force-graph 3d力导图使用
  17. k折交叉验证KFold()函数
  18. java操纵excel文件2
  19. java 时间戳最大值_Java中在时间戳计算的过程中遇到的数据溢出问题解决
  20. 文件服务器升级方案,如何进行SOLIDWORKS PDM文件服务器的升级

热门文章

  1. 新手探索NLP(十一)——知识图谱
  2. GMM 模型需不需归一化问题
  3. 在Linux上进行内核参数调整
  4. angularJS学习笔记一
  5. Intersection of Two Linked Lists——经典问题
  6. gsonformat安装怎么使用_车载蓝牙充电器怎么安装使用?如何运用
  7. python时间序列分析航空旅人_时间序列分析-ARIMA模型(python)
  8. selenium判断元素是否存在_如何判断宝宝是否缺微量元素?
  9. 菏泽中考报名不报计算机,2020菏泽中考报名人数:94559人
  10. bool转nsnumber ios_iOS 的 NSNumber(对基本数据类型) NSValue(对结构体) 的装箱