Loading

CSP 后多校十

A. 石子合并

签到题.

A_code
#include <bits/stdc++.h>
using namespace std;
namespace BSS {
#define int long long
#define lf long double
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define lbt(x) ((x) & (-(x)))
#define Fill(x, y) memset(x, y, sizeof(x))
#define Copy(x, y) memcpy(x, y, sizeof(x))
#define File(x) freopen(#x ".in", "r", stdin), freopen(#x ".out", "w", stdout)
auto read = [](int w = 0, bool cit = 0, char ch = getchar()) -> int {
    for (; !isdigit(ch); ch = getchar()) cit = (ch == '-');
    for (; isdigit(ch); ch = getchar()) w = (w << 3) + (w << 1) + (ch ^ 48);
    return cit ? (-w) : w;
};
}  // namespace BSS
using namespace BSS;

const int N = 2e6 + 21, inf = 1e15;

int m, n, mn, ans;
int val[N];
auto Work = []() -> void {
    n = read(), ans = 0, mn = inf;
    int fz = 0, ff = 0;
    for (int i = 1; i <= n; i++) {
        val[i] = read();
        fz |= (val[i] >= 0), ff |= (val[i] <= 0);
    }
    if(n==1) {printf("%lld\n",val[1]); return ;}
    if (fz and ff) {
        for (int i = 1; i <= n; i++) ans += abs(val[i]);
    } else {
        for (int i = 1; i <= n; i++) ans += abs(val[i]), mn = min(mn, abs(val[i]));
        ans -= (mn << 1);
    }
    printf("%lld\n", ans);
};
signed main() {
    File(stone);
    for (int Ts = read(); Ts; Ts--) Work();
    exit(0);
}

B. 基站建设

签到题.

B_code
#include<bits/stdc++.h>
using namespace std;
namespace BSS{
	#define int long long
	#define lf long double
	#define pb push_back
	#define mp make_pair
	#define lb lower_bound
	#define ub upper_bound
	#define lbt(x) ((x)&(-(x)))
	#define Fill(x,y) memset(x,y,sizeof(x))
	#define Copy(x,y) memcpy(x,y,sizeof(x))
	#define File(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
	auto read=[](int w=0,bool cit=0,char ch=getchar())->int{
		for(;!isdigit(ch);ch=getchar()) cit=(ch=='-');
		for(;isdigit(ch);ch=getchar()) w=(w<<3)+(w<<1)+(ch^48);
		return cit?(-w):w;
	};
} using namespace BSS;

const int N=3e5+21;

#define y1 asasasasas
#define y2 sasasasasa

int P,Q;
int m,n,ans;
int x1[N],x2[N],y1[N],y2[N];
int pmax[2][N],pmin[2][N],smax[2][N],smin[2][N];
bitset<100> dd;
auto Work=[]()->void{
	Fill(pmax,0),Fill(smax,0);
	ans=0,P=read(),Q=read(),n=read();
	for(int i=1;i<=n;i++) x1[i]=read(),y1[i]=read(),x2[i]=read(),y2[i]=read();
	smin[0][n+1]=P,smin[1][n+1]=Q,pmin[0][0]=P,pmin[1][0]=Q;
	for(int i=1;i<=n;i++){
		pmax[0][i]=max(pmax[0][i-1],x1[i]),pmax[1][i]=max(pmax[1][i-1],y1[i]);
		pmin[0][i]=min(pmin[0][i-1],x2[i]),pmin[1][i]=min(pmin[1][i-1],y2[i]);
	}
	for(int i=n;i;i--){
		smax[0][i]=max(smax[0][i+1],x1[i]),smax[1][i]=max(smax[1][i+1],y1[i]);
		smin[0][i]=min(smin[0][i+1],x2[i]),smin[1][i]=min(smin[1][i+1],y2[i]);
	}
	int xl,xr,yl,yr,del;
	xl=pmax[0][n],xr=pmin[0][n],yl=pmax[1][n],yr=pmin[1][n];
	del=( (yr>yl and xr>xl) ? (yr-yl)*(xr-xl) : 0 );
	for(int i=1;i<=n;i++){
		xl=max(pmax[0][i-1],smax[0][i+1]),xr=min(pmin[0][i-1],smin[0][i+1]);
		yl=max(pmax[1][i-1],smax[1][i+1]),yr=min(pmin[1][i-1],smin[1][i+1]);
		// cout<<pmax[1][i-1]<<' '<<smax[1][i+1]<<endl;
		// cout<<xl<<' '<<yl<<' '<<xr<<' '<<yr<<endl;
		if(yr>yl and xr>xl) ans+=(yr-yl)*(xr-xl)-del;
	}
	printf("%lld\n",ans+del);
};
signed main(){
	File(carpet);	
	Fill(smin,0x3f),Fill(pmin,0x3f);
	for(int Ts=read();Ts;Ts--) Work();
	exit(0);
}

