USACO2008 Roads Around The Farm /// queue oj23321
题目大意:
N (1 ≤ N ≤ 1,000,000,000)牛群在遇到岔路时,若能分为恰好相差 K (1 ≤ K ≤ 1000)的两路,则持续分裂(假设会一直遇到岔路),否则停止开始吃草。
* Line 1: Two space-separated integers: N and K
* Line 1: A single integer representing the number of groups of grazing cows
6 2
3
SAMPLE INPUT DETAILS:
There are 6 cows and the difference in group sizes is 2.
SAMPLE OUTPUT DETAILS:
There are 3 final groups (with 2, 1, and 3 cows in them).
6
/ \
2 4
/ \
1 3
一开始直接随着分裂记录结果 结果一直WA
看了题解才恍然 其实遍历完所有的结果
记录下 不符合继续分裂条件 的结果个数其实就是最后的答案
#include <bits/stdc++.h>
using namespace std; int main()
{
int n,k,cnt;
queue <int> q;
scanf("%d%d",&n,&k); while(!q.empty()) q.pop();
cnt=;
q.push(n); while(!q.empty())
{
int m=q.front();
if( m>k && (m-k)%== )
{
q.push((m-k)/);
q.push((m-k)/+k);
}
else cnt++;
q.pop();
}
printf("%d\n",cnt); return ;
}
USACO2008 Roads Around The Farm /// queue oj23321的更多相关文章
- BZOJ1621: [Usaco2008 Open]Roads Around The Farm分岔路口
1621: [Usaco2008 Open]Roads Around The Farm分岔路口 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 521 S ...
- BZOJ 1621: [Usaco2008 Open]Roads Around The Farm分岔路口
题目 1621: [Usaco2008 Open]Roads Around The Farm分岔路口 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 56 ...
- BZOJ 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场
题目 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 491 S ...
- 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场
1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 498 Solve ...
- bzoj1621 / P2907 [USACO08OPEN]农场周围的道路Roads Around The Farm
P2907 [USACO08OPEN]农场周围的道路Roads Around The Farm 基础dfs,按题意递归即可. #include<iostream> #include< ...
- [Usaco2008 Open]Roads Around The Farm分岔路口[水题]
Description 约翰的N(1≤N≤1,000,000,000)只奶牛要出发去探索牧场四周的土地.她们将沿着一条路走,一直走到三岔路口(可以认为所有的路口都是这样的).这时候,这一群奶牛 ...
- 【BZOJ】1621: [Usaco2008 Open]Roads Around The Farm分岔路口(dfs)
http://www.lydsy.com/JudgeOnline/problem.php?id=1621 这题用笔推一下就懂了的.... 当2|(n-k)时,才能分,否则不能分. 那么dfs即可.. ...
- BZOJ 1621 [Usaco2008 Open]Roads Around The Farm分岔路口:分治 递归
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1621 题意: 约翰的N(1≤N≤1,000,000,000)只奶牛要出发去探索牧场四周的土 ...
- bzoj 1621: [Usaco2008 Open]Roads Around The Farm分岔路口【dfs】
模拟就行--讲道理这个时间复杂度为啥是对的??? #include<iostream> #include<cstdio> using namespace std; int k, ...
随机推荐
- 卿烨科技 Fireball
9人开发病毒感染超2亿电脑!Fireball病毒境外做案被举报 原标题:名校毕业生研发病毒年获利8000万 2.5亿台电脑感染 海淀网友协助民警追踪跨境黑客 高材生开公司研发病毒 一年获利8000 ...
- C语言指针函数和函数指针
#include <stdio.h> char *test(); void test1(); int main() { /********************************* ...
- BBS论坛 登录功能
四.登录功能 前端页面html代码: <!DOCTYPE html> <html lang="en"> <head> <meta char ...
- Tk1上搭建turtlebot环境
sudo apt-get install ros-indigo-turtlebot ros-indigo-turtlebot-apps ros-indigo-turtlebot-interaction ...
- AWS lambda DynamoDB api gateway之间的连接
创建角色 附加策略 AmazonDynamoDBFullAccess AWSLambdaDynamoDBExecutionRole 创建DynamoDB表 在表的项目中创建内容 this pipi 打 ...
- robotframework+python3+selenium之下拉框的选择---第五集
由于我没有找到option形式的,所以借鉴其他大神的博客内容,如下: 1.F12后看见下拉框的源码是<option xxx> 2.如果F12后看到的下拉源码是这样的: <div xx ...
- Vue.js 监听属性
demo <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf- ...
- 处理 vagrant Homestead 响应慢小记
环境 Homestead box: Homestead: v8.2.0 vagrant: 2.2.4 在Homestead中 安装nfs-kernel-server sudo apt-get inst ...
- C中为什么不能用==比较字符串?
通常的回答是,==比较的不是字符串的内容,它是在比较指针.或者说,==(或者!=)仅比较两个字符串的首地址,而不会比较字符串每个字符. 那其实接下来应该问的问题是,为什么会只比较首地址呢? 因为早期的 ...
- 暑期集训日志(Day6~Day17)
章·十七:2019-07-28:为谁辛苦为谁甜 ·昨日小结 颓爆了QAQ,昨天又垫底了. 最简单一道题弃疗的我直接被甩倒了总榜垫底…… 我……不想说啥…… 我是渣比. 我不能颓废了. 醒来啊麦克白! ...