- 博客(21)
- 收藏
- 关注
原创 p1496
分别对起点和终点进行排序,循环加上每一条线段的长度,若与前一条线段重复减去重复部分 #include #include #include using namespace std; int main() { int n; cin>>n; long long a[20001],b[20001],l=0;//a数组存储起点,b数组存储终点,l表示最终长度 for(int i=0;i<n;i++) cin>>a[i]>>b[i];//输入 sort(a,a+n); sort
2020-08-08 22:24:35
155
原创 p1029
#include #include #include #include int gcd(int x,int y){ if (y==0) return x; else return gcd(y,x%y); } int main(){ int n,m; scanf("%d%d",&n,&m); int ans=0; for (int i=1;i<=(int)sqrt(nm);i++){ if ((nm)%i==0&&gcd(i,(nm)/i)==n) ans++; } pr
2020-08-01 09:03:04
212
原创 p1102
#include #include using namespace std; int big,n,c,s; int a[1000000],b[1000000]; //数组要大。 int main() { cin>>n>>c; for(int i=1;i<=n;i++) { cin>>a[i]; b[a[i]]++; //数组计数,判断数出现了几个次数。 if(a[i]>big) big=a[i]; } for(int i=1;i<=big;
2020-07-27 13:26:50
233
原创 p4715
#include <bits/stdc++.h> using namespace std; int n; struct team{ int a,num;//a代表能力值,num代编号 }t[1000]; bool cmp(team a,team b) {return a.a<b.a;} int main() { scanf("%d",&n); for(int i=1;i<=(1<<n);i++)//1的二进制左移三位在换成十进制 scanf("%d",&t
2020-07-24 10:59:49
214
原创 p5738
#include<bits/stdc++.h> using namespace std; int n,m; double ans,sum,maxn,minn; int main(){ cin>>n>>m; for(int i=1;i<=n;++i){ sum=maxn=0,minn=11; for(int j=1;j<=m;++j){ double x; cin>>x; sum+=x; maxn=max(maxn,x); mi
2020-07-21 09:11:11
268
原创 p1605
#include #include using namespace std; bool G[15][15],VIS[15][15];//G为总地图,VIS记录是否访问 int n,m,d[5]={-1,0,1,0,-1};//方向 int nx,ny,ex,ey,sum; //nx,ny起点坐标;ex,ey终点坐标,sum路径条数 void dfs(int x,int y) { if (x ==ex&&y ==ey)//如果到终点 { sum++;//路径加一 return;//回去继续
2020-07-16 21:16:42
136
原创 p1012
题目描述 设有n个正整数(n≤20)(n≤20),将它们联接成一排,组成一个最大的多位整数。 输入格式 第一行有一个整数,表示数字个数 nn。 第二行有 nn个整数,表示给出的 nn个整数 ai 输出格式 一个正整数,表示最大的整数 #include<bits/stdc++.h> using namespace std; bool cmp(string a,string b) { return a+b>b+a;//直接用string类型将两个数连起来进行比较 } int mai
2020-07-13 11:23:45
152
原创 p1028数的计算
设f[i]为初始值为i时的满足条件总数,可得f[i]=f[1]+f[2]+f[3]+…+f[i/2];容易想到f[1]=1; 因为f[i]=f[1]+f[2]+f[3]+…+f[i/2] 所以当i为奇数时f[i]=f[i-1],当i为偶数时f[i]=f[i-1]+f[i/2]; #include <iostream> using namespace std; int f[1001]; int main() { int n; cin>>n; f[1]=1;
2020-07-10 11:11:53
168
原创 p1042
//直接分为11分和21分两种情况进行讨论(在判断为E时结束) #include <stdio.h> #include #include using namespace std;//namespace,是指标识符的各种可见范 围。C++标准程序库中的所有标识符都被定义于一个名为std 的namespace中 int win[60000]; //每行25,2500行,大概11制下结果最多也要有5000多组 int w,l; int main() { char s; for(int i=1;c
2020-07-10 10:54:12
217
原创 p1012拼数
//#include //#include #include<bits/stdc++.h> //万能头文件 using namespace std; bool cmp(string x,string y) { return x+y>y+x; } int main(){ int n; cin>>n; string num[21]; for(int i=1;i<=n;i++) cin>>num[i];//<=n找半天 sort(num+1,num+1+n,c
2020-07-09 12:15:14
144
原创 vector
使用vexctor容器bai必须包含”duvector”头文件,然后创建一个zhivector容器对象(方式很多dao种,这里就不一一介绍了,具体看实例 ????),然后我们对vector容器初始化赋值(可以使用push_back在容器尾端加入元素),如果我们要对vector容器遍历的话,可以常用数组或者迭代器的方式. 下面的例子展示了如何用数组方式访问vector元素. #include #include using namespace std; int main(void){ vector v; v
2020-07-09 11:50:04
128
原创 p1104
#include #include #include #include #include #include #include #include using namespace std; int n; struct node{ string name;//姓名 int year,mon,day;//年月日 int level;//记输出顺序 }nn[105]; bool cmp(node a,node b){ if(a.year != b.year) return a.year < b.year;//出
2020-07-07 11:05:19
278
原创 p1149
#include using namespace std; int n[10]={6,2,5,5,4,5,6,3,7,6};//每个数字所需的火柴数 int matches(int num){ //计算一个数需要多少火柴 int i,k=0; //K是火柴棒的数量 for(i=num;i!=0;i/=10)k+=n[i%10]; //将这个数字每一位的火柴棒的数量都计算出来 if(num0)k+=n[0]; //0特判 return k; } int main(){ int
2020-07-06 10:47:01
130
原创 p1217
#include #include using namespace std; int prime(int n) {//判定素数 if(n1)//1不是质数 return 0; if(n%20)//偶数也不是质数 return 0; else {//可以直接到根号n,节省时间 int i; for(i=2; i<=sqrt(n); i++) { if(n%i0) return 0; } return 1; } } int hw(int n) {//判定回文数 int sum=0; int k=n; wh
2020-07-05 23:34:39
295
原创 p1781
#include #include #include using namespace std; struct node { string x; //装票数 int num; //装号数 int lenx; //装票数的位数 }s[25]; bool cmp(node a,node b) { if(a.lenx>b.lenx) return 1; //前一个比后一个位数多,不交换 if(a.lenx==b.lenx&&a.x>b.x) return 1; //位数相同,但前一个按
2020-07-05 22:43:04
132
原创 p1093
#include #include using namespace std; struct stu {//先定义一个结构体stu: int num;//编号 int c,m,e; int sum; }student[310]; bool cmp(stu a,stu b) {//比较函数 if(a.sum>b.sum) return 1; else if(a.sum<b.sum) return 0; else { if(a.c>b.c) return 1; else if(a.c<b.
2020-07-05 21:34:56
322
原创 P1042
//直接分为11分和21分两种情况进行讨论(在判断为E时结束) #include <stdio.h> #include <iostream> #include <cstring> using namespace std; int win[10000]; int w,l; int main() { char s; for(int i=1;cin>>s&&s!='E';i++)//循环判断,当碰到E结束 { if(s=='W')wi.
2020-07-05 12:10:26
263
原创 Java学习之方法
类中方法的声明和使用。 * 比如:Math类:sqrt()、random()....... * Scanner类:nextXxxv()... * Array类:sort()\binarySearch() \toString()\ eauqls().... * * 1.举例 * public void eat(){} * public void sleep(int hour){} * pu...
2020-07-04 10:50:13
664
原创 Java学习之属性
类中属性的使用 * 属性(成员变量)vs局部变量 1.相同点: 1.1定义变量的格式:数据类型 变量名=变量值 1.2先声明,后使用 1.3 变量都有作用域 2.不同点: 2.1在类中声明的位置不同 属性:直接定义在类的一对{}内 局部变量:声明在方法内,方法形参,代码快内, 构造器形参,构造器内部的变量 2.2 权限修饰符的不同 属性:可以在声明属性时,指明起权限,使用权限 修饰符。
2020-07-04 10:48:13
201
1
原创 P1303
首先将两个特别大的数字读入字符串,然后倒着放进一维数组(和高精度算法一样); cin>>a>>b;//获取两个数 int lena=strlen(a); int lenb=strlen(b); for(i=1;i<=lena;i++)a[i]=a[lena-i]-'0'; for(i=1;i<=lenb;i++)b[i]=b[lenb-i]-'0'; 计算乘法的时候可以使用两个循环进行枚举 数组c作为答案数组,在枚举时令c[i+j-1]+=a[i] * b..
2020-07-02 21:39:25
202
原创 高精度
1: void method(int *a, int *b) //高精度乘法 { // memset(r, 0, sizeof(r)); for(int i = 0; i < 500; ++i) { int before = 0; for(int j = 0; j < 500; ++j) { r[i + j] += a[i] * b[j] + before; before = ...
2020-07-01 15:15:08
172
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人