E - Cup 2 dfs记忆化搜索

博客围绕欧洲杯决赛,西班牙和意大利对决展开。重点提出在ZJU有M个球迷,N个支持意大利,作为支持意大利的学生会主席,探讨能否通过合理分组让所有M个球迷看似都支持意大利,还给出输入输出要求及示例。

Description

The European Cup final is coming. The past two World Cup winners, Spain and Italy, will contest the decider at Kiev's Olympic Stadium. Italy-Spain Euro final promises to be clash of polar opposites, so it's difficult to say which team will win.

Now there are M fans in ZJU, N of them support Italy. Suppose you are the president of the students' union and you support Italy. You can divide these M fans into s1 groups(Level 1). More than half of the group(Level 1) support Italy ,than you can say it seems all the Mfans support Italy. You can also divide each group(Level 1) into s2 groups(Level 2). More than half of the group(Level 2) support Italy ,than you can say this group(Level 1) support Italy. ... .You can also divide each group(Level i) into s(i+1) groups(Level i+1). More than half of the group(Level i+1) support Italy ,than you can say this group(Level i) support Italy. To be fair, every group(Level i) has the same number of person. Can you find an suitable way to arrange these N person so that all these M fans seem to support Italy.

Input

Mutiple test cases, process to the end of file.
Each case has a single line with two integer M , N (1<=M,N<=100000000).

Output

For each case:
The firt line output Yes if you can do the task or No for not. The second line output the minimum person you need.

Sample Input

4 3
12 5

Sample Output

Yes
3
No
6
***********************************************************************************************************************************************************
枚举所有的组,记忆化搜索
*********************************************************************************************************************************************************U*
 1 #include<iostream>
 2 #include<string>
 3 #include<cstring>
 4 #include<cmath>
 5 #include<cstdio>
 6 #include<map>
 7 using namespace std;
 8 map<int,int>ans;
 9 int n,m;
10 int dfs(int n)
11 {
12   int MIN=n/2+1;
13   int it;
14   if(ans.count(n))
15     return ans[n];
16   for(it=2;it*it<=n;it++)
17   {
18     if(n%it==0)//枚举所有的分组
19     {
20         MIN=min(MIN,((n/it)/2+1)*dfs(it));
21         MIN=min(MIN,(it/2+1)*dfs(n/it));
22     }
23   }
24   ans[n]=MIN;//分成对应的组,所需要的最小值
25   return MIN;
26 }
27 int main()
28 {
29     while(scanf("%d %d",&n,&m)!=EOF)
30     {
31         int  MIN=dfs(n);
32         if(MIN<=m)
33             puts("Yes");
34         else
35             puts("No");
36         printf("%d\n",MIN);
37     }
38     return 0;
39 }
View Code

 

转载于:https://www.cnblogs.com/sdau--codeants/p/3444324.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值