书山有径勤为路>>>>>>>>

<<<<<<<<学海无涯苦作舟!

随笔分类 -  C 基础知识

快速排序
摘要:#include <iostream>using namespace std;int a[50001];int qs(int s, int e){ int x = a[s], l = s, r = e; if(l >= r) return 0; while (l < r) { while(l<r && a[r]>=x) //从右向左扫描 r--; a[l] = a[r]; while(l<r && a[l]<=x) //从左向右扫描 l++; a[r] = ... 阅读全文

posted @ 2011-11-22 13:59 More study needed. 阅读(229) 评论(0) 推荐(0) 编辑

数组的强大作用
摘要:DescriptionAs a contestant, you must be familiar with the rules of ACM-ICPC. Teams are ranked according to the most problems solved. Teams who solve the same number of problems are ranked by least total time. The total time is the sum of the time consumed for each problem solved. The time consumed f 阅读全文

posted @ 2011-11-21 21:20 More study needed. 阅读(421) 评论(0) 推荐(0) 编辑

File ——fscanf&fprintf
摘要:View Code #include<stdio.h>#include<stdlib.h>FILE *fp;int main(){ long l; float f; char s[89]; char c; fp=fopen("C:\\file\\fscanf_fprintf.txt", "w+"); if(fp==NULL) printf("Can't Open The File\n"); else { fprintf(fp, "%s %d %f%c", "stringbu 阅读全文

posted @ 2011-11-06 00:37 More study needed. 阅读(242) 评论(0) 推荐(0) 编辑

File ——getchar() putchar()
摘要:1.使用文件的方式共有12种,下面给出了它们的符号和意义。文件使用方式 意义“rt” 只读打开一个文本文件,只允许读数据“wt” 只写打开或建立一个文本文件,只允许写数据“at” 追加打开一个文本文件,并在文件末尾写数据“rb” 只读打开一个二进制文件,只允许读数据“wb” 只写打开或建立一个二进制文件,只允许写数据“ab” 追加打开一个二进制文件,并在文件末尾写数据“rt+” 读写打开一个文本文件,允许读和写“wt+” 读写打开或建立一个文本文件,允许读写“at+” 读写打开一个文本文件,允许读,或在... 阅读全文

posted @ 2011-11-04 22:00 More study needed. 阅读(400) 评论(0) 推荐(0) 编辑

对闰年 平年的优化
摘要:Description定义一个结构体变量(包括年、月、日),编程序,要求输入年月日,计算并输出该日在本年中第几天。注意本题一定要定义结构体变量,否则本实验成绩无效。Input输入三个整数(并且三个整数是合理的,既比如当输入月份的时候应该在1 至12 之间,不应该超过这个范围)否则输出Input error!Output输出一个整数.既输入的日期是本月的第几天。Sample Input1985 1 202006 3 12Sample Output2071Hint1、算法提示:如果输入的是2006 年3 月12 日,计算方法是:计算2006 年1 月1 日到2006-3-12 是多少天。注意同样判 阅读全文

posted @ 2011-11-04 14:47 More study needed. 阅读(266) 评论(0) 推荐(0) 编辑

闰年 平年
摘要:Description定义一个结构体变量(包括年、月、日),编程序,要求输入年月日,计算并输出该日 在本年中第几天。注意本题一定要定义结构体变量,否则本实验成绩无效。Input输入三个整数(并且三个整数是合理的,既比如当输入月份的时候应该在1 至12 之间, 不应该超过这个范围)否则输出Input error!Output输出一个整数.既输入的日期是本月的第几天。Sample Input1985 1 202006 3 12Sample Output2071Hint1、算法提示:如果输入的是2006 年3 月12 日,计算方法是:计算2006 年1 月1 日 到2006-3-12 是多少天。注意 阅读全文

posted @ 2011-11-03 21:08 More study needed. 阅读(348) 评论(0) 推荐(0) 编辑

位运算处理N皇后
摘要:n皇后问题位运算版n皇后问题是啥我就不说了吧,学编程的肯定都见过。下面的十多行代码是n皇后问题的一个高效位运算程序,看到过的人都夸它牛。初始时,upperlim:=(1 shl n)-1。主程序调用test(0,0,0)后sum的值就是n皇后总的解数。procedure test(row,ld,rd:longint);varpos,p:longint;begin{ 1}if row<>upperlim then{ 2}begin{ 3} pos:=upperlim and not (row or ld or rd);{ 4} while pos<>0 do{ 5} be 阅读全文

