ZOJ 3681E

版权声明:本文为博主原创文章。未经博主同意不得转载。

https://blog.csdn.net/opm777/article/details/25726221

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 3
12 5

Sample Output

Yes
3
No
6

题意: 题意有点难表述,有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
%d
",ans);
        else
            printf("Yes
%d
",ans);
    }
    return 0;
}

/*
4 3
12 5
*/


原文地址:https://www.cnblogs.com/ldxsuanfa/p/10883234.html