zoukankan      html  css  js  c++  java
  • 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
    ",x);
    54     return 0;
    55 }
    View Code
  • 相关阅读:
    Dll版本管理
    线程池ThreadPool
    关于sitemesh和freemark在struts2中的一些问题总结
    Google 怎么搜索
    android 设计模式
    android webview
    ios 基础数据类型
    android 常用
    android Handler vs Timer
    网站
  • 原文地址:https://www.cnblogs.com/fanminghui/p/3616325.html
Copyright © 2011-2022 走看看