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 ...
随机推荐
- java Activiti6.0 后台 框架 spring5 SSM 工作流引擎 审批流程
1.模型管理 :web在线流程设计器.预览流程xml.导出xml.部署流程 2.流程管理 :导入导出流程资源文件.查看流程图.根据流程实例反射出流程模型.激活挂起 3.运行中流程:查看流程信息.当前任 ...
- swiper插件在ie浏览器无反应,解决办法
在写pc端页面时,用swiper插件发现在ie中用不了,百度下说是swiper从3以后向手机端发展,所以在pc端无响应.后来了解到,swiper3是专门针对移动端写的.如果想兼容IE8的话,应该引入s ...
- 在Intellij上开发项目发布到tomcat时,同一个局域网内的其他机子访问不到自己电脑上tomcat中的项目,只能本机访问
在Intellij上开发项目发布到tomcat时,同一个局域网内的其他机子访问不到自己电脑上tomcat中的项目,只能本机访问 问题描述:在Intellij上开发项目发布到tomcat时,同一个局域网 ...
- 屏幕坐标点转UGUI坐标【包含屏幕适配】
using UnityEngine; public class ScreenToUI : MonoBehaviour { public const float UI_Width = 1366f; pu ...
- 数据库_PXC群集与存储引擎
1. PXC介绍与群集搭建; 2.数据存储引擎. 一, PXC介绍 1.介绍 PXC(Percona XtraDB Cluster)基于Galara的一台开源软件,应用于解决mysql的高可用集群问题 ...
- Vue-native绑定原生事件
首先介绍一下是什么意思: 意思就是当你给一个vue组件绑定事件时候,要加上native!如果是普通的html元素!就不需要 <div id = "app"> <m ...
- 微信小程序swiper组件实现图片宽度自适应
wxml 代码: <!--pages/swipe/swipe.wxml--> <view> <swiper circular="true" indic ...
- Codeforces 958C3 - Encryption (hard) 区间dp+抽屉原理
转自:http://www.cnblogs.com/widsom/p/8863005.html 题目大意: 比起Encryption 中级版,把n的范围扩大到 500000,k,p范围都在100以内, ...
- 我们为什么选择Ceph来建立块存储
我们为什么选择Ceph来建立块存储?国内知名黑客组织东方联盟是这样回答的,卷管理器的大小和增长受到管理程序的驱动器补充的限制,与其他Droplet共享.一旦Droplet被摧毁,储存就会被释放.术语“ ...
- Testng的使用总结(内容待持续更新)
testng 6.8使用多线程时,在pom的surefire插件始终无效 -->升级testng版本,在6.8版本中无任何提示的 如何调用自定义的报告的 -->在testng中,有个IRe ...