五一欢乐赛!题解

22 篇文章 0 订阅
20 篇文章 0 订阅

前言

五一欢乐赛有点一言难尽, 这次本来想的给大火减减压放了很多区域赛和省赛的签到题(还有一些是写过的题), 没想到打的并不是很理想, 还用了分数值想减少一些差距, 结果看起来好像让差距更大了, 尴尬
虽然不是很想打击各位, 但是省赛/区域赛的签到题都写成这样, 明年就等着打铁吧
早点退役准备考研或者学项目也许是个出路?

A题 Frozen Scoreboard

https://codeforces.com/gym/104076/problem/D
济南站的中等题
看起来就很ex的模拟题, 别人推荐的我自己还没写, 写了再更新题解

B题 Math master

https://codeforces.com/gym/103447/problem/D
https://codeforces.com/gym/103447/problem/D
哈尔滨省赛的中等题

题意

给你一个分数, 让你化简, 化简的方式是分子分母各减去一个相同数字, 在保证分数值不变的同时将其化为最简

题解

https://blog.csdn.net/Tanya_xiaomai/article/details/130223013
这个我写过题解

C题 Fibonacci

在这里插入图片描述
上海区域赛的签到题
https://codeforces.com/gym/102900/problem/G

题意

题目讲的很清楚, 公式都给出来了没什么好说的

题解

说打表是有原因的, 这题我就是打表出的
给出打表代码然后自己推规律

void solve()
{
	n=t;
	vector<ll>fi(n+3);
	fi[1]=1;
	fi[2]=1;
    rep(i,3,n) fi[i]=fi[i-1]+fi[i-2];
	ans=0;
	rep(i,1,n)
		rep(j,i+1,n)
		{
			if(fi[i]*fi[j]%2) continue;
			ans++;
		}
	cout<<ans<<' ';
    return;
}

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>m;
	for(t=1;t<=m;t++)
        solve();
    return 0;
}

打出来30的表是这样的
0 0 2 3 4 9 11 13 21 24 27 38 42 46 60 65 70 87 93 99 119 126 133 156 164 172 198 207 216
给这个序列表上下标再看看

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21  22  23  24  25  26  27  28  29  30
0 0 2 3 4 9 11 13 21 24 27 38 42 46 60 65 70 87 93 99 119 126 133 156 164 172 198 207 216

将这个序列的差值算出来
得到
0 2 1 1 5 2 2 8 3 3 11 4 4…
加粗的序列每隔开2个就+3, 其他元素随着加粗序列增加一次就+1
别想着我给你全部推导出来, 自己动脑把公式推出来
推不出来再看代码
要学会打表找规律------lk学长

代码

#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
	ll n;cin>>n;
    ll num=n/3;
	num--;
	ll ans=(num+1)*num;
	ans+=(num+1)*(n%3);
	ll cc=n/3;
	ans+=(4+3*(cc-1))*cc/2;
	cout<<ans<<endl;
	return 0;
}

D题 Mine Sweeper II

在这里插入图片描述
这题也是上海站的签到题
https://codeforces.com/gym/102900/problem/B

题意

就是扫雷的规则, 然后给你两个图, 让上面的数字和 和 下面的数字和相同

题解

作为一个acmer要学会从时空复杂度来考虑解法, 这题n和m都是1000, 只给了一秒钟, 那么dfs和bfs铁定超时, 再根据榜单上过的人这么多区域赛的时候过的人挺多, 就能知道这题肯定是脑筋急转弯猜结论
看到可以修改 n m 2 \frac {nm}{2} 2nm
先想整体, 假如上下不同的雷在 n m 2 \frac {nm}{2} 2nm以内, 直接改成上图就行
如果不同的雷大于 n m 2 \frac {nm}{2} 2nm, 考虑一下将有雷的地方全部置换为没雷的地方模拟自己猜的结论结论是有雷和没雷的地区置换一下, 数字和是一致的, 置换后可以发现修改数在 n m 2 \frac {nm}{2} 2nm以内

代码

