跳到正文

题解

题解:CF2172E Number Maze

NoneOfTheAbove约 2 分钟
原文
文章信息与版本

文章信息

发布
2026年3月27日
收录
2026年10月15日
更新
2026年11月22日
篇幅
约 2 分钟
获赞
1
题目
CF2172E

版本

  1. v1当前

luogu link
codeforces link

Solution

我们只需要分讨 nn 的值,然后求第 jj 和第 kk 个排列,最后求 x,yx,y 就可以了。

求下一个排列可以用函数 next_permutation,用 j−1,k−1j-1,k-1 次就可以求第 j,kj,k 个排列。

求 x,yx,y 可以枚举,如果两个排列里同一位的数相同,那么 xx 加一,否则 yy 加一。原因:都是排列,不相同肯定是错位了。

Code

code
C++
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef char ch;
typedef string str;
typedef double db;
typedef __int128 i128;
const ll inf=9e18,maxn=5;
const i128 Inf=1e35;
ll n,a[maxn],b[maxn],m,j,k,x,y,t;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>t;
	while(t--)
	{
	  	cin>>n>>j>>k;
	  	x=y=0;
	  	if(n==12) m=2,a[1]=b[1]=1,a[2]=b[2]=2;
	  	else if(n==123) m=3,a[1]=b[1]=1,a[2]=b[2]=2,a[3]=b[3]=3;
	  	else m=4,a[1]=b[1]=1,a[2]=b[2]=2,a[3]=b[3]=3,a[4]=b[4]=4;
	  	j--,k--;
	  	while(j--) next_permutation(a+1,a+m+1);
	  	while(k--) next_permutation(b+1,b+m+1);
	  	for(int i=1;i<=m;i++)
	  	{
	  		if(a[i]==b[i]) x++;
	  		else y++;
	  	}
	  	cout<<x<<"A"<<y<<"B\n";
	}
}
原文
存档评论1 条抓取于