关注
#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
相关推荐
牛客热帖
更多
正在热议
更多
# 那些年,我收到的‘奇葩’回复 #
23307次浏览 159人参与
# 实习需要主动找活干吗? #
55060次浏览 295人参与
# 百度秋招 #
50507次浏览 384人参与
# OC/开奖 #
191055次浏览 1324人参与
# 你后悔选择现在的专业吗 #
101797次浏览 697人参与
# 职场中那些令人叹为观止的八卦 #
30439次浏览 243人参与
# 腾讯音乐秋招 #
431043次浏览 4779人参与
# 实习教会我的事 #
41943次浏览 342人参与
# 蚂蚁求职进展汇总 #
131503次浏览 1204人参与
# 秋招你经历过哪些无语的事 #
22244次浏览 239人参与
# 2022毕业即失业取暖地 #
120267次浏览 709人参与
# 校招薪资来揭秘 #
83707次浏览 524人参与
# 听到哪句话代表面试稳了OR挂了? #
105784次浏览 457人参与
# 秋招吐槽大会 #
92174次浏览 795人参与
# 材料人,你最希望上岸的是? #
11480次浏览 56人参与
# 你今年的保底offer是哪家 #
143717次浏览 620人参与
# 牛客十周岁生日快乐 #
184729次浏览 1825人参与
# 扒一扒那些奇葩实习经历 #
131970次浏览 1125人参与
# AI时代,哪些岗位最容易被淘汰 #
12033次浏览 99人参与
# 你找工作想离家近 or 离家远? #
16853次浏览 245人参与
# 你秋招最后悔的选择 #
18379次浏览 135人参与
# 我的职场社死时刻 #
22749次浏览 171人参与