2020.1.3计导全面复习
Posted thmyl
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2020.1.3计导全面复习相关的知识,希望对你有一定的参考价值。
//用宏定义替换文本 #include<iostream> #include<cstdio> #define p(m,n) printf("Hi,"#m"! ""...And "#n"~ ") int main(){ p(John,Amy); }
//条件编译 #include<iostream> #include<cstdio> #ifdef WIN32 #define PLL "%I64d" #else #define PLL "%lld" #endif int main(){ long long x; scanf("%lld",&x); printf(PLL" ",x); }
//用带参宏计算圆的面积和周长 #include<iostream> #include<cstdio> #define PI 3.1415926 #define C(r) (2*PI*(r)) #define S(r) (PI*(r)*(r)) int main(){ double x=1.2; printf("%lf %lf ",C(x),S(x)); return 0; }
//线性同余产生随机数 #include<iostream> #include<cstdio> #include<ctime> #define maxn 100010 const int a=975323; const int b=2333333; const int mod=152487967; using namespace std; int X[maxn]; int main(){ X[0]=time(0); for(int i=1;i<=10;i++){ X[i]=(1LL*a*X[i-1]+b)%mod; } for(int i=1;i<=10;i++) printf("%d ",X[i]); return 0; }
//冒泡排序+二分查找 #include<iostream> #include<cstdio> using namespace std; int n,a[1000]; int main(){ scanf("%d",&n); for(int i=1;i<=n;i++)scanf("%d",&a[i]); for(int i=1;i<n;i++) for(int j=1;j<=n-i;j++) if(a[j]>a[j+1])swap(a[j],a[j+1]); int l=1,r=n,ans=0; for(int i=1;i<=n;i++)printf("%d ",a[i]);puts(""); int x;scanf("%d",&x); while(l<=r){ int mid=(l+r)>>1; if(a[mid]>=x){ r=mid-1; ans=mid; } else l=mid+1; } printf("%d ",ans); return 0; }
//蒙特卡洛算法求积分 #include<iostream> #include<ctime> #include<cstdlib> #include<cstdio> using namespace std; double l,r,up,down; double M,N; int main(){ srand(time(0));rand();rand(); double x,y; l=1;r=2;up=1;down=0; for(int i=1;i<=1000000;i++){ x=1LL*rand()*rand()*rand()%10000000; y=1LL*rand()*rand()*rand()%10000000; x+=10000000; x=x/10000000.0; y=y/10000000.0; if(x>=1&&x<=2&&y>=0&&y<=1)M++; if(x>=1&&x<=2&&y>=0&&y<1.0/x)N++; } double ans=1.0*N/M; printf("%f ",ans); return 0; }
#include<iostream> #include<cstdio> #include<cstring> #include<ctime> #include<cstdlib> using namespace std; int main(){ srand(time(0));rand();rand(); double x,y,M=0,N=0; for(int i=1;i<=10000000;i++){ x=1LL*rand()*rand()*rand()%10000000; y=1LL*rand()*rand()*rand()%10000000; x/=10000000.0; y/=10000000.0; if(x<=1&&x>=0&&y<=1&&y>=0){ M++; if(x*x+y*y<=1)N++; } } double ans=N*4.0/M; printf("%f",ans); return 0; }
以上是关于2020.1.3计导全面复习的主要内容,如果未能解决你的问题,请参考以下文章