11 2019 档案
摘要:#include<iostream> using namespace std ; const int N=3030; int n; int a[N]; int b[N]; int f[N][N]; //f[i][j] //表示所有由第一个序列的前i个字母,和第二个序列的前j个字母构成的, //且以b
阅读全文
摘要://dp+dfs+贪心 //记一个全局变量 #include<iostream> using namespace std ; const int N=55; int n; int ans; int q[N]; int up[N],down[N];//表示上升子序列结尾和下降子序列结尾 void df
阅读全文
摘要://贪心加dp #include<iostream> using namespace std ; const int N=1010; int n; int q[N]; int f[N]; int g[N];//存每个序列末尾的数字 int main() { while(cin>>q[n]) n++;
阅读全文
摘要:#include <iostream> #include<algorithm> #include<queue> #include<vector> #include <cstdio> using namespace std; typedef long long ll; const int maxn=1
阅读全文
摘要:#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e5+10; int a[N]; int n; bool prime(int x) {//判断是否为质数 for(int i = 2;
阅读全文
摘要://为了连贯,采取一条路形式,从第一行开始 也就是s型 #include <bits/stdc++.h> using namespace std; const int MAXN = 106; char str[MAXN][MAXN]; vector<char> ch;//存放鸡的名字 void in
阅读全文
摘要:#include<iostream> #include<algorithm> using namespace std ; typedef pair<int,int>PII; const int N=5050; PII a[N]; int f[N]; int main() { int n; cin>>
阅读全文
摘要:#include<iostream> using namespace std ; const int N=1010; int f[N]; int a[N]; int main() { int n; cin>>n; int res=0; for(int i=1; i<=n; i++) cin>>a[i
阅读全文
摘要:#include<iostream> using namespace std ; const int N=1100; int f[N],g[N]; int w[N]; int main() { int n; cin>>n; int res=0; for(int i=1; i<=n; i++) cin
阅读全文
摘要:#include<iostream> using namespace std ; const int N=1100; int f[N],g[N]; int w[N]; int main() { int n; cin>>n; int res=0; for(int i=1; i<=n; i++) cin
阅读全文
摘要:#include<iostream> using namespace std ; const int N=110; int f[N],g[N]; int w[N]; int main() { int t; cin>>t; while(t--) { int n; cin>>n; int res=0;
阅读全文
摘要:#include<iostream> using namespace std ; const int N=110; int f[2*N][N][N]; int w[N][N]; int n,m; int main() { cin>>n>>m; for(int i=1; i<=n; i++) for(
阅读全文
摘要:#include<iostream> using namespace std ; const int N=110,INF=1e9; int dp[N][N],w[N][N]; int n; int main() { cin>>n; for(int i=1; i<=n; i++) for(int j=
阅读全文
摘要:#include<iostream> using namespace std ; const int N=110; int f[2*N][N][N]; int w[N][N]; int n; int main() { cin>>n; int a,b,c; while(cin>>a>>b>>c,a||
阅读全文
摘要:#include <iostream> #include <string> #include <cstring> using namespace std; string a1,b1; int a[100001],b[100001],c[100001],t[100001]; int compare(i
阅读全文
摘要:把每一次输入的一组数字存下来,然后把每个数字出现的组数存下来 然后找只出现过一次的数字a,那么这个数字a不是开头就是结尾,默认为开头(是哪个都无所谓),然后去找和它出现在同一组的两个数字b和c,而b和c同时出现的只有两组,除了已经知道的,就是需要去查找的,然后循环,同时存在的组数,找到两个数字a和b
阅读全文
摘要://题目要求的是每一个点最少要有两条边连接,所以可以先构成一个环。然后再把剩余的最短的边连接起来 #include<iostream> #include<algorithm> using namespace std ; const int N=100010; int n,m; struct edge
阅读全文
摘要:好吧,其实我拿到这个题的时候,首先想到了bfs,写完之后,开开森森的去交代码,却在第二个数据就TEL,然后优化半天,还是不行。 最终,我盯着1,2,5发呆半天,wc,然后直接贪心 #include<iostream> using namespace std; int main() { int T;
阅读全文
摘要:#include<iostream> #include<stdio.h> using namespace std; typedef long long ll; const int N=1e5+10; int dp[N]; int x[85],r[85]; int main() { int n,m;
阅读全文
摘要:#include<iostream> using namespace std ; const int N=200200; int p[N]; int cnt; int find(int x) { if(p[x]!=x) p[x]=find(p[x]); return p[x]; } int main
阅读全文
摘要:#include<iostream> #include<algorithm> #include<cstring> using namespace std ; typedef long long ll; const int MAXN = 2e5+5; ll arr[MAXN],dp[MAXN]; in
阅读全文
摘要:#include<iostream> #include<cstdio> #include<cstdlib> using namespace std; int T,n; int a[100001],b[100001]; int main() { scanf("%d",&T); while(T--) {
阅读全文
摘要:#include<iostream> #include<map> #include<set> #include<algorithm> using namespace std; const int N = 1e7+10; map<int,bool>vis; set<int>b; int n,a[N],
阅读全文
摘要:#include <cstring> #include <iostream> #include <algorithm> #include <unordered_set> using namespace std; const int N = 110; int n; int f[N]; int sg(i
阅读全文
摘要://只能拿某些特定个数的石子 #include <cstring> #include <iostream> #include <algorithm> #include <unordered_set> using namespace std; const int N = 110, M = 10010;
阅读全文
摘要:#include<iostream> using namespace std; int n; int main() { cin>>n; int res=0; for(int i=1; i<=n; i++) { int x; cin>>x; if(i%2) res=res^x;//判断是不是奇数 }
阅读全文
摘要://a1 ^ a2 ^ ··· ^ an = 0 –>先手必败; //a1 ^ a2 ^ ··· ^ an != 0 –>先手必胜; #include<iostream> using namespace std; int main() { int n; cin >> n; int res = 0;
阅读全文
摘要:#include<iostream> #include<math.h> using namespace std ; const int N=1001; int n; bool st[N]; double x[N]; double y[N]; double dis[N][N]; double ans=
阅读全文
摘要:#include<iostream> using namespace std ; const int N=1010; int y[N][N]; int n; int a[N]; bool st[N]; int sum; bool flag; void print() { for(int i=1; i
阅读全文
摘要://按照wi+si从小到大的顺序排,结果一定最优,最大的危险系数一定是最小的 //类比于国王游戏 #include <iostream> #include <algorithm> using namespace std; typedef pair<int, int> PII; const int N
阅读全文
摘要:#include <iostream> #include <algorithm> using namespace std; const int N = 100010; int n; int q[N]; int main() { scanf("%d", &n); for (int i = 0; i <
阅读全文
摘要:#include <iostream> #include <algorithm> using namespace std; typedef long long LL; const int N = 100010; int n; int t[N]; int main() { scanf("%d", &n
阅读全文
摘要:#include <iostream> #include <algorithm> #include <queue> using namespace std; int main() { int n; scanf("%d", &n); priority_queue<int, vector<int>, g
阅读全文
摘要://1.将所有区间按左端点从小到大排序 //2.从前往后处理每个区间,判断能否将其放到某个现有的组中 //判断某一组的最后一个区间的右端点是否小于该区间的左端点 //如果大于或等于,就开新组,如果小于,就放到组里去,并更新最后一个区间的右端点 #include <iostream> #include
阅读全文
摘要://1.将所有区间按照左端点从小到大排序 //2.从前往后依次枚举每个区间 //首先选择能够覆盖左端点的区间当中右端点最靠右的端点 //在所有能覆盖start的区间当中,选择右端点最大的区间 //选完之后将start更新成右端点的最大值 #include <iostream> #include <a
阅读全文
摘要://1.将每个区间按右端点从小到大排序 //2.从前往后依次枚举每个区间,如果当前区间中已经包含点,就直接跳过,否则,选择当前区间的右端点 //选右端点的话,可以尽可能的包含在多个区间里 #include <iostream> #include <algorithm> using namespace
阅读全文
摘要://1.将每个区间按右端点从小到大排序 //2.从前往后依次枚举每个区间,如果当前区间中已经包含点,就直接跳过,否则,选择当前区间的右端点 //选右端点的话,可以尽可能的包含在多个区间里 //那么选的点的数量,就是最大的不相交的区间的数量 #include <iostream> #include <
阅读全文
摘要:#include <iostream> #include <algorithm> #include <vector> using namespace std; const int N = 10; /* 001~abc-1, 999 abcxegf 1. num[i] < x, 0 2. num[i]
阅读全文
摘要://f[i][j]表示从(i,j)开始滑的路径 #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int N = 310; int n, m; int g[N][N]; int
阅读全文
摘要://f[u][0]是所有以u为根的子树中选择,并且不选u这个点的方案 //f[u][1]是所有以u为根的子树中选择,并且 选u这个点的方案 #include <cstring> #include <iostream> #include <algorithm> using namespace std;
阅读全文
摘要://f[i][j]表示从0走到j,走过的所有点是i(一个二进制数)的所有路径 #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int N = 20, M = 1 << N;
阅读全文
摘要:#include<bits/stdc++.h> using namespace std; const int N = 12, M = 1 << N; int st[M]; long long f[N][M]; //用f[i][j]记录第i列第j个状态。j状态位等于1表示上一列有横放格子,本列有格子捅
阅读全文
摘要:#include <iostream> #include <algorithm> using namespace std; const int N = 1010, mod = 1e9 + 7; int n; int f[N][N]; int main() { cin >> n; f[0][0]=1;
阅读全文
摘要://不考虑数字的顺序 //可以看出完全背包问题,1~ n-1 的数字可以用无限次 #include <iostream> #include <algorithm> using namespace std; const int N = 1010, mod = 1e9 + 7; int n; int f
阅读全文
摘要:#include <iostream> #include <algorithm> using namespace std; const int N = 1010; int n, m; char a[N], b[N]; int f[N][N];//a的前N个去匹配b的前N个需要编辑的最小操作 int
阅读全文
摘要:#include <iostream> #include <algorithm> #include <string.h> using namespace std; const int N = 15, M = 1010; int n, m; int f[N][N]; char str[M][N]; i
阅读全文
摘要:#include<iostream> #include<algorithm> #include<vector> using namespace std; int main(void) { int n; cin >> n; vector<int>arr(n); for (int i = 0; i <
阅读全文
摘要:石子合并终极通用版 #include<bits/stdc++.h> using namespace std ; int stone[50010]; int n,t,ans; void combine(int k) { int tem=stone[k]+stone[k-1];//合并k和k-1堆 an
阅读全文
摘要:#include <iostream> #include <algorithm> using namespace std; const int N = 310; int n; int s[N];//前缀和 int f[N][N];//状态 int main() { scanf("%d", &n);
阅读全文
摘要://设上升序列的最后一个数字为第i个,那么就以第i-1个位分类标准, //i-1可以没有,也可以是在数组中下标为1,下标为2 //一直到下标为i-1的数字 #include <iostream> #include <algorithm> using namespace std; const int
阅读全文
摘要:#include <iostream> #include <algorithm> using namespace std; const int N = 1010; int n, m; char a[N], b[N]; int f[N][N]; int main() { scanf("%d%d", &
阅读全文
摘要://从上往下 #include <iostream> #include <algorithm> using namespace std; const int N = 510, INF = 1e9; int n; int a[N][N]; int f[N][N]; int main() { scanf
阅读全文
摘要:#include<iostream> #include<algorithm> #include<cstring> using namespace std ; const int N=110; int n,v,m; int f[N][N]; int main() { cin>>n>>v>>m; for
阅读全文
摘要:#include<bits/stdc++.h> using namespace std ; const int N=1010; int n,m; int f[N]; struct Thing { int kind;//记录背包种类 int v,w; }; vector<Thing>things; i
阅读全文
摘要:#include <iostream> #include <algorithm> using namespace std; const int N = 110; int n, m; int v[N][N], w[N][N], s[N]; int f[N]; int main() { cin >> n
阅读全文
摘要://二进制优化 最后变为01背包 #include <iostream> #include <algorithm> using namespace std; const int N = 12010, M = 2010; int n, m; int v[N], w[N]; int f[M]; int
阅读全文
摘要:朴素 #include<iostream> #include<algorithm> using namespace std ; const int N=1010; int n,m; int v[N],w[N]; int f[N][N]; int main() { cin>>n>>m;//n个物品 最
阅读全文
摘要:朴素 数据范围小 //数据范围小 #include<iostream> #include<algorithm> using namespace std ; const int N=110; int n,m; int v[N],w[N],s[N]; int f[N][N]; int main() {
阅读全文
摘要:朴素 //朴素二维 #include <iostream> #include <algorithm> using namespace std; const int N = 1010; int n, m; int v[N], w[N]; int f[N][N]; int main() { cin >>
阅读全文
摘要:#include <iostream> #include <algorithm> using namespace std; typedef long long LL; LL qmi(int a, int k, int p) { LL res = 1 % p; while (k) { if (k &
阅读全文
摘要:#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=1e6+10; int primes[N],cnt; int phi[N]; bool st[N]; ll get_eulers(int n)
阅读全文
摘要://用定义直接求 #include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; while(n--) { int x; cin>>x; int res=x; for(int i=2; i<=x/i; i++) { i
阅读全文
摘要:A team of three programmers is going to play a contest. The contest consists of nn problems, numbered from 11 to nn. Each problem is printed on a sepa
阅读全文
摘要:You play a computer game. In this game, you lead a party of mm heroes, and you have to clear a dungeon with nn monsters. Each monster is characterized
阅读全文
摘要:Let's call an array tt dominated by value vv in the next situation. At first, array tt should have at least 22 elements. Now, let's calculate number o
阅读全文
摘要:Recently Petya walked in the forest and found a magic stick. Since Petya really likes numbers, the first thing he learned was spells for changing numb
阅读全文
摘要:You are the gym teacher in the school. There are nn students in the row. And there are two rivalling students among them. The first one is in position
阅读全文
摘要:#include <iostream> #include <algorithm> using namespace std; //辗转相除法 //a和b的最大公约数 = b和(a % b)的最大公约数 int gcd(int a, int b) { //如果b不是0 返回gcd(b, a % b)】
阅读全文
摘要:#include <iostream> #include <algorithm> #include <vector> using namespace std; vector<int> get_divisors(int x) { vector<int> res; for (int i = 1; i <
阅读全文
摘要:#include <iostream> #include <algorithm> #include <unordered_map> #include <vector> using namespace std; typedef long long LL; const int N = 110, mod
阅读全文
摘要:#include <iostream> #include <algorithm> #include <unordered_map> #include <vector> using namespace std; typedef long long LL; const int N = 110, mod
阅读全文
摘要:#include <iostream> #include <algorithm> using namespace std; void divide(int x) { for (int i = 2; i <= x / i; i ++ ) if (x % i == 0) { //枚举的都是质因子,因为已
阅读全文
摘要:#include <iostream> #include <algorithm> using namespace std; const int N= 1000010; int primes[N], cnt; bool st[N]; void get_primes(int n) { //n只会被最小质
阅读全文
摘要:#include <iostream> #include <algorithm> using namespace std; bool is_prime(int x) { if (x < 2) return false; for (int i = 2; i <= x / i; i ++ ) if (x
阅读全文
摘要:#include <cstring> #include <iostream> #include <algorithm> using namespace std; const int N = 100010, M = 200010; int n, m; int h[N], e[M], ne[M], id
阅读全文
摘要:#include <cstring> #include <iostream> #include <algorithm> using namespace std; const int N = 510, M = 100010; int n1, n2, m; int h[N], e[M], ne[M],
阅读全文
摘要://稀疏图 #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int N = 510, INF = 0x3f3f3f3f; int n, m; int g[N][N]; int
阅读全文
摘要://稠密图 #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int N = 100010, M = 200010, INF = 0x3f3f3f3f; int n, m; i
阅读全文
摘要://不存在负权回路 //边权可能为负数 #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int N = 210, INF = 1e9; int n, m, Q; int d[
阅读全文
摘要:#include <cstring> #include <iostream> #include <algorithm> #include <queue> using namespace std; const int N = 100010; int n, m; int h[N], w[N], e[N]
阅读全文
摘要://存在负权值 处理负环 //如果能求出来 一般是不存在负权回路 //如果有负回路 那最小距离可能是负无穷 #include <cstring> #include <iostream> using namespace std; const int N = 1e4+1; struct Edge { i
阅读全文
摘要:#include <cstring> #include <iostream> #include <algorithm> #include <queue> using namespace std; const int N = 2010, M = 10010; int n, m; int h[N], w
阅读全文
摘要://稀疏图 点和边差不多 #include <cstring> #include <iostream> #include <algorithm> #include <queue> using namespace std; typedef pair<int, int> PII; const int N
阅读全文
摘要://朴素Dijkstra 边权都是正数 稠密图:点和边差的比较多 #include<cstring> #include<iostream> #include<algorithm> using namespace std; const int N = 510; int n, m; int g[N][N
阅读全文
摘要:模拟队列 #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int N = 100010; int n, m; int h[N], e[N], ne[N], idx;//邻接表
阅读全文
摘要:队列 #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <queue> using namespace std; const int N = 100010; int n, m;
阅读全文
摘要:#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int N = 100010, M = N * 2; int n; int h[N], e
阅读全文
摘要:Ujan has been lazy lately, but now has decided to bring his yard to good shape. First, he decided to paint the path from his house to the gate. The pa
阅读全文
摘要:This problem is different from the easy version. In this version Ujan makes at most 2n2n swaps. In addition, k≤1000,n≤50k≤1000,n≤50 and it is necessar
阅读全文
摘要:This problem is different from the hard version. In this version Ujan makes exactly one exchange. You can hack this problem only if you solve both pro
阅读全文
摘要:Ujan decided to make a new wooden roof for the house. He has nn rectangular planks numbered from 11 to nn. The ii-th plank has size ai×1ai×1 (that is,
阅读全文
摘要:vector, 变长数组,倍增的思想 size() 返回元素个数 empty() 返回是否为空 clear() 清空 front()/back() push_back()/pop_back() begin()/end() [] 支持比较运算,按字典序 pair<int, int> first, 第一
阅读全文
摘要://快速判断两次字符串是不是相等 #include<bits/stdc++.h> using namespace std ; typedef unsigned long long ULL; const int N=100010,P=131;//经验值 13331 这两个出错情况最少 int n,m;
阅读全文
摘要:拉链法 #include<cstring> #include<iostream> using namespace std ; const int N=100003; int h[N],e[N],ne[N],idx; void insert(int x) { int k=(x%N+N)%N;//哈希函
阅读全文
摘要:笔记.md 9/16/2019 %%%xxh 题目背景 小A是一名新入ACM协会的萌新,众所周知acm的训练日常就是水群膜大佬于是小A也加入了%群巨的行列中 输入格式 每行(不超过100行)包含一个被':'分隔开的字符串S(|S|<=100,)代表了一个人的QQid和他所说的话 输出格式 对于每个人
阅读全文
摘要:#include <iostream> using namespace std; const int N = 50010; int n, m; int p[N], d[N]; //p是baba,d是距离 int find(int x) { if (p[x] != x) {//如果x不是树根 int
阅读全文
摘要://先转换成二进制,然后从从高位开始异或 #include <iostream> #include <algorithm> using namespace std; const int N = 100010, M = 3000000; int n; int a[N], son[M][2], idx;
阅读全文
摘要:#include <iostream> #include <algorithm> using namespace std; const int N = 100010; int n, m; int h[N], size; void down(int u) { int t = u; //u这个点的做儿子
阅读全文
摘要:#include <iostream> using namespace std; const int N = 100010; int p[N]; int find(int x) {//返回祖宗节点,同时进行路径压缩 if (p[x] != x) p[x] = find(p[x]); return p
阅读全文
摘要:#include <iostream> using namespace std; const int N = 100010; int n, m; int p[N], size[N]; int find(int x) { if (p[x] != x) p[x] = find(p[x]); return
阅读全文
摘要:#include <iostream> using namespace std; const int N = 100010; int idx;//下标 int son[N][26], cnt[N];//因为英文字母只有26个,所以二维开26个 char str[N]; void insert(cha
阅读全文
摘要:You are given two strings ss and tt both of length nn and both consisting of lowercase Latin letters. In one move, you can choose any length lenlen fr
阅读全文
摘要:There are nn students at your university. The programming skill of the ii-th student is aiai. As a coach, you want to divide them into teams to prepar
阅读全文
摘要:You are given a binary string of length nn (i. e. a string consisting of nn characters '0' and '1'). In one move you can swap two adjacent characters
阅读全文
摘要:There is a river of width nn. The left bank of the river is cell 00 and the right bank is cell n+1n+1 (more formally, the river can be represented as
阅读全文
摘要:B. Minimize the Permutation You are given a permutation of length nn. Recall that the permutation is an array consisting of nn distinct integers from
阅读全文
摘要:#include <iostream> using namespace std; const int N = 10010, M = 100010; int n, m; int ne[N];//ne[i] : 以i为结尾的部分匹配的值 char s[M], p[N]; int main() { cin
阅读全文
摘要:https://www.acwing.com/problem/content/156/
阅读全文
摘要:https://www.acwing.com/activity/content/problem/content/863/1/
阅读全文
摘要:#include <iostream> #include <vector> #include <algorithm> using namespace std; typedef pair<int, int> PII; void merge(vector<PII> &segs) { vector<PII> res; sort(segs.begin(), segs.end());//pair排序会优先以
阅读全文
摘要:#include<bits/stdc++.h> using namespace std ; int n; struct City { int id; long long x,y; //坐标 long long cc,kk; //自建的花费,连线的花费 bool self;//是否建站 int fa;//连线的站 bool operator < (const City & a)const { ret
阅读全文
摘要:#include <bits/stdc++.h> using namespace std; typedef long long ll; char x[105]; char xx[105]; int main() { int t; cin>>t; while(t--) { int a,b,c,n; cin>>n>>a>>b>>c; for(int i=0; i<n; i++) xx[i]=0; sc
阅读全文
摘要:#include<bits/stdc++.h> using namespace std; char s[101010]; int dp[101010]; const int MOD = 1e9+7; int main() { dp[0] = 1; scanf("%s", s+1); int N = strlen(s+1); for(int i=1; i<=N; ++i) { if(s[i] ==
阅读全文
摘要:https://www.acwing.com/problem/content/804/
阅读全文
摘要:https://www.luogu.org/problem/P1434 记忆化搜索 1. 2.
阅读全文
摘要://是柱状数组的一个基操作 //返回n的最后一位1:lowbit(n) = n & -n //比如 x=1010 那么返回10 x=101000 返回1000 #include<bits/stdc++.h> using namespace std ; int lowbit(int x) { return x&-x;; } int main() { int n; cin>>n; while(n--)
阅读全文