天梯赛省赛选拔赛暨实验室招新赛复盘

题目链接
password:zzuacm2022spring
水平太菜有几题没补出来

A-蜗牛与井(小学数学)

#include 
using namespace std;
const int N = 1e5 + 10;
typedef long long LL;
typedef pair <int, int> PII;
LL h, n, m;
int main ()
{
	ios::sync_with_stdio (false);
	cin.tie (0); cout.tie (0);
	cin >> h >> n >> m;
	LL c = n - m;
	h -= n;
	LL res = 0;
	if (h % c) res = h / c + 1;
	else res = h / c;
	cout << res + 1;
	return 0;
		
} 

B-火力覆盖(贪心)

#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
const int N = 2e5 + 10;
typedef long long LL;
typedef pair <int, int> PII;
int n, m;

int main ()
{
	ios::sync_with_stdio (false);
	cin.tie (0); cout.tie (0);
	vector <int> v;
	cin >> n;
	int last = 1;
	for (int i = 1; i <= n; i ++) 
	{
		if (i * 0.8 > last)
		{
			v.push_back(i - 1);
			last = (int)((i - 1) * 1.2) + 1;
		}
	}
    if (last - 1 < n) v.push_back (n);
	cout << v.size() << "\n";
	for (auto t : v)
		cout << t << " ";
	return 0;	
} 

D-自然溢出(规律题)

#include 
using namespace std;
const int N = 1e5 + 10;
typedef unsigned long long LL;
typedef pair <int, int> PII;
int x[N], y[N];
LL n;

int main ()
{
	ios::sync_with_stdio (false);
	cin.tie (0); cout.tie (0);
	cin >> n;
	if (n >= 66){
		cout << 0;
		return 0;
	}
	LL res = 1;
	for (LL i = 1; i <= n; i ++)
		res = res * i;
	cout << res;
	return 0;
		
} 

E-小y的棋子(线段树)

#include 
using namespace std;
const int N = 1e6 + 10;
typedef long long LL;
typedef pair <int, int> PII;
int n, m;
bitset<145>tr[40010], ans;
int a[N], b[N];
map <int, int> s;
int idx = 0;
int get (int x)
{
	if (s.count(x)) return s[x];
	s[x] = ++ idx;
	return s[x];	
} 

void build (int u, int l, int r)
{
    if (l == r)
    {
        tr[u][a[l]] = 1;
        return ; 
    }
    int mid = (l + r) / 2;
    build (u * 2, l , mid);
    build (u * 2 + 1, mid + 1, r);
    tr[u] = tr[u * 2] | tr[u * 2 + 1];
}
 
void query (int u, int l, int r, int al, int ar)
{
    if (l >= al && r <= ar)
    {
        ans = ans | tr[u];
        return ;
    }
    int mid = (l + r) / 2; //
    if (al <= mid)
        query (u * 2, l, mid, al, ar);
    if (ar > mid)
        query (u * 2 + 1, mid + 1, r, al, ar);
}
 
void modify (int u, int l, int r, int x, int old, int now)
{
    if (l == r)
    {
        tr[u].reset (old);
        tr[u].set (now);
        return ;
    }
    int mid = (l + r) / 2;
    if (x <= mid) 
        modify (u * 2, l, mid, x, old, now);
    else
        modify (u * 2 + 1, mid + 1, r,  x, old, now);
     
    tr[u] = tr[u * 2] | tr[u * 2 + 1];
}
int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i ++)
    {
    	cin >> a[i];
    	a[i] = get (a[i]);
	}

    build(1,1,n);
    while (m --)
    {
    	int op, l, r;
    	cin >> op;
    	if (op == 1)
    	{
    		ans.reset ();
    		cin >> l >> r;
    		query (1, 1, n, l, r);
    		cout << ans.count() << "\n";
		}
        else
        {
            cin >> l;
            modify (1, 1, n, l, a[l], a[l % n + 1]);
            a[l] = a[l % n + 1];
        }
    }
}

F-小y的镜像串(马拉车算法)

#include 
using namespace std;
const int N = 2e5 + 10, mod = 998244353;
char a[N], b[N];
int p[N];
int n;

bool check (char c)
{
	if (c == '0' || c == '1' || c == '8' || c == '#')
		return true;
	return false;
}

void init ()
{
	int k = 0;
	b[k ++] = '$'; b[k ++] = '#';
	for (int i = 0; i < n; i ++)
	{
		b[k ++] = a[i];
		b[k ++] = '#';
	}
	b[k ++] = '^';
	n = k;
} 

void manacher ()
{
	int mr = 0, mid;
	for (int i = 1; i < n; i ++)
	{
		if (i < mr) p[i] = min (mr - i, p[mid * 2 - i]);
		else p[i] = 1;
		while (b[i - p[i]] == b[i + p[i]] && check(b[i - p[i]])) p[i] ++;
		if (i + p[i] > mr)
		{
			mr = i + p[i];
			mid = i;
		}
	}
}

int main ()
{
	cin >> n >> a;
	n = strlen (a);
	init ();
	manacher ();
	int res = 0;
	for (int i = 1; i < n; i ++)
		if (check (b[i]))
			res = (res + p[i] / 2) % mod;
	cout << res;
}

G-飞,比跑快吧(bfs)

#include 
using namespace std;
const int N = 2e5 + 10, mod = 998244353;
int n, m, vf, vd;
int X, Y, Z;

struct node
{
	int x, y, z;
}tar[N];

struct node1
{
	int x, y, low, height;
}wind[N];

int vist[N], visw[N];

