HDU 5500 Reorder the Books
2017-11-08 20:34
288 查看
http://acm.hdu.edu.cn/showproblem.php?pid=5500
思路
从最大的数向上找,如果发现一个连续比他小的数的位置在他上面,说明发现了一个不用扔的书,ans–
代码
思路
从最大的数向上找,如果发现一个连续比他小的数的位置在他上面,说明发现了一个不用扔的书,ans–
代码
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> using namespace std; int t,n,ans,maxn,pos; int num[1000010]; int main() { scanf("%d",&t); for(int i=1;i<=t;i++) { maxn=-1e9+7; scanf("%d",&n); ans=n-1; for(int i=1;i<=n;i++) { scanf("%d",&num[i]); if(num[i]>maxn) { maxn=num[i]; pos=i; } } for(int i=pos-1;i>=1;i--) { if(num[i]==ans)//比较巧 ans--; } printf("%d\n",ans);//退格键救不了回车 } return 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
- Reorder the Books hdu 5500 贪心
- Reorder the Books-HDU-5500-BC59div2
- HDU 5500 Reorder the Books(贪心+思维)
- hdu 5500 Reorder the Books 【BestCoder Round #59 (div.2) 第二题】
- 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(贪心)
- hdu 5500 Reorder the Books【贪心】【思维】
- hdu 5500 Reorder the books 思维
- hdu 5500 Reorder the books
- HDU 5500 Reorder the Books(O(n)的复杂度就够了)——BestCoder Round #59(div.1 div.2)