zoukankan      html  css  js  c++  java
  • ACM训练联盟周赛 G. Teemo's convex polygon

    •  65536K
     

    Teemo is very interested in convex polygon. There is a convex n-sides polygon, and Teemo connect every two points as diagonal lines, and he want to kown how many segments which be divided into intersections. Teemo ensure that any three diagonals do not intersect at a point.

    As the result may be very large, please output the result mod 1000000007.

    Input Format

    The input contains several test cases, and the first line is a positive integer T indicating the number of test cases which is up to 100.

    For each test case, the first line contains an integer n(3<=n<=10^18).

    Output Format

    For each test case, output a line containing an integer that indicates the answer.

    样例输入

    2
    3
    4

    样例输出

    0
    4


     1 #include <iostream>
     2 #include <cstdio>
     3 #include <algorithm>
     4 #include <cstdlib>
     5 #include <cstring>
     6 #include <string>
     7 #include <deque>
     8 #include <map>
     9 #include <vector>
    10 #include <stack>
    11 using namespace std;
    12 #define  ll long long 
    13 #define  N   29
    14 #define  M 1000000000
    15 #define  gep(i,a,b)  for(int  i=a;i<=b;i++)
    16 #define  gepp(i,a,b) for(int  i=a;i>=b;i--)
    17 #define  gep1(i,a,b)  for(ll i=a;i<=b;i++)
    18 #define  gepp1(i,a,b) for(ll i=a;i>=b;i--)    
    19 #define  mem(a,b)  memset(a,b,sizeof(a))
    20 #define  ph  push_back
    21 #define  mod  1000000007
    22 void  egcd(ll a,ll b,ll &x,ll &y)
    23 {
    24     ll d=a;
    25     if(!b) {
    26         x=1;y=0;
    27         return ;
    28     }
    29     else{
    30         egcd(b,a%b,y,x);
    31         y-=(a/b)*x;
    32     }
    33 }
    34 ll inv(int n){
    35     ll x,y;
    36     egcd(n,mod,x,y);
    37     return (x%mod+mod)%mod;
    38 }
    39 int t;
    40 ll n;
    41 /*
    42 //任意三个无交点
    43 n*(n-3) : 凸多边形的每个顶点与其他的点连接形成的线段数目
    44 4*C(n,4) : 4个点形成形内1顶点,而1个点出现4个分割的线段
    45 都出现了两次
    (C(n,4)*4+n*(n-3))/2
    46 / 47 int main() 48 { 49 scanf("%d",&t); 50 while(t--) 51 { 52 scanf("%lld",&n); 53 n%=mod;//避免溢出 54 ll ans=n*(n-3)%mod*(8+n*n%mod-3*n%mod+mod)%mod*inv(12)%mod; 55 printf("%lld ",ans); 56 } 57 return 0; 58 }
  • 相关阅读:
    Entity Framework使用汇总
    关于大型网站技术演进的思考(二)--存储的瓶颈(中)(转)
    关于大型网站技术演进的思考(一)--存储的瓶颈(上)(转)
    百度十年产品经验总结:产品经理的独孤九剑
    2014年最热门的国人开发开源软件TOP100
    将javadoc附加到eclipse中
    Equals与GetHashcode
    AngularJS学习笔记二
    AngularJS学习笔记一
    Visual Studio无法解析nuget的解决方法
  • 原文地址:https://www.cnblogs.com/tingtin/p/9512856.html
Copyright © 2011-2022 走看看