【题目链接】: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. BZOJ 2780 Sevenk Love Oimaster (后缀自动机+树状数组+dfs序+离线)

    题目大意: 给你$n$个大串和$m$个询问,每次给出一个字符串$s$询问在多少个大串中出现过 好神的一道题 对$n$个大串建出广义$SAM$,建出$parent$树 把字符串$s$放到$SAM$里跑, ...

  3. [luogu2151 SDOI2009] HH去散步 (矩阵快速幂)

    传送门 题目描述 HH有个一成不变的习惯,喜欢饭后百步走.所谓百步走,就是散步,就是在一定的时间 内,走过一定的距离. 但是同时HH又是个喜欢变化的人,所以他不会立刻沿着刚刚走来的路走回. 又因为HH ...

  4. 六、利用frp穿透连接内网的linx系统和windows系统

    服务端的配置 # frps.ini [common] bind_port = 7000 说明:防火墙放行该端口 启动:./frps -c ./frps.ini 后台启动:nohup ./frps -c ...

  5. Proxifier安装与使用

    Proxifier安装与使用 1.Proxifier官网可能打不开,这是一个下载地址,提取码为p1l8. 用户名随意填 注册码下边 5EZ8G-C3WL5-B56YG-SCXM9-6QZAP G3ZC ...

  6. ES6之用let,const和用var来声明变量的区别

    var(掌握) 不区分变量和常量   用var声明的变量都是变量,都是可变的,我们可以随便对它进行运算操作.这样当多个人进行同一个项目时,区分变量和常量会越来越难,一不小心就会把设计为常量的数据更改了 ...

  7. [luogu] P4823 [TJOI2013]拯救小矮人(贪心)

    P4823 [TJOI2013]拯救小矮人 题目描述 一群小矮人掉进了一个很深的陷阱里,由于太矮爬不上来,于是他们决定搭一个人梯.即:一个小矮人站在另一小矮人的 肩膀上,知道最顶端的小矮人伸直胳膊可以 ...

  8. WinServer-IIS-IIS负载均衡

    安装应用程序路由 提供的服务器的地址必须是可以访问,不然无法进入到下面的这个管理界面 来自为知笔记(Wiz)

  9. 带输出參数的存储过程的定义,以及在aso.net中调用

    ALTER proc [dbo].[mp_w_RechargePortalPayPal_All] ( @PayPalOrderNo nvarchar(50), --订单号 @nAccountIDFro ...

  10. IE input X 去掉文本框的叉叉和password输入框的眼睛图标

    IE input X 去掉文本框的叉叉和password输入框的眼睛图标 从IE 10開始,type="text" 的 input 在用户输入内容后.会自己主动产生一个小叉叉(X) ...