2018中国大学生程序设计竞赛 - 网络选拔赛 Dream hdu6440 Dream 给出一个(流氓)构造法

http://acm.hdu.edu.cn/showproblem.php?pid=6440

题意:让你重新定义任意一对数的乘法和加法结果(输出乘法口诀表和加法口诀表),使得m^p+n^p==(m+n)^p(p为质数),并且存在一个0<q<p使得 q^k(0<k<p)取遍1~p-1的所有值,并且该运算是封闭的(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}.)

题解:不难看出,出题人想要你把加法重定义成乘法,这样明显满足m^p+n^p==(m+n)^p,并且modp以后能取遍1~p-1的所有值。并且能卡掉全部输出零的流氓方法。

这里给出另一种流氓做法,

先考虑如何使得 q^k取遍1~p-1的所有值,

因为q^5==1*q*q*q*q*q,

定义

1*q=2

2*q=3

3*q=4

4*q=1

于是q^5次方为2.

在乘法表中就是竖着填2341。

我们把每一列都这么填,

此时对任意x有x^p==2,我们只需将m^p+n^p定义成二即可。

怎么做呢? 把加法表填满2就行。

ac代码:

#include<iostream>
#include<cstdio>
using namespace std;
int n, N;
#define rep(i,t,n)  for(int i =(t);i<=(n);++i)
#define per(i,n,t)  for(int i =(n);i>=(t);--i)
int main() {
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        if (n == 2) {printf("0 1\n1 0\n0 0\n0 1");}
        else {
            rep(i, 1, n) { rep(j, 1, n) cout << 2 << ‘ ‘; cout << endl; }
            rep(i, 1, n)printf("0 "); printf("\n");
            rep(i, 2, n - 1) {rep(j, 1, n) printf("%d ", i ); printf("\n");}
            rep(i, 1, n)printf("1 "); printf("\n");
        }

    }
    return 0;
}

原文地址:https://www.cnblogs.com/SuuT/p/9534892.html

时间: 2024-08-29 08:30:29

2018中国大学生程序设计竞赛 - 网络选拔赛 Dream hdu6440 Dream 给出一个(流氓)构造法的相关文章

HDU6447 YJJ&#39;s Salesman 2018中国大学生程序设计竞赛 - 网络选拔赛1010 离散化+线段树+DP

YJJ's Salesman Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 253    Accepted Submission(s): 62 Problem Description YJJ is a salesman who has traveled through western country. YJJ is always on

2018中国大学生程序设计竞赛 - 网络选拔赛 1010 YJJ&#39;s Salesman 【离散化+树状数组维护区间最大值】

题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6447 YJJ's Salesman Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 919    Accepted Submission(s): 290 Problem Description YJJ is a salesman who h

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

传送门 A.HDU6438 Buy and Resell 题意 给你N天N个价格,每天都可以从1.买入一个,2.卖出一个,3.什么都不做,求最高获利 低买高卖问题,这题与其他的差距就是要在满足获利最多的情况下,买卖次数最小; 思路 手算一下发现价格具有传递性;例如数据是1,5,9; 5的时候买入1赚了4;9的时候买入5赚了4;相当于直接把5当成跳板直接9的时候买1;然后再把中间的5当成没有买过的; 建立一个小根堆(优先队列);把当前遇到的天数的价钱放入,然后对于第i天; 1.如果新天数的价钱比堆

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

Buy and Resell Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1126    Accepted Submission(s): 359 Problem Description The Power Cube is used as a stash of Exotic Power. There are n cities numbe

HDU 5833 Zhu and 772002(高斯消元)——2016中国大学生程序设计竞赛 - 网络选拔赛

传送门 Zhu and 772002 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 48    Accepted Submission(s): 16 Problem Description Zhu and 772002 are both good at math. One day, Zhu wants to test the abili

2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6154 CaoHaha&#39;s staff 思维

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6154 题意:在笛卡尔坐标系下,画一个面积至少为  n 的简单多边形,每次只能画一条边或者一个格子的对角线,问至少要画几条. 解法:如果一个斜着的矩形长宽分别是 a,b,那么它的面积是 2ab.最优解肯定是离 sqrt(n/2)很近的位置.想想 n=5 时答案为什么是7 然后在那个小范围内枚举一下就好了.我给一张做题时画的图 #include <bits/stdc++.h> using namesp

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

solved 4/11 2016中国大学生程序设计竞赛 - 网络选拔赛

HDU 5832 A water problem(取模~)—— 2016中国大学生程序设计竞赛 - 网络选拔赛

传送门 A water problem Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 60    Accepted Submission(s): 37 Problem Description Two planets named Haha and Xixi in the universe and they were created wit

2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6154 CaoHaha&#39;s staff(几何找规律)

Problem Description "You shall not pass!"After shouted out that,the Force Staff appered in CaoHaha's hand.As we all know,the Force Staff is a staff with infinity power.If you can use it skillful,it may help you to do whatever you want.But now,hi