题目链接:A. Sereja and Swaps 题意:给定一个序列,能够交换k次,问交换完后的子序列最大值的最大值是多少 思路:暴力枚举每一个区间,然后每一个区间[l,r]之内的值先存在优先队列内,然后找区间外假设有更大的值就替换掉. 求出每一个区间的最大值,最后记录下全部区间的最大值 代码: By lab104_yifan, contest: Codeforces Round #243 (Div. 2), problem: (C) Sereja and Swaps, Accepted, #…
题目 这要学习的是如何枚举区间,vector的基本使用(存入,取出,排序等),这题的思路来自: http://www.tuicool.com/articles/fAveE3 //vector 可以用sort排序:sort(ve.begin(),ve.end()); //下标从0开始,内部元素可以用vec[i]这样像数组一样表示 //插入用push_back() //个数用size() #include <cstdio> #include<iostream> #include <…
[题目链接] https://codeforces.com/contest/425/problem/A [算法] 枚举最终序列的左端点和右端点 , 尝试用这段区间中小的数与区间外大的数交换 时间复杂度 : O(N^3logN) [代码] #include<bits/stdc++.h> using namespace std; ; const int inf = 2e9; int n , k; int a[MAXN],b[MAXN],value[MAXN]; template <typen…
A. Sereja and Swaps time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output As usual, Sereja has array a, its elements are integers: a[1], a[2], ..., a[n]. Let's introduce notation: A swap operatio…
D. Diverse Garland time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ii-th lamp is sisi ('…
D. Jerry's Protest time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Andrew and Jerry are playing a game with Harry as the scorekeeper. The game consists of three rounds. In each round, Andr…
http://codeforces.com/contest/426/problem/C 题意:找出连续序列的和的最大值,可以允许交换k次任意位置的两个数. 思路:枚举区间,依次把区间内的比较小的数换成区间外的比较大的数. #include <cstdio> #include <iostream> #include <cstring> #include <queue> #include <algorithm> using namespace std…
题意: 给你一个有n个数的序列 取一个区间 这个区间内的数可以与区间外的值交换k次 问这样的区间最大值是多少 思路: 看数据是200 时间复杂度O(n*n) 应该可以暴力 顺便学习一下优先队列 枚举区间 每次将区间内最小的数和区间外最大的值交换然后更新和 #include<stdio.h> #include<iostream> #include<algorithm> #include<math.h> #include<string.h> #inc…
输入n*m的01矩阵.以及k. n,m<=100,k<=10 问修改至多k个,使得矩阵内的各连通块(连着的0或1构成连通块)都是矩形,且不含另外的数字(边界为0(1)的矩形内不含1(0)),求最少修改个数. 再次感觉以前见过类似的....完全不会... 看了题解再看别人的代码才搞懂.... 首先,要知道一个结论,满足题意的矩阵,任意2行(列)的抑或值必须为全0或全1. 然后,分类讨论, 如果可以修改个数k<n,如果有答案,那必然至少有一行是没修改的,枚举不修改的行,统计. k>=n…
题目链接: B. Restoring Painting time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he…