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

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\n%d\n",ans);
else
printf("Yes\n%d\n",ans);
}
return 0;
} /*
4 3
12 5
*/

ZOJ 3681E - Cup 2(记忆化dfs)不好读的更多相关文章

  1. 从DFS到记忆化DFS到动态规划

    什么是动态规划? 动态规划(Dynamic Programming)是通过组合子问题的解来解决问题的.动态规划是用于求解包含重叠子问题的最优化问题的方法.其基本思想是,将原问题分解为相似的子问题.在求 ...

  2. 【poj3252】 Round Numbers (数位DP+记忆化DFS)

    题目大意:给你一个区间$[l,r]$,求在该区间内有多少整数在二进制下$0$的数量$≥1$的数量.数据范围$1≤l,r≤2*10^{9}$. 第一次用记忆化dfs写数位dp,感觉神清气爽~(原谅我这个 ...

  3. HDU1978How Many Ways 记忆化dfs+dp

    /*记忆化dfs+dp dp[i][j]代表达到这个点的所有路的条数,那么所有到达终点的路的总数就是这dp[1][1]加上所有他所能到达的点的 所有路的总数 */ #include<stdio. ...

  4. 滑雪 矩阵中的最长上升路径 /// 记忆化DFS || DP oj22919

    大致题意: Description 难怪Michael喜欢滑雪,因为滑雪确实很刺激.为了获得加速度,滑雪道必须向下倾斜,而且当滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道在一 ...

  5. *HDU1142 最短路+记忆化dfs

    A Walk Through the Forest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...

  6. HDU ACM 1078 FatMouse and Cheese 记忆化+DFS

    题意:FatMouse在一个N*N方格上找吃的,每一个点(x,y)有一些吃的,FatMouse从(0,0)的出发去找吃的.每次最多走k步,他走过的位置能够吃掉吃的.保证吃的数量在0-100.规定他仅仅 ...

  7. 洛谷 P3953 逛公园【spfa+记忆化dfs+bfs】

    spfa预处理出最短路数组dis,然后反向建边bfs出ok[u]表示u能到n点 然后发现有0环的话时候有inf解的,先dfs找0环判断即可 然后dfs,设状态f[u][v]为到u点,还可以跑最短路+v ...

  8. 2014 Super Training #9 C E - Cup 2 --记忆化搜索

    原题:ZOJ 3681 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3681 题意:给一个m,n,m表示m个人,可以把m个 ...

  9. HDU3709:Balanced Number(数位DP+记忆化DFS)

    Problem Description A balanced number is a non-negative integer that can be balanced if a pivot is p ...

随机推荐

  1. Java笔试题-List l = new List()

    前言: 最近遇到的一道很基础的题,有时候大家可能离开了编译器就不行了. import java.util.List; /** * * @author catchegg * create date: 2 ...

  2. 微信小程序(6)--获取屏幕宽度及弹窗滚动与页面滚动冲突

    1.获取屏幕宽度,并赋值给view <view class="ships-img" style="height:{{windowWidth}}px;"&g ...

  3. vue,一路走来(9)--聊天窗口

    闲暇时间,介绍一下我做一个聊天窗口的心得.如图: 首先要考虑的是得判断出是自己的信息还是对方发来的信息,给出如图的布局,切换不同的类. <li class="clearfix" ...

  4. React 和 Vue 到底谁更牛?听听尤雨溪怎么说

    React 和 Vue 到底谁更牛?听听尤雨溪怎么说 知乎上近日有人发起了一个 “react 是不是比 vue 牛皮,为什么?” 的问题,再度引发一场关于前端框架谁更牛的口水战,评论里可以说是撕得不可 ...

  5. java api 调用es集群(1.7版本)

    public static void main(String[] args) { Settings settings = ImmutableSettings.settingsBuilder() // ...

  6. LINUX Mysql5.6.19 安装

    1.需要扩展安装 yum -y install make bison gcc-c++ cmake ncurses ncurses-devel 2.下载Mysql5.6.19 wget ftp://mi ...

  7. HTML5知识点总结(一)

    最近在复习前端的基础知识,在这里做一个总结,这是HTML5篇. 新特性 取消了过时的显示效果标记<font></font>和<center></center& ...

  8. Es学习第八课, Filter、bool和范围查询

    Filter过滤查询 filter是不计算相关性的,同时可以缓存.因此filter速度快于query. 我们先在kibana上先添加数据来做准备 POST /lib4/items/_bulk { &q ...

  9. RIME-使用小心得

    从4月份我才接触到RIME输入法,当时的感觉上相见恨晚的,现在感觉也不错,时至今日,想写点东西,也算是小感触吧. RIME称为中州韵输入法引擎,是开放源代码的输入法软件,其主页是http://rime ...

  10. oracle中分页函数写法

    1.常见的分页查询语句: 查询21到40条之间的数据:SELECT *FROM (select UI.*,ROWNUM RN FROM (select * from user_info) AWHERE ...