题目链接:https://ac.nowcoder.com/acm/contest/883/H

题目大意

  给定 N 个不同的整数点,N 为偶数,求一条直线,这条直线能把这 N 个点对半分开,输出这条直线经过的两个整点坐标。

分析1

  在无穷远处选一个点(我选两个互质的质数),设为$(x, y)$,然后极角排序,然后取最中间两个点的中点,设为$(\frac{a}{2}, \frac{b}{2})$,由于题目要求整数点,通过求出直线方程,可以发现整数点$(3x - a, 3y - b)$也在直线上,于是答案就出来了。

代码如下

 #include <bits/stdc++.h>
using namespace std; #define INIT() ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define Rep(i,n) for (int i = 0; i < (n); ++i)
#define For(i,s,t) for (int i = (s); i <= (t); ++i)
#define rFor(i,t,s) for (int i = (t); i >= (s); --i)
#define ForLL(i, s, t) for (LL i = LL(s); i <= LL(t); ++i)
#define rForLL(i, t, s) for (LL i = LL(t); i >= LL(s); --i)
#define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
#define rforeach(i,c) for (__typeof(c.rbegin()) i = c.rbegin(); i != c.rend(); ++i) #define pr(x) cout << #x << " = " << x << " "
#define prln(x) cout << #x << " = " << x << endl #define LOWBIT(x) ((x)&(-x)) #define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())
#define UNIQUE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define REMOVE(x, c) x.erase(remove(x.begin(), x.end(), c), x.end()); // ?? x ?????? c
#define TOLOWER(x) transform(x.begin(), x.end(), x.begin(),::tolower);
#define TOUPPER(x) transform(x.begin(), x.end(), x.begin(),::toupper); #define ms0(a) memset(a,0,sizeof(a))
#define msI(a) memset(a,inf,sizeof(a))
#define msM(a) memset(a,-1,sizeof(a)) #define MP make_pair
#define PB push_back
#define ft first
#define sd second template<typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
in >> p.first >> p.second;
return in;
} template<typename T>
istream &operator>>(istream &in, vector<T> &v) {
for (auto &x: v)
in >> x;
return in;
} template<typename T>
ostream &operator<<(ostream &out, vector<T> &v) {
Rep(i, v.size()) out << v[i] << " \n"[i == v.size()];
return out;
} template<typename T1, typename T2>
ostream &operator<<(ostream &out, const std::pair<T1, T2> &p) {
out << "[" << p.first << ", " << p.second << "]" << "\n";
return out;
} inline int gc(){
static const int BUF = 1e7;
static char buf[BUF], *bg = buf + BUF, *ed = bg; if(bg == ed) fread(bg = buf, , BUF, stdin);
return *bg++;
} inline int ri(){
int x = , f = , c = gc();
for(; c<||c>; f = c=='-'?-:f, c=gc());
for(; c>&&c<; x = x* + c - , c=gc());
return x*f;
} template<class T>
inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
} inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
} //min <= aim <= max
template<typename T>
inline bool BETWEEN(const T aim, const T min, const T max) {
return min <= aim && aim <= max;
} typedef long long LL;
typedef unsigned long long uLL;
typedef pair< double, double > PDD;
typedef pair< int, int > PII;
typedef pair< int, PII > PIPII;
typedef pair< string, int > PSI;
typedef pair< int, PSI > PIPSI;
typedef set< int > SI;
typedef set< PII > SPII;
typedef vector< int > VI;
typedef vector< double > VD;
typedef vector< VI > VVI;
typedef vector< SI > VSI;
typedef vector< PII > VPII;
typedef map< int, int > MII;
typedef map< int, string > MIS;
typedef map< int, PII > MIPII;
typedef map< PII, int > MPIII;
typedef map< string, int > MSI;
typedef map< string, string > MSS;
typedef map< PII, string > MPIIS;
typedef map< PII, PII > MPIIPII;
typedef multimap< int, int > MMII;
typedef multimap< string, int > MMSI;
//typedef unordered_map< int, int > uMII;
typedef pair< LL, LL > PLL;
typedef vector< LL > VL;
typedef vector< VL > VVL;
typedef priority_queue< int > PQIMax;
typedef priority_queue< int, VI, greater< int > > PQIMin;
const double EPS = 1e-;
const LL inf = 0x7fffffff;
const LL infLL = 0x7fffffffffffffffLL;
const LL mod = 1e9 + ;
const int maxN = 1e3 + ;
const LL ONE = ;
const LL evenBits = 0xaaaaaaaaaaaaaaaa;
const LL oddBits = 0x5555555555555555; template<typename T>
struct Point{
T X,Y;
Point< T >(T x = ,T y = ) : X(x), Y(y) {}
inline T setXY(T x, T y) { return X = x, Y = y; } inline bool operator== (const Point<T>& x) const { return X == x.X && Y == x.Y; }
inline bool operator< (const Point<T>& x) const {
if(Y == x.Y)return X < x.X;
return Y < x.Y;
}
inline bool operator> (const Point<T>& x)const{return x < *this;} inline Point<T> operator* (const T& k) { return Point<T>(k*X, k*Y); }
inline Point<T> operator/ (const T& k) { return Point<T>(X/k, Y/k); }
inline Point<T> operator+ (const Point<T>& x) { return Point<T>(X+x.X,Y+x.Y); }
inline Point<T> operator- (const Point<T>& x) { return Point<T>(X-x.X,Y-x.Y); } T operator^(const Point<T> &x) const { return X*x.Y - Y*x.X; }
T operator*(const Point<T> &x) const { return X*x.X + Y*x.Y; }
}; template<typename T>
istream &operator>> (istream &in, Point<T> &x) {
in >> x.X >> x.Y;
return in;
} template<typename T>
ostream &operator<< (ostream &out, const Point<T> &x) {
out << "(" << x.X << ", " << x.Y << ")" << endl;
return out;
} int T, N;
Point< LL > p[maxN];
Point< LL > a(-, -), b; inline bool cmp(const Point< LL > &x, const Point< LL > &y) {
return ((a - x) ^ (a - y)) > ;
} int main(){
//freopen("MyOutput.txt","w",stdout);
//freopen("input.txt","r",stdin);
//INIT();
scanf("%d", &T);
while(T--) {
scanf("%d", &N);
For(i, , N) cin >> p[i];
sort(p + , p + + N, cmp); Point< LL > b = a * - (p[N >> ] + p[(N >> ) + ]); printf("%lld %lld %lld %lld\n", a.X, a.Y, b.X, b.Y);
}
return ;
}

