zoukankan      html  css  js  c++  java
  • 牛客 136J-洋灰三角 +高中数学博大精深

    参考学习:http://www.cnblogs.com/l609929321/p/9500814.html

    牛客 136J-洋灰三角

    题意:

       在一个1 * n的棋盘中,第一格放1,之后的每一个放前一个格子的k倍多P个石子,问填满整个棋盘需要多少个石子。

    思路:

      

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    #include <string>
    #include <vector>
    #include <map>
    #include <set>
    #include <queue>
    #include <list>
    #include <cstdlib>
    #include <iterator>
    #include <cmath>
    #include <iomanip>
    #include <bitset>
    #include <cctype>
    using namespace std;
    //#pragma GCC optimize(3)
    //#pragma comment(linker, "/STACK:102400000,102400000")  //c++
    #define lson (l , mid , rt << 1)
    #define rson (mid + 1 , r , rt << 1 | 1)
    #define debug(x) cerr << #x << " = " << x << "
    ";
    #define pb push_back
    #define pq priority_queue
    
    
    
    typedef long long ll;
    typedef unsigned long long ull;
    
    typedef pair<ll ,ll > pll;
    typedef pair<int ,int > pii;
    typedef pair<int ,pii> p3;
    //priority_queue<int> q;//这是一个大根堆q
    //priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
    #define fi first
    #define se second
    //#define endl '
    '
    
    #define OKC ios::sync_with_stdio(false);cin.tie(0)
    #define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行
    #define REP(i , j , k)  for(int i = j ; i <  k ; ++i)
    //priority_queue<int ,vector<int>, greater<int> >que;
    
    const ll mos = 0x7FFFFFFFLL;  //2147483647
    const ll nmos = 0x80000000LL;  //-2147483648
    const int inf = 0x3f3f3f3f;
    const ll inff = 0x3f3f3f3f3f3f3f3fLL; //18
    const double PI=acos(-1.0);
    
    template<typename T>
    inline T read(T&x){
        x=0;int f=0;char ch=getchar();
        while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
        while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
        return x=f?-x:x;
    }
    // #define _DEBUG;         //*//
    #ifdef _DEBUG
    freopen("input", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    /*-----------------------show time----------------------*/
                
                const int mod = 1e9+7;
                ll ksm (ll a,ll n){
                    ll res = 1;
                    while(n>0){
                        if(n&1) res = res * a%mod;
                        a = a * a %mod;
                        n >>= 1;
                    }
                    return res;
                }
    int main(){     
                ll n,k,p;
                cin>>n>>k>>p;
                if(k==1){
                    cout<<(n*(n-1)%mod*ksm(2,mod-2) * p%mod + n)%mod<<endl;
                    return 0;
                }
                ll ans = (((ksm(k,n) - 1 + mod)*ksm(k-1,mod-2))%mod*(1 + p * ksm(k-1, mod-2)%mod) + mod)%mod;
                ans = ((ans - (n*p%mod*ksm(k-1,mod-2))%mod)%mod+mod)%mod;
                cout<<ans<<endl;
                return 0; 
    }
    View Code
  • 相关阅读:
    结对第二次作业——某次疫情统计可视化的实现
    结对第一次—疫情统计可视化(原型设计)
    寒假作业(2/2)——疫情统计
    软工实践寒假作业(1/2)
    3DMAX三维编辑命令FFD的使用
    个人作业——软件工程实践总结&个人技术博客
    个人作业——软件评测
    结对第二次作业——某次疫情统计可视化的实现
    软工实践寒假作业(2/2)
    软工实践寒假作业(1/2)
  • 原文地址:https://www.cnblogs.com/ckxkexing/p/9520366.html
Copyright © 2011-2022 走看看