博文
Another Eight Puzzle(2008-10-08 21:39:00)
摘要:Another Eight Puzzle
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 12 Accepted Submission(s) : 4
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Fill the following 8 circles with digits 1~8,with each number exactly once . Conntcted circles cannot be filled with two consecutive numbers.There are 17 pairs of connected cicles:A-B , A-C, A-DB-C, B-E, B-FC-D, C-E, C-F, C-GD-F, D-GE-F, E-HF-G, F-HG-H
Filling G with 1 and D with 2 (or G with 2 and D with 1) is illegal since G and D are connected and 1 and 2 are consecutive .However ,filling A with 8 and B with 1 is legal since 8 and 1 are not consecutive .In this problems,some circles are already filled,your tast is to fill the remaining circles to obtain a solution (if possivle).
Input
The first line contains a single integer T(1≤T≤10),the number of test cases. Each test case is a single line containing 8 integers 0......
decimal system(2008-10-07 15:14:00)
摘要:decimal system
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 28 Accepted Submission(s) : 13
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
As we know , we always use the decimal system in our common life, even using the computer. If we want to calculate the value that 3 plus 9, we just import 3 and 9.after calculation of computer, we will get the result of 12.But after learning <<The Principle Of Computer>>,we know that the computer will do the calculation as the following steps:1 computer change the 3 into binary formality like 11;2 computer change the 9 into binary formality like 1001;3 computer plus the two number and get the result 1100;4 computer change the result into decimal formality like 12;5 computer export the result;In the computer system there are other formalities to deal with the number such as hexadecimal. Now I will give several numb......
Public Sale(2008-10-07 15:10:00)
摘要:Public Sale
Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 19 Accepted Submission(s) : 5
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
虽然不想,但是现实总归是现实,Lele始终没有逃过退学的命运,因为他没有拿到奖学金。现在等待他的,就是像FarmJohn一样的农田生涯。要种田得有田才行,Lele听说街上正在举行一场别开生面的拍卖会,拍卖的物品正好就是一块20亩的田地。于是,Lele带上他的全部积蓄,冲往拍卖会。后来发现,整个拍卖会只有Lele和他的死对头Yueyue。通过打听,Lele知道这场拍卖的规则是这样的:刚开始底价为0,两个人轮流开始加价,不过每次加价的幅度要在1~N之间,当价格大于或等于田地的成本价 M 时,主办方就把这块田地卖给这次叫价的人。Lele和Yueyue虽然考试不行,但是对拍卖却十分精通,而且他们两个人都十分想得到这块田地。所以他们每次都是选对自己最有利的方式进行加价。由于Lele字典序比Yueyue靠前,所以每次都是由Lele先开始加价,请问,第一次加价的时候,Lele要出多少才能保证自己买得到这块地呢?
Input
本题目包含多组测试,请处理到文件结束(EOF)。每组测试占一行。每组测试包含两个整数M和N(含义见题目描述,0<N,M<1100)
Output
对于每组数据,在一行里按递增的顺序输出Lele第一次可以加的价。两个数据之间用空格隔开。如果Lele在第一次无论如何出价都无法买到这块土地,就输出"none"。
Sample Input
4 2
3 2
3 5
Sample Output
1
none
3 4 5
Author
Linle
Source
ACM程序设计期末考试——2008-01-02(3 教417)
算是比较简单的博议了!
办法比较死!倒着推的!
......
Worm(2008-10-07 15:06:00)
摘要:Worm
Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 17 Accepted Submission(s) : 5
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
自从见识了平安夜苹果的涨价后,Lele就在他家门口水平种了一排苹果树,共有N棵。突然Lele发现在左起第P棵树上(从1开始计数)有一条毛毛虫。为了看到毛毛虫变蝴蝶的过程,Lele在苹果树旁观察了很久。虽然没有看到蝴蝶,但Lele发现了一个规律:每过1分钟,毛毛虫会随机从一棵树爬到相邻的一棵树上。比如刚开始毛毛虫在第2棵树上,过1分钟后,毛毛虫可能会在第1棵树上或者第3棵树上。如果刚开始时毛毛虫在第1棵树上,过1分钟以后,毛毛虫一定会在第2棵树上。现在告诉你苹果树的数目N,以及毛毛刚开始所在的位置P,请问,在M分钟后,毛毛虫到达第T棵树,一共有多少种行走方案数。
Input
本题目包含多组测试,请处理到文件结束(EOF)。每组测试占一行,包括四个正整数N,P,M,T(含义见题目描述,0<N,P,M,T<100)
Output
对于每组数据,在一行里输出一共的方案数。题目数据保证答案小于10^9
Sample Input
3 2 4 2
3 2 3 2
Sample Output
4
0
[Hint]
第一组测试中有以下四种走法:
2->1->2->1->2
2->1->2->3->2
2->3->2->1->2
2->3->2->3->2[/Hint]
Author
Linle
Source
ACM程序设计期末考试——2008-01-02(3 教417)
#include<stdio.h>__int64 a[110][100];int main(){ int n,......
Marching Ants(2008-10-06 13:17:00)
摘要:
Marching Ants
Time Limit: 5000ms, Special Time Limit:12500ms, Memory Limit:65536KB
Total submit users: 8, Accepted users: 8
Problem 11301 : No special judgement
Problem description
Ants! Aren’t they fascinating? Thousands of these insects are marching their paths on and on. They can build highly organized ant-hills. Sometimes, however, they act a little bit stupidly.Imagine that you have a long piece of wood and a couple of ants is walking on top of it. Their behavioral pattern is very simple: each ant walks slowly forward with a constant speed of 1 cm per second. Whenever it meets another ant, both of them only touch with their antennae and immediately turn around and walk the opposite direction. If an ant comes to the end of the wood, it falls down and does not affect other ants anymore.
The picture above shows an example of moving ants in time 0 s. In one second, the ants E and A meet at position 2 and change their directions. The ant A then meets B in......
Software Bugs(2008-10-05 20:36:00)
摘要:
Software Bugs
Time Limit: 5000ms, Special Time Limit:12500ms, Memory Limit:65536KB
Total submit users: 12, Accepted users: 9
Problem 11302 : No special judgement
Problem description
The biggest problem for all software developers are bugs. You definitely know the situation when a user calls to say ”I’ve found a bug in your program”. Once you have found and removed the bug, another one appears immediately. It is a hard and never-ending process.Recently, there appeared a promising open-source initiative called “bug-preprocessor”. The bugpreprocessor is a program able to find all bugs in your source code and mark them, so they are relatively easy to be removed. Your task is to write a program that will remove all marked bugs from the preprocessed source code.
Input
The input contains a text representing the preprocessed source code, an unspecified number of lines of text, some of them may be empty. Bugs are represented by a case-sensitive string “BUG”.T......
Emoticons :-)(2008-10-04 21:16:00)
摘要:Emoticons :-)Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 30 Accepted Submission(s): 6
Problem Description
Emoticons are used in chat and e-mail conversations to try to express the emotions that printed words cannot. This may seem like a nice feature for many, but a lot of people find it really annoying and wants to get rid of emoticons.George is one of those people. He hates emoticons so bad, that he is preparing a plan to remove all emoticons from all e-mails in the world. Since you share his visionary plans, you are preparing a special program to help him.Your program will receive the list of emoticons to proscribe. Each emoticon will be a string of characters not including any whitespace. You will also receive several lines of text. What you need to do is change some characters of the text into spaces to ensure no emoticon is left on the text. For an emoticon to be considered to ......
不可摸数(2008-10-04 21:13:00)
摘要:
不可摸数Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 654 Accepted Submission(s): 181
Problem Description
s(n)是正整数n的真因子之和,即小于n且整除n的因子和.例如s(12)=1+2+3+4+6=16.如果任何数m,s(m)都不等于n,则称n为不可摸数.
Input
包含多组数据,首先输入T,表示有T组数据.每组数据1行给出n(2<=n<=1000)是整数。
Output
如果n是不可摸数,输出yes,否则输出no
Sample Input
3
2
5
8
Sample Output
yes
yes
no
Author
Zhousc@ECJTU
Source
华东交通大学2008(春季)ACM程序设计竞赛
Recommend
lcy
想不出好方法!死算!
不过肯定超时!
先用电脑算出来!
直接拷贝到A数组!
后来查表就不会超了!哈哈
include<stdio.h>#include<iostream>#include<math.h>using namespace std;int a[1001]={2,0,0,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,1......
extern "C"(2008-10-01 17:08:00)
摘要:extern "C"的使用
2008-09-15 11:45
时常在cpp的代码之中看到这样的代码:
#ifdef __cplusplu* **tern "C" { #endif
//一段代码
#ifdef __cplusplus } #endif
这样的代码到底是什么意思呢?首先,__cplusplus是cpp中的自定义宏,那么定义了这个宏的话表示这是一段cpp的代码,也就是说,上面的代码的含义是:如果这是一段cpp的代码,那么加入extern "C"{和}处理其中的代码。
要明白为何使用extern "C",还得从cpp中对函数的重载处理开始说起。在c++中,为了支持重载机制,在编译生成的汇编码中,要对函数的名字进行一些处理,加入比如函数的返 回类型等等.而在C中,只是简单的函数名字而已,不会加入其他的信息.也就是说:C++和C对产生的函数名字的处理是不一样的.
比如下面的一段简单的函数,我们看看加入和不加入extern "C"产生的汇编代码都有哪些变化:
int f(void) { return 1; }
在加入extern "C"的时候产生的汇编代码是:
.file "test.cxx" .text .align 2 .globl _f .def _f; .scl 2; .type 32; .endef _f: pushl %ebp movl %esp, %ebp movl $1, %eax popl %ebp ret
但是不加入了extern "C"之后
.file "test.cxx" .text .align 2 .globl __Z1fv .def __Z1fv; .scl 2; .type 32; .endef __Z1fv: pushl %ebp movl %esp, %ebp movl $1, %eax popl %ebp ret
两段汇编代码同样都是使用gcc -S命令产生的,所有的地方都是一样的,唯独是产生的函数名,一个是_f,一个是__Z1fv。
明白了加入与不加入extern "C"之后对函数名称产生的影响,我们继续我们的讨论:为什么需要使用......
inline(2008-10-01 16:35:00)
摘要:
一、inline 关键字用来定义一个类的内联函数,引入它的主要原因是用它替代C中表达式形式的宏定义。
表达式形式的宏定义一例:
#define ExpressionName(Var1,Var2) (Var1+Var2)*(Var1-Var2)
为什么要取代这种形式呢,且听我道来:
1. 首先谈一下在C中使用这种形式宏定义的原因,C语言是一个效率很高的语言,这种宏定义在形式及使用上像一个函数,但它使用预处理器实现,没有了参数压栈,代码生成 等一系列的操作,因此,效率很高,这是它在C中被使用的一个主要原因。
2. 这种宏定义在形式上类似于一个函数,但在使用它时,仅仅只是做预处理器符号表中的简单替换,因此它不能进行参数有效性的检测,也就不能享受C++编译器严格类型检查的好处,另外它的返回值也不能被强制转换为可转换的合适的类型,这样,它的使用就存在着一系列的隐患和局限性。
3. 在C++中引入了类及类的访问控制,这样,如果一个操作或者说一个表达式涉及到类的保护成员或私有成员,你就不可能使用这种宏定义来实现(因为无法将this指针放在合适的位置)。
4. inline 推出的目的,也正是为了取代这种表达式形式的宏定义,它消除了它的缺点,同时又很好地继承了它的优点。
为什么inline能很好地取代表达式形式的预定义呢?
对应于上面的1-3点,阐述如下:
1. inline 定义的类的内联函数,函数的代码被放入符号表中,在使用时直接进行替换,(像宏一样展开),没有了调用的开销,效率也很高。
2. 很明显,类的内联函数也是一个真正的函数,编译器在调用一个内联函数时,会首先检查它的参数的类型,保证调用正确。然后进行一系列的相关检查,就像对待任何一个真正的函数一样。这样就消除了它的隐患和局限性。
3. inline 可以作为某个类的成员函数,当然就可以在其中使用所在类的保护成员及私有成员。
在何时使用inline函数:
首先,你可以使用inline函数完全取代表达式形式的宏定义。
另外要注意,内联函数一般只会用在函数内容非常简单的时候,这是因为,内联函数的代码会在任何调用它的地方展开,如果函数太复杂,代码膨胀带来的恶果很可能会大于效率的提高带来的益处。内联函数最......
