2018中国大学生程序设计竞赛 - 网络选拔赛 hdu 6440 Dream 模拟

Posted l609929321

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2018中国大学生程序设计竞赛 - 网络选拔赛 hdu 6440 Dream 模拟相关的知识,希望对你有一定的参考价值。

Dream

Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1014    Accepted Submission(s): 200
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,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,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=1?1=1. On the other hand, 02=0?0=012=1?1=102+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 (i?1)+(j?1). The j-th(1jp) integer of (p+i)-th(1ip) line denotes the value of (i?1)?(j?1).
 

 

Sample Input
1 2
 

 

Sample Output
0 1 1 0 0 0 0 1

 

分析:比赛的时候做出来的队友说的是数论结论题,比赛后我是按照题目意思直接模拟A掉的。。
  根据题目给出的数字p按照题目的意思我们可以得到一个2*p行,p列的矩阵
  其中1<=i<=p,1<=j<=p时:mapn[i][j] = ((i-1)+(j-1))%p
    p+1<=i<=2*p,1<=j<=p时:mapn[i][j] = ((i-1)*(j-1))%p
AC代码:
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define ls (r<<1)
#define rs (r<<1|1)
#define debug(a) cout << #a << " " << a << endl
using namespace std;
typedef long long ll;
const ll maxn = pow(2,10)+10;
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const ll inf = 1e9;
const double pi = acos(-1.0);
ll mapn[2*maxn][maxn];
int main() {
    ll T, p;
    scanf("%lld",&T);
    while(T--) {
        memset(mapn,0,sizeof(mapn));
        scanf("%lld",&p);
        for( ll i = 1; i <= 2*p; i ++ ) {
            for( ll j = 1; j <= p; j ++ ) {
                if( i <= p ) {
                    mapn[i][j] = ((i-1)+(j-1))%p;
                } else {
                    mapn[i][j] = (i-1)*(j-1)%p;
                }
                if( j != p ) {
                    printf("%lld ",mapn[i][j]);
                } else {
                    printf("%lld
",mapn[i][j]);
                }
            }
        }
    }
    return 0;
}

  






























以上是关于2018中国大学生程序设计竞赛 - 网络选拔赛 hdu 6440 Dream 模拟的主要内容,如果未能解决你的问题,请参考以下文章

2018中国大学生程序设计竞赛 - 网络选拔赛

HDU - 6440 Dream 2018中国大学生程序设计竞赛 - 网络选拔赛

2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛

2018中国大学生程序设计竞赛 - 网络选拔赛 1009 - Tree and Permutation dfs+树上两点距离和

2018中国大学生程序设计竞赛 - 网络选拔赛 hdu6438 Buy and Resell 买入卖出问题 贪心

2018中国大学生程序设计竞赛 - 网络选拔赛 1001 - Buy and Resell 优先队列维护最小堆+贪心