IOI 94 The Clock 详细的总结,从指数级复杂度到常数时间的优化

Shor算法如何动摇RSA加密?原理、模拟器实操与后量子迁移 现代信息安全中,公钥加密体系(如RSA)的安全性依赖于大整数分解的数学困难性。然而,量子计算的崛起带来了新的变数:Shor算法借助量子傅里叶变换,可以在多项式时间内快速寻找周期,从而将大整数分解的复杂度从亚指数级降到多项式级,直接冲击RSA的根基。这一威胁不仅影响加密通信、数字签名等广泛应用,也推动后量子密码学成为研究焦点。从原理到实操,结合模拟器分解15与21的完整流程,分析当前量子硬件与攻击RSA-2048之间的真实差距,并给出后量子密码迁移的可行步骤,帮助安全从业者理性应对这个潜在危机。 阅读详情

原题

如果用bfs的话,也即,把操作顺序的先后考虑上的话,那么要注意用hash表来判重,用空间换时间。这个低效的方法也是能过的……

//hash表判重,dfs,从短到长按字典序扩展操作序列的长度 
/*
{
ID: lzwjava1
PROG: clocks
LANG: C++
}
*/
#include<cstdio>
#include<cstring>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
const int MaxState=500000;
int move[9][5]={{0,1,3,4},{0,1,2},{1,2,4,5},{0,3,6},
{1,3,4,5,7},{2,5,8},{3,4,6,7},{6,7,8},{4,5,7,8}};
int Nmove[9]={4,3,4,3,5,3,4,3,4};

typedef char state[9];
state st[MaxState];
char oper[MaxState];

bool isGoal(state a)
{
	for(int i=0;i<9;i++)
	  if(a[i]) return false;
  return true;
}

int fa[MaxState];

void doOper(state &a,int op)
{
	for(int i=0;i<Nmove[op];i++)
	  ++a[move[op][i]]%=4;
}

const int HashSize=10007;
int head[HashSize];
int next[MaxState];
int value[10];

int hash(int u)
{
	int t=0;
	for(int i=9;i>=0;i--)//mistook:i++,it should be"i--"
	  t+=value[9-i]*st[u][i];
  return t%HashSize;
}

bool tryToInsert(int u)
{
	int h=hash(u);
	int p=head[h];
	while(p!=-1)
	{
		if(memcmp(st[p],st[u],sizeof(st[p]))==0) return false;
		p=next[p];
	}
	next[u]=head[h];
	head[h]=u;
	return true;
}

void init_hash()
{
	memset(head,-1,sizeof(head));
	value[0]=1;
	for(int i=1;i<10;i++)
	  value[i]=value[i-1]*4;
}

int bfs()
{
	int front,rear;
	front=0;rear=1;
	fa[front]=-1;
	init_hash();
	while(front<rear)
	{
		state &u=st[front];
		if(isGoal(u)) return front;
		for(int i=0;i<9;i++)
		{
			state &v=st[rear];
			memcpy(v,u,sizeof(v));
			doOper(v,i);
			if(tryToInsert(rear))
			{
				fa[rear]=front;
				oper[rear++]=i;
			}
		}
		front++;
	}
}

void print_ans(int u)
{
	if(fa[u]==-1) return;
	print_ans(fa[u]);
	if(fa[u]!=0)  printf(" ");
  printf("%d",oper[u]+1);
}

int main()
{
  freopen("clocks.in","r",stdin);
  freopen("clocks.out","w",stdout);
  int i,j;
  for(i=0;i<9;i++)
  {
  	int t;
  	scanf("%d",&t);
  	st[0][i]=t/3%4;
  	//printf("%d\n",st[0][i]);
  }
  int ans=bfs();
  //printf("%d\n",ans);
  print_ans(ans);printf("\n");
  return 0;
}

/*
*/

事实上,操作的先后并不重要。用dfs降低空间复杂度,但最坏的时间复杂度是一样的。4^9。bfs找到解即返回。

