牛客练习赛104 A 放羊的贝贝

https://ac.nowcoder.com/acm/contest/43058/A

思路

实质上就是找一个最小的长方形,这波真的是小学题,就不证明了

要注意开\(long\ \ long\)(按理说只有2e9不应该会炸int呀)

代码

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cctype>
#include<bitset>
#define ll long long
#define gc getchar
#define maxn 10005
using namespace std;

inline ll read(){
	ll a=0;int f=0;char p=gc();
	while(!isdigit(p)){f|=p=='-';p=gc();}
	while(isdigit(p)){a=(a<<3)+(a<<1)+(p^48);p=gc();}
	return f?-a:a;
}ll n,m,k,lx,ly,rx,ry;

int main(){
	n=read();m=read();k=read();
	lx=read();ly=read();rx=read();ry=read();
	while(k--){
		ll x=read(),y=read();
		lx=min(lx,x),rx=max(rx,x+1);
		ly=min(ly,y),ry=max(ry,y+1);
	}
	printf("%lld\n",(rx-lx+ry-ly)<<1);
	return 0;
}
posted @ 2022-10-21 21:41  子谦。  阅读(35)  评论(0编辑  收藏  举报
Live2D
//雪