分析2(正解)

  其实没必要极角排序,只要进行一次二维偏序排序,选中间两个点,直接构造直线即可。

代码如下

 #include <bits/stdc++.h>
using namespace std; #define INIT() ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define Rep(i,n) for (int i = 0; i < (n); ++i)
#define For(i,s,t) for (int i = (s); i <= (t); ++i)
#define rFor(i,t,s) for (int i = (t); i >= (s); --i)
#define ForLL(i, s, t) for (LL i = LL(s); i <= LL(t); ++i)
#define rForLL(i, t, s) for (LL i = LL(t); i >= LL(s); --i)
#define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
#define rforeach(i,c) for (__typeof(c.rbegin()) i = c.rbegin(); i != c.rend(); ++i) #define pr(x) cout << #x << " = " << x << " "
#define prln(x) cout << #x << " = " << x << endl #define LOWBIT(x) ((x)&(-x)) #define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())
#define UNIQUE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define REMOVE(x, c) x.erase(remove(x.begin(), x.end(), c), x.end()); // ?? x ?????? c
#define TOLOWER(x) transform(x.begin(), x.end(), x.begin(),::tolower);
#define TOUPPER(x) transform(x.begin(), x.end(), x.begin(),::toupper); #define ms0(a) memset(a,0,sizeof(a))
#define msI(a) memset(a,inf,sizeof(a))
#define msM(a) memset(a,-1,sizeof(a)) #define MP make_pair
#define PB push_back
#define ft first
#define sd second template<typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
in >> p.first >> p.second;
return in;
} template<typename T>
istream &operator>>(istream &in, vector<T> &v) {
for (auto &x: v)
in >> x;
return in;
} template<typename T>
ostream &operator<<(ostream &out, vector<T> &v) {
Rep(i, v.size()) out << v[i] << " \n"[i == v.size()];
return out;
} template<typename T1, typename T2>
ostream &operator<<(ostream &out, const std::pair<T1, T2> &p) {
out << "[" << p.first << ", " << p.second << "]" << "\n";
return out;
} inline int gc(){
static const int BUF = 1e7;
static char buf[BUF], *bg = buf + BUF, *ed = bg; if(bg == ed) fread(bg = buf, , BUF, stdin);
return *bg++;
} inline int ri(){
int x = , f = , c = gc();
for(; c<||c>; f = c=='-'?-:f, c=gc());
for(; c>&&c<; x = x* + c - , c=gc());
return x*f;
} template<class T>
inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
} inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
} //min <= aim <= max
template<typename T>
inline bool BETWEEN(const T aim, const T min, const T max) {
return min <= aim && aim <= max;
} typedef long long LL;
typedef unsigned long long uLL;
typedef pair< double, double > PDD;
typedef pair< int, int > PII;
typedef pair< int, PII > PIPII;
typedef pair< string, int > PSI;
typedef pair< int, PSI > PIPSI;
typedef set< int > SI;
typedef set< PII > SPII;
typedef vector< int > VI;
typedef vector< double > VD;
typedef vector< VI > VVI;
typedef vector< SI > VSI;
typedef vector< PII > VPII;
typedef map< int, int > MII;
typedef map< int, string > MIS;
typedef map< int, PII > MIPII;
typedef map< PII, int > MPIII;
typedef map< string, int > MSI;
typedef map< string, string > MSS;
typedef map< PII, string > MPIIS;
typedef map< PII, PII > MPIIPII;
typedef multimap< int, int > MMII;
typedef multimap< string, int > MMSI;
//typedef unordered_map< int, int > uMII;
typedef pair< LL, LL > PLL;
typedef vector< LL > VL;
typedef vector< VL > VVL;
typedef priority_queue< int > PQIMax;
typedef priority_queue< int, VI, greater< int > > PQIMin;
const double EPS = 1e-;
const LL inf = 0x7fffffff;
const LL infLL = 0x7fffffffffffffffLL;
const LL mod = 1e9 + ;
const int maxN = 1e3 + ;
const LL ONE = ;
const LL evenBits = 0xaaaaaaaaaaaaaaaa;
const LL oddBits = 0x5555555555555555; template<typename T>
struct Point{
T X,Y;
Point< T >(T x = ,T y = ) : X(x), Y(y) {}
inline T setXY(T x, T y) { return X = x, Y = y; } inline bool operator== (const Point<T>& x) const { return X == x.X && Y == x.Y; }
inline bool operator< (const Point<T>& x) const {
if(X == x.X) return Y < x.Y;
return X < x.X;
}
inline bool operator> (const Point<T>& x)const{return x < *this;} inline Point<T> operator* (const T& k) { return Point<T>(k*X, k*Y); }
inline Point<T> operator/ (const T& k) { return Point<T>(X/k, Y/k); }
inline Point<T> operator+ (const Point<T>& x) { return Point<T>(X+x.X,Y+x.Y); }
inline Point<T> operator- (const Point<T>& x) { return Point<T>(X-x.X,Y-x.Y); } T operator^(const Point<T> &x) const { return X*x.Y - Y*x.X; }
T operator*(const Point<T> &x) const { return X*x.X + Y*x.Y; }
}; template<typename T>
istream &operator>> (istream &in, Point<T> &x) {
in >> x.X >> x.Y;
return in;
} template<typename T>
ostream &operator<< (ostream &out, const Point<T> &x) {
out << "(" << x.X << ", " << x.Y << ")" << endl;
return out;
} int T, N;
Point< int > p[maxN]; int main(){
//freopen("MyOutput.txt","w",stdout);
//freopen("input.txt","r",stdin);
//INIT();
scanf("%d", &T);
while(T--) {
scanf("%d", &N);
For(i, , N) cin >> p[i];
sort(p + , p + + N); printf("%d %d %d %d\n", p[N >> ].X - , p[N >> ].Y + (int)1e8, p[(N >> ) + ].X + , p[(N >> ) + ].Y - (int)1e8);
}
return ;
}

