2018深圳 CCPC final I - Cockroaches 模拟技巧

题目链接:https://vjudge.net/contest/342441#problem/I

题意:有n个蟑螂,每个杀虫剂可以杀死所在格子的行列的蟑螂问,只用一个杀虫剂杀死最大蟑螂的位置有几种,杀多少只。

思路:暴力模拟,要注意杀虫剂可能在蟑螂身上。。。

错了很多次,写下博客。

ac代码:

#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <queue>
#include <map>
#include <iterator>
using namespace std;
typedef long long ll;
const ll mx = 2e5+100;
const ll mod = 1e9+7;

map<int, int>ml, mr;
int x[mx], y[mx];

int main() {
    int n, m, q, k;
    scanf("%d", &q);
    for (ll i = 1; i <= q; ++i) {
        printf("Case %lld: ", i);
        ml.clear();
        mr.clear();
        ll sum, l = 0, r = 0, al = 0, bl = 0;
        int mxx = 0, myy = 0;
        scanf("%d", &n);
        for(int j = 0; j < n; ++j) {
            scanf("%d%d", &x[j], &y[j]);
            ml[x[j]]++;
            mr[y[j]]++;
        }
        if (n == 1) puts("1 1");
        else {
            map<int,int>::iterator a = ml.begin(), b = mr.begin();
            for (;a != ml.end(); a++) {
                if (a->second == al) l++;
                if (a->second > al) al = a->second, l = 1;
            }
            for (;b != mr.end(); b++) {
                if (b->second == bl) r++;
                if (b->second > bl) bl = b->second, r = 1;
            }
            sum = al+bl;
            ll su = l*r;
            for (int j = 0; j < n; ++j) {
                if (ml[x[j]]+mr[y[j]] == sum) su--;
            }
            if (!su) {
                sum--;
                su = l*r;
                a = ml.begin(), b = mr.begin();
                for (; a!= ml.end(); ++a) {
                    if (a->second == al-1) su+=r;
                }
                for (; b!= mr.end(); ++b) {
                    if (b->second == bl-1) su+=l;
                }
                for (int j = 0; j < n; ++j) {
                    if (ml[x[j]]+mr[y[j]] == sum) su--;
                }
            }
            if (sum == 2) printf("%lld %lld\n", sum, su/2);
            else printf("%lld %lld\n", sum, su);
        }
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值