落絮飞雁

顺流而下,把梦做完

POJ1833:排列——全排列问题

Description

题目描述:
大家知道,给出正整数n,则1到n这n个数可以构成n!种排列,把这些排列按照从小到大的顺序(字典顺序)列出,如n=3时,列出1 2 3,1 3 2,2 1 3,2 3 1,3 1 2,3 2 1六个排列。

任务描述:
给出某个排列,求出这个排列的下k个排列,如果遇到最后一个排列,则下1排列为第1个排列,即排列1 2 3…n。
比如:n = 3,k=2 给出排列2 3 1,则它的下1个排列为3 1 2,下2个排列为3 2 1,因此答案为3 2 1。
Input

第一行是一个正整数m,表示测试数据的个数,下面是m组测试数据,每组测试数据第一行是2个正整数n( 1 <= n < 1024 )和k(1<=k<=64),第二行有n个正整数,是1,2 … n的一个排列。
Output

对于每组输入数据,输出一行,n个数,中间用空格隔开,表示输入排列的下k个排列。
Sample Input

3
3 1
2 3 1
3 1
3 2 1
10 2
1 2 3 4 5 6 7 8 9 10
Sample Output

3 1 2
1 2 3
1 2 3 4 5 6 7 9 8 10

一道全排列问题。用next_permutation轻松AC。注意头文件是algorithm即可。


#include
#include
using namespace std;
int cache[2000];
int main()
{
	int N;
	scanf("%d", &N);
	while (N--)
	{
		int n, k, i;
		scanf("%d%d",&n,&k);
		for (i = 0; i < n; i++)
			scanf("%d", &cache[i]);
		for (i = 0; i < k; i++)
			next_permutation(cache, cache + n);
		printf("%d", cache[0]);
		for (i = 1; i < n; i++)
			printf(" %d", cache[i]);
		printf("n");
	}
	return 0;
}

 

设置Openwrt为二级路由

手头的WR703n只有一个网口。刷过Openwrt之后通过修改配置来连接上级路由的简单方法。网口为WAN口,LAN只能通过wifi连接。

/etc/config/network:


config interface 'loopback'
	option ifname 'lo'
	option proto 'static'
	option ipaddr '127.0.0.1'
	option netmask '255.0.0.0'

config interface 'wan'
	option ifname 'eth0'
	option proto 'dhcp'

config interface 'lan'
	option type 'bridge'
	option proto 'static'
	option ipaddr '10.76.1.1'
	option netmask '255.255.255.0'


 

ar71xx可用Openwrt软件源

  • Openwrt官方:

http://downloads.openwrt.org/snapshots/trunk/ar71xx/packages/packages/

  • Openwrt中文:

http://downloads.openwrt.org.cn/backfire/10.03.1/ar71xx/packages/

  • 爱好者自建:

http://openwrt.herokuapp.com/snapshots/trunk/ar71xx/packages

POJ1146:ID Codes——全排列问题

Description

It is 2084 and the year of Big Brother has finally arrived, albeit a century late. In order to exercise greater control over its citizens and thereby to counter a chronic breakdown in law and order, the Government decides on a radical measure–all citizens are to have a tiny microcomputer surgically implanted in their left wrists. This computer will contains all sorts of personal information as well as a transmitter which will allow people’s movements to be logged and monitored by a central computer. (A desirable side effect of this process is that it will shorten the dole queue for plastic surgeons.)

An essential component of each computer will be a unique identification code, consisting of up to 50 characters drawn from the 26 lower case letters. The set of characters for any given code is chosen somewhat haphazardly. The complicated way in which the code is imprinted into the chip makes it much easier for the manufacturer to produce codes which are rearrangements of other codes than to produce new codes with a different selection of letters. Thus, once a set of letters has been chosen all possible codes derivable from it are used before changing the set.

For example, suppose it is decided that a code will contain exactly 3 occurrences of `a’, 2 of `b’ and 1 of `c’, then three of the allowable 60 codes under these conditions are:
abaabc

abaacb

ababac

These three codes are listed from top to bottom in alphabetic order. Among all codes generated with this set of characters, these codes appear consecutively in this order.

Write a program to assist in the issuing of these identification codes. Your program will accept a sequence of no more than 50 lower case letters (which may contain repeated characters) and print the successor code if one exists or the message `No Successor’ if the given code is the last in the sequence for that set of characters.
Input

Input will consist of a series of lines each containing a string representing a code. The entire file will be terminated by a line consisting of a single #.
Output

Output will consist of one line for each code read containing the successor code or the words ‘No Successor’.
Sample Input

abaacb
cbbaa
#
Sample Output

ababac
No Successor


 

C++中STL的next_permutation类问题,查找排序中的下一序列。