//dfs,无所谓操作的先后,而只记次数。遍历每一种可能的情况。 
/*
{
ID: lzwjava1
PROG: clocks
LANG: C++
}
*/
#include<cstdio>
#include<cstring>
#include<stdlib.h>
using namespace std;
const int MaxMove=27;
char move[9][9]={"ABDE","ABC","BCEF",//直接复制粘贴题目,在程序中来得到操作矩阵 
"ADG","BDEFH","CFI","DEGH","GHI","EFHI"};
int A[9];
int best[9];//最优答案 
int nbest;//最优答案的序列长度。先要最短,然后字典序最小 
int Clock[9][9];//Clock[i][j]为操作i一次j需要转过的刻钟的数目,3表示90°,0表示0°。只有这两种情况 
FILE *in,*out;

void cal_Clock()
{
	memset(Clock,0,sizeof(Clock));
	char *p;
	for(int i=0;i<9;i++)
		for(p=move[i];*p;p++)
		  Clock[i][*p-'A']=3;
}

bool is_ok(int *A)
{
	for(int i=0;i<9;i++)
	  if(A[i]!=12) return false;
  return true;
}

void solve(int *m,int cur)
{
	int i,j;
	if(cur==9)
	{
		if(is_ok(A))
		{
			int t=0;
			for(i=0;i<cur;i++) t+=m[i];
			if(!nbest || t<nbest)
			{
				memcpy(best,m,sizeof(best));
				nbest=t;
			}
		}
		return;//mistook:没加 
	}
	for(i=3;i>=0;i--)//先3个小序号的操作,这样可以得到最小字典序的方案 
	{
		for(j=0;j<i;j++)
			for(int k=0;k<9;k++)
			{
				A[k]+=Clock[cur][k];
				if(A[k]==15) A[k]=3;
				//fprintf(out,"A[k]=%d\n",A[k]);
			}
		m[cur]=i;
		solve(m,cur+1);
		for(j=0;j<i;j++)
			for(int k=0;k<9;k++)
			{
				A[k]-=Clock[cur][k];
				if(A[k]==0) A[k]=12;
			}
	}
}

void testClock()
{
	int i,j;
	for(i=0;i<9;i++,printf("\n"))
	  for(j=0;j<9;j++)
	  {
  		printf(" %d",Clock[i][j]);
  	}
}

int main()
{
	in=fopen("clocks.in","r");
	out=fopen("clocks.out","w");
	int i,j;
	for(i=0;i<9;i++) fscanf(in,"%d",&A[i]);
	//for(i=0;i<9;i++) printf("%d ",A[i]);
	int m[9];//m为次数数组,m[i]为执行操作i的次数 
	cal_Clock();
	//testClock();
	nbest=0;
	solve(m,0);
	bool first=true;
	for(i=0;i<9;i++)
	  if(best[i])
	  {
  		for(j=0;j<best[i];j++)
  		{
		  	if(!first) fprintf(out," ");
		  	else first=false;
		  	fprintf(out,"%d",i+1);
		  }
  	}
	fprintf(out,"\n");
	exit(0);
}

还可以通过打表得到最优解。这下可以优化到常数时间。

简便起见,把3,6,9,10表示成0,1,2,3。现在得到一个数组A,有9个操作,记第i个操作为O[i],O[i]让数组A中的某些数向前增加1,超过3则变为0。求一个最短的操作序列,让数组A的9个元素都变为0。

记V[j]为在最终的操作序列中执行O[j]的次数。

a[i][j],表示仅让A[i]向前增1,而其它数都不变,所要执行O[j]的次数。得到矩阵a。矩阵a可以通过dfs的方法得到。

先求得a数组。改造一下上面的程序即可。

//dfs,巧妙得到a数组 
#include<cstdio>
#include<cstring>
#include<stdlib.h>
using namespace std;
const int MaxMove=27;
char move[9][9]={"ABDE","ABC","BCEF",
"ADG","BDEFH","CFI","DEGH","GHI","EFHI"};
int A[9];
int best[9];
int nbest;
int Clock[9][9];
FILE *in,*out;

void cal_Clock()
{
	memset(Clock,0,sizeof(Clock));
	char *p;
	for(int i=0;i<9;i++)
		for(p=move[i];*p;p++)
		  Clock[i][*p-'A']=3;
}

bool is_ok(int *A)
{
	for(int i=0;i<9;i++)
	  if(A[i]!=12) return false;
  return true;
}

