03 2019 档案
摘要:Employee; package textq; /** * 调用接口Comparable排序 * @author Administrator * */ public class Employee implements Comparable<Employee>{ private int id; pr
阅读全文
摘要:public abstract class Car { public abstract String getInfo(); //用来描述汽车的信息 } public class BMW extends Car { @Override public String getInfo() { //用来描述汽
阅读全文
摘要:Shape: Shape: package Area; /** * 求面積 * @author Administrator * */ public abstract class Shape { public String getName(){ return this.getClass().getNa
阅读全文
摘要:Employee: package text1; public class Employee { public String getInfo(){ return "我是王大錘"; } } Manager: package text1; public class Manager { public St
阅读全文
摘要:Employee: import java.util.Date; /* * */ public class Employee { private String name; private double salary; private Date birthday; public Employee(){
阅读全文
摘要:类: 生活中类是人们对客观事物不断认识而产生的抽象概念,而对象则是现实生活中的一个个实体 面向对象程序设计中,对象是程序的基本单位,相似的对象像变量和类型的关系一样归并到一类,所以,并不先具体地定义对象,而是先定义对象的类 类的本质上定义的是一种对象类型,它是对具有相似行为的对象的一种抽象,描述了属
阅读全文
摘要:接口是一种特殊的抽象类,接口只提供了方法的原形,当没有具体的方法实现。子类必须提供父类中抽象方法的实现方式。接口与抽象类一样,也能定义抽象的方法,并且接口中只能包含抽象的方法,不能有常量、初始化块和构造函数。就像手机模型,只是模型只是壳子 package text5; interface Stude
阅读全文
摘要:类型的检测——向上转型 向下转型 向上转型:父类对象的引用指向子类对象,向下转型:向上转型的基础上再次指向子类的对象 1.向上转型 package text5; public class Father { public void say(){ System.out.println("father s
阅读全文
摘要:MotoVehicle抽象类 package text1; /* * 抽象 */ public abstract class MotoVehicle { // 共同的属性 private String no;// 车牌号 private String brand;// 品牌2 private Str
阅读全文
摘要:子类继承父类的属性和方法并根据需要增加它为自己的新的属性和方法 ,子类 父类(超类) java所有的类都继承object类, 对象中的克隆 1.克隆的限制 克隆的类必须自己实现Cloneable接口 实现Cloneable的接口应该使用公共的方法重写Object.clone 在java.lang.O
阅读全文
摘要:对象的克隆是java的一项高级技术,他可以根据给定的对象,获得与其完全相同的另一个对象。 1.浅克隆主要是复制对象的值 2.深克隆:当类存在聚合关系的时候,克隆就必须考虑聚合对象的克隆,可以复制引用类型的字段。 一、常见的错误: Employee 类 package text1; public cl
阅读全文
摘要:#include<iostream> using namespace std; int const maxn=1000; int n,W; int w[maxn],v[maxn]; int rec(int i,int j){ int res; if(i==n){ res=0; }else if(j<
阅读全文
摘要:#include <iostream> using namespace std; int a[1000000]; int f(int x)//判断是否为素数 { for(int i = 2; i < x; i++) { if(x%i == 0) { return 0; } } return 1; }
阅读全文
摘要:注意一下::::A Z 65--90 a z 97 122 #include<iostream> using namespace std; int main() { string str; int len,flag,i; while(getline(cin,str)){ // cout<<str<<
阅读全文
摘要://三角形的选择 #include<iostream> using namespace std; int a[101]; int i,j,k,nmm,ans,n; void solve(){ for(i=0;i<n-2;i++){ for(j=i+1;j<n-1;j++){ for(k=j+1;k<
阅读全文
摘要:二分法,这一题有点小难度。。。 首先,任意找一个数字运用二分法, #include<iostream> using namespace std; typedef long long ll; const ll inf = 0x3f3f3f3f; const int maxn = 1e5 + 10; i
阅读全文
摘要:感觉没思路的题目应该就是动态规划 #include<iostream> #include<vector> using namespace std; bool IsPalindRome(string str){//回文判断 int end=str.length()-1; int start=0; wh
阅读全文
摘要:#include<iostream> using namespace std; int main() { int n,i; while(cin>>n){ printf("%d=",n); for(i=2;i<=n;i++) while(n!=i) { if(n%i==0) { printf("%d*
阅读全文
摘要:数组求和 //求和库函数 #include<iostream> #include<numeric> #include<vector> using namespace std; int main() { int arr[]={1,2,3,4,5}; vector<int> v(arr,arr+5);
阅读全文
摘要:f(x)=4*f(x-1)+1 1=<x<=100 十位数字后溢出 有效9.63位 19位数字后溢出 有效18 (9.63*2) 分析:得使用大数处理,与大整数乘法类似 //计算 N! 30 #include<iostream> #include<cstring> using namespace s
阅读全文
摘要:第一个代码:(正确%50) //不计算简单做标记 #include<iostream> #include<cstring> using namespace std; const int maxn=1000010; int book[maxn]; int m,n; void gcd(int x){ i
阅读全文
摘要:1.求N的阶乘(10000以内的整数)数组实现 MOD数的设定与N的范围有关N最大为10^4 ,所以MOD设定10^5,相乘最大不超过九位 0!=0 printf("%05d\n",g[i]); //计算 N! 30 #include<iostream> #include<cstring> usin
阅读全文
摘要:第一次想到的是数组来表示, //打印菱形 #include<iostream> #include<cstring> using namespace std; int map[50][50]; int main() { int n; while(cin>>n){ memset(map,0,sizeof
阅读全文
摘要://K进制 递推牛逼 #include<stdio.h> int k; int f(int n) { if(n == 1) { return k-1; } else if(n == 2) { return (k-1)*k; } else { return f(n-1)*(k-1) + f(n-2)*
阅读全文
摘要:IP判断: 我想了大半天,忽然发现一位大佬,相当的逆天解法,受益匪浅!!! #include<stdio.h> #include<stdlib.h> #define JUDGE(n) (n>=0 && n<= 255)?1:0 int main(void) { char IP[16]; int a,
阅读全文
摘要:分析: 关键问题在使用 getchar()回收 '/n',不然的话getline(cin,str)会将'/n'录入 //字符串的输入输出处理 #include<iostream> using namespace std; int main() { // cout<<endl; int n,i=0;
阅读全文
摘要:分析: 周期问题,小母牛第四年才生小母牛,周期为4,递归超时的话使用备忘录 //奶牛问题 放置时间超限 #include<iostream> #include<cstring> using namespace std; int book[100]; int gcd(int n){ if(book[n
阅读全文
摘要://扫雷游戏 #include<iostream> #include<cstring> using namespace std; int i,j; char g[100][100]; int book[100][100]; int gcd(int x,int y){ int num=0; if(g[
阅读全文
摘要:网上看到的一个类似代码: #include <cstdio> #include <iostream> #include <queue> using namespace std; const int MAX_N = 100; const int MAX_M = 100; const int INF =
阅读全文
摘要:用一维数组存储二叉树,利用二分查找降低效率 1.线段树的构造,区间查询 //balanced lineup #include<iostream> #include<cstring> #include<climits> using namespace std; const int maxn=50001
阅读全文
摘要:测试数据: 100 4 2 1 2 5 10 13 11 12 14 2 0 1 2 99 2 200 2 1 5 5 1 2 3 4 5 1 0 0 0 样例输出:4 1 1 分析: 最基础的只需要解决查询问题 //并查集 #include<iostream> using namespace st
阅读全文
摘要:首先,并查集是用来区分群体,树的双亲作为并查集的存储结构,每一个集合用一棵树来表示,根节点的双亲指针为一个负数,表示元素的个数 初始化: 小变化 合并: 操作代码: //自我实现 并查集 //a[]={1,2,3,4,5,6,7} #include<iostream> using namespace
阅读全文
摘要:分析: 首先限定输出n个数,入堆n个数,输出n个数, #include<iostream> #include<queue> #include<algorithm> using namespace std; const int maxn=100000; int n,i,j; int a[100000]
阅读全文
摘要:priority_queue本质是一个堆,默认为按照元素值的大小从大到小排序 1.简单的使用方法 //二叉树 默认为小根堆 #include<iostream> #include<queue> using namespace std; int main() { priority_queue<int>
阅读全文
摘要:分析: 首先要用到队列queue,先进后出 最先q.push(1)属于预存1,杨辉三角上一层比下一层的数字少1 第0层 输出1 队列最终状态 01 第二层 输出 1 1 队列最终状态 011 第三层 输出 1 2 1 队列最终状态 0121 ...... //打印杨辉三角 #include<iost
阅读全文
摘要:这个问题,大一困扰我很长时间,我总结一下 分析: 循环三个动作 当 n==1时候,将n从 x >z; n>1时候 我们需要将n-1 借助z 搬到y,再将n由x搬到z,再将n-1由y借助z搬到x #include<iostream> using namespace std; void gcd(int
阅读全文
摘要:基本思想,当出现不匹配的时候,就知晓一部分文本内容(因为在匹配失败前已经发生匹配) P[0 ~ k-1] == P[j-k ~ j-1] //KMP #include<iostream> #include<string.h> #include<malloc.h> using namespace st
阅读全文
摘要:分析:子集不是全排列,子集与二进制先关, 1.位向量法 b[i]做标记 #include<iostream> using namespace std; int b[100]={0}; void gcd(char *s,int n,int *b,int cur){ int i; if(cur==n){
阅读全文
摘要:前面实现的字典排序算法 描述:给出一个数组S,按字典排序输出所有的序列 此时不在局限于数字,可以是字符 可以改进生成1--n全排列的代码,但是问题是当S有重复元素时候不能解决问题 出现重复: #include<iostream> using namespace std; int p[100]={0}
阅读全文
摘要:分析: 先生成1开头的排列,然后输出2开头的排列,,,最后输出n开头的排列 p[1...n] 标记作用,初始化为0, 循环 1...n判断是否取用,在每一个循环中进行递归,循环的作用是以i开头 //生成 1 n的全排列 #include<iostream> using namespace std;
阅读全文
摘要:错误代码: //筛选法? AK #include<iostream> #include<cstring> using namespace std; const int maxn=1000010; string str; int book[1000010]; int b[1000010]; int m
阅读全文
摘要:题目描述 小P感到自己前几天太作了,于是非常有远见的决定为自己建立一座金字塔。 现在他有n种标准长方体的石头,每种石头只有两个,第i种石头是长宽高分别为Xi,Yi,Zi的长方体。由于整个工程只有小P一个人,所以一切从简, 金字塔每一层只有一个石头且上一层的长宽必须严格小于下一层(石头可以旋转),为了彰显自己的地位,小P希望自己的金字塔尽量高 在此基础上小P希望自己的金字塔歪扭度最低,歪扭度为所...
阅读全文
摘要:错误代码:‘ #include<iostream> #include<cmath> using namespace std; string str; int main() { int j,i,len,num,sum=0; string arr; cin>>str; str=' '+str; len=
阅读全文
摘要:我的错误: //M份盒饭。 总共有N个学校来参加比赛 //每两个相邻点之间,小明需要行走15秒 //交付一份盒饭需要3秒时间 //102=15*(n*2)+(A1+A2+An)*3 //a1 a2 a3 a4 #include<iostream> using namespace std; int m
阅读全文
摘要:1.冒泡排序 从后往前,比较两个数的大小,交换位置 //冒泡排序 #include<iostream> using namespace std; void bubble_sort(int a[],int start,int end){ int i,j,tmp; for(i=start;i<=end-
阅读全文
摘要:问题:给n个整数,按从大到小的顺序,输出前m大的整数0<m,n<1000000,每个整数[-500000,500000]输入:5 33 -35 92 213 -644输出:213 92 3 思路:先按从小到大用快排排好序,然后输出排好序的数组从最后开始输出m个即可关键:1 已经达到千万数量级,1秒不
阅读全文
摘要:1.直接插入排序 分析:a[n]有n个元素 a[0...n-1] 从 i=1...n-1 a[i]依次与 a[0...n-2]数字进行比较 发现后面的数字大于前面的数字交换位置,每一次比较,与前面的数字x比较,小于等于x的话往前推a[j]=a[j+1],当大于a[j]时候 a[j+1]=a[i]插入
阅读全文