C. 优美的旋律

签到题.

C_code
#include<bits/stdc++.h>
using namespace std;
namespace BSS{
	// #define int long long
	#define lf long double
	#define pb push_back
	#define mp make_pair
	#define lb lower_bound
	#define ub upper_bound
	#define lbt(x) ((x)&(-(x)))
	#define Fill(x,y) memset(x,y,sizeof(x))
	#define Copy(x,y) memcpy(x,y,sizeof(x))
	#define File(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
	auto read=[](int w=0,bool cit=0,char ch=getchar())->int{
		for(;!isdigit(ch);ch=getchar()) cit=(ch=='-');
		for(;isdigit(ch);ch=getchar()) w=(w<<3)+(w<<1)+(ch^48);
		return cit?(-w):w;
	};
} using namespace BSS;

const int N=3e3+21;

char ch[N];

int A,B;
int m,n,ans;
int maxb[N],val[N];
int fail[N][N];
auto gcd=[](int x,int y)->int{
	if(!(x and y)) return x|y;
	int z; while(z=y) y=x%y,x=z;
	return x;
};
signed main(){
	File(melody);
	A=read(),B=read(),scanf("%s",ch+1),n=strlen(ch+1); int x,y,z;
	for(int i=1;i<=n;i++) val[i]=ch[i]-'a'+1;
	for(int st=1;st<=n;st++){
		for(int i=0;i<=n;i++) fail[st][i]=st-1;
		for(int i=st+1,j=st-1;i<=n;i++){
			while(j>st-1 and val[i]^val[j+1]) j=fail[st][j];
			j+=(val[i]==val[j+1]),fail[st][i]=j;
		}
	}
	// for(int i=1;i<=n;i++){
	// 	for(int j=i;j<=n;j++) cout<<fail[i][j]<<' ';
	// 	puts("");
	// }
	for(int i=1;i<=n;i++){
		for(int l=1,r=i;r<=n;l++,r++){
			if(fail[l][r]<l) continue;
			y=r-fail[l][r];
			if(gcd(i,y)^y) continue;
			maxb[y]=max(maxb[y],i);
		}
	}
	for(int i=1;i<=n;i++){
		if(!maxb[i]) continue;
		for(int j=i;j+j<=maxb[i];j+=i){
			ans=max(ans,j*A+(maxb[i]/j)*B);
		}
	}
	printf("%d\n",ans),exit(0);
}

D. 翻转游戏

签到题.

D_code
#include<bits/stdc++.h>
using namespace std;
namespace BSS{
	#define int long long
	#define lf long double
	#define pb push_back
	#define mp make_pair
	#define lb lower_bound
	#define ub upper_bound
	#define lbt(x) ((x)&(-(x)))
	#define Fill(x,y) memset(x,y,sizeof(x))
	#define Copy(x,y) memcpy(x,y,sizeof(x))
	#define File(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
	auto read=[](int w=0,bool cit=0,char ch=getchar())->int{
		for(;!isdigit(ch);ch=getchar()) cit=(ch=='-');
		for(;isdigit(ch);ch=getchar()) w=(w<<3)+(w<<1)+(ch^48);
		return cit?(-w):w;
	};
} using namespace BSS;