void solve(int *m,int cur)
{
	int i,j;
	if(cur==9)
	{
		if(is_ok(A))
		{
			int t=0;
			for(i=0;i<cur;i++) t+=m[i];
			if(!nbest || t<nbest)
			{
				memcpy(best,m,sizeof(best));
				nbest=t;
			}
		}
		return;//mistook:没加 
	}
	for(i=3;i>=0;i--)
	{
		for(j=0;j<i;j++)
			for(int k=0;k<9;k++)
			{
				A[k]+=Clock[cur][k];
				if(A[k]==15) A[k]=3;
				//fprintf(out,"A[k]=%d\n",A[k]);
			}
		m[cur]=i;
		solve(m,cur+1);
		for(j=0;j<i;j++)
			for(int k=0;k<9;k++)
			{
				A[k]-=Clock[cur][k];
				if(A[k]==0) A[k]=12;
			}
	}
}

void testClock()
{
	int i,j;
	for(i=0;i<9;i++,printf("\n"))
	  for(j=0;j<9;j++)
	  {
  		printf(" %d",Clock[i][j]);
  	}
}

void work()
{
	//in=fopen("clocks.in","r");
	int i,j;
	//for(i=0;i<9;i++) printf("%d ",A[i]);
	int m[9];
	//testClock();
	nbest=0;
	solve(m,0);
	bool first=true;
	fprintf(out,"{%d",best[0]);
	for(i=1;i<9;i++)
	  fprintf(out,",%d",best[i]);
	fprintf(out,"},\n");
}

int main()
{
	out=fopen("a.out","w");
	int i,j;
	for(i=0;i<9;i++) A[i]=12;
	cal_Clock();
	for(i=0;i<9;i++)
	{
		A[i]=9;
		work();//得到尽让钟i转过90度的最优序列
		A[i]=12;
	}
	exit(0);
}
接下来,神代码出现了:

//dfs下得到预处理数组。情况有限, 
/*
{
ID: lzwjava1
PROG: clocks
LANG: C++
}
*/
#include<cstdio>
#include<cstring>
int a[9][9]={
{3,3,3,3,3,2,3,2,0},
{2,3,2,3,2,3,1,0,1},
{3,3,3,2,3,3,0,2,3},
{2,3,1,3,2,0,2,3,1},
{2,3,2,3,1,3,2,3,2},
{1,3,2,0,2,3,1,3,2},
{3,2,0,3,3,2,3,3,3},
{1,0,1,3,2,3,2,3,2},
{0,2,3,2,3,3,3,3,3}
};

int main()
{
	freopen("clocks.in","r",stdin);
	freopen("clocks.out","w",stdout);
	int v[9];//v[i]表示操作i的执行次数 
	memset(v,0,sizeof(v));
	int i,j,k;
	for(i=0;i<9;i++)
	{
		scanf("%d",&k);
		for(j=0;j<9;j++)//计算把第i个钟的k变为12 v数组的变化。 
		  v[j]=(v[j]+a[i][j]*(12-k)/3)%4;//转一次,要执行j操作a[i][j]次 
	} 
	bool first=true;
	for(i=0;i<9;i++)
	  if(v[i])
	  {
  		for(j=0;j<v[i];j++)
  		{
		  	if(first) first=false;
  		  else printf(" ");
  		  printf("%d",i+1);
		  }	  
  	}
	printf("\n");
	return 0;
}

如果不是很理解,见:

Lucian Boca submitted a constant time solution

You can precalculate a matrix a as following:

a[i][0],a[i][1],....,a[i][8] is the number of moves '1','2','3',...'9' necessarly to move ONLY clock i (where 0 < i <= 8 - there are 9 clocks: 0=A, 1=B, ... 8=I) 90 degrees clockwise. So, you have the matrix:

int a[9][9]= { {3,3,3,3,3,2,3,2,0},
               {2,3,2,3,2,3,1,0,1},
               {3,3,3,2,3,3,0,2,3},
               {2,3,1,3,2,0,2,3,1},
               {2,3,2,3,1,3,2,3,2},
               {1,3,2,0,2,3,1,3,2},
               {3,2,0,3,3,2,3,3,3},
               {1,0,1,3,2,3,2,3,2},
               {0,2,3,2,3,3,3,3,3} };

That means: to move ONLY the clock 0 (clock A) 90 degrees clockwise you have to do {3,3,3,3,3,2,3,2,0}, 3 moves of type 1, three moves of type 2, ..., 2 moves of type 8, 0 moves of type 9, etc.

