BestCoder Round #82 (div.2) (HDU 5675)(HDU 5676)

ztr loves math

 
 Accepts: 315
 
 Submissions: 1975
 Time Limit: 2000/1000 MS (Java/Others)
 
 Memory Limit: 65536/65536 K (Java/Others)
Problem Description

ztr loves research Math.One day,He thought about the "Lower Edition" of triangle equation set.Such as n=x^{2}-y^{2}n=x2y2.

He wanted to know that ,for a given number n,is there a positive integer solutions?

Input

There are T test cases. The first line of input contains an positive integer T(T<=10^{6})T(T<=106) indicating the number of test cases.

For each test case:each line contains a positive integer ,n <=10^{18}n<=1018.

Output

If there be a positive integer solutions,print TrueTrue,else print FalseFalse

Sample Input
4
6
25
81
105
Sample Output
False
True
True
True


     
     
     
     
Hint
For the fourth case, 105 = 13^{2}-8^{2}105=13282
题意很简单,就不多说了。我用的方法比较复杂,打表。但是后来又看到了别人的做法,感觉比较简单,但是不容易想到。
#include<iostream>
#include<cstdio>
using namespace std;
const  int N = 999999;
int a[N]={0};
int main()
{
    for(int i=1;i<N;i++)
        for(int j=i+1;j*j-i*i<N;j++)
            a[j*j-i*i]=1;
    int t,n;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        if(a[n])
            printf("True\n");
        else
            printf("False\n");
    }
    return 0;
}
简单代码的:
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int t,n;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        if(n==3||(n>4&&n%4!=2))
            printf("True\n");
        else
            printf("False\n");
    }
    return 0;
}






ztr loves lucky numbers

 
 Accepts: 99
 
 Submissions: 736
 Time Limit: 2000/1000 MS (Java/Others)
 
 Memory Limit: 65536/65536 K (Java/Others)
Problem Description

ztr loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.

One day ztr came across a positive integer n. Help him to find the least super lucky number which is not less than n.

Input

There are T(1\leq\;n\leq\;10^{5})(1n105) cases

For each cases:

The only line contains a positive integer n(1\leq\;n\leq\;10^{18})n(1n1018). This number doesn't have leading zeroes.

Output

For each cases Output the answer

Sample Input
2
4500
47
Sample Output
Copy
4747
47
这个题目是真不会啊,到了最后也没做出来,然后看了别人的解题报告,学到了一个新函数next_permutation

这是一个求一个一个序列的全排列的函数,具体用法我也是看了别人的解析才懂得,推荐kuangbin 和next_permutation

代码如下:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
    int t;
    char str[100],str47[100];
    scanf("%d",&t);
    while(t--)
    {
        scanf("%s",str);
        int len = strlen(str);
        if(len & 1)//其实就相当于 len%2,判断奇偶性,按位与真神奇,二进制好广大
        {
            for(int i=0;i<=len/2;i++)
                printf("4");
            for(int i=0;i<=len/2;i++)
                printf("7");
            printf("\n");
            continue;
        }
        //长度为偶数的情况
        for(int i=0;i<len/2;i++)
            str47[i]='4';
        for(int i=len/2;i<len;i++)
            str47[i]='7';
        int flag=1;
        str47[len]='\0';//终止符
        do
        {
            if(strcmp(str47,str)>=0)
            {
                printf("%s\n",str47);
                flag=0;
                break;
            }
        }while(next_permutation(str47,str47+len));
        if(flag)
        {
             for(int i=0;i<=len/2;i++)
                printf("4");
             for(int i=0;i<=len/2;i++)
                printf("7");
            printf("\n");
        }
    }
    return 0;
}


你可能感兴趣的:(HDU)