• 17-06-14模拟赛


    T1:

    Code:

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 #define MN 100005
     5 using namespace std;
     6 inline int in(){
     7     int x=0;bool f=0; char c;
     8     for (;(c=getchar())<'0'||c>'9';f=c=='-');
     9     for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    10     return f?-x:x;
    11 }
    12 struct edge{
    13     int to,next;
    14 }e[MN];
    15 int head[MN],edi[MN],t[MN],x[MN],cnt=0,n,tail=0,cur;
    16 char op[MN];
    17 inline void ins(int x,int y){
    18     e[++cnt].to=y;e[cnt].next=head[x];head[x]=cnt;
    19 }
    20 void dfs(int p){
    21     if (op[p]=='T') t[++tail]=x[p];
    22     if (op[p]=='Q') x[p]=t[x[p]];
    23     for (int i=head[p];i;i=e[i].next) dfs(e[i].to);
    24     if (op[p]=='T') --tail;
    25 }
    26 int main()
    27 {
    28     n=in();cur=0;for (int i=1;i<=n;++i){
    29         do op[i]=getchar();while (op[i]!='T'&&op[i]!='U'&&op[i]!='Q');
    30         if (op[i]=='T') getchar(),x[i]=getchar();else x[i]=in();
    31         if (op[i]=='U') ins(edi[cur-x[i]],i);else ins(i-1,i);
    32         if (op[i]=='T'||op[i]=='U') edi[++cur]=i;
    33     }dfs(0);
    34     for (int i=1;i<=n;++i) if (op[i]=='Q') printf("%c
    ",(char)x[i]);return 0;
    35 }

    T2:动态规划。考虑将1-n从小到大插入数列。

    设f[i][j]表示数列中已插入1-i,恰有j个"<"的方案数,则f[i][j]=f[i-1][j-1]*(i-j)+f[i-1][j]*(j+1).

    Code:

     1 #include<iostream>
     2 #include<cmath>
     3 #include<cstdio>
     4 #include<cstdlib>
     5 #include<cstring>
     6 #include<algorithm>
     7 #define MOD 2012 
     8 using namespace std;
     9 inline int in(){
    10     int x=0;bool f=0; char c;
    11     for (;(c=getchar())<'0'||c>'9';f=c=='-');
    12     for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    13     return f?-x:x;
    14 }int f[1003][1003],n,k;
    15 int main()
    16 {
    17     n=in();k=in();
    18     for (int i=1;i<=n;++i) f[i][0]=f[i][i-1]=1;
    19     for (int i=2;i<=n;++i)
    20     for (int j=1;j<=min(k,i-1);++j)
    21     f[i][j]=(f[i-1][j]*(j+1)%MOD+f[i-1][j-1]*(i-j)%MOD)%MOD;
    22     printf("%d",f[n][k]);return 0;
    23 }

    T3:

    考虑从后往前处理,可以发现是否开采或维修只对在其后星球的开采收入产生影响,即其后星球的最优方案与是否在该星球开采或修复无关。所以可以贪心处理本题。

    Code:

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 #define MN 100005
     5 using namespace std;
     6 inline int in(){
     7     int x=0;bool f=0; char c;
     8     for (;(c=getchar())<'0'||c>'9';f=c=='-');
     9     for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    10     return f?-x:x;
    11 }
    12 int n,w,x[MN];
    13 double k,c,ans;
    14 bool tp[MN];
    15 int main()
    16 {
    17     n=in();k=1-(in()/100.0);c=1+(in()/100.0);w=in();
    18     for (int i=1;i<=n;++i) tp[i]=in()-1,x[i]=in();ans=0.0;
    19     for (int i=n;i;--i){
    20         if (!tp[i]) ans=max(ans,ans*k+x[i]);
    21         else ans=max(ans,ans*c-x[i]);
    22     }printf("%.2lf",ans*w);
    23     return 0;
    24 }
  • 相关阅读:
    [BZOJ2179]FFT快速傅立叶
    [UOJ#34]多项式乘法
    [BZOJ4636]蒟蒻的数列
    [BZOJ4632]树的编码
    [BZOJ1070][SCOI2007]修车
    [BZOJ1529][POI2005]ska Piggy banks
    [BZOJ2654]tree
    腾讯应用管理中心,腾讯开放平台应用认领
    Sony/索尼 NW-ZX300A ZX300 无损音乐播放器4.4口
    read progress
  • 原文地址:https://www.cnblogs.com/codingutopia/p/test170614.html
Copyright © 2020-2023  润新知