To move ONLY the clock 8 (clock I), you have to do the moves {0,2,3,2,3,3,3,3,3}: 0 moves of type 1, 2 moves of type 2... 3 moves of type 9....

That's it! You count in a vector v[9] how many moves of each type you have to do, and the results will be modulo 4 (%4 - 5 moves of any type have the same effect 1 move has). 


【安全算法之概述】一文带你简要了解常见常用的安全算法(RT-Thread技术论坛优秀文章) 【安全算法】一文带你简要了解常见常用的安全算法**0 前言****1 算法的大致分类****2 对称加解密算法****2.1 DES/TDES算法****2.2 AES算法****2.3 SM4算法****2.4 RC2、RC4算法****2.5 对称加密算法对比总结****3 非对称加解密算法****3.1 对称加密算法与非对称加密算法的本质区别****3.2 非对称加密算法的分类和对比****3.2.1 RSA算法****3.2.2 SM2算法****3.2.3 ECC算法**3.2.3.1 **优点* 阅读详情

相关推荐

基于verilog的16QAM调制

思路1:正交调幅法——实现16QAM调制,可以理解为时相位相差90度的两个正弦波的4PAM叠加。 4比特输入经过2->4进制转化得到两路2比特输入,然后分别经过4PAM后叠加所得输出即为16QAM调制结果。 具体程序稍后编写。 思路2:复合相移法——可以借助前面编写的QPSK,相当于两路幅度不同的QPSK的叠加,比如幅度分别取1和3 。 思路1正交调幅法的设计方案: 两正弦波相位差...

weixin_30725467的博客 2929

IOI 1994 The_Triangle 题解

蒟蒻的第一篇题解吧,,,也是蒟蒻的第一个AC的DP题。 感觉这个应该是当年的一道签到题了。。。 题目是这样的。。。(蒟蒻从自家学校OJ上扒的,不知道是不是,不是也凑合着当是看吧23333) Description 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 (Figure 1) Fi...

QuaDparAlk_的博客 483

快速搭建SpringBoot3+Vue3+ElementPlus管理系统

快速搭建SpringBoot3+Vue3管理系统前端项目搭建(默认开发环境:node20,Jdk17)创建项目并下载依赖--执行以下命令 前端项目搭建(默认开发环境:node20,Jdk17) 创建项目并下载依赖–执行以下命令 创建项目 yarn create vite admin-vue --template 2.下载依赖(也可按需下载) yarn add echarts --save yarn add vue-router --save yarn add element-plus --save y

adingyb的博客 2817

[USACO1.4] [IOI1994]时钟 The Clocks

每个函数都保持在20行以内,出锅的概率大大降低,编译样例无debug一遍过,这里不是说代码能力有多好,而是说,使用这个写法,会让自己思路更加清晰,一段时间内只关注一段逻辑,很多人代码debug不出来不是因为代码能力弱,反而是因为代码能力太强,像一个。这样的代码在自己脑子十分清晰的时候是可以码的飞起的,不过可能只有两天内的自己才能看懂,可能过了两天自己回头看的时候惊呼“我靠,什么shit”。bfs肯定是那个bfs,关键是状态的表示,可以用一个int来表示状态,这样转移的时候比较麻烦,也可以用。

NDCSID的博客 974

陆地观测卫星数据服务平台深度体验:高分、中巴、资源系列影像的检索与下载技巧

本文深度解析国产陆地观测卫星数据服务平台的使用技巧,重点介绍高分、中巴、资源系列卫星影像的检索与下载方法。通过权限体系解析、高级检索策略、数据预处理等实战技巧,帮助用户高效获取高质量遥感数据,适用于环境监测、资源调查等多种应用场景。

eee77的博客 980

同步整流buck电路图设计:手把手入门必看

从零开始拆解同步整流Buck电路图及其原理,手把手带你画出关键拓扑、选型MOSFET、分析续流路径。重点讲清占空比控制逻辑与体二极管导通损耗的规避方法,让buck电路图及其原理真正落地可调、稳定可靠。

weixin_33308579的博客 995

1.算法入门必知必会:时间复杂度和空间复杂度

