• codeforces FF div2


    A:

     1 // File Name: a.cpp
     2 // Author: darkdream
     3 // Created Time: 2014年07月13日 星期日 20时47分08秒
     4 
     5 #include<vector>
     6 #include<list>
     7 #include<map>
     8 #include<set>
     9 #include<deque>
    10 #include<stack>
    11 #include<bitset>
    12 #include<algorithm>
    13 #include<functional>
    14 #include<numeric>
    15 #include<utility>
    16 #include<sstream>
    17 #include<iostream>
    18 #include<iomanip>
    19 #include<cstdio>
    20 #include<cmath>
    21 #include<cstdlib>
    22 #include<cstring>
    23 #include<ctime>
    24 #include<climits>
    25 #include<queue>
    26 
    27 using namespace std;
    28 int hs[1000];
    29 int a[1000];
    30 int main(){
    31    int ok = -1; 
    32    int n , m ; 
    33    memset(hs,0,sizeof(hs));
    34    scanf("%d %d",&m,&n);
    35    for(int i =1 ;i <= n;i  ++)
    36    {
    37       scanf("%d",&a[i]);
    38    }
    39    for(int i = 1;i <= n;i ++){
    40       if(hs[a[i]% m] == 1)
    41       {
    42         ok = i;
    43         break;
    44       }else hs[a[i]%m] = 1; 
    45    }
    46    printf("%d
    ",ok);
    47 return 0;
    48 }
    View Code

    B:

     1 // File Name: b.cpp
     2 // Author: darkdream
     3 // Created Time: 2014年07月13日 星期日 20时47分12秒
     4 
     5 #include<vector>
     6 #include<list>
     7 #include<map>
     8 #include<set>
     9 #include<deque>
    10 #include<stack>
    11 #include<bitset>
    12 #include<algorithm>
    13 #include<functional>
    14 #include<numeric>
    15 #include<utility>
    16 #include<sstream>
    17 #include<iostream>
    18 #include<iomanip>
    19 #include<cstdio>
    20 #include<cmath>
    21 #include<cstdlib>
    22 #include<cstring>
    23 #include<ctime>
    24 #include<climits>
    25 #include<queue>
    26 
    27 using namespace std;
    28 struct node{
    29   char c ; 
    30   int v; 
    31 }p[1005];
    32 char str[1005];
    33 int a[30];
    34 bool cmp(struct node a ,struct node b)
    35 {
    36   return a.v < b.v;
    37 }
    38 int main(){
    39     scanf("%s",str);
    40     int len = strlen(str);
    41     for(int i =0 ;i < len ;i ++)
    42     {
    43       p[i].c = str[i];
    44     }
    45     int k ; 
    46     scanf("%d",&k);
    47     int max = 0 ; 
    48     for(int i =0;i < 26 ;i++)
    49     {   scanf("%d",&a[i]);
    50        if(a[i] > max)
    51            max = a[i];
    52     }
    53     long long  sum = 0 ; 
    54     for(int i = 0 ;i < len ;i ++)
    55     {
    56       sum += a[p[i].c -'a']*(i+1);
    57     }
    58     for(int i = len +1; i <= len +k ;i++)
    59     {
    60       sum += max * i ;
    61     }
    62     printf("%I64d
    ",sum);
    63 return 0;
    64 }
    View Code

    C:

    方法一:枚举

     1 // File Name: c1.cpp
     2 // Author: darkdream
     3 // Created Time: 2014年07月13日 星期日 21时42分30秒
     4 
     5 #include<vector>
     6 #include<list>
     7 #include<map>
     8 #include<set>
     9 #include<deque>
    10 #include<stack>
    11 #include<bitset>
    12 #include<algorithm>
    13 #include<functional>
    14 #include<numeric>
    15 #include<utility>
    16 #include<sstream>
    17 #include<iostream>
    18 #include<iomanip>
    19 #include<cstdio>
    20 #include<cmath>
    21 #include<cstdlib>
    22 #include<cstring>
    23 #include<ctime>
    24 #include<climits>
    25 #include<queue>
    26 
    27 using namespace std;
    28 int a[100005];
    29 int ans[100005];
    30 int last[100005];
    31 int n; 
    32 int main(){
    33    scanf("%d",&n);
    34    int t = 0;
    35    last[0] = 0 ;
    36    a[0] = -1000000 ; 
    37    int M = 0; 
    38    memset(last,0,sizeof(last));
    39    memset(ans,0,sizeof(ans));
    40    for(int i =1 ;i <= n;i ++)
    41    {
    42        scanf("%d",&a[i]);
    43        if(a[i] <= a[i-1])
    44        {  
    45           last[i] = 1;
    46           ans[t] = i -1;
    47           t = i;
    48        }else{
    49          last[i] = last[i-1] +1;
    50        }
    51       M = max(last[i],M);
    52    }
    53    if(M != n)
    54        M ++;
    55   // printf("%d
    ",M);
    56    ans[t] = n; 
    57    ans[1] = 1;
    58   // for(int i =1 ;i <= n;i ++)
    59     //  printf("%d ",ans[i]);
    60    for(int i = 1;i <= n;i ++)
    61    {
    62       if(ans[i])
    63       {
    64           int temp = a[i-1] + 1;
    65           if(a[i+1] > temp)
    66           {
    67             M = max(M,ans[i]-i+1 +last[i-1]);
    68           }else{
    69             M = max(M,last[i-1] +1);
    70           }
    71       }
    72       if(ans[i+1])
    73       {
    74          int temp = a[i-1] + 1;
    75          if(a[i+1] > temp)
    76          {
    77            M = max(M,last[i] + last[ans[i+1]]);
    78          }   
    79       }
    80    }
    81    printf("%d
    ",M);
    82 return 0;
    83 }
    View Cod枚举e

    方法二:DP

     1 // File Name: c1.cpp
     2 // Author: darkdream
     3 // Created Time: 2014年07月13日 星期日 21时42分30秒
     4 
     5 #include<vector>
     6 #include<list>
     7 #include<map>
     8 #include<set>
     9 #include<deque>
    10 #include<stack>
    11 #include<bitset>
    12 #include<algorithm>
    13 #include<functional>
    14 #include<numeric>
    15 #include<utility>
    16 #include<sstream>
    17 #include<iostream>
    18 #include<iomanip>
    19 #include<cstdio>
    20 #include<cmath>
    21 #include<cstdlib>
    22 #include<cstring>
    23 #include<ctime>
    24 #include<climits>
    25 #include<queue>
    26 
    27 using namespace std;
    28 int a[1000005];
    29 int ans[100005];
    30 int last[100005];
    31 int n; 
    32 int main(){
    33    scanf("%d",&n);
    34    int t = 0;
    35    last[0] = 0 ;
    36    a[0] = -100 ; 
    37    int M = (n == 1? 1:2); 
    38    memset(last,0,sizeof(last));
    39    memset(ans,0,sizeof(ans));
    40    for(int i =1 ;i <= n;i ++)
    41    {
    42        scanf("%d",&a[i]);
    43        if(a[i] <= a[i-1])
    44        {  
    45           last[i] = 1;
    46           ans[t] = i -1;
    47           t = i;
    48        }else{
    49          last[i] = last[i-1] +1;
    50        }
    51       M = max(last[i],M);
    52    }
    53    ans[t] = n; 
    54    ans[1] = 1;
    55  //  for(int i =1 ;i <= n;i ++)
    56 //     printf("%d ",ans[i]);
    57    for(int i = 1;i <= n;i ++)
    58    {
    59       if(ans[i])
    60       {
    61           int temp = a[i-1] + 1;
    62           if(a[i+1] > temp)
    63           {
    64             M = max(M,ans[i]-i+1 +last[i-1]);
    65           }else{
    66             M = max(M,last[i-1] +1);
    67           }
    68       }
    69       if(ans[i+1])
    70       {
    71          int temp = a[i-1] + 1;
    72          if(a[i+1] > temp)
    73          {
    74            M = max(M,last[i] + last[ans[i+1]]);
    75          }   
    76       }
    77    }
    78    printf("%d
    ",M);
    79 return 0;
    80 }
    View Code

    D:

    可以发现答案与顺序无关

    优先队列处理

     1 // File Name: e.cpp
     2 // Author: darkdream
     3 // Created Time: 2014年07月14日 星期一 19时51分54秒
     4 
     5 #include<vector>
     6 #include<list>
     7 #include<map>
     8 #include<set>
     9 #include<deque>
    10 #include<stack>
    11 #include<bitset>
    12 #include<algorithm>
    13 #include<functional>
    14 #include<numeric>
    15 #include<utility>
    16 #include<sstream>
    17 #include<iostream>
    18 #include<iomanip>
    19 #include<cstdio>
    20 #include<cmath>
    21 #include<cstdlib>
    22 #include<cstring>
    23 #include<ctime>
    24 #include<climits>
    25 #include<queue>
    26 #define LL long long 
    27 using namespace std;
    28 LL n , m, k, p ; 
    29 struct cmp1{
    30     bool operator()(LL x, LL y)
    31     {
    32         return x < y ; 
    33     }
    34 };
    35 priority_queue<LL,vector<LL>,cmp1>q;
    36 priority_queue<LL,vector<LL>,cmp1>q1;
    37 
    38 LL sumh[1005];
    39 LL suml[1005];
    40 long long  dp[1000005][3];
    41 int main(){  
    42     scanf("%I64d %I64d %I64d %I64d",&n,&m,&k,&p);
    43     memset(sumh,0,sizeof(sumh));
    44     memset(suml,0,sizeof(suml));
    45     memset(dp,0,sizeof(dp))    ;
    46     LL  temp = 0 ; 
    47     for(LL i = 1;i <= n; i ++)
    48         for(LL j = 1;j <= m;j ++)
    49         {
    50             scanf("%I64d",&temp) ;
    51             sumh[i] += temp;
    52             suml[j] += temp;
    53         }
    54 
    55     for(LL i = 1;i<= n;i ++)
    56     {
    57        q.push(sumh[i]);
    58     }
    59 
    60     for(LL i = 1;i<= m;i ++)
    61     {
    62        q1.push(suml[i]);
    63     }
    64     long long t;    
    65     for(LL i = 1;i <= k;i ++)
    66     {
    67         t = q.top();
    68         q.pop();
    69         dp[i][1] = dp[i-1][1] + t;
    70         q.push(t - m*p);
    71     }
    72 //    printf("****
    ");
    73     for(LL i = 1;i <= k;i ++)
    74     {
    75         t = q1.top();    
    76         q1.pop();
    77         dp[i][2] = dp[i-1][2] + t;
    78         q1.push(t - n*p);
    79     }
    80 //    printf("****
    ");
    81 /*    for(LL i = 1;i <= 2;i ++)
    82     {
    83        for(LL j = 0;j <= k ;j ++)
    84            printf("%I64d ",dp[j][i]);
    85        printf("
    ");
    86     }*/
    87     LL ans = - 1e17;
    88     for(LL i= 0;i <= k;i ++)
    89     {
    90         ans = max(ans,dp[i][1]+ dp[k-i][2] - i*(k-i)*p);
    91     }
    92     printf("%I64d
    ",ans);
    93     return 0;
    94 }
    View Code
    没有梦想,何谈远方
  • 相关阅读:
    08day 操作命令以及目录结构
    换工作
    json转为字典
    快速排序
    冒泡排序
    python函数-生成器
    关键字global
    函数的定义和参数调用
    count()函数与center()函数
    python字符串常用函数:strip()
  • 原文地址:https://www.cnblogs.com/zyue/p/3843532.html
Copyright © 2020-2023  润新知