简单AC代码:

#include
#include
using namespace std;
int main()
{
	int lenth;
	char s[51];
	while (scanf("%s", s) != EOF)
	{
		if (s[0] == '#')
			break;
		lenth = strlen(s);
		if (next_permutation(s, s + lenth))
			printf("%sn", s);
		else
			printf("No Successorn");
	}
	return 0;
}

 

嘘,老大哥在盯着你…………

CentOS安装dnsmasq简明教程

自搭了一个DNS服务,写写步骤备忘。

  • 安装

yum install dnsmasq

  • 配置

编辑 /etc/dnsmasq.conf

添加

port=5151//使用默认53端口会被GFW拦截
no-hosts//不使用本机host
log-queries//生成日志文件
log-facility=/var/log/dnsmasq.log

  • DNS服务

vi /etc/dnsmasq.d/resolv.dnsmasq.conf

添加

nameserver 8.8.8.8

  • 开机启动||运行

chkconfig dnsmasq on

/etc/init.d/dnsmasq restart

  • 开防火墙

vi /etc/sysconfig/iptables

添加

-A INPUT -p udp -m state –state NEW –dport 53 -j ACCEPT
-A INPUT -p tcp -m state –state NEW –dport 53 -j ACCEPT

 

完毕,服务启动~

[root@master ~]# netstat -tunlp|grep 5151

分享那些好用的WP插件Vol.2

上集回顾:分享那些好用的WP插件

复习累了,水一篇文章。分享一点在用的插件。

 


百度官方推出的一款提交网页的插件,可以加快百度收录。

禁用谷歌字体。因为WP默认使用Google Fonts,由于某些原因……禁用谷歌字体后可以加快大陆访问网站的速度。

大侠SEO。可以设置META信息,自动锚文本,以及相似文章推荐等功能,还可以自动生成网站地图。

根据页面显示不同的小工具。比如只在文章页添加音乐或者只在首页添加友链等等,详细介绍可以看这里

代码高亮插件。因为兼容问题停用了Developer Formatter这款插件。不过这款插件貌似存在在非IE核心下显示问题。

自动翻译文章别名。在发布文章的时候可以自动将文章的别名翻译成英文(效果如链接示)。因为网站之前用的都是中文别名所以怕全部翻译后会出现大量死链,被搜索引擎K掉。所以就保留了以前的中文别名,现在发布的文章用英文别名的形式。

为WP生成伪静态页面。加快WP的访问速度,堪称神器。

  • 随机名言

随机显示一条名言。根据random quotes稍加修改用到网站上,效果还不错:-)

 

HDOJ1008:Elevator——简单数学题

Problem Description
The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and 4 seconds to move down one floor. The elevator will stay for 5 seconds at each stop.

For a given request list, you are to compute the total time spent to fulfill the requests on the list. The elevator is on the 0th floor at the beginning and does not have to return to the ground floor when the requests are fulfilled.

Input
There are multiple test cases. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100. A test case with N = 0 denotes the end of input. This test case is not to be processed.

Output
Print the total time on a single line for each test case.

Sample Input
1 2
3 2 3 1
0

Sample Output
17
41

Author
ZHENG, Jianqiang

别人问的一道题目,没什么好说的。要注意即便是相同楼层也要停5s才行。

样例:

3 1 1 1

输出:

21

 
代码:

#include
int main()
{
	int n;
	while (~scanf("%d", &n)&&n!=0)
	{
		int f, fi,j, sum;
		f = sum = 0;
		for (j = 0; j f)
			{
				sum += 4 * (fi - f);
			}
			//if (j!=n-1)注意最后也要停五秒
				sum += 5;
		}
		printf("%dn", sum);
	}
	return 0;
}

临近期末,心浮气躁。来点水题降降火~

POJ3617:Best Cow Line——字典序最小问题

Description

FJ is about to take his N (1 ≤ N ≤ 2,000) cows to the annual”Farmer of the Year” competition. In this contest every farmer arranges his cows in a line and herds them past the judges.

The contest organizers adopted a new registration scheme this year: simply register the initial letter of every cow in the order they will appear (i.e., If FJ takes Bessie, Sylvia, and Dora in that order he just registers BSD). After the registration phase ends, every group is judged in increasing lexicographic order according to the string of the initials of the cows’ names.

FJ is very busy this year and has to hurry back to his farm, so he wants to be judged as early as possible. He decides to rearrange his cows, who have already lined up, before registering them.

FJ marks a location for a new line of the competing cows. He then proceeds to marshal the cows from the old line to the new one by repeatedly sending either the first or last cow in the (remainder of the) original line to the end of the new line. When he’s finished, FJ takes his cows for registration in this new order.

Given the initial order of his cows, determine the least lexicographic string of initials he can make this way.

Input

* Line 1: A single integer: N
* Lines 2..N+1: Line i+1 contains a single initial (‘A’..’Z’) of the cow in the ith position in the original line

Output

The least lexicographic string he can make. Every line (except perhaps the last one) contains the initials of 80 cows (‘A’..’Z’) in the new line.

Sample Input

6
A
C
D
B
C
B
Sample Output

ABCBCD


题目大意是给定一个长度为N的字符串S,要求构造一个字符串T。T的默认状态为空。然后随机将S的头部(或尾部)删除一个字符,加到T的尾部。

要求构造一个字典序尽可能小的字符串T。

思路:

  1. 按照字典序比较S和反转后的字符串S’
  2. 如果S较小,就从S开头取出字符,放到T的末尾
  3. 如果S’较小,就从S末位取出字符,放到T的末尾
  4. 如果相同,则比较(S+1)和(S’-1)两字符的大小;相同则继续。

字典序+贪心问题。

出现PE问题:每行最多80个字符

 

#include
#include
#include
int N,i;
const int MAX_N = 2000;
char S[MAX_N + 1];

int main()
{
	while (~scanf("%d", &N))
	{
		for (i = 0; i < N; i++)
		{
			getchar();
			scanf("%c", &S[i]);
		}
		int a = 0, b = N - 1, cnt;
		cnt = 0;
		while (a <= b)
		{
			bool left = false;//比较左侧和右侧的字符串
			for (int i = 0; a + i <= b; i++)
			{
				if (S[a + i] < S[b - i])
				{
					left = true;
					break;
				}
				else if (S[a + i]>S[b - i])
				{
					left = false;
					break;
				}
			}
			if (left)putchar(S[a++]);
			else putchar(S[b--]);
			cnt++;
			if (cnt % 80 == 0)
				putchar('n');
		}
	}
	return 0;
}

 

我想谈说种种纯洁的事情——何其芳

 

我想谈说种种纯洁的事情,

我想起了我最早的朋友,最早的爱情。

地上有花。天上有星星。

人——有着心灵。

我知道没有什么东西能够永远坚固,

在自然的运行中一切消逝如朝露。

但那些发过光的东西是如此可珍,

而且在它们自己的光辉里获得了永恒。

我曾经和我最早的朋友一起坐在草地上读着书籍,

一起在星空下走着,谈着我们的未来。

对于贫穷的孩子它们是那样富足。

我又曾沉默地爱着一个女孩子,

我是那样喜欢为她做着许多小事情。

没有回答,甚至于没有觉察,

我的爱情已经和十五晚上的月亮一样圆满。

呵,时间的灰尘遮盖了我的心灵,

我太久太久没有想起过他们!

我最早的朋友早已睡在坟墓里了。

我最早的爱人早已作了母亲。

我也再不是一个少年人。

但自然并不因我停止它的运行,

世界上仍然到处有着青春,

到处有着刚开放的心灵。

年轻的同志们,我们一起到野外去吧,

在那柔和的蓝色的天空之下,

我想对你们谈说种种纯洁的事情。

三月十五日


 

题图:Tre Fontane At Night

作者:Dirklaudio Fasetti

送不到的『明天』——纪念已成历史的雅虎邮箱

今天是2014年最后一天。

刚刚看到消息:从明天起。阿里云不再代收雅虎中国的邮件。也就是说,从明天起,@yahoo.com.cn邮箱将『失联』:将收不到任何邮件了:-(

记得雅虎邮箱是我申请的第二个邮箱,因为之前的zsfx24gx@sohu.com(已停用)这个邮箱容量太小了(区区10MB),而雅虎邮箱可以提供1GB容量,所以就义无反顾的投身了雅虎的怀抱。哪知雅虎一直没有发展好中国市场。慢慢的,Gmail变成了我的主力邮箱。再后来,就被阿里并购了……

记得在08年左右的时候,雅虎邮箱宣称自己可以做用户的『终生邮箱』。大体是说自家的服务可靠,容量够大,公司有保障云云。让用户把雅虎邮箱作为一个『值得托付终身』的邮箱。我搜了一下,相关链接

从当年提出口号到现在,不过区区六年时间。不得不让人唏嘘……

而且雅虎邮箱泄露用户隐私的问题又为用户所不齿。

而且13年雅虎中国邮箱关闭后,因为要更换各网站ID注册邮箱的问题也把我折腾的筋疲力尽。更有如X雷公司甚者,居然不能更改注册邮箱!

尽管现在已经对雅虎邮箱不抱有任何好感了。

但无论怎样,

忘不掉『zbctgaoxu@yahoo.com.cn』这串长长的电邮地址

或许,这就是记忆?