题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4631
#include<bits/stdc++.h>
using namespace std;
#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long
#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root l,r,rt
const int maxn =1e5+5;
const int mod=1e9+7;
const int ub=10000;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*
二维点附加动态查询点之间最小距离,
最后输出所有动态最小距离之和。
想了好久实在没办法了就暴力吧。。。(20秒。。。)
因为题目意思中有最小的限制,
就剪个枝吧,只要把之前的点丢到个动态排序的结构中就可以了。
选择set吧,然后对于当前x坐标,查询点距离在x-sqrt(minv),x+sqrt(minv)之间的二维点,
更新答案并且计数吧。
*/
ll n,a1,b1,c1,a2,b2,c2,x,y;
///pair<ll,ll> pii[maxn];
set<pair<ll,ll>> st;
set<pair<ll,ll>>::iterator it,pos1,pos2;
const ll INF=1e18;
ll sqt(ll w){return w*w;};
int main()
{
int t;scanf("%d",&t);
while(t--)
{
scanf("%lld%lld%lld%lld%lld%lld%lld",&n,&a1,&b1,&c1,&a2,&b2,&c2);
x=y=0;
ll ans=0,minv=INF;
st.clear();
for(int i=1;i<=n;i++)
{
x=(x*a1+b1)%c1;
y=(y*a2+b2)%c2;
if(minv==0) continue;
pos1=st.lower_bound(make_pair(x+(ll)sqrt(minv)+1,0));
pos2=st.lower_bound(make_pair(x-(ll)sqrt(minv-1),0));
///cout<<x<<" "<<y<<endl;
///for(it=st.begin();it!=st.end();it++) cout<<it->first<<" "<<it->second<<endl;puts("");
for(it=pos2;it!=pos1;it++) minv=min(minv,sqt(x-(it->first))+sqt(y-(it->second)));
if(minv!=INF) ans+=minv;
st.insert(make_pair(x,y));
}
printf("%lld\n",ans);
}
return 0;
}

这篇博客介绍了如何利用暴力搜索结合剪枝策略解决HDU 4631题目的详细过程,通过链接可以访问题目详情。
923

被折叠的 条评论
为什么被折叠?