时间复杂度与系数无关 如何判断一段代码的时间复杂度,就是直接看他会执行多少次 一、常见的时间复杂度 O(1) Constant Complexity 常数复杂度 下面的都是常数复杂度,与系数无关。打印三次sysout他的时间复杂度也是O(1) int n = 1 System.out.println("abc is"+n); int n = 2 System.out.println("abc is"+n); System.out.println("bdc is"+n); System.out.

AsapDawn的博客 2603

深入傅里叶级数与傅里叶变换:从基础到应用

傅里叶分析为我们提供了一种理解信号频率结构的强大工具。从傅里叶级数到傅里叶变换,再到快速傅里叶变换(FFT),其理论与应用紧密结合,对现代科学技术的发展意义非凡。如果你对信号处理、数据分析或工程计算感兴趣,傅里叶分析是必须掌握的基础工具。希望本文能帮助你对傅里叶分析有更深入的理解!如果有问题或想法,欢迎在评论区讨论!

qq_56683019的博客 3519

时间复杂度(学习总结)

什么是时间复杂度?时间复杂度是用来干什么? 时间复杂度是一个函数,用来定性描述算法的运行时间。 假设算法的问题规模为n,那么操作单元数量便用函数f(n)来表示,随着数据规模n的增大,算法执行时间的增长率和f(n)的增长率相同,这称作为算法的渐近时间复杂度,简称时间复杂度,记为 O(f(n))。 在软件开发中,时间复杂度方便开发者估算当前程序运行的一般时间。 数据规模对时间复杂度有什么影响? 从下图中可以看出不同算法的时间复杂度在不同数据输入规模下...

weixin_45720714的博客 3447

本地搭建 GitLab 14.1.0版本CI/CD

GitLab 镜像版本 gitlab/gitlab-ce:14.1.0-ce.0 GitLab Runner 镜像版本 gitlab/gitlab-runner:v14.1.0 搭建此套环境是在一台32G的windows电脑上安装的。 使用dokcer安装。 此外还涉及的软件Docker Desktop,WSL 安装GitLab 首先启动 dockcer,打开WSL 打开后 首先定义GitLab的持久化目录 export GITLAB_HOME=/srv/gitlab 然后运行安装GitLab的命令

知无涯 4491

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

【算法与数据结构】5 常见的时间复杂度,你知道吗?

1.常见的时间复杂度1.1 O(n)级别1.21.3 🚩复杂度分析,定要明确n是什么1.4 O(logn)1.5 1.6 指数级别的复杂度1.7 阶乘级别的复杂度1.8 常数级别的复杂度O(1)1.9 常见时间复杂度的比较2.空间复杂度

爱书不爱输的程序猿 2236

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

算法的复杂度分析

