第一次应聘实习 | 排列与阶乘进制

Leek posted @ 2010年5月26日 20:25 in 【算法学习】 with tags Coding 数据结构 实习 , 2298 阅读

昨天去ND面试 (车上收到有道短信 说下午视频答疑,估计也没什么问题问的就算了 .主考官直接问我什么时候有时间过去 (囧。然后说暑假吧,直接被他否决了 ,说是不能那么晚,现在就得去,平时没时间可以请假一个星期有到三四天就行了...就这样默默地答应了。之后回来打电话给我说明天要过去签协议,补贴方面800保障,出勤好的话每个月加80(可是网上说是1100,这里怎么变了呢 ,他解释什么税收管理费等(= =不是2k以上才要税收吗,显然地有猫腻...被人坑的感觉自然不爽加上路途漫漫(温泉路口 所以今天一大早打电话过去说不去了 酱紫第一次很山寨的笔试面试经历结束了...

        回来继续复习和整理算法。发现模板的《排列与阶乘进制》有猫腻,大牛的代码写的很玄乎看不出是不是真的错了(代码不能多几个注释嘛,然后按自己的想法改动了跑了一下果然假想没错

        现在就说说Coding吧,之前排列与顺序等问题直接都是土土地写地,看了阶乘进制赞叹Knuth大师的伟大(...  然后再看逆过程无比纠结(反正死活看不懂喽,然后偷偷暗想他Coding有问题吧,越看越有问题(= = 鄙视一下自己,经过简单数据验证还好真的是模板的问题(XD

        原先的逆过程:

 

void back(__int64 perm)
{
	int i, j, k, p[N + 1] = {0},mark[N + 1] = {0};
	i = 1;
	while (perm)
	{
		p[i] = perm % (i + 1);
		perm /= ++i;
	}

	for (i = n-1; i >= 1; --i)
	{
		j = n,k = 0;
		while (k <= p[i])
		{
			if (!mark[j++])
				k++;
		}
		j++;
		a[j] = i + 1;
		mark[j] = 1;
	}
	j = 1;
	while (mark[j])
		j++;
	a[j] = 1;
}
修改后代码:
void back(__int64 perm)
{
	int i, j, k, p[N + 1] = {0},mark[N + 1] = {0};
	i = 1;
	while (perm)
	{
		p[i] = perm % (i + 1);
		perm /= ++i;
	}

	for (i = n-1; i >= 1; --i)
	{
		j = 1,k = 0;
		while (k <= p[i])
		{
			if (!mark[j++])
				k++;
		}
		j--;
		a[n-i] = j;
		mark[j] = 1;
	}
	j = 1;
	while (mark[j])
		j++;
	a[N] = j;
}
顺便贴上转化为阶乘进制代码:
int KnuthPEncode()
{
	int i,j;
	int place = n,e = 0;
	for (i = 1; i <= n; ++i)
	{
		int t = a[i];
		e *= place--;
		for (j = i+1; j <= n ; ++j)
			a[j] < t &&  e++;
	}
	return e;
}
CGBSE 11th Question 说:
2022年8月25日 19:03

Chhattisgarh Class 11th Important Model Question Paper 2023 PDF is Proclaimed on the Official Website. CGBSE 11th Question Paper 2023 CG Board 11th Class Important Model Question Paper 2023 Scheme and Other Important Model Question Paper 2023 are Download From Here. Chhattisgarh XI Standard Biology, Accounting, Chemistry, Economics, Physics, Mathematics, Computer Last Year Important Model Question Paper 2023 are Published in Online Mode. Old Important Model Question Paper 2023 are Significant Study Materials for Pursuing Candidates. CG Class 11th Arts, Science, and Commerce Streams Students can Download the Important Model Question Paper 2023 for Further Uses. Chhattisgarh Board 11th Important Model Question Paper 2023 Details are Given on This Page.

civaget 说:
2023年12月10日 03:42

백링크 is your golden ticket to organic traffic. When other websites endorse your content, you not only gain valuable visitors but also signal to search engines that your content is authoritative.

civaget 说:
2023年12月10日 21:24

Join the EPL conversation with epl무료중계's expert insights and comprehensive coverage.

civaget 说:
2023年12月10日 21:41

오피 Magazine is a valuable urban guide, offering insights and relaxation tips for city dwellers seeking respite from their hectic lives.

civaget 说:
2023年12月11日 21:47

대부도키즈풀빌라 offers a well-rounded experience for families. Toys, play areas, and learning opportunities all in one place.

SEO 说:
2023年12月19日 12:40

커뮤니티 토토매치 ensures safety and satisfaction in online betting. Trustworthy reviews and ratings, along with Toto Match's insights, lead to the best betting choices.

civaget 说:
2023年12月20日 14:50

If you haven't been to 인천오피 yet, you're missing out. The spa retreat is a sanctuary, and their massages are simply exceptional. A must-visit!

civaget 说:
2023年12月28日 21:52

Is there a tutorial on how to use 폰허브?

civaget 说:
2023年12月28日 22:11

I had the best massage of my life at 전주휴게텔. The therapists are skilled, and the sauna is a wonderful addition. I can't wait to go back!

civaget 说:
2023年12月31日 14:36

누누티비 is a movie lover's haven. Say goodbye to ads and hello to unlimited entertainment.

SEO 说:
2024年1月23日 17:37 It is very interesting topic you’ve written here..The truth I’m not related to this, but I think is a good opportunity to learn more about, And as well talk about a different topic to which I used to talk with others The Presidential Family
how to turn off do n 说:
2024年2月03日 12:52

I love your blog.. very nice colors & theme. Did you create this website yourself or did you hire someone to do it for you? Plz answer back as I’m looking to create my own blog and would like to know where u got this from. thanks

SEO 说:
2024年2月04日 15:27

Many thanks for being the mentor on this niche. We enjoyed the article greatly and most of all appreciated how you really handled the issues I regarded as being controversial. You are always very kind towards readers really like me and assist me to in my life. Thank you. Palm Beach Gardens Büyükçekmece Escort

seo 说:
2024年2月07日 15:28

Loving the information on this web site , you have done great job on the posts . agen murahqq

sar 说:
2024年2月07日 20:44

I seriously loved this post. You describe this topic adequately. When hiring home contractors it’s critical for go with a trusted name in construction. Experienced and efficient staff should shoot for excellence and absorb every detail of your dwelling. Sugar Defender

seo 说:
2024年2月11日 12:47

Generally I do not read article on blogs, however I wish to say that this write-up very forced me to check out and do so! Your writing taste has been amazed me. Thanks, very great post. 셔츠룸

sar 说:
2024年2月11日 21:13

The post is written in very a good manner and it contains many useful information for me. sevilla

seo 说:
2024年2月12日 17:50

Nice information, many thanks to the author. It is incomprehensible to me now, but in general, the usefulness and significance is overwhelming. Thanks again and good luck! Blox Fruits codes

seo 说:
2024年2月12日 19:29

hey there, your site is fantastic. I do thank you for work Best price for battery tab

seo 说:
2024年2月13日 12:07

ello! I’ve been following your blog for a while now and finally got the courage to go ahead and give you a shout out from Kingwood Texas! Just wanted to mention keep up the good work! Steroidify

roses delivery abu d 说:
2024年4月16日 01:15

I am overwhelmed by your post with such a nice topic. Usually I visit your blogs and get updated through the information you include but today’s blog would be the most appreciable. Well done!


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter