2018CCPC网络赛 C - Dream

题意

给定一个P,现在可以以任意方式重载'+'和'*'两个符号,使得满足下列等式

其中定义如下

需要注意的是,重载过后的'*'需要满足以下要求:

也就是说,重载'*'之后通过计算得到的**(k=1,2,3,...,p-1)的取值对于集合{1,2,3,...,p-1}是一个一一映射的关系**

​​​​最后输出2*p行,按照自己重载的'+'和'*',输出:

思路

由于可以以任意方式重载,所以可以把a+b直接重载为a+0 ,此时等式变成了,,可以发现等式恒成立,现在只需要满足一一映射就可以了,可以想到把a*b直接重载为a+1 ,按照上面的定义,=>(也就是)=>(也就是)=>.....=>k+1

此时得到的集合就是{2,3,4,....,p}恰好与一一映射需要的集合差一个p 于是对a*b的重载中加一个判断如果得到p就返回1就可以解决这个问题

代码

cpp 复制代码
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <cmath>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define pp pop_back()
#define int long long
#define laile cout<<"laile"<<endl
#define lowbit(x) ((x)&(-x))
#define double long double
#define sf(x) scanf("%lld",&x)
#define sff(x,y) scanf("%lld %lld",&x,&y)
#define sd(x) scanf("%Lf",&x)
#define sdd(x,y) scanf("%Lf %Lf",&x,&y)
#define _for(i,n) for(int i=0;i<(n);++i)
#define _rep(i,a,b) for(int i=(a);i<=(b);++i)
#define _pre(i,a,b) for(int i=(a);i>=(b);--i)
#define all(x) (x).begin(), (x).end()
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
int p;
int deal(int a,int b)
{
	int now=a+1;
	if(now==p)return 1;
	else return now;
}
void solve()
{
	cin>>p;
	_rep(i,1,p)
	{
		_rep(j,1,p)
			cout<<(i-1)<<" ";
		cout<<'\n';
	}
	_rep(i,1,p)
	{
		_rep(j,1,p)
		cout<<deal(i-1,j-1)<<" ";
		cout<<'\n';
	}
	return ;
}
signed main()
{
	IOS;
	int T=1;
	cin>>T;
	while(T--)
		solve();
	return 0;
}
相关推荐
傻啦嘿哟21 分钟前
王者荣耀爬虫:爬取全英雄皮肤数据,用Python做可视化分析
开发语言·爬虫·python
优化Henry23 分钟前
学习笔记之爱立信站点指向证书执行
运维·服务器·网络·笔记·学习·信息与通信
AI直播技术杂谈26 分钟前
直播画面突然模糊了,排查了三个小时
开发语言·php
菜冻鱼35 分钟前
Python-pytorch-数据加载
开发语言·人工智能·pytorch·python·深度学习·机器学习
heimeiyingwang40 分钟前
【架构实战】可观测性三支柱实战:Metrics、Logging、Tracing 如何统一落地
开发语言·架构·php
霸道流氓气质43 分钟前
邮件发送服务(以 SendGrid 为例)— 概念、原理、场景与代码示例
网络
—Miss. Z—1 小时前
第11章 故障管理
网络·数据库·oracle
保密资质顾问说1 小时前
网络安全等级保护与涉密信息系统集成资质的区别及选型分析
运维·网络·经验分享·安全·web安全
caimouse1 小时前
ReactOS 图形系统分析(53):系统库存对象 — stockobj.c
c语言·开发语言·spring
ZJU_统一阿萨姆1 小时前
【推理优化进阶】通信关键路径:NCCL、RDMA 与计算通信重叠
开发语言·人工智能·语言模型·架构·系统架构