zoukankan      html  css  js  c++  java
  • 【bzoj2751】[HAOI2012]容易题(easy) 数论-快速幂

    【bzoj2751】[HAOI2012]容易题(easy)

    先考虑k=0的情况

    那么第一个元素可能为[1,n] 如果序列长度为m-1时的答案是ans[m-1]

    那么合并得

    然后同理答案就是

    k很小 而且顺序可以随便交换

    排序暴力减去就好了

     1 /* http://www.cnblogs.com/karl07/ */
     2 #include <cstdlib>
     3 #include <cstdio>
     4 #include <cstring>
     5 #include <cmath>
     6 #include <algorithm>
     7 using namespace std;
     8 
     9 const int P=1000000007;
    10 int n,m,k,cnt=0,sum,ans=1;
    11 struct data{int x,y;}d[100005];
    12 int Q_pow(int x,int y){
    13     int ans=1;
    14     while (y){
    15         if (y&1) ans=1ll*ans*x%P;
    16         x=1ll*x*x%P;
    17         y=(y>>1);
    18     }
    19     return ans;
    20 }
    21 bool oper(data a,data b) {return ((a.x<b.x) || (a.x==b.x && a.y<b.y));}
    22 
    23 int main(){
    24     scanf("%d%d%d",&n,&m,&k);
    25     sum=1ll*n*(n+1)/2%P;
    26     for (int i=1;i<=k;i++){
    27         scanf("%d%d",&d[i].x,&d[i].y);
    28     }
    29     sort(d+1,d+k+1,oper);
    30     d[k+1].x=-1;
    31     d[k+1].y=0;
    32     for (int i=2,s=1ll*(sum-d[1].y+P)%P;i<=k+1;i++){
    33         if (d[i].x!=d[i-1].x) {ans=1ll*ans*s%P; s=sum; cnt++; }
    34         if (d[i].y!=d[i-1].y || d[i].x!=d[i-1].x) s=(s-d[i].y+P)%P;
    35     }
    36     printf("%lld
    ",1ll*ans*Q_pow(sum,m-cnt)%P);
    37     return 0;
    38 }
    View Code

    这么水的题想了半天。。没有调整负数WA了几发。。药丸。。

  • 相关阅读:
    04-set方法的内存管理
    03-OC内存管理原则
    02-引用计数器的使用(含野指针、空指针)
    01-OC内存管理的基本原理
    16-NSDate
    15-NSValue
    14-NSNumber
    13-NSMutableDictionary
    12-NSDictionary(字典)
    11-NSArray和NSSet的区别
  • 原文地址:https://www.cnblogs.com/karl07/p/6596183.html
Copyright © 2011-2022 走看看