zoukankan      html  css  js  c++  java
  • Codeforce922B (Magic Forest)

    B. Magic Forest
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Imp is in a magic forest, where xorangles grow (wut?)

    A xorangle of order n is such a non-degenerate triangle, that lengths of its sides are integers not exceeding n, and the xor-sum of the lengths is equal to zero. Imp has to count the number of distinct xorangles of order n to get out of the forest.

    Formally, for a given integer n you have to find the number of such triples (a, b, c), that:

    • 1 ≤ a ≤ b ≤ c ≤ n;
    • , where denotes the bitwise xor of integers x and y.
    • (a, b, c) form a non-degenerate (with strictly positive area) triangle.
    Input

    The only line contains a single integer n (1 ≤ n ≤ 2500).

    Output

    Print the number of xorangles of order n.

    Examples
    Input
    Copy
    6
    Output
    1
    Input
    Copy
    10
    Output
    2
    Note

    The only xorangle in the first sample is (3, 5, 6).

    分析:暴力出奇迹=_=。

    #include<cstdio>
    #include<algorithm>
    using namespace std;
    int main()
    {
        int N,ans=0;
        scanf("%d",&N);
        for(int i=1;i<=N;i++)
        {
            for(int j=i+1;j<=N;j++)
            {
                int MAX=min(N+1,i+j);//i+j>k&&i+k>j&&k+j>iprintf("(%d,%d,%d)
    ",i,j,k);
                for(int k=j+1;k<MAX;k++)
                {
                    if((i^j^k)==0)
                    {ans++;}
                }
            }
        }
        printf("%d
    ",ans);
        return 0;
    }
    View Code

     这个15ms左右: 

    #include<cstdio>
    int main()
    {
        int N,ans=0;
        scanf("%d",&N);
        for(int i=1;i<=N;i++)
        {
            for(int j=i+1;j<=N;j++)
            {
                int k=i^j;
                if(k>j&&k<=N&&i+j>k&&i+k>j&&k+j>i) ans++;
            }
        }
        printf("%d
    ",ans);
        return 0;
    }
    View Code
  • 相关阅读:
    Leetcode 1489找到最小生成树李关键边和伪关键边
    Leetcode 113 路径总和 II
    hdu 1223 还是畅通工程
    hdu 1087 Super Jumping! Jumping! Jumping!
    hdu 1008 Elevator
    hdu 1037 Keep on Truckin'
    湖工oj 1241 畅通工程
    湖工oj 1162 大武汉局域网
    hdu 2057 A + B Again
    poj 2236 Wireless Network
  • 原文地址:https://www.cnblogs.com/ACRykl/p/8461278.html
Copyright © 2011-2022 走看看