• NOIp2018集训test-9-1(pm)


    欢乐%你赛,大家都AK了。

    1. 小澳的方阵

    吸取了前几天的教训,我一往复杂的什么二维树状数组上想就立刻打住阻止自己,就可以发现它是超级大水题了。记录每一行每一列最后一次的修改,对每个格子看它所在行和列哪一个修改更靠后即可。

     1 //Achen
     2 #include<algorithm>
     3 #include<iostream>
     4 #include<cstring>
     5 #include<cstdlib>
     6 #include<vector>
     7 #include<cstdio>
     8 #include<queue>
     9 #include<cmath>
    10 #include<set>
    11 #include<map>
    12 #define Formylove return 0
    13 #define For(i,a,b) for(int i=(a);i<=(b);i++)
    14 #define Rep(i,a,b) for(int i=(a);i>=(b);i--)
    15 const int N=1007;
    16 typedef long long LL;
    17 typedef double db;
    18 using namespace std;
    19 int n,m,q,h[N][2],l[N][2];
    20 
    21 template<typename T>void read(T &x)  {
    22     char ch=getchar(); x=0; T f=1;
    23     while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    24     if(ch=='-') f=-1,ch=getchar();
    25     for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f;
    26 }
    27 
    28 #define ANS
    29 int main() {
    30 #ifdef ANS
    31     freopen("matrix.in","r",stdin);
    32     freopen("matrix.out","w",stdout);
    33 #endif
    34     read(n); read(m); read(q);
    35     For(i,1,q) {
    36         int x,y,z;
    37         read(x); read(y); read(z);
    38         if(x==1) h[y][0]=z,h[y][1]=i;
    39         else l[y][0]=z,l[y][1]=i;
    40     }
    41     For(i,1,n) {
    42         For(j,1,m) {
    43             if(h[i][1]<l[j][1]) printf("%d ",l[j][0]);
    44             else printf("%d ",h[i][0]);
    45         } puts("");
    46     }
    47     Formylove;
    48 }
    View Code

    2. 小澳的坐标系

    可以暴搜或者打个n^2dp(根据竖着走上多少行,每一行走多少步,往左还是往右dp)找规律。我不会找规律,就继续yy怎么更优秀地dp。

    f[i][0]表示走i步的方案,f[i][1]表示走i步且最后一步往上走的方案。

    若最后一步往左走,下一步可以往左,往上 2种走法

    若最后一步往右走,下一步可以往右,往上 2种走法

    若最后一步往上走,下一步可以往左,往右,往上 3种走法

    所以 f[i][0]=f[i-1][0]*2+f[i-1][1]

    显然 f[i][1]=f[i-1][0]

    这个递推方程一出来,就可以套矩乘板子了。

     1 //Achen
     2 #include<algorithm>
     3 #include<iostream>
     4 #include<cstring>
     5 #include<cstdlib>
     6 #include<vector>
     7 #include<cstdio>
     8 #include<queue>
     9 #include<cmath>
    10 #include<set>
    11 #include<map>
    12 #define Formylove return 0
    13 #define For(i,a,b) for(int i=(a);i<=(b);i++)
    14 #define Rep(i,a,b) for(int i=(a);i>=(b);i--)
    15 const int N=1007,p=1e9+7;
    16 typedef long long LL;
    17 typedef double db;
    18 using namespace std;
    19 int n;
    20 
    21 template<typename T>void read(T &x)  {
    22     char ch=getchar(); x=0; T f=1;
    23     while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    24     if(ch=='-') f=-1,ch=getchar();
    25     for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f;
    26 }
    27 
    28 struct jz {
    29     LL a[2][2];
    30     friend jz operator *(const jz&A,const jz&B) {
    31         jz rs;
    32         For(i,0,1) For(j,0,1) {
    33             rs.a[i][j]=0;
    34             For(k,0,1) 
    35                 (rs.a[i][j]+=A.a[i][k]*B.a[k][j]%p)%=p;
    36         }
    37         return rs;
    38     }
    39 }bs,rs;
    40 
    41 void ksm(int b) {
    42     while(b) {
    43         if(b&1) rs=rs*bs;
    44         bs=bs*bs;
    45         b>>=1; 
    46     }
    47 }
    48 
    49 #define ANS
    50 int main() {
    51 #ifdef ANS
    52     freopen("coordinate.in","r",stdin);
    53     freopen("coordinate.out","w",stdout);
    54 #endif
    55     read(n);
    56     rs.a[0][1]=rs.a[1][0]=0;
    57     rs.a[0][0]=rs.a[1][1]=1;
    58     bs.a[0][0]=2; bs.a[0][1]=1;
    59     bs.a[1][0]=1; bs.a[1][1]=0;
    60     ksm(n-1);
    61     LL ans=(3LL*rs.a[0][0]%p+1LL*rs.a[1][0])%p;
    62     printf("%lld
    ",ans);
    63     Formylove;
    64 }
    View Code

    3.小澳的葫芦

    dp[x][y]表示从1到x经过y个点的最短路。

    DAG上dp,拓扑排序即可。

     1 //Achen
     2 #include<algorithm>
     3 #include<iostream>
     4 #include<cstring>
     5 #include<cstdlib>
     6 #include<vector>
     7 #include<cstdio>
     8 #include<queue>
     9 #include<cmath>
    10 #include<set>
    11 #include<map>
    12 #define Formylove return 0
    13 #define For(i,a,b) for(int i=(a);i<=(b);i++)
    14 #define Rep(i,a,b) for(int i=(a);i>=(b);i--)
    15 const int N=207,M=2007;
    16 typedef long long LL;
    17 typedef double db;
    18 using namespace std;
    19 int n,m,f[N][N];
    20 
    21 template<typename T>void read(T &x)  {
    22     char ch=getchar(); x=0; T f=1;
    23     while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    24     if(ch=='-') f=-1,ch=getchar();
    25     for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f;
    26 }
    27 
    28 int ecnt,fir[N],nxt[M],to[M],val[M],in[N];
    29 void add(int u,int v,int w) {
    30     nxt[++ecnt]=fir[u]; fir[u]=ecnt; to[ecnt]=v; val[ecnt]=w; in[v]++;
    31 }
    32 
    33 queue<int>que;
    34 void tpsort() {
    35     memset(f,127/3,sizeof(f));
    36     int inf=f[0][0];
    37     f[1][1]=0;
    38     For(i,1,n) if(!in[i]) que.push(i);
    39     while(!que.empty()) {
    40         int x=que.front();
    41         que.pop();
    42         for(int i=fir[x];i;i=nxt[i]) {
    43             in[to[i]]--;
    44             if(!in[to[i]]) que.push(to[i]);
    45             For(j,1,n) if(f[x][j]!=inf) {
    46                 if(f[x][j]+val[i]<f[to[i]][j+1]) 
    47                     f[to[i]][j+1]=f[x][j]+val[i];
    48             }
    49         }
    50     }
    51 }
    52 
    53 #define ANS
    54 int main() {
    55 #ifdef ANS
    56     freopen("calabash.in","r",stdin);
    57     freopen("calabash.out","w",stdout);
    58 #endif
    59     read(n); read(m);
    60     For(i,1,m) {
    61         int u,v,w;
    62         read(u); read(v); read(w);
    63         add(u,v,w);
    64     }
    65     tpsort();
    66     db ans=1e18;
    67     For(i,1,n) ans=min(ans,(db)f[n][i]/(1.0*i));
    68     printf("%lf
    ",ans);
    69     Formylove;
    70 }
    View Code
  • 相关阅读:
    asp.net中Session过期设置方法
    SQL server的一道入门面试题背后的思考
    SQL Server 2008中SQL应用之-“阻塞(Blocking)”
    win2003+vs2010下安装asp.net MVC3正式版失败经历
    WinForm下ComboBox设定SelectedValue总结
    SQL Server 2008中的代码安全(四):主密钥
    【译】SQL Server误区30日谈Day12TempDB的文件数和需要和CPU数目保持一致
    西雅图SQL PASS之旅
    【译】SQL Server误区30日谈Day10数据库镜像在故障发生后,马上就能发现
    Ado.net的连接池
  • 原文地址:https://www.cnblogs.com/Achenchen/p/9572668.html
Copyright © 2020-2023  润新知