zoukankan      html  css  js  c++  java
  • Codeforces Round #188 (Div. 2)D

    这题太坑了,无奈了, 当n==30000时,在我的电脑上跑了3.5s,提交竟然过了。。。 

    因为这个比较均匀散开的,所以最多只会散开成150*150(准确的来说是124*124)的一个矩阵,然后暴力即可!

    30000*100*100 在cf这题还是没有超时的

     
    D. Ants
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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 (xy) containing at least four ants a group of four ants will be formed, and these four ants will scatter to the neighbouring junctions (x + 1y), (x - 1y), (xy + 1), (xy - 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 xiyi ( - 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 test(s)
    input
    1 3
    0 1
    0 0
    0 -1
    output
    0
    1
    0
    input
    6 5
    0 -2
    0 -1
    0 0
    0 1
    0 2
    output
    0
    1
    2
    1
    0
    Note

    In the first sample the colony consists of the one ant, so nothing happens at all.

    In the second sample the colony consists of 6 ants. At the first minute 4 ants scatter from (0, 0) to the neighbouring junctions. After that the process stops.

  • 相关阅读:
    【C++】类的特殊成员变量+初始化列表
    SM Java实现
    Android使用OKHttp3实现下载(断点续传、显示运行进度)
    codeforces 486C Palindrome Transformation 贪心求构造回文
    手把手教你画AndroidK线分时图及指标
    怎样使用 iOS 7 的 AVSpeechSynthesizer 制作有声书(3)
    C# 读取Excel中的数据
    Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Query was empty
    java debug
    8种移动APP导航设计模式对照
  • 原文地址:https://www.cnblogs.com/chenhuan001/p/3137438.html
Copyright © 2011-2022 走看看