CodeForces 734D Anton and Chess 【模拟】
2016-11-18 10:44
363 查看
题目:点击打开链接
题意:给定一个白棋坐标,给出n个黑色的棋子的坐标,表示象,车,女王的中的一个,棋子不能越过另一个棋子,问是否白棋能被吃掉
分析:以白棋为中心,分散中八条横竖斜的射线,储存与最近的黑棋的距离,再遍历一遍黑棋,看是否满足黑棋距离等于该射线的最近距离且能吃掉白棋
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <vector>
#include <map>
#define sqr(x) ((x)*(x))
#define PR pair<int,int>
#define MP make_pair
#define fi first
#define se second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ll long long
const ll INF = (1ULL<<63)-1;
const int inf=0x3f3f3f3f;
const int M=100010;
const int N=500010;
const ll MOD=1000000007;
const double eps=1e-3;
const double pi=acos(-1.0);
using namespace std;
struct node{char s[3];int x,y;}p
;
ll n,sx,sy,x,y,a[8];
char s[3];
ll dis(ll x,ll y) {return abs(x-sx)+abs(y-sy);}
bool judge(ll x,ll y){return abs(x-sx)==abs(y-sy);}
int main()
{
int i,ok=0;
for(i=0;i<8;i++)a[i]=INF;
scanf("%I64d%I64d%I64d",&n,&sx,&sy);
for(i=0;i<n;i++)
{
scanf("%s%I64d%I64d",s,&x,&y);
strcpy(p[i].s,s);p[i].x=x,p[i].y=y;
ll d=dis(x,y);
if(x<sx&&y==sy) a[0]=min(a[0],d);
if(x==sx&&y>sy) a[2]=min(a[2],d);
if(x>sx&&y==sy) a[4]=min(a[4],d);
if(x==sx&&y<sy) a[6]=min(a[6],d);
if(judge(x,y))
{
if(x<sx&&y>sy) a[1]=min(a[1],d);
if(x>sx&&y>sy) a[3]=min(a[3],d);
if(x>sx&&y<sy) a[5]=min(a[5],d);
if(x<sx&&y<sy) a[7]=min(a[7],d);
}
}
for(i=0;i<n;i++)
{
strcpy(s,p[i].s);x=p[i].x,y=p[i].y;
ll d=dis(x,y);
if(s[0]=='R'||s[0]=='Q')
{
if(x<sx&&y==sy&&a[0]>=d) ok=1;
if(x==sx&&y>sy&&a[2]>=d) ok=1;
if(x>sx&&y==sy&&a[4]>=d) ok=1;
if(x==sx&&y<sy&&a[6]>=d) ok=1;
}
if(s[0]=='B'||s[0]=='Q')
{
if(judge(x,y))
{
if(x<sx&&y>sy&&a[1]==d) ok=1;
if(x>sx&&y>sy&&a[3]==d) ok=1;
if(x>sx&&y<sy&&a[5]==d) ok=1;
if(x<sx&&y<sy&&a[7]==d) ok=1;
}
}
}
if(ok) puts("YES");else puts("NO");
}
题意:给定一个白棋坐标,给出n个黑色的棋子的坐标,表示象,车,女王的中的一个,棋子不能越过另一个棋子,问是否白棋能被吃掉
分析:以白棋为中心,分散中八条横竖斜的射线,储存与最近的黑棋的距离,再遍历一遍黑棋,看是否满足黑棋距离等于该射线的最近距离且能吃掉白棋
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <vector>
#include <map>
#define sqr(x) ((x)*(x))
#define PR pair<int,int>
#define MP make_pair
#define fi first
#define se second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ll long long
const ll INF = (1ULL<<63)-1;
const int inf=0x3f3f3f3f;
const int M=100010;
const int N=500010;
const ll MOD=1000000007;
const double eps=1e-3;
const double pi=acos(-1.0);
using namespace std;
struct node{char s[3];int x,y;}p
;
ll n,sx,sy,x,y,a[8];
char s[3];
ll dis(ll x,ll y) {return abs(x-sx)+abs(y-sy);}
bool judge(ll x,ll y){return abs(x-sx)==abs(y-sy);}
int main()
{
int i,ok=0;
for(i=0;i<8;i++)a[i]=INF;
scanf("%I64d%I64d%I64d",&n,&sx,&sy);
for(i=0;i<n;i++)
{
scanf("%s%I64d%I64d",s,&x,&y);
strcpy(p[i].s,s);p[i].x=x,p[i].y=y;
ll d=dis(x,y);
if(x<sx&&y==sy) a[0]=min(a[0],d);
if(x==sx&&y>sy) a[2]=min(a[2],d);
if(x>sx&&y==sy) a[4]=min(a[4],d);
if(x==sx&&y<sy) a[6]=min(a[6],d);
if(judge(x,y))
{
if(x<sx&&y>sy) a[1]=min(a[1],d);
if(x>sx&&y>sy) a[3]=min(a[3],d);
if(x>sx&&y<sy) a[5]=min(a[5],d);
if(x<sx&&y<sy) a[7]=min(a[7],d);
}
}
for(i=0;i<n;i++)
{
strcpy(s,p[i].s);x=p[i].x,y=p[i].y;
ll d=dis(x,y);
if(s[0]=='R'||s[0]=='Q')
{
if(x<sx&&y==sy&&a[0]>=d) ok=1;
if(x==sx&&y>sy&&a[2]>=d) ok=1;
if(x>sx&&y==sy&&a[4]>=d) ok=1;
if(x==sx&&y<sy&&a[6]>=d) ok=1;
}
if(s[0]=='B'||s[0]=='Q')
{
if(judge(x,y))
{
if(x<sx&&y>sy&&a[1]==d) ok=1;
if(x>sx&&y>sy&&a[3]==d) ok=1;
if(x>sx&&y<sy&&a[5]==d) ok=1;
if(x<sx&&y<sy&&a[7]==d) ok=1;
}
}
}
if(ok) puts("YES");else puts("NO");
}
相关文章推荐
- 【模拟】Codeforces 691B s-palindrome
- CodeForces 670E(模拟双向链表)
- codeforces 251 div2 C. Devu and Partitioning of the Array 模拟
- CodeForces 349A Cinema Line (模拟)
- CodeForces 758C Unfair Poll(模拟)
- CodeForces 722B. Verse Pattern(模拟)
- Codeforces 398D Instant Messanger 轻重点分类 模拟
- codeforces 691A 模拟
- Codeforces 520D. Cubes 贪心模拟
- CodeForces 545B Equidistant String (模拟)
- CodeForces - 366A Dima and Guards (模拟)
- CodeForces - 733C Epidemic in Monstropolis (模拟乱搞)
- 模拟好题 CodeForces 864C Bus
- Codeforces 746C Tram 模拟+思维
- codeforces 677B Vanya and Food Processor(模拟)
- 模拟赛#1补题 CodeForces 574B Bear and Three Musketeers(模拟判环)
- CodeForces 691C Exponential notation(模拟)
- Codeforces 631B Print Check【模拟】
- Codeforces 903B - The Modcrab 模拟+记录
- codeforces 719C (复杂模拟-四舍五入-贪心)