queue <node> q;
//判断是否能到达
bool check (int x1, int y1, int z1, int x2, int y2, int z2)
{
	double dis = 1.0 * (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
	dis = sqrt (dis);
	if (1.0 * (z1 - z2) / vd >= dis / vf) return 1;
	return 0;
}
void bfs ()
{
	q.push({X, Y, Z});
	while (q.size())
	{
		node t = q.front(); q.pop();
		int sx = t.x, sy = t.y, sz = t.z;
		for (int i = 1; i <= n; i ++)	//检查目标点 
		{
			if (vist[i]) continue;
			int tx = tar[i].x, ty = tar[i].y, tz = tar[i].z;
			if (check (sx, sy, sz, tx, ty, tz))
			{
				vist[i] = 1;
				q.push({tx, ty, tz});	
			}	
		} 
		for (int i = 1; i <= m; i ++)	//检查风场
		{
			if (visw[i]) continue;
			int wx = wind[i].x, wy = wind[i].y, wz = wind[i].low;
			if (check (sx, sy, sz, wx, wy, wz))
			{
				visw[i] = 1;
				//判断低点添加高点
				q.push ({wx, wy, wind[i].height});
			}		
		} 
	}
}
int main ()
{
	cin >> n >> m >> vf >> vd;
	cin >> X >> Y >> Z;
	for (int i = 1; i <= n; i ++)
		cin >> tar[i].x >> tar[i].y >> tar[i].z;
	for (int i = 1; i <= m; i ++)
		cin >> wind[i].x >> wind[i].y >> wind[i].low >> wind[i].height;
	bfs ();
	int res = 0;
	for (int i = 1; i <= n; i ++)
		if (vist[i])
			res ++;
	cout << res;
	
}

H-旋转矩阵(思维)

#include 
using namespace std;

int a[5][110];
int t[5], tmp[5];

int main ()
{
	int T; cin >> T;
	while (T --)
	{
		int n, m;
		cin >> n >> m;
		for (int i = 1; i <= n; i ++)
			for (int j = 1; j <= m; j ++)
				cin >> a[i][j];
		for (int i = 1; i <= n; i ++)
			t[i] = a[i][1];
		
		for (int j = 2; j <= m; j ++)
		{
			int total = 0, tk = 0;
			for (int k = 0; k < n; k ++)
			{
				int to = 0;
				for (int i = 1; i <= n; i ++)
				{
					tmp[i] = max (t[i], a[(i + k) % n + 1][j]);
					to += tmp[i];
				}
				if (to > total)
				{
					total = to;
					tk = k;
				}
			}
			for (int i = 1; i <= n; i ++)
				t[i] = max (t[i], a[(i + tk) % n + 1][j]);
		}
		int res = 0;
		for (int i = 1; i <= n; i ++)
			res += t[i];
		cout << res << "\n";
	}
}

I-抽卡游戏(数学推导+快速幂)

#include 
using namespace std;
const int N = 1e6 + 10, mod = 998244353;
typedef long long LL;
LL n, m;
LL f[N];
LL ksm (LL a, LL b)
{
    LL res = 1;
    a = a % mod;
    while (b)
    {
        if (b & 1) res = (res * a) % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}
int main ()
{
    cin >> n >> m;
    LL fz = ksm ((n + 1) * n / 2, (LL)mod - 2);
    for (int i = 1; i <= n; i ++)
        f[i] = ksm ((LL)(n * 2 - i + 1) * i / 2 % mod * fz, m);
    for (int i = 1; i <= n; i ++)
        cout << (f[i] - f[i - 1] + mod) % mod << "\n";
    return 0; 
}

K-回文时刻(模拟)

#include 
using namespace std;
const int N = 1e5 + 10;
typedef long long LL;
typedef pair <int, int> PII;
int x[N], y[N];
int h, m ,s, t;
int flag = 0;
int a[6] = {0, 11, 22, 33, 44, 55};

bool check (int hh)
{
	int ss = hh % 10 * 10 + hh / 10;
	if (ss >= 60) return false;			//秒数不能大于60
	
	for (int i = 0; i < 6; i ++)
	{
	//	cout << a[i] << " " << endl;
		if (hh == h)
		{
			//cout << "a" << i << "=" << a[i] << "m = " << m << endl;
			if (a[i] < m) continue;
			else if (a[i] == m) 
			{
				if (ss <= s) continue;
				else 
				{
					//输出答案
					printf ("%02d:%02d:%02d", hh, a[i], ss); 
					return true; 
				}	
			}
			else
			{
				printf ("%02d:%02d:%02d", hh, a[i], ss); 
				return true; 
			}	
		}
		else
		{
			//输出答案 
			printf ("%02d:%02d:%02d", hh, a[i], ss); 
			return true;	
		}	
	} 
	return false;
}
int main ()
{
	ios::sync_with_stdio (false);
	cin.tie (0); cout.tie (0);
	scanf ("%d:%d:%d", &h, &m, &s);
	
	//	check (12);
	for (int i = h; i <= 23; i ++)
	{
		if (check (i))
			return 0;
	}
	cout << "00:00:00";
	return 0;
		
} 

L-hs爱矩阵(签到)

#include 
using namespace std;
const int N = 1e5 + 10;
typedef long long LL;
typedef pair <int, int> PII;
LL h, n, m;
int x[N], y[N];

int main ()
{
	ios::sync_with_stdio (false);
	cin.tie (0); cout.tie (0);
	int resx, resy;
	int x1, y1, x2, y2, x3, y3;
	cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
	if (x1 == x2) resx = x3;
	if (x2 == x3) resx = x1;
	if (x1 == x3) resx = x2;
	if (y1 == y3) resy = y2;
	if (y1 == y2) resy = y3;
	if (y2 == y3) resy = y1;
	cout << resx << " " << resy;
	
	return 0;
		
} 

你可能感兴趣的:(算法,c++)