E - Cup 2

Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

Submit Status

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 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个人中。

思路: 对于n个人,我们只需求出最小的球迷数Minsgin和m比较下就能得出答案。而求Minsgin可以dfs记忆化搜一下,把n的所有可能分组情况遍历一遍。

AC代码:

 #include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<map>
using namespace std; map<int,int>kiss; int dfs(int n)
{
if(kiss.count(n)){//已经进行过计算,则直接返回值即可
return kiss[n];
}
int minsgin=n/+;//先初始化最小值,这应该是各种分法中最小值最大的一种分法
for(int i=;i*i<=n;i++){
if(n%i==){
minsgin=min(minsgin,(n/i/+)*dfs(i));//进行递归运算,分成n/i组,每组i个人
minsgin=min(minsgin,(i/+)*dfs(n/i));//分成i组,每组n/i个人;
}
}
kiss[n]=minsgin;//返回求出的最小值
return minsgin;
} int main()
{
int n;
while(scanf("%d",&n)==){//进行数据的输入
int m;
scanf("%d",&m);
int sgin=dfs(n);
if(sgin<=m){
printf("Yes\n%d\n",sgin);
}
else{
printf("No\n%d\n",sgin);
}
}
return ;
}

E - Cup 2(dfs)的更多相关文章

  1. LeetCode Subsets II (DFS)

    题意: 给一个集合,有n个可能相同的元素,求出所有的子集(包括空集,但是不能重复). 思路: 看这个就差不多了.LEETCODE SUBSETS (DFS) class Solution { publ ...

  2. LeetCode Subsets (DFS)

    题意: 给一个集合,有n个互不相同的元素,求出所有的子集(包括空集,但是不能重复). 思路: DFS方法:由于集合中的元素是不可能出现相同的,所以不用解决相同的元素而导致重复统计. class Sol ...

  3. HDU 2553 N皇后问题(dfs)

    N皇后问题 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description 在 ...

  4. 深搜(DFS)广搜(BFS)详解

    图的深搜与广搜 一.介绍: p { margin-bottom: 0.25cm; direction: ltr; line-height: 120%; text-align: justify; orp ...

  5. 【算法导论】图的深度优先搜索遍历(DFS)

    关于图的存储在上一篇文章中已经讲述,在这里不在赘述.下面我们介绍图的深度优先搜索遍历(DFS). 深度优先搜索遍历实在访问了顶点vi后,访问vi的一个邻接点vj:访问vj之后,又访问vj的一个邻接点, ...

  6. 深度优先搜索(DFS)与广度优先搜索(BFS)的Java实现

    1.基础部分 在图中实现最基本的操作之一就是搜索从一个指定顶点可以到达哪些顶点,比如从武汉出发的高铁可以到达哪些城市,一些城市可以直达,一些城市不能直达.现在有一份全国高铁模拟图,要从某个城市(顶点) ...

  7. 深度优先搜索(DFS)和广度优先搜索(BFS)

    深度优先搜索(DFS) 广度优先搜索(BFS) 1.介绍 广度优先搜索(BFS)是图的另一种遍历方式,与DFS相对,是以广度优先进行搜索.简言之就是先访问图的顶点,然后广度优先访问其邻接点,然后再依次 ...

  8. 图的 储存 深度优先(DFS)广度优先(BFS)遍历

    图遍历的概念: 从图中某顶点出发访遍图中每个顶点,且每个顶点仅访问一次,此过程称为图的遍历(Traversing Graph).图的遍历算法是求解图的连通性问题.拓扑排序和求关键路径等算法的基础.图的 ...

  9. 搜索——深度优先搜索(DFS)

    设想我们现在身处一个巨大的迷宫中,我们只能自己想办法走出去,下面是一种看上去很盲目但实际上会很有效的方法. 以当前所在位置为起点,沿着一条路向前走,当碰到岔道口时,选择其中一个岔路前进.如果选择的这个 ...

随机推荐

  1. JS获取ckeditor4.x里的值

    项目中有这样一个需求,使用ckeditor可以上传图片,需要在前端验证一下不可上传多于5张图片. 以下是查看源代码所看到的ckeditor里的值 <p>AAAAA</p> &l ...

  2. 删除重复&海量数据

    08. 删除重复&海量数据   重复数据,通常有两种:一是完全重复的记录,也就是所有字段的值都一样:二是部分字段值重复的记录. 一. 删除完全重复的记录完全重复的数据,通常是由于没有设置主键/ ...

  3. VirtualBox安装CentOS6.4(32bit)

    实验环境 Win7 64bit 目的: 实验VirtualBox安装CentOS6.4(32bit) 下载VirtualBox 地址: http://www.oracle.com/technetwor ...

  4. Iveely Search Engine 0.4.0 的发布

    千呼万唤始出来,Iveely Search Engine 0.4.0 的发布   经过无数个夜晚的奋战,以及无数个夜晚的失眠,Iveely Search Engine 0.4.0 终于熬出来了,这其中 ...

  5. Jquery EasyUI tabs处理

    一 获取选中的 Tab 1.   // 获取选中的 tab panel 和它的 tab 对象 2.  var pp = $('#tt').tabs('getSelected'); 3.  var ta ...

  6. TOGAF架构内容框架之架构交付物

    TOGAF架构内容框架之架构交付物 3. 架构交付物(Architecture Deliverables) 架构交付物是在整个架构开发方法循环过程中所产生或被使用的契约性且正规化的企业架构内容,因而其 ...

  7. 设计模式之 - 外观模式 (Facade design pattern)

    1. 模式意图:  为子系统中的一组接口提供一个一致的界面,Facade模式定义了一个高层接口,这个接口使得这一子系统更容易使用. 2. 结构 3. 工厂方法模式C#实现 using System; ...

  8. 如何调用在$(function(){ //内部函数代码 });

    这个文件主要完成如何调用在jquery内部定义的函数,主要有两种方法 法①: <script type="text/javascript"> $(function() ...

  9. 杭电OJ——1011 Starship Troopers(dfs + 树形dp)

    Starship Troopers Problem Description You, the leader of Starship Troopers, are sent to destroy a ba ...

  10. 异常分析:关于jsp页面使用jstl

    1.在jsp页面中使用如下代码加入jstl的支持 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/c ...