- 博客(28)
- 资源 (1)
- 收藏
- 关注
原创 POJ 1258 最小生成树
思路:求最小生成树无非是两种思路,用prim()算法或者克鲁斯算法。prim算法就是对一棵先拆成每个独立的点,随便找到一个点,然后比较与该点相连的所有点中权值最小的,然后把该权值加入到一个用来你保存最小生成树中的权值,然后把点加入到用来保存已选取点的数组,并对该顶点做一个标记,表示该顶点已经加入到数组中,再选取该顶点中与它相连顶点中权值最小的,以此类推。若是某个顶点与它所有相连的顶点都已经添加进去
2016-10-27 23:27:10 326
原创 POJ1521
DescriptionAn entropy encoder is a data encoding method that achieves lossless data compression by encoding a message with "wasted" or "extra" information removed. In other words, entropy encoding
2016-10-22 22:40:33 463
原创 POJ3253 求出花费最少的钱
DescriptionFarmer John wants to repair a small length of the fence around the pasture. He measures the fence and finds that he needs N (1 ≤ N ≤ 20,000) planks of wood, each having some integer len
2016-10-20 23:16:01 346
原创 POj1862 求一组数据中经过某个运算后的最小值
DescriptionOur chemical biologists have invented a new very useful form of life called stripies (in fact, they were first called in Russian - polosatiki, but the scientists had to invent an Englis
2016-10-20 21:08:17 333
原创 POj2255 利用先序,中序输出后序序列
DescriptionLittle Valentine liked playing with binary trees very much. Her favorite game was constructing randomly looking binary trees with capital letters in the nodes. This is an example of o
2016-10-18 23:47:06 348
原创 POJ1577 二叉树的创建及先序遍历(给定一些二叉树中的值,大于根的排在右边,小于根的排在左边)
Description Figure 1Figure 1 shows a graphical representation of a binary tree of letters. People familiar with binary trees can skip over the definitions of a binary tree of letters, leaves
2016-10-18 19:26:20 1119
原创 时钟类
#includeusing namespace std;class colck{public:void settime(int newh = 0,int newm = 0,int news=0);void showtime();private:int hour, minute, second;};void colck::settime(int new
2016-10-16 20:10:00 288
原创 POJ 2499 Binary Tree
DescriptionBackground Binary trees are a common data structure in computer science. In this problem we will look at an infinite binary tree where the nodes contain a pair of integers. The tree i
2016-10-15 16:30:10 391
原创 Given any integer 0 <= n <= 10000 not divisible by 2 or 5, some multiple of n is a number which in d
Given any integer 0 <= n <= 10000 not divisible by 2 or 5, some multiple of n is a number which in decimal notation is a sequence of 1's. How many digits are in the smallest such a multiple of n?
2016-10-13 00:43:51 2036 1
原创 输入一个8位二进制数,转换成十进制数输出
#includeusing namespace std;int power(int x, int y){int val=1;while (y--){val *= x;}return val;}int main(){int value = 0;for (int i = 7; i >= 0; i--){char ch;cin >>
2016-10-10 23:44:02 7155
翻译 POJ1028 利用栈求解的问题
DescriptionStandard web browsers contain features to move backward and forward among the pages recently visited. One way to implement these features is to use two stacks to keep track of the pages
2016-10-10 22:40:51 464
原创 编写一个求x的n次方的函数
直接求解#includeusing namespace std;int main(){int x,n;cin >> x>>n;int s=1;for (int i = 1; i {s = s*x;}cout system("pause");return 0;}-----------------------------------
2016-10-10 19:59:18 18088 2
原创 打印九九乘法表
#includeusing namespace std;int main(){int i, j;int s;for (i = 1; i {for (j = 1; j { s = i*j;cout }cout }system("pause");return 0;}
2016-10-10 17:37:23 415
原创 定义一个变量,赋予1~100的值,让用户猜值,比较大小,直到猜对位置
#includeusing namespace std;int main(){int i;int n;cin >> n;while (n){i = rand()%100;if(i == n){cout break;} else if(n>i){cout }else{cout }cin >> n;}
2016-10-10 17:11:02 1372
原创 声明时间的结构体,输入时间,然后完整的显示出来
#includeusing namespace std;typedef struct{int year;int month;int day;int hours;int min;int second;}Data;int main(){Data d;cin >> d.year>>d.month>>d.day>>d.hours>>d.mi
2016-10-10 16:53:29 1547
原创 读入一系列整数,统计出正整数个数及负整数个数,读入0就结束
#includeusing namespace std;int main(){int a=0;int i=0,j=0;cin>>a;while(a!=0){ if(a>0){i++;}else if(a{j++;}cin>>a;} coutsystem("pause");return 0;}
2016-10-09 22:25:29 7869
原创 求100~200之间不能被3整除的数
#includeusing namespace std;int main(){for(int i=100;i{if(i%3!=0){cout}}system("pause");return 0;}
2016-10-09 22:16:41 2391
原创 输入一个整数,求出它的所有因子
#includeusing namespace std;int main(){int n;cin >> n;while (n>=0){for (int i = 1; i {if (n%i == 0){cout }}coutcin >> n;}system("pause");return 0;}
2016-10-09 21:57:04 12816
原创 输入一个整数,将各位数字反转后输出
#include<iostream>using namespace std;int main(){int n;cin >> n;int s;if(n==0){return 0 ;}while (n){s = n % 10;cout << s ;n /= 10;}system("pause");return 0;}
2016-10-08 23:52:36 6148 3
原创 求自然数1~10的值
#includeusing namespace std;int main(){int n=10;int s = 0;//cin >> n;while (n>0){s += n;n--;}cout system("pause");return 0;}
2016-10-08 23:47:24 679
原创 输入一个0~6的整数,换成星期输出
#includeusing namespace std;int main(){int n;cin >> n;switch (n){case 0: cout case 1: cout case 2: cout case 3: cout case 4: cout case 5: cout case 6: cout defau
2016-10-08 23:43:24 5728
原创 比较两数的大小
#includeusing namespace std;int main(){int a, b;cin >> a >> b;while (a&&b){if (a > b){cout b"}else if (a {cout }else if (a =b){cout }cin >> a >> b;}system(
2016-10-08 23:32:57 373
原创 判断某年是否为闰年
#includeusing namespace std;int main(){int year;cin >> year;while (year>0){if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)){cout }else{cout }cin >> year;
2016-10-08 23:28:33 349
翻译 逆序数
样例:输入10 6AACATGAAGGTTTTGGCCAATTTGGCCAAAGATCAGATTTCCCGGGGGGAATCGATGCAT输出:CCCGGGGGGAAACATGAAGGGATCAGATTTATCGATGCATTTTTGGCCAATTTGGCCAAA#include #include #include
2016-10-08 22:49:23 333
转载 快速排序Sort调用
sort函数的用法做ACM题的时候,排序是一种经常要用到的操作。如果每次都自己写个冒泡之类的O(n^2)排序,不但程序容易超时,而且浪费宝贵的比赛时间,还很有可能写错。STL里面有个sort函数,可以直接对数组排序,复杂度为n*log2(n)。使用这个函数,需要包含头文件。 这个函数可以传两个参数或三个参数。第一个参数是要排序的区间首地址,第二个参数是区间尾地址的下一地址。也就是说,
2016-10-08 22:45:52 962
翻译 从2000年一月一日算,给一个天数,算出它是多少年月日 星期几
/#include #include using namespace std; bool isLeapYear(int year) //判断是否为闰年 {return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0); } int main()
2016-10-06 10:45:24 4920 1
翻译 并查集的例题
/*题意为: 已知学校有n个学生 ,想知道有多少个宗教,但是不能一个一个问学生 ,已知两个一起的是一个宗教的,现可以问m对学生,请求出最多有多少个宗教 输入数据 10 4 2 3 4 5 4 8 5 8 答案为7 由题知采用并查集求解 (可看做二叉树 ) */#includeusin
2016-10-06 10:34:22 445
转载 并查集的题目
/*题意:有很多组学生,在同一个组的学生经常会接触,也会有新的同学的加入。但是SARS是很容易传染的,只要在该组有一位同学感染SARS,那么该组的所有同学都被认为得了SARS。已知编号为0的同学是得了SARS的,现在的任务是计算出有多少位学生感染SARS了。思路:使用并查集*/#define _CRT_SECURE_NO_WARNINGS // 让编译环境忽略对sc
2016-10-04 21:09:53 593
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人