Codeforces Round #188 (Div. 1) B. Ants 暴力
2015-06-14 11:49
267 查看
B. Ants
Time Limit: 20 SecMemory Limit: 256 MB
题目连接
http://codeforces.com/contest/317/problem/BDescription
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.
[b]Input[/b]
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).
[b]Output[/b]
Print t integers, one per line — the number of ants at the corresponding junctions when the movement of the ants stops.
[b]Sample Input[/b]
1 3
0 1
0 0
0 -1
[b]Sample Output[/b]
0
1
0
HINT
[b]题意[/b]一个格子中的蚂蚁如果大于等于4个,这四个蚂蚁就会向四周扩散,扩散到(x+1,y),(x-1,y),(x,y+1),(x,y-1)这四个格子
然后q次查询,每次查询(x,y)格子里面有多少个蚂蚁
[b]题解:[/b]
蚂蚁最多为30000个,假设所有格子都是4只蚂蚁,那么也就最多30000/4=7500个格子
然后我们直接就好啦~
[b]代码:[/b]
#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; else printf("%d\n",a[x+500][y+500]); } }
相关文章推荐
- 正则表达式总结之查找
- Linus多线程编程(1)
- c++ 模板联系4
- JDBC的配置(包括db.properties等)
- 《Java从入门到精通》第八章学习笔记
- c++ 模板联系4
- 在电子商务里,一般会提到这样几个词:商品、单品、SPU、SKU
- 智联招聘自动刷新简历软件
- #leetcode#Jump Game
- 【VTK】可视化管线
- 微笑面对自己的生活
- c++ 模板练习2
- C++ 一般模板友元关系
- C++ 一般模板友元关系
- c++ 模板练习2
- startActivityForResult和setResult详解
- java 线程池的原理以及使用
- Spark编译安装和运行
- GDI与OpenGL与DirectX之间的区别
- &(((AClass*)0)->aProperty) 这样的表达式会报错吗?