(如有错误,望留言指正,感谢!)
unsigned long long:
范围:0~2^64-1 = 18446744073709551615; (1e19+8e18)
输入输出:
unsigned long long a,b,c;
scanf("%llu",&a);
printf("%llu\n", a);
cin>>b;
cout<<b<<"\n";
scanf("%I64u",&c);
printf("%I64u\n",c );
有的OJ要用%I64u使用uLL,用%I64d使用LL,比如codeforces等。
Microsoft Visual C++ 6.0 :要用 %I64u
Win系统:可以用 %llu
Linux系统:要用 %llu
(听说还有更大_int128,但是我不会用)
__int128 x = 10;
printf("%d\n",x);
printf("%u\n",x);
printf("%lld\n",x);
printf("%llu\n",x);
long double:
比特位:128位
有效数字:18~19
(具体与编译器,操作系统有关)
输入输出:
long double a,b;
scanf("%llf",&a);
printf("%llf\n",a );
cin>>b;
cout<<b<<"\n";
tips:
刷ACM题的时候,当输出类型double时,不一定需要使用%lf,一般都使用%f。
浮点类型的输出方法还有:%e/%E 和 %g;一个是指数形式,一个是自动选择
向上/下取整:
向上取整:double ceil(double x)
向下取整:double floor(double x)
四舍五入:
double b;
int a=(int)(b+0.5);
精度控制:
1).
const double eps = 1e-8;
在强制类型转化和比较浮点大小时,加上eps往往更为保险,而eps具体精度,视题目而定!
double强制转化为int:
int a;
double b;
a = (int)(b+eps);
比较浮点类型大小:
double a,b;
if(a-b>eps)printf("a比较大\n");
if(a-b<-eps)printf("a比较小\n");
2).
控制输出几位小数时:
#include <iomanip>
double a;
printf("%.4f\n",a );
printf("%.*f\n",4,a);
double b;
cout.setf(ios::fixed);
cout<<setprecision(4)<<b<<"\n";
double c;
cout<<fixed<<setprecision(4)<<c<<"\n";
cout.unsetf(ios::fixed);//关闭补0
cout <<setprecision(4)<<d<<"\n";
cout << fixed << setprecision(9) << ans;
acos,asin,atan,atan2的值范围:
acos: [0,π]
asin: [-π/2,π/2]
atan: (-π/2,π/2)
atan2: (-π,π]
浮点数比较大小:
bool dy(double x,double y) { return x > y + eps;} // x > y
bool xy(double x,double y) { return x < y - eps;} // x < y
bool dyd(double x,double y) { return x > y - eps;} // x >= y
bool xyd(double x,double y) { return x < y + eps;} // x <= y
bool dd(double x,double y) { return fabs( x - y ) < eps;} // x == y
int dcmp(double x) {//三态函数,减少精度问题
if (fabs (x) < eps) return 0;
else return x < 0 ? -1 : 1;
}
求gcd的几种方法:
LL gcd(LL a,LL b){
while(b^=a^=b^=a%=b);
return a;
}
LL gcd(LL a,LL b){
LL s=1,c;
while(a&&b){
if((~a&1)&&(~b&1))
a>>=1,b>>=1,s<<=1;
else if(~a&1)a>>=1;
else if(~b&1)b>>=1;
else if(a>b)a=a-b;
else c=b-a,b=a,a=c;
}
if(!a)return b*s;
if(!b)return a*s;
}
LL gcd(LL a,LL b){
return b==0?a:gcd(b,a%b);
}
int exgcd(int a,int b,int &d,int &x,int &y){
if(b==0){
x=1;y=0;d=a;
return;
}
exgcd(b,a%b,d,y,x);
y -= a/b*x;
return;
}
运算符优先级问题: