Good Bye 2018 B. New Year and the Treasure Geolocation
https://www.cnblogs.com/violet-acmer/p/10201535.html
题意:
在二维空间中有 n 个 obelisk 点,n 个 p 点;
存在坐标T(x,y),obelisk 中的每个点 o[ i ] : (x,y) 都可以在 p 中找到一个点 p[ j ] : (x,y) 使得 o[ i ].x + p[ j ].x == T.x , o[ i ].y + p[ j ].y == T.y ;
求出这个T点坐标。
题解:
我的做法--暴力枚举
让 o[1]点与每个 p[ i ] 点结合,假设 T( o[ 1 ].x + p[ j ].x , o[ 1 ].y + p[ j ].y ) ;
判断其余的o点能否找到某个p点,使得其坐标和为T( ),如果全部找到,输出T点坐标,否则,枚举下一个点;
AC代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
const int maxn=1e3+; int n;
struct Node
{
int x,y;
}o[maxn];
struct Node1
{
int x,y;
}p[maxn];
bool vis[maxn]; bool cmp(Node1 _a,Node1 _b)
{
return _a.x < _b.x;
}
bool Find(int x,int y)//判断p中有无点(x,y)
{
for(int i=;i <= n;++i)
if(p[i].x == x && p[i].y == y)
return true;
return false;
}
void Solve()
{
sort(p+,p+n+,cmp);
for(int i=;i <= n;++i)
{
int tX=o[].x+p[i].x;
int tY=o[].y+p[i].y;
bool flag=false;
for(int j=;j <= n;++j)
if(!Find(tX-o[j].x,tY-o[j].y))
flag=true; if(!flag)
{
printf("%d %d\n",tX,tY);
return ;
}
}
}
int main()
{
scanf("%d",&n);
for(int i=;i <= n;++i)
scanf("%d%d",&o[i].x,&o[i].y);
for(int i=;i <= n;++i)
scanf("%d%d",&p[i].x,&p[i].y);
Solve();
return ;
}
枚举
当时做的时候,就分析了一下时间复杂度O(n3),又看了一下数据范围 n <= 1000,emmmm,可以过

赛后分析:
其实,当时还想着用二分来着(查找p中是否含有对应的(x,y)),因为看到了所有的xi != xj , yi != yj,但是比赛的时候并没有写,因为遍历一遍p数组比二分要容易好多。
然后,今天撸了一发二分的代码,wa,又看了一遍题,发现漏了个条件
,两坐标不等是用 or 连接的,而不是 and..........
又换了个查找方法,嵌套map
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
#define P pair<int ,int >
const int maxn=1e3+; int n;
P o[maxn];
P p[maxn];
map<int ,map<int ,bool> >mymap;//mymap[i][j] = true : p中含有点(x,y) void Solve()
{
for(int i=;i <= n;++i)
{
bool flag=false;
P T=P(o[].first+p[i].first,o[].second+p[i].second);
for(int j=;j <= n;++j)
{
int x=T.first-o[j].first;
int y=T.second-o[j].second;
if(mymap[x][y] == false)
flag=true;
}
if(!flag)
{
printf("%d %d\n",T.first,T.second);
return ;
}
}
}
int main()
{
// freopen("C:\\Users\\lenovo\\Desktop\\in.txt\\cf1091.txt","r",stdin);
scanf("%d",&n);
for(int i=;i <= n;++i)
{
int x,y;
scanf("%d%d",&x,&y);
o[i]=P(x,y);
}
for(int i=;i <= n;++i)
{
int x,y;
scanf("%d%d",&x,&y);
p[i]=P(x,y);
mymap[x][y]=true;
}
Solve();
return ;
}
嵌套map查找是否含有相应的p坐标
上网搜了一下map的时间复杂度,emmmm,log(n);
然后,分析了一波代码时间复杂度,O(n2*log(n) );
那么,起不要比O(n3)快,提交一发看看,然鹅.......

