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 ...
随机推荐
- 背包DP HDOJ 5410 CRB and His Birthday
题目传送门 题意:有n个商店,有m金钱,一个商店买x件商品需要x*w[i]的金钱,得到a[i] * x + b[i]件商品(x > 0),问最多能买到多少件商品 01背包+完全背包:首先x == ...
- 题解报告:hdu 1124 Factorial(求N!尾数有多少个0。)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1124 Problem Description The most important part of a ...
- 题解报告:hdu 1039 Easier Done Than Said?
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1039 Problem Description Password security is a trick ...
- C#中如何判断键盘按键和组合键
好记性不如烂笔头子,现在记录下来,不一定会有很详尽的实例,只写最核心的部分. C# winform的窗体类有KeyPreview属性,可以接收窗体内控件的键盘事件注册.窗体和控件都有KeyDown,K ...
- javaservlet介绍
servlet 是 serve applet的意思 Java servlet是用Java编写的服务器端程序.其主要功能在于交互式地浏览和修改数据,生成动态Web内容. Servlet运行于支持Jav ...
- Linux终端下对话
1.首先查看当前账户 [hadoop@weekend01 ~]$ who hadoop tty1 2016-11-14 09:31 (:0) hadoop pts/0 ...
- 一个页面通过iframe,获取另一个页面的form
document.getElementsByTagName("iframe")[0].contentWindow.document.forms[0].submit(); var z ...
- EditText自动弹出软键盘
editText.requestFocus() editText.isFocusable = true editText.isFocusableInTouchMode = true val timer ...
- Visual SVN自动给文件加锁
在使用SVN作为版本控制器的时候,在VS里安装VISUALSVN插件,当修改文件公共文件的时候需要先Get Lock,如果对于多次操作这个鼠标操作显得是一些复杂,自动给文件加锁的操作实际是给文件加一个 ...
- call、apply/bind的区别和用法(简单粗暴的解释)
var obj1={ name:"bob", age:20 } var obj2={ name:"coco", age:22 } function getAge ...