unsigned long long与long double与向上/下取整与精度控制与小数位控制

(如有错误,望留言指正,感谢!)

 

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;
}

 

运算符优先级问题:

 

 

 

 

 

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值