csu 1619 Con + tin / (ued + Frac / tions)
来源:互联网 发布:excel调用数据图表 编辑:程序博客网 时间:2024/05/16 07:47
写一个分数类模拟一下就行了。。。。很多坑
#include <iostream>#include <queue>#include <stack>#include <map>#include <set>#include <bitset>#include <cstdio>#include <algorithm>#include <cstring>#include <climits>#include <cstdlib>#include <cmath>#include <time.h>#define maxn 505#define maxm 10005#define eps 1e-12#define mod 998244353#define INF 0x3f3f3f3f#define PI (acos(-1.0))#define lowbit(x) (x&(-x))#define mp make_pair//#define ls o<<1//#define rs o<<1 | 1//#define lson o<<1, L, mid //#define rson o<<1 | 1, mid+1, R//#pragma comment(linker, "/STACK:102400000,102400000")#define pii pair<int, int> typedef long long LL;typedef unsigned long long ULL;//typedef int LL;using namespace std;LL qpow(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base;base=base*base;b/=2;}return res;}LL powmod(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base%mod;base=base*base%mod;b/=2;}return res;}// headstruct Fra{LL e, d;Fra(LL e = 0, LL d = 0) : e(e), d(d) {}void inv(){swap(e, d);if(d < 0) e = -e, d = -d;}void to(){LL g = __gcd(e, d);e /= g, d /= g;if(d < 0) e = -e, d = -d;}Fra operator + (const Fra& b) const {Fra res = Fra(e * b.d + b.e * d, d * b.d);res.to();return res;}Fra operator - (const Fra& b) const {Fra res = Fra(e * b.d - b.e * d, d * b.d);res.to();return res;}Fra operator * (const Fra& b) const {Fra res = Fra(e * b.e, d * b.d);res.to();return res;}Fra operator / (const Fra& b) const {Fra res = Fra(e * b.d, d * b.e);res.to();return res;}}r1, r2;LL a[maxn];int n1, n2;void solve(Fra x){int flag = 0;if(x.e == 0) printf("0");while(x.d && x.e) {LL t = x.e / x.d;if(x.e < 0 && x.e % x.d) t--;if(flag == 0) flag = 1, printf("%lld", t);else printf(" %lld", t);x.e -= x.d * t;x.to();x.inv();}printf("\n");}void work(){for(int i = 1; i <= n1; i++) scanf("%lld", &a[i]);r1 = Fra(a[n1], 1LL);for(int i = n1-1; i >= 1; i--) {r1.inv();r1 = r1 + Fra(a[i], 1LL);}for(int i = 1; i <= n2; i++) scanf("%lld", &a[i]);r2 = Fra(a[n2], 1LL);for(int i = n2-1; i >= 1; i--) {r2.inv();r2 = r2 + Fra(a[i], 1LL);}solve(r1 + r2);solve(r1 - r2);solve(r1 * r2);solve(r1 / r2);}int main(){int _ = 0;while(scanf("%d%d", &n1, &n2), n1 || n2) {printf("Case %d:\n", ++_);work();}return 0;}
0 0
- csu 1619 Con + tin / (ued + Frac / tions)
- CSU1619: Con + tin / (ued + Frac / tions)
- CSU1619 Con + tin / (ued + Frac / tions)
- CSU 1715 Positive Con Sequences
- UED
- ued
- con
- Frac函数
- Shader frac
- CSU-1715 Positive Con Sequences(模拟分四种情况 )From湖南省多校对抗赛E题(2016.03.27)
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- JSoup 代码总结
- win8 64位Emgu.CV.CvInvoke”的类型初始值设定项引发异常
- 函数重载
- 如何使用Ubuntu手机平台中的照相机API来存储照片
- 苹果开发 笔记(25)CATransition
- csu 1619 Con + tin / (ued + Frac / tions)
- IOS开发完整学习路线图
- php获取url
- win8全新安装wampserver数据库管理phpmyadmin显示forbidden 403错误 的解决方法
- 两种初始化参数文件
- iOS 图片加载 圆形进度条
- android使用http协议实现多线程断点下载
- 利用Facebook登录应用的方法
- 【5/18笔记】主要关于margin负值和display:none,overflow清除浮动