Codeforces Beta Round #95 (Div. 2) E. Yet Another Task with Queens(模拟)
来源:互联网 发布:传智播客java课程 编辑:程序博客网 时间:2024/05/22 01:30
题目地址:http://codeforces.com/problemset/problem/131/E
思路:行i,列j,对角线一 i+j,对角线二 i-j 。使用set(有序),若当前皇后对应项(行列对角线)在set一端且元素个数不为1,则该皇后在该项被1皇后攻击。若在set元素中间,则该皇后在该项被2皇后攻击。
#include<set>#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;const int maxn=1e5+50;struct Node{ int x,y; Node(int a=0,int b=0):x(a),y(b) {} bool operator < (const Node & rhs) const { return rhs.y<y; } bool operator !=(const Node & rhs) const { return rhs.y!=y; } bool operator ==(const Node & rhs) const { return rhs.y==y; }};int n,m;int ans[10];Node P[maxn];set<Node> A[maxn],B[maxn];set<Node> C[2*maxn],D[3*maxn];int solve(const set<Node> & tmp,Node x){ set<Node>::iterator it1; set<Node>::iterator it2; it1=tmp.begin(),it2=tmp.end(),it2--; if((x==(*it1)||x==(*it2))&&(*it1!=*it2)) return 1; if(x!=(*it1)&&x!=(*it2)) return 2; return 0;}int main(){ scanf("%d%d",&n,&m); for(int i=0; i<m; i++) { int x,y; scanf("%d%d",&x,&y); P[i].x=x,P[i].y=y; A[x].insert(Node(x,y)); B[y].insert(Node(y,x)); C[x+y].insert(Node(x+y,x-y+2*n)); D[x-y+2*n].insert(Node(x-y+2*n,x+y)); } for(int i=0; i<m; i++) { int r=P[i].x,c=P[i].y,sum=0; sum+=solve(C[r+c],Node(r+c,r-c+2*n)); sum+=solve(D[r-c+2*n],Node(r-c+2*n,r+c)); sum+=solve(A[r],Node(r,c))+solve(B[c],Node(c,r)); ans[sum]++; } for(int i=0; i<8; i++) printf("%d ",ans[i]); printf("%d\n",ans[8]); return 0;}
0 0
- Codeforces Beta Round #95 (Div. 2) E. Yet Another Task with Queens(模拟)
- Codeforces Beta Round #95 (Div. 2) -- E. Yet Another Task with Queens(STL)
- Codeforces Beta Round #49 (Div. 2) E
- Codeforces Beta Round #95 (Div. 2) A B C E
- Codeforces Beta Round #96 (Div. 2) (模拟)
- Codeforces Round #441 (Div. 2): E. National Property(模拟?)
- Codeforces Round #441 (Div. 2)-E-National Property(模拟)
- Codeforces Beta Round #63 (Div. 2) E题
- Codeforces Beta Round #69 (Div. 2 Only) E题
- Codeforces Beta Round #22 (Div. 2 Only) E. Scheme
- Codeforces Beta Round #46 (Div. 2) E. Common ancestor
- Codeforces Beta Round #89 (Div. 2) E. Bertown roads
- Codeforces Beta Round #57 (Div. 2) E. Enemy is weak
- Codeforces Beta Round #16 (Div. 2 Only) E. Fish
- Codeforces Beta Round #14 (Div. 2) E. Camels
- Codeforces Beta Round #61 (Div. 2) E. Petya and Post
- Codeforces Beta Round #6 (Div. 2 Only) E. Exposition
- Codeforces Beta Round #91 (Div. 2 Only)-E. Lucky Permutation
- 【Python】基础学习——列表(list),元祖(tuple),字典(dict),字符串(string),集合(set)
- 【BLE】CC2541之SBL修改bootloader大小
- LoadRunner手动关联具体步骤
- TCP/IP,http,socket,长连接,短连接
- 顺序表应用1:多余元素删除之移位算法
- Codeforces Beta Round #95 (Div. 2) E. Yet Another Task with Queens(模拟)
- 【9005】最短网络agrinet
- 记录在写学术论文时使用MATLAB制作折线图
- MAC地址特殊规定--设置MAC地址时需要有非法MAC设置判断,否则会导致网卡无法启动
- 【CodeForces】[274A]k-Multiple Free Set
- Android控件属性
- Android扫一扫
- 你对C语言的关键字,知多少
- HDU 5754 博弈(威佐夫博弈)