zoukankan      html  css  js  c++  java
  • bzoj2751: [HAOI2012]容易题(easy)

     结论很简单,就是把每个位置的数相加再相乘就好了。对于限制比较少,而位置比较多,所以处理出限制的位置,剩余位置用快速幂就好了。

     1 #include<bits/stdc++.h>
     2 #define N 100005
     3 #define LL long long
     4 #define inf 0x3f3f3f3f
     5 #define ls c[x][0]
     6 #define rs c[x][1]
     7 using namespace std;
     8 inline int ra()
     9 {
    10     int x=0,f=1; char ch=getchar();
    11     while (ch<'0' || ch>'9') {if (ch=='-') f=-1; ch=getchar();}
    12     while (ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
    13     return x*f;
    14 }
    15 const LL mod=1000000007LL;
    16 LL n,m,k;
    17 struct node{
    18     LL x,y;
    19 }a[N];
    20 bool operator == (node a, node b)
    21 {
    22     return a.x==b.x && a.y==b.y;
    23 }
    24 bool cmp(node a, node b)
    25 {
    26     if (a.x==b.x) return a.y<b.y;
    27     return a.x<b.x;
    28 }
    29 LL ksm(LL x, LL p)
    30 {
    31     LL sum=1;
    32     for (;p;p>>=1,x=x*x%mod)
    33         if (p&1) sum=sum*x%mod;
    34     return sum%mod; 
    35 }
    36 int main()
    37 {
    38     n=ra(); m=ra(); k=ra();
    39     LL sum=(n+1)*n/2%mod;
    40     for (LL i=1; i<=k; i++)
    41         a[i].x=ra(),a[i].y=ra();
    42     sort(a+1,a+k+1,cmp);
    43     LL ans=1; LL tot=1;
    44     LL del=0;
    45     for (int i=1; i<=k; i++)
    46         if (a[i].x!=a[i-1].x) m--;
    47     for (int i=1,last; i<=k; i=last)
    48     {
    49         LL now=sum;
    50         for (last=i;a[last].x==a[i].x;last++)
    51             if (last==i || a[last].y!=a[last-1].y)
    52                 now=(now-a[last].y+mod)%mod;
    53         ans=ans*now%mod;
    54     }
    55     ans=(ans*ksm(sum,m))%mod;
    56     cout<<(ans+mod)%mod;
    57     return 0;
    58 }
  • 相关阅读:
    c++字符串排序
    JAVA实现四则运算的简单计算器
    JAVA图形小动画之简单行星运动
    JAVA多线程编程
    ege图形库之简单贪吃蛇(c++)
    ege图形库之动画排序
    mysql 性能优化方案
    MYSQL 优化常用方法
    [手把手教你] 用Swoft 搭建微服务(TCP RPC)
    php有效防止同一用户多次登录
  • 原文地址:https://www.cnblogs.com/ccd2333/p/6418029.html
Copyright © 2011-2022 走看看