栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

1026. 皇后问题

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

1026. 皇后问题


样例:
input:
3
1 1
1 2
1 3
output:
3

input:
2
1 1
2 2
output:
1

input:
4
1 3
2 1
3 4
4 2
output:
0
思路:
一开始的思路其实是想记录一下出现在某一行某一列的皇后个数,然后发现对角线的没有办法操作,所以把每个皇后能走到的位置都标记下来,这样就能算出有多少对,当然在题目所给的这个数据范围里,显然是会wa的,如果都是100以内的,那可以使用。
60分做法:

#include 
#include 
#include 
using namespace std;
int n;
int num[11111][11111];
void mark(int x,int y)
{

	for(int i=1;i<=n;i++) num[x][i]++;
    for(int i=1;i<=n;i++) num[i][y]++;
    for(int i=1;in||tempy>n) break;
        num[tempx][tempy]++;
    }
    for(int i=1;in||tempy<1) break;
        num[tempx][tempy]++;
    }
    for(int i=1;in) break;
        num[tempx][tempy]++;
    }
}
int main()
{
    cin>>n;
    int x,y,cnt;
	for(int i=1;i<=n;i++)
    {
        cin>>x>>y;
        if(num[x][y]!=0) cnt+=num[x][y];
        mark(x,y);
        //cout<<"i="<
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/330582.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号