CERC17 Problem L - Lunar Landscape(差分,坐标系)

CERC17 Problem L - Lunar Landscape

Solution

如果只有 A A A,我们可以简单地使用差分解决。
加入了 B B B之后,可以把单位正方形用对角线拆成四个等腰Rt,统计等腰Rt的个数。我们先进行坐标转换,把 ( x , y ) − > ( x − y , x + y ) (x,y)->(x-y,x+y) (x,y)>(xy,x+y),然后差分。

时间复杂度 O ( n + W 2 ) O(n+W^2) O(n+W2)

Code

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=998244353;
const int MAXN=600005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
const int L=1501;
int A[L*2][L*2],B[L*4][L*4];
signed main()
{
	int n=read();
	for (int i=1;i<=n;i++)
	{
		char c; scanf("%c",&c);
		int x=read(),y=read(),z=read()>>1;
		
		if (c=='A') x+=L,y+=L,A[x-z][y-z]++,A[x-z][y+z]--,A[x+z][y-z]--,A[x+z][y+z]++;
		else 
		{
			int X=x-y+L*2,Y=x+y+L*2;
			B[X-z][Y-z]++,B[X-z][Y+z]--,B[X+z][Y-z]--,B[X+z][Y+z]++;
		}
	}
	for (int i=1;i<L*2;i++) for (int j=0;j<L*2;j++) A[i][j]+=A[i-1][j];
	for (int i=0;i<L*2;i++) for (int j=1;j<L*2;j++) A[i][j]+=A[i][j-1];
	for (int i=1;i<L*4;i++) for (int j=0;j<L*4;j++) B[i][j]+=B[i-1][j];
	for (int i=0;i<L*4;i++) for (int j=1;j<L*4;j++) B[i][j]+=B[i][j-1];
	int ans=0;
	for (int i=-L;i<L;i++)
		for (int j=-L;j<L;j++)
			if (A[i+L][j+L]) ans+=4;
			else ans+=(B[i-j+L*2][i+j+L*2]>0)+(B[i-j+L*2-1][i+j+L*2]>0)+(B[i-j+L*2][i+j+L*2+1]>0)+(B[i-j+L*2-1][i+j+L*2+1]>0);
	printf("%.2lf\n",ans*.25);
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值