D的小L
4000 ms | 内存限制: 65535
2
一天TC的匡匡找ACM的小L玩三国杀,但是这会小L忙着哩,不想和匡匡玩但又怕匡匡生气,这时小L给匡匡出了个题目想难倒匡匡(小L很D吧
),有一个数n(0<n<10),写出1到n的全排列,这时匡匡有点囧了
,,,聪明的你能帮匡匡解围吗?
第一行输入一个数N(0<N<10),表示有N组测试数据。后面的N行输入多组输入数据,每组输入数据都是一个整数x(0<x<10)
按特定顺序输出所有组合。
特定顺序:每一个组合中的值从小到大排列,组合之间按字典序排列。
2 2 3
12 21 123 132 213 231 312 321
代码:
Same binary weight
300 ms | 内存限制: 65535
3
The binary weight of a positive integer is the number of 1's in its binary representation.for example,the decmial number 1 has a binary weight of 1,and the decimal number 1717 (which is 11010110101 in binary) has a binary weight of 7.Give a positive integer N,return the smallest integer greater than N that has the same binary weight as N.N will be between 1 and 1000000000,inclusive,the result is guaranteed to fit in a signed 32-bit interget.
The input has multicases and each case contains a integer N.
For each case,output the smallest integer greater than N that has the same binary weight as N.
1717 4 7 12 555555
代码:
求次数
1000 ms | 内存限制: 65535
2
题意很简单,给一个数n 以及一个字符串str,区间【i,i+n-1】 为一个新的字符串,i 属于【0,strlen(str)】如果新的字符串出现过ans++,例如:acmacm n=3,那么 子串为acm cma mac acm ,只有acm出现过
求ans;
LINE 1: T组数据(T<10)
LINE 2: n ,n <= 10,且小于strlen(str);
LINE 3:str
str 仅包含英文小写字母 ,切长度小于10w
求 ans
2 2 aaaaaaa 3 acmacm
5 1
代码:
Registration system
1000 ms | 内存限制: 65535
2
A new e-mail service "Berlandesk" is going to be opened in Berland in the near future.
The site administration wants to launch their project as soon as possible, that's why they
ask you to help. You're suggested to implement the prototype of site registration system.
he system should work on the following principle.
Each time a new user wants to register, he sends to the system a request with his name.
If such a name does not exist in the system database, it is inserted into the database, and
the user gets the response OK, confirming the successful registration. If the name already
exists in the system database, the system makes up a new user name, sends it to the user
as a prompt and also inserts the prompt into the database. The new name is formed by the
following rule. Numbers, starting with 1, are appended one after another to name (name1,
name2, ...), among these numbers the least i is found so that namei does not yet exist in
the database.
The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 1000 characters, which are all lowercase Latin letters.
Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken.
4 abacaba acaba abacaba acab
OK OK abacaba1 OK
代码:
汉诺塔(三)
3000 ms | 内存限制: 65535
3
在印度,有这么一个古老的传说:在世界中心贝拿勒斯(在印度北部)的圣庙里,一块黄铜板上插着三根宝石针。印度教的主神梵天在创造世界的时候,在其中一根针上从下到上地穿好了由大到小的64片金片,这就是所谓的汉诺塔。不论白天黑夜,总有一个僧侣在按照下面的法则移动这些金片:一次只移动一片,不管在哪根针上,小片必须在大片上面。僧侣们预言,当所有的金片都从梵天穿好的那根针上移到另外一根针上时,世界就将在一声霹雳中消灭,而梵塔、庙宇和众生也都将同归于尽。
现在我们把三根针编号为1,2,3。
所有的金片在初始时都在1号针上,现在给你的任务是判断一系列的指令过程中,是否会出现非法的指令。
而非法指令有以下两种情况:
1、某个针上已经没有金片了,但是指令依然要求从该处移动金片到其它针上。
2、把一个大的金片移动到了小的金片上。
第一行输入一个整数N表示测试数据的组数(N<10)
每组测试数据的第一行有两个整数P,Q(1<P<64,1<Q<100),分别表示汉诺塔的层数与随后指令的条数
随后的Q行,每行都输入两个整数a,b,(1<=a,b<=3)表示一条指令。
指令1 2表示把1号针最上面的金片移动到2号针最上面。
数据保证a,b不会相同。
如果存在非法指令,请输出illegal
不存在非法指令则输出legal
3 2 1 1 2 3 3 1 2 1 3 3 2 2 1 2 1
legal illegal illegal
代码: