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 ...
随机推荐
- 什么是SWP文件?能否删除swp文件?
SWP意思就是交换文件..SWP是各种操作系统(Windows或Linux)使用的交换文件的文件扩展名. 可以安全地清理SWP文件以释放磁盘空间. 要清理SWP文件,请按照以下步骤操作: 运行WinU ...
- 最重要的“快捷键” IntelliJ IDEA
转载:http://www.youmeek.com/intellij-idea-part-iii-hotkeys-explain/ @IntelliJ IDEA第三部分视频教程:最重要的“快捷键”专讲 ...
- [18/12/03] 多态(polymorphism)和对象的转型(casting)
一.多态 多态指的是同一个方法调用,由于对象不同可能会有不同的行为.现实生活中,同一个方法,具体实现会完全不同. 比如:同样是调用人的“休息”方法,张三是睡觉,李四是旅游,同样是调用人“吃饭”的方法, ...
- ASP.NET Web API 自定义MediaType实现jsonp跨域调用
代码来自<ASP.NET Web API 2 框架揭秘>一书. 直接上代码: /// <summary> /// 自定义jsonp MediaType /// </sum ...
- Windows下同时安装Anaconda2与Anaconda3
1. 安装一个作为主版本,比如先安装Anaconda2,安装时选择[添加path环境变量].我的安装地址为:E:\ProgramData\Anaconda3 2. 安装另一个版本python,安装时注 ...
- 统计决策——贝叶斯决策理论(Bayesian Decision Theory)
(本文为原创学习笔记,主要参考<模式识别(第三版)>(张学工著,清华大学出版社出版)) 1.概念 将分类看做决策,进行贝叶斯决策时考虑各类的先验概率和类条件概率,也即后验概率.考虑先验概率 ...
- 【洛谷P1879】玉米田Corn Fields
玉米田Corn Fields 题目链接 此题和互不侵犯状压DP的做法类似 f[i][j]表示前i行,第i行种植(1)/不种植(0)构成的二进制数为j时的方案数 首先我们可以预处理出所有一行中没有两个相 ...
- 【luogu P2939 [USACO09FEB]改造路Revamping Trails】 题解
题目链接:https://www.luogu.org/problemnew/show/P2939 本来说是双倍经验题,跟飞行路线一样的,结果我飞行路线拿deque优化SPFA过了这里过不了了. 所以多 ...
- 【luogu P3381 最小费用最大流】 模板
题目链接:https://www.luogu.org/problemnew/show/P3381 把bfs变成spfa #include <queue> #include <cstd ...
- JavaScript函数的方法
在一个对象中绑定函数,称为这个对象的方法. 在JavaScript中,对象的定义是: var xiaoming = { name:'小明'; birth:1990; }; 但是,如果我们给xiaomi ...