scau 10692 XYM-入门之道
2015-12-23 12:50
351 查看
题目:http://paste.ubuntu.com/14157516/
思路:判断一个西瓜,看看能不能直接吃完,如果能,就吃了。但是:如果不能,就要分成两半,就这样分割,不用以为要用到n维数组,用一个一维数组就够了,利用队列的特点,把分割了的入队,然后一直遍历整个队列。
思路:判断一个西瓜,看看能不能直接吃完,如果能,就吃了。但是:如果不能,就要分成两半,就这样分割,不用以为要用到n维数组,用一个一维数组就够了,利用队列的特点,把分割了的入队,然后一直遍历整个队列。
#include <stdio.h> #include <stdlib.h> void work() { int n,k; int que[100000]={0}; int head,tail; int i_count=0; head=tail=1; scanf ("%d%d",&n,&k); que[tail++]=n; while (head<tail) { if (que[head]<=k) { i_count++; head++; } else { if (que[head]%2==0) { que[tail++]=que[head]/2; que[tail++]=que[head]/2; head++; } else { que[tail++]=que[head]/2; que[tail++]=que[head]/2+1; head++; } } } printf ("%d\n",i_count); return ; } int main() { int t; scanf ("%d",&t); while (t--) { work(); } return 0; }
相关文章推荐
- 在安卓上使用Goldendict 查字典
- JSONArray使用
- Calendar用法
- OSGI环境下的一个错误:javax.xml.bind.JAXBException: ClassCastException
- Experimental CBIR Systems 基于内容的图像检索系统
- 6月英语
- 兼容所有浏览器的JQuery zClip插件实现复制到剪贴板功能
- CBIR: Texture Features 基于内容的图像检索:纹理特征
- [多线程之二]-NSOperation练习
- golang的各种数据格式的互相转换
- Android对话框 - Dialog
- golang 的编译安装以及supervisord部署
- CBIR: Colour Features 基于内容的图像检索:颜色特征
- 耿建玲视频总结
- GIT常用命令整理
- IOS学习笔记之UISwitch
- Win10数字签名错误/winload.exe 错误解决办法
- QBE and Content Representation 基于图例检索和内容表示
- leetcode刷题日记——Number of 1 Bits
- 2015年Android 开发有哪些新技术出现