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 ;
}

最新文章

  1. JAVA Collections工具类sort()排序方法
  2. php set_time_limit()用法测试详解
  3. Thomas Brinkhoff 基于路网的移动对象生成器的使用
  4. js 抽奖转盘实现
  5. CentOS下源码安装MySQL
  6. [转]理解WSRF之一 使用WS-ResourceProperties (整理自IBM网站)
  7. 理解 strcpy方法
  8. PhpStorm快捷键设置/个性化设置,
  9. Mysql 列转行group_concat函数,与行转列
  10. OD: Register, Stack Frame, Function Reference
  11. select操作
  12. mysql utf8 中文
  13. linux c in common use function reference manual
  14. net搭建热插拔式web框架(沙箱的构建)
  15. EditText 限制输入整数和小数 的位数
  16. POJ2385——Apple Catching
  17. Scratch 数字游戏
  18. jvm是如何管理内存的 .ZT
  19. Zabbix使用微信发送告警(附Python代码)
  20. C# 趣味小程序(4)——遍历特定目录及其子目录

热门文章

  1. 开发时复制aspx网页的方法
  2. 配置环境变量时,cmd下运行java -version,报错:找不到或无法加载主类 -version
  3. 设计模式——简单工厂模式(SimpleFactory Pattern)
  4. bootstrap table通过ajax获取后台数据展示在table
  5. 前端开发css禁止选中文本
  6. Gym - 101334E 多叉树遍历
  7. 「SDOI2008沙拉公主的困惑」
  8. Codeforces Round #340 (Div. 2) E. XOR and Favorite Number 【莫队算法 + 异或和前缀和的巧妙】
  9. 【题解】洛谷P3205【HNOI2010】合唱队
  10. js动画之requestAnimationFrame