传送门

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的更多相关文章

  1. Good Bye 2018

    Good Bye 2018 2018年最后一场CF,OVER! 弱弱的我只能做出3道A,B,D~~~~ 最后几分钟,感觉找到了C题的规律,结束的那一刻,提交了一发 "Wrong answer ...

  2. Good Bye 2018 (A~F, H)

    目录 Codeforces 1091 A.New Year and the Christmas Ornament B.New Year and the Treasure Geolocation C.N ...

  3. Codeforces Good Bye 2018

    咕bye 2018,因为我这场又咕咕咕了 无谓地感慨一句:时间过得真快啊(有毒 A.New Year and the Christmas Ornament 分类讨论后等差数列求和 又在凑字数了 #in ...

  4. Codeforces:Good Bye 2018(题解)

    Good Bye 2018! 题目链接:https://codeforces.com/contest/1091 A. New Year and the Christmas Ornament 题意: 给 ...

  5. Good Bye 2018题解

    Good Bye 2018题解 题解 CF1091A [New Year and the Christmas Ornament] 打完cf都忘记写题解了qwq 题意就是:给你一些黄,蓝,红的球,满足蓝 ...

  6. CF Good Bye 2018

    前言:这次比赛爆炸,比赛时各种想多,导致写到\(D\)题时思路已经乱了,肝了\(1\)个多小时都没肝出来,\(B\)题中途因为没开\(long\ long\)又被\(HACK\)了..\(C\)题因为 ...

  7. 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 的 ...

  8. 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 ...

  9. Good Bye 2018 A. New Year and the Christmas Ornament

    传送门 https://www.cnblogs.com/violet-acmer/p/10201535.html 题解: 这题没什么好说的,读懂题意就会了. 比赛代码: #include<ios ...

随机推荐

  1. windows 10 screenshot keyboard shortcut

    windows 10 screenshot keyboard shortcut Win + Shfit + S https://www.cnet.com/how-to/8-ways-to-take-s ...

  2. peewee 事物 回滚

    peewee 事物 回滚 #!/usr/bin/env python # coding=utf-8 from peewee import * db = MySQLDatabase(host='123. ...

  3. Ehlib(Delphi控件) v9.2.024 D7-XE10.2 免费绿色特别版

    下载地址:https://www.jb51.net/softs/579413.html#downintro2 EHLib是一个DELPHI 下的非常棒的第三方Grid控件,比DELPHI自带的强大许多 ...

  4. vue組件

    組件有局部組件和全局組件,全局組件,其它的元素能夠調用. Prop父組件子組件看不大明白.

  5. HTML中文本过长时自动隐藏末尾部分或中间等任意部分

    一.    一般情况下,HTML字符串过长时都会将超过的部分隐藏点,方法如下: 设置CSS: .ellipsis-type{ max-width: 50px;                      ...

  6. Spring Boot 构建电商基础秒杀项目 (一) 项目搭建

    SpringBoot构建电商基础秒杀项目 学习笔记 Spring Boot 其实不是什么新的框架,它默认配置了很多框架的使用方式,就像 maven 整合了所有的 jar 包, Spring Boot ...

  7. HttpWebRequest using Basic authentication

    System.Net.CredentialCache credentialCache = new System.Net.CredentialCache(); credentialCache.Add( ...

  8. codeforces-div2-449-B

    题意:确定一个回文偶数十进制数字,输入k和q,求前k小的和对q取余的值 解题思路:首先确定一个,第k个回文偶数一定前半段一定是k,比如第12个,这个数就是1221: 代码: #include<i ...

  9. Tomcat启动特慢之SecureRandom问题解决

    tomcat启动日志: 08-Jun-2018 09:23:00.445 WARNING [localhost-startStop-1] org.apache.catalina.util.Sessio ...

  10. C# 电脑上提示未知发布者

    参考6楼:http://tieba.baidu.com/p/5767451198?pid=120504172126&cid=120504203560#120504203560 解决方案:mak ...