关注
#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-19 11:21
门头沟学院 算法工程师 点赞 评论 收藏
分享
点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# OC/开奖 #
196897次浏览 1342人参与
# 材料转码还有必要吗? #
31740次浏览 148人参与
# 百度秋招 #
52678次浏览 389人参与
# 你面试时吹过最大的牛 #
244次浏览 1人参与
# 实习学到最有价值的工作习惯 #
41131次浏览 362人参与
# 蚂蚁求职进展汇总 #
132846次浏览 1208人参与
# 腾讯音乐秋招 #
431866次浏览 4779人参与
# 为了秋招你都做了哪些准备? #
25584次浏览 497人参与
# 滴滴求职进展汇总 #
278167次浏览 2367人参与
# 你知道哪些职场黑话? #
64422次浏览 445人参与
# 材料人,你最希望上岸的是? #
12927次浏览 58人参与
# 哪些行业值得去? #
10783次浏览 63人参与
# 那些年,我收到的‘奇葩’回复 #
29169次浏览 175人参与
# 牛客十周岁生日快乐 #
185822次浏览 1829人参与
# 秋招投简历越早越好吗 #
99431次浏览 839人参与
# 实习需要主动找活干吗? #
56123次浏览 297人参与
# 秋招你经历过哪些无语的事 #
26037次浏览 256人参与
# 你今年的保底offer是哪家 #
144904次浏览 620人参与
# 校招薪资来揭秘 #
95161次浏览 594人参与
# 2022毕业即失业取暖地 #
121245次浏览 710人参与
# CVTE求职进展汇总 #
26286次浏览 327人参与
# 双非本科的出路是什么? #
178523次浏览 1456人参与

