2018 ccpc final I. Cockroaches
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的更多相关文章
- 2018 CCPC 桂林游记
TYPE: Onsite Contest NAME: 2018 - CCPC - Guilin PLAT: HUSTOJ TIME: 2018/10/28 09:00-14:00 CST LOCA: ...
- 2018 CCPC网络赛
2018 CCPC网络赛 Buy and Resell 题目描述:有一种物品,在\(n\)个地点的价格为\(a_i\),现在一次经过这\(n\)个地点,在每个地点可以买一个这样的物品,也可以卖出一个物 ...
- 2018 CCPC 桂林站(upc复现赛)补题
2018 CCPC 桂林站(upc复现赛)补题 G.Greatest Common Divisor(思维) 求相邻数的差值的gcd,对gcd分解素因子,对所有的素因子做一次遍历,找出最小答案. 几个样 ...
- 2018 CCPC 吉林站 H Lovers
2018 CCPC 吉林站 H Lovers 传送门:https://www.spoj.com/problems/LIS2/en/ 题意: q次操作 1.将第l~r个数的左边和和右边都加上一个数d, ...
- CCPC final Cockroaches
算法假了,我想的是通过枚举x,删除y的影响,这样答案第一个是没有任何问题的,但是第二个会算重复. 因为我枚举每一个x的时候,得到的y,而算另外一个x的时候,可能已经通过其他的点选到了这个点y这就有点麻 ...
- 2018 CCPC网络赛 几道数学题
1002 Congruence equation 题目链接 : http://acm.hdu.edu.cn/showproblem.php?pid=6439 题解 : https://www.zyb ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- JavaScript 三种工厂模式
标签(空格分隔): JavaScript 简单工厂模式是工厂函数返回实例化对象或者对象,工厂函数作为一个方法. 工厂方法模式是工厂函数不作改变,将子类放在工厂原型中:工厂函数返回对应的实例化对象:re ...
- Docker入门系列之三:如何将dockerfile制作好的镜像发布到Docker hub上
这个系列的前两篇文章,我们已经把我们的应用成功地在Docker里通过nginx运行了起来,并且用dockerfile里制作好了一个镜像. Docker入门系列之一:在一个Docker容器里运行指定的w ...
- SAP+DB2 糟糕的报表查询『ZCOR0015』 优化全程记录
ZCOR0015的优化全过程记录文档 2015年3月,今天无意翻到这篇写于2010年7月的文档,回想那时的工作,毕业3年初出茅庐的我面对接触不多的SAP+DB2竟敢操刀动斧,自信满满. 虽然这过程一路 ...
- 设计模式——模板方法模式(TemplateMethod Pattern)
模板方法模式:定义一个操作中的算法的骨架,而将一些步骤延迟到子类中.模板方法使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤. UML图: 抽象模板: package com.cnblo ...
- BZOJ3053:The Closest M Points(K-D Teee)
Description The course of Software Design and Development Practice is objectionable. ZLC is facing a ...
- 【[HEOI2012]采花】
\(HH\)的项链加强版,数据范围和题意都加强了 题意大概:给出n个数,求区间出现次数>=2的数的个数. 一眼莫队,可是我还不会莫队啊 那就树状数组吧 回忆一下\(HH\)的项链,套路差不多,那 ...
- 【[AHOI2012]树屋阶梯】
卡特兰数! 至于为什么是卡特兰数,就稍微说那么一两句吧 对于一个高度为\(i\)的阶梯,我们可以在左上角填一个高度为\(k\)的阶梯,右下角填一个高度为\(i-1-k\)的阶梯剩下的我们用一个大的长方 ...
- C# 利用HttpWebRequest进行HTTPS的post请求的示例
最近一个推送信息的目标接口从http格式换成https格式,原来的请求无法正常发送,所以修改了发送请求的方法.标红的代码是新加了,改了之后就可以正常访问(不检测证书的) public static s ...
- Entity Framework 四
实体框架支持三种类型的查询:1)LINQ to Entities,2)Entity SQL,3)Native SQL LINQ方法语法: LINQ查询语法: 实体SQL: 这种可以简单的了解,不必深入 ...
- python学习笔记--数据类型
Life is short, You need Python! 霸气的口号! 今天我也开始学python了,毕竟不懂后端的前端不是好前端.之前有过‘世界上最好的语言’和JavaScript的学习经验. ...