• NOIp2018集训test-10-16 (bike day2)


    “毕姥爷:今天的题好简单啊,你们怎么考得这么烂啊,如果是noip你们就凉透了啊“

    今天的题难度应该是3、2、1递减的,但是我不知道哪根筋没搭对,平时我最多1h多就弃题了,今天硬生生写了2h20min的T1,要不是倒数50min的时候把T1样例过了,可能今天就废了。然鹅我T只有10pt……然后10min打了T3的50pt,剩下40min打T2的30pt,75pt,100pt然后开开心心地拍还发现30pt部分写错了。

    B 君的第一题 python

    哪个啥子自动机,似乎就是把kmp跳到的地方预处理出来,然后我没有预处理直接跳并且我dp的状态没对,我的f[l][x]是走l步走到x点的方案数,这样会只能找到长度并没法输出第n小。。我就又开了一维记录第一位的数然后乱搞也是看每一位够不够然后出现了各种问题,搞到了70pt再也搞不下去了。

    正解是f[l][x]表示从x点出发走l步到达终止状态的方案数,x是初始状态,这就很好了。最后找答案的时候一位位确定,确定了前面的位就知道在自动机上走到哪个位置了,问一下个要选到哪个就非常方便了。具体见代码。

     1 //Achen
     2 #include<bits/stdc++.h>
     3 #define For(i,a,b) for(int i=(a);i<=(b);i++)
     4 #define Rep(i,a,b) for(int i=(a);i>=(b);i--)
     5 #define Formylove return 0
     6 const int N=2007;
     7 typedef unsigned long long LL;
     8 typedef double db;
     9 const LL up=1e18;
    10 using namespace std;
    11 char s[N];
    12 int len,nxt[N],ts[N][10];
    13 LL n,f[N][N];
    14 
    15 template<typename T> void read(T &x) {
    16     char ch=getchar(); x=0; T f=1;
    17     while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    18     if(ch=='-') f=-1,ch=getchar();
    19     for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f;
    20 }
    21 
    22 void kmp() {
    23     for(int i=1,k=0;i<len;i++) {
    24         while(k&&s[i]!=s[k]) k=nxt[k-1];
    25         if(s[i]==s[k]) k++;
    26         nxt[i]=k;
    27     }
    28     For(i,0,9) ts[len][i]=len;
    29     For(i,0,len-1) {
    30         For(x,0,9) {
    31             int k=i;
    32             while(s[k]-'0'!=x&&k) k=nxt[k-1];
    33             if(s[k]-'0'==x) k++;
    34             ts[i][x]=k;
    35         }
    36     }
    37 }
    38 
    39 LL mo(LL x) { 
    40     return x>up?up:x; 
    41 }
    42 
    43 int ans[N];
    44 void print(int l) {
    45     int np=0;
    46     Rep(p,l,1) {
    47         For(x,(p==l),9) {
    48             if(f[p-1][ts[np][x]]>=n) {
    49                 np=ts[np][x];
    50                 printf("%d",x); break;
    51             }
    52             else n-=f[p-1][ts[np][x]];
    53         }
    54     }
    55 }
    56 
    57 #define ANS
    58 int main() {
    59 #ifdef ANS
    60     freopen("python.in","r",stdin);
    61     freopen("python.out","w",stdout);
    62 #endif
    63     scanf("%s",s);
    64     len=strlen(s);
    65     kmp();
    66     read(n);
    67     f[0][len]=1;
    68     LL tp=0;
    69     for(int l=0;;l++) {
    70         if(tp>=n) {
    71             print(l); break;
    72         }
    73         if(l) n-=tp;
    74         tp=0;
    75         For(j,0,len) For(x,0,9) {
    76             f[l+1][j]=mo(f[l+1][j]+f[l][ts[j][x]]);
    77             if(x&&j==0) tp=mo(tp+f[l][ts[j][x]]);
    78         }
    79     }
    80     Formylove;
    81 }
    View Code

    B 君的第二题 ruby

    T2似乎被所有人秒了啊,线段树维护两个标记维护bfs序就好了。

      1 //Achen
      2 #include<bits/stdc++.h>
      3 #define For(i,a,b) for(int i=(a);i<=(b);i++)
      4 #define Rep(i,a,b) for(int i=(a);i>=(b);i--)
      5 #define Formylove return 0
      6 const int N=200007,p=1000000007;
      7 typedef long long LL;
      8 typedef double db;
      9 using namespace std;
     10 int n,m,x;
     11 LL k,b;
     12 
     13 template<typename T> void read(T &x) {
     14     char ch=getchar(); x=0; T f=1;
     15     while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
     16     if(ch=='-') f=-1,ch=getchar();
     17     for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f;
     18 }
     19 
     20 LL v[N];
     21 int ecnt,fir[N],nxt[N<<1],to[N<<1];
     22 void add(int u,int v) {
     23     nxt[++ecnt]=fir[u]; fir[u]=ecnt; to[ecnt]=v;
     24     nxt[++ecnt]=fir[v]; fir[v]=ecnt; to[ecnt]=u;
     25 }
     26 
     27 LL mo(LL x) { return x>=p?x-p:x; }
     28 
     29 #define lc (x<<1)
     30 #define rc ((x<<1)|1)
     31 #define mid ((l+r)>>1)
     32 LL sg[N<<2],lz[N<<2],lz2[N<<2];
     33 void cg(int x,int len,LL k,LL v) {
     34     sg[x]=mo(sg[x]*k%p+v*len%p);
     35     lz[x]=mo(lz[x]*k%p+v);
     36     lz2[x]=lz2[x]*k%p;
     37 }
     38 
     39 void down(int x,int l_len,int r_len) {
     40     if(!lz[x]&&lz2[x]==1) return;
     41     cg(lc,l_len,lz2[x],lz[x]);
     42     cg(rc,r_len,lz2[x],lz[x]);
     43     //sg[lc]=mo(sg[lc]+l_len*lz[x]%p); lz[lc]=mo(lz[lc]+lz[x]);
     44     //sg[rc]=mo(sg[rc]+r_len*lz[x]%p); lz[rc]=mo(lz[rc]+lz[x]);
     45     lz[x]=0;  lz2[x]=1;
     46 }
     47     
     48 void upd(int x,int l,int r,int ql,int qr,LL k,LL v) {
     49     if(l>=ql&&r<=qr) {
     50         cg(x,r-l+1,k,v);
     51         return;
     52     }
     53     down(x,mid-l+1,r-mid);
     54     if(ql<=mid) upd(lc,l,mid,ql,qr,k,v);
     55     if(qr>mid) upd(rc,mid+1,r,ql,qr,k,v);
     56     sg[x]=mo(sg[lc]+sg[rc]);
     57 }
     58 
     59 LL qry(int x,int l,int r,int ql,int qr) {
     60     if(l>=ql&&r<=qr) return sg[x];
     61     down(x,mid-l+1,r-mid);
     62     if(qr<=mid) return qry(lc,l,mid,ql,qr);
     63     if(ql>mid) return qry(rc,mid+1,r,ql,qr);
     64     return mo(qry(lc,l,mid,ql,qr)+qry(rc,mid+1,r,ql,qr));
     65 }
     66 
     67 queue<int>que;
     68 int fa[N],son[N],fson[N],dfn[N],dfk;
     69 void bfs() {
     70     que.push(1);
     71     while(!que.empty()) {
     72         int x=que.front();
     73         dfn[x]=++dfk;
     74         que.pop();
     75         for(int i=fir[x];i;i=nxt[i]) if(to[i]!=fa[x]) {
     76             son[x]++;
     77             if(son[x]==1) fson[x]=to[i];
     78             fa[to[i]]=x;
     79             que.push(to[i]);
     80         }
     81     }
     82 }
     83 
     84 #define ANS
     85 int main() {
     86 #ifdef ANS
     87     freopen("ruby.in","r",stdin);
     88     freopen("ruby.out","w",stdout);
     89 #endif
     90     read(n); read(m);
     91     For(i,2,n) {
     92         int x,y;
     93         read(x); read(y);
     94         add(x,y);
     95     }
     96     bfs();
     97     memset(lz2,1,sizeof(lz2));
     98     For(i,1,m) {
     99         read(x); read(k); read(b);
    100         upd(1,1,n,dfn[x],dfn[x],k,b);
    101         if(fa[x]) upd(1,1,n,dfn[fa[x]],dfn[fa[x]],k,b);
    102         if(son[x]) upd(1,1,n,dfn[fson[x]],dfn[fson[x]]+son[x]-1,k,b);
    103         LL rs=0;
    104         rs=mo(rs+qry(1,1,n,dfn[x],dfn[x]));
    105         if(fa[x]) rs=mo(rs+qry(1,1,n,dfn[fa[x]],dfn[fa[x]]));
    106         if(son[x]) rs=mo(rs+qry(1,1,n,dfn[fson[x]],dfn[fson[x]]+son[x]-1));
    107         printf("%lld
    ",rs);
    108     }
    109     Formylove;
    110 }
    View Code

    B 君的第三题 haskell

    很智障的题,然后机房得分超低,毕姥爷说我们大概是要凉了。

    k=1的时候算每条边两边的点就知道每条边的贡献了。

    如果一条路径长度mod k==x贡献就要加上k-x,最后答案除以k。k很小只有10,那么统计长度mod k=0~9的路径条数就好了。

     1 //Achen
     2 #include<bits/stdc++.h>
     3 #define For(i,a,b) for(int i=(a);i<=(b);i++)
     4 #define Rep(i,a,b) for(int i=(a);i>=(b);i--)
     5 #define Formylove return 0
     6 const int N=100007;
     7 typedef long long LL;
     8 typedef double db;
     9 using namespace std;
    10 int n,k;
    11 LL ans;
    12 
    13 template<typename T> void read(T &x) {
    14     char ch=getchar(); x=0; T f=1;
    15     while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    16     if(ch=='-') f=-1,ch=getchar();
    17     for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f;
    18 }
    19 
    20 int ecnt,fir[N],nxt[N<<1],to[N<<1],val[N<<1];
    21 void add(int u,int v,int w) {
    22     nxt[++ecnt]=fir[u]; fir[u]=ecnt; to[ecnt]=v; val[ecnt]=w;
    23     nxt[++ecnt]=fir[v]; fir[v]=ecnt; to[ecnt]=u; val[ecnt]=w;
    24 }
    25 
    26 int sz[N];
    27 LL f[N][10],c[10];
    28 void dfs(int x,int fa) {
    29     sz[x]=1;
    30     f[x][0]=1;
    31     for(int i=fir[x];i;i=nxt[i]) if(to[i]!=fa) {
    32         int y=to[i];
    33         dfs(y,x);
    34         sz[x]+=sz[y];
    35         ans+=(LL)val[i]*sz[y]*(n-sz[y]);
    36         For(a,0,k-1) For(b,0,k-1) 
    37             c[(a+b+val[i])%k]+=f[x][a]*f[y][b];
    38         For(a,0,k-1) 
    39             f[x][(a+val[i])%k]+=f[y][a];
    40     }
    41 }
    42 
    43 #define ANS
    44 int main() {
    45 #ifdef ANS
    46     freopen("haskell.in","r",stdin);
    47     freopen("haskell.out","w",stdout);
    48 #endif
    49     read(n); read(k);
    50     For(i,2,n) {
    51         int x,y,z;
    52         read(x); read(y); read(z);
    53         add(x,y,z);
    54     }
    55     dfs(1,0);
    56     For(i,1,k-1) 
    57         ans+=c[i]*(k-i);
    58     printf("%lld
    ",ans/k);
    59     Formylove;
    60 }
    View Code
  • 相关阅读:
    css实现水平/垂直居中效果
    Mac 下用homebrew安装配置MongoDB
    阿里云ECS搭建node/mongodb开发环境及部署
    阿里云首次安装和部署nginx
    前端学习借鉴目录
    040.[转] 对于程序框架的理解
    039.[转] 基于 Kubernetes 和 Spring Cloud 的微服务化实践
    038.[转] JVM启动过程与类加载
    037.[转] springboot 配置多个数据源
    036.[转] JNDI 学习
  • 原文地址:https://www.cnblogs.com/Achenchen/p/9800108.html
Copyright © 2020-2023  润新知