• 暑假集训test-8-28


    大概是从我一年以来做过的最傻逼的一套题了。。

    一个半小时打完三个程序三个暴力拍完以为自己AK了,开心地耍了两个小时。

    结果T3要写高精,LL炸了后4个点,中间还有个点是啥都不选的,我没用0去更新又炸了一个点,成功把自己炸成一个二百五。

    1.最小生成树模板题,前天那道题的——弱化+大概期望你去写个prim但是kruskal也可以过你可以两个拍一拍——版

    几百年没写过prim了

     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=507;
    16 typedef long long LL;
    17 typedef double db;
    18 using namespace std;
    19 int n,a[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 vis[N];
    29 LL ans,dis[N];
    30 #define inf 1e18
    31 void prim(int n) {
    32     For(i,1,n) dis[i]=inf;
    33     dis[n]=0;
    34     For(i,1,n) {
    35         int x=0;
    36         For(j,1,n) if(!vis[j]&&(!x||dis[j]<dis[x])) x=j;
    37         if(!x) break;
    38         vis[x]=1;
    39         ans+=dis[x];
    40         dis[x]=0;
    41         For(j,1,n) if(!vis[j]&&dis[j]>dis[x]+a[x][j])
    42             dis[j]=dis[x]+a[x][j];
    43     }
    44 }
    45 
    46 #define ANS
    47 int main() {
    48 #ifdef ANS
    49     freopen("newstart.in","r",stdin);
    50     freopen("newstart.out","w",stdout);
    51 #endif
    52     read(n);
    53     For(i,1,n) {
    54         read(a[i][n+1]);
    55         a[n+1][i]=a[i][n+1];
    56     }
    57     For(i,1,n) For(j,1,n) read(a[i][j]);
    58     prim(n+1);
    59     printf("%lld
    ",ans);
    60     Formylove;
    61 }
    62 /*
    63 4 
    64 5 4 4 3
    65 0 2 2 2
    66 2 0 3 3
    67 2 3 0 4
    68 2 3 4 0
    69 */
    View Code

    2、智障型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 #define inf 1e9+7
    16 const int N=1007;
    17 typedef long long LL;
    18 typedef double db;
    19 using namespace std;
    20 int n,m,a[N][N],b[N][N],f[N][N],sum1[N][N],sum2[N][N];
    21 
    22 template<typename T>void read(T &x)  {
    23     char ch=getchar(); x=0; T f=1;
    24     while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    25     if(ch=='-') f=-1,ch=getchar();
    26     for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f;
    27 }
    28 
    29 #define ANS
    30 int main() {
    31 #ifdef ANS
    32     freopen("industry.in","r",stdin);
    33     freopen("industry.out","w",stdout);
    34 #endif
    35     read(n); read(m);
    36     For(i,1,n) For(j,1,m) read(a[i][j]);
    37     For(i,1,n) For(j,1,m) read(b[i][j]);
    38     For(i,1,n) 
    39         For(j,1,m) sum1[i][j]=sum1[i][j-1]+a[i][j];
    40     For(i,1,n) {
    41         int sum=0;
    42         For(j,1,m) {
    43             sum+=b[i][j];
    44             sum2[i][j]=sum2[i-1][j]+sum;
    45         }
    46     }
    47     For(i,1,n) {
    48         int mx=-inf;
    49         For(j,0,m) {
    50             mx=max(mx,f[i-1][j]-sum2[i-1][j]);
    51             f[i][j]=max(f[i][j],mx+sum1[i][j]+sum2[i-1][j]);
    52         }
    53     }
    54     int ans=0;
    55     For(j,0,m) ans=max(ans,f[n][j]+sum2[n][m]-sum2[n][j]);
    56     printf("%d
    ",ans); 
    57     Formylove;
    58 }
    59 /*
    60 4 4
    61 0 0 10 9
    62 1 3 10 0
    63 4 2 1 3
    64 1 1 20 0
    65 10 0 0 0
    66 1 1 1 30
    67 0 0 5 5
    68 5 10 10 10
    69 */
    View Code

    3、会写高精的话比上面还智障,三方dp就可以得到70。如果再不那么智障一点点,贪心地把直接减血的塔放最后二方dp就可以过了。

    我懒得写高精了,用__int128水过去了。。

     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 typedef long long LL;
    16 typedef double db;
    17 using namespace std;
    18 __int128 f[1050][1050],n,r,g,b,T;
    19 
    20 template<typename T>void read(T &x)  {
    21     char ch=getchar(); x=0; T f=1;
    22     while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    23     if(ch=='-') f=-1,ch=getchar();
    24     for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f;
    25 }
    26 
    27 void print(__int128 x){
    28     if (x==0) return;
    29     if (x) print(x/10);
    30     putchar(x%10+'0');
    31 }
    32 
    33 #define ANS
    34 int main() {
    35 #ifdef ANS
    36     freopen("antbuster.in","r",stdin);
    37     freopen("antbuster.out","w",stdout);
    38 #endif
    39     read(n); read(r); read(g); read(b); read(T);
    40     __int128 ans=0;
    41     memset(f,128,sizeof(f));
    42     f[0][0]=0;
    43     For(i,1,n) 
    44         For(j,0,i) {
    45             int gc=j,tc=i-j;
    46             f[i][j]=max(f[i-1][j-1]+(T+tc*b)*(gc-1)*g,f[i-1][j]+(T+(tc-1)*b)*gc*g);
    47             ans=max(ans,f[i][j]+(n-i)*(T+tc*b)*(r+g*gc));
    48         }
    49     ans=max(ans,f[0][0]+n*T*r);
    50     print(ans);
    51     Formylove;
    52 }
    53 /*
    54 1024 6545 65436 1146 6436
    55 */
    View Code
  • 相关阅读:
    ExtJs学习准备工作(二) firebug firefox插件的安装 全新时代
    Hibernate系统中调试SQL方式 全新时代
    Eclipse工程出现红叉导致无法编译的问题 全新时代
    javascript 取table中内容
    Asp.Net中清空所有textbox的几种方法
    SQL Server:使用系统存储过程实现的通用分页存储过程
    C# 检查网络是否连通
    sq分页原理
    SQL Server:日志备份和差异备份还原中的常见问题示例
    javascript:连接数据库
  • 原文地址:https://www.cnblogs.com/Achenchen/p/9548159.html
Copyright © 2020-2023  润新知