zoukankan      html  css  js  c++  java
  • hdu1698 Just a Hook

    In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes. The hook is made up of several consecutive metallic sticks which are of the same length.



    Now Pudge wants to do some operations on the hook.

    Let us number the consecutive metallic sticks of the hook from 1 to N. For each operation, Pudge can change the consecutive metallic sticks, numbered from X to Y, into cupreous sticks, silver sticks or golden sticks.
    The total value of the hook is calculated as the sum of values of N metallic sticks. More precisely, the value for each kind of stick is calculated as follows:

    For each cupreous stick, the value is 1.
    For each silver stick, the value is 2.
    For each golden stick, the value is 3.

    Pudge wants to know the total value of the hook after performing the operations.
    You may consider the original hook is made up of cupreous sticks.

     
    Input
    The input consists of several test cases. The first line of the input is the number of the cases. There are no more than 10 cases.
    For each case, the first line contains an integer N, 1<=N<=100,000, which is the number of the sticks of Pudge’s meat hook and the second line contains an integer Q, 0<=Q<=100,000, which is the number of the operations.
    Next Q lines, each line contains three integers X, Y, 1<=X<=Y<=N, Z, 1<=Z<=3, which defines an operation: change the sticks numbered from X to Y into the metal kind Z, where Z=1 represents the cupreous kind, Z=2 represents the silver kind and Z=3 represents the golden kind.
     
    Output
    For each case, print a number in a line representing the total value of the hook after the operations. Use the format in the example.
     
    Sample Input
    1
    10 2
    1 5 2
    5 9 3
     
    Sample Output
    Case 1: The total value of the hook is 24.

    这道题本来是想用线段树写的,不过一直超时,直到看到discuss区里一位大神的代码,给跪了,就在这里记录一下

    很容易懂的

     1 #include<stdio.h>
     2 #include<string.h>
     3 int p[100005][4];
     4 int main()
     5 {
     6     int i,j,k,n,m,T;
     7     scanf("%d",&T);
     8     for(i=1;i<=T;++i)
     9     {
    10         int sum=0;
    11         scanf("%d%d",&n,&m);
    12         for(j=1;j<=m;++j)
    13             scanf("%d%d%d",&p[j][0],&p[j][1],&p[j][2]);
    14         for(j=1;j<=n;++j)
    15         {
    16             int v=1;
    17             for(k=m;k>0;--k)
    18             {
    19                 if(p[k][0]<=j&&j<=p[k][1])
    20                 {
    21                     v=p[k][2];
    22                     break;
    23                 }
    24             }
    25             sum+=v;
    26 //            printf("%d %d
    ",j,sum);
    27         }
    28         printf("Case %d: The total value of the hook is %d.
    ",i,sum);
    29     }
    30     return 0;
    31 }
    现在所有的不幸都是以前不努力造成的。。。
  • 相关阅读:
    限制泛型可用类型,类型通配符声明,泛型方法
    泛型简介,泛型类及使用
    异常概念和处理机制,try-catch-finally,throw和throws,自定义异常
    随机验证码
    常用类--Date日期类,SimpleDateFormat日期格式类,Calendar日历类,Math数学工具类,Random随机数类
    String、StringBuffer和StringBuilder,定义一个自己的StringBuilder的类
    自动装箱和拆箱,枚举类型
    使用内部类开发一个存放数据的容器
    手推期望、方差
    ML 徒手系列 最大似然估计
  • 原文地址:https://www.cnblogs.com/shuizhidao/p/8652831.html
Copyright © 2011-2022 走看看