I. Cockroaches
time limit per test6. s
memory limit per test256 MB
inputstandard input
outputstandard output
There are N cockroaches in the field. Cockroach i is located at coordinate (xi,yi). No two cockroaches are located at the same spot. Boss Luo has a powerful pesticide that can instantly kill all cockroaches on the horizontal and vertical line of the spot where it is used. i.e. cockroaches with either the same x coordinate or y coordinate as the pesticide spot will be killed. Boss Luo wonders how many cockroaches can be killed at most when the pesticide is used in one spot. He is also interested in the number of different subsets of the annihilated cockroaches when the pesticide kills most cockroaches. Input
The first line of the input gives the number of test cases, T (≤T≤). T test cases follow. For each test case, the first line contains an integers N (≤N≤), the number of cockroaches. The next N lines each contains two integers x and y (≤x,y≤), describing the coordinates of the cockroaches. For at least test cases, it is guaranteed that N≤. Output
For each test case, output one line containing "Case x: y z", where x is the test case number (starting from ), y is the maximum number of cockroaches that can be killed with pesticide applied on one spot, and z is the number of different subsets of the annihilated cockroaches when the pesticide kills most cockroaches. Example
inputCopy outputCopy
Case :
Case :
Note
For test case , cockroaches can be killed if the pesticide is used optimally. There are possible subsets: {,,},{,,},{,,},{,,},{,,}. For test case , cockroaches can be kill at best. All subsets with cockroaches are possible: {,},{,},{,}.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <utility>
#include <vector>
using namespace std;
#define ll long long
#define P pair<ll,ll>
int t;
ll n;
ll maxx,maxy,max_x;
ll cntx1,cntx2,cnty1,cnty2;
ll cnt1,cnt2;
/*
记录每个点的横纵坐标所在行列的点的数目
找到最大的maxx,maxy,max_x = maxx+maxy
其实消灭蟑螂的最大数目只能是max_x,或者max_x-1
cnt1 : max_x 的集合数目
cnt2 : max_x -1 集合数目
*/
int main()
{
scanf("%d",&t);
for(int i =;i<=t;i++)
{
scanf("%lld",&n);
map<ll,ll>cntx,cnty;
vector<P>ve(n);//必须为 (),
maxx=;maxy=;
for(auto &it : ve){//前面ve(n)一定要是n,不然输入不完
scanf("%d%d",&it.first,&it.second);
maxx = max(maxx,++cntx[it.first]);
maxy = max(maxy,++cnty[it.second]);
}
//两个if为特判
if(cntx.size()==||cnty.size()==){
printf("Case %d: %lld 1\n",i,n);
continue;
//cntx.size()==1时全在一列,只有maxx,不存在maxx-1
}
if(maxx==&&maxy==){ //一定是&&
printf("Case %d: 2 %lld\n",i,n*(n-)/);
continue;
}
cntx1=,cntx2=;cnty1=,cnty2=;
for(auto &it : cntx){
if(it.second==maxx) cntx1++;
else if(it.second==maxx-) cntx2++;
}
for(auto &it : cnty){
if(it.second==maxy) cnty1++;
else if(it.second==maxy-) cnty2++;
}
max_x = maxx+maxy;//在最好情况下,下面的两个式子成立
cnt1=cntx1*cnty1;cnt2=cntx1*cnty2+cnty1*cntx2;
//只需要遍历输入的所有点,因为cntx[]==0||cnty[]==0的无意义
for(auto &it : ve){
ll num = cntx[it.first]+cnty[it.second];
if(num==max_x) {
cnt1--;//这个点会让max_x变为max_x -1
cnt2++;
}
else if(num==max_x-) cnt2--;//这个点会让max_x -1变为max_x -2
}
if(cnt1>) {
printf("Case %d: %lld %lld\n",i,max_x,cnt1);
}
else
printf("Case %d: %lld %lld\n",i,max_x-,cnt2);
}
return ;
}

