Radar Scanner Gym - 102220G
题目链接:https://vjudge.net/problem/Gym-102220G
题意:在水平直角坐标系中有n个矩形,你可以将矩形沿着平行于X轴和Y轴水平移动,问至少经过几次移动可以使得所有的矩形都有公共顶点。
思路:可以把每一个矩形看成一段线段,对线段进行移动,沿着平行于X轴和Y轴移动算法是一样的都是d=(abs(x1-x)+abs(x2-x)-abs(x1-x2))/2;最终只要把每一个d加起来即可。现在怎么求这个公共点(x,y),因为abs(x1-x2)是定值所以不用考虑,那么显然(x,y)就是这么多(x1,y1),(x2,y2),(x3,y3)........(xn,yn)中的中位数点。
1 #include <bits/stdc++.h>
2 #include <time.h>
3 #include <set>
4 #include <map>
5 #include <stack>
6 #include <cmath>
7 #include <queue>
8 #include <cstdio>
9 #include <string>
10 #include <vector>
11 #include <cstring>
12 #include <utility>
13 #include <cstring>
14 #include <iostream>
15 #include <algorithm>
16 #include <list>
17 using namespace std;
18 //cout<<setprecision(10)<<fixed;
19 #define eps 1e-6
20 #define PI acos(-1.0)
21 #define lowbit(x) ((x)&(-x))
22 #define zero(x) (((x)>0?(x):-(x))<eps)
23 #define mem(s,n) memset(s,n,sizeof s);
24 #define rep(i,a,b) for(int i=a;i<=b;i++)
25 #define rep2(i,a,b) for(int i=a;i>=b;i--)
26 #define ios {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
27 typedef long long ll;
28 typedef unsigned long long ull;
29 const int maxn=1e6+5;
30 const ll Inf=0x7f7f7f7f7f7f7f;
31 const ll mod=1e6+3;
32 //const int N=3e3+5;
33 bool isPowerOfTwo(int n) { return n > 0 && (n & (n - 1)) == 0; }//判断一个数是不是 2 的正整数次幂
34 int modPowerOfTwo(int x, int mod) { return x & (mod - 1); }//对 2 的非负整数次幂取模
35 int getBit(int a, int b) { return (a >> b) & 1; }// 获取 a 的第 b 位,最低位编号为 0
36 int Max(int a, int b) { return b & ((a - b) >> 31) | a & (~(a - b) >> 31); }// 如果 a>=b,(a-b)>>31 为 0,否则为 -1
37 int Min(int a, int b) { return a & ((a - b) >> 31) | b & (~(a - b) >> 31); }
38 ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
39 ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
40 inline int read()
41 {
42 int X=0; bool flag=1; char ch=getchar();
43 while(ch<'0'||ch>'9') {if(ch=='-') flag=0; ch=getchar();}
44 while(ch>='0'&&ch<='9') {X=(X<<1)+(X<<3)+ch-'0'; ch=getchar();}
45 if(flag) return X;
46 return ~(X-1);
47 }
48 inline void write(int X)
49 {
50 if(X<0) {X=~(X-1); putchar('-');}
51 if(X>9) write(X/10);
52 putchar(X%10+'0');
53 }
54 /*
55 inline int write(int X)
56 {
57 if(X<0) {putchar('-'); X=~(X-1);}
58 int s[20],top=0;
59 while(X) {s[++top]=X%10; X/=10;}
60 if(!top) s[++top]=0;
61 while(top) putchar(s[top--]+'0');
62 }
63 */
64 int Abs(int n) {
65 return (n ^ (n >> 31)) - (n >> 31);
66 /* n>>31 取得 n 的符号,若 n 为正数,n>>31 等于 0,若 n 为负数,n>>31 等于 -1
67 若 n 为正数 n^0=n, 数不变,若 n 为负数有 n^(-1)
68 需要计算 n 和 -1 的补码,然后进行异或运算,
69 结果 n 变号并且为 n 的绝对值减 1,再减去 -1 就是绝对值 */
70 }
71 ll binpow(ll a, ll b) {
72 ll res = 1;
73 while (b > 0) {
74 if (b & 1) res = res * a%mod;
75 a = a * a%mod;
76 b >>= 1;
77 }
78 return res%mod;
79 }
80 void extend_gcd(ll a,ll b,ll &x,ll &y)
81 {
82 if(b==0) {
83 x=1,y=0;
84 return;
85 }
86 extend_gcd(b,a%b,x,y);
87 ll tmp=x;
88 x=y;
89 y=tmp-(a/b)*y;
90 }
91 ll mod_inverse(ll a,ll m)
92 {
93 ll x,y;
94 extend_gcd(a,m,x,y);
95 return (m+x%m)%m;
96 }
97 ll eulor(ll x)
98 {
99 ll cnt=x;
100 ll ma=sqrt(x);
101 for(int i=2;i<=ma;i++)
102 {
103 if(x%i==0) cnt=cnt/i*(i-1);
104 while(x%i==0) x/=i;
105 }
106 if(x>1) cnt=cnt/x*(x-1);
107 return cnt;
108 }
109 ll x[maxn],y[maxn];
110 ll ans=0;
111 int main()
112 {
113 int t,n;
114 t=read();
115 while(t--)
116 {
117 n=read();
118 ll x1,y1,x2,y2;
119 ans=0;
120 for(int i=0;i<n;i++)
121 {
122 scanf("%lld%lld%lld%lld",&x1,&y1,&x2,&y2);
123 ans-=y2-y1+x2-x1;
124 x[i]=x1;
125 x[i+n]=x2;
126 y[i]=y1;
127 y[i+n]=y2;
128 }
129 sort(x,x+n+n);
130 sort(y,y+n+n);
131 ll xx=x[n-1],yy=y[n-1];
132 for(int i=0;i<2*n;i++)
133 ans+=abs(x[i]-xx)+abs(y[i]-yy);
134 printf("%lld\n",ans/2);
135 }
136 return 0;
137 }
Radar Scanner Gym - 102220G的更多相关文章
- G - Radar Scanner Gym - 102220G(中位数~~)
zThere are n rectangle radar scanners on the ground. The sides of them are all paralleled to the axe ...
- 2018 Multi-University Training Contest 3 - HDU Contest
题解: solution Code: A. Ascending Rating #include<cstdio> const int N=10000010; int T,n,m,k,P,Q, ...
- 2018 Multi-University Training Contest 3 Solution
A - Problem A. Ascending Rating 题意:给出n个数,给出区间长度m.对于每个区间,初始值的max为0,cnt为0.遇到一个a[i] > ans, 更新ans并且cn ...
- The 13th Chinese Northeast Collegiate Programming Contest
题解: solution Code: A. Apple Business #include<cstdio> #include<algorithm> #include<ve ...
- The 13th Chinese Northeast Collegiate Programming Contest(B C E F H J)
B. Balanced Diet 思路:把每一块选C个产生的价值记录下来,然后从小到大枚举C. #include<bits/stdc++.h> using namespace std; ; ...
- Codeforces Gym 100269B Ballot Analyzing Device 模拟题
Ballot Analyzing Device 题目连接: http://codeforces.com/gym/100269/attachments Description Election comm ...
- Codeforces Gym 100338H High Speed Trains 组合数学+dp+高精度
原题链接:http://codeforces.com/gym/100338/attachments/download/2136/20062007-winter-petrozavodsk-camp-an ...
- Codeforces Gym 100431B Binary Search 搜索+组合数学+高精度
原题链接:http://codeforces.com/gym/100431/attachments/download/2421/20092010-winter-petrozavodsk-camp-an ...
- codeforces Gym 100735 D、E、G、H、I
http://codeforces.com/gym/100735 D题 直接暴力枚举 感觉这道题数据有点问题 为什么要先排下序才能过?不懂.. #include <stdio.h> #in ...
随机推荐
- 计算机网络 part3 HTTP&HTTPS
一.HTTP references: HTTP [HTTP协议]---HTTP协议详解 1.概述.特点 HTTP(超文本传输协议)是一种规定了浏览器和万维网服务器通信规则的协议.客户端和服务端的指定接 ...
- μC/OS-III---I笔记7---消息队列
消息队列 任务之间仅仅靠信号量进行"沟通"是不够的,信号量可以标志事件的发生,却无法传递更多的数据,在需要任务间的数据信息传递时就绪要用到消息队列,传统我们一般在前后太系统中都是通 ...
- vue-cli emit webpack config
vue-cli emit webpack config 如何暴漏出 vue-cli 的 webpack 配置文件 refs xgqfrms 2012-2020 www.cnblogs.com 发布文章 ...
- Nginx环境下,PHP下载,中文文件,下载失效(英文可以下载)怎么解决呢?
参考出处: http://www.imooc.com/qadetail/76393 Nginx环境下,PHP下载,中文文件,下载失效(英文可以下载)怎么解决呢? 背景介绍: 文件名 为英文时可以下载 ...
- Jamstack Conf 2020
Jamstack Conf 2020 Jamstack Conf Virtual https://jamstackconf.com/virtual/ Conf Schedule https://jam ...
- 抓手 & 技术管理
抓手 & 技术管理 https://zhuanlan.zhihu.com/p/28891618 技术管理的目的 管理就是通过别人拿到结果.而管理的两个着眼点就是:成事.育人. 把事情搞定,把人 ...
- modal 遮罩层,滚动穿透 bug
modal 遮罩层,滚动 穿透bug float 弹层 taro 小程序弹框 滚动击穿 问题 https://segmentfault.com/q/1010000011134345 solution ...
- multi selects & mutually exclusive
multi selects & mutually exclusive 互斥 selects import React, { useState, // useEffect, // useRef, ...
- css grid layout in practice
css grid layout in practice https://caniuse.com/#search=grid subgrid https://caniuse.com/#search=cal ...
- NGK八大板块:为何郊区市场近来火爆?-VALAITIS, PETER ANTHONY分析
PAUL ADAMS ARCHITECT LTD董事长VALAITIS, PETER ANTHONY称受大环境影响很多纽约人都选择离开纽约市中心,搬往附近郊区,因此附近地区楼市开始不断升温. 根据房地 ...