CodeForces NO.197B Limit
来源:互联网 发布:开淘宝微店能赚钱吗 编辑:程序博客网 时间:2024/05/21 12:47
问题描述:
求。
题目链接:CodeForces 197B
思路:
根据给出的样例输入输出,来编写代码。
如果给出的分子分母指数相等,当第一个系数同号时:直接输出分子分母第一个系数的比值;异号时:输出‘-’第一个系数的比值;
当分子指数大于分母指数时:同号时输出“Infinity”,异号时输出:“-Infinity”;
当分子指数小于分母指数时:输出“0/1”。
代码:
#include<iostream>#include<cstdio>#include<cmath>#include<queue>#include<cstring>#include<algorithm>#define INF 0x3f3f3f3f#define MAX 110using namespace std;int yueshu(int a, int b){ int t = 0; if(a > b){ t = b; b = a; a = t; } while(a % b != 0) { t = a % b; a = b; b = t; } return b;}int main(){ int m, n; while(~scanf("%d%d", &m, &n) ){ int s[MAX], ss[MAX]; for(int i = 0; i <= m; i++) cin >> s[i]; for(int i = 0; i <= n; i++) cin >> ss[i]; if(m > n && s[0] * ss[0] > 0){ cout << "Infinity" << endl; continue; } if(m > n && s[0] * ss[0] <= 0){ cout << "-Infinity" << endl; continue; } if(m < n){ printf("0/1\n"); continue; } if(m == n && s[0] * ss[0] > 0){ int res = yueshu(s[0], ss[0]); printf("%d/%d\n", s[0]/res, ss[0]/res); continue; } if(m == n && s[0] * ss[0] <= 0){ s[0] = fabs(s[0]); ss[0] = fabs(ss[0]); int res = yueshu(s[0], ss[0]); printf("-%d/%d\n", s[0]/res, ss[0]/res); continue; } } return 0;}
0 0
- CodeForces NO.197B Limit
- CodeForces 197B Limit
- CodeForces 197B Limit
- codeforces Limit
- a^b time limit
- Memory Limit Exceed B
- CodeForces NO.629B Far Relative’s Problem
- codeforces B
- codeforces B
- codeforces B
- codeforces B
- No managed connection after pool limit reached
- 一首好歌- Love Minus Zero/No Limit
- Docker - WARNING: No memory limit support 问题解决
- (12B)order by 、limit
- CodeForces 626B CodeForces 626B【暴力】
- CodeForces 841B (B) 博弈
- codeforces 134B
- junit 使用JUnit测试预期异常
- 微信红包随机算法初探
- android5.1后新增shadow$_monitor_和shadow$_klass_ ,导致反射无效
- linux开发调试工具---GDB的使用
- 流媒体技术
- CodeForces NO.197B Limit
- round、ceil、floor
- 转发和重定向的区别
- HTML5:定制表单
- [BZOJ2049]洞穴勘测[BZOJ2157]旅游Link-Cut Tree模板题
- Android Annotation基础教程
- mysql
- 什么是不可修改对象(Immutable Object)?你能否写一个例子?
- 架构师主要工作