本文主要是介绍ICPC 7096 A Rational Sequence,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目大意,看图片和样例。输入一个数,求这个数接下去的数。
可以找到规律。如果是左支。。。。。。右支。。。。。。
其中右支不能直接的和下一个数有联系。
可以看出,右支可以一路上推出某根,然后通过这个所谓的根,往下再一直推左支直到解。
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
using namespace std;
int main()
{long long T;cin >> T;while(T--){long long num,x,y;scanf("%lld %lld/%lld",&num,&x,&y);long long t;cout<<num<<" ";if(x==y)cout<<"1/2\n";else{t = x/y;if(x<y)cout<<y<<"/"<<(y-x)<<endl;elsecout<<y<<"/"<<(y-x+2*t*y)<<endl;}}return 0;
}
这篇关于ICPC 7096 A Rational Sequence的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!