【题目链接】:http://codeforces.com/problemset/problem/131/E

【题意】



给你n*n坐标上的m个皇后的位置;

然后让你求出,能够攻击到0,1,2…8个其他皇后的皇后个数;

(其他皇后可以被前面的皇后挡住,所以最多只能攻击到8个);

【题解】



按照横、纵、正对角、斜对角这4个方向搞;

横坐标的话,将纵坐标升序排;

然后对于每一个横坐标,将横坐标为它的皇后的标号加入到vector里面;

(因为纵坐标升序排了,所以最两端的皇后就是vector里面第一个和最后一个皇后,那两个皇后能攻击到的个数+1,其他的+2);

纵坐标、对角同理;



【Number Of WA】



1



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0),cin.tie(0) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1e5+100; struct dian{
int x,y,id;
}; dian a[N];
int n,m,can[N],ans[10];
vector <int> dic[N*3]; void init(){
rep1(i,0,(int) 3e5) dic[i].clear();
} int main(){
//Open();
Close();//scanf,puts,printf not use
//init??????
cin >> n >> m;
rep1(i,1,m){
cin >> a[i].x >> a[i].y;
a[i].id = i;
} sort(a+1,a+1+m,[&] (dian a,dian b){return a.y<b.y;});
rep1(i,1,m){
dic[a[i].x].pb(a[i].id);
}
rep1(i,1,n){
if ((int) dic[i].size()>1){
rep1(j,0,(int) dic[i].size()-1){
if (j==0 || j == (int) dic[i].size()-1){
can[dic[i][j]]++;
}
else
can[dic[i][j]]+=2;
}
}
} sort(a+1,a+1+m,[&] (dian a,dian b){return a.x<b.x;});
init();
rep1(i,1,m){
dic[a[i].y].pb(a[i].id);
}
rep1(i,1,n){
if ((int) dic[i].size()>1){
rep1(j,0,(int) dic[i].size()-1){
if (j==0 || j == (int) dic[i].size()-1){
can[dic[i][j]]++;
}
else
can[dic[i][j]]+=2;
}
}
} init();
rep1(i,1,m){
dic[a[i].x+a[i].y].pb(a[i].id);
}
rep1(i,1,2*n){
if ((int) dic[i].size()>1){
rep1(j,0,(int) dic[i].size()-1){
if (j==0 || j == (int) dic[i].size()-1){
can[dic[i][j]]++;
}
else
can[dic[i][j]]+=2;
}
}
} init();
rep1(i,1,m){
dic[a[i].x-a[i].y+(int)1e5].pb(a[i].id);
}
rep1(i,0,(int)2e5+10){
if ((int) dic[i].size()>1){
rep1(j,0,(int) dic[i].size()-1){
if (j==0 || j == (int) dic[i].size()-1){
can[dic[i][j]]++;
}
else
can[dic[i][j]]+=2;
}
}
} rep1(i,1,m){
ans[can[i]]++;
} rep1(i,0,8){
cout << ans[i]<<(i==8?'\n':' ');
}
return 0;
}

【codeforces 131E】Yet Another Task with Queens的更多相关文章

  1. 【30.93%】【codeforces 558E】A Simple Task

    time limit per test5 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...

  2. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  3. 【34.57%】【codeforces 557D】Vitaly and Cycle

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. 【35.29%】【codeforces 557C】Arthur and Table

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. 【23.33%】【codeforces 557B】Pasha and Tea

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 【55.70%】【codeforces 557A】Ilya and Diplomas

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. 【23.39%】【codeforces 558C】Amr and Chemistry

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  8. 【47.40%】【codeforces 743B】Chloe and the sequence

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  9. 【24.34%】【codeforces 560D】Equivalent Strings

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

随机推荐

  1. Kendo UI diagram 更改connnect线颜色,及shapes的属性值

    1.改diagram中连线的颜色:redraw一下就OK // Change the Line Green diagram.connections[indexS].redraw({ stroke:{ ...

  2. Eigen下载安装

    首先提供Eigen的两个重要网站 官方网站 下载地址 1.下载 wget http://bitbucket.org/eigen/eigen/get/3.3.5.tar.gz 2.解压缩 tar -zx ...

  3. linux查看前几条命令记录

    1.按上下箭头键2.history|more分页显示3.vi /etc/profile找HISTSIZE=1000,说明你最多能存1000条历史记录.4.!!执行最近执行的命令5.history|he ...

  4. Django -聚合分组,FQ操作, cookie, session

    一. 聚合查询和分组 1. 聚合 aggregate(*args, **kwargs) 对一组数据进行统计分析, 通过对QuerySet进行计算, 返回一个聚合值得字典. arrgregate()中每 ...

  5. (转)redis源代码分析 – event library

    每个cs程序尤其是高并发的网络服务端程序都有自己的网络异步事件处理库,redis不例外. 事件库仅仅包括ae.c.ae.h,还有3个不同的多路复用(本文仅描述epoll)的wrapper文件,事件库封 ...

  6. 简单来说一下java中的泛型,ssh中dao层使用会简化代码量

    原来仅仅是听老师说泛型特别好用,但是后来一直弄android用的泛型就比較少了.但是感觉它真的非常重要,于是花了一下午的时间写了个demo.好,老规矩.上代码: 首先,sysout是个工具,可是用着不 ...

  7. node.js mongodb ReplSet

    随着web2.0兴起,高并发大数据量的应用对数据库高速响应的性能要求日趋明显,传统的关系型数据库在这方面显得有些乏力.有矛自有盾,内存DB的出现弥补了传统关系型db的不足.眼下市面流行的内存db主要有 ...

  8. oracle 11g sql developer安装后无法使用

    oracle11g安装后出现   再去官网单独下来个sql developer安装 sql developer须要jre支持

  9. hdu1213 How Many Tables(并查集)

    How Many Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  10. (插播)关于使用jenkins + unity +Xcode 来进行自己主动打包的处理。

    近期了解了下jenkins流程化服务的东西,个人感觉jenkins是一个非常方便的工具.主要是方便.设置好流程性得命令.仅仅需确定下就能够达到自己主动化. 减轻了错误得发生和简化了带来的复杂得步骤.今 ...