水题巨坑 1
AtCoDeer the deer is seeing a quick report of election results on TV. Two candidates are standing for the election: Takahashi and Aoki. The report shows the ratio of the current numbers of votes the two candidates have obtained, but not the actual numbers of votes. AtCoDeer has checked the report N times, and when he checked it for the i-th (1≤i≤N) time, the ratio was Ti:Ai. It is known that each candidate had at least one vote when he checked the report for the first time.
Find the minimum possible total number of votes obtained by the two candidates when he checked the report for the N-th time. It can be assumed that the number of votes obtained by each candidate never decreases.
Constraints
1≤N≤1000
1≤Ti,Ai≤1000(1≤i≤N)
Ti and Ai (1≤i≤N) are coprime.
It is guaranteed that the correct answer is at most 1018.
Find the minimum possible total number of votes obtained by the two candidates when he checked the report for the N-th time. It can be assumed that the number of votes obtained by each candidate never decreases.
Constraints
1≤N≤1000
1≤Ti,Ai≤1000(1≤i≤N)
Ti and Ai (1≤i≤N) are coprime.
It is guaranteed that the correct answer is at most 1018.
输入
The input is given from Standard Input in the following format:
N
T1 A1
T2 A2
:
TN AN
N
T1 A1
T2 A2
:
TN AN
输出
Print the minimum possible total number of votes obtained by Takahashi and Aoki when AtCoDeer checked the report for the N-th time.
样例输入
3
2 3
1 1
3 2
样例输出
10
提示
When the numbers of votes obtained by the two candidates change as 2,3→3,3→6,4, the total number of votes at the end is 10, which is the minimum possible number.
感觉挺容易的 然后用ceil一直红
好像是没特判整除的情况。。。
#include <bits/stdc++.h> #define ll long long using namespace std; int main(){ int n; scanf("%d",&n); ll a=0,b=0,x,y,maxn,t,p; while(n--){ //t=0,p=0; scanf("%lld %lld",&x,&y); maxn=1; if(a>x){ maxn=a/x; if(a%x!=0) maxn++; } if(b>y){ p=b/y; if(b%y!=0) p++; maxn=max(maxn,p); } a=x*maxn; b=y*maxn; } printf("%lld\n",a+b); return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; int main(){ int n; scanf("%d",&n); ll a=0,b=0,x,y,sum=0,maxn,t,p; while(n--){ t=-1,p=-1; scanf("%lld %lld",&x,&y); if(x>=a&&y>=b) {a=x,b=y;} else if(x>a&&y==b){a=x;} else if(y>b&&x==a){b=y;} else if(a>x||b>y){ if(a>x){ t=a/x; if(a%x!=0) t++; } if(b>y){ p=b/y; if(b%y!=0) p++; } maxn=max(t,p); a=x*maxn; b=y*maxn; } } printf("%lld\n",a+b); return 0; }
这是之前的,后来发现错那么多次就是那个t和p惹的祸,没有赋初值,可能有p没t
然后前面一开始没有想到用longlong 。。。。
一种做题习惯不好的感觉
数据范围啊,变量赋初值之类的都没有考虑很好,然后使用函数可能产生double之类的.....
要改变这种做题习惯
不要忘记努力,不要辜负自己
欢迎指正 QQ:1468580561

浙公网安备 33010602011771号