Poetize12
A.seal 模拟+贪心
B.energy 树形dp
C.journey 瞎搞。。。优化暴力即可。
A
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define ll long long
#define N 100010
#define inf 0x3f3f3f3f
inline int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
return x*f;
}
int n,aa[N],ansid=0;
ll sum[N],ans=0;
struct Data{
int l,r;
}a[N];
inline bool cmp(Data x,Data y){return x.r<y.r;}
int main(){
// freopen("seal.in","r",stdin);
n=read();for(int i=1;i<=n;++i) a[i].l=read(),a[i].r=read(),aa[i]=a[i].l;
sort(a+1,a+n+1,cmp);sort(aa+1,aa+n+1);int p=1;
for(int i=1;i<=n;++i) sum[i]=sum[i-1]+aa[i];
for(int i=1;i<=n;++i){
if(a[i].r==a[i-1].r) continue;
while(p<=n&&aa[p]<=a[i].r) ++p;
ll res=sum[n]-sum[p-1]+(ll)a[i].r*(p-1-i+1);
if(res>ans) ans=res,ansid=a[i].r;
}printf("%d %lld\n",ansid,ans);
return 0;
}
B
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
#define ll long long
#define N 1010
#define inf 0x3f3f3f3f
inline int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
return x*f;
}
int n,fa[N],a[N],w[N],dp[N][110],ans=0;//dp[i][j],i的子树中,有j能量时,最多选多少个
vector<int>son[N];
void dfs(int x){
int tmp[110];memset(tmp,0,sizeof(tmp));
for(int i=0;i<son[x].size();++i){
int y=son[x][i];dfs(y);
for(int j=w[x];j>=0;--j)
for(int k=0;k<=j;++k)
tmp[j]=max(tmp[j],dp[y][k]+tmp[j-k]);
}for(int j=w[x];j>=a[x];--j) tmp[j]=max(tmp[j],tmp[j-a[x]]+1);
memcpy(dp[x],tmp,sizeof(tmp));
}
int main(){
// freopen("energy.in","r",stdin);
n=read();
for(int i=1;i<=n;++i) fa[i]=read(),a[i]=read(),w[i]=read(),son[fa[i]].push_back(i);
for(int i=0;i<son[0].size();++i) dfs(son[0][i]),ans+=dp[son[0][i]][w[son[0][i]]];
printf("%d\n",ans);
return 0;
}
C
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define ll long long
#define N 100010
#define inf 0x3f3f3f3f
inline int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
return x*f;
}
int n,m,ans=0,num=0,tot=0,len[110],f[N<<1][110];//f[i][j]-i及i以后,最早的出现j串的位置
char a[N<<1],b[110],t[110];
void solve(){
int last=inf;
for(int i=n+n-1-num+1;i>=1;--i){
bool flag=1;
for(int j=1;j<=num;++j)
if(t[j]!=a[i+j-1]){flag=0;break;}
if(flag) last=i;f[i][tot]=last;
}
}
bool jud(int st){
int p=st,ed=st-1+n;
if(b[1]!='*'){//特殊处理开头结尾
if(f[st][1]!=st) return 0;else p=st+len[1];
}else p=f[st][1]+len[1];if(p>=inf) return 0;
for(int i=2;i<tot;++i){
p=f[p][i]+len[i];if(p-1>ed) return 0;
}
if(b[m]!='*'){
if(f[ed-len[tot]+1][tot]!=ed-len[tot]+1) return 0;
if(p<=ed-len[tot]+1) return 1;return 0;
}if(f[p][tot]+len[tot]-1<=ed) return 1;return 0;
}
int main(){
// freopen("journey1.in","r",stdin);
scanf("%s%s",b+1,a+1);n=strlen(a+1);m=strlen(b+1);
for(int i=1;i<n;++i) a[i+n]=a[i];
for(int i=1,last=1;i<=m;i=last){
while(i<=m&&b[i]=='*') i++;last=i;num=0;
while(last<=m&&b[last]!='*') t[++num]=b[last],++last;
if(i==last) break;len[++tot]=num;solve();
}
for(int i=1;i<=n;++i) if(jud(i)) ans++;
printf("%d\n",ans);
return 0;
}