一个多月前打的,但是由于一点事情一直没写关于A题的反思,今天有空果断补上:
Problem Description

Bit operation is a common computing method in computer science ,Now we have two positive integers A and B ,Please find a positive integer C that minimize the value of the formula (A xor C) & (B xor C) .Sometimes we can find a lot of C to do this ,So you need to find the smallest C that meets the criteria .

For example ,Let’s say A is equal to 5 and B is equal to 3 ,we can choose C=1,3… ,so the answer we’re looking for C is equal to 1.

If the value of the expression is 0 when C=0, please print 1.

Input

The input file contains T test samples.(1<=T<=100)

The first line of input file is an integer T.

Then the T lines contains 2 positive integers, A and B, (1≤A,B<232)

Output

For each test case,you should output the answer and a line for each answer.
分别考虑P点作直角顶点和非直角顶点。
此篇文章想说map的用法,自定义小于运算符,使得在map中查找的时候,统一斜率的向量都会加起来,虽然在map中依然会保存多个不同的向量。
复杂度为n^2log(n)
下面是AC代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2005;
struct P
{
ll x, y;
P(ll xx=0, ll yy=0) {
x = xx; y = yy;
}
P base()const{
if (x < 0 || (x == 0 && y < 0))return P(-x, -y);
return this;
}
bool operator<(const P&b)const {
P p1 = base(); P p2 =b.base();
//如果共线,考虑是相同的索引
return p1.x
p2.y<p1.y
p2.x;
}
P operator-(const P&b)const {
return P(x - b.x, y - b.y);
}
}a[N],qur[N];
int n, q;
map<P, int>m;
ll ans[N];
int main() {
while (~scanf("%d%d", &n, &q)) {
memset(ans,0,sizeof(ans));
for (int i = 0; i < n; i++)scanf("%lld%lld", &a[i].x, &a[i].y);
for (int i = 0; i < q; i++)scanf("%lld%lld", &qur[i].x, &qur[i].y);
for (int i = 0; i < q; i++) {
//求解作为直角顶点
m.clear();
for (int j = 0; j < n; j++)
m[a[j] - qur[i]]++;
for (int j = 0; j < n; j++) {
P p = a[j] - qur[i];
p = P(-p.y, p.x);
ans[i] += m.count§ ? m[p] : 0;
}
       //由于两条直角边都会枚举,所以除2
ans[i] /= 2;
}
for (int i = 0; i < n; i++) {
//作为非直角顶点,每次枚举点i,作为直角顶点,更新全部的q组询问点
m.clear();
for (int j = 0; j < n; j++) {
if (i != j)m[a[j] - a[i]]++;
}
for (int j = 0; j < q; j++) {
P p = qur[j] - a[i];
p = P(-p.y, p.x);
ans[j] += m.count§ ? m[p] : 0;
}
}
for (int i = 0; i < q; i++)printf("%lld\n", ans[i]);
}
return 0;
}

最新文章

  1. 华为实施微服务架构的五大军规
  2. 最强通用编译器优化工具!MIT三篇顶会论文打造,准确率是传统方法5倍
  3. python 错误、调试、单元测试、文档测试
  4. Kafka学习:CentOS7下Kafka集群搭建
  5. 天翼云从业认证课后习题(3.1天翼云计算产品)
  6. Algorithm Master Road:算法的时间/空间复杂度
  7. TextWatcher() 的用法
  8. android系统签名app自动更新,【Android 进阶】Apk 使用系统签名
  9. kaggle账号_Kaggle 数据挖掘比赛经验分享
  10. elementary os(ubuntu)开启ipv6 与走SwitchyOmega代理
  11. java案例代码4-数组的复制
  12. C语言 Linux版俄罗斯方块,C语言版俄罗斯方块源代码
  13. 网格交易法——震荡行情的必杀技交易策略
  14. matlab样本标准差,关于样本标准差(SD)与样本标准误差(SE)
  15. ffmpeg合并mp4脚本
  16. 用Python画个新冠病毒
  17. 关于Android的post,get、cookie网络获取的一些坑
  18. uva10306(dp)
  19. available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations:
  20. Vue、VueCLI(脚手架)安装、使用详细步骤

热门文章

  1. 类似索引Model套Model之 iOS模型闲聊二
  2. Winodows10 安全登录(Administrator账户与Microsoft Account关联
  3. 在eclipse中启动Tomcat访问localhost:8080失败项目添加进Tomcat在webapp中找不到
  4. InnoDB事务结构体代码变量列表
  5. 【hibernate merge】session1.merge(T entity)方法的含义和update方法的区别
  6. 【译】NoClassDefFoundError和ClassNotFoundException的不同
  7. Spring学习(20)--- Schema-based AOP(基于配置的AOP实现) -- 配置切入点pointcut
  8. MFC消息响应机制及映射机制理解
  9. 微软全新Chromium版Edge浏览器下载
  10. java手机状态栏圆形图标,android实现状态栏添加图标的函数实例