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

 

转载于:https://www.cnblogs.com/fanminghui/p/3616325.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值