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 ...
随机推荐
- Spring标签之Bean @Scope
@Bean 的用法 @Bean是一个方法级别上的注解,主要用在@Configuration注解的类里,也可以用在@Component注解的类里.添加的bean的id为方法名 定义bean 下面是@Co ...
- EmpireCMS的使用
1.下载安装empirecms 下载完成后解压将upload目录整体上传到服务器,并更名为empirecms_test 更改目录文件的权限: chmod -R 777 empirecms_test 配 ...
- springboot swagger2 泛型踩坑记
最近使用一些工具需要和swagger打通,swagger的格式总是不对. 后来查了一下:哈哈. https://blog.csdn.net/hupingjin/article/details/8299 ...
- idea中Lombok的使用
使用了lombok的注解(@Setter,@Getter,@ToString,@@RequiredArgsConstructor,@EqualsAndHashCode或@Data)之后,就不需要编写或 ...
- 我踩过的Alwayson的坑!
最近被sql server Alwayson高可用组和读写分离,弄得神魂颠倒,身心俱疲.遇到了下面一些问题,提醒自己也给后来人做些记录. EntityFramework支不支持Alwayson? 起因 ...
- E - Just a Hook HDU - 1698 线段树区间修改区间和模版题
题意 给出一段初始化全为1的区间 后面可以一段一段更改成 1 或 2 或3 问最后整段区间的和是多少 思路:标准线段树区间和模版题 #include<cstdio> #include& ...
- The Cow Lexicon POJ - 3267 dp
题意 给出一个母串 和一个字典 问母串最少删去几个字母 删去后的母串是由字典里面的单词拼起来的 思路:dp[i]表示从i到母串结尾最少需要删除多少个字母 初始化dp[length]=0 ...
- P1403 [AHOI2005]约数研究
原题链接 https://www.luogu.org/problemnew/show/P1403 这个好难啊,求约数和一般的套路就是求1--n所有的约数再一一求和,求约数又要用for循环来判断.... ...
- 用随机投掷飞镖法计算Pi值(Randomness Throwing dart Pi Python)
画一个边长为r的正方形和半径为r的四分之一的圆(如下图所示),向上面随机投掷飞镖,通过计算落在星星区域和整体区域的飞镖比例,即可求出π值. 公式推导如下: 假设正方形的边长r为1,那么飞镖落在星星区域 ...
- 【CF981D】Bookshelves(贪心,动态规划)
[CF981D]Bookshelves(贪心,动态规划) 题面 洛谷 Codeforces 给定一个长度为\(n\)的数列,把他们划分成\(k\)段,使得每段的和的结构按位与起来最大. 题解 从高位往 ...