• 2018 CCPC网络赛 Dream&&Find Integer


    首先这场比赛打得很难受,因为是第一次打网络赛而且也是比较菜的那种,所以对这场网络赛还是挺期待和紧张的,但是在做题的过程中,主要的压力不是来自于题目,更多的来自于莫干山。。。从12.40-2.00所有的题目都不判了,中间也就写了1003和1004但是都不知道结果就很难受, 然后一直不判就已经没什么看其他题的兴趣了,然后上床休息了一会,直到说杭电的评测机好了,之后才上去继续做题。然后。。一直在写1001和1009。。后面也没有写出来。。直到比赛结束

      首先说下1004 签到题竟然写了这么久,而且用了cin超时了一发

      

    Find Integer

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 6597    Accepted Submission(s): 1852
    Special Judge


    Problem Description
    people in USSS love math very much, and there is a famous math problem .

    give you two integers n ,a ,you are required to find 2 integers b ,c such that an +bn=cn .
     
    Input
    one line contains one integer T ;(1T1000000)

    next T lines contains two integers n ,a ;(0n1000 ,000 ,000,3a40000)
     
    Output
    print two integers b ,c if b ,c exits;(1b,c1000 ,000 ,000) ;

    else print two integers -1 -1 instead.
     
    Sample Input
    1 2 3
     
    Sample Output
    4 5
     
    思路:首先是对于n>2的情况,根据费马大定理 不存在整数解,所以直接输出-1 -1就行了, 然后最难的地方应该就是对于n=2的情况的判断了,即找勾股数
    这里我一开始用map存数的平方wa了,后面被大佬告知勾股数有规律的。。。心态崩了
    对于勾股数 如果给的直角边是奇数 只需要将这个数的平方拆成两个连续的数就行了,即一个数是a*a/2,另一个数是a*a/2+1.
    然后对于偶数来说,将这个数的平方的一半拆成差2的两个数就行了,即一个数是a*a/4-1,另一个数是a*a/4+1.
    附上代码
    #include <cstdio>
    #include <iostream>
    #include <cmath>
    #include <map>
    using namespace std;
    int main()
    {
        long long n;
        int a;
        int t;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%lld %d",&n,&a);
            if(n>2) printf("-1 -1
    ");
            else if(n==0) printf("-1 -1
    ");
            else if(n==1) printf("1 %d
    ",a+1);
            else {
                if(a==1||a==2) printf("-1 -1
    ");
                else if(a%2==1){
                    int sum=a*a;
                    printf("%d %d
    ",sum/2,sum/2+1);
                }
                else{
                    int sum=a*a/2;
                    printf("%d %d
    ",sum/2-1,sum/2+1);
                }
            }
        }
        return 0;
    
    }

    然后是1003

    Dream

    Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 2193    Accepted Submission(s): 805
    Special Judge


    Problem Description
    Freshmen frequently make an error in computing the power of a sum of real numbers, which usually origins from an incorrect equation (m+n)p=mp+np , where m,n,p are real numbers. Let's call it ``Beginner's Dream''.

    For instance, (1+4)2=52=25 , but 12+42=1725 . Moreover, 9+16=25=5 , which does not equal 3+4=7 .

    Fortunately, in some cases when p is a prime, the identity
    (m+n)p=mp+np

    holds true for every pair of non-negative integers m,n which are less than p , with appropriate definitions of addition and multiplication.

    You are required to redefine the rules of addition and multiplication so as to make the beginner's dream realized.

    Specifically, you need to create your custom addition and multiplication, so that when making calculation with your rules the equation (m+n)p=mp+np is a valid identity for all non-negative integers m,n less than p . Power is defined as
    ap={1,ap1a,p=0p>0


    Obviously there exists an extremely simple solution that makes all operation just produce zero. So an extra constraint should be satisfied that there exists an integer q(0<q<p) to make the set {qk|0<k<p,kZ} equal to {k|0<k<p,kZ} . What's more, the set of non-negative integers less than p ought to be closed under the operation of your definitions.

    Hint

    Hint for sample input and output:
    From the table we get 0+1=1 , and thus (0+1)2=12=11=1 . On the other hand, 02=00=0 , 12=11=1 , 02+12=0+1=1 .
    They are the same.
     
    Input
    The first line of the input contains an positive integer T(T30) indicating the number of test cases.

    For every case, there is only one line contains an integer p(p<210) , described in the problem description above. p is guranteed to be a prime.
     
    Output
    For each test case, you should print 2p lines of p integers.

    The j -th(1jp ) integer of i -th(1ip ) line denotes the value of (i1)+(j1) . The j -th(1jp ) integer of (p+i) -th(1ip ) line denotes the value of (i1)(j1) .
     
    Sample Input
    1 2
     
    Sample Output
    0 1 1 0 0 0 0 1
     
    思路 :其实没有特别懂题目的意思,只是按照输出描述去写的,然后对于加法和乘法重新定义,根据题目描述的定义的话只需要取模就行了,一开始没有看懂题目,看题看了好久好久
    #include <cstdio>
    #include <iostream>
    #include <cmath>
    #include <map>
    using namespace std;
    int main()
    {
        long long n,p;
        int a;
        int t;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%lld",&p);
            for(unsigned long long i=0;i<p;i++){
                printf("%lld",i);
                for(unsigned long long j=1;j<p;j++){
                    printf(" %lld",(i+j)%p);
                }
                printf("
    ");
            }
            for(unsigned long long i=0;i<p;i++){
                printf("0");
                for(unsigned long long j=1;j<p;j++){
                    printf(" %lld",(i*j)%p);
                }
                printf("
    ");
            }
        }
        return 0;
    }
  • 相关阅读:
    java基础之switch
    String的getBytes()方法
    Android adb命令
    shell中grep命令详解
    su root 和su
    adb shell 命令详解
    adb shell am 的用法
    adb logcat 基本用法
    Android、iOS和Windows Phone中的推送技术
    Android客户端消息推送原理简介
  • 原文地址:https://www.cnblogs.com/maybe96/p/9536320.html
Copyright © 2020-2023  润新知