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 ...
随机推荐
- 修改ssh服务的默认端口
修改ssh服务的默认端口 1.查看当前服务端口 一般ssh服务的默认端口为22端口,查看监听的端口用netstat,如下: [root@ansiblemoniter ~]# netstat -tnlp ...
- Chapter13:拷贝控制
拷贝控制操作:拷贝构造函数.拷贝赋值运算符.移动构造函数.移动赋值运算符.析构函数. 实现拷贝控制操作的最困难的地方是首先认识到什么时候需要定义这些操作. 拷贝构造函数: 如果一个构造函数的第一个参数 ...
- Thrift框架介绍
1.前言 Thrift是一个跨语言的服务部署框架,最初由Facebook于2007年开发,2008年进入Apache开源项目.Thrift通过一个中间语言(IDL, 接口定义语言)来定义RPC的接口和 ...
- Java基础 —— CSS
CSS:层叠样式表(Cascading Style Sheets) --> 提高显示功能,定义样式 html提供了div与span,只为了封装文本数据,div为一行数据,span为行内的数据. ...
- html5 canvas 鼠标绘制
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- ECMAScript 6 入门学习笔记(持续更新)
1.let命令(作用同var) ES6新增了let命令,用来声明变量.它的用法类似于var,但是所声明的变量,只在let命令所在的代码块内有效. { let a = 10; var b = 1; } ...
- oracle数据库建表
create or replace directory dumpdir as 'E:\oracle\dumpdir';create temporary tablespace ydxt_temp tem ...
- 第三百三十四天 how can I 坚持
I give up my dream that day,else,I coming on,the day my heart is die…… 那天,梦已碎,那天,心已死. 晚上看了个电影<奔爱& ...
- 用UltraISO制作的u盘ubuntu11.04,启动失败解决方案
错误提示:SYSLINUX 3.84 2009-12-18 EBIOS Copyright c 1994-2009 H.Peter Anvin et al 折腾的很久,尝试用Pauly的bootice ...
- CodeForces 709C Letters Cyclic Shift (水题)
题意:给定一个字符串,让你把它的一个子串字符都减1,使得总字符串字典序最小. 析:由于这个题是必须要有一个字串,所以你就要注意这个只有一个字符a的情况,其他的就从开始减 1,如果碰到a了就不减了,如果 ...