题意:给出最后的时间n,div 1必须和div2一起举行,并且div2的时间总是比div1大1 给出Sereja(只能参加div2)参加过的k场比赛的时间,问他最少错过了多少场div2,最多错过了多少场div 2 先扫描一遍单个的没有用过的时间,再扫一遍连续的两个没有用过的时间 #include<iostream> #include<cstdio> #include<cstring> #include <cmath> #include<stack>…
题目连接:Codeforces 437C  The Child and Toy 贪心,每条绳子都是须要割断的,那就先割断最大值相应的那部分周围的绳子. #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; const int MAX_N = 1000 + 10; int G[MAX_N][MAX_N]; struct…
https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则,假如u在v相邻前面,那么u和v可以交换位置,问你是队列最后一个人的时候你最前可以换到前面哪里 题解 因为相邻才能换,所以最后一个换到前面一定是一步一步向前走,所以不存在还要向后走的情况 设最后一个为u,假设前面有一个能和u换位置的集合,那么需要将这些点尽量往后移动去接u 假设前面有一个不能和u换位置的集合S,…
Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds. Codesorfes has rounds of two types: Div1 (for advanced coders) and Div2 (for beginner coders).…
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main(){ int x,k; cin >> x >> k; vector<, false); num[x] = true; ; i < k ; ++ i){ int index, num1,num2; cin >> index; ){ cin >&…
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of bconsecutive cells. No cell can be part of two ships, however, the shi…
C. Load Balancing 题目连接: http://www.codeforces.com/contest/609/problem/C Description In the school computer room there are n servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server:…
B. Restaurant Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/problem/B Description A restaurant received n orders for the rental. Each rental order reserve the restaurant for a continuous period of time, the i-th order…
题目链接:Codeforces 437D The Child and Zoo 题目大意:小孩子去參观动物园,动物园分非常多个区,每一个区有若干种动物,拥有的动物种数作为该区的权值.然后有m条路,每条路的权值为该条路连接的两个区中权值较小的一个.假设两个区没有直接连接,那么f值即为从一个区走到还有一个区中所经过的路中权值最小的值做为权值.问,平均两个区之间移动的权值为多少. 解题思路:并查集+贪心.将全部的边依照权值排序,从最大的開始连接,每次连接时计算的次数为连接两块的节点数的积(乘法原理).…
题目链接: http://codeforces.com/problemset/problem/777/B 题目大意: A, B玩游戏,每人一串数字,数字不大于1000,要求每人从第一位开始报出数字,并且比较,如果等于则没事,A>B则B被打一下,反之A被打一下,A很老实不会耍计谋,老老实实从第一个开始报,但是B很狡猾,会改变数字的顺序.问2个次数,一个是B最小被打的次数,二是A最多被打的次数. 思路: 贪心,模拟一下就行了.这里用到了cmp的技巧,直接用字符比较,这样就省去了转换为字符串的步骤.…
https://codeforces.com/contest/1141/problem/F2 题意 一个大小为n的数组a[],问最多有多少个不相交的区间和相等 题解 离散化用值来做,贪心选择较前的区间 代码 #include<bits/stdc++.h> #define M 5000005 #define ll long long #define pb push_back using namespace std; struct N{int l,r;N(int l=0,int r=0):l(l)…
C. Simple Strings 题目连接: http://www.codeforces.com/contest/665/problem/C Description zscoder loves simple strings! A string t is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add a…
Codeforces 762B 题目大意: 有a台只有USB接口的电脑,b台PS/2接口的电脑,c台两种接口都有的电脑.每台电脑只用装一个鼠标.给出n个鼠标及其费用,每个鼠标只能使用一遍.在最大化有鼠标的电脑数目的情况下最小化费用. \((0 \le a,b,c \leq 10^5 , n \leq 3*10^5 )\) 题解: 这道题我们很容易抽象出来一个网络流模型 我们设超级源汇为S,T,每台电脑和鼠标都抽象成一个节点 我们可以这么建图 S -> 每台电脑 (flow = 1,cost =…
一道用STL的贪心,正好可以用来学习使用STL库 题目大意:给出n条可以内含,相交,分离的线段,如果重叠条数超过k次则为坏点,n,k<2e5 所以我们贪心的想我们从左往右遍历,如果重合部分条数超过了k,就必须去除线段,(此时从左边看去除线段后不会出现冲突,右边还有剩余很多线段未知)所以我们选择去除这些重合线段里右端最右的部分 实现: #include<bits/stdc++.h>using namespace std;typedef pair<int,int> pii;typ…
https://codeforces.com/contest/1152/problem/D 题意 给你一个n代表合法括号序列的长度一半,一颗有所有合法括号序列构成的字典树上,选择最大的边集,边集的边没有公共点,问边集大小 题解 对于一颗字典树,从低向上贪心,最底层的边全拿,定义好状态,记忆化搜索计数 定义dp[i][j]为左括号数量为i,右括号数量为j的最大边集 \(i<n\),\(dp[i][j]->dfs(i+1,j)\) \(j<i\),\(dp[i][j]->dfs(i,j…
题目描述: time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Dima worked all day and wrote down on a long paper strip his favorite number n consisting of l digits. Unfortunately, the strip turned…
Codeforces Round #228 (Div. 1) 题目链接:C. Fox and Card Game Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card. The players take turns and Ciel takes the first…
Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] 题目链接:B. "Or" Game You are given \(n\) numbers \(a_1, a_2, ..., a_n\). You can perform at most \(k\) operations. For each operation you can multiply one of the numbers by \(x\). We want to make…
链接:https://codeforces.com/contest/1282/problem/C 题意:  有一个人参加考试,考试只有两种题,一种是简单题,每道题耗时固定为a:另一种是困难题,每道题耗时固定为b,保证b>a.解出一道题得分都是1.考试的规则并不只是写多少题得多少分,鼓励提前交卷.假如你没有提前交卷,那么有一部分的题目会列为“必做题”,当“必做题”的题目没有全部被完成的话,这门课就算0分:否则得到与题数相同的分数,包括“必做”和“非必做”的. 题意: 题意很明显需要按题目的“必做时…
链接:https://codeforces.com/contest/1283/problem/E 题意: 有n个人住在一些房子里,有的人住在同一个房子里.每个人可以选择搬去他的房子左边那个房子或者右边那个房子,亦或是不搬,搬只能向左或向右移动一次.问这些人最少住几个房子和最多住几个房子. 题解:贪心.最小值就是三人聚合起来,聚合在一个房子.最大值就是贪心地尽可能地向空房子移动 AC代码: #include<iostream> #include<cstdio> #include<…
https://codeforces.com/problemset/problem/1000/B 题意: 一个模拟思维题.就是有一盏灯,0时刻开着.n次操作,你可以在其中加入一次操作(或者不加),操作为:a[i]时刻按一下开关,状态变为相反状态(开->关or关->开).问灯亮着的时长最长为多少? 样例一0~4开(时长为4-0),4~6关(时长为6-4),6~7开(时长为7-6),7~10关(时长为10-7),可以这这些时间点中加操作使开灯时间变长 在3处加操作,开灯时长变为0-3(开)3-4(…
http://codeforces.com/contest/1294/problem/B 大致题意: 一张图上有n个包裹,给出他们的坐标,一个机器人从(0,0)出发,只能向右(R)或向上(U),问能否收集到所有包裹,如果能,给出字典序最小的路径. 最开始当成搜索题了,其实可以排序+贪心写的. #include <stdio.h> #include <string.h> #include <iostream> #include <string> #includ…
https://codeforces.com/problemset/problem/995/B 题意: 就是通过每次移动相邻的两位数,来使数值相同的数挨在一起,求最少要移动多少次. 思路: 直接从前往后遍历,贪心+暴力即可 代码如下: #include <stdio.h> #include <string.h> #include <iostream> #include <string> #include <math.h> #include <…
题目链接:http://codeforces.com/problemset/problem/712/C 题目大意: 给连个值x,y (3 ≤ y < x ≤ 100 000), x,y都为等边三角形.从y等边三角形 每次修改一条边,且修改后的三个边还能组成一个三角形(两边之和大于第三边).问修改几次能够得到x为边的等边三角形. 例如: 输入: 22 4 输出: 6 解题思路: 从y->x ,定义三个边y1=y2=y3=y, 每次修改一条边 y1=y2+y3-1(两边之和大于第三遍) 修改++ …
题目链接: C. Artem and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Artem has an array of n positive integers. Artem decided to play with it. The game consists of n moves. Each move g…
题目链接: B. Andrey and Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Andrey needs one more problem to conduct a programming contest. He has n friends who are always willing to help.…
题目链接: C. Letters Cyclic Shift 题意: 现在一串小写的英文字符,每个字符可以变成它前边的字符即b-a,c-a,a-z这样,选一个字串变换,使得得到的字符串字典序最小; 思路: 贪心,尽量让前边的字典序变小; AC代码: #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #inclu…
D. Queue time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For e…
题目链接: B. Skills time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was…
C. Make Palindrome Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/problem/C Description A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo&q…