警示后人
  • 板块灌水区
  • 楼主Fake_Cry
  • 当前回复4
  • 已保存回复4
  • 发布时间2024/10/10 08:45
  • 上次更新2024/10/10 15:31:56
查看原帖
警示后人
891975
Fake_Cry楼主2024/10/10 08:45

我们模拟赛的题面
我的代码

#include<bits/stdc++.h>
using namespace std;
int a[30],ans;
int main() {
	freopen("xpy.in","r",stdin);
	freopen("xpy.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n,k;
	cin>>n>>k;
	int Pow=1;
	for(int i=1; i<=n; i++) {
		a[i]=n-i+1;
		Pow*=i;
	}
	for(int i=1; i<=Pow; i++) {
		bool o=1;
		next_permutation(a+1,a+n+1);
		for(int x=1; x<=n; x++) 
			if(x!=1&&abs(a[x]-a[x-1])==k){
				o=0;
				break;
			}
		if(o) ans++;
	}
	cout<<ans;
	return 0;
}

就只是因为最内层循环if中的break赛时没有加,TLE了,就这么丢了10分,好可惜啊

2024/10/10 08:45
加载中...