I did ABCE this time~
A - Rainy Season
Too lazy to discuss directly
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#include<string>
#include<iostream>
using namespace std;
int main()
{
string s;
cin>>s;
int res=0;
if(s[0]=='R'&&s[1]=='R'&&s[2]=='R') cout<<3<<endl;
else if(s[0]=='R'&&s[1]=='R'||s[1]=='R'&&s[2]=='R') cout<<2<<endl;
else if(s[0]=='S'&&s[1]=='S'&&s[2]=='S') cout<<0<<endl;
else cout<<1<<endl;
return 0;
}
B - Making Triangle
Direct violence
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=110;
ll a[N];
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
sort(a+1,a+1+n);
int res=0;
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
for(int k=j+1;k<=n;k++)
{
if(a[i]==a[j]||a[i]==a[k]||a[j]==a[k]) continue;
if(a[i]+a[j]>a[k]) res++;
}
cout<<res<<endl;
return 0;
}
C - Walking Takahashi
For math problems, go to the nearest one first. Just look at the few steps left and sort them.
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll x,k,d;
int main()
{
cin>>x>>k>>d;
ll cnt=abs(x)/d;
if(k<=cnt) cout<<abs(x)-d*k<<endl;
else
{
ll now=abs(x)-d*cnt;
if((k-cnt)&1) cout<<abs(now-d)<<endl;
else cout<<now<<endl;
}
return 0;
}
D - Moving Piece
No adjustment has been transferred out of the examination room wtcl
pretreatment dist[i][j]
array represents from i
start walking j
step etc., how can. circle[i]
Indicates i
how many steps will be taken from the beginning. The brute force enumeration starts at each point as the starting point, and then the brute force enumeration starts at that point and finally stops at that point. The maximum score is calculated. Time complexity O (n 2) O(n^2)O ( n2)
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=5010;
ll dist[N][N],circle[N],mark[N];
bool st[N];
int pos[N],n;
ll k;
int main()
{
cin>>n>>k;
for(int i=1;i<=n;i++) cin>>pos[i];
for(int i=1;i<=n;i++) cin>>mark[i];
for(int i=1;i<=n;i++)
{
memset(st,0,sizeof st);
int j=pos[i],idx=0;
while(!st[j])
{
st[j]=1;
idx++;
dist[i][idx]=dist[i][idx-1]+mark[j];
j=pos[j];
}
circle[i]=idx;
}
ll res=-1e18;
for(int i=1;i<=n;i++)
for(int j=1;j<=circle[i];j++)
{
ll x=dist[i][j];
if(k<j) break;
if(dist[i][circle[i]]>=0) x+=(k-j)/circle[i]*dist[i][circle[i]];
res=max(res,x);
}
cout<<res<<endl;
return 0;
}
E - Picking Goods
Dynamic programming f [i] [j] [k] f[i][j][k]f [ i ] [ j ] [ k ] Check the number of squares.
State: ①Set: go toiijj inrow ij column, andiiline i has selectedkkSet of k ②Properties: maximum value
State calculation:
go right
Do not chooseiijj inrow ij列: f [ i ] [ j ] [ k ] = f [ i ] [ j − 1 ] [ k ] f[i][j][k]=f[i][j-1][k] f[i][j][k]=f[i][j−1 ] [ k ]
Selectiijj inrow ij列 f [ i ] [ j ] [ k ] = f [ i ] [ j − 1 ] [ k − 1 ] + g [ i ] [ j ] f[i][j][k]=f[i][j-1][k-1]+g[i][j] f[i][j][k]=f[i][j−1][k−1]+g [ i ] [ j ]
Go down
Do not chooseiijj inrow ij列 f [ i ] [ j ] [ 0 ] = f [ i − 1 ] [ j ] [ 0 … k ] f[i][j][0]=f[i-1][j][0\dots k] f[i][j][0]=f[i−1][j][0…k ]
selectiijj inrow ij列 f [ i ] [ j ] [ 1 ] = f [ i − 1 ] [ j ] [ 0 … k ] + g [ i ] [ j ] f[i][j][1]=f[i-1][j][0\dots k]+g[i][j] f[i][j][1]=f[i−1][j][0…k]+g[i][j]
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=3010;
ll g[N][N];
int n,m,k;
ll f[N][N][4];
int main()
{
cin>>n>>m>>k;
while(k--)
{
int x,y;
ll w;
cin>>x>>y>>w;
g[x][y]=w;
}
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
//不选择这一个格子
ll w=max(max(f[i-1][j][0],f[i-1][j][1]),max(f[i-1][j][2],f[i-1][j][3]));
for(int k=0;k<=3;k++) f[i][j][k]=max(f[i][j][k],f[i][j-1][k]);
f[i][j][0]=max(f[i][j][0],w);
if(g[i][j])//说明这个格子有数才能选择
{
//选择这一个格子
for(int k=1;k<=3;k++) f[i][j][k]=f[i][j-1][k-1]+g[i][j];
f[i][j][1]=max(f[i][j][1],w+g[i][j]);
}
}
cout<<max(max(f[n][m][0],f[n][m][1]),max(f[n][m][2],f[n][m][3]))<<endl;
return 0;
}
Come on~