传送门 题意 给出一个数组A,你有一个数组B(一开始全为0),询问多少次操作后B转化为A 一次操作:选择一段区间,加上某个正整数 分析 构建一个栈, 输入一个数,若当前栈空或栈顶元素比输入小,则加入栈中,否则若大于栈顶元素,则删去栈顶元素,放入输入元素,复杂度O(n) trick 代码 #include <bits/stdc++.h> using namespace std; #define ll long long #define F(i,a,b) for(int i=a;i<=b;+…
Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. There are m bidirectional roads, each of whose connects some pair of cities. To bake…
Problem A: 题目大意: 给出以节点1为根的一棵树A,判断它是否是特殊的.一棵树是特殊的当且仅当不存在和它不完全相同的一棵树B,使得A中点i到点1的距离和B中相等. 题解: 假设一个点x的深度是d,它的父亲是y,如果存在一个深度为d-1的点z,那么把x从y下面移到z下面就可以得到树B了.所以求出每个深度的点的个数,只有当所有深度的点的个数都为1,最大深度的点的个数任意的时候 树是特殊的. Problem B: 题目大意: 给出N个点N条边的无向图判断是否存在哈密顿路. N<=1000.…
http://acm.hdu.edu.cn/showproblem.php?pid=5424 哈密顿通路:联通的图,访问每个顶点的路径且只访问一次 n个点n条边 n个顶点有n - 1条边,最后一条边的连接情况: (1)自环(这里不需要考虑): (2)最后一条边将首和尾连接,这样每个点的度都为2: (3)最后一条边将首和除尾之外的点连接或将尾和出尾之外的点连接,这样相应的首或尾的度最小,度为1: (4)最后一条边将首和尾除外的两个点连接,这样就有两个点的度最小,度都为1 如果所给的图是联通的话,那…
http://acm.hdu.edu.cn/showproblem.php?pid=5423 题目大意:给你一个树 判断这棵树是否是独特的 一颗树是独特的条件:不存在一颗和它本身不同但相似的树 两颗树相似条件:两颗树中点的数量相等且相对应的点的深度相同 如第2个样例 4 1 2 2 3 1 4 与 4 1 2 1 4 3 4 如图:这两棵树的点的数量相等且相应的点的深度deep相同,所以这两棵树相似,所以样例2存在一颗树与它不同但相似,即不特殊 运用广搜统计每个点的深度 要想一颗树特殊,只有保证…
D. Berland Fair time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output XXI Berland Annual Fair is coming really soon! Traditionally fair consists of nn booths, arranged in a circle. The booths ar…
A:差点开场懵逼.只要有相邻两位不同就可以作为答案. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; int read() { ,f=;char c=getchar(); ;c=getchar();} )+(x<<)…
Three Equal Time limit: 1000 msMemory limit: 256 MB   You are given an array AA of NN integers between 00 and 22. With cost 11 you can apply the following operation A_i = ((A_i + 1)\ \% \ 3)A​i​​=((A​i​​+1) % 3). Find the minimum cost to make all ele…
csa66 Risk Rolls Time limit: 1000 msMemory limit: 256 MB   Alena and Boris are playing Risk today. We'll call an outcome the sum of values on the faces of 111 or more rolled dice. Alena has NNN possible outcomes whilst Boris has MMM. In turns, each o…
传送门 题意 给出一个排列,定义\(value为\sum_{i=1}^{n-1}abs(f[i+1]-f[i])\) \(swap(a[i],a[j])(i≠j)为一次交换\),询问最少的交换次数使得value最大 分析 如果f[i+1]>f[i],答案就+f[i+1]-f[i]; 如果f[i+1]<f[i],答案就+f[i]-f[i+1]; 那么我们可以找到一个pretty good solution 定义 L 为 f[i]<=n/2, R 为 f[i]>n/2, 得到L R L…