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 ...
随机推荐
- bryce1010专题训练——线段树习题汇总
一.区间查询,无单点更新 hdu2795 Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 ...
- poj2573Bridge(过桥问题)
链接 A,B为最快和次快 有两种方式可以使c,d过桥 一是a与c一起走,a回来接d再与d一起走,一直到对岸人为0为止 而是 a与b一起走 a回来送灯 c与d一起走 b回来送灯 重复此过程. 只剩2人时 ...
- vue学习之遇见的问题
1.本地图片加载不出来 错误原因:图片放置位置不对: 解决方法:需要将图片放在static文件夹里
- 在WIndowsPhone8 上制作的简单的计算器
今天,闲着没事,就自己做了一个小小的计算器...虽说自己刚学wp8开发没多长时间,望大神多多指教..1.这是前台页面的代码 <Grid x:Name=" Margin="10 ...
- SQLServer性能优化专题
SQLServer性能优化专题 01.SQLServer性能优化之----强大的文件组----分盘存储(水平分库) http://www.cnblogs.com/dunitian/p/5276431. ...
- MongoDB入门解析
刚开始学习mongodb,对笔记做了一个整理.是基于nodejs来学习的. 1.mongodb介绍 mongodb 是C++语言编写的,是一个基于分布式文件存储的开源数据库系统. 在高负载的情况下,添 ...
- Java Hello World 错误 找不到或无法加载主类
Java 有几年没用了 生疏了好多 最近又捡起来 结果第一个Hello World 就在黑窗口内报错! 遇到几个小问题. 1. 安装JDK后 在 CMD 中 执行 java -version 正常 因 ...
- PHP exif扩展方法开启详解(亲测)
本节主要介绍了如何开启PHP exif扩展方法,主要在于对php.ini文件的修改 服务器配置说明: 1.在php.ini文件中找到;extension=php_exif.dll,去掉前面的分号 2. ...
- vue热重载
依据官网使用 webpack 的 Hot Module Replacement API,Vuex 支持在开发过程中热重载 mutation.module.action 和 getter.你也可以在 B ...
- C++ 异常处理(try catch throw)、命名空间
一.c++工具 模板(函数模板.类模板).异常处理.命名空间等功能是c++编译器的功能,语言本身不自带,这些功能已经成为ANSI C++标准了,建议所有的编译器都带这些功能,早期的c++是没有这些功能 ...