Codeforces Round #188 (Div. 1) B. Ants 暴力
B. Ants
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/317/problem/B
Description
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
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=,f=;char ch=getchar();
- while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
- while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
- return x*f;
- }
- //**************************************************************************************
- int a[maxn][maxn];
- void solve(int x,int y)
- {
- if(a[x][y]<)
- a[x][y]++;
- else
- {
- a[x][y]=;
- solve(x+,y);
- solve(x,y+);
- solve(x,y-);
- solve(x-,y);
- }
- }
- int main()
- {
- int n=read(),q=read();
- for(int i=;i<n;i++)
- solve(,);
- for(int i=;i<q;i++)
- {
- int x=read(),y=read();
- if(x>||x<-||y>||y<-)
- cout<<""<<endl;
- else
- printf("%d\n",a[x+][y+]);
- }
- }
Codeforces Round #188 (Div. 1) B. Ants 暴力的更多相关文章
- Codeforces Round #188 (Div. 1 + Div. 2)
A. Even Odds 奇数个数\(\lfloor \frac{n+1}{2}\rfloor\) B. Strings of Power 从位置0开始,统计heavy个数,若当前为metal,则可以 ...
- Codeforces Round #307 (Div. 2) B. ZgukistringZ 暴力
B. ZgukistringZ Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/probl ...
- Codeforces Round #328 (Div. 2) A. PawnChess 暴力
A. PawnChess Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/592/problem/ ...
- Codeforces Round #404 (Div. 2)(A.水,暴力,B,排序,贪心)
A. Anton and Polyhedrons time limit per test:2 seconds memory limit per test:256 megabytes input:sta ...
- Codeforces Round #369 (Div. 2) A B 暴力 模拟
A. Bus to Udayland time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #188 (Div. 2) C. Perfect Pair 数学
B. Strings of Power Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/318/p ...
- Codeforces Round #188 (Div. 2) B. Strings of Power 水题
B. Strings of Power Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/318/p ...
- Codeforces Round #188 (Div. 2) A. Even Odds 水题
A. Even Odds Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/318/problem/ ...
- Codeforces Round #329 (Div. 2) A. 2Char 暴力
A. 2Char Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/593/problem/A De ...
随机推荐
- 新的小游戏发布啦。Pop Jungle
丛林爱消除是一款画面清新,效果绚丽的消除类休闲游戏.你只需要选中尽可能多的图块,并消除它们就可以得到高分,并有无限多的关卡等待你去征服.一旦你开始玩儿你将无法停止下来,如果你还是消除星星的粉丝,那你更 ...
- Drupal 7.23:函数drupal_alter()注释
/** * Passes alterable variables to specific hook_TYPE_alter() implementations. * * This dispatch fu ...
- Nodejs_day03
1.Stream (流) Stream有四种流类型 1.Readable - 可读操作 2.Writable - 可写操作 3.Duplex - 可读可写操作 4.Transform - 操作被写入数 ...
- CListCtrl总结.xml
pre{ line-height:1; color:#d1653c; background-color:#000000; font-size:16px;}.sysFunc{color:#566d68; ...
- 【Unity入门】碰撞检测与触发检测
版权声明:本文为博主原创文章,转载请注明出处. 在Unity里面,游戏物体的碰撞我们可以通过刚体组件(Rigidbody)和碰撞器组件(Collider)来进行检测.首先在场景里面添加一个Plane面 ...
- ansible控制windows的官方翻译
Ansible控制windows 1. Windows下如何工作 在ansible控制linux的时候,用的是ssh的方式,在windows中,使用的是power shell,在客户端机器上也是 ...
- 【LeetCode】190 & 191 - Reverse Bits & Number of 1 Bits
190 - Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 432615 ...
- 转 Flash与PS交互动画
FLASH是可以点击体验的,不是图片哦. UI中国不能上传flash,但是站酷可以,UI中国的就下载载附件看看吧 本人学生党兼网页设计师菜鸟一名,因为无聊练习做了个FLASH的交互 所以很多学弟学妹们 ...
- string 与char* char[]之间的转换 2015-04-09 11:30 29人阅读 评论(0) 收藏
1.首先必须了解,string可以被看成是以字符为元素的一种容器.字符构成序列(字符串).有时候在字符序列中进行遍历,标准的string类提供了STL容器接口.具有一些成员函数比如begin().en ...
- java getEnv不区分大小写 getProperty区分大小写
System.out.println(System.getenv("JAVA_HOME")); System.out.println(System.getenv("Pat ...