最新文章

  1. Oracle常用的SQL方法总结
  2. iis 重新注册 .net 方法
  3. 【AutoMapper】实体类间自动实现映射关系,及其转换。
  4. Javascript之响应式相册
  5. (转载)PHP获取客户端、PHP获取服务器相关信息
  6. mysql 查询表的行数和空间使用及其它信息
  7. hdu2845(dp)
  8. Android RecyclerView完全解析
  9. PHP+Redis 实例【一】点赞 + 热度 上篇
  10. MySql foreach属性
  11. [LeetCode] Transform to Chessboard 转为棋盘
  12. JavaScript常用数组操作方法,包含ES6方法
  13. BZOJ 2463: [中山市选2009]谁能赢呢?(智商)
  14. Linux文件误删之后恢复方法
  15. 用开源项目ActivityOptionsICS让ActivityOptions的动画实现兼容
  16. [Java in NetBeans] Lesson 03. More Variables / Type Casting
  17. DateFrame
  18. (转)rootvg镜像
  19. ORID方法在敏捷中的利用
  20. mysql 密码忘记

热门文章

  1. CF232E Quick Tortoise , Fzoj 3118
  2. python url编码与解码
  3. Linux启动过程的C语言代码分析
  4. 静态成员 static 能被继承吗
  5. GIT 学习第二天 (二)
  6. MySQL数据库_目录
  7. Java缓冲区读写
  8. shell提取rpm的报名
  9. Zabbix监控搭建
  10. 第五篇 scrapy安装及目录结构,启动spider项目