Cow Rectangles
Cow Rectangles
题目描述
输入
is located. The character is H or G, indicating the cow's breed. No two cows are located at the same point, and there is always at least one Holstein.
输出
样例输入
5
1 1 H
2 2 H
3 3 G
4 4 H
6 6 H
样例输出
2
1
分析:答案的矩形四个边界必然有H型牛;
所以可以枚举上下边界,对于左右边界双指针更新答案,复杂度O(N³);
注意要排除边界上G型牛;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=1e3+;
const int dis[][]={{,},{-,},{,-},{,}};
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m,k,t,y[maxn],ans[];
struct node
{
int x,y,z;
bool operator<(const node&p)const
{
if(x==p.x)return z<p.z;
else return x<p.x;
}
}a[maxn];
char b[];
int main()
{
int i,j;
scanf("%d",&n);
rep(i,,n-){
scanf("%d%d%s",&a[i].x,&a[i].y,b);
if(b[]=='H')a[i].z=,y[m++]=a[i].y;;
}
sort(a,a+n);
sort(y,y+m);
int num=unique(y,y+m)-y;
rep(i,,num-)rep(j,i,num-)
{
int l=-,r,now=,flag=-;
rep(k,,n-)
{
if(a[k].y>=y[i]&&a[k].y<=y[j])
{
if(!a[k].z)
{
flag=a[k].x;
if(now>ans[]||(now==ans[]&&(r-l)*(y[j]-y[i])<ans[]))
{
ans[]=now;
ans[]=(r-l)*(y[j]-y[i]);
}
now=,l=-;
}
else
{
if(a[k].x==flag)continue;
now++;
if(l!=-)r=a[k].x;
else l=a[k].x,r=a[k].x;
}
}
}
if(now>ans[]||(now==ans[]&&(r-l)*(y[j]-y[i])<ans[]))
{
ans[]=now;
ans[]=(r-l)*(y[j]-y[i]);
}
}
printf("%d\n%d\n",ans[],ans[]);
//system("Pause");
return ;
}
Cow Rectangles的更多相关文章
- 题解 P3117 【[USACO15JAN]牛的矩形Cow Rectangles】
暴力什么的就算了,贪心他不香吗 这题其实如果分开想,就三种情况需要讨论:(由于不会发图,只能手打) 1) 5 . . . . . 4 . . . . . 3 . . . H . 2 . . G . . ...
- 2018.09.29 bzoj3885: Cow Rectangles(悬线法+二分)
传送门 对于第一个问题,直接用悬线法求出最大的子矩阵面积,然后对于每一个能得到最大面积的矩阵,我们用二分法去掉四周的空白部分来更新第二个答案. 代码: #include<bits/stdc++. ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- POJ 3278 Catch That Cow(bfs)
传送门 Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 80273 Accepted: 25 ...
- 【BZOJ1623】 [Usaco2008 Open]Cow Cars 奶牛飞车 贪心
SB贪心,一开始还想着用二分,看了眼黄学长的blog,发现自己SB了... 最小道路=已选取的奶牛/道路总数. #include <iostream> #include <cstdi ...
- HDU Cow Sorting (树状数组)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2838 Cow Sorting Problem Description Sherlock's N (1 ...
- [BZOJ1604][Usaco2008 Open]Cow Neighborhoods 奶牛的邻居
[BZOJ1604][Usaco2008 Open]Cow Neighborhoods 奶牛的邻居 试题描述 了解奶牛们的人都知道,奶牛喜欢成群结队.观察约翰的N(1≤N≤100000)只奶牛,你会发 ...
- 细读cow.osg
细读cow.osg 转自:http://www.cnblogs.com/mumuliang/archive/2010/06/03/1873543.html 对,就是那只著名的奶牛. //Group节点 ...
- POJ 3176 Cow Bowling
Cow Bowling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13016 Accepted: 8598 Desc ...
随机推荐
- swf version 与flash player 对应关系
2013-04-16更新:更新Flash Player 11.7/AIR 3.7正式版. 详细链接FlashPlayer 11.7详情 2013-03-10更新:更新Flash Player 11.6 ...
- 运行出第一个程序Hello World、第二个程序网页浏览器
很长时间没有发博客记录我的奋斗历程了,原因不外乎遇到了对我而言“巨大的”困难. 经历了长期的找不到合适的教材.找不到Xcode资源.运行不出例程的痛苦以后,近日终于走上正轨. 现在补发一个过去2个月来 ...
- 解析:DNS 原理(入门篇)
DNS 是互联网核心协议之一.不管是上网浏览,还是编程开发,都需要了解一点它的知识. 本文详细介绍DNS的原理,以及如何运用工具软件观察它的运作.我的目标是,读完此文后,你就能完全理解DNS. 一.D ...
- /etc/rc.local 与 /etc/init.d Linux 开机自动运行程序
1. /etc/rc.local 这是使用者自订开机启动程序,把需要开机自动运行的程序写在这个脚本里 --------引用---------------------- 在完成 run level 3 ...
- vs找不到svn源代码管理插件之我见
使用svn要安装两个文件,一个客户端:TortoiseSVN-1.8.msi,一个插件:AnkhSvn-2.5.msi:两个都安装好之后,在vs的tool(工具)选项卡中,选择自定义,然后选择sour ...
- 前端 MVC 变形记
背景: MVC是一种架构设计模式,它通过关注点分离鼓励改进应用程序组织.在过去,MVC被大量用于构建桌面和服务器端应用程序,如今Web应用程序的开 发已经越来越向传统应用软件开发靠拢,Web和应用之间 ...
- masonry使用问题
2015年11月3日 coreData的学习练习中复习使用masonry自动布局 masonry自动布局发现问题: 两个控件的相对布局: 如果被参考对象用这个带anchor的属性,就会报这样一个错误: ...
- MSSQL存储过程接收另一个存储过程返回列表
CREATE TABLE #tmp(m_Meter_ID varchar(20),low_Voltage int,num_Attack int,num_DER int,company_id int,a ...
- **ERROR: Ninja build tool not found.
| if which ninja-build ;\| then \| ln -s `which ninja-build` bin/ninja ;\| else \| echo "***ERR ...
- actor
_timcharper1月 20 02:18 @timcharper , so what app the actor model can help, and what app the thread m ...