关注
#include<iostream> #include<vector> #include<stdlib.h> #include<math.h> using namespace std; int main() { int x, y; cin >> x >> y; if (x < 0 || y < 0 || x > 1000000 || y > 1000000) { return (0); } if (x == y) { cout << x + 1 << endl; return (0); } //if (x==1) //{ // cout << y + 1 << endl; // return (0); //} //if (y == 1) //{ // cout << y + 1 << endl; // return (0); //} if (x < y) { int temp = x; x = y; y = temp; } //fuction y=y0/x0*x double a = y + 1; double b = x + 1; double coe = a / b; int res = 0; double flag1 = 0; int flag = 0; for (int i = 0; i <= x + 1; i++) { double temp1 = 0; temp1 = coe*i; int temp2 = (int)temp1; if (fabs(temp1 - temp2) < 0.000001 || fabs(temp1 - temp2 - 1) < 0.000001) { flag = 1; flag1 = temp1; continue; } else { int temp3_top = int(temp1 + 1); int temp3_bottom = int(temp1); if (temp3_top > flag1 && temp3_top > temp1 ) { if (flag == 1) { flag1 = temp1; res += 2; flag = 0; continue; } else if (temp3_bottom > flag1 && temp1 > temp3_bottom) { flag1 = temp1; res += 2; flag = 0; continue; } else { res += 1; flag1 = temp1; continue; } } else { flag1 = temp1; res += 2; continue; } } } cout << res << endl; return (0); }
查看原帖
点赞 1
相关推荐
03-15 15:44
南阳理工学院 运营 点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 如何一边实习一边找下家? #
7844次浏览 71人参与
# 重来一次,你会对开始求职的自己说 #
37782次浏览 397人参与
# 春招/暑实第一面是哪家? #
9319次浏览 131人参与
# 面试官最爱问的 AI 问题是...... #
6452次浏览 234人参与
# 跟HR说什么能被秒回? #
3616次浏览 70人参与
# 你收到了哪些公司的笔试? #
8580次浏览 44人参与
# 你的嫡系AI是哪个? #
1616次浏览 43人参与
# 现在入门AI应该走哪些方向? #
1521次浏览 35人参与
# 你现在的工作,是“成长”还是“消耗”? #
5443次浏览 85人参与
# 把自己当AI,现在最消耗你token的问题是什么? #
812次浏览 24人参与
# 你的mentor是什么样的人? #
56325次浏览 765人参与
# 金三银四,你的春招进行到哪个阶段了? #
19822次浏览 266人参与
# 技术岗笔试题求解 #
109709次浏览 1114人参与
# 运营/市场营销人的秋招现状 #
31679次浏览 213人参与
# 2022届毕业生现状 #
1067096次浏览 7704人参与
# 迅雷笔试 #
5155次浏览 23人参与
# 27届实习投递记录 #
2302次浏览 48人参与
# 滴滴笔试 #
39357次浏览 215人参与
# 职场上哪些行为很加分? #
340846次浏览 3837人参与
# 你认为小厂实习有用吗? #
128495次浏览 709人参与