上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 14 下一页
摘要: 任意一个5位数,比如:34256,把它的各位数字打乱,重新排列,可以得到一个最大的数:65432,一个最小的数23456。求这两个数字的差,得:41976,把这个数字再次重复上述过程(如果不足5位,则前边补0)。如此往复,数字会落入某个循环圈(称为数字黑洞)。比如,刚才的数字会落入:[82962, 75933, 63954, 61974] 这个循环圈。请编写程序,找到5位数所有可能的循环圈,并输出,每个循环圈占1行。其中5位数全都相同则循环圈为 [0],这个可以不考虑。循环圈的输出格式仿照:[82962, 75933, 63954, 61974] 1 #include<string.h& 阅读全文
posted @ 2013-05-19 16:39 萧凡客 阅读(247) 评论(0) 推荐(0) 编辑
摘要: 1 #include <stdio.h> 2 #define n 4 3 typedef struct 4 { 5 int parent; 6 int lchild,rchild; 7 int weight; 8 int flag; 9 }Node;10 11 typedef struct 12 {13 char bit[n];14 int start;15 char ch;16 }CodeNode;17 18 Node haffman[7];19 CodeNode code[n];20 21 int select(int j)22... 阅读全文
posted @ 2013-05-01 22:48 萧凡客 阅读(238) 评论(0) 推荐(0) 编辑
摘要: 会场安排问题时间限制:3000ms | 内存限制:65535KB难度:4描述学校的小礼堂每天都会有许多活动,有时间这些活动的计划时间会发生冲突,需要选择出一些活动进行举办。小刘的工作就是安排学校小礼堂的活动,每个时间最多安排一个活动。现在小刘有一些活动计划的时间表,他想尽可能的安排更多的活动,请问他该如何安排。输入第一行是一个整型数m(m<100)表示共有m组测试数据。每组测试数据的第一行是一个整数n(1<n<10000)表示该测试数据共有n个活动。随后的n行,每行有两个正整数Bi,Ei(0<=Bi,Ei<10000),分别表示第i个活动的起始与结束时间(Bi&l 阅读全文
posted @ 2013-05-01 22:45 萧凡客 阅读(427) 评论(0) 推荐(0) 编辑
摘要: 1 #include<stdio.h> 2 3 int a[10000]; 4 int n,m; 5 6 int is_part(int u) 7 { 8 int sum,i,count,ok; 9 sum=count=0;ok=1;10 for(i=0;i<n;i++)11 {12 if(a[i]>u)13 {14 ok=0;15 break;16 }17 if(sum+a[i]>u) 18 { 19 s... 阅读全文
posted @ 2013-05-01 22:35 萧凡客 阅读(465) 评论(0) 推荐(0) 编辑
摘要: 1 //2^n个运动员 2 #include<stdio.h> 3 int a[100][100]; 4 int n; 5 6 void fun(int n) 7 { 8 int u,v,j,i; 9 if(n==0) a[n][n]=1;10 else11 {12 fun(n-1);13 u=1<<(n-1);14 v=1<<n;15 for(i=0;i<u;i++)16 for(j=u;j<v;j++)17 a[i][j]=a[i][j... 阅读全文
posted @ 2013-04-30 09:53 萧凡客 阅读(222) 评论(0) 推荐(0) 编辑
摘要: 问题描述:n在我们现在使用的日历中, 闰年被定义为能被4整除的年份n但是能被100整除而不能被400整除的年是例外,它们不是闰年。例如:1700, 1800, 1900 和 2100 不是闰年,而 1600, 2000 和 2400是闰年。给定从公元2000年1月1日(周六)开始逝去的天数,你的任务是给出这一天是哪年哪月哪日星期几输入:n输入包含若干行,每行包含一个正整数,表示从2000年1月1日开始逝去的天数。输入最后一行是−1, 不必处理。可以假设结果的年份不会超过9999。输出:n对每个测试样例,输出一行,该行包含对应的日期和星期几。n格式为“YYYY-MM-DD DayOfWeek”, 阅读全文
posted @ 2013-04-26 18:07 萧凡客 阅读(1374) 评论(0) 推荐(0) 编辑
摘要: 1 #include<cstdio> 2 #include<cstring> 3 #include<cstdlib> 4 const int maxn = 6; 5 int table[maxn][maxn]; 6 int hash_col[maxn][maxn], hash_row[maxn][maxn], hash_gro[maxn][maxn]; 7 int gro_id[maxn][maxn]; 8 int cas = 0; 9 void next_pos(int& r, int& c)10 {11 if(5 == c)//这里写成了 阅读全文
posted @ 2013-04-25 11:04 萧凡客 阅读(380) 评论(6) 推荐(0) 编辑
摘要: 1 #include<stdio.h> 2 void move(char a,char b) 3 { 4 printf("%c->%c\n",a,b); 5 } 6 void han(int n,char a,char b,char c) 7 { 8 if(n>0) 9 {10 han(n-1,a,c,b);11 move(a,b);12 han(n-1,c,b,a);13 }14 }15 int main()16 {17 int n;18 scanf("%d",&n);19 printf... 阅读全文
posted @ 2013-04-25 10:13 萧凡客 阅读(161) 评论(0) 推荐(0) 编辑
摘要: 1 #include<stdio.h> 2 #include<string.h> 3 #include<set> 4 #include<time.h> 5 using namespace std; 6 7 typedef int state[9]; 8 const int max=1000000; 9 state st[max],goal;10 int dist[max];11 const int dx[]={-1,1,0,0};12 const int dy[]={0,0,-1,1};13 14 struct cmp15 {16 bool op 阅读全文
posted @ 2013-04-24 21:43 萧凡客 阅读(197) 评论(0) 推荐(0) 编辑
摘要: 拓扑排序一.概念 由某个集合上的一个偏序得到该集合上的一个全序,这个操作称之为拓扑排序。二.拓扑排序方法如下: (1)从有向图中选择一个没有前驱(即入度为0)的顶点并且输出它. (2)从网中删去该顶点,并且删去从该顶点发出的全部有向边. (3)重复上述两步,直到剩余的网中不再存在没有前趋的顶点为止.三.算法实现 1.普通实现 1 #include<iostream> 2 #include<stdlib.h> 3 #include<stdio.h> 4 #define MAX 100 5 using namespace std; 6 7 void toposo 阅读全文
posted @ 2013-04-23 20:54 萧凡客 阅读(150) 评论(0) 推荐(0) 编辑
上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 14 下一页