Pagini recente » Cod sursa (job #985533) | Cod sursa (job #1582540) | Cod sursa (job #2111956) | Cod sursa (job #9817) | Cod sursa (job #3173868)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("zc.in");
ofstream fout("zc.out");
vector <pair <int,int>> capc1;
vector <pair <int,int>> capc2;
int n, m, x, y, dim, sol;
char c;
int main()
{
ios::sync_with_stdio(false);
fin.tie(NULL);
fout.tie(NULL);
fin >> n >> m;
for(int i=1; i<=n; i++)
{
fin >> x >> y;
for(int j=-2; j<=2; j++)
for(int k=-2; k<=j; k++)
{
if(abs(j)+abs(k)<=2)
{
if(x+j!=0||y+k!=0)
{
capc1.push_back(make_pair(x+j,y+k));
capc2.push_back(make_pair(y+k,x+j));
}
}
}
}
sort(capc1.begin(),capc1.end());
sort(capc2.begin(),capc2.end());
capc1.resize(unique(capc1.begin(),capc1.end())-capc1.begin());
capc2.resize(unique(capc2.begin(),capc2.end())-capc2.begin());
/*
for(pair<int,int> a:capc1)
cout << a.first << ' ' << a.second << '\n';
*/
int x = 0;
int y = 0;
for(int i=1; i<=m; i++)
{
fin >> c >> dim;
if(c=='N')
{
int st = lower_bound(capc1.begin(),capc1.end(),make_pair(x,y+1))-capc1.begin();
int dr = upper_bound(capc1.begin(),capc1.end(),make_pair(x,y+dim))-capc1.begin();
if (st<=dr && capc1[st].first==x && y<=capc1[st].second && capc1[st].second<=y+dim)
sol+=(dr-st);
y+=dim;
}
if(c=='S')
{
int st = lower_bound(capc1.begin(),capc1.end(),make_pair(x,y-dim))-capc1.begin();
int dr = upper_bound(capc1.begin(),capc1.end(),make_pair(x,y-1))-capc1.begin();
if (st<=dr && capc1[st].first==x && y-dim<=capc1[st].second && capc1[st].first<=y)
sol+=(dr-st);
y-=dim;
}
if(c=='E')
{
int st=lower_bound(capc2.begin(),capc2.end(),make_pair(y,x+1))-capc2.begin();
int dr=upper_bound(capc2.begin (),capc2.end (),make_pair(y,x+dim))-capc2.begin();
if (st<=dr && capc2[st].first==y && x<=capc2[st].second && capc2[st].second<=x+dim)
sol+=(dr-st);
x+=dim;
}
if(c=='V')
{
int st=lower_bound(capc2.begin(),capc2.end(),make_pair(y,x-dim))-capc2.begin ();
int dr=upper_bound(capc2.begin(),capc2.end(),make_pair(y,x-1))-capc2.begin ();
if(st<=dr && capc2[st].first==y && x-dim<capc2[st].second&& capc2[st].second<=x)
sol+=(dr-st);
x-=dim;
}
}
fout << sol;
fin.close();
fout.close();
return 0;
}