Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4829208

Browse files
committed
num-of-sweets
1 parent4acf097 commit4829208

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// https://practice.geeksforgeeks.org/contest-problem/number-of-sweets
2+
3+
#include<bits/stdc++.h>
4+
usingnamespacestd;
5+
6+
7+
vector<string>getDecision(int a ,int b)
8+
{
9+
vector<string> ans;
10+
while (a != b)
11+
{
12+
if (a > b)
13+
{
14+
a--;
15+
ans.push_back("eat");
16+
}
17+
else
18+
{
19+
// even b's
20+
if (b%2 ==0)
21+
{
22+
if (a <= b/2)
23+
{
24+
a *=2;
25+
ans.push_back("overflow");
26+
}
27+
else
28+
{
29+
a--;
30+
ans.push_back("eat");
31+
}
32+
}
33+
// odd b's
34+
else
35+
{
36+
if (a <= (b/2+1))
37+
{
38+
a *=2;
39+
ans.push_back("overflow");
40+
}
41+
else
42+
{
43+
a--;
44+
ans.push_back("eat");
45+
}
46+
}
47+
}
48+
}
49+
return ans;
50+
}
51+
52+
53+
intmain()
54+
{
55+
int t;
56+
cin>>t;
57+
while(t--)
58+
{
59+
60+
int m , n;
61+
cin>>m>>n;
62+
vector<string>ans;
63+
ans =getDecision(m,n);
64+
for(int i=0;i<ans.size();i++)
65+
cout<<ans[i]<<"";
66+
cout<<endl;
67+
68+
}
69+
return0;
70+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp