zoukankan      html  css  js  c++  java
  • “玲珑杯”ACM比赛 Round #1 题解

    A:DESCRIPTION
    Eric has an array of integers a1,a2,...,ana1,a2,...,an. Every time, he can choose a contiguous subsequence of length kk and increase every integer in the contiguous subsequence by 11. He wants the minimum value of the array is at least mm. Help him find the minimum number of operations needed.
    INPUT
    There are multiple test cases. The first line of input contains an integer TT, indicating the number of test cases. For each test case: The first line contains three integers nn, mm and kk (1n105,1kn,1m104)(1≤n≤105,1≤k≤n,1≤m≤104). The second line contains nn integers a1,a2,...,ana1,a2,...,an (1ai104)(1≤ai≤104).
    OUTPUT
    For each test case, output an integer denoting the minimum number of operations needed.
    SAMPLE INPUT
    3
    2 2 2
    1 1
    5 1 4
    1 2 3 4 5
    4 10 3
    1 2 3 4
    SAMPLE OUTPUT
    1
    0
    15

    题目链接:http://ifrog.cc/acm/problem/1014?contest=1001&no=0

    *************************************

    错误代码:(貌似错的还挺离谱,没办法,太弱了)

     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<math.h>
     4 #include<queue>
     5 #include<algorithm>
     6 #include<time.h>
     7 #include<stack>
     8 using namespace std;
     9 #define N 120000
    10 #define INF 0x3f3f3f3f
    11 
    12 int a[N];
    13 
    14 int main()
    15 {
    16     int T,n,m,k,i;
    17 
    18     scanf("%d", &T);
    19 
    20     while(T--)
    21     {
    22         scanf("%d %d %d", &n,&m,&k);
    23 
    24         for(i=0; i<n; i++)
    25             scanf("%d", &a[i]);
    26 
    27         sort(a,a+n);
    28 
    29         int i=0,sum=0;
    30         while(i<n)
    31         {
    32             if(m-a[i]>0)
    33                 sum+=m-a[i];
    34             i+=k;
    35         }
    36         printf("%d
    ",sum);
    37     }
    38 
    39     return 0;
    40 }

     比赛全部的题从链接里面找,有兴趣的可以自己做做看。下面是全部题解:

     

  • 相关阅读:
    hdu6761 Mininum Index // lyndon分解 + duval贪心 + 秦九韶算法
    hdu6762 Mow // 半平面交 模拟 双端队列
    数据库增删改查操作
    移动端自动化概念
    范围查询和模糊查询
    软件测试技能要求总结
    继承
    luogu_P2024 [NOI2001]食物链
    luogu_P4092 [HEOI2016/TJOI2016]树
    luogu_P2887 [USACO07NOV]防晒霜Sunscreen
  • 原文地址:https://www.cnblogs.com/weiyuan/p/5790673.html
Copyright © 2011-2022 走看看