• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            hdu3434

            題目來源: http://acm.hdu.edu.cn/showproblem.php?pid=3434 

            Sequence Adjustment

            Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
            Total Submission(s): 463    Accepted Submission(s): 144


            Problem Description
            Given a sequence consists of N integers. Each time you can choose a continuous subsequence and add 1 or minus 1 to the numbers in the subsequence .You task is to make all the numbers the same with
            the least tries. You should calculate the number of the least tries
            you needed and the number of different final sequences with the least tries.
             


             

            Input
            In the first line there is an integer T, indicates the number of test cases.(T<=30)
            In each case, the first line contain one integer N(1<=N<=10^6),
            the second line contain N integers and each integer in the sequence is between [1,10^9].
            There may be some blank lines between each case.
             


             

            Output
            For each test case , output “Case d: x y “ where d is the case number
            counted from one, x is the number of the least tries you need and y
            is the number of different final sequences with the least tries.
             


             

            Sample Input
            2 2 2 4 6 1 1 1 2 2 2
             


             

            Sample Output
            Case 1: 2 3 Case 2: 1 2
            Hint
            In sample 1, we can add 1 twice at index 1 to get {4,4},or minus 1 twice at index 2 to get {2,2}, or we can add 1 once at index 1 and minus 1 once at index 2 to get {3,3}. So there are three different final sequences.
             


             

            Author
            wzc1989
             


             

            Source


            /*
            更詳盡的解題報告見:
            http://hi.baidu.com/liwang112358/blog/item/3dac7e566f300f55d0090679.html 
            */
            #include <stdio.h>
            #include <memory>
            #include <iostream>
            #include <algorithm>
            #include <cstring>
            #include <vector>
            #include <map>
            #include <cmath>
            #include <set>
            #include <queue>
            #include <time.h>
            #include <limits>
            using namespace std;
            #define N 1000005
            #define ll long long
            #define ABS(a) (a > 0 ? a : -a)
            ll a[N], p[N];
            int main(){
            #ifndef ONLINE_JUDGE
             freopen("in.txt", "r", stdin);
             //freopen("out.txt", "w", stdout);
            #endif
             int t, n, ca;
             ca = a[0] = p[0] = p[1] = 0;
             scanf("%d", &t);
             while(t--){
              scanf("%d", &n);
              int i, j;
              ll sum, ans;
              for(i = 1; i <= n; i++) scanf("%d", a+i);
              for(i = 2, j = 1; i <= n; i++){
               if(a[i] != a[j]){
                a[++j] = a[i];
                p[j] = a[j] - a[j - 1];
               }
              }
              n = j;
              ans = sum = 0;
              for(i = 2; i <= n; i++){
               if(p[i] * sum < 0) ans += min(ABS(sum), ABS(p[i]));
               sum += p[i];
              }
              sum = ABS(sum);
              ans += sum;
              //printf("Case %d: %lld %lld\n", ++ca, ans, sum + 1);
              printf("Case %d: %I64d %I64d\n", ++ca, ans, sum + 1);
             }
             return 0;
            }

             

             

            posted on 2011-01-21 16:01 tw 閱讀(253) 評論(0)  編輯 收藏 引用 所屬分類: HDU題解

            <2025年6月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            293012345

            導航

            統計

            常用鏈接

            留言簿

            文章分類

            文章檔案

            搜索

            最新評論

            久久青青草原精品影院| 婷婷五月深深久久精品| 国产精品青草久久久久福利99 | 性色欲网站人妻丰满中文久久不卡 | 精品多毛少妇人妻AV免费久久| 久久天天躁夜夜躁狠狠躁2022| 久久久久久夜精品精品免费啦 | 中文精品久久久久国产网址| 久久国产精品无| 国产精品久久久久jk制服| 久久久久一本毛久久久| 亚洲AV日韩精品久久久久| 国内精品久久久久久麻豆| 久久国产色av免费看| 国产福利电影一区二区三区久久久久成人精品综合| 久久精品国产亚洲Aⅴ蜜臀色欲| 东京热TOKYO综合久久精品| 亚洲欧美国产精品专区久久| 亚洲国产精品热久久| 99久久精品免费看国产一区二区三区 | 国产人久久人人人人爽| 思思久久99热只有频精品66| 久久午夜无码鲁丝片午夜精品| 久久久久久毛片免费播放| 久久这里有精品| 一级做a爰片久久毛片毛片| 久久午夜电影网| 国产成人精品久久一区二区三区| 久久人妻AV中文字幕| 午夜精品久久久久久| 久久久久久久综合综合狠狠| 91精品国产91久久久久久| 国产欧美久久一区二区| …久久精品99久久香蕉国产| 亚洲国产精品一区二区久久hs| 久久人妻AV中文字幕| 久久久久亚洲AV片无码下载蜜桃 | 久久精品日日躁夜夜躁欧美 | 亚洲一本综合久久| 日韩亚洲欧美久久久www综合网| 久久久久亚洲av无码专区导航|