ZOJ 3681E - Cup 2(记忆化dfs)不好读
版权声明:本文为博主原创文章。未经博主同意不得转载。
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个人所在
比方拆成m组,假设这m组中多于一半是
转载自:left_hand
发现有些情况不能表达。就是
只是開始开数组老是
#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)不好读的更多相关文章
- 从DFS到记忆化DFS到动态规划
什么是动态规划? 动态规划(Dynamic Programming)是通过组合子问题的解来解决问题的.动态规划是用于求解包含重叠子问题的最优化问题的方法.其基本思想是,将原问题分解为相似的子问题.在求 ...
- 【poj3252】 Round Numbers (数位DP+记忆化DFS)
题目大意:给你一个区间$[l,r]$,求在该区间内有多少整数在二进制下$0$的数量$≥1$的数量.数据范围$1≤l,r≤2*10^{9}$. 第一次用记忆化dfs写数位dp,感觉神清气爽~(原谅我这个 ...
- HDU1978How Many Ways 记忆化dfs+dp
/*记忆化dfs+dp dp[i][j]代表达到这个点的所有路的条数,那么所有到达终点的路的总数就是这dp[1][1]加上所有他所能到达的点的 所有路的总数 */ #include<stdio. ...
- 滑雪 矩阵中的最长上升路径 /// 记忆化DFS || DP oj22919
大致题意: Description 难怪Michael喜欢滑雪,因为滑雪确实很刺激.为了获得加速度,滑雪道必须向下倾斜,而且当滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道在一 ...
- *HDU1142 最短路+记忆化dfs
A Walk Through the Forest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...
- HDU ACM 1078 FatMouse and Cheese 记忆化+DFS
题意:FatMouse在一个N*N方格上找吃的,每一个点(x,y)有一些吃的,FatMouse从(0,0)的出发去找吃的.每次最多走k步,他走过的位置能够吃掉吃的.保证吃的数量在0-100.规定他仅仅 ...
- 洛谷 P3953 逛公园【spfa+记忆化dfs+bfs】
spfa预处理出最短路数组dis,然后反向建边bfs出ok[u]表示u能到n点 然后发现有0环的话时候有inf解的,先dfs找0环判断即可 然后dfs,设状态f[u][v]为到u点,还可以跑最短路+v ...
- 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个 ...
- HDU3709:Balanced Number(数位DP+记忆化DFS)
Problem Description A balanced number is a non-negative integer that can be balanced if a pivot is p ...
随机推荐
- 快速部署业务类为webapi服务
接着前一篇博文,将接口快速打包固定请求格式,不需要修改代码,可以自动完成接口调用,实际上就是生成了一个接口的代理类. 那么仅仅是接口请求代理,没有服务端怎么行?所以需要将实现接口的类部署为webapi ...
- 剑指offer学习--初级c++面试题
定义一个空的类型,里面没有任何成员函数和成员变量,对该类型求sizeof,得到的结果是多少? 答案是1.空类型中的实例中不包含任何信息,本来求sizeof应该是0,但是当我们声明该类型的实例的时候,他 ...
- https://blog.csdn.net/eguid_1/article/category/6270094
https://blog.csdn.net/eguid_1/article/category/6270094
- ssh 操作 esxi 基本命令
1.查看虚拟机: vim-cmd vmsvc/getallvms 会显示当前esxi上的虚拟机数量,没一个都有编号. 2.停用虚拟机:vim-cmd vmsvc/power.suspend + 之前命 ...
- 前端JSON添加
一. var _params={ "name": name, "sex": sex } //循环动态添加 for(v ...
- 8VC Venture Cup 2017 - Elimination Round - B
题目链接:http://codeforces.com/contest/755/problem/B 题意:给定PolandBall 和EnemyBall 这2个人要说的单词,然后每一回合轮到的人要说一个 ...
- pycharm 断点跟踪
F8 下一步 F7 step info F9 直接运行
- bootz to be continued
dmesgcat /proc/interrupts cat /proc/meminfocat /proc/cpuinfo top bootz 0x10000000 0x12000000 0x11000 ...
- bzoj2560 串珠子 状压DP
题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=2560 题解 大概是这类关于无向图的联通性计数的套路了. 一开始我想的是这样的,考虑容斥,那么就 ...
- Testng的使用总结(内容待持续更新)
testng 6.8使用多线程时,在pom的surefire插件始终无效 -->升级testng版本,在6.8版本中无任何提示的 如何调用自定义的报告的 -->在testng中,有个IRe ...