zoukankan      html  css  js  c++  java
  • codeforces Gym 100418D BOPC 打表找规律,求逆元

    BOPC
    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86686#problem/D

    Description

    You invented a new chess figure and called it BOPC. Suppose it stands at the square grid at the point with coordinates X1, Y1. The point with coordinates X2, Y2 is under attack if |X1 - X2| < |Y1 - Y2|. Let the power of the figure denote the number of fields under attack for all possible starting positions of BOPC. Your goal is to calculate the power of BOPC figure given the field size.

    Input

    Single line containing one integer N — size of the field (1 ≤ N ≤ 109).

    Output

    Single line containing power of BOPC figure given the field size modulo 109 + 7.

    Sample Input

    3

    Sample Output

    26

    HINT

    题意

    给你一个棋盘,棋盘上面有炮塔,只要满足|yj-yi|>|xj-xi|的地方,都能被攻击到

    然后就问如果这个棋盘上面,全是炮塔的话,问你一共攻击了多少个地方(一个地方可以重复攻击的)

    题解

    先打一个表,然后再找规律,不要问我为什么找到这个规律的,我也不造……

    注意,除法求mod,要写一个逆元,除此之外,就应该没什么问题了

    代码:

    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <cmath>
    
    
    using namespace std;
    const long long mod = 1e9 + 7;
    
    
    void extend_gcd(long long a , long long b , long long& d , long long & x , long long &y )
    {
      if (!b)
       {
             d = a;
             x = 1;
             y = 0;
       }
      else
       {
             extend_gcd(b,a%b,d,y,x);
             y -= x*(a/b);
       }
    }
    
    long long inv(long long a,long long n)
    {
      long long d , x , y;
      extend_gcd(a,n,d,x,y);
      return d==1? (x+n) % n : -1;
    }
    
    
    int main(int argc,char *argv[])
    {     
      long long N;
      cin >> N;
      long long check = inv(6,mod);
      long long ANS = (((N*(N-1) % mod) * ((3*N*N - N + 2) % mod)) %mod * check) % mod;
      cout << ANS << endl;
      return 0;
    }
  • 相关阅读:
    Ubuntu下hadoop2.4搭建集群(单机模式)
    软考历程(2)——海明码校验
    key 串口
    android删除文件出错
    ORACLE 11G没有备份文件參数文件在异机通过rman备份恢复找回被误删的数据
    【SICP归纳】2 高阶函数和数据抽象
    Java加密算法 AES
    从BAE到SAE,从SAE又回到BAE
    velocity-字母序号 list
    Java 加密解密 对称加密算法 非对称加密算法 MD5 BASE64 AES RSA
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4711722.html
Copyright © 2011-2022 走看看