• A


     1 #include <cstdio>
     2 #include <cstring>
     3 #include <vector>
     4 #include <algorithm>
     5 #include <set>
     6 #include <iostream>
     7 using namespace std;
     8 const int MAX = 1e5+10;
     9 double a[MAX];
    10 int main() {
    11     int n,m,k;
    12     while(scanf("%d %d %d",&n,&k,&m)==3) {
    13         a[0]=0;
    14         for(int i=1;i<=n;i++) {
    15             cin>>a[i];
    16         }
    17         double res1=0,res2=0;
    18         double last1=-1,last2=-1;
    19         bool last=true;
    20         int x=max(k,m);
    21         for(int i=1;i<=n;i++) {
    22             res1+=a[i];
    23             res2+=a[i];
    24             if(i>=m) res1-=a[i-m];
    25             if(i>=k) res2-=a[i-k];
    26             if(i <= x){
    27                 if(i==1) {
    28                     printf("silent");
    29                 }
    30                 else {
    31                     printf(" silent");
    32                 }
    33                 last1=res1/m;
    34                 last2=res2/k;
    35                 continue;
    36             }
    37             if(i<x) {
    38                 if(i==1) {
    39                     printf("silent");
    40                 }
    41                 else {
    42                     printf(" silent");
    43                 }
    44                 continue;
    45             }
    46           //  printf("%lf %lf ",res2/k,res1/m);
    47             if(last1>=last2&&res1*k<res2*m) {
    48                 if(i==1) {
    49                     printf("buy");
    50                 }
    51                 else {
    52                     printf(" buy");
    53                 }
    54             }
    55             else if(last1<=last2&&res1*k>res2*m) {
    56                 if(i==1) {
    57                     printf("sell");
    58                 }
    59                 else {
    60                     printf(" sell");
    61                 }
    62             }
    63             else {
    64                 if(i==1) {
    65                     printf("silent");
    66                 }
    67                 else {
    68                     printf(" silent");
    69                 }
    70             }
    71             last1=res1/m;
    72             last2=res2/k;
    73         }
    74         printf(" ");
    75     }
    76 }
    View Code
  • 相关阅读:
    求字符串中最大的递增子序列
    分析函数改写自关联
    收集统计信息让SQL走正确的执行计划
    利用case when 减少表扫描次数
    利用查询提示优化SQL
    利用SQL进行推理
    查找字段连续相同的最大值
    优化有标量子查询的SQL
    将部分相同的多行记录转成一行多列
    .net 测试工具类
  • 原文地址:https://www.cnblogs.com/acvc/p/4419822.html
Copyright © 2020-2023  润新知