Count Color

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=34869#problem/D

线段树,染色问题

// 3d.cpp : 定义控制台应用程序的入口点。
//

//#include "stdafx.h"
#include<iostream>
#include<cstdio>
#include<cmath> 

using namespace std;
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1

const int maxn = 200005;
int sum[ maxn << 2 ], Add[ maxn << 2 ];

void PushUp( int rt ){
	sum[ rt ] = ( sum[ rt << 1 ] | sum[ rt << 1 | 1 ] );
}

void PushDown( int rt ){
	if( Add[ rt ] != 0 ){
		Add[ rt << 1 ] = Add[ rt << 1 | 1 ] = Add[ rt ];
		sum[ rt << 1 ] = sum[ rt << 1 | 1 ] =  sum[ rt ];
		Add[ rt ] = 0;
	}
}

void Build( int l, int r, int rt ){
	Add[ rt ] = 0;
	sum[ rt ] = 1;
	if( l == r ){
		return;
	}
	int m = ( l + r ) >> 1;
	Build( lson );
	Build( rson );
	PushUp( rt );
}

void Update( int L, int R, int temp, int l, int r, int rt ){
	if( L <= l && r <= R ){
		Add[ rt ] = 1;
		sum[ rt ] = temp;
		return;
	}
	PushDown( rt );
	int m = ( l + r ) >> 1;
	if( L <= m ){
		Update( L, R, temp, lson );
	}
	if( R > m ){
		Update( L, R, temp, rson );
	}
	PushUp( rt );
}

int Query( int L, int R, int l, int r, int rt ){
	if( L == l && r == R ){
		return sum[ rt ];
	}
	PushDown( rt );
	int m = ( l + r ) >> 1;
	int ans = 0;
	if( R <= m )
		ans = Query( L, R, lson );
	else if( L > m )
		ans = Query( L, R, rson );
	else 
		ans = ( Query( L, m, lson ) | Query( m + 1, R, rson ) );
	return ans;
}

//int _tmain(int argc, _TCHAR* argv[])
int main()
{
	int n, m, k, a, b, c;
	char str[ 10 ];
	while( scanf( "%d%d%d", &n, &m, &k ) != EOF ){
		Build( 1, n, 1 );
		while( k-- ){
			scanf( "%s", str );
			if( str[ 0 ] == 'C' ){
				scanf( "%d%d%d", &a, &b, &c );
				Update( a, b, 1 << ( c - 1 ), 1, n, 1 );
			}
			else{
				scanf( "%d%d", &a, &b );
				if( a > b )
					swap( a, b);
				int temp = Query( a, b, 1, n, 1 );
				int ans = 0;
				while( temp ){
					if( temp % 2 != 0 )
						ans++;
					temp = ( temp >> 1 );
				}
				printf( "%d\n", ans );
			}
		}
	}
	return 0;
}


以下是修改后的代码,可以在PPT中运行,实现相同功能的宏代码: ``` Sub ApplyRandomFont() Dim colorList As Variant colorList = Array(RGB(255, 0, 0), RGB(255, 165, 0), RGB(255, 255, 0), RGB(0, 255, 0), RGB(139, 69, 19), RGB(0, 255, 255), RGB(0, 0, 255), RGB(128, 0, 128), RGB(255, 192, 203), RGB(0, 0, 0)) Dim fontList As Variant fontList = Array("星座文字A5", "星座文字A12", "几何标准体A3", "花型文字A1", "花型文字A2", "花型文字A3", "花型文字A4", "欧拉文字A4", "几何标准体B3", "华为文字A1", "星座文字A1", "星座文字B3", "几何方滑体A32") Dim slide As Slide For Each slide In ActivePresentation.Slides Dim shape As Shape For Each shape In slide.Shapes If shape.HasTextFrame Then Dim paragraph As TextRange For Each paragraph In shape.TextFrame.TextRange.Paragraphs Dim run As TextRange For Each run In paragraph.Runs Dim color As Long color = run.Font.Color.RGB Dim i As Integer For i = 0 To UBound(colorList) If color = colorList(i) Then Dim fontIndex As Integer fontIndex = Int(Rnd * UBound(fontList) + 1) run.Font.Name = fontList(fontIndex) fontList(fontIndex) = "" Exit For End If Next i Next run Next paragraph End If Next shape Next slide End Sub ``` 这段代码与之前的代码基本相同,只是将操作对象从Word文档改为PPT文档,并稍作调整以适应PPT文档结构。具体来说,它会遍历PPT的所有文本框,找到指定颜色的字符并随机应用字体。具体实现方法与之前的代码相同,不再赘述。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值