HDU 5500 Reorder the Books(思维题,很巧妙)
来源:互联网 发布:java微信授权直接登陆 编辑:程序博客网 时间:2024/05/29 19:59
题目地址:点击打开链接
题意:给你一堆书,每个书有一个代号,每次抽一本书放到最上面,问最少移动多少次,可以把书变的有序,即最上面的书的代号最小,最下面的书的代号最大
思路:从标号最大数从后往前扫一遍就行,扫到最后就是要搬的次数,因为这些标号大的书可以不动,把他们中间的书抽走就行,而把这些标号大的书放到前面只会浪费次数
AC代码:
#include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <map>#include <cstring>#include <climits>#include <cmath>#include <cctype>using namespace std;int a[20];int main(){ int i; int t,n; scanf("%d",&t); while(t--) { scanf("%d",&n); for(i=0; i<n; i++) { scanf("%d",&a[i]); } for(i=n-1; i>=0; i--) { if(a[i] == n) { n = n - 1; } } printf("%d\n",n); } return 0;}
0 0
- HDU 5500 Reorder the Books(思维题,很巧妙)
- hdu 5500 Reorder the Books【贪心】【思维】
- hdu 5500 Reorder the books 思维
- HDU 5500 Reorder the Books 思维分析题
- HDU 5500 Reorder the Books(贪心+思维)
- HDU 5500 Reorder the Books(模拟)
- HDU 5500 Reorder the Books (规律)
- hdu 5500 Reorder the Books(规律题)
- HDU 5500 Reorder the Books
- HDU 5500 Reorder the Books
- hdu 5500 Reorder the books
- hdu 5500 Reorder the Books
- HDU 5500 Reorder the Books
- hdu 5500 Reorder the Books
- HDU 5500 Reorder the Books
- Reorder the Books HDU - 5500
- HDU 5500 Reorder the Books
- HDU 5500 Reorder the Books
- csr 蓝牙
- docker安装gitlab
- python----小数点精度控制round()
- 模型Bean:Model Bean
- How to check a static library is built contain bitcode?
- HDU 5500 Reorder the Books(思维题,很巧妙)
- linux 抓包 tcpdump
- log4j:WARN No appenders could be found for logger
- 开源静态分析工具androguard体验(一) (二)
- Java 多线程 并发编程
- 1441 士兵的数字游戏
- Android 性能测试_Monkey 实践
- 关于事务的简单理解
- Linux信号(signal) 机制分析