zoukankan      html  css  js  c++  java
  • 牛客练习赛43B Tachibana Kanade Loves Probability

    题目链接:https://ac.nowcoder.com/acm/contest/548/C

    题目大意

      略

    分析

      利用快速幂先移到 k1 位,然后开始一个一个取余数。

    代码如下

      1 #include <bits/stdc++.h>
      2 using namespace std;
      3  
      4 #define INIT() std::ios::sync_with_stdio(false);std::cin.tie(0);
      5 #define Rep(i,n) for (int i = 0; i < (n); ++i)
      6 #define For(i,s,t) for (int i = (s); i <= (t); ++i)
      7 #define rFor(i,t,s) for (int i = (t); i >= (s); --i)
      8 #define ForLL(i, s, t) for (LL i = LL(s); i <= LL(t); ++i)
      9 #define rForLL(i, t, s) for (LL i = LL(t); i >= LL(s); --i)
     10 #define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
     11 #define rforeach(i,c) for (__typeof(c.rbegin()) i = c.rbegin(); i != c.rend(); ++i)
     12  
     13 #define pr(x) cout << #x << " = " << x << "  "
     14 #define prln(x) cout << #x << " = " << x << endl
     15  
     16 #define LOWBIT(x) ((x)&(-x))
     17  
     18 #define ALL(x) x.begin(),x.end()
     19 #define INS(x) inserter(x,x.begin())
     20  
     21 #define ms0(a) memset(a,0,sizeof(a))
     22 #define msI(a) memset(a,inf,sizeof(a))
     23 #define msM(a) memset(a,-1,sizeof(a))
     24 #define mcy(d,s) memcpy(d, s, sizeof(s))
     25 
     26 #define MP make_pair
     27 #define PB push_back
     28 #define ft first
     29 #define sd second
     30  
     31 template<typename T1, typename T2>
     32 istream &operator>>(istream &in, pair<T1, T2> &p) {
     33     in >> p.first >> p.second;
     34     return in;
     35 }
     36  
     37 template<typename T>
     38 istream &operator>>(istream &in, vector<T> &v) {
     39     for (auto &x: v)
     40         in >> x;
     41     return in;
     42 }
     43  
     44 template<typename T1, typename T2>
     45 ostream &operator<<(ostream &out, const std::pair<T1, T2> &p) {
     46     out << "[" << p.first << ", " << p.second << "]" << "
    ";
     47     return out;
     48 }
     49 
     50 inline int gc(){
     51     static const int BUF = 1e7;
     52     static char buf[BUF], *bg = buf + BUF, *ed = bg;
     53     
     54     if(bg == ed) fread(bg = buf, 1, BUF, stdin);
     55     return *bg++;
     56 } 
     57 
     58 inline int ri(){
     59     int x = 0, f = 1, c = gc();
     60     for(; c<48||c>57; f = c=='-'?-1:f, c=gc());
     61     for(; c>47&&c<58; x = x*10 + c - 48, c=gc());
     62     return x*f;
     63 }
     64  
     65 typedef long long LL;
     66 typedef unsigned long long uLL;
     67 typedef pair< double, double > PDD;
     68 typedef pair< int, int > PII;
     69 typedef pair< string, int > PSI;
     70 typedef set< int > SI;
     71 typedef vector< int > VI;
     72 typedef map< int, int > MII;
     73 typedef pair< LL, LL > PLL;
     74 typedef vector< LL > VL;
     75 typedef vector< VL > VVL;
     76 const double EPS = 1e-10;
     77 const LL inf = 0x7fffffff;
     78 const LL infLL = 0x7fffffffffffffffLL;
     79 const LL mod = 1e9 + 7;
     80 const int maxN = 5e3 + 7;
     81 const LL ONE = 1;
     82 const LL evenBits = 0xaaaaaaaaaaaaaaaa;
     83 const LL oddBits = 0x5555555555555555;
     84 
     85 LL T, m, n, k1, k2;
     86 
     87 // Calculate x^y % p
     88 inline LL pow_mod(LL x, LL y, LL p = mod){
     89     LL ret = 1;
     90     while(y){
     91         if(y & 1) ret = (ret * x) % p;
     92         x = (x * x) % p;
     93         y >>= 1;
     94     }
     95     return ret;
     96 } 
     97 
     98 int main(){
     99     INIT(); 
    100     cin >> T;
    101     while(T--){
    102         cin >> m >> n >> k1 >> k2;
    103         m = m * pow_mod(10, k1-1, n) % n;
    104         
    105         Rep(i, k2-k1+1) {
    106             m *= 10;
    107             cout << m / n;
    108             m %= n;
    109         }
    110         cout << endl;
    111     }
    112     return 0;
    113 }
    View Code
  • 相关阅读:
    unity3d 几种镜头畸变
    深度学习主机环境配置: Ubuntu16.04 + GeForce GTX 1070 + CUDA8.0 + cuDNN5.1 + TensorFlow
    Autofac 中间件使用
    NetCore SignalR 重连逻辑实现
    CentOS 7 安装 MySql8.0
    CentOS 7 安装 Nginx
    CentOS 7 安装 Docker
    Nginx 配置站点
    VUE AXIOS 跨域问题
    CentOS 7 安装 MySql 8
  • 原文地址:https://www.cnblogs.com/zaq19970105/p/10869524.html
Copyright © 2011-2022 走看看