文章目录一、大 O 复杂度表示法1.1 时间复杂度1.2 空间复杂度 一、大 O 复杂度表示法 1.1 时间复杂度 假设每行代码运行的时间为 unit_time ,那么所有代码的总执行时间 T(n)与每行代码的执行次数 f(n) 成正比,那么可得:T(n) = O(f(n)),此处大 O 表示的不是代码的具体执行时间,而是代码的执行时间虽数据规模增长的变化趋势。 加法法则:算法的总时间复杂度等于算法中量级最大的复杂度,通常情况下公式中的低阶、常量和系数都可以忽略,例如:O(n2 + n + 2) = O(

不会飞的鱼的博客 660

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

USACO:1.4.2 The Clocks 时钟(IOI 94) 解析

USACO:The Clocks 时钟(IOI 94) 解析 IOI'94 - Day 2 题目描述: 考虑将如此安排在一个3X3 行列中的九个时钟: |-------| |-------| |-------| | | | | | | | |---O | |---O | | O |

蓝e的专栏 2669

算法复杂度介绍

复杂度分析是估算算法执行效率的方法,**公式O(f(n))表示算法的复杂度**,此方法即为**大O复杂度表示法O(f(n))中n表示数据规模**,**f(n)表示运行算法所需要执行的指令数**。

weixin_46002001的博客 803

The Clocks(DFS)

The ClocksIOI'94 - Day 2 Consider nine clocks arranged in a 3x3 array thusly: |-------| |-------| |-------| | | | | | | | |---O | |---O | | O |...

Simone chou... 228

java基础面试题

java基础面试题http常用的状态码数据库索引的作用数据库索引的缺点联合索引注意事项(最左前缀原则)数据库事务三大范式索引失效的几种情况表的冗余字段什么情况下使用常见的加密算法对称加密算法和非对称加密算法的区别摘要算法加密的目的https怎么实现通信加密restful是什么前后端的跨域问题http默认端口https默认端口tcp三次握手http怎么实现数据压缩参数linux常用命令常用的数据结构数据和链表的使用场景区别有哪几种排序算法冒泡排序的时间复杂度什么是时间复杂度mybatis#{}和${}的区别$

NewBeeMu的博客 1381

时间复杂程度和计算方式

例如,如果某个算法的时间复杂度为O(n),表示算法的运行时间与输入规模n成线性关系。确定增长数量级:根据操作次数的分析,我们可以得到一个与输入规模n相关的函数,表示算法的运行时间。即假设算法的输入是最坏情况下的输入,这样可以保证对于任意输入,算法的运行时间都不会超过最坏情况下的运行时间。输入规模是衡量问题规模大小的指标,例如,可以用数组的长度n、列表的长度n、图的节点数等来表示。指数时间复杂度 (O(2^n)):算法的运行时间与输入规模n的指数关系,通常出现在一些穷举搜索等指数级算法中。

lewis_cai的博客 291

复杂度分析

复杂度分析是整个算法的精髓,衡量算法好坏的两个重要指标是时间复杂度分析以及空间复杂度分析

My Blog 620

[IOI 1994]数字三角形

数字三角形总时间限制: 1000ms 内存限制: 65536kB 描述 7 3 8 8 1 0 2 7 4 44 5 2 6 5 (图1)图1给出了一个数字三角形。从三角形的顶部到底部有很多条不同的路径。对于每条路径,把路径上面的数加起来可以得到一个和,你的任务就是找到最大的和。 输入

songyu005615的博客 743

如何计算时间复杂度

一、概念 时间复杂度是总运算次数表达式中受n的变化影响最大的那一项(不含系数) 比如:一般总运算次数表达式类似于这样: a*2^n+b*n^3+c*n^2+d*n*lg(n)+e*n+f a ! =0时,时间复杂度就是O(2^n); a=0,bO(n^3); a,b=0,cO(n^2)依此类推 eg: (1) for(i=1;i //循环了n*n次,当然是O(n^2)

firefly_2002的专栏 33万+

Python常见操作的时间复杂度计算

在Python中,不同操作的时间复杂度可以通过大O表示法来计算。以下是常见操作的时间复杂度计算:常数时间复杂度:O(1) 无论数据规模的大小,操作都可以在常数时间内完成。例如,访问列表或字典中的元素,执行算术运算等。线性时间复杂度:O(n) 操作的执行时间与数据规模n成正比。例如,遍历一个列表,求列表或字符串的长度等。对数时间复杂度:O(log n) 操作的执行时间随着数据规模n的增加而增加,但是不是线性增长。例如,在二分查找算法中,每次操作都能将搜索范围减半。

captain 2358

洛谷 P1213 时钟 &&IOI 1994 The Clocks

IOI 1994 The Clocks 题目描述 考虑将如此安排在一个 3 x 3 行列中的九个时钟: 目标要找一个最小的移动顺序将所有的指针指向12点。下面原表格列出了9种不同的旋转指针的方法,每一种方法都叫一次移动。选择1到9号移动方法,将会使在表格中对应的时钟的指针顺时...

weixin_30580341的博客 376

初学数据结构

数据结构分类与类型 1.数据结构分类 2.数据类型 数据类型的分类类似于离散数学中的分类 算法 1.算法的特性 在《计算机科学导论》中我们学过,算法有着以下特性: 2.怎么计算效率? 事前分析估算法 我们都知道二重循环要花费的时间一定比两个一重循环花的时间久,类似于这样的判断得出的结论就是事前分析估算法。 事后统计方法 通过同一计算机对不同程序所花费的时间进行对比,从而得出结论的方法就是事后...

TGYYS的博客 1084

算法复杂度及常数优化

各种

weixin_43192587的博客 623
上一篇: 马拉松
下一篇: 优秀的年轻企业家Sam Altman给19岁满怀壮志的青年的建议
lzw_java
博客等级 码龄15年 49粉丝 73原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值