传送门

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. Java的HashMap数据结构

    标题太大~~~自己做点笔记.别人写得太好了. https://www.cnblogs.com/liwei2222/p/8013367.html HashMap 1.6时代, 使用Entry[]数组, ...

  2. 解决post、get端中文乱码问题

    在web.xml中配置: <filter> <filter-name>CharacterEncodingFilter</filter-name> <filte ...

  3. DBC格式解析(数据部分)

    dbc格式说明:DBC Format   实战: 我们先来看一段数据 BO_ VOLTAGE01: BMS2 SG_ V01 : |@+ () [|] "" Vector__XXX ...

  4. Java常用调试技巧(转)

    调试不仅可以查找到应用程序缺陷所在,还可以解决缺陷.对于Java程序员来说,他们不仅要学会如何在Eclipse里面开发像样的程序,更需要学会如何调试程序.本文介绍了Java程序员必知的10个调试技巧, ...

  5. Spring 使用介绍(三)—— 资源

    一.Resource接口 Spring提供Resource接口,代表底层外部资源,提供对底层外部资源的一致性访问接口 public interface InputStreamSource { Inpu ...

  6. BZOJ1319Sgu261Discrete Roots——BSGS+exgcd+原根与指标+欧拉定理

    题目描述 给出三个整数p,k,a,其中p为质数,求出所有满足x^k=a (mod p),0<=x<=p-1的x. 输入 三个整数p,k,a. 输出 第一行一个整数,表示符合条件的x的个数. ...

  7. IDEA Failed to prepare an update: Temp directory inside installation

    具体错误: Connection Error Failed to prepare an update: Temp directory inside installation: F:\IDEA_Tool ...

  8. POJ 1966 Cable TV Network (算竞进阶习题)

    拆点+网络流 拆点建图应该是很常见的套路了..一张无向图不联通,那么肯定有两个点不联通,但是我们不知道这两个点是什么. 所以我们枚举所有点,并把每个点拆成入点和出点,每次把枚举的两个点的入点作为s和t ...

  9. 如何保证 spring-boot 和 spring-cloud版本一致

    spring-boot 版本 和 spring-cloud版本是一一对应的,很多错误都是由于版本不一致导致的.很多百度的东西太老了, 版本一升级就会出错. spring的jar包依赖关系是最难的,但聪 ...

  10. 睡眠麻痹 CSP HSP

    睡眠麻痹 CSP HSP 来源 https://www.zhihu.com/question/29666875/answer/65480583 俗名“鬼压床”.“鬼压身”或者“梦魇”的,学名叫睡眠麻痹 ...