const int N=5e4+21,M=2e5+21;

int m,n,ans;
int val[N],rk[N],vis[N];
unordered_map<int,bool> to[N];
struct I { int d,id; } p[N];
struct Graph{
	int ts; int head[N];
	struct II { int u,v,nxt; } e[M<<1];
	inline void add(int u,int v){
		e[++ts].u=u,e[ts].v=v,e[ts].nxt=head[u];
		head[u]=ts;
	};
}A,B;
auto con=[](int u,int v)->bool{
	if(u>v) swap(u,v); return to[u].find(v)!=to[u].end();
};
signed main(){
	File(station);
	n=read(),m=read(); int u,v,z,a,b,c,d,xa,ya,xb,yb;
	for(int i=1;i<=n;i++) val[i]=read(),p[i].id=i;
	for(int i=1;i<=m;i++){
		u=read(),v=read();
		if(u>v) swap(u,v);
		A.add(u,v),A.add(v,u),to[u][v]=1;
	}
	sort(p+1,p+1+n,[](I i,I j){ return i.d==j.d ? i.id<j.id : i.d>j.d ; });
	for(int i=1;i<=n;i++) rk[p[i].id]=i;
	for(int i=1,lmi=A.ts;i<=lmi;i+=2){
		u=A.e[i].u,v=A.e[i].v;
		(rk[u]<rk[v]) ? B.add(u,v) : B.add(v,u) ;
	}
	for(u=1;u<=n;u++){
		for(int i=A.head[u];i;i=A.e[i].nxt) vis[A.e[i].v]=1;
		for(int i=A.head[u];i;i=A.e[i].nxt){
			a=0,b=0,c=0,d=0,z=A.e[i].v;
			for(int j=B.head[z];j;j=B.e[j].nxt){
				if(!vis[v=B.e[j].v]) continue;
				if(con(v,u)){
					if(val[v]>b) a=b,b=val[v];
					else if(val[v]>a) a=val[v];
				}
				else{
					if(val[v]>d) c=d,d=val[v];
					else if(val[v]>c) c=val[v];
				}
			}
			// cout<<val[u]<<' '<<val[z]<<" "<<a<<' '<<b<<" "<<c<<' '<<d<<endl;
			if(a and b){
				xa=max(val[u],val[z]),ya=min(val[u],val[z]),xb=a,yb=b;
				if(xa<xb) swap(xa,xb); if(yb<ya) swap(yb,ya);
				ans=max(ans,(xa+1)*(yb+1)+xb*ya);
			}
			if(b and d){
				xa=max(val[u],val[z]),ya=min(val[u],val[z]),xb=b,yb=d;
				if(xb<ya) swap(xb,ya);
				ans=max(ans,(xa+1)*(xb+1)+ya*yb);
			}
			if(c and d){
				xa=max(val[u],val[z]),ya=min(val[u],val[z]);
				ans=max(ans,(xa+1)*(ya+1)+c*d);
			}
		}
		for(int i=A.head[u];i;i=A.e[i].nxt) vis[A.e[i].v]=0;
	}
	printf("%lld\n",ans),exit(0);
}

总结

今天考试挺杀我的,人均 \(AK\).

\(T1\) 忘记特判 \(n==1\).
\(T2\) 没能正确分析正解应该有的复杂度.
\(T3\) 代码里忘记实现思路中的一部分直接死了,自己太浮躁了,看到水题就放松了,思路都没打出来.
\(T4\) 没打完直接死了.

以后要注意,小的数据争取一定跑暴力防止自己粗心,另外自己本就不应该粗心.
打代码应该想周全,要不然调半天影响全局.

posted @ 2021-11-07 21:38  AaMuXiiiiii  阅读(40)  评论(0编辑  收藏  举报