posted @ 2011-10-17 08:45 More study needed. 阅读(800) 评论(0) 推荐(0) 编辑

最基本的位运算
摘要:=== 1. and运算 ===( & ) and运算通常用于二进制取位操作,例如一个数 and 1的结果就是取二进制的最末位。这可以用来判断一个整数的奇偶,二进制的最末位为0表示该数为偶数,最末位为1表示该数为奇数. 相同位的两个数字都为1,则为1;若有一个不为1,则为0。 00111 11100 (&或者and) ---------------- 00100=== 2. or运算 ===( | ) or运算通常用于二进制特定位上的无条件赋值,例如一个数or 1的结果就是把二进制最末位强行变成1。如果需要把二进制最末位变成0,对这个数or 1之后再减一就可以了,其实际意义就是 阅读全文

posted @ 2011-10-16 19:53 More study needed. 阅读(1788) 评论(0) 推荐(5) 编辑

经典进制转换——USACO Palindromic Squares
摘要:DescriptionPalindromes are numbers that read the same forwards as backwards. The number 12321 is a typical palindrome.Given a number base B (2 <= B <= 20 base 10), print all the integers N (1 <= N <= 300 base 10) such that the square of N is palindromic when expressed in base B; also pri 阅读全文

posted @ 2011-10-16 11:00 More study needed. 阅读(235) 评论(0) 推荐(0) 编辑

归并排序
摘要:#include<iostream>using namespace std;const int SIZE = 100;int arr[SIZE];void mergeSort(int fir,int end){ //当子序列就只有一个元素的时候就弹出 if(fir==end)return; //分治 int mid = (fir+end)/2; mergeSort(fir,mid); mergeSort(mid+1,end); //合并 int tempArr[SIZE]; int fir1=fir,fir2=mid+1; for(int i=fir;i<=end;i++) 阅读全文

posted @ 2011-10-14 13:19 More study needed. 阅读(172) 评论(0) 推荐(0) 编辑

二分查找
摘要:这个是精简了的二分查找,个人觉得实在是无法简化了,如果还可以的话,请高人指点一二,先谢谢了。View Code #include "iostream"#include "algorithm"using namespace std;int BinSearch(int *R, int n, int KeyNum){ int low = 0, high = n+1, mid=0; //mid设置为0,是为了利用R[mid]来查找,这样更加精简代码 while(low <= high) { if(R[mid] == KeyNum) //包含了R[0]的情况 阅读全文

posted @ 2011-10-13 22:53 More study needed. 阅读(215) 评论(0) 推荐(0) 编辑

大整数乘法——简单
摘要:写这个程序的时候有三个关键点,知道了这个,你Win, Or, 你Lose!我将它们一一注释在了代码中。View Code #include "iostream"#include "cstring"#include "string"using namespace std;#define maxlen 200int a[maxlen]; int b[maxlen]; int c[2*maxlen+1]; //这个地方也是个关键,一定要多加一个正数,不然错string s1;string s2;int main(){ while(cin&g 阅读全文

posted @ 2011-10-12 11:24 More study needed. 阅读(312) 评论(0) 推荐(0) 编辑

大整数加法——带有负数的
摘要:#include "iostream"#include "string"#include "cstring"using namespace std;#define maxlen 2001int a[maxlen];int b[maxlen];int len1, len2, i, j;int bigger(int a, int b){ return a>b?a:b;}void Add(int underzero){ if(underzero) cout<<'-'; int big = bigger(le 阅读全文

posted @ 2011-10-10 21:53 More study needed. 阅读(497) 评论(0) 推荐(0) 编辑

大整数加法——最简单的
摘要:#include<iostream>#include<string>#include<cstring>using namespace std;#define maxlen 200int a[maxlen];int b[maxlen];int bigger(int a, int b){ return a>b?a:b;}int main(){ string s1, s2; while(cin>>s1>>s2) { int len1 = s1.length(); int len2 = s2.length(); memset(a, 0, 阅读全文

posted @ 2011-10-10 21:51 More study needed. 阅读(202) 评论(0) 推荐(0) 编辑

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

书山有径勤为路>>>>>>>>

<<<<<<<<学海无涯苦作舟!

点击右上角即可分享
微信分享提示