/*
⣿⣿⣿⣿⣿⣿⡷⣯⢿⣿⣷⣻⢯⣿⡽⣻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⠸⣿⣿⣆⠹⣿⣿⢾⣟⣯⣿⣿⣿⣿⣿⣿⣽⣻⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣻⣽⡿⣿⣎⠙⣿⣞⣷⡌⢻⣟⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣿⣿⡄⠹⣿⣿⡆⠻⣿⣟⣯⡿⣽⡿⣿⣿⣿⣿⣽⡷⣯⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣟⣷⣿⣿⣿⡀⠹⣟⣾⣟⣆⠹⣯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢠⡘⣿⣿⡄⠉⢿⣿⣽⡷⣿⣻⣿⣿⣿⣿⡝⣷⣯⢿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣯⢿⣾⢿⣿⡄⢄⠘⢿⣞⡿⣧⡈⢷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸⣧⠘⣿⣷⠈⣦⠙⢿⣽⣷⣻⣽⣿⣿⣿⣿⣌⢿⣯⢿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣟⣯⣿⢿⣿⡆⢸⡷⡈⢻⡽⣷⡷⡄⠻⣽⣿⣿⡿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣏⢰⣯⢷⠈⣿⡆⢹⢷⡌⠻⡾⢋⣱⣯⣿⣿⣿⣿⡆⢻⡿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⡎⣿⢾⡿⣿⡆⢸⣽⢻⣄⠹⣷⣟⣿⣄⠹⣟⣿⣿⣟⣿⣿⣿⣿⣿⣿⣽⣿⣿⣿⡇⢸⣯⣟⣧⠘⣷⠈⡯⠛⢀⡐⢾⣟⣷⣻⣿⣿⣿⡿⡌⢿⣻⣿⣿
⣿⣿⣿⣿⣿⣿⣧⢸⡿⣟⣿⡇⢸⣯⣟⣮⢧⡈⢿⣞⡿⣦⠘⠏⣹⣿⣽⢿⣿⣿⣿⣿⣯⣿⣿⣿⡇⢸⣿⣿⣾⡆⠹⢀⣠⣾⣟⣷⡈⢿⣞⣯⢿⣿⣿⣿⢷⠘⣯⣿⣿
⣿⣿⣿⣿⣿⣿⣿⡈⣿⢿⣽⡇⠘⠛⠛⠛⠓⠓⠈⠛⠛⠟⠇⢀⢿⣻⣿⣯⢿⣿⣿⣿⣷⢿⣿⣿⠁⣾⣿⣿⣿⣧⡄⠇⣹⣿⣾⣯⣿⡄⠻⣽⣯⢿⣻⣿⣿⡇⢹⣾⣿
⣿⣿⣿⣿⣿⣿⣿⡇⢹⣿⡽⡇⢸⣿⣿⣿⣿⣿⣞⣆⠰⣶⣶⡄⢀⢻⡿⣯⣿⡽⣿⣿⣿⢯⣟⡿⢀⣿⣿⣿⣿⣿⣧⠐⣸⣿⣿⣷⣿⣿⣆⠹⣯⣿⣻⣿⣿⣿⢀⣿⢿
⣿⣿⣿⣿⣿⣿⣿⣿⠘⣯⡿⡇⢸⣿⣿⣿⣿⣿⣿⣿⣧⡈⢿⣳⠘⡄⠻⣿⢾⣽⣟⡿⣿⢯⣿⡇⢸⣿⣿⣿⣿⣿⣿⡀⢾⣿⣿⣿⣿⣿⣿⣆⠹⣾⣷⣻⣿⡿⡇⢸⣿
⣿⣿⣿⣿⣿⣿⣿⣿⡇⢹⣿⠇⢸⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⠻⡇⢹⣆⠹⣟⣾⣽⣻⣟⣿⣽⠁⣾⣿⣿⣿⣿⣿⣿⣇⣿⣿⠿⠛⠛⠉⠙⠋⢀⠁⢘⣯⣿⣿⣧⠘⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⡈⣿⡃⢼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⡙⠌⣿⣆⠘⣿⣞⡿⣞⡿⡞⢠⣿⣿⣿⣿⣿⡿⠛⠉⠁⢀⣀⣠⣤⣤⣶⣶⣶⡆⢻⣽⣞⡿⣷⠈⣿
⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⠘⠁⠉⠉⠉⠉⠉⠉⠉⠉⠉⠙⠛⠛⢿⣄⢻⣿⣧⠘⢯⣟⡿⣽⠁⣾⣿⣿⣿⣿⣿⡃⢀⢀⠘⠛⠿⢿⣻⣟⣯⣽⣻⣵⡀⢿⣯⣟⣿⢀⣿
⣿⣿⣿⣟⣿⣿⣿⣿⣶⣶⡆⢀⣿⣾⣿⣾⣷⣿⣶⠿⠚⠉⢀⢀⣤⣿⣷⣿⣿⣷⡈⢿⣻⢃⣼⣿⣿⣿⣿⣻⣿⣿⣿⡶⣦⣤⣄⣀⡀⠉⠛⠛⠷⣯⣳⠈⣾⡽⣾⢀⣿
⣿⢿⣿⣿⣻⣿⣿⣿⣿⣿⡿⠐⣿⣿⣿⣿⠿⠋⠁⢀⢀⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣌⣥⣾⡿⣿⣿⣷⣿⣿⢿⣷⣿⣿⣟⣾⣽⣳⢯⣟⣶⣦⣤⡾⣟⣦⠘⣿⢾⡁⢺
⣿⣻⣿⣿⡷⣿⣿⣿⣿⣿⡗⣦⠸⡿⠋⠁⢀⢀⣠⣴⢿⣿⣽⣻⢽⣾⣟⣷⣿⣟⣿⣿⣿⣳⠿⣵⣧⣼⣿⣿⣿⣿⣿⣾⣿⣿⣿⣿⣿⣽⣳⣯⣿⣿⣿⣽⢀⢷⣻⠄⠘
⣿⢷⣻⣿⣿⣷⣻⣿⣿⣿⡷⠛⣁⢀⣀⣤⣶⣿⣛⡿⣿⣮⣽⡻⣿⣮⣽⣻⢯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⢀⢸⣿⢀⡆
⠸⣟⣯⣿⣿⣷⢿⣽⣿⣿⣷⣿⣷⣆⠹⣿⣶⣯⠿⣿⣶⣟⣻⢿⣷⣽⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢀⣯⣟⢀⡇
⣇⠹⣟⣾⣻⣿⣿⢾⡽⣿⣿⣿⣿⣿⣆⢹⣶⣿⣻⣷⣯⣟⣿⣿⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⢀⡿⡇⢸⡇
⣿⣆⠹⣷⡻⣽⣿⣯⢿⣽⣻⣿⣿⣿⣿⣆⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⢸⣿⠇⣼⡇
⡙⠾⣆⠹⣿⣦⠛⣿⢯⣷⢿⡽⣿⣿⣿⣿⣆⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⠎⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⢀⣿⣾⣣⡿⡇
⣿⣷⡌⢦⠙⣿⣿⣌⠻⣽⢯⣿⣽⣻⣿⣿⣿⣧⠩⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡏⢰⢣⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⢀⢀⢿⣞⣷⢿⡇
⣿⣽⣆⠹⣧⠘⣿⣿⡷⣌⠙⢷⣯⡷⣟⣿⣿⣿⣷⡀⡹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣈⠃⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⢀⣴⡧⢀⠸⣿⡽⣿⢀
⢻⣽⣿⡄⢻⣷⡈⢿⣿⣿⢧⢀⠙⢿⣻⡾⣽⣻⣿⣿⣄⠌⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⢁⣰⣾⣟⡿⢀⡄⢿⣟⣿⢀
⡄⢿⣿⣷⢀⠹⣟⣆⠻⣿⣿⣆⢀⣀⠉⠻⣿⡽⣯⣿⣿⣷⣈⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⢀⣠⠘⣯⣷⣿⡟⢀⢆⠸⣿⡟⢸
⣷⡈⢿⣿⣇⢱⡘⢿⣷⣬⣙⠿⣧⠘⣆⢀⠈⠻⣷⣟⣾⢿⣿⣆⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⣠⡞⢡⣿⢀⣿⣿⣿⠇⡄⢸⡄⢻⡇⣼
⣿⣷⡈⢿⣿⡆⢣⡀⠙⢾⣟⣿⣿⣷⡈⠂⠘⣦⡈⠿⣯⣿⢾⣿⣆⠙⠻⠿⠿⠿⠿⡿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⢋⣠⣾⡟⢠⣿⣿⢀⣿⣿⡟⢠⣿⢈⣧⠘⢠⣿
⣿⣿⣿⣄⠻⣿⡄⢳⡄⢆⡙⠾⣽⣿⣿⣆⡀⢹⡷⣄⠙⢿⣿⡾⣿⣆⢀⡀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⣀⣠⣴⡿⣯⠏⣠⣿⣿⡏⢸⣿⡿⢁⣿⣿⢀⣿⠆⢸⣿
⣿⣿⣿⣿⣦⡙⣿⣆⢻⡌⢿⣶⢤⣉⣙⣿⣷⡀⠙⠽⠷⠄⠹⣿⣟⣿⣆⢙⣋⣤⣤⣤⣄⣀⢀⢀⢀⢀⣾⣿⣟⡷⣯⡿⢃⣼⣿⣿⣿⠇⣼⡟⣡⣿⣿⣿⢀⡿⢠⠈⣿
⣿⣿⣿⣿⣿⣷⣮⣿⣿⣿⡌⠁⢤⣤⣤⣤⣬⣭⣴⣶⣶⣶⣆⠈⢻⣿⣿⣆⢻⣿⣿⣿⣿⣿⣿⣷⣶⣤⣌⣉⡘⠛⠻⠶⣿⣿⣿⣿⡟⣰⣫⣴⣿⣿⣿⣿⠄⣷⣿⣿⣿
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstring>
#include <string>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define ll long long
#define endl "\n"
#define S second
#define F first
#define ln cout<<endl;
#define rep(i, a, b) for (ll i = (a); i <= (b); i++)
#define repr(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (b); i >= (a); i--)
#define rrepr(i, a, b) for (ll i = (b); i > (a); i--)
#define mem(a) memset((a),0,sizeof (a));
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define debug cout<<"here!"<<endl;

ll cnt,n,m,t,ans,ant;
const int N=2e5+10;
const int INF=0x3f3f3f3f;
const ll llINF=0x3f3f3f3f3f3f3f3f;
ll arr[N];
string str;

inline ll read()
{
    char c = getchar();int x = 0,s = 1;
    while(c < '0' || c > '9') {if(c == '-') s = -1;c = getchar();}//是符号
    while(c >= '0' && c <= '9') {x = x*10 + c -'0';c = getchar();}//是数字
    return x*s;
}


void solve()
{
	cin>>n>>m;
	ans=(n*m)>>1;
	string s1[1010];
	string s2[1010];
	rep(i,1,n) cin>>s1[i];
	rep(i,1,n) cin>>s2[i];
	rep(i,1,n)
		repr(j,0,m)
		{
			if(s1[i][j]!=s2[i][j]) ans--;
			if(ans<0) break;
		}
	if(ans>=0)
		rep(i,1,n) cout<<s1[i]<<endl;
	else 
	{
		rep(i,1,n)
		{
			repr(j,0,m) 
				if(s1[i][j]=='.') cout<<'X';
				else cout<<'.';
			ln
		}	
	}
    return;
}

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //所有输入用cin
    //所有输出用cout
	
        solve();
    return 0;
}

E题 Takeaway

https://codeforces.com/gym/103145/problem/I
在这里插入图片描述
东北省赛的签到题
并不是很能理解这题还能wa的学弟
属于读懂题意就能ac的模拟

不给题解也不给代码, 自己想

F题 Easy Math Problem

https://codeforces.com/gym/103145/problem/E
在这里插入图片描述
也是个签到题, 可惜没什么人去写

题意

给出一个数字p, 可以乘上任意一个数字a得到b=a*p, 然后输出n个数, 每个数都是b的因子, 这n个数字之和==b

题解

1= 1 3 \frac {1}{3} 31+ 1 2 \frac {1}{2} 21+ 1 6 \frac {1}{6} 61

代码

#include<iostream>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		unsigned long long p;
		cin>>p;
		cout<<6*p<<" 3\n";
		cout<<p<<" "<<2*p<<" "<<3*p<<endl;
	}
}

G题 City

https://codeforces.com/gym/103145/problem/K
在这里插入图片描述
中等题, 感觉学弟们稍微想一想还是能做的
这题不是最小生成树, 但是却需要并查集+排序
在这里插入图片描述
懒了, 有学弟不会的再来问, 虽然很推荐补这题, 但是感觉应该没多少学弟会来补, 不会再来问我

代码

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=3e5+5;
ll t,n,m,q,f[N],cnt[N];
struct E
{
	ll u,v, k;
}ed[N];
ll find(ll x)
{
	if(f[x]==x) return x;
	return f[x]=find(f[x]);
}
bool cmp(E a,E b)
{
	return a.k<b.k;
}
void solve()
{
	vector<ll> ans(N);map<ll,ll> mp;
    cin>>n>>m>>q;vector<ll> b;
	for(int i=1;i<=n;i++) f[i]=i,cnt[i]=1;
	for(int i=1;i<=m;i++)
	{
		scanf("%lld%lld%lld",&ed[i].u,&ed[i].v,&ed[i].k);
	}
	sort(ed+1,ed+m+1,cmp);
	ll num=0;
	for(int i=m;i>=1;i--)
	{
		ll fu=find(ed[i].u),fv=find(ed[i].v);
		if(fu!=fv)
		{
			f[fu]=fv;
			num-=cnt[fu]*(cnt[fu]-1),num-=cnt[fv]*(cnt[fv]-1);
		    cnt[fv]=cnt[fu]+cnt[fv];
			num+=cnt[fv]*(cnt[fv]-1);
		    
		}
	   mp[ed[i].k]=max(mp[ed[i].k],num);
	}
	
	ll cc=0;
	for(auto & tt:mp)
	 b.push_back(tt.first);
    
	while(q--)
	{
		ll op;scanf("%lld",&op);
		auto pos=lower_bound(b.begin(),b.end(),op);
		if(pos==b.end())
			cout<<"0\n";
		else 
		    cout<<mp[*pos]/2<<endl;
	}
	
}
int main()
{
   cin>>t;
   while(t--)
   {
	   solve();
   }
}

H题 Matrix

https://codeforces.com/gym/103145/problem/A
在这里插入图片描述
中等题, 很好的一个组合数学题

题解

在这里插入图片描述

代码

/*
⣿⣿⣿⣿⣿⣿⡷⣯⢿⣿⣷⣻⢯⣿⡽⣻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⠸⣿⣿⣆⠹⣿⣿⢾⣟⣯⣿⣿⣿⣿⣿⣿⣽⣻⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣻⣽⡿⣿⣎⠙⣿⣞⣷⡌⢻⣟⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣿⣿⡄⠹⣿⣿⡆⠻⣿⣟⣯⡿⣽⡿⣿⣿⣿⣿⣽⡷⣯⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣟⣷⣿⣿⣿⡀⠹⣟⣾⣟⣆⠹⣯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢠⡘⣿⣿⡄⠉⢿⣿⣽⡷⣿⣻⣿⣿⣿⣿⡝⣷⣯⢿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣯⢿⣾⢿⣿⡄⢄⠘⢿⣞⡿⣧⡈⢷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸⣧⠘⣿⣷⠈⣦⠙⢿⣽⣷⣻⣽⣿⣿⣿⣿⣌⢿⣯⢿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣟⣯⣿⢿⣿⡆⢸⡷⡈⢻⡽⣷⡷⡄⠻⣽⣿⣿⡿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣏⢰⣯⢷⠈⣿⡆⢹⢷⡌⠻⡾⢋⣱⣯⣿⣿⣿⣿⡆⢻⡿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⡎⣿⢾⡿⣿⡆⢸⣽⢻⣄⠹⣷⣟⣿⣄⠹⣟⣿⣿⣟⣿⣿⣿⣿⣿⣿⣽⣿⣿⣿⡇⢸⣯⣟⣧⠘⣷⠈⡯⠛⢀⡐⢾⣟⣷⣻⣿⣿⣿⡿⡌⢿⣻⣿⣿
⣿⣿⣿⣿⣿⣿⣧⢸⡿⣟⣿⡇⢸⣯⣟⣮⢧⡈⢿⣞⡿⣦⠘⠏⣹⣿⣽⢿⣿⣿⣿⣿⣯⣿⣿⣿⡇⢸⣿⣿⣾⡆⠹⢀⣠⣾⣟⣷⡈⢿⣞⣯⢿⣿⣿⣿⢷⠘⣯⣿⣿
⣿⣿⣿⣿⣿⣿⣿⡈⣿⢿⣽⡇⠘⠛⠛⠛⠓⠓⠈⠛⠛⠟⠇⢀⢿⣻⣿⣯⢿⣿⣿⣿⣷⢿⣿⣿⠁⣾⣿⣿⣿⣧⡄⠇⣹⣿⣾⣯⣿⡄⠻⣽⣯⢿⣻⣿⣿⡇⢹⣾⣿
⣿⣿⣿⣿⣿⣿⣿⡇⢹⣿⡽⡇⢸⣿⣿⣿⣿⣿⣞⣆⠰⣶⣶⡄⢀⢻⡿⣯⣿⡽⣿⣿⣿⢯⣟⡿⢀⣿⣿⣿⣿⣿⣧⠐⣸⣿⣿⣷⣿⣿⣆⠹⣯⣿⣻⣿⣿⣿⢀⣿⢿
⣿⣿⣿⣿⣿⣿⣿⣿⠘⣯⡿⡇⢸⣿⣿⣿⣿⣿⣿⣿⣧⡈⢿⣳⠘⡄⠻⣿⢾⣽⣟⡿⣿⢯⣿⡇⢸⣿⣿⣿⣿⣿⣿⡀⢾⣿⣿⣿⣿⣿⣿⣆⠹⣾⣷⣻⣿⡿⡇⢸⣿
⣿⣿⣿⣿⣿⣿⣿⣿⡇⢹⣿⠇⢸⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⠻⡇⢹⣆⠹⣟⣾⣽⣻⣟⣿⣽⠁⣾⣿⣿⣿⣿⣿⣿⣇⣿⣿⠿⠛⠛⠉⠙⠋⢀⠁⢘⣯⣿⣿⣧⠘⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⡈⣿⡃⢼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⡙⠌⣿⣆⠘⣿⣞⡿⣞⡿⡞⢠⣿⣿⣿⣿⣿⡿⠛⠉⠁⢀⣀⣠⣤⣤⣶⣶⣶⡆⢻⣽⣞⡿⣷⠈⣿
⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⠘⠁⠉⠉⠉⠉⠉⠉⠉⠉⠉⠙⠛⠛⢿⣄⢻⣿⣧⠘⢯⣟⡿⣽⠁⣾⣿⣿⣿⣿⣿⡃⢀⢀⠘⠛⠿⢿⣻⣟⣯⣽⣻⣵⡀⢿⣯⣟⣿⢀⣿
⣿⣿⣿⣟⣿⣿⣿⣿⣶⣶⡆⢀⣿⣾⣿⣾⣷⣿⣶⠿⠚⠉⢀⢀⣤⣿⣷⣿⣿⣷⡈⢿⣻⢃⣼⣿⣿⣿⣿⣻⣿⣿⣿⡶⣦⣤⣄⣀⡀⠉⠛⠛⠷⣯⣳⠈⣾⡽⣾⢀⣿
⣿⢿⣿⣿⣻⣿⣿⣿⣿⣿⡿⠐⣿⣿⣿⣿⠿⠋⠁⢀⢀⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣌⣥⣾⡿⣿⣿⣷⣿⣿⢿⣷⣿⣿⣟⣾⣽⣳⢯⣟⣶⣦⣤⡾⣟⣦⠘⣿⢾⡁⢺
⣿⣻⣿⣿⡷⣿⣿⣿⣿⣿⡗⣦⠸⡿⠋⠁⢀⢀⣠⣴⢿⣿⣽⣻⢽⣾⣟⣷⣿⣟⣿⣿⣿⣳⠿⣵⣧⣼⣿⣿⣿⣿⣿⣾⣿⣿⣿⣿⣿⣽⣳⣯⣿⣿⣿⣽⢀⢷⣻⠄⠘
⣿⢷⣻⣿⣿⣷⣻⣿⣿⣿⡷⠛⣁⢀⣀⣤⣶⣿⣛⡿⣿⣮⣽⡻⣿⣮⣽⣻⢯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⢀⢸⣿⢀⡆
⠸⣟⣯⣿⣿⣷⢿⣽⣿⣿⣷⣿⣷⣆⠹⣿⣶⣯⠿⣿⣶⣟⣻⢿⣷⣽⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢀⣯⣟⢀⡇
⣇⠹⣟⣾⣻⣿⣿⢾⡽⣿⣿⣿⣿⣿⣆⢹⣶⣿⣻⣷⣯⣟⣿⣿⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⢀⡿⡇⢸⡇
⣿⣆⠹⣷⡻⣽⣿⣯⢿⣽⣻⣿⣿⣿⣿⣆⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⢸⣿⠇⣼⡇
⡙⠾⣆⠹⣿⣦⠛⣿⢯⣷⢿⡽⣿⣿⣿⣿⣆⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⠎⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⢀⣿⣾⣣⡿⡇
⣿⣷⡌⢦⠙⣿⣿⣌⠻⣽⢯⣿⣽⣻⣿⣿⣿⣧⠩⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡏⢰⢣⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⢀⢀⢿⣞⣷⢿⡇
⣿⣽⣆⠹⣧⠘⣿⣿⡷⣌⠙⢷⣯⡷⣟⣿⣿⣿⣷⡀⡹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣈⠃⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⢀⣴⡧⢀⠸⣿⡽⣿⢀
⢻⣽⣿⡄⢻⣷⡈⢿⣿⣿⢧⢀⠙⢿⣻⡾⣽⣻⣿⣿⣄⠌⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⢁⣰⣾⣟⡿⢀⡄⢿⣟⣿⢀
⡄⢿⣿⣷⢀⠹⣟⣆⠻⣿⣿⣆⢀⣀⠉⠻⣿⡽⣯⣿⣿⣷⣈⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⢀⣠⠘⣯⣷⣿⡟⢀⢆⠸⣿⡟⢸
⣷⡈⢿⣿⣇⢱⡘⢿⣷⣬⣙⠿⣧⠘⣆⢀⠈⠻⣷⣟⣾⢿⣿⣆⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⣠⡞⢡⣿⢀⣿⣿⣿⠇⡄⢸⡄⢻⡇⣼
⣿⣷⡈⢿⣿⡆⢣⡀⠙⢾⣟⣿⣿⣷⡈⠂⠘⣦⡈⠿⣯⣿⢾⣿⣆⠙⠻⠿⠿⠿⠿⡿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⢋⣠⣾⡟⢠⣿⣿⢀⣿⣿⡟⢠⣿⢈⣧⠘⢠⣿
⣿⣿⣿⣄⠻⣿⡄⢳⡄⢆⡙⠾⣽⣿⣿⣆⡀⢹⡷⣄⠙⢿⣿⡾⣿⣆⢀⡀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⣀⣠⣴⡿⣯⠏⣠⣿⣿⡏⢸⣿⡿⢁⣿⣿⢀⣿⠆⢸⣿
⣿⣿⣿⣿⣦⡙⣿⣆⢻⡌⢿⣶⢤⣉⣙⣿⣷⡀⠙⠽⠷⠄⠹⣿⣟⣿⣆⢙⣋⣤⣤⣤⣄⣀⢀⢀⢀⢀⣾⣿⣟⡷⣯⡿⢃⣼⣿⣿⣿⠇⣼⡟⣡⣿⣿⣿⢀⡿⢠⠈⣿
⣿⣿⣿⣿⣿⣷⣮⣿⣿⣿⡌⠁⢤⣤⣤⣤⣬⣭⣴⣶⣶⣶⣆⠈⢻⣿⣿⣆⢻⣿⣿⣿⣿⣿⣿⣷⣶⣤⣌⣉⡘⠛⠻⠶⣿⣿⣿⣿⡟⣰⣫⣴⣿⣿⣿⣿⠄⣷⣿⣿⣿
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstring>
#include <string>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define ll long long
#define endl "\n"
#define S second
#define F first
#define ln cout<<endl;
#define rep(i, a, b) for (ll i = (a); i <= (b); i++)
#define repr(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (b); i >= (a); i--)
#define rrepr(i, a, b) for (ll i = (b); i > (a); i--)
#define mem(a) memset((a),0,sizeof (a));
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define debug cout<<"here!"<<endl;

ll cnt,n,m,t,ans,ant;
const int N=3e7+10;
//ll arr[N];
string str;
ll infact[N],fact[N];
const int p=998244353;

ll qmi(ll a,ll k)
{
	ll sum=1;
	while(k)
	{
		if(k&1) sum=(ll)sum*a%p;
		a=(ll)a*a%p;
		k>>=1;
	}
	return sum;
}

ll q(ll x)
{
	return x%p;
}


ll C(ll a,ll b)
{
	if(b>a) return 0;
	ll sum=0;
	sum=fact[a]*infact[b]%p*infact[a-b]%p;
	return sum;
}

void solve()
{
	ans=0;
	cin>>n;
	rep(i,1,n) ans=q(ans+q(n*q(q(C(n*n-i,n-1))*q(fact[n]*fact[n*n-n]))));
	cout<<ans%p<<endl;
//	cout<<t<<endl;
    return;
}

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	
	fact[0]=infact[0]=1;
	rep(i,1,25000005) 
	{
		fact[i]=fact[i-1]*i%p;
//		infact[i]=infact[i-1]*qmi(i,p-2)%p;		
	}
	infact[25000005]=qmi(fact[25000005],p-2);
	rrep(i,1,25000004)
	{
		infact[i]=infact[i+1]*(i+1)%p;
	}
	cin>>t;
    while(t--)
        solve();
    return 0;
}

I题 越狱

https://loj.ac/p/10196
组合数学入门题
高中数学题

中文题面就不说题意了

题解

先看不发生越狱的情况:
第一个犯人有m个选择, 第二个犯人有m-1种选择, 第三种犯人也有m-1种选择
也就是说n-1个犯人有m-1种选择, 一种犯人有m种选择, 不发生越狱的情况应该有 ( m − 1 ) ( n − 1 ) ∗ m (m-1)^{(n-1)}*m (m1)(n1)m
显而易见一共有 m n m^n mn种情况
所以答案应该是 m n − ( m − 1 ) ( n − 1 ) ∗ m m^n-(m-1)^{(n-1)}*m mn(m1)(n1)m
还需要注意两个点
快速幂
m n m^n mn%mod之后可能会小于 ( m − 1 ) ( n − 1 ) ∗ m (m-1)^{(n-1)}*m (m1)(n1)m%mod
所以两者相减后再加上mod取模避免出现负数的情况

代码

const int p=100003;

ll f(ll x)
{
    return x%p;
}

ll ksm(ll x,ll y)
{
    ll sum=1;
    while(y)
    {
        if(y&1) sum=sum*x%p;
        x=x*x%p;
        y>>=1;
    }
    return sum;
}

void solve()
{
    cin>>m>>n;
    cout<<f(ksm(m,n)-f(m*ksm(m-1,n-1))+p);
    return;
}

J题 Station of Fate

https://codeforces.com/gym/104053/problem/L
在这里插入图片描述
签到题
广州站的签到题
高中组合数学

题意

n个人站m个队伍, 问有多少种站法

题解

插板法
在这里插入图片描述
On模拟都行, 这题n是1e5
A n n ∗ C m − 1 n − 1 A_{n}^{n}*C_{m-1}^{n-1} AnnCm1n1
在这里插入图片描述

代码

#include<bits/stdc++.h>
using namespace std;
int main(){
	int t;
	cin>>t;
	for(int i=0;i<t;i++){
		long long a,b;
		cin>>a>>b;
		long long num=1;
		for(long long j=a;j>a-b;j--)
		num=num*j%998244353;
		for(long long j=b;j<a;j++)
		num=num*j%998244353;
		cout<<num%998244353<<endl;
	}
	return 0;
}

K题 太难了不会

L题 Catch That Cow

这题我出锅了, 本来是POJ的题, 没有多组输入, 因为poj提交的问题有的同学交上去一直ce, 我就给换成了hdu的题, 然而hdu的题面没说多组输入, 然后我csdn找了个题解交上去ac了以为题没问题就没管了, 赛后才发现这bHDU的多组输入没提前说被阴了焯

题解

没有题解, 写过的题还不会抓出去枪毙

M题 AtCoder abc171_c

我寻思这题也是出过的题怎么这么少人过呢
看来得严查补题情况了
这题就是一个进制转换abc的C题难度, 水的不行了
abc的C题就相当于div4的B~C的难度吧
这题还要看题解真的自我反思吧, 是比赛策略失败还是平时在摸鱼

N题 Let Them Eat Cake

在这里插入图片描述
https://codeforces.com/gym/104065/problem/G
我承认这题我wa了一发wa8
但这题真的是会vector随便写
我提倡你们都多使用STL免得到时候写模拟的时候, STL用时方恨少
STL中一两句可以很容易做出一些比结构体和数组要写好几十行的代码
多看看jls的代码(或者其他巨巨的代码), 可以发现人家大多数都是熟练使用STL, 只有在卡时空的一些题中会使用数组

题意

感觉翻译说的挺清楚的
在这里插入图片描述

题解

在这里插入图片描述

暴力删掉较小的那个数字删一轮答案+1, 删剩下最后2个数字就退出

代码

#define repr(i, a, b) for (ll i = (a); i < (b); i++)
void solve()
{
    cin>>n;
    vector<ll>f(n),q(f);
    repr(i,0,n) cin>>f[i];
    while(f.size()>1)
    {
        q=f;
        f.clear();
        repr(i,0,q.size())
        {
            if(i==0&&q[i]>q[i+1]) f.push_back(q[i]);
            else if(i==q.size()-1&&q[i]>q[i-1]) f.push_back(q[i]);
            else if(q[i]>q[i-1]&&q[i]>q[i+1]) f.push_back(q[i]);
        }
        ans++;
    }
    cout<<ans<<endl;
    return;
}

O题 A. Goodbye, Ziyin!

这题编译器好像有问题, 得换成G++17才能ac, 不然的话好像会一直t
https://codeforces.com/gym/103428/problem/A
在这里插入图片描述
威海站签到题

题意

给出一棵树, 问你这棵树能有几个节点能够作为二叉树的根节点

题解

连图都不用存的

首先我们要知道二叉树是个什么结构
二叉树的根节点有两个儿子, 也就是度为2
二叉树的其他节点有一个父亲和0~1个儿子, 也就是度为1~3

由于题目中给的是边, 所以我们只要统计每个节点的出现次数即为度
只有度为1~2的节点就能作为根节点, 当出现度>3的节点时, 不符合二叉树的规范, 答案为0

代码

#define repr(i, a, b) for (ll i = (a); i < (b); i++)
void solve()
{
    cin>>n;
    map<ll,ll>mp;
    repr(i,1,n)
    {
        ll u,v;
        cin>>u>>v;
        mp[u]++;
        mp[v]++;
    }
 
    for(auto i:mp)
    {
        ll v=i.second;
        if(v>3) 
        {
            cout<<0;
            return;
        }
        if(v==3) ans++;
    }
    cout<<n-ans<<endl;
    return;
}
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值