最大子序列和:HDU 1003 Max Sum 用动态规划的思想,求解前i个数能获得的最大和,当sum<0的时候,再加上a[i]就不如直接要a[i](不管a[i]是正是负),所以if sum < 0 then sum = 0,from = i+1;这里要更新起点 如果sum > ans则更新ans和起点、终点。 //Must so#include<iostream>#include<
1081 Rational Sum (20 分) Given N rational numbers in the form numerator/denominator, you are supposed to calculate their sum. Input Specification: Each input file contains one test case. Each case
分数的求和,还是规成求最大公因数的问题。 注意讨论各种情况,整数,真分数,假分数。 #include <iostream>using namespace std;int n;long long gcd(long long a, long long b) {if (b == 0) return a;else return gcd(b, a%b);}int main() {cin >> n;