Codeforces-D-Diverse Garland(思维)】的更多相关文章

题目链接:http://codeforces.com/problemset/problem/1108/D time limit per test 1 secondmemory limit per test 256 megabytesinput standard inputoutput standard output You have a garland consisting of n lamps. Each lamp is colored red, green or blue. The colo…
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 ('…
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 ('R', 'G' and 'B' — colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means chang…
Diverse Permutation Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 483C Description Permutationp is an ordered set of integers p1,   p2,   ...,   pn, consisting of n distinct positive i…
https://codeforces.com/contest/1117/problem/C 题意 在一个二维坐标轴上给你一个起点一个终点(x,y<=1e9),然后给你一串字符串代表每一秒的风向,然后每一秒你也可以选择一个方向移动,问到达从起点到终点的最短时间 题解 思维:等效法 假如到达终点之后,可以静止不动,可以用自己走反向风方向来抵消风的方向 先只考虑风向,用前缀和将每一秒到达的位置维护出来,假设x秒到达的位置是[x,y],终点为[sx,sy],则若|sx-x|+|sy-y|<=x,则一定…
https://codeforces.com/contest/1132/problem/F 思维 + 区间dp 题意 给一个长度为n的字符串(<=500),每次选择消去字符,连续相同的字符可以同时消去,问最少需要消去多少次 题解 定义dp[l][r]为区间[l,r]剩下一个字符所需要的最小次数 dp[l][r]=min(dp[l][i]+dp[i+1][r]+x) x为消去剩下两个字符所需要的次数,假如两个字符相同需要x=-1 代码 #include<bits/stdc++.h> #de…
Codeforces 1178D (思维+数学) 题面 给出正整数n(不一定是质数),构造一个边数为质数的无向连通图(无自环重边),且图的每个节点的度数为质数 分析 我们先构造一个环,每个点的度数都是2.但由于n不一定是质数,我们还需要再加k条边.然后对于\(i \in [1,k]\),我们加边(i,i+n/2).当\(k\leq \frac{n}{2}\)的时候,只会把一些点的度数由2变成3,否则会出现重边问题.假设新图的边数为m,那\(m \in [n,n+\frac{n}{2}]\),如果…
B - Sorted Adjacent Differences(CodeForces - 1339B) 题目链接 算法 思维+贪心 时间复杂度O(nlogn) 1.这道题的题意主要就是让你对一个数组进行一种特殊的排序,使得数组中相邻的两个数的差的绝对值成非递减趋势: 2.刚开始对这道题总是执拗于两个相等的数在不同位置,如何把它们放到前面这个问题,因为路走歪了,最终无果,没有思路.后来看了一些关于这道题的解题博客,豁然开朗. 3.使得数组中相邻的两个数的差的绝对值成非递减趋势,怎么想呢.单纯想怎么…
原题:http://codeforces.com/contest/675/problem/C 让我们用数组a保存每个银行的余额,因为所有余额的和加起来一定为0,所以我们能把整个数组a划分为几个区间,每个区间的和都为0.对于每个区间来说,设该区间长度为l,则让该区间都为0的操作数为l-1,例如:1 .1 .-3 .1的操作数为3,也就是说,若把a分成k个区间,则a所需要的总的操作数为n-k. 所以现在我们的目标就是把数组a划分为尽可能多的部分,这个时候我们可以用一个map,统计前缀和的个数,因为对…
题目链接:http://codeforces.com/problemset/problem/483/C 题目意思:给出 n 和 k,要求输出一个含有 n 个数的排列 p1, p2, ...,pn,使得 |p1 - p2|, |p2 - p3|, ..., |pn - 1 - pn| 恰好有 k 个不同的数.注意,p1, p2, ..., pn 每个数是不相等的,而且不大于 n. 构造题,这个通过手动很容易知道答案.又献上我的恶心涂鸦---看完之后会发现其实很简单,好像比 B 还要简单. 只要红色…
题目链接 TAG: 这是我近期做过最棒的一道贪心思维题,不容易想到,想到就出乎意料. 题意:给定两个含有N个正整数的数组a和b,让你输出一个数字k ,要求k不大于n/2+1,并且输出k个整数,范围为1~n的不重复数字, 要求这k个数字为下标的对应a和b中的数的和乘以2的值  分别大于a和b 的数组总和. 思路:首先对a进行降序排序,然后输出最大值的下标,随后进行幅度为2的枚举,对排序后的a2~an进行选择性输出下标,(注意,排序的时候用一个新数组开两个变量,一个index,一个v进行排序,可以用…
题目链接:https://codeforces.com/contest/1090/problem/D Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these…
C. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given positive integer number n. You should create such strictly increasing sequence of k positive numbers a1, a2, ...…
题目链接:http://codeforces.com/problemset/problem/219/C 题目大意: 给出一个字符串,只包含k种字符,问最少修改多少个字符(不增长新的种类)能够得到一个新的字符串,这个字符串满足相邻的字符没有相同的.解题思路:k=2时:字符串只能是ABABAB.....或者BABABA.....两种都枚举一下即可.k>2时:若有奇数个相同,如AAAAA则可变为ABABA的形式即可.若有偶数个相同,如AAAAAA则变为ABABAC的形式即可,C保证与后一个不同. 代码…
C. Diverse Permutation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Permutation p is an ordered set of integers p1,   p2,   ...,   pn, consisting of n distinct positive integers not larg…
题目链接:http://codeforces.com/contest/758/problem/B 题意:一个原先为4色环的链子少了部分,要你找出死的最少的一种可能,各输出四种颜色的死了多少. 分析:就是要找出这个链子是那个部分.那么就有4!种可能. #include <bits/stdc++.h> using namespace std; ][] = { "BGRY", "BGYR", "BRGY", "BRYG"…
[题目链接] https://codeforces.com/contest/482/problem/A [算法] 首先构造一个(k + 1)个数的序列 , 满足它们的差为1-k 对于i > k + 1,令Ai = i 时间复杂度 : O(N) [代码] #include<bits/stdc++.h> using namespace std; template <typename T> inline void chkmax(T &x,T y) { x = max(x,y…
[题目链接]:http://codeforces.com/contest/767/problem/C [题意] 一棵树; 树上的每个节点都有一个权值; 让你把一棵树切掉两条边; 然后把这棵树分成了3个部分; 要求这3个部分,每个部分的权值和相同; 即sum1=sum2=sum3 [题解] 树形DP; 一开始累加所有节点的权值和sum; 如果不是3的倍数则直接输出无解; 用cnt[x]记录x节点下方的子树和(权值和); 假设dfs到了第x个节点 考虑两种情况; ① 有两个节点y,z; 且sum/3…
题目链接:http://codeforces.com/problemset/problem/831/C 题意:有一位参赛选手,我们不知道他初始或最后的成绩,但是知道k次评审所加(减)的分数,以及n个在这过程中的他的分数.问这名选手初始分有几种情况. 思路:一开始考虑先求出评审分的前缀和,对过程分减去前缀和就能得到的初始分数,求出所有的初始分数情况,用map记录每个初始分重复的次数,重复次数==n 的即为正确的初始分. 然而这么做是WA了的. 分析第一个样例: 4 1-5 5 0 2010 如果按…
题目连接:https://codeforces.com/contest/1283/problem/F 题意:一根电线连接着两个点,这两个点分别代表着两个灯,灯有自己的编号i,其亮度是2 ^ i,每根电线的两个灯分别为主灯和副灯,电源从主灯来,电流向副灯.最开始有一个源点灯,所有的电源从此处流入,对于每根电线,定义其重要性为 :切断这根电线后不能通电的所有灯的亮度之和.首先题目按电线的重要性给出n-1条电线的主灯编号,让你从大到小输出每条电线所连接的两个灯的序号(无前后差别) 题解:首先,题目的所…
http://codeforces.com/problemset/problem/990/B 题意: 有n个细菌,每个细菌的尺寸为ai,现在有以常数k,如果细菌i的尺寸ai大于细菌j的尺寸aj,并且ai<=aj+k,那么细菌i就可以吃掉细菌j,问最后可以剩于多少个细菌. 做法: 用map记录相同尺寸细菌的个数,然后用set进行去重排序,从次小的细胞开始比较比该细胞小一点的细胞是否符合要求,如果符合要求,减去被比较的细胞的个数 #include <stdio.h> #include <…
ACM思维题训练集合 There is a board with a grid consisting of n rows and m columns, the rows are numbered from 1 from top to bottom and the columns are numbered from 1 from left to right. In this grid we will denote the cell that lies on row number i and col…
ACM思维题训练集合 Furik and Rubik love playing computer games. Furik has recently found a new game that greatly interested Rubik. The game consists of n parts and to complete each part a player may probably need to complete some other ones. We know that the…
题意:1...n 的全排列中 p1, p2, p3....pn中,找到至少有k个 |p1-p2| , |p2-p3|, ...|pn-1 - pn| 互不相同的元素! 思路: 保证相邻的两个数的差值的绝对值为单调递减序列..... 如果够k个了,最后将没有访问到的元素直接添加到末尾! #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define N 1000…
题意 给出字符串a与b 可以将a中的单个字符改为# 问最少改多少次 a中就找不到b了 一开始想的是用strstr 因为如果找到 可以将strstr(a,b)-a+1改成# 即改首字母 用while循环strstr来做题 然而改第一个字母不行 因为有可能重叠 比如在lll之中找ll 改了第一个还能找出来 但是其实只改一个就可以了 之后又想是不是能改最后一个 但是用strstr不会... 所以最后想出了暴力扫一遍的神奇解法..因为最多 a是五次方 b是30 最多是3乘十的六次方..结果46ms就好了…
B. z-sort time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output A student of z-school found a kind of sorting called z-sort. The array a with n elements are z-sorted if two conditions hold: ai ≥ …
这是一道蛮基础的构造题. - k         +(k - 1)      -(k - 2) 1 + k ,    1 ,         k ,             2,    ................... \  /        \  /           \  / k          k-1          k-2 如图所示,先构造第一个数,就是1 + k, 然后接下来每个数字和上个数相差k , k -1 , k -2 这样下来,最后一个数字就是一个中间的数字,过程就…
A. Div. 64 time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills. Her problem is f…
D. Minimum Triangulation time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a regular polygon with nn vertices labeled from 11 to nn in counter-clockwise order. The triangulatio…
题意:灯有三种颜色R,G,B.只要同一种颜色相邻就不可以.问最少需要换几次,可以使在一串灯中没有相邻灯的颜色相同. 思路:贪心思路:我们知道一个程序都是要子阶段,然后子阶段各个组合起来形成这个程序.那么对于每一个子阶段的贪心,就能形成整个程序的贪心. 贪心思路就是:只要出现相邻的相同a[i]==a[i+1], 然后,就选择一个a[i+1]!=a[i]&&a[i+1]!=a[i+2]的情况.注意:最后2个字母相同时,需要自己处理一下. #include<iostream> usi…