Beispiel #1
0
inline void solve() {
    std::sort(p+1, p+p_n+1), p[p_n+1].x = p[1].x+L;
    for(int i = 1; i <= p_n; ++i) {
        info[i] = Data2(p[i+1].x-p[i].x, info[i-1].cnt+(p[i].type==1?-1:1), i);
        //debug("%d\n", info[i].cnt);
    }
    std::sort(info+1, info+p_n+1);
    for(int i = 1; i <= p_n; ++i)                    
        sum += 1ll*info[i].len*(info[i].cnt-info[1].cnt);
    ans = sum, cut = info[1].id, cnt = info[1].len;
    //debug("%lld\n", sum);
    for(int i = 2; i <= p_n; ++i) {
        sum += (2*cnt-L)*(info[i].cnt-info[i-1].cnt);
        //debug("%lld\n", sum);
        if(sum < ans) ans = sum, cut = info[i].id;
        cnt += info[i].len;
    }
    get_match(nex(cut));
    std::cout << ans << std::endl;
    for(int i = 1; i <= n; ++i)
        printf("%d%c", match[i], i==n?'\n':' ');
}
Beispiel #2
0
	bool initTexture()
	{
		bool Validated(true);

		gli::gl GL;

		{
			//gli::texture2d Texture(gli::SRGB8, gli::dim2_t(16));
			//Texture.clear(glm::u8vec3(glm::convertRgbToSrgb(glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)) * 255.0f));
			gli::texture2d Texture(gli::FORMAT_RGBA8_SRGB_PACK8, gli::texture2d::extent_type(16));
			Texture.clear(glm::u8vec4(glm::convertLinearToSRGB(glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)) * 255.0f));
			//gli::texture2d Texture(gli::RGBA8_UNORM, gli::dim2_t(16));
			//Texture.clear(glm::u8vec4(glm::vec4(1.0f, 0.5f, 0.0f, 1.0f) * 255.0f));
			gli::save_dds(Texture, "orange.dds");
		}

		gli::texture2d Texture(gli::load_dds((getDataDirectory() + TEXTURE_DIFFUSE).c_str()));
		gli::gl::format const Format = GL.translate(Texture.format());
		gli::gl::swizzles const Swizzles = GL.translate(Texture.swizzles());

		std::size_t Levels = Texture.levels();

		//gli::texture2d Texture(gli::load_dds((getDataDirectory() + TEXTURE_DIFFUSE).c_str()));
		assert(!Texture.empty());

		glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

		glGenTextures(texture::MAX, &TextureName[0]);

		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, TextureName[texture::DIFFUSE]);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, static_cast<GLint>(Texture.levels() - 1));
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, Swizzles[0]);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, Swizzles[1]);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, Swizzles[2]);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, Swizzles[3]);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

		glm::vec4 Data2(glm::convertLinearToSRGB(glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)) * 255.f);
		glm::vec4 Data(glm::convertLinearToSRGB(glm::vec4(0.0f, 0.5f, 1.0f, 1.0f)));
		glTexImage2D(GL_TEXTURE_2D, 0,
			GL_SRGB8_ALPHA8,
			1, 1, 0,
			GL_RGBA, GL_FLOAT,
			&Data[0]);
/*
		for (gli::texture2d::size_type Level = 0; Level < Texture.levels(); ++Level)
		{
			glTexImage2D(GL_TEXTURE_2D, static_cast<GLint>(Level),
				GL.internal_format(Texture.format()),
				static_cast<GLsizei>(Texture[Level].extent().x), static_cast<GLsizei>(Texture[Level].extent().y), 0,
				GL.external_format(Texture.format()), GL.type_format(Texture.format()),
				Texture[Level].data());
		}
*/
		glm::ivec2 WindowSize(this->getWindowSize() * this->FramebufferScale);

		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, TextureName[texture::COLORBUFFER]);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexImage2D(GL_TEXTURE_2D, GLint(0), GL_SRGB8_ALPHA8, GLsizei(WindowSize.x), GLsizei(WindowSize.y), 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);

		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, TextureName[texture::RENDERBUFFER]);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
		glTexImage2D(GL_TEXTURE_2D, GLint(0), GL_DEPTH_COMPONENT24, GLsizei(WindowSize.x), GLsizei(WindowSize.y), 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr);

		glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

		return Validated;
	}