比赛总结
T1
题意是预估出 的最大排名和最小排名。 我们可以统计有多少人至少一场比赛比 高,多少人至少一场比赛比 低即可。
AC代码
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define TRACE 1
#define tcout TRACE and cout
#define fst ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define int long long
#define re register
#define inl inline
const int P = 998244353;
const int Base = 322225477;
const int INF = 0x3f3f3f3f3f3f3f3f;
const int N = 1e6 + 10, M = 2e3 + 10;
int n,m;
int a[N];
int ma,mi;
signed main(){
fst
cin>>n>>m;
ma=m;
for(int i=1;i<=n;i++){
cin>>a[i];
ma-=m-a[i];
mi+=a[i]-1;
}
cout<<max(1LL,ma)<<endl<<min(mi+1,m);
return 0;
}
/*
4 5 6 6 5 6
*/T2
有 次输入和输出,每一轮将2个球分别放入 ,前 轮中放入袋子 和袋子 的所有数字一一配对后,和最大的一对的最小值。
我们可以同时维护两个桶。在回答的时候,我们只需维护两个指针 p和q,设 和 的较小者为 ,将两者都减去 ,得到 对 ,然后继续移动两个指针即可。
AC代码:
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define TRACE 1
#define tcout TRACE && cout
#define fst ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define int long long
#define re register
#define inl inline
const int P = 998244353;
const int Base = 322225477;
const int INF = 0x3f3f3f3f3f3f3f3f;
const int N = 1e6 + 10, M = 2e3 + 10;
int n;
int a[N],b[N];
int tot1[N],tot2[N];
int max1,max2;
int tmp[N],tmp2[N]
signed main(){
fst
cin>>n;
for(int i=1;i<=n;i++){
int x,y;
cin>>x>>y;
tot1[x]++;
tot2[y]++;
max1=max(max1,x);
max2=max(max2,y);
for(int i=1;i<=100;i++){
tmp[i]=tot1[i],tmp2[i]=tot2[i];
}
int l=0,r=max2,ans=0;
while(true){
while(tmp[l]==0 and l<=max1){
l++;
}
if(l>max1){
break;
}
while(tmp2[r]==0){
r--;
}
int minv=min(tmp[l],tmp2[r]);
tmp[l]-=minv;
tmp2-=minv;
ans=max(ans,l+r);
}
cout<<ans<<endl;
}
return 0;
}T3
这是一个环形染色问题,推导它的公式再用快速幂就是即可, 对于一个有 个区域环,有 个颜色可以选择,相邻的石块不能涂一样的颜色,将环从某两个区域分开,展开为一个线性排列,那么相邻元素不同的排列有 种,设 个区域的环的涂色方案有 种,那么线性排列首位颜色有两种情况,
首位颜色相同,那么把首位两个区域叠成一个区域,那么组成了一个 个区域的环,就等于 首位颜色不同,那么直接拼接首位成为一个 个区域的环,就等于
综合两种情况,得到方程 ,所以
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define TRACE 1
#define tcout TRACE && cout
#define fst ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define int long long
#define re register
#define inl inline
const int P = 1e9 + 7;
const int Base = 322225477;
const int INF = 0x3f3f3f3f3f3f3f3f;
const int N = 1e6 + 10, M = 2e3 + 10;
inl int fun(int n, int m){
int base = m-1, nub = n,ans = 1;
while(nub){
if(nub&1) ans = ans%P*base%P;
nub /= 2;
base = base%P*base%P;
}
return ans + (n&1 ? -(m-1):(m-1));
}
signed main(){
fst
int t;
cin >> t;
while(t--){
int n, m;
cin >> n >> m;
if(n == 1) cout << m%P << '\n';
else if(n == 2) cout << m%P*(m-1)%P << '\n';
else if(n == 3) cout << m%P*(m-1)%P*(m-2) << '\n';
else {
cout << fun(n,m) %P<< '\n';
}
}
}