2023河南省赛vp题解

news2024/9/21 22:19:58

目录

A题:

B题

C题

D题 

E题

F题

G题

H题

I题

J题

K题

         L题


A题:

        1.思路:考虑暴力枚举和双hash,可以在O(n)做完。

        2.代码实现:

#include<bits/stdc++.h>
#define sz(x) (int) x.size()
#define rep(i,z,n) for(int i = z;i <= n; i++)
#define per(i,n,z) for(int i = n;i >= z; i--)
#define pii pair<int,int>
#define fi first
#define se second
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define ull unsigned long long
#define all(x) (x).begin(),(x).end()
#define endl '\n'
#define mp make_pair
using namespace std;
using ll = long long;
const int N = 5e5 + 10;
const ull bas = 133331;
const ll mod1 = 1000000033;
const ll mod2 = 1000000103;
typedef pair<int,int> hashv;
hashv pw[N],s1[N],s2[N];
hashv operator + (hashv a,hashv b)
{
    int c1 = a.fi + b.fi,c2 = a.se + b.se;
    if(c1 >= mod1) c1 -= mod1;
    if(c2 >= mod2) c2 -= mod2;
    return mp(c1,c2);
}
hashv operator - (hashv a,hashv b)
{
    int c1 = a.fi - b.fi,c2 = a.se - b.se;
    if(c1 < 0) c1 += mod1;
    if(c2 < 0) c2 += mod2;
    return mp(c1,c2);
}
hashv operator * (hashv a,hashv b)
{
    int c1 = (ll)a.fi * b.fi % mod1,c2 = (ll) a.se * b.se % mod2;
    return mp(c1,c2);
}
void init(string s)
{
	int n = sz(s);
	string t = s;
	reverse(all(t));
	t = " " + t;
	s = " " + s;
	hashv base = mp(10331,100313);
    pw[0] = mp(1,1);
	rep(i,1,n) {
		pw[i] = pw[i - 1] * base;
        s1[i] = s1[i - 1] * base + mp(s[i],s[i]);
        s2[i] = s2[i - 1] * base + mp(t[i],t[i]);
//		pw[i] = pw[i - 1] * bas;
	}
}
hashv get1(int l,int r)
{
	return s1[r] - s1[l - 1] * pw[r - l + 1];
}
hashv get2(int l,int r)
{
	return s2[r] - s2[l - 1] * pw[r - l + 1];
}
void solve(){
	string s;
	cin >> s;
	init(s);
	int n = sz(s);
	s = " " + s;
	vector<int> vis(26);
	rep(i,1,n - 1) {
		if(vis[s[i] - 'a']) break;
		vis[s[i] - 'a'] = true;	
		int len = n - i;
		if(get1(i + 1,n) == get2(1,len)) {
			cout << "HE" << endl;
			return;
		}
	}
	cout << "NaN" << endl;
}
int main()
{
    ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int T = 1;
	cin >> T;
	while(T --) solve();
}

B题

        1.思路:暴力枚举+ST表,暴力枚举是调和级数的复杂度。

        2.代码实现:

#include<bits/stdc++.h>
#define sz(x) (int) x.size()
#define rep(i,z,n) for(int i = z;i <= n; i++)
#define per(i,n,z) for(int i = n;i >= z; i--)
#define pii pair<int,int>
#define fi first
#define se second
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define ull unsigned long long
#define all(x) (x).begin(),(x).end()
#define endl '\n'
#define mp make_pair
using namespace std;
using ll = long long;
const int N = 1e6 + 10;
#include <functional>
#include <numeric>

namespace OY {
    template <typename _Tp, typename _Maximum>
    class STTable {
        std::vector<std::vector<_Tp>> m_sub;
        _Maximum m_maxi;
        int m_length;
        _Tp m_defaultValue;
        void _check() {
            // assert(m_maxi(m_defaultValue, m_defaultValue) == m_defaultValue);
        }

