标签:include cstring sizeof stream getc lap view tco math
A:阅读。
#include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; #define ll long long char getc(){char c=getchar();while ((c<‘A‘||c>‘Z‘)&&(c<‘a‘||c>‘z‘)&&(c<‘0‘||c>‘9‘)) c=getchar();return c;} int gcd(int n,int m){return m==0?n:gcd(m,n%m);} int read() { int x=0,f=1;char c=getchar(); while (c<‘0‘||c>‘9‘) {if (c==‘-‘) f=-1;c=getchar();} while (c>=‘0‘&&c<=‘9‘) x=(x<<1)+(x<<3)+(c^48),c=getchar(); return x*f; } int a,b,c; int main() { a=read(),b=read(),c=read(); cout<<b+min(c,a+b+1); return 0; }
B:一个显然的做法是设f[i][j][0/1]为已经砍掉了1~i和j~n的树且停在左/右边的最长路,类似区间dp转移即可。因为开始头铁想了会正解和初始化出了些锅,很久之后才过掉这个部分分。
#include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; #define ll long long #define N 200010 char getc(){char c=getchar();while ((c<‘A‘||c>‘Z‘)&&(c<‘a‘||c>‘z‘)&&(c<‘0‘||c>‘9‘)) c=getchar();return c;} int gcd(int n,int m){return m==0?n:gcd(m,n%m);} int read() { int x=0,f=1;char c=getchar(); while (c<‘0‘||c>‘9‘) {if (c==‘-‘) f=-1;c=getchar();} while (c>=‘0‘&&c<=‘9‘) x=(x<<1)+(x<<3)+(c^48),c=getchar(); return x*f; } int n,m,a[N]; ll ans,f[2010][2010][2]; int main() { m=read(),n=read(); for (int i=1;i<=n;i++) a[i]=read();a[n+1]=m; memset(f,200,sizeof(f)); f[1][n+1][0]=a[1],f[0][n][1]=m-a[n]; for (int i=2;i<=n;i++) for (int j=0;j<=i;j++) { if (j) f[j][n+1-(i-j)][0]=max(f[j-1][n+1-(i-j)][0]+a[j]-a[j-1],f[j-1][n+1-(i-j)][1]+a[j]+m-a[n+1-(i-j)]); if (j<i) f[j][n+1-(i-j)][1]=max(f[j][n+2-(i-j)][1]+a[n+2-(i-j)]-a[n+1-(i-j)],f[j][n+2-(i-j)][0]+a[j]+m-a[n+1-(i-j)]); } for (int i=1;i<=n;i++) ans=max(ans,f[i][i+1][0]),ans=max(ans,f[i][i+1][1]); cout<<ans; return 0; }
然后因为一些原因也没什么心思想题,就这么心态平稳地自闭到结束了。根本没脸写这玩意了题过会再补
result:rank 312 rating +56 怎么打成什么样都涨分啊?
标签:include cstring sizeof stream getc lap view tco math
原文地址:https://www.cnblogs.com/Gloid/p/10198239.html