• HDU 6979 Photoshop Layers


    Problem Description

    Pixels in a digital picture can be represented with three integers (R,G,B) in the range 0 to 255 that indicate the intensity of the red, green, and blue colors. The color of a pixel can be expressed as a six-digit hexadecimal capital string. For example, (R=100,G=255,B=50) can be expressed as ''64FF32''.

    There are n layers in Photoshop workstation, labeled by 1,2,…,n from bottom to top. The screen will display these layers from bottom to top. In this problem, you only need to handle the case that the color of all the pixels in a layer are the same. The color of the i-th layer is ci=(Ri,Gi,Bi), the blending mode of the i-th layer is mi (mi∈{1,2}):

    • If mi=1, the blending mode of this layer is ''Normal''. Assume the previous color displayed on the screen is (Rp,Gp,Bp), now the new color will be (Ri,Gi,Bi).
    • If mi=2, the blending mode of this layer is ''Linear Dodge''. Assume the previous color displayed on the screen is (Rp,Gp,Bp), now the new color will be (min(Rp+Ri,255), min(Gp+Gi,255), min(Bp+Bi,255)).

    You will be given q queries. In the i-th query, you will be given two integers li and ri (1≤li≤ri≤n). Please write a program to compute the final color displayed on the screen if we only keep all the layers indexed within [li,ri] without changing their order. Note that the color of the background is (R=0,G=0,B=0).

     

    Input

    The first line contains a single integer T (1≤T≤10), the number of test cases. For each test case:

    The first line of the input contains two integers n and q (1≤n,q≤100000), denoting the number of layers and the number of queries.

    In the next n lines, the i-th line contains an integer mi and a six-digit hexadecimal capital string ci, describing the i-th layer.

    In the next q lines, the i-th line contains two integers li and ri (1≤li≤ri≤n), describing the i-th query.

     

    Output

    For each query, print a single line containing a six-digit hexadecimal capital string, denoting the final displayed color.

     

    Sample Input

     
     

    1 5 5 1 64C832 2 000100 2 010001 1 323C21 2 32C8C8 1 2 1 3 2 3 2 4 2 5

     

    Sample Output

     
     

    64C932 65C933 010101 323C21 64FFE9

    思路:因为颜色最大为255,因此直接对数据进行处理输出时直接分情况与255取最小值即可,可以采用scanf("%x")来读入十六进制的颜色字符串;

    AC代码:

    1. #include
    2. #include
    3. #include
    4. using namespace std;
    5. const int N=100010;
    6. int n,m,type;
    7. int r[N],g[N],b[N],fa[N];
    8. int main()
    9. {
    10. int T;
    11. scanf("%d",&T);
    12. while(T--)
    13. {
    14. scanf("%d%d",&n,&m);
    15. for(int i=1;i<=n;i++)
    16. {
    17. int a;
    18. scanf("%d %X",&type,&a);
    19. b[i]=a%256;
    20. a/=256;
    21. g[i]=a%256;
    22. r[i]=a/256;
    23. fa[i]=i;
    24. if(type==2)
    25. {
    26. fa[i]=fa[i-1];
    27. r[i]+=r[i-1];
    28. g[i]+=g[i-1];
    29. b[i]+=b[i-1];
    30. }
    31. }
    32. while(m--)
    33. {
    34. int l,R;
    35. scanf("%d%d",&l,&R);
    36. if(l>fa[R])
    37. printf("%02X%02X%02X\n",min(r[R]-r[l-1],255),min(g[R]-g[l-1],255),min(b[R]-b[l-1],255));
    38. else
    39. printf("%02X%02X%02X\n",min(r[R],255),min(g[R],255),min(b[R],255));
    40. }
    41. }
    42. }

  • 相关阅读:
    新的iLeakage攻击从Apple Safari窃取电子邮件和密码
    Day130.MySQL高级:Liunx安装、三大范式、InnoDB、数据结构、B+树
    leakCanary原理
    ubuntu 更新
    【嵌入式开发工具】STM32+Keil实现软件工程搭建与开发调试
    python实现冒泡排序
    Impala时间转换to_date、to_timestamp
    什么年代了,还在用FastQC?试试Falco吧
    IntelliJ IDEA创建Web项目并使用Web服务器----Tomcat
    Linux shell脚本进阶使用
  • 原文地址:https://blog.csdn.net/qq_62242287/article/details/126671256