• 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 }
    现在所有的不幸都是以前不努力造成的。。。
  • 相关阅读:
    MYSQL数据丢失讨论【转】
    MySQL 5.6 新功能之 Index Condition Pushdown (ICP)
    MySQL Binlog 【ROW】和【STATEMENT】选择
    MySQL open_files_limit相关设置
    Python颜色输出和random的学习
    Python 之 【二进制、十进制、八进制、十六进制 】之间的转换【转】
    初识 MySQL 5.5 新功能、参数
    Oracle Inventory关键词解释
    plsql 输出当月的所有日期
    ORA29279: SMTP permanent error: 550 XXX@XX.com... No such user
  • 原文地址:https://www.cnblogs.com/shuizhidao/p/8652831.html
Copyright © 2020-2023  润新知