T1T1

考试错误:无。

思路:

直接暴力枚举 ++ 数位分离即可。

代码:

#include <bits/stdc++.h>
#define int long long
using namespace std;
int sto(string s){
    int ans=0;
    for(int i=0;i<s.size();i++){
        ans=ans*10+s[i]-'0';
    }
    return ans;
}
signed main(){
    freopen("num.in","r",stdin);
    freopen("num.out","w",stdout);
    string n;
    cin >> n;
    int mx=-1;
    for(int i=0;i<n.size();i++){
        mx=max(mx,1ll*sto(n.substr(0,i+1))*sto(n.substr(i+1)));
	}
    cout << mx;
}

T2T2

考试错误:无。

思路:

同样是直接暴力即可。

代码:

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=5e5+50;
int sq(int x){
	return x*x;
}
struct P{
	int num;
	int qid;
	int hid;
	bool operator<(const P& T) const{
		return num>T.num;
	}
};
P hb[N];
int a[N],b[N];
bool cmp(int a,int b){
	return a>b;
}
signed main(){
    freopen("class.in","r",stdin);
    freopen("class.out","w",stdout);
    int n,m;
    cin >> n >> m;
    for(int i=1;i<=n;i++){
    	cin >> a[i];
	}
	for(int i=1;i<=m;i++){
		cin >> b[i];
	}
	sort(a+1,a+n+1,cmp);
	sort(b+1,b+m+1,cmp);
	for(int i=1;i<=n;i++){
		if(i!=1&&a[i]==a[i-1]) hb[i].qid=hb[i-1].qid;
		else hb[i].qid=i;
		hb[i].num=a[i];
	}
	for(int i=1;i<=m;i++){
		if(i!=1&&b[i]==b[i-1]) hb[i+n].qid=hb[i+n-1].qid;
		else hb[i+n].qid=i;
		hb[i+n].num=b[i];
	}
	sort(hb+1,hb+n+m+1);
	int sum=0;
	for(int i=1;i<=n+m;i++){
		if(i!=1&&hb[i].num==hb[i-1].num) hb[i].hid=hb[i-1].hid;
		else hb[i].hid=i;
		int qid=hb[i].qid,hid=hb[i].hid;
		sum+=sq(qid-hid);
	}
	cout << sum;
}

T3T3

考试错误:写的暴力,骗了 5050 分。

思路:

定义 aia_i 表示第 ii 个位置左边第一个棋子的位置,如果这个位置已经有棋子了,则 ai=ia_i=i

接下来循环遍历,每次定义一个 d=iaid=i-a_i,当 aiia_i \not =i 并且 aid>aai1a_i-d>a_{a_i-1},则令 fi=faid+d×2f_i=f_{a_i-d}+d\times 2,最终输出 fif_i 中的最大值即可。

代码:

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+50;
int a[N],f[N];
signed main(){
    freopen("chess.in","r",stdin);
    freopen("chess.out","w",stdout);
    int n,m;
    cin >> n >> m;
    for(int i=1;i<=m;i++){
        int x;
        cin >> x;
        a[x]=1;
    }
    for(int i=1;i<=n;i++){
        if(a[i]==0) a[i]=a[i-1];
        else a[i]=i;
    }
    int mx=0;
    for(int i=1;i<=n;i++){
        if(a[i]==i) continue;
        int d=i-a[i];
        if(a[i]-d<=a[a[i]-1]) continue;
        f[i]=f[a[i]-d]+d*2;
        mx=max(mx,f[i]);
    }
    cout << mx;
}