zoukankan      html  css  js  c++  java
  • 2018 hdu 多校 第四场

    1002 BPM136 莫队

      1 /* ***********************************************
      2 Author        :BPM136
      3 Created Time  :2018/8/1 12:08:40
      4 File Name     :1002.cpp
      5 ************************************************ */
      6 
      7 #include<iostream>
      8 #include<cstdio>
      9 #include<algorithm>
     10 #include<cstdlib>
     11 #include<cmath>
     12 #include<cstring>
     13 #include<iomanip>
     14 #include<bitset>
     15 #include<queue>
     16 #include<ctime>
     17 #include<set>
     18 #include<map>
     19 #include<vector>
     20 #include<cassert>
     21 #include<functional>
     22 #define pb push_back
     23 #define popb pop_back
     24 #define MID ((l+r)>>1)
     25 #define LSON (k<<1)
     26 #define RSON (k<<1|1)
     27 #define get(a,i) ((a)&(1<<(i-1)))
     28 #define PAU putchar(32)
     29 #define ENT putchar(10)
     30 #define clr(a,b) memset(a,b,sizeof(a))
     31 #define rep(_i,_a,_b) for(int _i=(_a);_i<=(_b);_i++)
     32 #define down(_i,_a,_b) for(int _i=(_a);_i>=(_b);_i--)
     33 #define FOR(_i,_b) for(int _i=1;_i<=(_b);_i++)
     34 #define efo(_i,_a) for(int _i=last[(_a)];_i!=0;_i=e[_i].next)
     35 #define Remax(a,b) if(b>a) a=b;
     36 #define Remin(a,b) if(b<a) a=b;
     37 #define filein(x) freopen(#x".in","r",stdin)
     38 #define fileout(x) freopen(#x".out","w",stdout)
     39 #define file(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout);
     40 #define mkd(x) freopen(#x".in","w",stdout);
     41 #define setlargestack(x) int _SIZE=x<<20;char *_PPP=(char*)malloc(size)+_SIZE;__asm__("movl %0, %%esp
    " :: "r"(_PPP));
     42 #define END system("pause")
     43 #define read2(a,b) read(a),read(b)
     44 #define read3(a,b,c) read(a),read(b),read(c)
     45 #define readg(_x1,_y1,_x2,_y2) read(_x1),read(_y1),read(_x2),read(_y2)
     46 using namespace std;
     47 
     48 typedef long long ll;
     49 typedef double DB;
     50 typedef long double LD;
     51 typedef unsigned int  UI;
     52 typedef unsigned long long ULL;
     53 typedef vector<int> VI;
     54 typedef set<int> SI;
     55 typedef set<int , greater<int> > SIG;
     56 typedef map<int, int > MII;
     57 typedef map<int, int, greater<int> > MIIG;
     58 
     59 namespace fastIO{  
     60     #define BUF_SIZE 100000  
     61     #define OUT_SIZE 100000  
     62     //fread->read  
     63     bool IOerror=0;  
     64     inline char nc(){  
     65         static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;  
     66         if (p1==pend){  
     67             p1=buf; pend=buf+fread(buf,1,BUF_SIZE,stdin);  
     68             if (pend==p1){IOerror=1;return -1;}  
     69             //{printf("IO error!
    ");system("pause");for (;;);exit(0);}  
     70         }  
     71         return *p1++;  
     72     }  
     73     inline bool blank(char ch){return ch==32||ch==10||ch==13||ch==9;}  
     74     inline bool enter(char ch){return ch==10||ch==13;}
     75     inline void read(int &x){  
     76         bool sign=0; char ch=nc(); x=0;  
     77         for (;blank(ch);ch=nc());  
     78         if (IOerror)return;  
     79         if (ch==45)sign=1,ch=nc();  
     80         for (;ch>=48&&ch<=57;ch=nc())x=x*10+ch-48;  
     81         if (sign)x=-x;  
     82     }  
     83     inline void read(ll &x){  
     84         bool sign=0; char ch=nc(); x=0;  
     85         for (;blank(ch);ch=nc());  
     86         if (IOerror)return;  
     87         if (ch==45)sign=1,ch=nc();  
     88         for (;ch>=48&&ch<=57;ch=nc())x=x*10+ch-48;  
     89         if (sign)x=-x;  
     90     }  
     91     inline void read(double &x){  
     92         bool sign=0; char ch=nc(); x=0;  
     93         for (;blank(ch);ch=nc());  
     94         if (IOerror)return;  
     95         if (ch==45)sign=1,ch=nc();  
     96         for (;ch>=48&&ch<=57;ch=nc())x=x*10+ch-48;  
     97         if (ch==46){  
     98             double tmp=1; ch=nc();  
     99             for (;ch>=48&&ch<=57;ch=nc())tmp/=10.0,x+=tmp*(ch-48);  
    100         }  
    101         if (sign)x=-x;  
    102     }  
    103     inline void read(char *s){  
    104         char ch=nc();  
    105         for (;blank(ch);ch=nc());  
    106         if (IOerror)return;  
    107         for (;!blank(ch)&&!IOerror;ch=nc())*s++=ch;  
    108         *s=0;  
    109     }  
    110     inline void read(char *s,bool f) {
    111         char ch=nc();
    112         for (;blank(ch);ch=nc());
    113         if(IOerror)return;
    114         for(;!enter(ch)&&!IOerror;ch=nc())*s++=ch;
    115         *s=0;
    116     }
    117     inline void read(char &c){  
    118         for (c=nc();blank(c);c=nc());  
    119         if (IOerror){c=-1;return;}  
    120     } 
    121 #undef OUT_SIZE  
    122 #undef BUF_SIZE  
    123 }; using namespace fastIO;
    124 
    125 const int N = 200005;
    126 const ll MOD = 1e9 + 7;
    127 
    128 ll inv[N];
    129 ll fac[N];
    130 ll fac_inv[N];
    131 int T;
    132 
    133 ll C(int n,int m) {
    134     return fac[n]*fac_inv[m]%MOD*fac_inv[n-m]%MOD;
    135 }
    136 
    137 struct ques {
    138     int n,m;
    139     ll ans;
    140     int id;
    141     int posl;
    142 }q[N];
    143 int bsz;
    144 
    145 bool cmpq(ques a,ques b) {
    146     if(a.posl==b.posl) return a.n<b.n;
    147     return a.posl<b.posl;
    148 }
    149 
    150 bool cmpid(ques a,ques b) {
    151     return a.id<b.id;
    152 }
    153 
    154 void solve() {
    155     ll ans=1;
    156     for(int n=1,m=0,i=1;i<=T;i++) {
    157         for(;n<q[i].n;n++) {
    158             ans=ans*2-C(n,m);
    159             if(ans<0) ans+=MOD;
    160             if(ans>=MOD) ans-=MOD;
    161         }
    162         for(;n>q[i].n;n--) ans=(ans+C(n-1,m))*inv[2]%MOD;
    163         for(;m<q[i].m;m++) {
    164             ans=ans+C(n,m+1);
    165             if(ans>MOD) ans-=MOD;
    166         }
    167         for(;m>q[i].m;m--) {
    168             ans=ans-C(n,m);
    169             if(ans<0) ans+=MOD;
    170         }
    171 
    172         q[i].ans=ans;
    173     }
    174 }
    175 
    176 int main() {
    177     inv[0]=fac[0]=1; inv[1]=1;
    178     rep(i,1,N-1) fac[i]=fac[i-1]*i%MOD;
    179     rep(i,2,N-1) inv[i]=(MOD-MOD/i)*inv[MOD%i]%MOD;
    180     fac_inv[0]=1; rep(i,1,N-1) fac_inv[i]=fac_inv[i-1]*inv[i]%MOD;
    181     scanf("%d",&T);
    182     bsz=sqrt(T)+1;
    183     rep(i,1,T) {
    184         scanf("%d%d",&q[i].n,&q[i].m);
    185         q[i].id=i;
    186         q[i].posl=(q[i].m-1)/bsz+1;
    187     }
    188     sort(q+1,q+T+1,cmpq);
    189     solve();
    190     sort(q+1,q+T+1,cmpid);
    191 
    192     rep(i,1,T) printf("%lld
    ",q[i].ans);
    193     return 0;
    194 }
    View Code

    1004 BPM136 垃圾题(小声bb

      1 /* ***********************************************
      2 Author        :BPM136
      3 Created Time  :2018/8/1 12:39:04
      4 File Name     :1004.cpp
      5 ************************************************ */
      6 
      7 #include<iostream>
      8 #include<cstdio>
      9 #include<algorithm>
     10 #include<cstdlib>
     11 #include<cmath>
     12 #include<cstring>
     13 #include<iomanip>
     14 #include<bitset>
     15 #include<queue>
     16 #include<ctime>
     17 #include<set>
     18 #include<map>
     19 #include<vector>
     20 #include<cassert>
     21 #include<functional>
     22 #define pb push_back
     23 #define popb pop_back
     24 #define MID ((l+r)>>1)
     25 #define LSON (k<<1)
     26 #define RSON (k<<1|1)
     27 #define get(a,i) ((a)&(1<<(i-1)))
     28 #define PAU putchar(32)
     29 #define ENT putchar(10)
     30 #define clr(a,b) memset(a,b,sizeof(a))
     31 #define rep(_i,_a,_b) for(int _i=(_a);_i<=(_b);_i++)
     32 #define down(_i,_a,_b) for(int _i=(_a);_i>=(_b);_i--)
     33 #define FOR(_i,_b) for(int _i=1;_i<=(_b);_i++)
     34 #define efo(_i,_a) for(int _i=last[(_a)];_i!=0;_i=e[_i].next)
     35 #define Remax(a,b) if(b>a) a=b;
     36 #define Remin(a,b) if(b<a) a=b;
     37 #define filein(x) freopen(#x".in","r",stdin)
     38 #define fileout(x) freopen(#x".out","w",stdout)
     39 #define file(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout);
     40 #define mkd(x) freopen(#x".in","w",stdout);
     41 #define setlargestack(x) int _SIZE=x<<20;char *_PPP=(char*)malloc(size)+_SIZE;__asm__("movl %0, %%esp
    " :: "r"(_PPP));
     42 #define END system("pause")
     43 #define read2(a,b) read(a),read(b)
     44 #define read3(a,b,c) read(a),read(b),read(c)
     45 #define readg(_x1,_y1,_x2,_y2) read(_x1),read(_y1),read(_x2),read(_y2)
     46 using namespace std;
     47 
     48 typedef long long ll;
     49 typedef double DB;
     50 typedef long double LD;
     51 typedef unsigned int  UI;
     52 typedef unsigned long long ULL;
     53 typedef vector<int> VI;
     54 typedef set<int> SI;
     55 typedef set<int , greater<int> > SIG;
     56 typedef map<int, int > MII;
     57 typedef map<int, int, greater<int> > MIIG;
     58 
     59 namespace fastIO{  
     60     #define BUF_SIZE 100000  
     61     #define OUT_SIZE 100000  
     62     //fread->read  
     63     bool IOerror=0;  
     64     inline char nc(){  
     65         static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;  
     66         if (p1==pend){  
     67             p1=buf; pend=buf+fread(buf,1,BUF_SIZE,stdin);  
     68             if (pend==p1){IOerror=1;return -1;}  
     69             //{printf("IO error!
    ");system("pause");for (;;);exit(0);}  
     70         }  
     71         return *p1++;  
     72     }  
     73     inline bool blank(char ch){return ch==32||ch==10||ch==13||ch==9;}  
     74     inline bool enter(char ch){return ch==10||ch==13;}
     75     inline void read(int &x){  
     76         bool sign=0; char ch=nc(); x=0;  
     77         for (;blank(ch);ch=nc());  
     78         if (IOerror)return;  
     79         if (ch==45)sign=1,ch=nc();  
     80         for (;ch>=48&&ch<=57;ch=nc())x=x*10+ch-48;  
     81         if (sign)x=-x;  
     82     }  
     83     inline void read(ll &x){  
     84         bool sign=0; char ch=nc(); x=0;  
     85         for (;blank(ch);ch=nc());  
     86         if (IOerror)return;  
     87         if (ch==45)sign=1,ch=nc();  
     88         for (;ch>=48&&ch<=57;ch=nc())x=x*10+ch-48;  
     89         if (sign)x=-x;  
     90     }  
     91     inline void read(double &x){  
     92         bool sign=0; char ch=nc(); x=0;  
     93         for (;blank(ch);ch=nc());  
     94         if (IOerror)return;  
     95         if (ch==45)sign=1,ch=nc();  
     96         for (;ch>=48&&ch<=57;ch=nc())x=x*10+ch-48;  
     97         if (ch==46){  
     98             double tmp=1; ch=nc();  
     99             for (;ch>=48&&ch<=57;ch=nc())tmp/=10.0,x+=tmp*(ch-48);  
    100         }  
    101         if (sign)x=-x;  
    102     }  
    103     inline void read(char *s){  
    104         char ch=nc();  
    105         for (;blank(ch);ch=nc());  
    106         if (IOerror)return;  
    107         for (;!blank(ch)&&!IOerror;ch=nc())*s++=ch;  
    108         *s=0;  
    109     }  
    110     inline void read(char *s,bool f) {
    111         char ch=nc();
    112         for (;blank(ch);ch=nc());
    113         if(IOerror)return;
    114         for(;!enter(ch)&&!IOerror;ch=nc())*s++=ch;
    115         *s=0;
    116     }
    117     inline void read(char &c){  
    118         for (c=nc();blank(c);c=nc());  
    119         if (IOerror){c=-1;return;}  
    120     } 
    121 #undef OUT_SIZE  
    122 #undef BUF_SIZE  
    123 }; using namespace fastIO;
    124 
    125 ll a[10000];
    126 
    127 
    128 ll Ceil(ll sum,ll k) {
    129     ll ret=sum/k;
    130     if(sum%k) ret++;
    131     return ret;
    132 }
    133 
    134 int main() {
    135     ll T;
    136     read(T);
    137     while(T--) {
    138         ll n,m;
    139         read2(n,m);
    140         rep(i,1,n) {
    141             ll x,y;
    142             read2(x,y);
    143             a[i]=y;
    144         }
    145         sort(a+1,a+n+1);
    146         ll sum=m,ans=0;
    147         rep(i,1,n) {
    148             if(sum<a[i]+1) break;
    149             sum/=(a[i]+1);
    150             ans++;
    151         }
    152         printf("%lld
    ",ans);
    153     }
    154     return 0;
    155 }
    View Code

    1005 BPM136 发现每2n*2n的矩阵都是相同的,所以熔池一下就好了qaq

      1 /* ***********************************************
      2 Author        :BPM136
      3 Created Time  :2018/8/1 14:43:40
      4 File Name     :1005.cpp
      5 ************************************************ */
      6 
      7 #include<iostream>
      8 #include<cstdio>
      9 #include<algorithm>
     10 #include<cstdlib>
     11 #include<cmath>
     12 #include<cstring>
     13 #include<iomanip>
     14 #include<bitset>
     15 #include<queue>
     16 #include<ctime>
     17 #include<set>
     18 #include<map>
     19 #include<vector>
     20 #include<cassert>
     21 #include<functional>
     22 #define pb push_back
     23 #define popb pop_back
     24 #define MID ((l+r)>>1)
     25 #define LSON (k<<1)
     26 #define RSON (k<<1|1)
     27 #define get(a,i) ((a)&(1<<(i-1)))
     28 #define PAU putchar(32)
     29 #define ENT putchar(10)
     30 #define clr(a,b) memset(a,b,sizeof(a))
     31 #define rep(_i,_a,_b) for(int _i=(_a);_i<=(_b);_i++)
     32 #define down(_i,_a,_b) for(int _i=(_a);_i>=(_b);_i--)
     33 #define FOR(_i,_b) for(int _i=1;_i<=(_b);_i++)
     34 #define efo(_i,_a) for(int _i=last[(_a)];_i!=0;_i=e[_i].next)
     35 #define Remax(a,b) if(b>a) a=b;
     36 #define Remin(a,b) if(b<a) a=b;
     37 #define filein(x) freopen(#x".in","r",stdin)
     38 #define fileout(x) freopen(#x".out","w",stdout)
     39 #define file(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout);
     40 #define mkd(x) freopen(#x".in","w",stdout);
     41 #define setlargestack(x) int _SIZE=x<<20;char *_PPP=(char*)malloc(size)+_SIZE;__asm__("movl %0, %%esp
    " :: "r"(_PPP));
     42 #define END system("pause")
     43 #define read2(a,b) read(a),read(b)
     44 #define read3(a,b,c) read(a),read(b),read(c)
     45 #define readg(_x1,_y1,_x2,_y2) read(_x1),read(_y1),read(_x2),read(_y2)
     46 using namespace std;
     47 
     48 typedef long long ll;
     49 typedef double DB;
     50 typedef long double LD;
     51 typedef vector<int> VI;
     52 typedef set<int> SI;
     53 typedef set<int , greater<int> > SIG;
     54 typedef map<int, int > MII;
     55 typedef map<int, int, greater<int> > MIIG;
     56 
     57 namespace fastIO{  
     58     #define BUF_SIZE 100000  
     59     #define OUT_SIZE 100000  
     60     //fread->read  
     61     bool IOerror=0;  
     62     inline char nc(){  
     63         static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;  
     64         if (p1==pend){  
     65             p1=buf; pend=buf+fread(buf,1,BUF_SIZE,stdin);  
     66             if (pend==p1){IOerror=1;return -1;}  
     67             //{printf("IO error!
    ");system("pause");for (;;);exit(0);}  
     68         }  
     69         return *p1++;  
     70     }  
     71     inline bool blank(char ch){return ch==32||ch==10||ch==13||ch==9;}  
     72     inline bool enter(char ch){return ch==10||ch==13;}
     73     inline void read(int &x){  
     74         bool sign=0; char ch=nc(); x=0;  
     75         for (;blank(ch);ch=nc());  
     76         if (IOerror)return;  
     77         if (ch==45)sign=1,ch=nc();  
     78         for (;ch>=48&&ch<=57;ch=nc())x=x*10+ch-48;  
     79         if (sign)x=-x;  
     80     }  
     81     inline void read(ll &x){  
     82         bool sign=0; char ch=nc(); x=0;  
     83         for (;blank(ch);ch=nc());  
     84         if (IOerror)return;  
     85         if (ch==45)sign=1,ch=nc();  
     86         for (;ch>=48&&ch<=57;ch=nc())x=x*10+ch-48;  
     87         if (sign)x=-x;  
     88     }  
     89     inline void read(double &x){  
     90         bool sign=0; char ch=nc(); x=0;  
     91         for (;blank(ch);ch=nc());  
     92         if (IOerror)return;  
     93         if (ch==45)sign=1,ch=nc();  
     94         for (;ch>=48&&ch<=57;ch=nc())x=x*10+ch-48;  
     95         if (ch==46){  
     96             double tmp=1; ch=nc();  
     97             for (;ch>=48&&ch<=57;ch=nc())tmp/=10.0,x+=tmp*(ch-48);  
     98         }  
     99         if (sign)x=-x;  
    100     }  
    101     inline void read(char *s){  
    102         char ch=nc();  
    103         for (;blank(ch);ch=nc());  
    104         if (IOerror)return;  
    105         for (;!blank(ch)&&!IOerror;ch=nc())*s++=ch;  
    106         *s=0;  
    107     }  
    108     inline void read(char *s,bool f) {
    109         char ch=nc();
    110         for (;blank(ch);ch=nc());
    111         if(IOerror)return;
    112         for(;!enter(ch)&&!IOerror;ch=nc())*s++=ch;
    113         *s=0;
    114     }
    115     inline void read(char &c){  
    116         for (c=nc();blank(c);c=nc());  
    117         if (IOerror){c=-1;return;}  
    118     } 
    119 #undef OUT_SIZE  
    120 #undef BUF_SIZE  
    121 }; using namespace fastIO;
    122 
    123 const int N = 105;
    124 
    125 int M[N][N];
    126 int A[N];
    127 int L;
    128 ll sum;
    129 
    130 ll calc(ll x,ll y) {
    131     if(x<0 || y<0) return 0;
    132     ll numx=x/L+1;
    133     ll numy=y/L+1;
    134     ll dx=x%L;
    135     ll dy=y%L;
    136     ll ret=sum*(numx-1)*(numy-1);
    137     
    138     ll sumx=0;
    139     rep(i,0,dx) rep(j,0,L-1) sumx+=M[i][j];
    140     
    141     ll sumy=0;
    142     rep(i,0,L-1) rep(j,0,dy) sumy+=M[i][j];
    143 
    144     ret+=sumx*(numy-1)+sumy*(numx-1);
    145 
    146     rep(i,0,dx) rep(j,0,dy) ret+=M[i][j];
    147     return ret;
    148 }
    149 
    150 int t[1000][1000];
    151 int main() {
    152     int T;
    153     read(T);
    154     while(T--) {
    155         int n;
    156         read(n);
    157         rep(i,0,n-1) read(A[i]);
    158 
    159         L=n*2;
    160 
    161         clr(M,0);
    162         int cursor = 0;
    163         for (int i = 0; i<L*3 ; ++i) {
    164             for (int j = 0; j <= i; ++j) { 
    165                 if(j<L && i-j<L) M[j][i - j] = A[cursor];
    166                 cursor = (cursor + 1) % n;
    167             }
    168         }
    169         sum=0;
    170         rep(i,0,L-1) rep(j,0,L-1) sum+=M[i][j];
    171 
    172         ll Q,x0,x1,y0,y1;
    173         read(Q);
    174         while(Q--) {
    175             readg(x0,y0,x1,y1);
    176             ll ans=calc(x0-1,y0-1)-calc(x0-1,y1)-calc(x1,y0-1)+calc(x1,y1);
    177             printf("%lld
    ",ans);
    178         }
    179     }
    180     return 0;
    181 }
    View Code

    1007 BPM136 注意size使用的时候要转化成intQAQQQ

    solve函数太恶心了最后偷偷去看了别人的= =

    不过思路还是很明显的

      1 #define FOR(_i,_b) for(int _i=1;_i<=(_b);_i++)
      2 #define efo(_i,_a) for(int _i=last[(_a)];_i!=0;_i=e[_i].next)
      3 #define Remax(a,b) if(b>a) a=b;
      4 #define Remin(a,b) if(b<a) a=b;
      5 #define SZ(x) ((int)(x).size())
      6 #define filein(x) freopen(#x".in","r",stdin)
      7 #define fileout(x) freopen(#x".out","w",stdout)
      8 #define file(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout);
      9 #define mkd(x) freopen(#x".in","w",stdout);
     10 #define setlargestack(x) int _SIZE=x<<20;char *_PPP=(char*)malloc(size)+_SIZE;__asm__("movl %0, %%esp
    " :: "r"(_PPP));
     11 #define END system("pause")
     12 #define read2(a,b) read(a),read(b)
     13 #define read3(a,b,c) read(a),read(b),read(c)
     14 #define readg(_x1,_y1,_x2,_y2) read(_x1),read(_y1),read(_x2),read(_y2)
     15 using namespace std;
     16 
     17 typedef long long ll;
     18 typedef double DB;
     19 typedef long double LD;
     20 typedef unsigned int  UI;
     21 typedef unsigned long long ULL;
     22 typedef vector<int> VI;
     23 typedef set<int> SI;
     24 typedef set<int , greater<int> > SIG;
     25 typedef map<int, int > MII;
     26 typedef map<int, int, greater<int> > MIIG;
     27 
     28 namespace fastIO{  
     29     #define BUF_SIZE 100000  
     30     #define OUT_SIZE 100000  
     31     //fread->read  
     32     bool IOerror=0;  
     33     inline char nc(){  
     34         static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;  
     35         if (p1==pend){  
     36             p1=buf; pend=buf+fread(buf,1,BUF_SIZE,stdin);  
     37             if (pend==p1){IOerror=1;return -1;}  
     38             //{printf("IO error!
    ");system("pause");for (;;);exit(0);}  
     39         }  
     40         return *p1++;  
     41     }  
     42     inline bool blank(char ch){return ch==32||ch==10||ch==13||ch==9;}  
     43     inline bool enter(char ch){return ch==10||ch==13;}
     44     inline void read(int &x){  
     45         bool sign=0; char ch=nc(); x=0;  
     46         for (;blank(ch);ch=nc());  
     47         if (IOerror)return;  
     48         if (ch==45)sign=1,ch=nc();  
     49         for (;ch>=48&&ch<=57;ch=nc())x=x*10+ch-48;  
     50         if (sign)x=-x;  
     51     }  
     52     inline void read(ll &x){  
     53         bool sign=0; char ch=nc(); x=0;  
     54         for (;blank(ch);ch=nc());  
     55         if (IOerror)return;  
     56         if (ch==45)sign=1,ch=nc();  
     57         for (;ch>=48&&ch<=57;ch=nc())x=x*10+ch-48;  
     58         if (sign)x=-x;  
     59     }  
     60     inline void read(double &x){  
     61         bool sign=0; char ch=nc(); x=0;  
     62         for (;blank(ch);ch=nc());  
     63         if (IOerror)return;  
     64         if (ch==45)sign=1,ch=nc();  
     65         for (;ch>=48&&ch<=57;ch=nc())x=x*10+ch-48;  
     66         if (ch==46){  
     67             double tmp=1; ch=nc();  
     68             for (;ch>=48&&ch<=57;ch=nc())tmp/=10.0,x+=tmp*(ch-48);  
     69         }  
     70         if (sign)x=-x;  
     71     }  
     72     inline void read(char *s){  
     73         char ch=nc();  
     74         for (;blank(ch);ch=nc());  
     75         if (IOerror)return;  
     76         for (;!blank(ch)&&!IOerror;ch=nc())*s++=ch;  
     77         *s=0;  
     78     }  
     79     inline void read(char *s,bool f) {
     80         char ch=nc();
     81         for (;blank(ch);ch=nc());
     82         if(IOerror)return;
     83         for(;!enter(ch)&&!IOerror;ch=nc())*s++=ch;
     84         *s=0;
     85     }
     86     inline void read(char &c){  
     87         for (c=nc();blank(c);c=nc());  
     88         if (IOerror){c=-1;return;}  
     89     } 
     90 #undef OUT_SIZE  
     91 #undef BUF_SIZE  
     92 }; using namespace fastIO;
     93 
     94 const int N = 1000005;
     95 const ll MOD = 1e9 + 7;
     96 
     97 ll KSM(ll a,ll k) {
     98     ll ret=1%MOD;
     99     for(;k;k>>=1) {
    100         if(k&1) ret=ret*a%MOD;
    101         a=a*a%MOD;
    102     }
    103     return ret;
    104 }
    105 
    106 ll inv[N];
    107 ll fac[N];
    108 ll fac_inv[N];
    109 
    110 VI E[N];
    111 ll val[N];
    112 ll val_inv[N];
    113 int a[N];
    114 int n;
    115 ll ans;
    116 int ind;
    117 
    118 struct lowbit_tree {
    119     VI T;
    120     int n;
    121     void init(int _n) {
    122         n=_n;
    123         T.resize(n+1);
    124         rep(i,0,n) T[i]=0;
    125     }
    126     void add(int x,int val) {
    127         for(int i=x;i<=n;i+=i&-i) T[i]+=val;
    128     }
    129     ll sum(int x) {
    130         ll ret=0;
    131         if(x>n) x=n;
    132         for(int i=x;i>0;i-=i&-i) ret+=T[i];
    133         return ret;
    134     }
    135 }t[N];
    136 
    137 void prework() {
    138     inv[0]=fac[0]=inv[1]=fac_inv[0]=1;
    139     rep(i,1,N-1) fac[i]=fac[i-1]*i%MOD;
    140     rep(i,2,N-1) inv[i]=(MOD-MOD/i)*inv[MOD%i]%MOD;
    141     rep(i,1,N-1) fac_inv[i]=fac_inv[i-1]*inv[i]%MOD;
    142 }
    143 
    144 void init() {
    145     rep(i,1,n) E[i].clear();
    146     ans=0;
    147 }
    148 
    149 void dfs(int x,int pre) {
    150     sort(E[x].begin(),E[x].end());
    151     if(pre!=-1) E[x].erase(lower_bound(E[x].begin(),E[x].end(),pre));
    152     val[x]=fac[SZ(E[x])];
    153     for(auto v : E[x]) {
    154         dfs(v,x);
    155         val[x]=val[x]*val[v]%MOD;
    156     }
    157     val_inv[x]=KSM(val[x],MOD-2);
    158     t[x].init(SZ(E[x]));
    159     rep(i,0,SZ(E[x])-1) t[x].add(i+1,1);
    160 }
    161 
    162 /*
    163 void dfs_(int x,int pre,int k) {
    164     ll mul=1;
    165     for(auto v : E[x]) mul=(mul*val[v])%MOD;
    166 
    167     if(lower_bound(E[x].begin(),E[x].end(),a[k+1])==E[x].end()) {
    168         ans=(ans+E[x].size()*fac[E[x].size()]%MOD*mul%MOD)%MOD;
    169         return ;
    170     }
    171     int cnt=lower_bound(E[x].begin(),E[x].end(),a[k+1])-E[x].begin();
    172     if(pre<a[k+1]) cnt--;
    173     ans=(ans+E[x].size()*fac[E[x].size()]*mul)%MOD;
    174     dfs_(a[k+1],a[k],k+1);
    175 }
    176 */
    177 
    178 bool solve(int x,int pre,ll _mul) {
    179     ll mul=1; ind++;
    180     for(auto v : E[x])  mul=mul*val[v]%MOD;
    181     rep(i,0,SZ(E[x])-1) {
    182         int dx=lower_bound(E[x].begin(),E[x].end(),a[ind+1])-E[x].begin();
    183         int cnt=t[x].sum(dx);
    184         ans=(ans+mul*fac[SZ(E[x])-i-1]%MOD*_mul%MOD*cnt%MOD)%MOD;
    185         if(dx==E[x].size() || E[x][dx]!=a[ind+1]) return 0;
    186         t[x].add(dx+1,-1);
    187         mul=mul*val_inv[E[x][dx]]%MOD;
    188         if(solve(E[x][dx], x, mul*fac[SZ(E[x])-i-1]%MOD*_mul%MOD)==0) return 0;
    189     }
    190     return 1;
    191 }
    192 
    193 int main() {
    194     prework();
    195 
    196     int T;
    197     read(T);
    198     while(T--) {
    199         read(n);
    200 
    201         init();
    202 
    203         rep(i,1,n) read(a[i]);
    204         rep(i,1,n-1) {
    205             int x,y;
    206             read2(x,y);
    207             E[x].pb(y);
    208             E[y].pb(x);
    209         }
    210         ll mul=1;
    211         rep(i,1,n) mul=(mul*fac[E[i].size()-1])%MOD;
    212         rep(i,1,a[1]-1) ans=(ans+mul*fac[E[i].size()]%MOD*fac_inv[E[i].size()-1]%MOD)%MOD;
    213 
    214         dfs(a[1],-1);
    215         //dfs_(a[1],n+1,1);
    216         ind=0;
    217         solve(a[1],-1,1);
    218 
    219         printf("%lld
    ",ans);
    220     }
    221     return 0;
    222 }
    View Code

    1010 小洛洛

      1 #include <iostream>
      2 #include <cstdio>
      3 #include <cstdlib>
      4 #include <cstring>
      5 #include <cmath>
      6 #include <algorithm>
      7 #include <cstdint>
      8 using namespace std;
      9 
     10 typedef uint16_t u16;
     11 
     12 char s[16][17];
     13 u16 tbl[4][4][4][2][4], room[4][4];
     14 
     15 void rot_(u16 a[][4]) {
     16   u16 b[4][4];
     17   for(int i = 0; i < 4; ++i)
     18     for(int j = 0; j < 4; ++j)
     19       b[j][3 - i] = a[i][j];
     20   memcpy(a, b, sizeof b);
     21 }
     22 
     23 void load_room_(u16 arr[][2][4]) {
     24   for(int ifs = 0; ifs < 4; ++ifs, rot_(room)) {
     25     for(int i = 0; i < 4; ++i) {
     26       u16 row = 0;
     27       for(int j = 0; j < 4; ++j)
     28         row |= room[i][j];
     29       arr[ifs][0][i] = row;
     30     }
     31     for(int j = 0; j < 4; ++j) {
     32       u16 col = 0;
     33       for(int i = 0; i < 4; ++i)
     34         col |= room[i][j];
     35       arr[ifs][1][j] = col;
     36     }
     37   }
     38 }
     39 
     40 void load_() {
     41   for(int i = 0; i < 4; ++i)
     42     for(int j = 0; j < 4; ++j) {
     43       for(int x = 0; x < 4; ++x)
     44         for(int y = 0; y < 4; ++y) {
     45           char c = s[i * 4 + x][j * 4 + y];
     46           if('0' <= c && c <= '9')
     47             room[x][y] = 1u << (c - '0');
     48           else
     49             room[x][y] = 1u << (c - 'A' + 10);
     50         }
     51       load_room_(tbl[i][j]);
     52     }
     53 }
     54 
     55 int ans;
     56 u16 row[16], col[16];
     57 
     58 void dfs_(int ix, int iy, int cnt) {
     59   if(cnt >= ans) return;
     60   if(ix == 4 && iy == 0) {
     61     ans = cnt;
     62     return;
     63   }
     64   int nx, ny;
     65   if(iy == 3) nx = ix + 1, ny = 0;
     66   else nx = ix, ny = iy + 1;
     67 
     68   for(int ifs = 0; ifs < 4; ++ifs) {
     69     u16 (*blk)[4] = tbl[ix][iy][ifs];
     70     int i;
     71     for(i = 0; i < 4; ++i)
     72       if(row[ix * 4 + i] & blk[0][i])
     73         break;
     74       else
     75         row[ix * 4 + i] |= blk[0][i];
     76     if(i == 4) {
     77       int j;
     78       for(j = 0; j < 4; ++j)
     79         if(col[iy * 4 + j] & blk[1][j])
     80           break;
     81         else
     82           col[iy * 4 + j] |= blk[1][j];
     83       if(j == 4)
     84         dfs_(nx, ny, cnt + ifs);
     85       for(--j; j >= 0; --j)
     86         col[iy * 4 + j] ^= blk[1][j];
     87     }
     88     for(--i; i >= 0; --i)
     89       row[ix * 4 + i] ^= blk[0][i];
     90   }
     91 }
     92 
     93 int main() {
     94   int t;
     95   scanf("%d", &t);
     96   while(t--) {
     97     for(int i = 0; i < 16; ++i)
     98       scanf("%s", s[i]);
     99     load_();
    100     ans = 16 * 3;
    101     dfs_(0, 0, 0);
    102     printf("%d
    ", ans);
    103   }
    104   return 0;
    105 }
    View Code

    1011 小洛洛

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstdlib>
     4 #include <cstring>
     5 #include <cmath>
     6 #include <algorithm>
     7 using namespace std;
     8 
     9 const int LEN = 505;
    10 char s[LEN];
    11 
    12 bool chk_(int n) {
    13   if(s[0] == '+' || s[0] == '*') return false;
    14   if(s[0] == '?') s[0] = '1';
    15   for(int i = 1; i < n; ++i) {
    16     if(s[i - 1] == '+' || s[i - 1] == '*') {
    17       if(s[i] == '+' || s[i] == '*')
    18         return false;
    19       else if(s[i] == '?')
    20         s[i] = '1';
    21     } else if(s[i - 1] == '0' &&
    22         (i - 1 == 0 || s[i - 2] == '+' || s[i - 2] == '*')) {
    23       if(s[i] >= '0' && s[i] <= '9')
    24         return false;
    25       else if(s[i] == '?')
    26         s[i] = '+';
    27     } else if(s[i] == '?')
    28       s[i] = '1';
    29   }
    30   if(s[n - 1] == '+' || s[n - 1] == '*') return false;
    31   return true;
    32 }
    33 
    34 int main() {
    35   int t;
    36   scanf("%d", &t);
    37   while(t--) {
    38     scanf("%s", s);
    39     int n = strlen(s);
    40     if(chk_(n))
    41       puts(s);
    42     else
    43       puts("IMPOSSIBLE");
    44   }
    45   return 0;
    46 }
    View Code

    1012 小洛洛

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstdlib>
     4 #include <cstring>
     5 #include <cmath>
     6 #include <algorithm>
     7 using namespace std;
     8 
     9 const int N = 100002;
    10 int w[N];
    11 
    12 int main() {
    13   int t;
    14   scanf("%d", &t);
    15   while(t--) {
    16     int n;
    17     scanf("%d", &n);
    18     for(int i = 0; i < n; ++i)
    19       scanf("%d", w + i);
    20     double ans = sqrt((double)abs(w[0] - w[n - 1]));
    21     printf("%d
    ", (int)(ans + 1e-9));
    22   }
    23   return 0;
    24 }
    View Code
  • 相关阅读:
    vision transformer
    亮剑,gacutil.exe
    MOSS自定义登陆页面
    查看应用程序的进程ID
    基于AD的表单认证 Moss2010
    js 实现拖动
    获取指定数据库表, 以及指定表的数据信息
    二分法
    JZ053表示数值的字符串
    JZ054字符流中第一个不重复的字符
  • 原文地址:https://www.cnblogs.com/MyGirlfriends/p/9410433.html
Copyright © 2011-2022 走看看