    public:
        STTable(int __n = 0, _Maximum __maxi = std::max<_Tp>, _Tp __defaultValue = _Tp()) : m_maxi(__maxi), m_defaultValue(__defaultValue) {
            _check();
            resize(__n);
        }
        template <typename _Iterator>
        STTable(_Iterator __first, _Iterator __last, _Maximum __maxi = std::max<_Tp>, _Tp __defaultValue = _Tp()) : m_maxi(__maxi), m_defaultValue(__defaultValue) {
            _check();
            reset(__first, __last);
        }
        void resize(int __n) {
            if (!__n) return;
            m_length = __n;
            int d = 32 - (m_length > 1 ? __builtin_clz(m_length - 1) : 32);
            m_sub.resize(d);
            m_sub[0].assign(__n, m_defaultValue);
            for (int i = 1; i < d; i++) {
                m_sub[i].clear();
                m_sub[i].reserve(m_length - (1 << i) + 1);
                for (int j = 0; j <= m_length - (1 << i); j++)
                    m_sub[i].push_back(m_maxi(m_sub[i - 1][j], m_sub[i - 1][j + (1 << i - 1)]));
            }
        }
        template <typename _Iterator>
        void reset(_Iterator __first, _Iterator __last) {
            m_length = __last - __first;
            int d = 32 - (m_length > 1 ? __builtin_clz(m_length - 1) : 32);
            m_sub.resize(d);
            m_sub[0].assign(__first, __last);
            for (int i = 1; i < d; i++) {
                m_sub[i].clear();
                m_sub[i].reserve(m_length - (1 << i) + 1);
                for (int j = 0; j <= m_length - (1 << i); j++)
                    m_sub[i].push_back(m_maxi(m_sub[i - 1][j], m_sub[i - 1][j + (1 << i - 1)]));
            }
        }
        void update(int __i, _Tp __val) {
            m_sub[0][__i] = __val;
            for (int i = 1; i < m_sub.size(); i++)
                for (int j = std::max(0, __i - (1 << i) + 1), end = std::min(__i, int(m_sub[i].size() - 1)); j <= end; j++)
                    m_sub[i][j] = m_maxi(m_sub[i - 1][j], m_sub[i - 1][j + (1 << i - 1)]);
        }
        _Tp query(int __i) const {
            return m_sub[0][__i];
        }
        _Tp query(int __left, int __right) const {
            if (__left == __right) return m_sub[0][__left];
            int d = 31 - __builtin_clz(__right - __left);
            return m_maxi(m_sub[d][__left], m_sub[d][__right - (1 << d) + 1]);
        }
        _Tp queryAll() const {
            return query(0, m_length - 1);
        }
    };
    template <typename _Tp = int>
    STTable(int = 0, const _Tp &(*)(const _Tp &, const _Tp &) = std::max<_Tp>, _Tp = _Tp()) -> STTable<_Tp, const _Tp &(*)(const _Tp &, const _Tp &)>;
    template <typename _Tp = int>
    STTable(int, _Tp (*)(_Tp, _Tp), _Tp = _Tp()) -> STTable<_Tp, _Tp (*)(_Tp, _Tp)>;
    template <typename _Maximum, typename _Tp = std::decay_t<typename decltype(std::mem_fn(&_Maximum::operator()))::result_type>>
    STTable(int, _Maximum, _Tp = _Tp()) -> STTable<_Tp, _Maximum>;
    template <typename _Iterator, typename _Maximum, typename _Tp = typename std::iterator_traits<_Iterator>::value_type>
    STTable(_Iterator, _Iterator, _Maximum, _Tp = _Tp()) -> STTable<_Tp, _Maximum>;
    template <typename _Iterator, typename _Tp = typename std::iterator_traits<_Iterator>::value_type>
    STTable(_Iterator, _Iterator, const _Tp &(*)(const _Tp &, const _Tp &) = std::max<_Tp>, _Tp = _Tp()) -> STTable<_Tp, const _Tp &(*)(const _Tp &, const _Tp &)>;
    template <typename _Iterator, typename _Tp = typename std::iterator_traits<_Iterator>::value_type>
    STTable(_Iterator, _Iterator, _Tp (*)(_Tp, _Tp), _Tp = _Tp()) -> STTable<_Tp, _Tp (*)(_Tp, _Tp)>;
}
int n;
inline char nc() {
    static char buf[1000000], *p1 = buf, *p2 = buf;
    return p1 == p2 && (p2 = (p1 = buf) + fread (buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++;
}
template <class T> inline bool read(T &x) {
    x = 0; char c = nc(); bool f(0);
    while (c < '0' || c > '9') { if (c == EOF) return false; f = c == '-', c = nc(); }
    while (c >= '0' && c <= '9') x = x * 10 + (c ^ 48), c = nc(); if (f) x = -x; return true;
}
int a[N];
void solve(){
	read(n);
	rep(i,0,n-1) read(a[i]);
	auto mymax = [](int x, int y) {
        return x > y ? x : y;
    };
    OY::STTable st_max(a , a + n, mymax);
    OY::STTable st_min(a , a + n, std::min);
	int ans = 1;
	for(int i = 1;i < n;i ++) {
		bool ok = true;
		for(int j = i;j <= n;j += i) {
			if(j == n) break;
			int nxt = min(j + i,n);
			int v1 = st_max.query(j - i,j - 1);
			int v2 = st_min.query(j,nxt - 1);
			if(v1 > v2) {
				ok = false;
				break;
			}
		}
		if(ok) ans ++;
	}
	cout << ans << endl;
}
int main()
{
    ios::sync_with_stdio(false);
	cout.tie(0);
	int T = 1;
//	cin >> T;
	while(T --) solve();
}

C题

        1.思路:考虑验证这个序列,如果出现两个相同的连续超过40的串,那么就认为这个串不随机就行了,错误率就是\frac{1}{2^{40}},实现就是直接kmp搞一下next数组找个最大的看是否大于等于40即可。

        2.代码实现:

#include<bits/stdc++.h>
#define sz(x) (int) x.size()
#define rep(i,z,n) for(int i = z;i <= n; i++)
#define per(i,n,z) for(int i = n;i >= z; i--)
#define pii pair<int,int>
#define fi first
#define se second
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define endl '\n'
using namespace std;
using ll = long long;
const int N = 1e6 + 10;
const ll mod = 1e9 + 7;
int a[N],nxt[N];
void get_next(string s)
{
	int i = 0,j = -1;
	nxt[0] = -1;
	int n = s.size();
	while(i < n) {
	    if(j == -1 || s[i] == s[j]) {
	        i++, j++;
	        nxt[i] = j;
	    }
	    else j = nxt[j];
	 } 
}
void solve(){
	string s,t;
	s = "";
	while(cin >> t) s += t;	
	get_next(s);
	int n = sz(s);
	int mx = 0;
	for(int i = 1;i <= n;i ++) mx = max(mx,nxt[i]);
	if(mx >= 40) cout << "NO" << endl;
	else cout << "YES" << endl;
}
int main()
{
    ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int T = 1;
//	cin >> T;
	while(T --) solve();
}

D题 不会

E题

        1.思路:考虑dp[i][j][k]表示第i行第j列修改了k个问号的最大值是多少,因为数组内存开不了这么大,因此我们考虑优化空间,我们发现这一行的状态只跟这一行和上一行有关,因此可以滚动dp优化空间。

        2.代码实现:

#include<bits/stdc++.h>
#define sz(x) (int) x.size()
#define rep(i,z,n) for(int i = z;i <= n; i++)
#define per(i,n,z) for(int i = n;i >= z; i--)
#define pii pair<int,int>
#define fi first
#define se second
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define ull unsigned long long
#define all(x) (x).begin(),(x).end()
#define endl '\n'
#define mp make_pair
using namespace std;
using ll = long long;
const int N = 501;
int n;
inline char nc() {
    static char buf[1000000], *p1 = buf, *p2 = buf;
    return p1 == p2 && (p2 = (p1 = buf) + fread (buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++;
}
template <class T> inline bool read(T &x) {
    x = 0; char c = nc(); bool f(0);
    while (c < '0' || c > '9') { if (c == EOF) return false; f = c == '-', c = nc(); }
    while (c >= '0' && c <= '9') x = x * 10 + (c ^ 48), c = nc(); if (f) x = -x; return true;
}
int a[N];
string s[N];
void solve(){
	int m,x;
	cin >> n >> m >> x;
	rep(i,1,n) {
		cin >> s[i];
		s[i] = " " + s[i];
	}
	vector<vector<int>> odp(m + 1,vector<int>(x + 1));
	odp[1][0] = (s[1][1] == '1');
	if(s[1][1] == '?' && x >= 1) odp[1][1] = 1;
	rep(j,1,m) {
		rep(k,0,x) {
			int v = s[1][j] == '1';
			odp[j][k] = max(odp[j - 1][k] + v,odp[j][k]);
			if(s[1][j] == '?' && k + 1 <= x) odp[j][k + 1] = max(odp[j - 1][k] + 1,odp[j][k + 1]);
		}
	}
	rep(i,2,n) {
		vector<vector<int>> ndp(m + 1,vector<int>(x + 1));
		rep(j,1,m) {
			vector<int> dp(x + 1,0);
			rep(k,0,x) {
				int v = s[i][j] == '1';
				dp[k] = max(ndp[j - 1][k] + v,dp[k]);
				if(s[i][j] == '?' && k + 1 <= x) dp[k + 1] = max(dp[k + 1],ndp[j - 1][k] + 1);
				
				ndp[j][k] = max(ndp[j][k],odp[j][k] + v);
				if(s[i][j] == '?' && k + 1 <= x) ndp[j][k + 1] = max(ndp[j][k + 1],odp[j][k] + 1);
			}
			rep(k,0,x) ndp[j][k] = max(ndp[j][k],dp[k]);
		}
		swap(ndp,odp);
	}
	int ans = 0;
	rep(i,0,x) ans = max(ans,odp[m][i]);
	cout << ans << '\n';
}
int main()
{
    ios::sync_with_stdio(false);
	cout.tie(0),cin.tie(0);
	int T = 1;
	cin >> T;
	while(T --) solve();
}

F题

        1.思路:因为是任意i,j相差取min和max,因此考虑直接排序选k个中最大和最小的一直取min就是答案,考虑用multiset维护即可。

        2.代码实现

#include<bits/stdc++.h>
#define sz(x) (int) x.size()
#define rep(i,z,n) for(int i = z;i <= n; i++)
#define per(i,n,z) for(int i = n;i >= z; i--)
#define pii pair<int,int>
#define fi first
#define se second
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define ull unsigned long long
#define all(x) (x).begin(),(x).end()
#define endl '\n'
#define mp make_pair
using namespace std;
using ll = long long;
const int N = 5e5 + 10;
int n;
inline char nc() {
    static char buf[1000000], *p1 = buf, *p2 = buf;
    return p1 == p2 && (p2 = (p1 = buf) + fread (buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++;
}
template <class T> inline bool read(T &x) {
    x = 0; char c = nc(); bool f(0);
    while (c < '0' || c > '9') { if (c == EOF) return false; f = c == '-', c = nc(); }
    while (c >= '0' && c <= '9') x = x * 10 + (c ^ 48), c = nc(); if (f) x = -x; return true;
}
int a[N];
void solve(){
	int n,k;
	cin >> n >> k;
	rep(i,1,n) cin >> a[i];
	sort(a + 1,a + 1 + n);
	multiset<int> mt;
	ll ans = 2e18;
	rep(i,1,n) {
		if(i > 1) mt.insert(a[i] - a[i - 1]);
		if(i > k) mt.erase(mt.find(a[i - k + 1] - a[i - k]));
		if(i >= k) {
			int mx = a[i] - a[i - k + 1];
			int mi = *mt.begin();
//			cout << i << ',' << mi << ',' << mx << endl;
			ans = min(ans,1ll * mi * mx);
		}
	}
	cout << ans << endl;
}
int main()
{
    ios::sync_with_stdio(false);
	cout.tie(0),cin.tie(0);
	int T = 1;
//	cin >> T;
	while(T --) solve();
}

G题

        1.思路:模拟题,考虑特判1的情况就可以了。

        2.代码实现:

#include<bits/stdc++.h>
#define sz(x) (int) x.size()
#define rep(i,z,n) for(int i = z;i <= n; i++)
#define per(i,n,z) for(int i = n;i >= z; i--)
#define pii pair<int,int>
#define fi first
#define se second
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define ull unsigned long long
#define all(x) (x).begin(),(x).end()
#define endl '\n'
#define mp make_pair
using namespace std;
using ll = long long;
const int N = 5e5 + 10;
int n;
inline char nc() {
    static char buf[1000000], *p1 = buf, *p2 = buf;
    return p1 == p2 && (p2 = (p1 = buf) + fread (buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++;
}
template <class T> inline bool read(T &x) {
    x = 0; char c = nc(); bool f(0);
    while (c < '0' || c > '9') { if (c == EOF) return false; f = c == '-', c = nc(); }
    while (c >= '0' && c <= '9') x = x * 10 + (c ^ 48), c = nc(); if (f) x = -x; return true;
}
int a[N];
string ans[14];
string num[15][100];
string unum[12][100];
void init2()
{
	unum[0][1] = ".....";
	unum[0][2] = "00000";
	unum[0][3] = "0...0";
	unum[0][4] = "0...0";
	unum[0][5] = "0...0";
	unum[0][6] = "00000";
	unum[0][7] = ".....";
	unum[0][8] = ".....";
	unum[0][9] = ".....";
	unum[0][10] = ".....";
	
	unum[1][1] = ".....";
	unum[1][2] = "....1";
	unum[1][3] = "....1";
	unum[1][4] = "....1";
	unum[1][5] = "....1";
	unum[1][6] = "....1";
	unum[1][7] = ".....";
	unum[1][8] = ".....";
	unum[1][9] = ".....";
	unum[1][10] = ".....";
	
	unum[2][1] = ".....";
	unum[2][2] = "22222";
	unum[2][3] = "....2";
	unum[2][4] = "22222";
	unum[2][5] = "2....";
	unum[2][6] = "22222";
	unum[2][7] = ".....";
	unum[2][8] = ".....";
	unum[2][9] = ".....";
	unum[2][10] = ".....";
	
	unum[3][1] = ".....";
	unum[3][2] = "33333";
	unum[3][3] = "....3";
	unum[3][4] = "33333";
	unum[3][5] = "....3";
	unum[3][6] = "33333";
	unum[3][7] = ".....";
	unum[3][8] = ".....";
	unum[3][9] = ".....";
	unum[3][10] = ".....";
	
	unum[4][1] = ".....";
	unum[4][2] = "4...4";
	unum[4][3] = "4...4";
	unum[4][4] = "44444";
	unum[4][5] = "....4";
	unum[4][6] = "....4";
	unum[4][7] = ".....";
	unum[4][8] = ".....";
	unum[4][9] = ".....";
	unum[4][10] = ".....";
	
	unum[5][1] = ".....";
	unum[5][2] = "55555";
	unum[5][3] = "5....";
	unum[5][4] = "55555";
	unum[5][5] = "....5";
	unum[5][6] = "55555";
	unum[5][7] = ".....";
	unum[5][8] = ".....";
	unum[5][9] = ".....";
	unum[5][10] = ".....";
	
	unum[6][1] = ".....";
	unum[6][2] = "66666";
	unum[6][3] = "6....";
	unum[6][4] = "66666";
	unum[6][5] = "6...6";
	unum[6][6] = "66666";
	unum[6][7] = ".....";
	unum[6][8] = ".....";
	unum[6][9] = ".....";
	unum[6][10] = ".....";
	
	unum[7][1] = ".....";
	unum[7][2] = "77777";
	unum[7][3] = "....7";
	unum[7][4] = "....7";
	unum[7][5] = "....7";
	unum[7][6] = "....7";
	unum[7][7] = ".....";
	unum[7][8] = ".....";
	unum[7][9] = ".....";
	unum[7][10] = ".....";
	
	unum[8][1] = ".....";
	unum[8][2] = "88888";
	unum[8][3] = "8...8";
	unum[8][4] = "88888";
	unum[8][5] = "8...8";
	unum[8][6] = "88888";
	unum[8][7] = ".....";
	unum[8][8] = ".....";
	unum[8][9] = ".....";
	unum[8][10] = ".....";
	
	unum[9][1] = ".....";
	unum[9][2] = "99999";
	unum[9][3] = "9...9";
	unum[9][4] = "99999";
	unum[9][5] = "....9";
	unum[9][6] = "99999";
	unum[9][7] = ".....";
	unum[9][8] = ".....";
	unum[9][9] = ".....";
	unum[9][10] = ".....";
}
//处理下面的数字
void init()
{
	num[0][1] = ".......";
	num[0][2] = ".......";
	num[0][3] = "0000000";
	num[0][4] = "0.....0";
	num[0][5] = "0.....0";
	num[0][6] = "0.....0";
	num[0][7] = "0.....0";
	num[0][8] = "0.....0";
	num[0][9] = "0000000";
	num[0][10] = ".......";
	
	num[1][1] = ".......";
	num[1][2] = ".......";
	num[1][3] = "......1";
	num[1][4] = "......1";
	num[1][5] = "......1";
	num[1][6] = "......1";
	num[1][7] = "......1";
	num[1][8] = "......1";
	num[1][9] = "......1";
	num[1][10] = ".......";
	
	num[2][1] = ".......";
	num[2][2] = ".......";
	num[2][3] = "2222222";
	num[2][4] = "......2";
	num[2][5] = "......2";
	num[2][6] = "2222222";
	num[2][7] = "2......";
	num[2][8] = "2......";
	num[2][9] = "2222222";
	num[2][10] = ".......";
	
	num[3][1] = ".......";
	num[3][2] = ".......";
	num[3][3] = "3333333";
	num[3][4] = "......3";
	num[3][5] = "......3";
	num[3][6] = "3333333";
	num[3][7] = "......3";
	num[3][8] = "......3";
	num[3][9] = "3333333";
	num[3][10] = ".......";
	
	num[4][1] = ".......";
	num[4][2] = ".......";
	num[4][3] = "4.....4";
	num[4][4] = "4.....4";
	num[4][5] = "4.....4";
	num[4][6] = "4444444";
	num[4][7] = "......4";
	num[4][8] = "......4";
	num[4][9] = "......4";
	num[4][10] = ".......";
	
	num[5][1] = ".......";
	num[5][2] = ".......";
	num[5][3] = "5555555";
	num[5][4] = "5......";
	num[5][5] = "5......";
	num[5][6] = "5555555";
	num[5][7] = "......5";
	num[5][8] = "......5";
	num[5][9] = "5555555";
	num[5][10] = ".......";
	
	num[6][1] = ".......";
	num[6][2] = ".......";
	num[6][3] = "6666666";
	num[6][4] = "6......";
	num[6][5] = "6......";
	num[6][6] = "6666666";
	num[6][7] = "6.....6";
	num[6][8] = "6.....6";
	num[6][9] = "6666666";
	num[6][10] = ".......";
	
	num[7][1] = ".......";
	num[7][2] = ".......";
	num[7][3] = "7777777";
	num[7][4] = "......7";
	num[7][5] = "......7";
	num[7][6] = "......7";
	num[7][7] = "......7";
	num[7][8] = "......7";
	num[7][9] = "......7";
	num[7][10] = ".......";
	
	num[8][1] = ".......";
	num[8][2] = ".......";
	num[8][3] = "8888888";
	num[8][4] = "8.....8";
	num[8][5] = "8.....8";
	num[8][6] = "8888888";
	num[8][7] = "8.....8";
	num[8][8] = "8.....8";
	num[8][9] = "8888888";
	num[8][10] = ".......";
	
	num[9][1] = ".......";
	num[9][2] = ".......";
	num[9][3] = "9999999";
	num[9][4] = "9.....9";
	num[9][5] = "9.....9";
	num[9][6] = "9999999";
	num[9][7] = "......9";
	num[9][8] = "......9";
	num[9][9] = "9999999";
	num[9][10] = ".......";
	
	//I
	num[10][1] = ".......";
	num[10][2] = ".......";
	num[10][3] = "IIIIIII";
	num[10][4] = "...I...";
	num[10][5] = "...I...";
	num[10][6] = "...I...";
	num[10][7] = "...I...";
	num[10][8] = "...I...";
	num[10][9] = "IIIIIII";
	num[10][10] = ".......";
	
	//N
	num[11][1] = ".......";
	num[11][2] = ".......";
	num[11][3] = "N.....N";
	num[11][4] = "NN....N";
	num[11][5] = "N.N...N";
	num[11][6] = "N..N..N";
	num[11][7] = "N...N.N";
	num[11][8] = "N....NN";
	num[11][9] = "N.....N";
	num[11][10] = ".......";
	
	//F
	num[12][1] = ".......";
	num[12][2] = ".......";
	num[12][3] = "FFFFFFF";
	num[12][4] = "F......";
	num[12][5] = "F......";
	num[12][6] = "FFFFFFF";
	num[12][7] = "F......";
	num[12][8] = "F......";
	num[12][9] = "F......";
	num[12][10] = ".......";
	
	//=
	num[13][1] = ".......";
	num[13][2] = ".......";
	num[13][3] = ".......";
	num[13][4] = ".......";
	num[13][5] = "=======";
	num[13][6] = ".......";
	num[13][7] = "=======";
	num[13][8] = ".......";
	num[13][9] = ".......";
	num[13][10] = ".......";
	
}
void add1(int idx)
{
	rep(i,1,10) ans[i] += '.';
	rep(i,1,10) ans[i] += num[idx][i];
}
void add2(int idx)
{
	rep(i,1,10) ans[i] += '.';
	rep(i,1,10) ans[i] += unum[idx][i];
}
void dispose1(ll x)
{
	vector<int> nums;
	while(x) {
		nums.pb(x % 10);
		x /= 10;
	}
	reverse(all(nums));
	for(int i = 0;i < sz(nums);i ++) add1(nums[i]);
}
void dispose2(ll x)
{
	vector<int> nums;
	while(x) {
		nums.pb(x % 10);
		x /= 10;
	}
	reverse(all(nums));
	for(int i = 0;i < sz(nums);i ++) add2(nums[i]);
	add1(13);
}
void dispose3(ll x,bool lim)
{
	if(lim) {
		add1(10);
		add1(11);
		add1(12);
	}
	else dispose1(x);
}
void dispose4()
{
	rep(i,1,10) ans[i] += '.';
}
void solve(){
	rep(i,1,10) ans[i].clear();
	string s;
	ll x = 0,y = 0;
	cin >> s;
	int vis = 0;
	for(int i = 0;i < sz(s);i ++) {
		if(s[i] == '^' || s[i] == '{' || s[i] == '}') {
			vis ++;
			continue;
		}
		if(vis == 0) x = x * 10 + s[i] - '0';
		else y = y * 10 + s[i] - '0';
	}
	bool lim = false;
	dispose1(x);
	dispose2(y);
	ll tv = 1;
	rep(i,1,y) {
		if(x == 1) break;
		if((__int128)tv * x > 1e18) {
			lim = true;
			break;
		}
		tv *= x;
	}
	dispose3(tv,lim);
	dispose4();
	rep(i,1,10) cout << ans[i] << '\n';
}
int main()
{
    ios::sync_with_stdio(false);
	cout.tie(0),cin.tie(0);
	init();
	init2();
	int T = 1;
	cin >> T;
	while(T --) solve();
}

H题

        1.思路:找的规律

        2.代码实现:

#include<bits/stdc++.h>
#define sz(x) (int) x.size()
#define rep(i,z,n) for(int i = z;i <= n; i++)
#define per(i,n,z) for(int i = n;i >= z; i--)
#define pii pair<int,int>
#define fi first
#define se second
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define ull unsigned long long
#define all(x) (x).begin(),(x).end()
#define endl '\n'
#define mp make_pair
using namespace std;
using ll = long long;
const int N = 5e5 + 10;
int n;
inline char nc() {
    static char buf[1000000], *p1 = buf, *p2 = buf;
    return p1 == p2 && (p2 = (p1 = buf) + fread (buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++;
}
template <class T> inline bool read(T &x) {
    x = 0; char c = nc(); bool f(0);
    while (c < '0' || c > '9') { if (c == EOF) return false; f = c == '-', c = nc(); }
    while (c >= '0' && c <= '9') x = x * 10 + (c ^ 48), c = nc(); if (f) x = -x; return true;
}
int a[N];
void solve(){
	int n,k;
	cin >> n >> k;
	cout << n - min(2 * n,k - 1) / 2 << ' ' << n + (min(2 * n,k - 1) + 1) / 2 << endl;
}
int main()
{
    ios::sync_with_stdio(false);
	cout.tie(0),cin.tie(0);
	int T = 1;
	cin >> T;
	while(T --) solve();
}

I题

        1.思路:考虑x序列和y序列的特殊性,我们容易手搓出来最多每个格子只会被cover两次,因此我们考虑用扫描线处理这个问题,考虑答案求解,我们可以反着求答案用总数减去非纯色矩阵即可。考虑非纯色矩阵的构成,说明这个矩阵中有点被覆盖了,我们直接减去被矩形边覆盖的点数,问题转变为我们直接减去交点数即可,因此用树状数组维护一下单点修改区间查询即可。

        2.代码实现:

#include<bits/stdc++.h>
#define sz(x) (int) x.size()
#define rep(i,z,n) for(int i = z;i <= n; i++)
#define per(i,n,z) for(int i = n;i >= z; i--)
#define pii pair<int,int>
#define fi first
#define se second
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define endl '\n'
using namespace std;
using ll = long long;
const int N = 1e6 + 10;
pii a[N];
template <typename T>
struct Fenwick {
    const int n;
    std::vector<T> a;

    Fenwick (int n) : n(n), a(n + 1) {}

    void add(int pos, int x) {
        for (int i = pos; i <= n; i += i & -i) {
            a[i] += x;
        }
    }

    T query(int x) {
        T res = 0;
        for (int i = x; i; i -= i & -i) {
            res += a[i];
        }
        return res;
    }

    T query(int l, int r) {
        if (l == 0 || l > r) {
            return 0;
        }
        return query(r) - query(l - 1);
    }
};
inline char nc() {
    static char buf[1000000], *p1 = buf, *p2 = buf;
    return p1 == p2 && (p2 = (p1 = buf) + fread (buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++;
}
template <class T> inline bool read(T &x) {
    x = 0; char c = nc(); bool f(0);
    while (c < '0' || c > '9') { if (c == EOF) return false; f = c == '-', c = nc(); }
    while (c >= '0' && c <= '9') x = x * 10 + (c ^ 48), c = nc(); if (f) x = -x; return true;
}
void solve(){
	int n;
	read(n);
	rep(i,1,n) {
		int x1,y1,x2,y2;
		read(x1),read(y1);
		read(x2),read(y2);
		a[y1] = {x1,x2};
		a[y2] = {-x1,-x2};
	}
	Fenwick<int> fen(2 * n);
	ll ans = 0;
	rep(i,1,2*n) {
		int L = a[i].fi,R = a[i].se;
		if(L < 0) {
			L = -L,R = -R;
			fen.add(L,-1);
			fen.add(R,-1);
		}
		else {
			fen.add(L,1);
			fen.add(R,1);
		}
		ans = ans + 2 * n - (R - L + 1) - fen.query(2 * n) + fen.query(L,R);
	}
	cout << ans << endl;
}
int main()
{
	int T = 1;
//	cin >> T;
	while(T --) solve();
}

J题 不会

K题

        1.思路:考虑2为质数这个特性,我们尽可能把数差为2的构造,发现无论计数情况和偶数情况我们都能够剩下2和n-1这两个数,对于2这个数我们可以插入到4和6中间,n-1这个数我们可以插入到n-3和n-5中间去。小于10的话写个dfs就行了。

        2.代码实现:

#include<bits/stdc++.h>
#define sz(x) (int) x.size()
#define rep(i,z,n) for(int i = z;i <= n; i++)
#define per(i,n,z) for(int i = n;i >= z; i--)
#define pii pair<int,int>
#define fi first
#define se second
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define ull unsigned long long
#define all(x) (x).begin(),(x).end()
#define endl '\n'
#define mp make_pair
using namespace std;
using ll = long long;
const int N = 5e5 + 10;
inline char nc() {
    static char buf[1000000], *p1 = buf, *p2 = buf;
    return p1 == p2 && (p2 = (p1 = buf) + fread (buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++;
}
template <class T> inline bool read(T &x) {
    x = 0; char c = nc(); bool f(0);
    while (c < '0' || c > '9') { if (c == EOF) return false; f = c == '-', c = nc(); }
    while (c >= '0' && c <= '9') x = x * 10 + (c ^ 48), c = nc(); if (f) x = -x; return true;
}
struct Primes {
    bitset <N> st;
    int cnt,primes[N],idx[N],n;
 
    Primes(int n = N - 1) {
        this->n = n;
        init(n);
    }
 
    void init(int n) {
        st[0] = st[1] = 1;
        for(int i = 2;i <= n;i ++) {
            if(!st[i]) {
                primes[++ cnt] = i;
                idx[i] = cnt;
            }
            for(int j = 1;primes[j] <= n / i;j ++) {
                st.flip(primes[j] * i);
                if(i % primes[j] == 0) break;
            }
        }
    }
    
    //判断x是否是质数      
    bool isPrime(int x) {
        assert(x <= n);
        return !st[x];
    }
    
    //求解x在质数表是第几个                    
    bool atIndex(int x) {
        assert(!st[x]);
        assert(x <= n);
        return idx[x];
    }
}pr(1e5);
int n,vis[11],ans[N];
inline void dfs(int f)
{
	if(f == n + 1) {
		if(pr.isPrime(abs(ans[f - 1] - ans[1]))) {
			rep(i,1,n) cout << ans[i] << ' ';
			exit(0);
		}
		return ;
	}
	rep(i,1,n) {
		if(!vis[i]) {
			if(f > 1 && !pr.isPrime(abs(i - ans[f - 1]))) continue;
			vis[i] = true;
			ans[f] = i;
			dfs(f + 1);
			vis[i] = false;
		}
	}
}
void solve(){
	cin >> n;
	//10! = 40320*9*10
	if(n <= 10) {
		dfs(1);
		cout << -1 << endl;
		return;
	}
	if(n & 1) {
		int cnt = 0;
		for(int i = 1;i <= n;i += 2) ans[++ cnt] = i;
		for(int i = n - 3;i >= 4;i -= 2) ans[++ cnt] = i;
		//剩下n-1和2
		int ok1 = false,ok2 = false;
		rep(i,1,cnt - 1) {
			bool same = false;
			if(!ok1 && pr.isPrime(abs(n - 1 - ans[i])) && pr.isPrime(abs(n - 1 - ans[i + 1]))) {
				ok1 = i;
				same = true;
			}
			if(!same && !ok2 && pr.isPrime(abs(2 - ans[i])) && pr.isPrime(abs(2 - ans[i + 1]))) {
				ok2 = i;
			}
		}
		bool same = false;
		if(!ok1 && pr.isPrime(abs(n - 1 - ans[cnt])) && pr.isPrime(abs(n - 1 - ans[1]))) {
			ok2 = n;
			same = true;
		}
		if(!same && !ok2 && pr.isPrime(abs(2 - ans[cnt])) && pr.isPrime(abs(2 - ans[1]))) {
			ok2 = n;
		}
		assert(ok1 != ok2);
		rep(i,1,cnt) {
			cout << ans[i] << ' ';
			if(i == ok1) cout << n - 1 << ' ';
			if(i == ok2) cout << 2 << ' ';
		}
		cout << endl;
	}
	else {
		int cnt = 0;
		for(int i = 1;i <= n - 3;i += 2) ans[++ cnt] = i;
		for(int i = n;i >= 4;i -= 2) ans[++ cnt] = i;
		//剩下n-1和2
		int ok1 = false,ok2 = false;
		rep(i,1,cnt - 1) {
			bool same = false;
			if(!ok1 && pr.isPrime(abs(n - 1 - ans[i])) && pr.isPrime(abs(n - 1 - ans[i + 1]))) {
				ok1 = i;
				same = true;
			}
			if(!same && !ok2 && pr.isPrime(abs(2 - ans[i])) && pr.isPrime(abs(2 - ans[i + 1]))) {
				ok2 = i;
			}
		}
		bool same = false;
		if(!ok1 && pr.isPrime(abs(n - 1 - ans[cnt])) && pr.isPrime(abs(n - 1 - ans[1]))) {
			ok2 = n;
			same = true;
		}
		if(!same && !ok2 && pr.isPrime(abs(2 - ans[cnt])) && pr.isPrime(abs(2 - ans[1]))) {
			ok2 = n;
		}
		assert(ok1 != ok2);
		rep(i,1,cnt) {
			cout << ans[i] << ' ';
			if(i == ok1) cout << n - 1 << ' ';
			if(i == ok2) cout << 2 << ' ';
		}
		cout << endl;
	}
}
int main()
{
    ios::sync_with_stdio(false);
	cout.tie(0),cin.tie(0);
	int T = 1;
//	cin >> T;
	while(T --) solve();
}

L题 不会

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/511273.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

头歌计算机算法设计与分析:随机化算法

第1关&#xff1a;硬币实验 任务描述 相关知识随机数 编程要求 测试说明任务描述 本关任务&#xff1a;计算机产生的伪随机数来模拟抛硬币试验。 相关知识 为了完成本关任务&#xff0c;你需要掌握&#xff1a;1.如何获取数组的长度&#xff0c;2.如何遍历数组。 随机数 随机…

基于 SpringBoot+WebSocket 无DB实现在线聊天室

0 项目说明 0.1 样例展示 0.2 源码地址 GitHub&#xff1a;https://github.com/ShiJieCloud/web-chat Gitee&#xff1a;https://gitee.com/suitbaby/web-chat GitCode&#xff1a;I’m Jie / web-chat GitCode 1 WebSocket 简介 1.1 HTTP 常用的 HTTP 协议是一种无状态…

【牛客刷题专栏】0x27:JZ29 顺时针打印矩阵(C语言编程题)

前言 个人推荐在牛客网刷题(点击可以跳转)&#xff0c;它登陆后会保存刷题记录进度&#xff0c;重新登录时写过的题目代码不会丢失。个人刷题练习系列专栏&#xff1a;个人CSDN牛客刷题专栏。 题目来自&#xff1a;牛客/题库 / 在线编程 / 剑指offer&#xff1a; 目录 前言问…

2023年Pycharm安装教程,附详细图解

简介 PyCharm是一款Python IDE&#xff0c;其带有一整套可以帮助用户在使用Python语言开发时提高其效率的工具&#xff0c;比如&#xff0c; 调试、语法高亮、Project管理、代码跳转、智能提示、自动完成、单元测试、版本控制等等。此外&#xff0c;该IDE提供了一些高级功能&a…

面向对象构造顺序与析构顺序详解

#include<bits/stdc.h> using namespace std;class animal{public:animal(){cout<<"调用animal构造"<<endl;}~animal(){cout<<"调用animal析构"<<endl;} };class verhical{public:verhical(){cout<<"调用verhica…

服装供应链管理包含哪些内容,如何选择服装供应链管理系统?

服装供应链管理是指对服装工厂的采购、生产、物流、仓储和销售等环节的管理&#xff0c;包括原材料的采购、成品的制造、配送、零售等多个环节。 选择合适的服装供应链管理系统&#xff0c;能够帮助服装工厂提高供应链管理的效率、优化库存管理、降低运营成本、保证服装生产的品…

TCP协议三次握手四次挥手详细分析

在学习TCP协议的时候&#xff0c;接触最多的就是TCP的三次握手和四次挥手。关于这个的介绍大多数都是文字和图示来分析的&#xff0c;但是具体到协议的内容时&#xff0c;有可能还是不清楚&#xff0c;下面我就通过具体协议来分析一下这个过程。 这里使用Wireshark网络分析工具…

【Linux】进程与文件系统(上)

由于这部分的知识很多很多&#xff0c;分成两回 目录 1.文件描述符 文件描述符 1.文件描述符 首先我们看一下几个小问题 1.你真的理解文件原理和操作了吗&#xff1f; 这不是语言的问题&#xff0c;而是操作系统的问题 2.是不是只有C/C有文件操作&#xff1f; 其他语…

【数据结构】结构最复杂实现最简单的双向带头循环链表

【数据结构】结构最复杂实现最简单的双向带头循环链表 一、前言二、目标三、实现1、初始化工作2、尾插2.1、图解思路2.2、代码实现 3、尾删3.1、图解思路3.2、代码实现 4、打印链表5、头插5.1、图解思路5.2、代码实现 6、头删6.1、图解思路6.2、代码实现 7、查找8、随机插入8.1…

数据结构与算法基础(青岛大学-王卓)(2)

第二弹火爆来袭中 这波是单链表的内容整理&#xff0c;废话不多说&#xff0c;上小龙虾呀(又到了龙虾季节了&#xff0c;哎&#xff0c;口水直流了~~) beautiful的分割线 文章目录 第二弹火爆来袭中这波是单链表的内容整理&#xff0c;废话不多说&#xff0c;上小龙虾呀(又到了…

【致敬未来的攻城狮计划】— 连续打卡第二十七天:瑞萨RA RA2E1 的 BTN触摸按键

文章目录 由于一些特殊原因&#xff1a; 系列文章链接&#xff1a;&#xff08;其他系列文章&#xff0c;请点击链接&#xff0c;可以跳转到其他系列文章&#xff09;或者参考我的专栏“ 瑞萨MCU ”&#xff0c;里面是 瑞萨RA2E1 系列文章。 24.RA2E1的 DMAC——数据传输 25.R…

DB2_sql_问题

db2新增字段指定顺序 这个是不能做到的&#xff0c;除非把表删除重新创建的&#xff01; 原理是这样子的&#xff1a;当你创建表时系统会记录下你的SEQ-ID,就是字段的顺序号&#xff0c;这个是根据字段先后顺序来生成的&#xff0c;系统默认显示的时候也是根据这个来的&#x…

linux:工具(命令)vi、vim文本编辑器详解。

linux:工具(命令)vi/vim文本编辑器详解。 因此&#xff0c;本质上vi和vim是同种东西&#xff0c;后面也会合起来说&#xff0c;但是使用上会使用vim&#xff0c;因为vim是加强版。 使用形式&#xff1a; 无论退出还是进入都需要去到 “命令模式”。 当使用vi/vim时就会进入“命…

「高性能MySQL」读书笔记(1)- MySQL架构

一、前言 本系列主要是记录阅读「高性能MySQL」期间笔记&#xff0c;记录在日常使用中忽略的知识、模糊的点&#xff0c;主要面对有一定MySQL使用经验的开发者。 本文是针对于MySQL一些基础定义的解释说明&#xff0c;会非常浅显通俗易懂。 二、MySQL的逻辑架构 简单梳理My…

PCL学习九:Registration-配准

参考引用 Point Cloud Library黑马机器人 | PCL-3D点云 1. 点云中的数学 函数求导 对于函数 f ( x ) x 2 f(x)x^2 f(x)x2 其一阶导数也是 x x x 的函数&#xff1a; d f d x 2 x \frac{df}{dx}2x dxdf​2x其二阶导为常数&#xff0c;与 x x x 无关&#xff1a; d 2 f d x…

【漏洞分析】CVE-2021-0920 Linux内核垃圾回收机制中的竞争UAF漏洞

漏洞发现&#xff1a;该漏洞早在2016年被 RedHat 内核开发人员发现并披露&#xff0c;但 Linux 内核社区直到 2021 年重新报告后才对该漏洞进行修补&#xff08;patch&#xff09;。Google的威胁分析小组&#xff08;Threat Analysis Group&#xff09;发现该漏洞在野外被使用&…

shell脚本----基础命令

文章目录 一、sort命令二、uniq命令三、 tr命令四、cut命令 一、sort命令 sort命令以行为单位对文件内容进行排序&#xff0c;也可以根据不同的数据类型来排序&#xff0c;比较的原则是从首字符向后&#xff0c;一次按ASCII码的值进行比较&#xff0c;最后按序输出。 ASCII码…

【P17】JMeter 边界提取器(Boundary Extractor)

文章目录 一、准备工作二、测试计划设计 一、准备工作 慕慕生鲜&#xff1a; http://111.231.103.117/#/login 进入网页后&#xff0c;登录&#xff0c;页面提供了账户和密码 搜索框输入“虾” 右键检查或按F12&#xff0c;打开调试工具&#xff0c;点击搜索 二、测试计划设…

详细版易学版TypeScript - 元组 枚举

一、元组(Tuple) 数组:合并了相同类型的对象 const myArr: Array<number> [1, 2, 3]; 元组(Tuple):合并了不同类型的对象 // 定义元组时就要确定好数据的类型&#xff0c;并一一对应 const tuple: [number, string] [12, "hi"]; // 添加内容时&#xff0c;不…

SQLIST数据库编程

目录 数据库简介 1.常用数据库 2. SQLite基础 3.创建SQLite数据库 虚拟中sqlite3安装 基础SQL语句使用 sqlite3编程 数据库简介 1.常用数据库 大型数据库 &#xff1a;Oracle 中型数据库 &#xff1a;Server是微软开发的数据库产品&#xff0c;主要支持windows平台 小型数据库…