码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 5122 (2014北京区域赛 K题)

时间:2015-10-01 11:31:57      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:

把一个序列按从小到大排序 要执行多少次操作

只需要从右往左统计,并且不断更新最小值,若当前数为最小值,则将最小值更新为当前数,否则sum+1

Sample Input
2
5
5 4 3 2 1
5
5 1 2 3 4

Sample Output
Case #1: 4
Case #2: 1

 

技术分享
 1 # include <iostream>
 2 # include <cstdio>
 3 # include <cstring>
 4 # include <algorithm>
 5 # include <string>
 6 # include <cmath>
 7 # include <queue>
 8 # include <list>
 9 # define LL long long
10 using namespace std ;
11 
12 const int INF=0x3f3f3f3f;
13 
14 int a[1000010] ;
15 
16 int main()
17 {
18     //freopen("in.txt","r",stdin) ;
19     int T ;
20     scanf("%d" , &T) ;
21     int Case = 0 ;
22     while(T--)
23     {
24         Case++ ;
25         int n , i , j;
26         scanf("%d" , &n) ;
27         for (i = 0 ; i < n ; i++)
28             scanf("%d" , &a[i]) ;
29         int sum = 0 ;
30         int MIN = INF ;
31         for (i = n-1 ; i >=0 ; i--)
32         {
33             if (a[i] < MIN)
34                 MIN = a[i] ;
35             else
36                 sum++ ;
37         }
38         printf("Case #%d: %d\n" , Case , sum) ;
39 
40 
41     }
42 
43     return 0 ;
44 }
View Code

 

hdu 5122 (2014北京区域赛 K题)

标签:

原文地址:http://www.cnblogs.com/-Buff-/p/4850734.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!