回收站选址

试题编号: 201912-2
试题名称: 回收站选址
时间限制: 1.0s
内存限制: 512.0MB
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
题目解析:使用map数组可以很快地查找到该点是否存在,使用longlong数组应该可以,不过判断起来应该有些麻烦,我没写。

代码:

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<string.h>
#include<iostream>
#include<iomanip>
#include<fstream>
//#include<regex>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;  

const int N = 1000;
pair<int, int> p[N];
const int CN = 4;
int cnt[CN + 1];

int main()
{
    int n;
    map<pair<int, int>, int> ps;

    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        int x, y;
        scanf("%d%d", &x, &y);

        p[i] = make_pair(x, y);
        ps[p[i]] = 1;
    }

    memset(cnt, 0, sizeof(cnt));
    for(int i = 0; i < n; i++) {
        int x = p[i].first;
        int y = p[i].second;

        if(ps[make_pair(x, y -1)] && ps[make_pair(x, y + 1)] &&
                ps[make_pair(x - 1, y)] && ps[make_pair(x + 1, y)])
            cnt[ps[make_pair(x - 1, y - 1)] + ps[make_pair(x - 1, y + 1)] +
                    ps[make_pair(x + 1, y - 1)] + ps[make_pair(x + 1, y + 1)]]++;
    }

    for(int i = 0; i <= CN; i++)
        printf("%d\n", cnt[i]);

    return 0;
}

/*
7
1 2
2 1
0 0
1 1
1 0
2 0
0 1

2
0 0
-100000 10

11
9 10
10 10
11 10
12 10
13 10
11 9
11 8
12 9
10 9
10 11
12 11

*/

/* 
 
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<string.h>
#include<fstream>
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std; 
const int N = 1000;
int main()
{
    int n , x, y;
    map<pair<int, int>, int> ps;
	pair<int,int> p[N];
	map<int,int> rst;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> x >> y;
        p[i] = make_pair(x, y);
        ps[p[i]] = 1;
    }

    for(int i = 0; i < n; i++) {
        int x = p[i].first;
        int y = p[i].second;
		int score = 0;
        if(ps[make_pair(x, y -1)] && ps[make_pair(x, y + 1)] &&
                ps[make_pair(x - 1, y)] && ps[make_pair(x + 1, y)]){
                	rst[ps[make_pair(x - 1, y - 1)] + ps[make_pair(x - 1, y + 1)] +
                    ps[make_pair(x + 1, y - 1)] + ps[make_pair(x + 1, y + 1)]]++;
                    
				}
            
    }

    for(int i = 0; i <= 4; i++)
        cout << rst[i] << endl;

    return 0;
}
*/

/*测试用例
11
9 10
10 10
11 10
12 10
13 10
11 9
11 8
12 9
10 9
10 11
12 11

2
0 0
-100000 10

7
1 2
2 1
0 0
1 1
1 0
2 0
0 1

*/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值