【机房必备】对拍&读入输出优化&氧气&高精度
来源:互联网 发布:伊朗大学 知乎 编辑:程序博客网 时间:2024/04/29 03:32
跑到新机房,发现没有s盘
于是手写了一个对拍(实验证明是对的)
虽然给了板子在这,但还是强烈建议背下来
对拍
@echo off:loopdata.exe1.exe2.exefc 1.txt 2.txt if not errorlevel 1 goto looppausegoto loop
读入优化
inline int rd(){ int x=0,y=1; char ch; while((ch=getchar())<'0'||ch>'9')if(ch=='-')y=-1; while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); return x*y;}
cin可以用这个
ios::sync_with_stdio(false);
输出优化有两种
一般来说,递归的程序慢一点
稍快:
inline int wt(int x){ if(!x)putchar('0'); if(x<0)putchar('-'),x=-x; while(x)tmp[++tmp[0]]=x%10,x/=10; while(tmp[0])putchar(tmp[tmp[0]--]+'0'); putchar('\n');}
稍慢:
inline void write(int x){ if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10+'0');}
氧气
其实还有臭氧的。。。
#prag\ma GCC optimize ("O2")
高精度加法
void Plu(int *o,int *p,int *q){ memset(tmp,0,sizeof(tmp)); tmp[0]=max(p[0],q[0])+1; for(int i=1;i<=tmp[0];i++){ tmp[i]+=p[i]+q[i]; tmp[i+1]+=tmp[i]/10; tmp[i]%=10; } while(tmp[tmp[0]]==0&&tmp[0])tmp[0]--; memcpy(o,tmp,sizeof(tmp));}
高精度乘法
void Mul(int *o,int *p,int *q){ memset(tmp,0,sizeof(tmp)); tmp[0]=p[0]+q[0]; for(int i=1;i<=p[0];i++) for(int j=1;j<=q[0];j++) tmp[i+j-1]+=p[i]*q[j]; for(int i=1;i<=tmp[0];i++){ tmp[i+1]+=tmp[i]/10; tmp[i]%=10; } while(tmp[tmp[0]]==0&&tmp[0])tmp[0]--; memcpy(o,tmp,sizeof(tmp));}
高精度大于号
bool Max(int *p,int *q){ if(p[0]>q[0])return 1; if(p[0]<q[0])return 0; for(int i=p[0];i>=1;i--)if(p[i]>q[i])return 1; else if(p[i]<q[i])return 0; return 0;}
高精度输出(无优化)
void Pri(int *x){ if(x[0]==0)printf("0"); else for(int i=x[0];i>=1;i--)printf("%d",x[i]); printf("\n");}
阅读全文
0 0
- 【机房必备】对拍&读入输出优化&氧气&高精度
- 读入优化&输出优化
- 读入输出优化
- 读入输出优化
- ACM读入输出优化
- C++读入输出优化
- Tip_读入输出优化
- c++读入输出优化
- 读入/输出优化
- C++读入输出优化
- 读入输出优化板子
- 读入输出优化
- C++ 读入/输出优化
- 读入输出优化
- 2017.10.13. 读入、输出优化
- mac os 程序对拍(同Linux对拍) 以及c++文件读入
- C++ 读入优化与输出优化 模板
- 【SinGuLaRiTy-1009】 模板-读入优化 & 输出优化
- HTTP协议
- bzoj1717: [Usaco2006 Dec]Milk Patterns 产奶的模式
- ::memcpy()函数的用法?
- 在PHP框架中使用array_map()等函数
- 微信小程序开发-form 表单提交和取值
- 【机房必备】对拍&读入输出优化&氧气&高精度
- xUtils更新到3.0后的基本使用规则
- LeetCode: 581. Shortest Unsorted Continuous Subarray
- 从狡猾的房产中介来看动态代理
- 如何让一段代码在 tomcat 启动时就被运行?
- 闭包就是能够读取其他函数内部变量的函数
- Chrome谷歌浏览器下不支持css字体小于12px的解决办法
- g_strdup_printf
- 数据结构之二叉树遍历