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

;(1≤T≤1000000)

next T

lines contains two integers n

,a

;(0≤n≤1000

,000

,000,3≤a≤40000)

Output

print two integers b

,c

if b

,c

exits;(1≤b,c≤1000

,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\n");
        else if(n==0) printf("-1 -1\n");
        else if(n==1) printf("1 %d\n",a+1);
        else {
            if(a==1||a==2) printf("-1 -1\n");
            else if(a%2==1){
                int sum=a*a;
                printf("%d %d\n",sum/2,sum/2+1);
            }
            else{
                int sum=a*a/2;
                printf("%d %d\n",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=17≠25

. 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,ap−1⋅a,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,k∈Z}

equal to {k|0<k<p,k∈Z}

. 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=1⋅1=1

. On the other hand, 02=0⋅0=0

, 12=1⋅1=1

, 02+12=0+1=1

.
They are the same.

Input

The first line of the input contains an positive integer T(T≤30)

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(1≤j≤p

) integer of i

-th(1≤i≤p

) line denotes the value of (i−1)+(j−1)

. The j

-th(1≤j≤p

) integer of (p+i)

-th(1≤i≤p

) line denotes the value of (i−1)⋅(j−1)

.

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("\n");
        }
        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("\n");
        }
    }
    return 0;
}

原文地址:https://www.cnblogs.com/maybe96/p/9536320.html

时间: 2024-08-03 02:02:19

2018 CCPC网络赛 Dream&&Find Integer的相关文章

2018 CCPC网络赛 Dream (费马小定理)

Dream 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

2018 CCPC网络赛

2018 CCPC网络赛 Buy and Resell 题目描述:有一种物品,在\(n\)个地点的价格为\(a_i\),现在一次经过这\(n\)个地点,在每个地点可以买一个这样的物品,也可以卖出一个物品,问最终赚的钱的最大值. solution 用两个堆来维护,一个堆维护已经找到卖家的,一个堆维护还没找到卖家的. 对于第\(i\)个地点,在已经找到卖家的堆里找出卖的钱的最小值,如果最小值小于\(a_i\),则将卖家换成\(i\),然后将原来的卖家放到没找到卖家的那里:如果最小值对于\(a_i\)

[2018 CCPC 网络赛] 部分题解 (待补充)

真香爬山预警 1003 - Dream 题目链接 如题,p是一个质数,那么由费马小定理  a^p ≡ a (mod p)  ( a ∈ Z )  可得 只需将 加法定义为 (m + n) % p 乘法定义为 (m * n) % p 即可   1 #include <iostream> 2 #include <bits/stdc++.h> 3 using namespace std; 4 int main() 5 { 6 int t,p; 7 scanf("%d"

2018 CCPC网络赛 几道数学题

1002 Congruence equation 题目链接  : http://acm.hdu.edu.cn/showproblem.php?pid=6439 题解 : https://www.zybuluo.com/yang12138/note/1262592 相关定理 : 裴蜀定理 在数论中,裴蜀定理是一个关于最大公约数(或最大公约式)的定理.裴蜀定理得名于法国数学家艾蒂安·裴蜀,说明了对任何整数a.b和它们的最大公约数d,关于未知数x和y的线性丢番图方程(称为裴蜀等式): ax + by

HDU 6438 Buy and Resell ( 2018 CCPC 网络赛 &amp;&amp; 贪心 )

题目链接 题意 : 给出一些数.你可以从左到右对这些数进行三种操作花费 Ai 买入东西.以 Ai 价格卖出你当前有的东西.或者什么都不做.现在问你可以获取的最大利益是多少? 分析 : 和 CF 867E 一模一样 传送门 可以去搜这题的题解.有很多 对于每个元素产生的贡献 可以先算出暂时的最优值 如果下次碰到更优的选择再进行替换 具体就是首先使用小顶堆维护枚举过的元素 然后对于当前枚举到的元素 用它和堆顶元素做对比.如果小于或等于堆顶元素 那么它无法和之前枚举过的所有元素的任何一个做减法产生贡献

【2018 CCPC网络赛】1004 - 费马大定理&amp;数学

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6441 Knowledge Point: 1. 费马大定理:当整数n >2时,关于x, y, z的方程 x^n + y^n = z^n 没有正整数解. 2. 0^0次没有意义!! 所以我们知道 n=0, n>2的时候都没有正整数解: n=1 时显然 b=1, c=a+1 为一组整数解: n=2 时,a2 = c2-b2 = (c+b)*(c-b); 令x = c+b, y = c-b; 则有 a2 

2018徐州网络赛H. Ryuji doesn&#39;t want to study

题目链接: https://nanti.jisuanke.com/t/31458 题解: 建立两个树状数组,第一个是,a[1]*n+a[2]*(n-1)....+a[n]*1;第二个是正常的a[1],a[2],a[3]...a[n] #include "bits/stdc++.h" using namespace std; #define ll long long const int MAXN=1e5+10; ll sum[MAXN],ans[MAXN]; ll num[MAXN];

hdu6153 A Secret CCPC网络赛 51nod 1277 KMP

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6153 题意: 给出两个字符串S1,S2,求S2的所有后缀在S1中出现的次数与其长度的乘积之和. 思路: CCPC网络赛题解: https://post.icpc-camp.org/d/714-ccpc-2017 http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1277   是一样的 将s1,s2翻转,转化为求前缀在s1中出

树形DP CCPC网络赛 HDU5834 Magic boy Bi Luo with his excited tree

1 // 树形DP CCPC网络赛 HDU5834 Magic boy Bi Luo with his excited tree 2 // 题意:n个点的树,每个节点有权值为正,只能用一次,每条边有负权,可以走多次,问从每个点出发的最大获益 3 // 思路: 4 // dp[i]: 从i点出发回到i点的最大值 5 // d[i][0] 从i点出发不回来的最大值 6 // d[i][1] 从i点出发取最大值的下一个点 7 // d[i][2] 从i点出发取次大值 8 // dfs1处理出这四个 9