博文
约瑟夫环问题单循环链表解法(2006-06-16 21:16:00)
摘要:约瑟夫环问题
Time Limit:1000MS Memory Limit:65536KTotal Submit:50 Accepted:8
Description
约瑟夫环问题;有N个人围成一个环,从第一个人开始报数,报到M的人退出环,并且由他的M值来代替原有的M值,要求输出离开环的顺序。
Input
第一行有2个数,M和N。(0<N<=1000) 第二行有N个数,表示每个人的M值。
Output
按照样例的格式,输出所有人退出环的顺序。
Sample Input
4 6
5 4 2 3 4 2
Sample Output
4,1,2,3,6,5
Source
#include"iostream"
#include"cstdio"
#include"cstdlib"
using namespace std;
typedef struct cnode{
int label;
int data;
struct cnode *next;
}cnode;
int m,n,i,value,j;
cnode *p,*q;
int main()
{
cin>>m>>n;
cnode *clist;
q=(cnode *)malloc(sizeof(cnode));
clist=q;
for(i=1;i<=n;i++)
{
//cin>>value;
cin>>value;
p=(cnode *)malloc(sizeof(cnode));
//p=new cnode;
p->label=i;
p->data=value;
p->next=NULL;
q->next=p;
q=p;
if(i==n)q->next=clist->next;
}
p=clist;
......
1009(2006-06-10 15:43:00)
摘要:Rails
Time Limit:1000MS Memory Limit:65536KTotal Submit:52 Accepted:23
Description
There is a famous railway station in PopPush City. Country there is incredibly hilly. The station was built in last century. Unfortunately, funds were extremely limited that time. It was possible to establish only a surface track. Moreover, it turned out that the station could be only a dead-end one (see picture) and due to lack of available space it could have only one track.
The local tradition is that every train arriving from the direction A continues in the direction B with coaches reorganized in some way. Assume that the train arriving from the direction A has N <= 1000 coaches numbered in increasing order 1, 2, ..., N. The chief for train reorganizations must know whether it is possible to marshal coaches continuing in the direction B so that their order will be a1, a2, ..., aN. Help him and write a program that decides whether it is possible to get the required order of coaches. Y......
1051(2006-06-09 19:12:00)
摘要:More Flowers,More Love
Time Limit:1000MS Memory Limit:65536KTotal Submit:30 Accepted:13
Description
Valentine's Day is coming,while girls are preparing chocolate for their boys, we boys is also in preparation of choosing presents for the sweet to love carefully. Tom is Tom,Tom does not know too much about how to flattering the girl in his heart, so he just decides to buy flowes for his girl as what the knights in middle ages have already done. However thought he could do more than buying flowers, he wants to use out all the money in his pockets on flowers,because he loves his girl too much. There are three kinds of flowers in the florist: Rose, Carnation and Rosebush. Tom wants to know if he could use out of his money. Please tell him, our genius programmer.
Input
The input file contains multiple lines, and each line contains four numbers in sequence, the total money that Tom has, the price of Rose, the price of Carnation and of Rosebush.
Output
For each test case outp......
1023(2006-06-09 18:49:00)
摘要:Who's in the Middle
Time Limit:1000MS Memory Limit:65536KTotal Submit:14 Accepted:9
Description
FJ is surveying his herd to find the most average cow. He wants to know how much milk this 'median' cow gives: half of the cows give as much or more than the median; half give as much or less. Given an odd number of cows N (1 <= N < 10,000) and their milk output (1..1,000,000), find the median amount of milk given such that at least half the cows give the same amount of milk or more and at least half give the same or less.
Input
* Line 1: A single integer N * Lines 2..N+1: Each line contains a single integer that is the milk output of one cow.
Output
* Line 1: A single integer that is the median milk output.
Sample Input
5
2
4
1
3
5
Sample Output
3
Hint
INPUT DETAILS: Five cows with milk outputs of 1..5 OUTPUT DETAILS: 1 and 2 are below 3; 4 and 5 are above 3.
Source
#include"iostream"
#include"vector"
using namespace std;
vect......
1014(2006-06-09 16:28:00)
摘要:变形课
Time Limit:1000MS Memory Limit:65536KTotal Submit:44 Accepted:11
Description
呃......变形课上Harry碰到了一点小麻烦,因为他并不像Hermione那样能够记住所有的咒语而随意的将一个棒球变成刺猬什么的,但是他发现了变形咒语的一个统一规律:如果咒语是以字母a开头和以字母b结尾的一个单词,那么它的作用就恰好是使A物体变成B物体。譬如,一个咒语bright可以把一个B物体变成T。 Harry已经将他所会的所有咒语都列成了一个表,他想让你帮忙计算一下他是否能完成老师的作业,将一个B(ball)变成一个M(Mouse),你知道,如果他自己不能完成的话,他就只好向Hermione请教,并且被迫听一大堆好好学习的道理.
Input
每行一个单词,仅包括小写字母,是Harry所会的所有咒语.
Output
如果Harry可以完成他的作业,就输出"Yes.",否则就输出"No."(不要忽略了句号)
Sample Input
so
soon
river
goes
them
got
moon
begin
big
Sample Output
Yes.
Hint
Harry 可以念这个咒语:"big-got-them".
Source
#include"iostream"
#include"string"
#include"stack"
#include"vector"
using namespace std;
stack<string>sta;
vector<string>str;
int found=0;
bool chan()
{
int i,j;
for(i=0;i<str.size();)
{
if(str[i][0]=='b')
{
sta.push(str[i]);
str.erase(str.begin()+i);
if(sta.top()[sta.top().size()-1]=='m')return......
1017(2006-06-09 14:52:00)
摘要:杨辉三角
Time Limit:1000MS Memory Limit:65536KTotal Submit:61 Accepted:16
Description
打印杨辉三角
Input
每行一个数N(0<N<=20),最后一个数0
Output
对每个输入的N,输出N+1行的杨辉三角形.输出格式参考下面的Sample Output. 没有多余的空行和空格.
Sample Input
1
3
0
Sample Output
Case 1:
1
1 1
Case 2:
1
1 1
1 2 1
1 3 3 1
Hint
数据结构老师说要用队列做..
Source
#include"iostream"
#include"vector"
using namespace std;
vector<int>rect[21];
void v(int n)
{
int i,j;
for(i=0;i<=n;i++)
{
for(j=0;j<rect[i].size();j++)
cout<<rect[i][j]<<" ";
cout<<endl;
}
}
void init()
{
int i,j;
for(i=0;i<=20;i++)
{
rect[i].push_back(1);
if(i>=2)
for(j=1;j<i;j++)
rect[i].push_back(rect[i-1][j-1]+rect[i-1][j]);
if(i>=1)
rect[i].push_back(1);
}
}
int main()
{
int i=0,j=0;
int a[100];
cin>>a[0]......
1031(2006-06-08 17:20:00)
摘要:删除重复元素
Time Limit:1000MS Memory Limit:65536KTotal Submit:18 Accepted:11
Description
对于一个已排序的数组,用一个算法来删除里面重复的元素。
Input
一个已排序的数组。最多不超过10000个元素。
Output
将数组删除重复元素后得到的数组
Sample Input
1 1 2 2 3 4 5 5 6 6 6 7 8 8 8 9 9 9 10
Sample Output
1 2 3 4 5 6 7 8 9 10 Source #include"iostream"
#include"vector"
using namespace std;
vector<long>order;
int main()
{
long i,j;
while(cin>>i)
order.push_back(i);
for(j=0;j<order.size()-1;)
if(order[j]==order[j+1])
{
order.erase(order.begin()+j);
}
else j++;
for(j=0;j<order.size();j++)
cout<<order[j]<<" ";
return 1;
}
......
那叫竞赛吗?(2006-06-02 13:08:00)
摘要:昨晚,学校举办了个 程序设计大赛。
参赛的人不少,还算热闹,据说题目由几个ICPC队员(也就是学长了!)设计的。
第一题出奇的简单,但不能用递归,我居然傻傻的提交了六次,真是傻到极致,最终导致
排名的靠后~~~~~
第二题有点难度,貌似全场就一个人做对,感觉本人的算法还行,也出了结果,可就提交
不成功,反正以不懂规则。。。不然 MP3啊!HOHO!~~~~~~````
第三~~五,呵呵,没人做出.
回头想想,有点不像是竞赛。。。
我还拿个三等奖~
AC率也太低了吧~......
