ZOJ 3681E - Cup 2(记忆化dfs)不好读
来源:互联网 发布:sql数据库文件恢复 编辑:程序博客网 时间:2024/04/30 05:27
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
#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*/
- ZOJ 3681E - Cup 2(记忆化dfs)不好读
- [记忆化搜索] zoj 3681 E - Cup 2
- ZOJ-3681 E - Cup 2 dfs
- ZOJ 3681 E - Cup 2
- ZOJ 3681 E - Cup 2
- ZOJ-3805---Machine (记忆化dfs)
- ZOJ 3682 E - Cup 3
- ZOJ 3682 E - Cup 3
- [dp] zoj 3682 E - Cup 3
- ZOJ-3682-E - Cup 3【dp】
- zoj 3640 Help Me Escape 概率dp+dfs记忆化
- ZOJ 3640 Help Me Escape 概率DP 记忆化DFS
- [ZOJ 3682] E - Cup 3 (背包DP计数 + 滚动数组)
- ZOJ-3682 E - Cup 3 DP+01背包
- uva10306 - e-Coins(记忆化搜索)
- 【DFS(记忆化)】hdu 1501 Zipper
- POJ 1088--滑雪【DFS(记忆化)】
- POJ 1088 滑雪(DFS+记忆化)
- 误删文件后还能找回吗
- List
- BZOJ [Spoj 2021]Moving Pebbles(隐藏题)
- 初窥Quartz
- CDMA 猫用AT命令发中文短信(C#)
- ZOJ 3681E - Cup 2(记忆化dfs)不好读
- 辗转时光
- Simple statistics for SharePoint
- ssh 一些说明
- STM32 系统时钟设置
- 分布式数据库 HBase
- 68 Java 匿名内部类——抽象类
- hdu4570 Multi-bit Trie
- 弗洛伊德算法