关注
#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
相关推荐
点赞 评论 收藏
分享
点赞 评论 收藏
分享
11-04 19:37
桂林电子科技大学 运维工程师 点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 你想跟着什么样领导? #
5593次浏览 82人参与
# 什么样的背景能拿SSP? #
117354次浏览 410人参与
# 百度秋招 #
56023次浏览 394人参与
# 你的秋招白月光和意难平公司 #
7192次浏览 82人参与
# 分享一个让你热爱工作的瞬间 #
47502次浏览 412人参与
# 找实习是选平台还是选业务? #
10330次浏览 147人参与
# 从夯到拉,评价编程语言 #
5086次浏览 48人参与
# 秋招签约后的心态变化 #
106125次浏览 923人参与
# 职场吐槽大会 #
289810次浏览 2111人参与
# 每个月花钱最多的地方是? #
5367次浏览 76人参与
# xxx岗位的一天 #
10130次浏览 92人参与
# 作业帮求职进展汇总 #
77721次浏览 520人参与
# 十一月总结 #
13469次浏览 146人参与
# 你面试时吹过最大的牛 #
20339次浏览 116人参与
# 为什么国企只招应届生 #
218519次浏览 1262人参与
# 饿了么求职进展汇总 #
80328次浏览 684人参与
# 非技术求职现状 #
549579次浏览 3509人参与
# 实习学到最有价值的工作习惯 #
43671次浏览 378人参与
# 韶音科技求职进展汇总 #
65053次浏览 510人参与
# AI“智障”时刻 #
6103次浏览 54人参与
# 实习生如何通过转正 #
111812次浏览 1421人参与
查看16道真题和解析