ural 1090 In the Army Now

http://acm.timus.ru/problem.aspx?space=1&num=1090

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #define maxn 20000
 5 using namespace std;
 6 
 7 int c[maxn],n,a[maxn];
 8 int lowbit(int x)
 9 {
10     return x&(-x);
11 }
12 
13 void add(int pos)
14 {
15     while(pos<=n)
16     {
17         c[pos]++;
18         pos+=lowbit(pos);
19     }
20 }
21 
22 int sum1(int pos)
23 {
24     int sum=0;
25     while(pos>0)
26     {
27         sum+=c[pos];
28         pos-=lowbit(pos);
29     }
30     return sum;
31 }
32 
33 int main()
34 {
35     int m;
36     scanf("%d%d",&n,&m);
37     int max1=-1,x;
38     for(int i=1; i<=m; i++)
39     {
40         memset(c,0,sizeof(c));
41         for(int j=1; j<=n; j++)
42         {
43             scanf("%d",&a[j]);
44         }
45         int s=0;
46         for(int j=n; j>=1; j--)
47         {
48             add(a[j]);
49            s+=sum1(a[j]-1);
50         }
51         if(s>max1){max1=s; x=i;}
52     }
53     printf("%d\n",x);
54     return 0;
55 }
View Code

 

posted @ 2014-03-21 17:17  null1019  阅读(112)  评论(0编辑  收藏  举报