2018.8.26 练习赛

  • T1 函数
  • 题面:
  • 题解:
  • 堆code:
  •  1 #include<cstdio>
     2 #include<cstdlib>
     3 #include<cmath>
     4 #include<queue>
     5 #define maxn 100005
     6 #define db long double
     7 using namespace std;
     8 struct func {
     9     db k,v;
    10 };
    11 bool operator >(func a,func b) {
    12     return a.v>b.v;
    13 }
    14 db nb[maxn];
    15 priority_queue<func,vector<func>,greater<func> > q;
    16 db l,r,n,x;
    17 int main() {
    18     scanf("%Lf%Lf%Lf%Lf",&l,&r,&x,&n);
    19     for(db i=l; i<=r; i+=1) q.push((func) {
    20         i,i*sqrt(x)+1
    21     });
    22     while(n>1) {
    23         func t=q.top();
    24         q.pop();
    25         q.push((func) {
    26             t.k,t.v+1.0
    27         });
    28         n--;
    29     }
    30     printf("%.2Lf",q.top().v);
    31 }
    View Code

     

  • T2 情侣
  • 题面:
  • 题解:
  • 具体转移实现见code注释部分:
  •  1 #include<stdio.h>
     2 #include<algorithm>
     3 #include<ctype.h>
     4 #define ll long long
     5 #define inv2 499122177
     6 #define mod 998244353
     7 using namespace std;
     8 
     9 ll t;
    10 ll D[5005];
    11 int f[5005][5005];
    12 
    13 char buf[1<<20],*p1,*p2;
    14 inline char gc() {
    15     return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin))==p1?0:*p1++;
    16 }
    17 
    18 template<typename T>
    19 void read(T &x) {
    20     char tt;
    21     bool flag=0;
    22     while(!isdigit(tt=gc())&&tt!='-');
    23     tt=='-'?(x=0,flag=1):(x=tt-'0');
    24     while(isdigit(tt=gc())) x=x*10+tt-'0';
    25     if(flag) x=-x;
    26 }
    27 
    28 ll ksm(ll a,ll b) {
    29     ll ans=1;
    30     for(; b; b>>=1,a=(long long)a*a%mod)
    31         if(b&1) ans=(long long)ans*a%mod;
    32     return ans;
    33 }
    34 //f[i][j]
    35 //空2*i+1
    36 //情侣空 j
    37 //非情侣空2*i+1-j
    38 //f[1][1]=1
    39 //f[i][j]+=
    40 //在一起:
    41 //不拆 f[i-1][j-1]*(2*(i-1)+(1-(j-1)))=f[i-1][j-1]*(2*i-j)
    42 //拆 f[i-1][j]*j
    43 //不在一起:
    44 //不拆 f[i-1][j]*(2*(i-1)+1-j)*(2*(i-1)-j)>>1
    45 //拆一对  f[i-1][j+1]*(j+1)*(2*(i-1)-j)
    46 //拆两对  f[i-1][j+2]*(j+2)*(j+1)>>1
    47 void sent() {
    48     f[1][1]=1;
    49     for(ll i=2; i<=5000; i++)
    50         for(ll j=0; j<=i; j++) {
    51             if(j)f[i][j]=(f[i][j]+f[i-1][j-1]*(2*i-j)%mod)%mod;
    52             f[i][j]=(f[i][j]+f[i-1][j]*j%mod)%mod;
    53             f[i][j]=(f[i][j]+f[i-1][j]*(2*(i-1)+1-j)%mod*(2*(i-1)-j)%mod*inv2%mod)%mod;
    54             f[i][j]=(f[i][j]+f[i-1][j+1]*(j+1)%mod*(2*(i-1)-j)%mod)%mod;
    55             f[i][j]=(f[i][j]+f[i-1][j+2]*(j+2)%mod*(j+1)%mod*inv2%mod);
    56         }
    57 
    58     fact[0]=1;
    59     for(int i=1; i<=10000; i++) fact[i]=fact[i-1]*i%mod;
    60     ll now=inv2;
    61     for(int i=1; i<=5000; i++) {
    62         ni[i]=fact[i*2]*now%mod;
    63         now=now*inv2%mod;
    64     }
    65 }
    66 
    67 int main() {
    68     read(t);
    69     sent();
    70     while(t--) {
    71         ll n,d;
    72         read(n),read(d);
    73         D[0]=1;
    74         ll ans=f[n][0];
    75         for(ll i=1; i<=n; i++) {
    76             D[i]=D[i-1]*d%mod;
    77             ans=(ans+D[i]*f[n][i]%mod)%mod;
    78         }
    79         printf("%lld\n",ans*ksm(ni[n],mod-2)%mod);
    80     }
    81     return 0;
    82 }
    View Code

     

  • T3 军训(今日毒瘤)
  • 题面:
  • 题解:
  • std code:
  •   1 #pragma GCC optimize(3)
      2 #include<stdio.h>
      3 #include<ctype.h>
      4 #include<cmath>
      5 #include<cstring>
      6 #define RG register
      7 #define maxn 300005
      8 #define db double
      9 using namespace std;
     10 char buf[1<<20],*p1,*p2;
     11 #define GC (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?0:*p1++)
     12 inline int R_int()
     13 {
     14     char t=GC;
     15     int x=0,f=1;
     16     while(!isdigit(t)&&t!='-') t=GC;
     17     if(t=='-') f=-1,t=GC;
     18     while(isdigit(t)) x=x*10+t-48,t=GC;
     19     return f*x;
     20 }
     21 inline char R_alp()
     22 {
     23     char t=GC;
     24     while(!isalpha(t)) t=GC;
     25     return t;
     26 }
     27 struct op{char id;db v1,v2;}a[maxn];
     28 typedef db Mat[4][4];
     29 typedef db Vec[4];
     30 const db Pi=acos(-1.0);
     31 int ls[maxn*2],rs[maxn*2],tot=1,n,m;
     32 op lazy[maxn*2];
     33 int pd[maxn*2];
     34 Mat lval[maxn*2],rval[maxn*2];
     35 inline void Mulmat(Mat &at,Mat &s,Mat &c)
     36 {
     37     static db b[4][4],a[4][4];
     38     for(RG int i=1;i<=3;i++)
     39         for(RG int j=1;j<=3;j++)
     40             b[i][j]=s[j][i],a[i][j]=at[i][j];
     41     for(RG int i=1;i<=3;i++)
     42         for(RG int j=1;j<=3;j++)
     43         {
     44             RG db t=0;
     45             for(db *x=a[i]+1,*y=b[j]+1,k=1;k<=3;++x,++y,++k) t+=*x**y;
     46             c[i][j]=t;
     47         }
     48 }
     49 inline void Mulvec(Vec &a,Mat &s,Vec &c)
     50 {
     51     static db b[4][4];
     52     Vec tmp;
     53     for(RG int i=1;i<=3;i++)
     54         for(RG int j=1;j<=3;j++)
     55             b[i][j]=s[j][i];
     56     for(RG int i=1;i<=3;i++)
     57     {
     58         register db t=0.0;
     59         int k=1;
     60         for(db *x=b[i]+1,*y=a+1;k<=3;++x,++y,++k)
     61             t+=*x**y;
     62         tmp[i]=t;
     63     }
     64     for(RG int i=1;i<=3;i++) c[i]=tmp[i];
     65 } 
     66 inline void get(Mat &a,op b,int t)
     67 {
     68     memset(a,0,sizeof(a));
     69     a[1][1]=a[2][2]=a[3][3]=1;
     70     switch(b.id)
     71     {
     72         case 'R': {a[3][1]=b.v1*(db)t;break;}
     73         case 'L': {a[3][1]=-b.v1*(db)t;break;}
     74         case 'U': {a[3][2]=b.v1*(db)t;break;}
     75         case 'D': {a[3][2]=-b.v1*(db)t;break;}
     76         case 'X': {a[2][2]=((t&1)?-1:1);break;}
     77         case 'Y': {a[1][1]=((t&1)?-1:1);break;}
     78         case 'C':
     79         {
     80             int tmp=(int)floor(b.v1*(db)t);
     81             tmp%=360;
     82             db Rad=1.0*(db)tmp*Pi/180.0;
     83             a[1][1]=cos(Rad),a[1][2]=sin(Rad),a[2][1]=-sin(Rad),a[2][2]=cos(Rad);
     84             break;
     85         }
     86         case 'O': {if(t&1) a[1][1]=-1,a[2][2]=-1,a[3][1]=2*b.v1,a[3][2]=2*b.v2,a[3][3]=1;break;}
     87     }
     88 }
     89 void Read(op &x)
     90 {
     91     char cmd=R_alp();
     92     x.id=cmd;
     93     if(cmd=='U'||cmd=='D'||cmd=='L'||cmd=='R'||cmd=='C') x.v1=(db)R_int();
     94     else if(cmd=='O') x.v1=(db)R_int(),x.v2=(db)R_int();
     95 }
     96 inline void update(int p)
     97 {
     98     Mulmat(lval[ls[p]],lval[rs[p]],lval[p]);
     99     Mulmat(rval[rs[p]],rval[ls[p]],rval[p]);
    100 }
    101 inline void putdown(int p,int l,int r)
    102 {
    103     int mid=(l+r)>>1;
    104     get(lval[ls[p]],lazy[p],mid-l+1);
    105     get(rval[ls[p]],lazy[p],mid-l+1);
    106     get(lval[rs[p]],lazy[p],r-mid);
    107     get(rval[rs[p]],lazy[p],r-mid);
    108     lazy[ls[p]]=lazy[rs[p]]=lazy[p];
    109     pd[ls[p]]=1,pd[rs[p]]=1;
    110     pd[p]=0;
    111 }
    112 void build(int p,int l,int r)
    113 {
    114     if(l==r)
    115     {
    116         get(lval[p],a[l],1);
    117         get(rval[p],a[l],1);
    118         return;
    119     }
    120     int mid=(l+r)>>1;
    121     ls[p]=++tot,build(ls[p],l,mid);
    122     rs[p]=++tot,build(rs[p],mid+1,r);
    123     update(p);
    124 }
    125 void modify(int p,int l,int r,int x,op s)
    126 {
    127     if(l==r) {get(lval[p],s,1),get(rval[p],s,1);return;}
    128     if(pd[p]) putdown(p,l,r);
    129     int mid=(l+r)>>1;
    130     if(x<=mid) modify(ls[p],l,mid,x,s);
    131     else modify(rs[p],mid+1,r,x,s);
    132     update(p);
    133 }
    134 void mod_range(int p,int l,int r,int x,int y,op s)
    135 {
    136     if(x<=l&&r<=y)
    137     {
    138         get(lval[p],s,r-l+1),get(rval[p],s,r-l+1);
    139         lazy[p]=s,pd[p]=1;
    140         return;
    141     }
    142     if(pd[p]) putdown(p,l,r);
    143     int mid=(l+r)>>1;
    144     if(x<=mid&&y>=l) mod_range(ls[p],l,mid,x,y,s);
    145     if(y>mid&&x<=r) mod_range(rs[p],mid+1,r,x,y,s);
    146     update(p);
    147 }
    148 Mat ret;
    149 void query(int p,int l,int r,int x,int y,int f)
    150 {
    151     if(x<=l&&r<=y) {Mulmat(ret,f?lval[p]:rval[p],ret);return;}
    152     if(pd[p]) putdown(p,l,r);
    153     int mid=(l+r)>>1;
    154     if(f)
    155     {
    156         if(x<=mid&&y>=l) query(ls[p],l,mid,x,y,f);
    157         if(y>mid&&x<=r) query(rs[p],mid+1,r,x,y,f);        
    158     }
    159     else
    160     {
    161         if(y>mid&&x<=r) query(rs[p],mid+1,r,x,y,f);    
    162         if(x<=mid&&y>=l) query(ls[p],l,mid,x,y,f);
    163     }
    164 }
    165 void ask(db x,db y,int l,int r,int f)
    166 {
    167     memset(ret,0,sizeof(ret));
    168     ret[1][1]=ret[2][2]=ret[3][3]=1;
    169     Vec tmp={0,x,y,1};
    170     query(1,1,n,l,r,f);
    171     Mulvec(tmp,ret,tmp);
    172     printf("%.1lf %.1lf\n",tmp[1],tmp[2]);
    173 }
    174 int main()
    175 {
    176     n=R_int(),m=R_int();
    177     for(int i=1;i<=n;i++)
    178         Read(a[i]);
    179     build(1,1,n);
    180     for(int i=1;i<=m;i++)
    181     {
    182         op t;
    183         char cmd=R_alp();
    184         if(cmd=='M')
    185         {
    186             int p=R_int();
    187             Read(t);
    188             modify(1,1,n,p,t);
    189         }
    190         else if(cmd=='E')
    191         {
    192             int l=R_int(),r=R_int();
    193             Read(t);
    194             mod_range(1,1,n,l,r,t);
    195         }
    196         else if(cmd=='A'||cmd=='B')
    197         {
    198             db x=(db)R_int(),y=(db)R_int();
    199             int l=R_int(),r=R_int();
    200             cmd=='A'?ask(x,y,l,r,1):ask(x,y,l,r,0);
    201         }
    202     }
    203     return 0;
    204 }
    View Code

     

  • 未ac code(不完整,函数解法)……
  •   1 #include<cstdio>
      2 #include<cmath>
      3 #include<algorithm>
      4 #include<ctype.h>
      5 #define l(x) x<<1
      6 #define r(x) x<<1|1
      7 #define ll long long
      8 #define ld double
      9 using namespace std;
     10 
     11 char buf[1<<20],*p1,*p2;
     12 inline char gc() {
     13     return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin))==p1?0:*p1++;
     14 }
     15 
     16 ll n,m;
     17 ll M=1;
     18 ld x,y;
     19 const ld pi=acos(-1);
     20 struct node {
     21     ld A,B,C;
     22     node() {
     23         A=1;
     24         B=0;
     25         C=0;
     26     }
     27 };
     28 
     29 struct point {
     30     node x,y;
     31 } ca[300005<<2],cb[300005<<2];
     32 
     33 template<typename T>
     34 void read(T &x) {
     35     char tt;
     36     bool flag=0;
     37     while(!isdigit(tt=gc())&&tt!='-');
     38     tt=='-'?(x=0,flag=1):(x=tt-'0');
     39     while(isdigit(tt=gc())) x=x*10+tt-'0';
     40     if(flag) x=-x;
     41 }
     42 
     43 void up(point &a,ld t) {
     44     a.y.C+=t;
     45 }
     46 
     47 void down(point &a,ld t) {
     48     a.y.C-=t;
     49 }
     50 
     51 void left(point &a,ld t) {
     52     a.x.C+=t;
     53 }
     54 
     55 void right(point &a,ld t) {
     56     a.x.C-=t;
     57 }
     58 
     59 void dcx(point &a) {
     60     a.x.A=-a.x.A;
     61     a.x.B=-a.x.B;
     62     a.x.C=-a.x.C;
     63 }
     64 
     65 void dcy(point &a) {
     66     a.y.A=-a.y.A;
     67     a.y.B=-a.y.B;
     68     a.y.C=-a.y.C;
     69 }
     70 
     71 void dcxy(point &a,ld d,ld k) {
     72     a.x.A=-a.x.A;
     73     a.x.B=-a.x.B;
     74     a.x.C=2*d-a.x.C;
     75     a.y.A=-a.y.A;
     76     a.y.B=-a.y.B;
     77     a.y.C=2*k-a.x.C;
     78 }
     79 
     80 void turn(point &a,ld c) {
     81     c*=(pi/180);
     82     ld A=a.x.A,B=a.x.B,C=a.x.C,E=a.y.A,F=a.y.B,G=a.y.C;
     83     a.x.A=(A*cos(c)-E*sin(c));
     84     a.x.B=(B*cos(c)-F*sin(c));
     85     a.x.C=(C*cos(c)-G*sin(c));
     86     a.y.A=(A*sin(c)+E*cos(c));
     87     a.y.B=(B*sin(c)+F*cos(c));
     88     a.y.C=(C*sin(c)+G*cos(c));
     89 }
     90 
     91 point merge(point a,point b) {
     92     point tmp;
     93     ld A=b.x.A,B=b.x.B,C=b.x.C,D=b.y.A,E=b.y.A,F=b.y.A;
     94     ld aa=a.x.A,bb=a.x.A,c=a.x.A,d=a.y.A,e=a.y.A,f=a.y.A;
     95     tmp.x.A=(A*aa+B*d);
     96     tmp.x.B=(A*bb+B*e);
     97     tmp.x.C=(C+A*c+B*f);
     98 
     99     tmp.y.A=(D*aa+E*d);
    100     tmp.y.B=(D*bb+E*e);
    101     tmp.y.C=(F+D*c+E*f);
    102     return tmp;
    103 }
    104 
    105 void build() {
    106     for(int i=M-1; i>=1; i--) {
    107         ca[i]=merge(ca[l(i)],ca[r(i)]);
    108         cb[i]=merge(cb[l(i)],cb[r(i)]);
    109     }
    110 }
    111 
    112 int main() {
    113     scanf("%lld%lld",&n,&m);
    114     while(M<=n)M<<=1;
    115     for(int i=1; i<=n; i++) {
    116         char ch;
    117         ld xd,yd;
    118         scanf("\n%c",&ch);
    119         if(ch=='U') scanf("%lf",&xd),up(ca[M+i],xd),up(cb[M+n-i+1],xd);
    120         else if(ch=='D') scanf("%lf",&xd),down(ca[M+i],xd),down(cb[M+n-i+1],xd);
    121         else if(ch=='L') scanf("%lf",&xd),left(ca[M+i],xd),left(cb[M+n-i+1],xd);
    122         else if(ch=='R') scanf("%lf",&xd),right(ca[M+i],xd),right(cb[M+n-i+1],xd);
    123         else if(ch=='O') scanf("%lf%lf",&xd,&yd),dcxy(ca[M+i],xd,yd),dcxy(cb[M+n-i+1],xd,yd);
    124         else if(ch=='C') scanf("%lf",&xd),turn(ca[M+i],xd),turn(cb[M+n-i+1],xd);
    125         else if(ch=='X') dcx(ca[M+i]),dcx(cb[M+n-i+1]);
    126         else if(ch=='Y') dcy(ca[M+i]),dcy(cb[M+n-i+1]);
    127     }
    128     build();
    129     while(m--) {
    130         char cc;
    131         scanf("\n%c",&cc);
    132         if(cc=='M') {
    133             int p,xd,yd;
    134             char ch;
    135             scanf("%d",&p);
    136             
    137         } else if(cc=='E');
    138         else if(cc=='A');
    139         else if(cc=='B');
    140     }
    141 } 
    View Code

     

posted @ 2018-08-26 22:24  Katoumegumi  阅读(69)  评论(0编辑  收藏  举报
返回顶部