ZOJ 3681E - Cup 2(记忆化dfs)不好读

来源:互联网 发布:sql数据库文件恢复 编辑:程序博客网 时间:2024/04/30 05:27
E - Cup 2

Time Limit: 2 Seconds      Memory Limit: 65536 KB

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 M fans 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 312 5

Sample Output

Yes3No6

题意: 题意有点难表述,有n个人他们分在一组,如果其中支持意大利队的人多于一半,
那么这组就是一个合法组,同时我们可以说这n个人都支持意大利队。如果这n个人所在
的组是非法组,那么你可以把这组继续拆分。比如拆成m组,如果这m组中多于一半是
合法组那么这n个人所在组依然算是合法组。题目的规则就是这样。问:给你M个人其
中有N个意大利队球迷,能不能满足条件,使得我们可以说这M个人都是支持意大利的
,并输出最少需要多少个意大利球迷在这M个人中。转载自:left_hand

题目意思看了很久,开始看错了,写了一个暴利程序。发现有些情况不能表达。就是
不断分组,然后在分组里面找满足条件的最小值,记忆化搜索。不过开始开数组老是
说数组越界,开到100w,还是提示数组越界。

实在无语了,开了map..

题目地址:E - Cup 2

AC代码:
#include<iostream>#include<cstdio>#include<iostream>#include<cmath>#include<cstring>#include<map>using namespace std;//const int maxn=1000005;//int visi[maxn];map <int,int> mq;int dfs(int x){    if(mq.count(x)>0)        return mq[x];    int mi=x/2+1;    for(int k=2;k<=sqrt(x+0.5);k++)    {        if(x%k==0)        {            mi=min(mi,(k/2+1)*dfs(x/k));            mi=min(mi,(x/k/2+1)*dfs(k));        }    }    mq[x]=mi;    return mi;}int main(){    int m,n;    while(cin>>m>>n)    {        mq.clear();        //memset(visi,0,sizeof(visi));        int ans=dfs(m);        //int ans=0;        if(ans>n)            printf("No\n%d\n",ans);        else            printf("Yes\n%d\n",ans);    }    return 0;}/*4 312 5*/


0 0
原创粉丝点击