莫非,嵌套map的时间复杂度不是log(n)???????
Good Bye 2018 B. New Year and the Treasure Geolocation的更多相关文章
- Good Bye 2018
Good Bye 2018 2018年最后一场CF,OVER! 弱弱的我只能做出3道A,B,D~~~~ 最后几分钟,感觉找到了C题的规律,结束的那一刻,提交了一发 "Wrong answer ...
- Good Bye 2018 (A~F, H)
目录 Codeforces 1091 A.New Year and the Christmas Ornament B.New Year and the Treasure Geolocation C.N ...
- Codeforces Good Bye 2018
咕bye 2018,因为我这场又咕咕咕了 无谓地感慨一句:时间过得真快啊(有毒 A.New Year and the Christmas Ornament 分类讨论后等差数列求和 又在凑字数了 #in ...
- Codeforces:Good Bye 2018(题解)
Good Bye 2018! 题目链接:https://codeforces.com/contest/1091 A. New Year and the Christmas Ornament 题意: 给 ...
- Good Bye 2018题解
Good Bye 2018题解 题解 CF1091A [New Year and the Christmas Ornament] 打完cf都忘记写题解了qwq 题意就是:给你一些黄,蓝,红的球,满足蓝 ...
- CF Good Bye 2018
前言:这次比赛爆炸,比赛时各种想多,导致写到\(D\)题时思路已经乱了,肝了\(1\)个多小时都没肝出来,\(B\)题中途因为没开\(long\ long\)又被\(HACK\)了..\(C\)题因为 ...
- Good Bye 2018 D. New Year and the Permutation Concatenation
传送门 https://www.cnblogs.com/violet-acmer/p/10201535.html 题意: 求 n 的所有全排列组成的序列中连续的 n 个数加和为 n*(n+1)/2 的 ...
- Good Bye 2018 C. New Year and the Sphere Transmission
传送门 https://www.cnblogs.com/violet-acmer/p/10201535.html 题意: n 个people,编号1~n,按顺时针方向围城一圈: 初始,编号为1的peo ...
- Good Bye 2018 A. New Year and the Christmas Ornament
传送门 https://www.cnblogs.com/violet-acmer/p/10201535.html 题解: 这题没什么好说的,读懂题意就会了. 比赛代码: #include<ios ...
随机推荐
- PHP爬虫框架Snoopy的使用
参考文档: http://ibillxia.github.io/blog/2010/08/10/php-connecting-tool-snoopy-introduction-and-applicat ...
- SQL之CASE WHEN用法详解[1]
简单CASE WHEN函数: CASE SCORE WHEN 'A' THEN '优' ELSE '不及格' END CASE SCORE WHEN 'B' THEN '良' ELSE '不及格' E ...
- ES 6 系列 - 赋值的新方式:解构赋值
变量的解构赋值 es 6 允许按照一定的模式,从数组和对象中提取值,然后对变量进行赋值,这被称之为解构: 一.数组的解构赋值 最基本写法: let [a, b, c] = [1, 2, 3]; a / ...
- Data Science With R In Visual Studio
R Projects Similar to Python, when we installed the data science tools we get an “R” section in our ...
- Windows Server 2012 IIS 8 - 安装SSL证书
从证书邮件里或者用户中心复制对应的SSL证书文件代码 把代码粘贴到TXT文本文件里面 然后另存为cer或是crt文件,注意编码为ANSI 中级证书和交叉证书也是按以上方法保存为crt或cer文件即可 ...
- 实现中英文混合string的逆向输出
#include <iostream> using namespace std; // 输入一个字符串(包括英文和中文),将其反序输出, 如: // hello 今天真热 ---> ...
- echo显示空行
参考: https://blog.csdn.net/zhaogang1993/article/details/80934172 原生态的解释遗漏了echo另外一个重要功能:输出空行.在DOS脚本中,有 ...
- spring boot项目基本结构
/==================================Controller @Controller public class SimpleController { @Autowired ...
- python中的logging模块学习
Python的logging模块 Logging的基本信息: l 默认的情况下python的logging模块打印到控制台,只显示大于等于warning级别的日志 l 日志级别:critical ...
- 【BZOJ3236】【AHOI2013】作业 线段树 分治 树状数组
题目描述 给你一个长度为\(n\)的数列,还有\(m\)个询问,对于每个询问\((l,r,a,b)\),输出1.区间\([l,r]\)有多少范围在\([a,b]\)的数:2.区间\([l,r]\)有多 ...