2018 ccpc final I. Cockroaches的更多相关文章

  1. 2018 CCPC 桂林游记

    TYPE: Onsite Contest NAME: 2018 - CCPC - Guilin PLAT: HUSTOJ TIME: 2018/10/28 09:00-14:00 CST LOCA: ...

  2. 2018 CCPC网络赛

    2018 CCPC网络赛 Buy and Resell 题目描述:有一种物品,在\(n\)个地点的价格为\(a_i\),现在一次经过这\(n\)个地点,在每个地点可以买一个这样的物品,也可以卖出一个物 ...

  3. 2018 CCPC 桂林站(upc复现赛)补题

    2018 CCPC 桂林站(upc复现赛)补题 G.Greatest Common Divisor(思维) 求相邻数的差值的gcd,对gcd分解素因子,对所有的素因子做一次遍历,找出最小答案. 几个样 ...

  4. 2018 CCPC 吉林站 H Lovers

    2018 CCPC 吉林站 H Lovers 传送门:https://www.spoj.com/problems/LIS2/en/ 题意: q次操作 1.将第l~r个数的左边和和右边都加上一个数d, ...

  5. CCPC final Cockroaches

    算法假了,我想的是通过枚举x,删除y的影响,这样答案第一个是没有任何问题的,但是第二个会算重复. 因为我枚举每一个x的时候,得到的y,而算另外一个x的时候,可能已经通过其他的点选到了这个点y这就有点麻 ...

  6. 2018 CCPC网络赛 几道数学题

    1002 Congruence equation 题目链接  : http://acm.hdu.edu.cn/showproblem.php?pid=6439 题解 : https://www.zyb ...

  7. 2018 CCPC网络赛 hdu6444 Neko's loop

    题目描述: Neko has a loop of size n.The loop has a happy value ai on the i−th(0≤i≤n−1) grid. Neko likes ...

  8. 2018 CCPC 网络赛 Buy and Resell

    The Power Cube is used as a stash of Exotic Power. There are n cities numbered 1,2,…,n where allowed ...

  9. 2018 CCPC网络赛 1010 hdu 6447 ( 树状数组优化dp)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=6447 思路:很容易推得dp转移公式:dp[i][j] = max(dp[i][j-1],dp[i-1][j ...

随机推荐

  1. 字段处理rtrim去掉结尾的特殊字符和空格

    SQL> create table ycrtest2 (name varchar2(50)); Table created. SQL> insert into ycrtest2 value ...

  2. Orchard Core 文档翻译 (七)Contents

    CMS Modules »Contents Contents (OrchardCore.Contents) 此模块提供内容管理服务. Liquid 您可以使用“content ”属性从liquid 视 ...

  3. Template Pattern & Strategy Pattern

    详细见<C++设计模式 23种设计模式.pdf 55页> 在面向对象系统的分析与设计过程中经常会遇到这样一种情况:对于某一个业务逻辑(算法实现)在不同的对象中有不同的细节实现,但是逻辑(算 ...

  4. 2018.11.7 关于将Web项目部署到阿里云服务器-5个步骤搞定

    将Eclipse导出的War包部署到阿里云服务器上,提供给移动端实时的访问 1. 先登录阿里云网站注册账号,选择服务器类型(我用的是 云服务器ECS), 如果你还是在读大学生可享受优惠价,最低好像是9 ...

  5. Webstorm 添加新建.vue文件功能并支持高亮vue语法和es6语法

    添加新建.vue文件功能 ①Webstorm 右上角File-Plugins 搜索vue如果没有就去下载 点击serch in repositories ②点击安装vue.js ③安装成功后点击右下角 ...

  6. SpeedTree制作超真实老宅

  7. WPF窗口模板——Style样式

    通用模板,窗口样式 <!-- 通用窗口模板 --> <ControlTemplate x:Key="CustomWindowTemplate" TargetTyp ...

  8. shiro框架 4种授权方式 说明

    1. shiro的配置文件(applicationContext-shiro.xml)中使用filterChain过滤url的方式 详细配置看注释 <?xml version="1.0 ...

  9. JS定时器和单线程异步特性

    首先要说的是,定时器相关的方法都是属于BOM方法,而定时器呢,它是用于在设定的时间执行一段代码,或者在给定的时间间隔内重复该代码.具体函数: setTimeout(callback, delay);/ ...

  10. 【模板】全排列(运用STL的next_permutation)

    (1) 先将要排列的数据存入数组中: (2) 再将数组元素从小到大排序: (3) 每次调用next_permutation函数,都只进行1次排列,若数组元素完全变为递减的排列,则该函数返回0: int ...