http://codeforces.com/contest/760/problem/E 题目大意:现在对栈有m个操作,但是顺序是乱的,现在每输入一个操作要求你输出当前的栈顶, 注意,已有操作要按它们的时间顺序进行. 思路:线段树好题啊啊,我们把push当成+1, pop当成-1,按操作的位置建立线段树,那么如何 寻找栈顶呢,我们计算每个点的后缀,栈顶就是下标最大的>0的后缀,我们拿后缀建立线段树, 剩下的就是区间加减法,和求区间最大值啦. #include<bits/stdc++.h>…
D - Travel Card 思路:dp,类似于单调队列优化. 其实可以写的更简单... #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define pii pair<int, int> using namespace std; ; ; const int inf = 0x3f3f3f3f; const LL INF = 0…
A. Petr and a calendar time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to wee…
传送门:http://codeforces.com/contest/755 A题题意是给你一个数字n,让你找到一个数字m,使得n*m+1为合数,范围比较小,直接线性筛出1e6的质数,然后暴力枚举一下就好了. #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <vector> #i…
题目链接:http://codeforces.com/contest/755/problem/C 题意:PolandBall 生活在一个森林模型的环境中,定义森林由若干树组成,定义树为K个点,K-1条无向边的图.现在给定每个家庭在对应的树上离他最远的另一个家庭的编号.问这个森林有多少棵树组成. 思路:由于只给出了每个点在树上离他最远的点的坐标而不知道整体结构,但是可以知道该点和给定离他最远的点一定是在同一颗树上,所以维护一个并查集,最后有多少个连通分量就是有多少棵树了. import java.…
D. Factory Repairs 题目连接: http://www.codeforces.com/contest/635/problem/D Description A factory produces thimbles in bulk. Typically, it can produce up to a thimbles a day. However, some of the machinery is defective, so it can currently only produce…
C. XOR Equation 题目连接: http://www.codeforces.com/contest/635/problem/C Description Two positive integers a and b have a sum of s and a bitwise XOR of x. How many possible values are there for the ordered pair (a, b)? Input The first line of the input…
B. sland Puzzle 题目连接: http://www.codeforces.com/contest/635/problem/B Description A remote island chain contains n islands, labeled 1 through n. Bidirectional bridges connect the islands to form a simple cycle - a bridge connects islands 1 and 2, isl…
A. Orchestra 题目连接: http://www.codeforces.com/contest/635/problem/A Description Paul is at the orchestra. The string section is arranged in an r × c rectangular grid and is filled with violinists with the exception of n violists. Paul really likes vio…
暴力 A - Orchestra import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner (System.in); int r = cin.nextInt (); int c = cin.nextInt (); int n = cin.nextInt (); int k = cin.nextInt ();…