折半搜索,84pts TLE on #5 and #16,求调教
查看原帖
折半搜索,84pts TLE on #5 and #16,求调教
701254
Mu_leaf楼主2023/12/5 14:36

Rt.

现在已知开 unorderedmapunordered_map 和 hash 没用。

#include <bits/stdc++.h>
using namespace std;
inline int read(){
	int res=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){res=(res<<1)+(res<<3)+(c^48);c=getchar();}
	return res*f;
}
void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
const int N=45;
int n,vis[N],ans[N];
int ex,ey;
struct node{
	int x,y;
}a[N];
map<pair<int,int>,vector<int>> mp;
void dfs(int x,int nx,int ny,int st,int ed,int c,int op){
	if(x>ed){
		if(!op) mp[{nx,ny}].push_back(c);
		else{
			int sx=ex-nx,sy=ey-ny;
			vector<int> V=mp[{sx,sy}];
			for(auto v:V) ans[c+v]++;
		}
		return;
	}
	dfs(x+1,nx+a[x].x,ny+a[x].y,st,ed,c+1,op);
	dfs(x+1,nx,ny,st,ed,c,op);
}
signed main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	n=read();ex=read();ey=read();
	for(int i=1;i<=n;i++) a[i].x=read(),a[i].y=read();
	dfs(1,0,0,1,n/2,0,0);
	dfs(n/2+1,0,0,n/2+1,n,0,1);
	for(int i=1;i<=n;i++) write(ans[i]),puts("");
	return 0 ;
}

这个程序制造的数据会T,但不知道为啥。有没有大佬解答一下QAQ。

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int inf=1e9l
int n=40;
signed main(){
	srand(time(NULL));
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cout << n << "\n";
	cout << (rand()%2==1?-1:1)*inf << " " << (rand()%1==0?-1:1)*inf << "\n";
	for(int i=1;i<=n;i++){
		cout << (rand()%2==1?-1:1)*inf << " " << (rand()%2==1?-1:1)*inf << "\n";
	}
	return 0 ;
}

2023/12/5 14:36
加载中...