日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

2019 CCPC - 网络选拔赛 A题^^

發(fā)布時(shí)間:2025/3/11 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 2019 CCPC - 网络选拔赛 A题^^ 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

一個(gè)多月前打的,但是由于一點(diǎn)事情一直沒寫關(guān)于A題的反思,今天有空果斷補(bǔ)上:
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點(diǎn)作直角頂點(diǎn)和非直角頂點(diǎn)。
此篇文章想說map的用法,自定義小于運(yùn)算符,使得在map中查找的時(shí)候,統(tǒng)一斜率的向量都會(huì)加起來,雖然在map中依然會(huì)保存多個(gè)不同的向量。
復(fù)雜度為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.xp2.y<p1.yp2.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++) {
//求解作為直角頂點(diǎn)
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;
}
       //由于兩條直角邊都會(huì)枚舉,所以除2
ans[i] /= 2;
}
for (int i = 0; i < n; i++) {
//作為非直角頂點(diǎn),每次枚舉點(diǎn)i,作為直角頂點(diǎn),更新全部的q組詢問點(diǎn)
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;
}

總結(jié)

以上是生活随笔為你收集整理的2019 CCPC - 网络选拔赛 A题^^的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。