ACM-ICPC Shenyang Oniste 2018 Best ACMer Solves the Hardest Problem

ACM-ICPC Shenyang Oniste 2018 Best ACMer Solves the Hardest Problem

思路: 用map或者二维数组存点,然后先预处理出每个点的属于哪个k值,存在vector pair中,最后根据操作直接找就行了。如果是用二维数组存点的话,还要用vector把存进去的点记录下来,然后清空,不然直接memset会超时。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll mod = 6000;
int n,m,t;
int mp[6007][6007];

ll ans;
vector<pair<int,int> > g[10000007],vis;

bool check(int x,int y)
{
	if(x <= 6000 && x > 0 && y > 0 && y <= 6000) return 1;
	return 0;
}

void init()
{
	for(int i=0;i<=6000;i++)
	{
		for(int j=0;j<=6000;j++)
		{
			if(i * i + j * j > 1e7) break;
			g[i * i + j * j].push_back({i, j});
		}
	}
}

int main()
{
	init();
	scanf("%d",&t);
	for(int T=1;T<=t;T++)
	{
		ans = 0;
		scanf("%d%d",&n,&m);
		for(int i=1;i<=n;i++)
		{
			int x,y,w;
			scanf("%d%d%d",&x,&y,&w);
			mp[x][y]=w;
			vis.push_back({x, y});
		}
		printf("Case #%d:\n",T);
		while(m--)
		{
			int op,x,y,w,k;
			scanf("%d%d%d",&op,&x,&y);
			x = (x + ans) % mod + 1;
			y = (y + ans) % mod + 1;
			if(op == 1)
			{
				scanf("%d",&w);
				mp[x][y] = w;
				vis.push_back({x, y});
			}
			if(op == 2)
			{
				mp[x][y] = 0;
			}
			if(op == 3)
			{
				scanf("%d%d",&k,&w);
				if(k == 0)
				{
					mp[x][y] += w;
					continue;
				}
				for(int i=0;i<g[k].size();i++)
				{
					int t1 = g[k][i].first;
					int t2 = g[k][i].second;
					if(t1 == 0)
					{
						if(check(x - t1, y + t2) && mp[x - t1][y + t2] > 0) mp[x - t1][y + t2] += w;
						if(check(x - t1, y - t2) && mp[x - t1][y - t2] > 0) mp[x - t1][y - t2] += w;
					}
					else if(t2 == 0)
					{
						if(check(x + t1, y + t2) && mp[x + t1][y + t2] > 0) mp[x + t1][y + t2] += w;
						if(check(x - t1, y + t2) && mp[x - t1][y + t2] > 0) mp[x - t1][y + t2] += w;
					}
					else
					{
						if(check(x + t1, y + t2) && mp[x + t1][y + t2] > 0) mp[x + t1][y + t2] += w;
						if(check(x - t1, y + t2) && mp[x - t1][y + t2] > 0) mp[x - t1][y + t2] += w;
						if(check(x + t1, y - t2) && mp[x + t1][y - t2] > 0) mp[x + t1][y - t2] += w;
						if(check(x - t1, y - t2) && mp[x - t1][y - t2] > 0) mp[x - t1][y - t2] += w;
					}
				}
			}
			if(op == 4)
			{
				ans = 0;
				scanf("%d",&k);
				if(k == 0)
				{
					printf("%d\n",mp[x][y]);
					ans = mp[x][y];
					continue;
				}
				for(int i=0;i<g[k].size();i++)
				{
					int t1 = g[k][i].first;
					int t2 = g[k][i].second;
					if(t1 == 0)
					{
						if(check(x - t1, y + t2) && mp[x - t1][y + t2] > 0) ans += mp[x - t1][y + t2];
						if(check(x - t1, y - t2) && mp[x - t1][y - t2] > 0) ans += mp[x - t1][y - t2];
					}
					else if(t2 == 0)
					{
						if(check(x + t1, y + t2) && mp[x + t1][y + t2] > 0) ans += mp[x + t1][y + t2];
						if(check(x - t1, y + t2) && mp[x - t1][y + t2] > 0) ans += mp[x - t1][y + t2];
					}
					else
					{
						if(check(x - t1, y + t2) && mp[x - t1][y + t2] > 0) ans += mp[x - t1][y + t2];
						if(check(x - t1, y - t2) && mp[x - t1][y - t2] > 0) ans += mp[x - t1][y - t2];
						if(check(x + t1, y - t2) && mp[x + t1][y - t2] > 0) ans += mp[x + t1][y - t2];
						if(check(x + t1, y + t2) && mp[x + t1][y + t2] > 0) ans += mp[x + t1][y + t2];
					}
				}
				printf("%lld\n",ans);
			}
		}
		int len = vis.size();
		for(int i=0;i<len;i++)
		{
			mp[vis[i].first][vis[i].second] = 0;
		}
		vis.clear();
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值