请问关于递归中自加(++num)和加一(num+1)的区别(70pts)
查看原帖
请问关于递归中自加(++num)和加一(num+1)的区别(70pts)
1390639
URAISK421楼主2024/11/21 17:22

RT,代码31行递归中的num+1改为++num会导致测试点#2,#8, #10 WA WA
在网上也没找到相关的资料...

#include<iostream>
#include<cstdio>
#include<math.h>
using namespace std;
const int maxn = 1e3+5;
int x[maxn],y[maxn],vis[10];
double dis[10][10],r[10];
double ans;
int xx,yy,xxx,yyy,sq,n;
void Init(){
	cin>>n;
	cin>>xx>>yy>>xxx>>yyy;
	sq = abs(xx-xxx)*abs(yy-yyy);
	for(int i = 1;i<=n;i++)
		cin>>x[i]>>y[i];
	for(int i = 1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			dis[i][j] = dis[j][i] =sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
	
}
void dfs(int num,double sum){
	if(num == n+1 ) ans = max(sum,ans);
	for(int i = 1;i<=n;i++)
		if(!vis[i]){
			r[i] = min(min(abs(x[i]-xx),abs(x[i]-xxx)), min(abs(y[i]-yy),abs(y[i]-yyy)));//
			for(int j = 1;j<=n;j++)
				if(vis[j]) r[i] = min(r[i],dis[i][j]-r[j]);//
			vis[i] = true;
			if(r[i]<=0) r[i] = 0;
			dfs(++num,sum+M_PI*r[i]*r[i]);//++num会错:100pts->70pts
			vis[i] = false;
		}
	return ;
}
signed main(){
	Init();
	dfs(1,0.00);
	printf("%.0f",sq-ans);
}

#2:
in: 3 -98 5 30 30
-42 11
-51 17
-11 22

out:
2547

使用++num:
2748

2024/11/21 17:22
加载中...