CodeForcesGym 100524A Astronomy Problem
Astronomy Problem
This problem will be judged on CodeForcesGym. Original ID: 100524A
64-bit integer IO format: %I64d Java class name: (Any)
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = ;
struct Point{
LL val,a,b,c;
Point(LL val = ,LL a = ,LL b = ,LL c = ){
this->val = val;
this->a = a;
this->b = b;
this->c = c;
}
bool operator<(const Point &rhs)const{
return val < rhs.val;
}
}P[maxn*maxn];
int x[maxn],y[maxn],n,q,tot;
LL calc(int a,int b){
LL tmp = (LL)(x[a] - x[b])*(x[a] - x[b]);
return tmp + (LL)(y[a] - y[b])*(y[a] - y[b]);
}
int main(){
freopen("astronomy.in","r",stdin);
freopen("astronomy.out","w",stdout);
while(~scanf("%d",&n)){
if(!n) break;
tot = ;
for(int i = ; i <= n; ++i){
scanf("%d%d",x + i,y + i);
for(int j = ; j < i; ++j){
LL tmp = ((LL)x[i]*x[j] + (LL)y[i]*y[j])<<;
P[tot++] = Point(tmp,calc(j,),calc(i,),calc(i,j));
}
}
sort(P,P + tot);
scanf("%d",&q);
while(q--){
LL a,b,c;
scanf("%I64d%I64d%I64d",&a,&b,&c);
LL tmp = a - c + b;
if(n == || tmp&){
puts("");
continue;
}
int low = lower_bound(P,P + tot,Point(tmp,,,)) - P,ret = ;
while(low < tot && P[low].val == tmp){
if(P[low].a == a && P[low].b == b || P[low].a == b && P[low].b == a) ++ret;
++low;
}
printf("%d\n",ret);
}
}
return ;
}
/*
4
0 2
2 0
4 0
0 -4
2
4 16 20
16 4 20
*/
然后学习了下某位大神的写法
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = ;
unordered_map<LL,vector<int>>ump;
unordered_map<LL,int>ret;
map<pair<LL,LL>,vector<pair<LL,int>>>Q;
struct Point {
LL x,y;
Point(LL x = ,LL y = ) {
this->x = x;
this->y = y;
}
} p[maxn];
LL calc(const Point &a,const Point &b) {
LL tmp = (a.x - b.x)*(a.x - b.x);
return tmp + (a.y - b.y)*(a.y - b.y);
}
set<LL>st;
int ans[maxn];
int main() {
#define NAME "astronomy"
freopen(NAME".in","r",stdin);
freopen(NAME".out","w",stdout);
int n,q;
while(~scanf("%d",&n)) {
if(!n) break;
ump.clear();
Q.clear();
memset(ans,,sizeof ans);
for(int i = ; i <= n; ++i) {
scanf("%I64d%I64d",&p[i].x,&p[i].y);
ump[p[i].x*p[i].x+p[i].y*p[i].y].push_back(i);
}
scanf("%d",&q);
for(int i = ; i < q; ++i){
LL a,b,c;
scanf("%I64d%I64d%I64d",&a,&b,&c);
Q[make_pair(a,b)].push_back(make_pair(c,i));
}
for(auto &it:Q){
st.clear();
for(auto &it2:it.second) st.insert(it2.first);
LL a = it.first.first,b = it.first.second;
ret.clear();
for(auto &x:ump[a]){
for(auto &y:ump[b]){
if(a == b && x < y) continue;
if(x == y) continue;
LL d = calc(p[x],p[y]);
if(st.find(d) == st.end()) continue;
ret[d]++;
}
}
for(auto &v:it.second)
ans[v.second] = ret[v.first];
}
for(int i = ; i < q; ++i)
printf("%d\n",ans[i]);
}
return ;
}
/*
4
0 2
2 0
4 0
0 -4
2
4 16 20
16 4 20
*/
CodeForcesGym 100524A Astronomy Problem的更多相关文章
- CodeForcesGym 100548G The Problem to Slow Down You
The Problem to Slow Down You Time Limit: 20000ms Memory Limit: 524288KB This problem will be judged ...
- CodeForcesGym 100512D Dynamic LCA
Dynamic LCA Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForcesGym. ...
- CodeForcesGym 100517I IQ Test
IQ Test Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForcesGym. Orig ...
- CodeForcesGym 100517B Bubble Sort
Bubble Sort Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForcesGym. ...
- CodeForcesGym 100517H Hentium Scheduling
Hentium Scheduling Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForc ...
- CodeForcesGym 100524J Jingles of a String
Jingles of a String Time Limit: 2000ms Memory Limit: 524288KB This problem will be judged on CodeFor ...
- CodeForcesGym 100212E Long Dominoes
Long Dominoes Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on CodeForcesGym. ...
- CodeForcesGym 100753K Upside down primes
Upside down primes Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForc ...
- CodeForcesGym 100753F Divisions
Divisions Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForcesGym. Or ...
随机推荐
- 51nod 1874 字符串排序
1874 字符串排序 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题 收藏 关注 定义一个字符串的无序度为所有位置后面的字母比该位置的字母小的总数之和.比如&q ...
- 贪心 Codeforces Round #109 (Div. 2) B. Combination
题目传送门 /* 贪心:按照能选的个数和点数降序排序,当条件不符合就break,水题啊! */ #include <cstdio> #include <algorithm> # ...
- magento 添加事件
首先是配置文件config.xml里的配置 <checkout_cart_save_after> /*事件名字*/ <observers> <deal> /*模块名 ...
- Matlab实现图像分割 分类: 图像处理 2014-06-14 21:31 662人阅读 评论(1) 收藏
下面使用极小值点阈值选取方法,编写MATLAB程序实现图像分割的功能. 极小值点阈值选取法即从原图像的直方图的包络线中选取出极小值点, 并以极小值点为阈值将图像转为二值图像 clear all; cl ...
- solr 6.0 没有schema.xml未自动创建schema文件
solr 6.0 没有schema.xml未自动创建schema文件 摘要:在之前的Solr版本中(Solr5之前),在创建core的时候,Solr会自动创建好schema.xml,但是在之后的版本中 ...
- AJPFX关于面向对象中的对象初始化整理,综合子父类、代码块等等
今天总结了一下子父类当中含有静态代码块.代码块.构造函数.成员变量.子类复写父类方法时子类的初始化过程,把思路理清一下 class Fu { //父类成员变量 private int num = 3; ...
- DOM简介及节点、属性、查找节点的方法
DOM(Document Object Modle) 操作文档的编程接口DOM定义了表示和修改文档的方法,不能修改css样式表,在js中使用DOM方法改变元素的css样式,实质上是在元素上添加行间样式 ...
- java synchronized(object/this)的 区别
1.synchronized(object) package test.thread; import java.io.IOException; import org.junit.Test; /* * ...
- Jenkins .NET项目持续集成配置
基本步骤 1. 安装并配置MSBUILD 在系统管理->插件管理->添加MSBuild插件 在系统管理->系统设置->找到MSBuild配置部分,配置不同的MSbuild版本 ...
- apache反向代理配置
apache简单的反向代理配置 Proxypass /api /http://locahost:3000 反向代理-1.jpg