2019百度之星初賽三 1001最短路1(異或)


最短路一

題目鏈接:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=863&pid=1001

題目:

有一張 nnn 個點的完全無向圖,點的標號是 1...n1...n1...n,其中邊 (i,j)(i,j)(i,j) 的長度是 i xor jixorji xor j,現在你需要求出點 111 到點 nnn 的最短路的長度。

Input

第一行一個正整數 TTT 表示數據組數 1≤T≤1001\leq T\leq 1001T100

對於每組數據:第一行一個正整數 nnn 表示點數 (2≤n≤105)(2\leq n\leq 10^5)(2n105​​)

Output

輸出 TTT 行,每行一個整數表示點 111 到點 nnn 的最短路

Sample Input
1
3
Sample Output
2
思路:可以將10以內的所有i,j打個表,求出i,j的異或值,然后手推幾個例子就發現1到n的直接異或值是最短的,通過其他路徑的都比1到n的權值長

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <set>
#include<math.h>
#include<map>
using namespace std;
const int maxn=1e6+7;
int main()
{
    int n,T,m;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        m=(1^n);
        printf("%d\n",m);
    }
    return 0;
}

 

 
       


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM