Codeforces Round \ # 188 (Div. 1) B. Ants 폭력

8334 단어 codeforces
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 30 10 00 -1
Sample Output
010
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;
        else
            printf("%d
",a[x+500][y+500]); } }

좋은 웹페이지 즐겨찾기