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代码:

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;

const int N=100010;

int n,m,type;
int r[N],g[N],b[N],fa[N];

int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d%d",&n,&m);
		for(int i=1;i<=n;i++)
		{
			int a;
			scanf("%d %X",&type,&a);
			b[i]=a%256;
			a/=256;
			g[i]=a%256;
			r[i]=a/256;
			fa[i]=i;
			if(type==2)
			{
				fa[i]=fa[i-1];
				r[i]+=r[i-1];
				g[i]+=g[i-1];
				b[i]+=b[i-1];
			}
		}
		while(m--)
		{
			int l,R;
			scanf("%d%d",&l,&R);
			if(l>fa[R])
				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));
			else 
				printf("%02X%02X%02X\n",min(r[R],255),min(g[R],255),min(b[R],255));
		}
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Double.Qing

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值