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. 1.appium介绍

    appium介绍 官方网站 1.特点 appium 是一个自动化测试开源工具,支持 iOS 平台和 Android 平台上的原生应用,web应用和混合应用. “移动原生应用”是指那些用iOS或者 An ...

  2. 我的HTML总结之常用基础便签

    HTML:是Hyper Text Markup Language(超级文本标记语言)的缩写,HTML不是一种程序,只是一种控制网页中数据显示的标识语言. HTML由一组标签组成. HTML的基本结构 ...

  3. JQUERY实现点击INPUT使光标移动到最后或指定位置

    下面本文章给大家简单介绍一下JQUERY实现点击INPUT使光标移动到最后或指定位置例子,希望对各位有帮助,你要知道面对一个 处女座的 需求者, focus()是远远不够的,比如说“我点进去的时候光标 ...

  4. *92. Reverse Linked List II (follow up questions)

    Reverse a linked list from position m to n. Do it in one-pass and in-place Note: 1 ≤ m ≤ n ≤ length ...

  5. ubuntu16.4安装最新版wine3.0

    1.主体大致过程 $ wget https://dl.winehq.org/wine/source/3.0/wine-3.0.tar.xz $ tar -xvf wine-3.0.tar.xz $ c ...

  6. PIL 图像字符画绘制

    from PIL import Image ascii_char = list('"$%_&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]? ...

  7. Release模式下无法调试打印对象的解决方式

    之前碰到在release模式下无法打印对象的问题,只能切换到debug模式下调试, xcode release 模式下, 会关掉断点读取变量的上下文环境,以提高运行速度, ⚠️ 记得调试完再改回去,防 ...

  8. POJ Air Raid 【DAG的最小不相交路径覆盖】

    传送门:http://poj.org/problem?id=1422 Air Raid Time Limit: 1000MS   Memory Limit: 10000K Total Submissi ...

  9. 2018.10.31 Mac下的Mysql修改字符编码修改的问题总结

    今天在弄数据库的时候发现存入中文汉字变成了问号,Mac跟windows处理方式不一样. show variables like '%char%'; 查看当前mysql的编码格式 也就是默认编码格式 + ...

  10. SSH Secure Shell Client连接Linux断开

    修改/etc/ssh/sshd_config文件,将 ClientAliveInterval 0和ClientAliveCountMax 3的注释符号去掉,将ClientAliveInterval对应 ...